shroudedcode/apk-mitm

Error while encoding APK file with apk-mitm and Apktool

Opened this issue · 3 comments

Hello,
I ran into a problem when trying to use apk-mitm to decode and modify the APK file. There appears to be a bug with Apktool and AAPT during the encoding process. On default version of Apktool it stops on error while Decoding APK file

Here are the details:

apk-mitm version: 1.2.1
Apktool version: 2.9.3
APK file: com.facebook.orca_452.0.0.50.109-320409634_minAPI21(armeabi-v7a)(360,400,420,480dpi)_apkmirror.com.apk same error with different versions and different tested apk e.g. youtube
Operating system: Windows 11
Path to apktool.jar: C:\Windows\apktool.jar it's 2.9.3 but I have tried also with few oldest

During the encoding process, I receive many errors regarding invalid XML file paths in the res\color.2\ directory. Here is my console:

E:\android-unpinner>apk-mitm --apktool C:\Windows\apktool.jar "Messenger_452.0.0.50.109_apkcombo.com.apk"

  ╭ apk-mitm v1.2.1
  ├ apktool custom version
  ╰ uber-apk-signer v1.2.1

  Using temporary directory:
  C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2

  √ Checking prerequisities
  √ Decoding APK file
  √ Applying patches
  > Encoding patched APK file
    ↓ Encoding using AAPT2 [skipped]
      → Failed, falling back to AAPT...
    × Encoding using AAPT [fallback]
      → I: Building resources...
    Signing patched APK file

   Failed!  An error occurred:

I: Using Apktool 2.9.3
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether sources has changed...
I: Checking whether resources has changed...
I: Building resources...
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f170009.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f17000a.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f17000c.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f17000d.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f17000e.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f17000f.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f170010.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f170011.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f170012.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f170015.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f170016.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f170088.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f170089.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f1700ce.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f1700da.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f1700e2.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f1700e9.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f1700f7.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f170102.xml'.
W: error: invalid file path 'C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res\color.2\APKTOOL_DUMMYVAL_0x7f170103.xml'.
brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\Mateusz\AppData\Local\Temp\brut_util_Jar_17906002965217958657890834285878101796.tmp, compile, --dir, C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\res, --legacy, -o, C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\decode\build\resources.zip]

  The full logs of all commands are available here:
  C:\Users\Mateusz\AppData\Local\Temp\apk-mitm-181e80259811ac06885253714312dfb2\logs

I can also provide full logs if required. Could anyone help me understand what might be causing these errors and how to fix them?

Thank you for your help.


apktool d -f -r apkfilename.apk
here -f is to replace previous decompiled apk's code and -r is to ignore the decompiling of resources.

this would prevent the resources from being decompiled and will simply copy the same resources when you recompile the apk.

However, it is not possible to set these apktool settings in mitm-app? I couldn't find it. Please help me

apktool -r d *.apk

just add -r .

-r, --no-res
This will prevent the decompile of resources. This keeps the resources.arsc intact without any decode. If only editing Java (smali) then this is the recommended action for faster decompile & rebuild

Solution to the problem:

during --wait function you should copy the files to another location, add resources.arsc to the decoded folder and enter the path to the decoded folder in place of the former path to the application.

However, I got another problem: signing the app doesn't work. Lol. Stupidity

Solution to the problem:

during --wait function you should copy the files to another location, add resources.arsc to the decoded folder and enter the path to the decoded folder in place of the former path to the application.

However, I got another problem: signing the app doesn't work. Lol. Stupidity

It's all about Apktool compatibility. I think only apktool dev can bring any changes to make it works. Check that: iBotPeaches/Apktool#3436