iBotPeaches / Apktool

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

Miui 7 some apk's can't be decompiled, recompiled #1178

Closed kolbi077 closed 3 years ago

kolbi077 commented 8 years ago

The mistake generally it, how are you the decompile does not succeed. I tried apktool 2.0.3 and .2.1.0 snapsot the result same thing.

Installed apk's for framework:

apk decompile examle:

Settings.apk

d:\test>apktool d -s Settings.apk
I: Using Apktool 2.1.0-57a8eb-SNAPSHOT on Settings.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: C:\Users\Martin\apktool\framework\1.apk
I: Loading resource table from file: C:\Users\Martin\apktool\framework\16.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Loading resource table from file: C:\Users\Martin\apktool\framework\17.apk
I: Decoding Shared Library (miui), pkgId: 16
W: Could not decode attr value, using undecoded value instead: ns=android, name=
textColor, value=0x0106012d
W: Could not decode attr value, using undecoded value instead: ns=android, name=
textColor, value=0x0106012d
W: Could not decode attr value, using undecoded value instead: ns=android, name=
textColor, value=0x0106012d
W: Could not decode attr value, using undecoded value instead: ns=android, name=
summary, value=0x01040698
W: Could not decode attr value, using undecoded value instead: ns=android, name=
textColor, value=0x0106012d
I: Decoding values */* XMLs...
Exception in thread "main" brut.androlib.err.UndefinedResObject: resource spec:
0x01010501
        at brut.androlib.res.data.ResPackage.getResSpec(ResPackage.java:59)
        at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:66)
        at brut.androlib.res.data.ResTable.getResSpec(ResTable.java:62)
        at brut.androlib.res.data.value.ResReferenceValue.getReferent(ResReferen
ceValue.java:57)
        at brut.androlib.res.data.value.ResStyleValue.serializeToResValuesXml(Re
sStyleValue.java:54)
        at brut.androlib.res.AndrolibResources.generateValuesFile(AndrolibResour
ces.java:507)
        at brut.androlib.res.AndrolibResources.decode(AndrolibResources.java:261
)
        at brut.androlib.Androlib.decodeResourcesFull(Androlib.java:128)
        at brut.androlib.ApkDecoder.decode(ApkDecoder.java:106)
        at brut.apktool.Main.cmdDecode(Main.java:163)
        at brut.apktool.Main.main(Main.java:81)

d:\test>

MiuiCamera.apk decompile ok but the recompile fail:

Decompile:

d:\test>apktool d -s MiuiCamera.apk
I: Using Apktool 2.1.0-57a8eb-SNAPSHOT on MiuiCamera.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: C:\Users\Martin\apktool\framework\1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Loading resource table from file: C:\Users\Martin\apktool\framework\16.apk
I: Copying raw classes.dex file...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...

d:\test>

Recompile:

Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.Androl
ibException: brut.common.BrutException: could not exec (exit code = 1): [C:\User
s\Martin\AppData\Local\Temp\brut_util_Jar_7090668814826040442.tmp, p, --forced-
package-id, 7, --min-sdk-version, 16, --target-sdk-version, 19, --version-code,
1, --version-name, 1, -F, C:\Users\Martin\AppData\Local\Temp\APKTOOL16237399698
20867296.tmp, -x, -0, dex, -0, arsc, -0, xml, -0, graph, -0, arsc, -I, C:\Users\
Martin\apktool\framework\1.apk, -I, C:\Users\Martin\apktool\framework\16.apk, -S
, d:\test\MiuiCamera\res, -M, d:\test\MiuiCamera\AndroidManifest.xml]
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:433)
        at brut.androlib.Androlib.buildResources(Androlib.java:371)
        at brut.androlib.Androlib.build(Androlib.java:281)
        at brut.androlib.Androlib.build(Androlib.java:254)
        at brut.apktool.Main.cmdBuild(Main.java:224)
        at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not
 exec (exit code = 1): [C:\Users\Martin\AppData\Local\Temp\brut_util_Jar_709066
8814826040442.tmp, p, --forced-package-id, 7, --min-sdk-version, 16, --target-sd
k-version, 19, --version-code, 1, --version-name, 1, -F, C:\Users\Martin\AppDat
a\Local\Temp\APKTOOL1623739969820867296.tmp, -x, -0, dex, -0, arsc, -0, xml, -0,
 graph, -0, arsc, -I, C:\Users\Martin\apktool\framework\1.apk, -I, C:\Users\Martin\apktool\framework\16.apk, -S, d:\test\MiuiCamera\res, -M, d:\test\MiuiCamera\
AndroidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:430)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:419)
        ... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\
Martin\AppData\Local\Temp\brut_util_Jar_7090668814826040442.tmp, p, --forced-pa
ckage-id, 7, --min-sdk-version, 16, --target-sdk-version, 19, --version-code, 1,
 --version-name, 1, -F, C:\Users\Martin\AppData\Local\Temp\APKTOOL1623739969820
867296.tmp, -x, -0, dex, -0, arsc, -0, xml, -0, graph, -0, arsc, -I, C:\Users\Martin\apktool\framework\1.apk, -I, C:\Users\Martin\apktool\framework\16.apk, -S,
d:\test\MiuiCamera\res, -M, d:\test\MiuiCamera\AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:95)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.jav
a:424)
        ... 6 more

[> Please Help.

Thank's.](url)

iBotPeaches commented 8 years ago

@ingbrzy Do you have these errors with MIUI 7 apks?

kolbi077 commented 8 years ago

I uploaded the files. miui7.zip

ingbrzy commented 8 years ago

@iBotPeaches we are not using your aapt....

iBotPeaches commented 8 years ago

Thanks @ingbrzy

Yep, not supporting MIUI. Sorry @kolbi077

peter23 commented 7 years ago

I made some investigation about this problem and I hope my information will be useful. It is related to MIUI (both 7 and 8) based on Android 5.*. There are several related things:

Latest version of apktool (starting from https://github.com/iBotPeaches/Apktool/commit/c1cb9425d5f217beb273dee5a7cea7b0c9aa9b28) just ignores such references. And maybe the next version will show messages about them (using https://github.com/iBotPeaches/Apktool/pull/1413).

Also for my needs I made a patch to aapt from Android 5 which allows to build apps with ID != 1 and != 127: http://pastebin.com/iUbDCExN @iBotPeaches, is it useful if I'll make more clean solution? For example add option to aapt like "--allow-packages-with-any-id". And add the same option to apktool, which will just translate it to aapt.

If someone can read in Russian then you can also see my posts on 4pda.ru/forum/: http://4pda.ru/forum/index.php?showtopic=557858&view=findpost&p=51479597 http://4pda.ru/forum/index.php?showtopic=557858&view=findpost&p=51491728 http://4pda.ru/forum/index.php?showtopic=557858&view=findpost&p=51497921


In addition I checked xiaomi.eu firmwares for Redmi 3S (Android 6) and Mi5 (Android 7):

Also:

iBotPeaches commented 3 years ago

Closing because MIUI and aapt2 is out really changing the entire resource game. 3+ years without a response. This isn't going anywhere.