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!

user1118764
  • 359
  • 1
  • 5
  • 9

2 Answers2

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.

FloatingRock
  • 103
  • 4
Misty
  • 428
  • 2
  • 9
  • why someone gives me an -1? in res/values there are many xmls. Just open them you will find all IDs. – Misty May 25 '16 at 03:59
  • Thanks. Other than JEB, are there any other tools, preferably free, that can extract this xml file with the mapping? – user1118764 May 25 '16 at 06:35
  • @user1118764 I have said that apktool could do this too. – Misty May 25 '16 at 08: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. – user1118764 May 25 '16 at 08: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 '16 at 08:39
  • Nope, I didn't see any XML file that had any hex numbers in them. – user1118764 May 25 '16 at 09:22
  • @user1118764 Umm, is there anything starts with 0x – Misty May 25 '16 at 09:23
  • No, I see a bunch of values- directories, and in each of them, there's only string.xml which is the string name/value XML file I was talking about. I also see the actual resources such as images in the various drawable directories, but no mapping resource IDs to the view/string/value names. – user1118764 May 25 '16 at 10:11
  • @user1118764 have you read my answer carefully? those are for other languages. There is a folder just called "values" in it there will be at least 5 XML files. That file will be there. – Misty May 25 '16 at 10:28
  • Awesome. That worked. – user1118764 May 26 '16 at 13:10
  • Having public.xml and R.java, is there any automated way to replace 32 bit IDs all over the code with their "R.." equivalent? Manually doing that is very tedious! thanks – Saleh Jan 27 '20 at 20:20
  • @Saleh Hi Saleh. I think you can use some more advanced android decompiling tool like JEB, JADX. Some of them can automatically parses the resource id and symbolize them :) – Misty Jan 30 '20 at 22:02
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.

Guntram Blohm
  • 12,950
  • 2
  • 22
  • 32