sensepost / objection

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

Rebuilding the APK may have failed. Read the following output to determine if apktool actually had an error: #388

Closed hailstorm1422 closed 4 years ago

hailstorm1422 commented 4 years ago
kali@void:~/kkk$ objection patchapk --source app-internal-release-0.1.60.apk 
No architecture specified. Determining it using `adb`...
Detected target device architecture as: arm64-v8a
Using latest Github gadget version: 12.10.4
Patcher will be using Gadget version: 12.10.4
Detected apktool version as: 2.4.1
Running apktool empty-framework-dir...
I: Removing 1.apk framework file...
Unpacking app-internal-release-0.1.60.apk
App already has android.permission.INTERNET
Setting extractNativeLibs to true...
Target class not specified, searching for launchable activity instead...
Reading smali from: /tmp/tmp4a1g73u4.apktemp/smali/co/fable/fable/ui/main/home/HomeActivity.smali
Injecting loadLibrary call at line: 185
Attempting to fix the constructors .locals count
Current locals value is 0, updating to 1:
Writing patched smali back to: /tmp/tmp4a1g73u4.apktemp/smali/co/fable/fable/ui/main/home/HomeActivity.smali
Creating library path: /tmp/tmp4a1g73u4.apktemp/lib/arm64-v8a
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: 

W: invalid resource directory name: /tmp/tmp4a1g73u4.apktemp/res navigation
brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [/tmp/brut_util_Jar_13922208592425842436.tmp, p, --forced-package-id, 127, --min-sdk-version, 26, --target-sdk-version, 29, --version-code, 60, --version-name, 0.1.60, --no-version-vectors, -F, /tmp/APKTOOL10708857155343462440.tmp, -e, /tmp/APKTOOL13906446458217265754.tmp, -0, arsc, -I, /home/kali/.local/share/apktool/framework/1.apk, -S, /tmp/tmp4a1g73u4.apktemp/res, -M, /tmp/tmp4a1g73u4.apktemp/AndroidManifest.xml]

Built new APK with injected loadLibrary and frida-gadget
Signing new APK.
Signing the new APK may have failed.
jarsigner: unable to open jar file: /tmp/tmp4a1g73u4.apktemp.objection.apk

Signed the new APK
Performing zipalign
Zipaligning the APK may have failed. Read the following output to determine if zipalign actually had an error: 

Unable to open '/tmp/tmp4a1g73u4.apktemp.objection.apk' as zip archive

Zipalign completed
Copying final apk from /tmp/tmp4a1g73u4.apktemp.aligned.objection.apk to app-internal-release-0.1.60.objection.apk in current directory...
Traceback (most recent call last):
  File "/usr/local/bin/objection", line 10, in <module>
    sys.exit(cli())
  File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/kali/.local/lib/python3.7/site-packages/objection/console/cli.py", line 371, in patchapk
    patch_android_apk(**locals())
  File "/home/kali/.local/lib/python3.7/site-packages/objection/commands/mobile_packages.py", line 227, in patch_android_apk
    shutil.copyfile(patcher.get_patched_apk_path(), os.path.join(os.path.abspath('.'), destination))
  File "/usr/lib/python3.7/shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmp4a1g73u4.apktemp.aligned.objection.apk'
Cleaning up temp files...
Failed to cleanup with error: [Errno 2] No such file or directory: '/tmp/tmp4a1g73u4.apktemp.objection.apk'
rajeshnadiminti commented 4 years ago

I am having similar issue when using Objection

AkshayJainG commented 4 years ago

Have you tried doing it manually? Can the apk be shared?

leonjza commented 4 years ago

I added some tips for patching issues here: https://github.com/sensepost/objection/wiki/Android-APK-Patching