APK repackaging and signature verification bypass ideas: locate the verification point first, and then decide where to change it
The reasons why it crashes at startup after repackaging, Java/native two-layer positioning signature verification, four common bypass ideas, and the key points of apksigner signature closing.
After secondary packaging, it crashes on startup, mostly because the signature verification fails. This article is recorded in the order of "locating and verifying first, and then deciding where to change."
1. Why does repackaging crash?
The APK signature is an integrity check of the entire package content. Changing the original signature of a file will invalidate it. Reinforcement or risk control usually involves:
- Read its own signature and compare it with the built-in SHA1/MD5
- check
META-INFCheck whether the certificate information has been replaced - pass
PackageManager.getPackageInfoPicksignaturesCalculate again - Read the EOCD of APK at the native layer for direct verification
2. Locating the checkpoint
Java layer: Search these APIs globally
grep -r "getPackageInfo\|signatures\|GET_SIGNATURES\|getInstallerPackageName" smali/
Native layer:Search for string
strings lib/arm64-v8a/libtarget.so | grep -i -E "signature|sign|sha1|apk"
Dynamic confirmation: Use frida enumeration PackageManager Call to see who is reading the signature
Java.perform(() => {
const PM = Java.use('android.app.ApplicationPackageManager');
PM.getPackageInfo.overload('java.lang.String', 'int').implementation = function (p, f) {
console.log('getPackageInfo', p, f);
return this.getPackageInfo(p, f);
};
});
3. Common types of bypasses
1. Pure Java comparison
Locate the comparison function and change the return value, or replace the built-in original signature string with your own signature value. The latter is more stable because the control flow is not changed.
2. The signature value is hard-coded in so
Replace the original signature string in so with your own; if the lengths are inconsistent, find a buffer of equal length or longer to overwrite, and be careful not to destroy adjacent data.
3. Multi-process/multi-dex repeated verification
This type is the easiest to miss: the main process has passed,:remote or :push There is another copy in the process. After hanging spawn, enumerate the threads and modules and confirm them one by one.
4. Verification merged into integrity check
If you verify the CRC and md5 of dex at the same time, just changing the signature is not enough. You must either process the verification target file together, or directly hook the verification function and return it.
4. Finishing after repackaging
zipalign -p 4 in.apk aligned.apk
apksigner sign --ks my.keystore --v1-signing-enabled true \
--v2-signing-enabled true --v3-signing-enabled true aligned.apk
- The order cannot be reversed: align first and then sign, otherwise the v2 signature will become invalid.
- targetSdk 30+ must be signed with v2, otherwise the direct installation will fail.
- correct
AndroidManifest.xmlNoticeandroid:exportedBecomes required in 31+
5. Suggestions on the order of investigation
- First confirm the crash point: it crashes on startup or only after entering a certain page.
- Check the crash stack to see if there is any
PackageManager/signaturesRelated calls - Search the signature API statically and make the print call dynamically
- Prioritize changing the "constants used for verification" rather than the "verification results", with fewer side effects.
The above only focuses on the analysis and debugging of the signature verification mechanism itself.
please Log in or Register an account Participate in discussions, download exclusive add-ons or unlock level posts.