iBotPeaches / Apktool

A tool for reverse engineering Android apk files
https://apktool.org/
Apache License 2.0
20.23k stars 3.59k forks source link

[BUG] error: failed processing manifest. #3401

Closed auermich93 closed 1 year ago

auermich93 commented 1 year ago

Information

  1. Apktool Version (apktool -version) - 2.9.0
  2. Operating System (Mac, Linux, Windows) - Windows, Linux
  3. APK From? (Playstore, ROM, Other) - FDroid
  4. Java Version (java --version) - 15.0.2

Steps to Reproduce

$ apktool empty-framework-dir --force
I: Removing 1.apk framework file...

$ apktool d org.totschnig.myexpenses.apk -f -s
I: Using Apktool 2.9.0 on org.totschnig.myexpenses.apk
I: Loading resource table...
I: Decoding Shared Library (org.totschnig.myexpenses.webdav), pkgId: 123
I: Decoding Shared Library (org.totschnig.myexpenses.webdav), pkgId: 123
I: Decoding Shared Library (org.totschnig.myexpenses.ocr), pkgId: 126
I: Decoding Shared Library (org.totschnig.myexpenses.webdav), pkgId: 123
I: Decoding Shared Library (org.totschnig.myexpenses.ocr), pkgId: 126
I: Decoding file-resources...
I: Loading resource table from file: C:\Users\Michael\AppData\Local\apktool\framework\1.apk
I: Decoding values */* XMLs...
I: Decoding AndroidManifest.xml with resources...
W: Could not decode attr value, using undecoded value instead: ns=android, name=resource, value=0x7b040000
I: Regular manifest package...
I: Copying raw classes.dex file...
I: Copying raw classes2.dex file...
I: Copying raw classes3.dex file...
I: Copying raw classes4.dex file...
I: Copying raw classes5.dex file...
I: Copying raw classes6.dex file...
I: Copying raw classes7.dex file...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
I: Copying META-INF/services directory

$ apktool b
I: Using Apktool 2.9.0
I: Copying . classes.dex file...
I: Copying . classes2.dex file...
I: Copying . classes3.dex file...
I: Copying . classes4.dex file...
I: Copying . classes5.dex file...
I: Copying . classes6.dex file...
I: Copying . classes7.dex file...
I: Checking whether resources has changed...
I: Building resources...
W: C:\Users\Michael\git\mate-commander\org.totschnig.myexpenses\.\AndroidManifest.xml:250: error: '@2063859712' is incompatible with attribute resource (attr) reference.
W: error: failed processing manifest.
brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\Michael\AppData\Local\Temp\brut_util_Jar_92592725363662429924576015148392665503.tmp, link, -o, C:\Users\Michael\AppData\Local\Temp\APKTOOL16276545612821932593.tmp, --package-id, 127, --min-sdk-version, 21, --target-sdk-version, 31, --version-code, 556, --version-name, 3.4.5.2, --no-auto-version, --no-version-vectors, --no-version-transitions, --no-resource-deduping, --allow-reserved-package-id, --no-compile-sdk-metadata, -e, C:\Users\Michael\AppData\Local\Temp\APKTOOL912369806815818289.tmp, -0, arsc, -I, C:\Users\Michael\AppData\Local\apktool\framework\1.apk, --manifest, C:\Users\Michael\git\mate-commander\org.totschnig.myexpenses\.\AndroidManifest.xml, C:\Users\Michael\git\mate-commander\org.totschnig.myexpenses\.\build\resources.zip]

$ apktool empty-framework-dir --force
I: Removing 1.apk framework file...

$ java -jar ~/scripts/apktool_2.7.0.jar d org.totschnig.myexpenses.apk -f
I: Using Apktool 2.7.0 on org.totschnig.myexpenses.apk
I: Loading resource table...
I: Decoding Shared Library (org.totschnig.myexpenses.webdav), pkgId: 123
I: Decoding Shared Library (org.totschnig.myexpenses.webdav), pkgId: 123
I: Decoding Shared Library (org.totschnig.myexpenses.ocr), pkgId: 126
I: Decoding Shared Library (org.totschnig.myexpenses.webdav), pkgId: 123
I: Decoding Shared Library (org.totschnig.myexpenses.ocr), pkgId: 126
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: C:\Users\Michael\AppData\Local\apktool\framework\1.apk
W: Could not decode attr value, using undecoded value instead: ns=android, name=value, value=0x7b040000
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Baksmaling classes2.dex...
I: Baksmaling classes3.dex...
I: Baksmaling classes4.dex...
I: Baksmaling classes5.dex...
I: Baksmaling classes6.dex...
I: Baksmaling classes7.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
I: Copying META-INF/services directory

$ java -jar ~/scripts/apktool_2.7.0.jar b --use-aapt2
I: Using Apktool 2.7.0
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes2 folder into classes2.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes3 folder into classes3.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes4 folder into classes4.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes5 folder into classes5.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes6 folder into classes6.dex...
I: Checking whether sources has changed...
I: Smaling smali_classes7 folder into classes7.dex...
I: Checking whether resources has changed...
I: Building resources...
I: Copying libs... (/kotlin)
I: Copying libs... (/META-INF/services)
I: Building apk file...
I: Copying unknown files/dir...
I: Built apk into: .\dist\org.totschnig.myexpenses.apk

Frameworks

If this APK is from an OEM ROM (Samsung, HTC, LG). Please attach framework files (.apks that live in /system/framework or /system/priv-app)

APK

If this APK can be freely shared, please upload/attach a link to it. https://f-droid.org/de/packages/org.totschnig.myexpenses/

Questions to ask before submission

  1. Have you tried apktool d, apktool b without changing anything? YES
  2. If you are trying to install a modified apk, did you resign it? YES
  3. Are you using the latest apktool version? YES

You can re-assemble the APK using apktool 2.9.0 as long as you decoded it with apktool 2.7.0. The latest version seems to struggle with this entry: <meta-data android:name="com.android.vending.splits" android:value="@2063859712"/> Side note: The app remains functional when being re-assembled with apktool 2.7.0.

iBotPeaches commented 1 year ago

Do you have an older framework by chance?

➜  3401 apktool d F-Droid.apk -f -s
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
I: Using Apktool v2.9.0-8-34a69708-SNAPSHOT on F-Droid.apk
I: Loading resource table...
I: Decoding file-resources...
I: Loading resource table from file: /home/ibotpeaches/.local/share/apktool/framework/1.apk
I: Decoding values */* XMLs...
I: Decoding AndroidManifest.xml with resources...
I: Regular manifest package...
I: Copying raw classes.dex file...
I: Copying raw classes2.dex file...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
I: Copying META-INF/services directory
➜  3401 apktool b F-Droid
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
I: Using Apktool v2.9.0-8-34a69708-SNAPSHOT
I: Copying F-Droid classes.dex file...
I: Copying F-Droid classes2.dex file...
I: Checking whether resources has changed...
I: Building resources...
I: Copying libs... (/kotlin)
I: Copying libs... (/META-INF/services)
I: Building apk file...
I: Copying unknown files/dir...
I: Built apk into: F-Droid/dist/F-Droid.apk
➜  3401 

Perhaps what I need to build is detection of the internal framework in use to detect when one doesn't match the internal one we use.

iBotPeaches commented 1 year ago

Guess I missed that you did clear your framework, but so did I and I don't replicate. I don't even have the shared frameworks, so not sure what is going on here.

I confirmed I downloaded the file you listed. Closing as not replicating.

auermich93 commented 1 year ago

@iBotPeaches I am pretty sure you downloaded the 'FDroid' application itself not the app I supposed to, the correct link is a few lines below. Here is the direct download link to the latest version that still exposes the same behaviour: https://f-droid.org/repo/org.totschnig.myexpenses_655.apk Sorry for the inconvenience!

iBotPeaches commented 1 year ago

Okay now I see - this is an existing issue we have. The resource is not on 0x7F which we expect for all internal/private resources. This is because it points to a split.

I imagine when the manifest is being parsed on device - the split is there to resolve. I wrote about this in detail in this ticket: https://github.com/iBotPeaches/Apktool/issues/2514#issuecomment-787460352

Its the same root cause - we'll have adjust parser to support many packages to read and reference.

➜  3401 aapt2 d resources org.totschnig.myexpenses_655.apk| grep -i '79040000'
    resource 0x79040000 xml/splits0

However, since this example is much easier to investigate than the other issue (Twitter). I've copied this application into my folder for issue 2514.

So I'll close for that ticket, but I'm using this APK for it.

auermich93 commented 1 year ago

But why apktool 2.7.0 succeeds?

iBotPeaches commented 1 year ago

image

Something odd with the android:value vs android:resource. Unsure how that would have changed at the moment. I'll take another look.

iBotPeaches commented 1 year ago

Looks like Apktool is correct now (in my eyes) now. We corrected attribute resolution (https://github.com/iBotPeaches/Apktool/pull/3123/files) to prefer the res map over the string block, which lead to the resource/value mismatch.

Now that is correct (resource) that property is more strict and since we generated an invalid reference it failed. Prior as value it was treated as the scalar it was.

So it does look like my original comment was right - a duplicate now of an existing issue #2514