简体   繁体   中英

how to access resources (R.class) after apk to jar conversion

I have an apk file. I converted it to jar file using dex2jar tool in order to obtain a jar file. I opened the jar file with java decompiler. In the code (mainactivity.java) there is a piece of code like

ContentValues localContentValues = new ContentValues();
localContentValues.put("title", "testtesttest");
localContentValues.put("url", getApplicationContext().getString(2131034115));
localContentValues.put("bookmark", Integer.valueOf(1));
getContentResolver().insert(Browser.BOOKMARKS_URI, localContentValues);

what does this mean actually and how i obtain the actual value of getApplicationContext().getString(2131034115) with java decompiler. There is no resource file such as .xml after decompilation. R.java contains an information like

public static final class string
  {
    public static final int action_settings = 2131034114;
    public static final int app_name = 2131034112;
    public static final int baseurl = 2131034115;
    public static final int hello_world = 2131034113;
  }

what is the actual string value of baseurl?

After decompiling using APKTOOL

Go to the output folder where decompiled files are generated,

Inside that folder, Open ./res/values/public.xml file. Inside the file, you will get all the resources hex code along with their ids in string format.

Thanks.

There are two paths you might take here depending on what you want to accomplish:

The one you have already taken ie decompile the Dalvik bytecode (dex) into readable Java source. The next step is to use jd-gui . The resulting source is useful to read and understand the functionality of an app, but will likely not produce 100% usable code. In other words, you can read the source, but you can't really modify and repackage it. Note that if the source has been obfuscated with proguard, the resulting source code will be substantially more difficult to untangle.

The other major alternative is to disassemble the bytecode to smali , an assembly language designed for precisely this purpose. I've found that the easiest way to do this is with apktool . Once you've got apktool installed, you can just point it at an apk file, and you'll get back a smali file for each class contained in the application. You can read and modify the smali or even replace classes entirely by generating smali from new Java source (to do this, you could compile your .java source to .class files with javac, then convert your .class files to .dex files with Android's dx compiler, and then use baksmali (smali disassembler) to convert the .dex to .smali files, as described in this question . There might be a shortcut here). Once you're done, you can easily package the apk back up with apktool again. Note that apktool does not sign the resulting apk, so you'll need to take care of that just like any other Android application .

In short, your choices are pretty much either to decompile into Java, which is more readable but likely irreversible, or to disassemble to smali, which is harder to read but much more flexible to make changes and repackage a modified app. Which approach you choose would depend on what you're looking to achieve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM