This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef unsigned char u8; | |
static inline uint64_t bswapu64(uint64_t a) | |
{ | |
uint64_t b = 0; | |
for (u8 i = 0; i < sizeof(uint64_t); ++i) { | |
b = (b << __CHAR_BIT__) | (u8)a; | |
a >>= __CHAR_BIT__; | |
} | |
return b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @example 0x1122334455667788 => 0x4477225588336611 | |
* | |
* NB: Do not use this functin like a {cryptographic,} hash function | |
*/ | |
static inline uint64_t memfryu64(uint64_t a, u8 off) | |
{ | |
uint64_t b = 0; | |
for (u8 i = 0; i < sizeof(uint64_t); ++i) { | |
u8 aOff = (i + ((i % 2) ? 0 : off)) % sizeof(uint64_t); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROOT=$(dirname $0) | |
DYNAMORIO=$ROOT/../../../dynamorio/exports | |
DRMEMORY=$ROOT/../../../drmemory/.cmake/exported | |
MSAN_OPTIONS='verbosity=1:sleep_before_dying=10' \ | |
MSAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-3.4 \ | |
LD_LIBRARY_PATH=$DYNAMORIO/ext/lib64/release/:$DYNAMORIO/lib64/release/:$DRMEMORY/drmf/lib64/release/:$ROOT \ | |
LD_USE_LOAD_BIAS=1 \ | |
$DYNAMORIO/bin64/drrun -v -64 -c $ROOT/libmsandr.so -- \ | |
$* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Here we use pmap(1), but it can use smaps instead of it | |
# not do depends from pmap, but for now it's simpler | |
pid="$1" | |
# pmap -x $pid | tail -n+3 | awk '{ size = $2; addr = sprintf("%.f\n", "0x" $1); if (addr-size == prev_addr) { printf "%s # can merged with prev", $1}; prev_addr = addr; }' | |
pmap -x $pid | tail -n+3 | awk '{ size = $2; addr = sprintf("%.f\n", "0x" $1); printf("%.f vs %.f diff %.f\n", prev_addr, addr-size, addr-size-prev_addr); prev_addr = addr; }' | awk '{print $NF}' | sort | uniq -c | sort -nr -k1,1 | head |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Will print commands to run on another machine | |
# to validate that all symbols/versions available there. | |
env LD_DEBUG=all /path/to/bin -h 2>&1 | fgrep 'checking for version' | awk '{sym=$5; gsub(/[^a-zA-Z.0-9_]/, "", sym); printf "echo %s:%s && nm -D %s | fgrep %s || echo NOT FOUND\n", $8, sym, $8, sym}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lsof -n | awk '{ i = 1; i += !!index($0, "deleted"); i += !!index($0, "TCP"); printf "%i: ", i; for (j = 0; j < i; ++j) { printf "%s ", $(NF-j) }; printf "\n"; }' | less |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Translate with google-translate into X server OR tmux | |
# Bind it to shortcut | |
# | |
# @link http://habrahabr.ru/blogs/linux/137215/ | |
# | |
if [ -z $TMUX ]; then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diskToTrack=/ | |
pidToStop=$(pgrep sort) | |
leftPercents=97 | |
while [ 1 ] ; do if [[ $(df $diskToTrack | tail -n+2 | awk '{sub(/%/,"",$5); print $5}') -gt $leftPercents ]]; then kill -STOP $pidToStop && break; else sleep 30; fi; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gawk '{if ($1 ~ /^[0-90-f]+$/ && name ~ /^\./) { printf "[%25s] %.0f\n", name, strtonum("0x" $1); } name=$(NF > 3 ? NF-3 : ""); }' |