Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(No resource found that matches the given name) decompiling / recompiling ,without any changes. #1361

Closed
roshanfekr opened this issue Nov 4, 2016 · 21 comments
Labels

Comments

@roshanfekr
Copy link

roshanfekr commented Nov 4, 2016

I decompile SHAREit_3.6.68_ww.apk then recompile it again without any changes.

download link:
SHAREit_3.6.68_ww.apk
But the following error occurs:

deompile :

F:\Temp>apktool.bat d 1-SHAREit_3.6.68_ww.apk
I: Using Apktool 2.2.1 on 1-SHAREit_3.6.68_ww.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: C:\Users\...\AppData\Local\apktool\framework\1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...

recompile :

W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gc.xml:23: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.DescriptionItemLayout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gc.xml:24: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.DescriptionItem').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gc.xml:25: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/common_horizontal_divider_middle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gc.xml:27: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.ButtonStart').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:10: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.DescriptionTitle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:11: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.DescriptionSubTitle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:15: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.DescriptionItemLayout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:16: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.DescriptionItem').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:17: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/common_horizontal_divider_middle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:19: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.DescriptionItemLayout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:20: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.DescriptionItem').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:21: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/common_horizontal_divider_middle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:23: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.DescriptionItemLayout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:24: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.DescriptionItem').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:25: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/common_horizontal_divider_middle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gc.xml:27: error: Error: No resource found that matches the given name (at 'style' with value '@style/WebShareStyle.ButtonStart').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gd.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gd.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gd.xml:6: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gd.xml:7: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gd.xml:8: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gd.xml:18: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/dialog_button_operator_layout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gd.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gd.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gd.xml:6: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gd.xml:7: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gd.xml:8: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gd.xml:18: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/dialog_button_operator_layout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\ge.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\ge.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\ge.xml:5: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\ge.xml:6: error: Error: No resource found that matches the given name (at 'style' with value '@style/ListViewStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gg.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gg.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gg.xml:5: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gg.xml:7: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gg.xml:9: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogCheckViewStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gg.xml:10: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogCheckboxStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gg.xml:11: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogCheckInfoStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gg.xml:13: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/dialog_button_operator_layout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gh.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gh.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gh.xml:5: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gh.xml:6: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gh.xml:7: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogButtonViewStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gh.xml:8: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogButtonCancelStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gh.xml:9: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogButtonOkStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gi.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gi.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gi.xml:6: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gi.xml:7: error: Error: No resource found that matches the given name (at 'style' with value '@style/AnyShareRatingBar').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gi.xml:8: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gi.xml:9: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/dialog_button_operator_layout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gi.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gi.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gi.xml:6: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gi.xml:7: error: Error: No resource found that matches the given name (at 'style' with value '@style/AnyShareRatingBar').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gi.xml:8: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gi.xml:9: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/dialog_button_operator_layout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gl.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gl.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\gl.xml:12: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/dialog_button_operator_layout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gl.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gl.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\gl.xml:12: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/dialog_button_operator_layout').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\go.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\go.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\go.xml:9: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\go.xml:11: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\go.xml:13: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogCheckViewStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\go.xml:14: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogCheckboxStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\go.xml:15: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogCheckInfoStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\go.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\go.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\go.xml:9: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\go.xml:11: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\go.xml:13: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogCheckViewStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\go.xml:14: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogCheckboxStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\go.xml:15: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogCheckInfoStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\h.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\h.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\h.xml:7: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\h.xml:11: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\h.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyleBg').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\h.xml:4: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\h.xml:7: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogTitleStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout-v17\h.xml:11: error: Error: No resource found that matches the given name (at 'style' with value '@style/DialogMessageStyle').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\t.xml:6: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/common_view_title_bar').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\v.xml:5: error: Error: No resource found that matches the given name (at 'layout' with value '@layout/common_view_title_bar').
W:
W: F:\Temp\1-SHAREit_3.6.68_ww\res\layout\z.xml:2: error: Error: No resource found that matches the given name (at 'style' with value '@style/ListItemArrow').
W:
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\...\AppData\Local\Temp\brut_util_Jar_3126203442149383352.tmp, p, --forced-package-id, 127, --min-sdk-version, 8, --target-sdk-version, 19, --version-code, 4030668, --version-name, 3.6.68_ww, -F, C:\Users\...\AppData\Local\Temp\APKTOOL8686423678487437959.tmp, -0, arsc, -0, arsc, -I, C:\Users\...\AppData\Local\apktool\framework\1.apk, -S, F:\Temp\1-SHAREit_3.6.68_ww\res, -M, F:\Temp\1-SHAREit_3.6.68_ww\AndroidManifest.xml]
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:478)
        at brut.androlib.Androlib.buildResources(Androlib.java:412)
        at brut.androlib.Androlib.build(Androlib.java:311)
        at brut.androlib.Androlib.build(Androlib.java:264)
        at brut.apktool.Main.cmdBuild(Main.java:227)
        at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\...\AppData\Local\Temp\brut_util_Jar_3126203442149383352.tmp, p, --forced-package-id, 127, --min-sdk-version, 8, --target-sdk-version, 19, --version-code, 4030668, --version-name, 3.6.68_ww, -F, C:\Users\...\AppData\Local\Temp\APKTOOL8686423678487437959.tmp, -0, arsc, -0, arsc, -I, C:\Users\...\AppData\Local\apktool\framework\1.apk, -S, F:\Temp\1-SHAREit_3.6.68_ww\res, -M, F:\Temp\1-SHAREit_3.6.68_ww\AndroidManifest.xml]
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:439)
        at brut.androlib.Androlib.buildResourcesFull(Androlib.java:464)
        ... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\...\AppData\Local\Temp\brut_util_Jar_3126203442149383352.tmp, p, --forced-package-id, 127, --min-sdk-version, 8, --target-sdk-version, 19, --version-code, 4030668, --version-name, 3.6.68_ww, -F, C:\Users\...\AppData\Local\Temp\APKTOOL8686423678487437959.tmp, -0, arsc, -0, arsc, -I, C:\Users\...\AppData\Local\apktool\framework\1.apk, -S, F:\Temp\1-SHAREit_3.6.68_ww\res, -M, F:\Temp\1-SHAREit_3.6.68_ww\AndroidManifest.xml]
        at brut.util.OS.exec(OS.java:95)
        at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:433)
        ... 6 more

Information

  1. Apktool Version (apktool -version) -2.2.1
  2. Operating System (Mac, Linux, Windows) - Windows
  3. APK From? (Playstore, ROM, Other) -

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? NO
  3. Are you using the latest apktool version? YES
@chenxinxun
Copy link

chenxinxun commented Nov 15, 2016

The same to my situation. https://play.google.com/store/apps/details?id=com.felink.clean2&hl=en
It's useless resources lead to the error??

@TJYSunset
Copy link

TJYSunset commented Nov 16, 2016

Same issue here, trying to decode & rebuild this apk.
I'm pretty sure it's not framework issue because the styles' names are obviously built-in resources.

@iBotPeaches
Copy link
Owner

This is interesting. The original application obviously had some build procedure which obfuscated resource names, looks like AndroResGuard. Every resource is alphabetical like a, b, a1, a2, etc.

So take an offending line

            <LinearLayout android:orientation="vertical" android:id="@id/qw" android:layout_marginTop="0.0dip" style="@style/DialogMessageStyle">

Now the id attribute correctly is associated with the rename resource, but the style attribute is not. It points to a source that doesn't exist.

So we can leverage aapt to dump the above file

aapt d xmltree r/f/gd.xml
        E: TextView (line=6)
          A: android:id(0x010100d0)=@0x7f0c0337
          A: android:text(0x0101014f)=@0x7f0700a6
          A: android:singleLine(0x0101015d)=(type 0x12)0xffffffff
          A: style=@0x7f0a0019 (Raw: "@style/DialogTitleStyle")

So we can see the attribute style has the ID of 0x7f0a0019 but human readable name of DialogTitleStyle

That human readable name is just copied onward, but guess what. It doesn't exist. If we follow the resource ID once again with aapt we get.

➜  Bug1361 aapt d resources SHAREit_3.6.68_ww.apk | grep '7f0a0019'
      spec resource 0x7f0a0019 com.lenovo.anyshare.gps:style/z: flags=0x40000400
        resource 0x7f0a0019 com.lenovo.anyshare.gps:style/z: <bag> (PUBLIC)
        resource 0x7f0a0019 com.lenovo.anyshare.gps:style/z: <bag> (PUBLIC)

The correct resource was style/z

    <style name="z">
        <item name="android:textSize">@dimen/l1</item>
        <item name="android:textColor">#ff191919</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginLeft">@dimen/ku</item>
        <item name="android:layout_marginTop">@dimen/l0</item>
        <item name="android:layout_marginRight">@dimen/ku</item>
    </style>

Apktool should be updated to follow resourceIds instead of human readable names in term of parent style attributes.

@Bonjur
Copy link

Bonjur commented Nov 18, 2016

when dude

@Bonjur
Copy link

Bonjur commented Nov 18, 2016

@iBotPeaches fix it please

iBotPeaches added a commit that referenced this issue Dec 2, 2016
@iBotPeaches
Copy link
Owner

So I spent a lot of time trying to understand this and just tabulating my research. Apktool currently decodes this to

<?xml version="1.0" encoding="utf-8"?>
            ...
            <TextView android:id="@id/vl" android:text="@string/ds" android:singleLine="true" style="@style/DialogTitleStyle" />
            <TextView android:id="@id/vm" android:text="@string/na" style="@style/DialogMessageStyle" />
            ...
        </LinearLayout>
    </ScrollView>
</FrameLayout>

So the style attribute has no namespace, as expected because we are referencing an internal style, not an Android one. So back to the offending line.

 A: style=@0x7f0a0019 (Raw: "@style/DialogTitleStyle")

We know the key is value, with the value - @0x7f0a0019 and literal value of - "@style/DialogTitleStyle". However, we know this is wrong as proven here.

➜  Bug1361 aapt d resources SHAREit_3.6.68_ww.apk| grep '0x7f0a0019'
      spec resource 0x7f0a0019 com.lenovo.anyshare.gps:style/z: flags=0x40000400

So our decoder is really messing up. So lets check for this old resource (DialogTitleStyle).

SHAREit_3.6.68_ww/smali/com/lenovo/anyshare/gps/R$style.smali:.field public static final DialogTitleStyle:I = 0x7f0a0019

So wow. The application has the old attribute in the smali R class. Lets check the public.xml file that we create.

SHAREit_3.6.68_ww/res/values/public.xml:    <public type="style" name="z" id="0x7f0a0019" />

Ugh same resourceId. Two different resource names. What is correct? What shouldn't be there?

No idea yet.

@fixmania
Copy link

I have a trouble with the same thing. Haven't it fixed yet?

@arudeiandeita
Copy link

arudeiandeita commented Feb 20, 2017

@iBotPeaches Dear Owner/Developer, thanks for advise the aapt method... I got it all and successfully completed recovered all strings... Of course it must be one by one, and need some critical accuration...

Tools :

You can download the build tools from here :
http://dl.google.com/android/repository/build-tools_rXX-windows.zip
Note : Replace XX with SDK Number... (Ex. r25 for Android 7.1)

@zinis
Copy link

zinis commented Oct 13, 2017

Is it fixed ???

@sin5678
Copy link

sin5678 commented Jan 17, 2018

seams not fix yet

@Gintasz
Copy link

Gintasz commented Aug 1, 2018

any solution?

@Ibuprophen
Copy link

@Gintasz, If you had checked out the following reference to this issue...

#1820

... @iBotPeaches posted something there 12 days ago because the underlying issue there is similar/same as this issue in regards to the namespace (possibly connected to the aapt as well).

What this tells me is very positive because it reflects that iBotPeaches hasn't forgotten about the issue at hand.

Just be patient... 👍

~Ibuprophen

@ljysdfz
Copy link

ljysdfz commented Nov 26, 2018

@iBotPeaches

I really appreciate all the tough work you've done, only by which we could be able to gain more insights about this issue and so many other things as to Android reverse engineering.

I've recently encountered some similar troubles in the rebuilding phase.

  1. No resource identifier found for attribute "XXX" in package "com.XXX.XXX"

  1. No resource found that matches the given name (at "XXX" with value "XXX")

As you can see, these problems are caused by custom attribute in a private namespace of a resource file.

I've found that xml attribute names or values in a private namespace will be incorrectly refered to something that is exactly a system attribute resource as guys have mentioned in historical comments.

These errors seem to be widespread as occurring in a large number of issues.

I've got digging into the source code of apktool and have tried to tweak two files relating to the xml parsing phase.

    /////////////////////////////////////////////////
    //
    // brut.androlib.res.decoder.AXmlResourceParser
    //
    /////////////////////////////////////////////////
    
    public String getAttributeName(int index) {
        int offset = getAttributeOffset(index);
        int nameIndex = m_attributes[offset + ATTRIBUTE_IX_NAME];
        if (nameIndex == -1) return "";
        String name = m_strings.getString(nameIndex);
        String namespace = getAttributeNamespace(index);
        
		// If attribute name is lacking or a private namespace emerges, 
		// retrieve the exact attribute name by its id.
        if (name == null || name.length() == 0) {
			try {
				name = mAttrDecoder
				.decodeManifestAttr(getAttributeNameResource(index));
				if (name == null) name = "";
			} catch (AndrolibException e) {name = "";}
        } else if (! namespace.equals(android_ns)) {
        	try {
				String obfuscatedName = mAttrDecoder
				.decodeManifestAttr(getAttributeNameResource(index));
				if (! (obfuscatedName == null || obfuscatedName.equals(name))) {
					name = obfuscatedName;
				}
			} catch (AndrolibException e) {}
        }
        return name;
    }

    public String getAttributeValue(int index) {
        int offset = getAttributeOffset(index);
        int valueType = m_attributes[offset + ATTRIBUTE_IX_VALUE_TYPE];
        int valueId = m_attributes[offset + ATTRIBUTE_IX_VALUE_DATA];
        int valueRaw = m_attributes[offset + ATTRIBUTE_IX_VALUE_STRING];        
        
        if (mAttrDecoder != null) {
            try {
                String value = valueRaw == -1 ? null : ResXmlEncoders
                		.escapeXmlChars(m_strings.getString(valueRaw));
                String obfuscatedValue = mAttrDecoder
                		.decodeManifestAttr(valueId);
                if (! (value == null || obfuscatedValue == null)) {
                	int slashPos = value.lastIndexOf("/");
                	
                    if (slashPos != -1) {
                    	// Handle a value with a format of "@yyy/xxx"
                    	String dir = value.substring(0, slashPos);
                        value = dir + "/"+ obfuscatedValue;
                    } else if (! value.equals(obfuscatedValue)) {
                    	value = obfuscatedValue;
                    }
                }

                return mAttrDecoder.decode(
                        valueType,
                        valueId,
                        value,
                        getAttributeNameResource(index));
            } catch (AndrolibException ex) {
                setFirstError(ex);
                LOGGER.log(Level.WARNING, String.format(
"Could not decode attr value, using undecoded value "
                                + "instead: ns=%s, name=%s, value=0x%08x",
                        getAttributePrefix(index),
                        getAttributeName(index),
                        valueId), ex);
            }
        }
        return TypedValue.coerceToString(valueType, valueId);
    }
    /////////////////////////////////////////////////
    //
    // brut.androlib.res.decoder.ResAttrDecoder
    //
    /////////////////////////////////////////////////

    public String decodeManifestAttr(int attrResId)
            throws AndrolibException {
        if (attrResId != 0) {
            int attrId = attrResId;

            // See also: brut.androlib.res.data.ResTable.getResSpec
            if (attrId >> 24 == 0) {
                ResPackage pkg =  getCurrentPackage();
                int packageId = pkg.getId();
                int pkgId = (packageId == 0 ? 2 : packageId);
                attrId = (0xFF000000 & (pkgId << 24)) | attrId;
            }

            // Retrieve the ResSpec in a package by its id
            ResID resId = new ResID(attrId);
            ResPackage pkg = getCurrentPackage();
            if (pkg.hasResSpec(resId)) {
                ResResSpec resResSpec = pkg.getResSpec(resId);
                if (resResSpec != null) {return resResSpec.getName();}
            }
        }

        return null;
    }

The basic ideas:

  1. Get the attribute id in m_attributes by offset.
  2. Invoke brut.androlib.res.decoder.ResAttrDecoder.decodeManifestAttr method in order to inquire the exact attribute value by id.
  3. Replace the invalid one in a sensible condition.

Then I utilized the modified code to re-decode the apk.

At last, it worked and rebuilt the resource folder successfully.

Rebuilt

The originally falsely-referenced attribute had been corrected into an entity which is an obfuscated name.

It's too sad to file a pull request as I've got some network troubles in cloning no matter my forked branch or even the master branch.

Forgive me that I can't publish the apk I cracked here since it's a business production which is not owned by myself.

But if @iBotPeaches you need it, tell me and I'd be pleased to mail it to you.

The whole of experience of analysis and tweaking process has been posted in my blog.

Please let me know if you guys come up with any ideas or suggests.

@drakos
Copy link

drakos commented Jan 10, 2019

@ljysdfz any chance you could share your solution so I can try rebuilding my APK? Thanks!

@ljysdfz
Copy link

ljysdfz commented Feb 1, 2019

@drakos

Sure of course.
Sorry to reply so late 'cause I've been busy with a tricky task.
Glad to help and I've packed the .jar file that I'd compiled out into an attached archive.
I've been using it for quite a while, and it really keeps in good order.
Hope it works for you or any other guys, too.

--- Info for integrity & consistency ---
Target File: apktool.jar
MD5: 69E3A620490B1907A3ACAC1902A4BD2B
SHA1: 480E4D1AC4959BFC5CE7DD11C848880F861F2970
CRC32: 3882892A

@samlss
Copy link

samlss commented Feb 21, 2019

@drakos

Sure of course.
Sorry to reply so late 'cause I've been busy with a tricky task.
Glad to help and I've packed the .jar file that I'd compiled out into an attached archive.
I've been using it for quite a while, and it really keeps in good order.
Hope it works for you or any other guys, too.

--- Info for integrity & consistency ---
Target File: apktool.jar
MD5: 69E3A620490B1907A3ACAC1902A4BD2B
SHA1: 480E4D1AC4959BFC5CE7DD11C848880F861F2970
CRC32: 3882892A

Thanks, it works for me.

@pascalcaron
Copy link

Hello @ljysdfz thanks for the patch.

Hi @iBotPeaches the patch is still on version 2.3.4. Is it possible to check and merge the changes into 2.4.0 version or maybe a new release with other fixes?

Thanks

@iBotPeaches
Copy link
Owner

Sorry for delay. Lots of changes for attribute/namespace decoding in v2.5.0.

PRs for code changes in future won't be missed as easily :)

Apk is not findable anymore.

This item was deleted

So closing as there is nothing really I can do here, trying to clean backlog.

@wuruofan
Copy link

Sorry for delay. Lots of changes for attribute/namespace decoding in v2.5.0.

PRs for code changes in future won't be missed as easily :)

Apk is not findable anymore.

This item was deleted

So closing as there is nothing really I can do here, trying to clean backlog.

I met this problem too, just using @ljysdfz 's method solve my problem!

Here is my build of apktool, just do what @ljysdfz reply.
apktool-2.5.0-dirty.zip

The target apk link is here. I just tried decode and compile back.

@MrIkso
Copy link
Contributor

MrIkso commented Dec 22, 2020

@iBotPeaches yes, fix by @ljysdfz wok fine on apk with confused resources.

@JasonBrooks1984
Copy link

@iBotPeaches fix it please

Don't be that guy, he works his ass off, seeing stupid comments like this is garbage. Great work iBotPeaches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests