The Bytecode Club - Reverse Engineering Forum
matching android views xml ids to java - Printable Version

+- The Bytecode Club - Reverse Engineering Forum (https://the.bytecode.club)
+-- Forum: Lobby (https://the.bytecode.club/forumdisplay.php?fid=1)
+--- Forum: Programming (https://the.bytecode.club/forumdisplay.php?fid=86)
+--- Thread: matching android views xml ids to java (/showthread.php?tid=1610)



matching android views xml ids to java - AlexM20 - 03-10-2016

Hello, I'm new in RE. I'm searching for tools to decompile apk finding the link of android views xml ids to java code and cannot find. Are there such tools that link Android views as described in layout / xml files to findviewbyid methods in java code?

Java machine somehow does that during execution. Why I get like android:id="@id/textView1" in xlm and findviewbyid (3523423) in java in Bytecodeviewer? (I just started by use Bytecodeviewer and upon opening apk it produces such output - maybe there is some trick to match ids?).

Thanx!


RE: matching android views xml ids to java - mik01 - 03-23-2016

(03-10-2016, 08:29 PM)AlexM20 Wrote:  Why I get like android:id="@id/textView1" in xlm and findviewbyid (3523423) in java in Bytecodeviewer?

When developing an android app the buildsystem generates a class called R.java which holds all references to stuff defined in resource files (like xml files) in static members. The compiler is able to eliminate all references to the R.class by directly using static values defined in this class when building the apk. This is why you just see calls like findViewById(0x1234567Shadehappy after decompilation. The mapping between identifiers and static values gets saved in the compiled resources file resources.arsc.

I would suggest you use apktool (http://ibotpeaches.github.io/Apktool/) to get the link between identifiers and layouts. apktool is able to generate a xml file which holds the needed information from the compiled resources. You can find all identifiers in a file called public.xml in <targetapp>/res/values/public.xml after decompilation.

Just as an example: activity_layout.xml
Code:
...
<ImageView android:id="@id/oneupDrawable" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="80.0dip" android:src="@drawable/oneup" />
...

public.xml
Code:
...
<public type="drawable" name="oneup" id="0x7f020045" />
...
<public type="id" name="oneupDrawable" id="0x7f0c0053" />
...

activity.smali
Code:
const v4, 0x7f0c0053
invoke-virtual {p0, v4}, Lde/some/app/activity;->findViewById(I)Landroid/view/View;

Hope that will help you!
Regards, mik