// API 28+. The only correct form on a modern device.PackageInfopi=pm.getPackageInfo(pkg,PackageManager.GET_SIGNING_CERTIFICATES);// 0x08000000SigningInfosi=pi.signingInfo;Signature[]sigs=si.hasMultipleSigners()?si.getApkContentsSigners()// signed by N keys AT ONCE:si.getSigningCertificateHistory();// one signer, possibly ROTATEDfor(Signatures:sigs){// EVERY cert. Never sigs[0]if(Arrays.equals(sha256(s.toByteArray()),EXPECTED))returntrue;}returnfalse;// fail CLOSED
# host
apksignerverify-v--print-certsapp.apk# schemes, cert, debug key?
python3-Bscripts/tamper-surface-map.pyapp.apk# surface by tier
python3-Bscripts/tamper-surface-map.py-vapp.apk# with matched strings
python3-Bscripts/tamper-surface-map.py--jsondir/# corpus, for diffing releases
apktoold-f-ooutapp.apk
grep-rn"0x8000000\|GET_SIGNING_CERTIFICATES"out/smali*/# THE best grep
grep-rnE"getApkContentsSigners|getSigningCertificateHistory|hasSigningCertificate|\FLAG_DEBUGGABLE|isDebuggerConnected|/proc/self/(status|maps|mem)|27042|\getInstallerPackageName|getInstallSourceInfo|requestIntegrityToken"out/smali*/
jadx-djapp.apk&&grep-rn"134217728"j/sources/# jadx prints the flag in DECIMAL
llvm-readelf--dyn-symsout/lib/arm64-v8a/*.so|awk'$7=="UND"{print $8}'\|grep-E"^(ptrace|fork|syscall|dl_iterate_phdr|dladdr|mprotect|sigaction)$"
llvm-readelf--dyn-symsout/lib/arm64-v8a/*.so|grep-E"JNI_OnLoad|Java_"
llvm-readelf-Sout/lib/arm64-v8a/*.so|grepinit_array
aapt2dumpxmltree--fileAndroidManifest.xmlapp.apk|grep-idebuggable
# host — ALWAYS spawn. Most checks run before you could attach.
frida-U-fcom.target.app-lscripts/which-check-fired.js
# device, root — ground truth a Frida hook cannot miss
strace-f-etrace=openat,ptrace,connect,newfstatat-p$(pidof-scom.target.app)# host — the app "just closes"? Look before you leap
adblogcat-c;adbshellamstart-npkg/.Main;adblogcat-d\|grep-iE"integrity|tamper|signature|debugger|frida|FATAL|SIGABRT"# host — is it debuggable? one command
adbshell"run-as com.target.app id"# fails unless FLAG_DEBUGGABLE# host — what the platform recorded
adbshelldumpsyspackagepkg|grep-E"signatures=|flags=|installerPackageName"
Tracer output
Meaning
[J] + stack
Java tier → go to that class in jadx
[N] + module+offset
Native tier → open at that offset in Ghidra
[N] but no [J]
Do not write Java hooks
[!]
A consequence (System.exit, killProcess) — read the stack
// Hook the CONCRETE class. PackageManager is abstract; hooking it does nothing.Java.use('android.app.ApplicationPackageManager').getPackageInfo.overload('java.lang.String','int').implementation=function(p,f){console.log('getPackageInfo('+p+', 0x'+(f>>>0).toString(16)+')');returnthis.getPackageInfo(p,f);};
// The highest-value hook: every signature check ends here.Java.use('android.content.pm.Signature').toByteArray.implementation=function(){console.log('[+] Signature.toByteArray');returnthis.toByteArray();};
// Find the CONSEQUENCE without finding the check. Three lines, usually enough.Java.use('java.lang.System').exit.implementation=function(c){console.log(Java.use('android.util.Log').getStackTraceString(Java.use('java.lang.Exception').$new()));};
// Native: which needle is the maps scan looking for?Interceptor.attach(Module.getExportByName(null,'strstr'),{onEnter:function(a){this.n=a[1].readCString();},onLeave:function(r){if(this.n&&this.n.length>3)console.log('strstr("'+this.n+'") -> '+(r.isNull()?'miss':'HIT'));}});
// When did each library arrive? Its .init_array has ALREADY run by onLeave.Interceptor.attach(Module.getExportByName(null,'android_dlopen_ext'),{onEnter:function(a){console.log('dlopen '+a[0].readCString());}});
constv2,0x8000000# GET_SIGNING_CERTIFICATES — search for this
invoke-virtual{v0,v1,v2},Landroid/content/pm/PackageManager;->getPackageInfo(...)
iget-objectv0,v0,Landroid/content/pm/PackageInfo;->signingInfo:Landroid/content/pm/SigningInfo;
invoke-virtual{v0},Landroid/content/pm/SigningInfo;->getApkContentsSigners()[...
invoke-virtual{v0},Landroid/content/pm/Signature;->toByteArray()[B
sget-objectv1,Lcom/example/a/b;->a:[B# <-- THE BASELINE
invoke-static{v0,v1},Ljava/util/Arrays;->equals([B[B)Z
Want
Smali
Always true
.locals 1 / const/4 v0, 0x1 / return v0
Always false
.locals 1 / const/4 v0, 0x0 / return v0
Return void, do nothing
.locals 0 / return-void
Patching Smali means re-signing, which changes the certificate, which is what D1 detects.
Patch both or neither.
1. digest = sha256(requestBody) # bind to THIS request
2. nonce = server.requestNonce(op, digest) # SERVER issues, stores, single-use
3. token = platform.requestToken(nonce) # opaque — NEVER parse it
4. server.submit(op, requestBody, token) # server ENFORCES
Server must assert, in this order:
verifyJwsSignature(token)
claims.requestDetails.requestPackageName == OUR_PACKAGE # often omitted (3rd)
claims.appIntegrity.appRecognitionVerdict == PLAY_RECOGNIZED
claims.appIntegrity.certificateSha256Digest in OUR_CERTS # often omitted (2nd)
record = nonceStore.consume(nonce) # often omitted (1st) -> REPLAY
record.operationId == op AND record.requestDigest == sha256(body)
now - record.issuedAt < 60s
Three client anti-patterns: client-generated nonce · client parses the verdict · fail open.