sensepost / objection

📱 objection - runtime mobile exploration
GNU General Public License v3.0
7.41k stars 850 forks source link

Zipaligning the APK may have failed. Read the following output to determine if zipalign actually had an error: #648

Closed manojssc closed 2 months ago

manojssc commented 10 months ago

┌──(objection)─(kali㉿kali)-[~/Desktop] └─$ objection patchapk --source app-release.apk -a x86_64 Using latest Github gadget version: 16.1.7 Patcher will be using Gadget version: 16.1.7 Detected apktool version as: 2.9.0 Running apktool empty-framework-dir... I: Removing 1.apk framework file... Unpacking app-release.apk An error may have occurred while extracting the APK. Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true

App does not have android.permission.INTERNET, attempting to patch the AndroidManifest.xml...
Injecting permission: android.permission.INTERNET Writing new Android manifest... Target class not specified, searching for launchable activity instead... Reading smali from: /tmp/tmpvzojrn7j.apktemp/smali/asvid/github/io/fridaapp/MainActivity.smali Injecting loadLibrary call at line: 62 Attempting to fix the constructors .locals count Current locals value is 0, updating to 1: Writing patched smali back to: /tmp/tmpvzojrn7j.apktemp/smali/asvid/github/io/fridaapp/MainActivity.smali Creating library path: /tmp/tmpvzojrn7j.apktemp/lib/x86_64 Copying Frida gadget to libs path... Rebuilding the APK with the frida-gadget loaded... Rebuilding the APK may have failed. Read the following output to determine if apktool actually had an error:

Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true

Built new APK with injected loadLibrary and frida-gadget Performing zipalign Zipaligning the APK may have failed. Read the following output to determine if zipalign actually had an error:

/usr/bin/zipalign: symbol lookup error: /usr/bin/zipalign: undefined symbol: _ZN11zip_archive6WriterD2Ev

Zipalign completed Signing new APK. Signing the new APK may have failed.

Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true Exception in thread "main" java.io.FileNotFoundException: /tmp/tmpvzojrn7j.apktemp.aligned.objection.apk (No such file or directory)
at java.base/java.io.RandomAccessFile.open0(Native Method)
at java.base/java.io.RandomAccessFile.open(RandomAccessFile.java:344)
at java.base/java.io.RandomAccessFile.(RandomAccessFile.java:259)
at java.base/java.io.RandomAccessFile.(RandomAccessFile.java:213)
at com.android.apksig.ApkSigner.sign(ApkSigner.java:190)
at com.android.apksigner.ApkSignerTool.sign(ApkSignerTool.java:356)
at com.android.apksigner.ApkSignerTool.main(ApkSignerTool.java:85)

Signed the new APK Copying final apk from /tmp/tmpvzojrn7j.apktemp.aligned.objection.apk to app-release.objection.apk in current directory... Traceback (most recent call last): File "/home/kali/.venvs/objection/bin/objection", line 8, in sys.exit(cli()) ^^^^^ File "/home/kali/.venvs/objection/lib/python3.11/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kali/.venvs/objection/lib/python3.11/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/home/kali/.venvs/objection/lib/python3.11/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kali/.venvs/objection/lib/python3.11/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kali/.venvs/objection/lib/python3.11/site-packages/click/core.py", line 783, in invoke return __callback(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kali/.venvs/objection/lib/python3.11/site-packages/objection/console/cli.py", line 373, in patchapk patch_android_apk(locals()) File "/home/kali/.venvs/objection/lib/python3.11/site-packages/objection/commands/mobile_packages.py", line 230, in patch_android_apk shutil.copyfile(patcher.get_patched_apk_path(), os.path.join(os.path.abspath('.'), destination)) File "/usr/lib/python3.11/shutil.py", line 256, in copyfile with open(src, 'rb') as fsrc: ^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpvzojrn7j.apktemp.aligned.objection.apk' Cleaning up temp files...

I have got many warnings from unpacking to signing the apk, and finally it results in no such file or directory.... Please anyone help me with this, tried the available solutions but the error is not changing

mateofumis commented 10 months ago

I've had the same problem.

The solution that worked for me in Kali Linux:

Use Docker image "andrewmackrodt/objection"

docker run --rm -it -v "$PWD:/data" -w /data andrewmackrodt/objection \
  -- \
  patchapk -s MyApp.apk -a arm64-v8a
IPMegladon commented 2 months ago

Also think this may be an issue with zipalign itself. You can try to add --skip-resources and --ignore-nativelibs when patching the app. Also check your zipalign version. #673 is the same issue, so I suspect it might be to do with the kali repo.