5

I'm trying to reverse engineer an Android app. I've tried using several decompilers, and while I'm getting java source codes to varying levels of accuracy, I'm not able to convert the resource IDs to the resource strings. In the Java source, all I'm getting is the 32bit resource ID, which is meaningless to me. Is there anyway to get the resource string from this resource ID? I did not find any R.java in any of the decompiled code.

Thanks!

2 Answers 2

5

Using apktool you can decompile a program's resources. Also you can use JEB to view the resource id.

In res/values, you can find the id using name in public.xml (or something similar, e.g. publics.xml or name.xml). That's it.

P.S.: You'll need to convert the 32bit resource id into HEX before you search for it.

12
  • why someone gives me an -1? in res/values there are many xmls. Just open them you will find all IDs.
    – Misty
    May 25, 2016 at 3:59
  • Thanks. Other than JEB, are there any other tools, preferably free, that can extract this xml file with the mapping? May 25, 2016 at 6:35
  • @user1118764 I have said that apktool could do this too.
    – Misty
    May 25, 2016 at 8:02
  • I have used apktool to get the resources, but I only see the XML files which give the string names and values, and not the mapping between the string names and the resource ID. May 25, 2016 at 8:36
  • @user1118764 there are many XML files there.Just open them. You can using calculator convert the id to HEX and then search it in those files.
    – Misty
    May 25, 2016 at 8:39
4

Yunchao Guan's answer is correct.

For example, i recently unpacked an application (zaka.com.amperemeter-1.apk, yes, it's zaka.com, not com.zaka as it shoule be) to improve the bad German translation that had been done by google translate.

Unzipping the .apk, using dex2jar on the .dex, and procyon on the resulting jar gave me, for example:

unzip/procyon/gluapps/Ampere/meter/Activity/MainActivity.java:240
    return this.getString(2131099670)

ALSO, procyon gave me an R.java that has a name for that number:

unzip/procyon/gluapps/Ampere/meter/R.java:909
    public static final int Usb_plug_type = 2131099670;

So you really should get a R.java source code from decompiling. In case you don't, apktool d zaka.com.amperemeter-1.apk gives you several files that have the same number, in hex, in smali files:

work/smali/gluapps/Ampere/meter/R$string.smali:20
   .field public static final Usb_plug_type:I = 0x7f060016
work/smali/gluapps/Ampere/meter/Activity/MainActivity.smali:477
    const v1, 0x7f060016

these are basically the same as in the decompiled java files. Additionally:

work/res/values/public.xml:473
    <public type="string" name="Usb_plug_type" id="0x7f060016" />

This is the key that maps to the actual, translated, string in the language-dependent file:

work/res/values-de/strings.xml:25
    <string name="Usb_plug_type">USB</string>

So, with a normal apk, if you use unzip/dex2jar/decompiler/apktool correctly, everthing should be there. If not, it would be best if you provided a link to the apk, because something weird might be going on with yours, but there's no way to tell unless you give us a chance to look at your specific apk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.