Decision in Java? -> managed (then: cmd package compile -m verify -f)
Native, crosses a module boundary? -> PLT/GOT (cheapest, reversible, invisible to text checksums)
Native, intra-module call? -> inline (nothing else reaches it)
Native method, C name unknown? -> RegisterNatives (and be early)
Every caller in the process? -> inline on the export (and accept the noise)
Only need to KNOW, not change? -> observe. Always cheaper, always a better finding.
Bytes in file are reversed relative to the word.fd 7b bf a9 is the word a9bf7bfd.
Confusing the two is the most common reason a hand patch lands backwards.
int64_timm=sign_extend(((w>>5)&0x7FFFF)<<2|((w>>29)&3),21);uintptr_tpage=(old_pc&~0xFFFULL)+(imm<<12);/* where it pointed */int64_tdelta=(int64_t)(page-(new_pc&~0xFFFULL))>>12;/* from the new home *//* refuse if delta > 0xFFFFF or delta < -0x100000 */uint32_tout=(w&0x9F00001FU)|((delta&3)<<29)|(((delta>>2)&0x7FFFF)<<5);
1. Did it install? print bytes before and after
2. Did it fire? log unconditionally on entry
3. Never fired, native? grep for `bl` to the symbol -> inlining
4. Never fired, Java? cmd package compile -m verify -f ; force-stop
5. Never fired, late? spawn instead of attach ; hook dlopen
6. Fired, no change? you hooked a producer; find the consumer
7. Only now suspect the hooking engine
# device identity, before trusting any version-gated claim
adbdevices-l&&adbshellgetpropro.product.model&&adbshellgetpropro.build.version.sdk
adbshell"su -c id"2>/dev/null||adbshell"su 0 id"2>/dev/null||echo"not rooted"# run a native binary when /data/local/tmp refuses execve (errno ENXIO, exit 126)
adbshell/system/bin/linker64/data/local/tmp/prog
# build fixtures (outside the repo)cd65-Hooking/examples&&ANDROID_NDK=..../build-hook-fixtures.sh--run
# hook surface of a library or APK
./scripts/hook-surface.shlib.so
./scripts/hook-surface.shapp.apk
# is one function safely inline-hookable?
python3-Bscripts/hookability.pylib.so--symbolname-v
python3-Bscripts/hookability.pylib.so--all
python3-Bscripts/hookability.pylib.so--symbolname--patch-bytes4# disassembly and symbols
llvm-objdump-d--section=.textlib.so|sed-n'/<name>:/,/^$/p'
llvm-readelf--dyn-symslib.so|grep-E'\bJava_|JNI_OnLoad'
llvm-readelf--relocslib.so|grepJUMP_SLOT
# round-trip an encoding, never write one from memoryprintf'.globl _e\n_e:\n ret\n nop\n'>/tmp/e.s
$NDK/aarch64-linux-android21-clang-c-xassembler/tmp/e.s-o/tmp/e.o&&$NDK/llvm-objdump-d/tmp/e.o
python3-B../18-ARM/scripts/arm64-patch.py--show-encodings
# managed hook not firing
adbshellcmdpackagecompile-mverify-f<pkg>&&adbshellamforce-stop<pkg>
Module.findExportByName('libnative.so','checkLicense')hexdump(Module.findExportByName('libnative.so','checkLicense'),{length:32})Interceptor.attach(Module.findExportByName('libc.so','strcmp'),{onEnter:function(a){console.log(a[0].readCString(),'<=>',a[1].readCString());}});Interceptor.replace(Module.findExportByName('libnative.so','checkLicense'),newNativeCallback(function(){return1;},'int',[]));// GOT entries that point outside every mapped module = hooked, or a bugProcess.findModuleByName('libnative.so').enumerateImports().filter(i=>i.slot&&!Process.findModuleByAddress(i.slot.readPointer()));// what execution state is this Java method in? -> 13-ART/scripts/artmethod-inspect.js