Skip to content

Instantly share code, notes, and snippets.

@stbuehler
stbuehler / bma2otp.rb
Created January 25, 2014 14:10
Decode the Battle.net Mobile Authenticator (android) secret data into an otpauth url. Requires a way to access the private data of the application (i.e. a rooted android).
#!/usr/bin/ruby
# REQUIRES:
# * rooted android, as otherwise you can't read the applications private data
# * to display the qr code "qrencode" (http://fukuchi.org/works/qrencode/)
# and "display" from ImageMagick
# This script "decrypts" the token from the internal state of the
# Battle.net Mobile Authenticator on android application, converting
# it into an "otpauth" url (https://code.google.com/p/google-authenticator/wiki/KeyUriFormat)
@stbuehler
stbuehler / .gitignore
Last active November 2, 2023 10:58 — forked from markusfisch/README.md
Force any binary to use a specific network interface in Linux
*.so
@stbuehler
stbuehler / sshsystem
Last active October 28, 2023 14:20
ssh wrapper to quote command and arguments for remote end
#!/bin/bash
# quote command in ssh call to prevent remote side from expanding any arguments
# uses bash printf %q for quoting - no idea how compatible this is with other shells.
# http://stackoverflow.com/questions/6592376/prevent-ssh-from-breaking-up-shell-script-parameters
sshargs=()
while (( $# > 0 )); do
case "$1" in
@stbuehler
stbuehler / debug_fcntl_setlk.c
Created July 15, 2023 16:37
fcntl_setlk_bcc_trace
#include <uapi/linux/ptrace.h>
#include <linux/sched.h>
#include <linux/fcntl.h>
#include <linux/fs.h>
#include <linux/path.h>
#include <linux/dcache.h>
#include <linux/limits.h>
@stbuehler
stbuehler / fcntl_setlk.bt
Created July 15, 2023 12:17
debug fcntl F_SETLK[W] with bpftrace
#include <fcntl.h>
/* Usage example: bpftrace fcntl_setlk.bt podman */
kretfunc:vmlinux:fcntl_setlk / $# == 0 || comm == str($1) / {
if (args->flock->l_type == F_UNLCK) {
delete(@pending_locks[pid, args->filp])
} else if (retval == 0) {
@pending_locks[pid, args->filp] = 1
}
@stbuehler
stbuehler / hacker-evolution-checksum.hs
Created June 4, 2015 19:57
hacker evolution safegame checksum calculation
-- take all numbers from the 3rd until the second last line, multiply each
-- number with the associated multiplier from the list [10,5,6,7,8,9,11,13,14,15,16,2,3,17,18,19]
-- and sum everything up (modulo Int32) to get the checksum.
-- (hint: line 11, the 9th number in the list, is the cash amount)
-- in haskell:
import Data.Int
checksum :: [Int32] -> Int32
checksum nums = sum $ zipWith (*) nums [10,5,6,7,8,9,11,13,14,15,16,2,3,17,18,19]
@stbuehler
stbuehler / livecd-repair-rootfs-interactive.sh
Last active December 27, 2021 16:22
mount rootfs from livecd to repair grub / ...
# Find block device names for main disk, rootfs and /boot (if it is on a separate partition; usually with encrypted rootfs)
# your main disk isn't necessarily /dev/sda anymore; NVMe disks have names like /dev/nvme0n1
# -> /dev/sda might as well be the "livecd"
# For UEFI boot you should also identify the EFI partition; EFI requires a gpt PTTYPE.
lsblk -p -o NAME,RM,SIZE,RO,PTTYPE,TYPE,FSTYPE,MOUNTPOINT,LABEL,PARTLABEL
# or use `lsblk -p; blkid` instead of the long lsblk command
# If you run mdadm raid, probably should start with that. Instructions not included (yet).
# If encrypted rootfs: open it
cryptsetup open /dev/${cryptpart} ${cryptpart}_crypt
@stbuehler
stbuehler / mkcrypt.c
Created September 25, 2013 11:07
create crypt() hashes
/*
* Build:
* LDFLAGS=-lcrypt make mkcrypt
*
* Usage:
* mkcrypt [algo [saltlen [randomsource]]]
*
* - reads password from stdin (tries to set echo off)
*
* Defaults to $6$ as algo, 16 for saltlen and /dev/random for the
@stbuehler
stbuehler / scrot-xclip.sh
Created September 24, 2021 07:36
scrot to clipboard with automatic cleanup
#!/bin/sh
# example config for i3 (.config/i3/config):
# # select window with mouse
# bindsym Print exec --no-startup-id scrot-xclip.sh --select --freeze
# # current window
# bindsym $mod+Print exec --no-startup-id scrot-xclip.sh --focused
set -e
@stbuehler
stbuehler / batcher_oddeven_mergesort.cpp
Created March 23, 2011 18:22
Batcher odd-even mergesort
/* Batcher odd-even mergesort: http://en.wikipedia.org/wiki/Batcher_odd-even_mergesort */
/* O(n * (log n) * (log n)): inplace, and could run in O( (log n) * (log n) ) on n cores in parallel */
/* Most implemenations only handle power-of-two input sizes; this implementation
appends "virtual" infinity items at the end of input (takes no space) */
#include <vector>
#include <cassert>