简体   繁体   English

apk到jar转换后如何访问资源(R.class)

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

I have an apk file. 我有一个APK文件。 I converted it to jar file using dex2jar tool in order to obtain a jar file. 我使用dex2jar工具将其转换为jar文件,以获得jar文件。 I opened the jar file with java decompiler. 我用java decompiler打开了jar文件。 In the code (mainactivity.java) there is a piece of code like 在代码(mainactivity.java)中,有一段类似

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. 这实际上是什么意思,以及如何使用Java反编译器获取getApplicationContext()。getString(2131034115)的实际值。 There is no resource file such as .xml after decompilation. 反编译后,没有资源文件(如.xml)。 R.java contains an information like R.java包含类似的信息

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? baseurl的实际字符串值是多少?

After decompiling using APKTOOL 使用APKTOOL反编译后

Go to the output folder where decompiled files are generated, 转到生成反编译文件的输出文件夹,

Inside that folder, Open ./res/values/public.xml file. 在该文件夹中,打开./res/values/public.xml文件。 Inside the file, you will get all the resources hex code along with their ids in string format. 在文件内部,您将以字符串格式获取所有资源十六进制代码及其ID。

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. 您已经采取的方法,即将Dalvik字节码(dex)反编译为可读的Java源代码。 The next step is to use jd-gui . 下一步是使用jd-gui The resulting source is useful to read and understand the functionality of an app, but will likely not produce 100% usable code. 结果源对于阅读和理解应用程序的功能很有用,但可能不会产生100%的可用代码。 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. 请注意,如果源代码已被proguard混淆,则生成的源代码将更难解开。

The other major alternative is to disassemble the bytecode to smali , an assembly language designed for precisely this purpose. 另一个主要选择是将字节码反汇编为smali ,这是专门为此目的设计的一种汇编语言。 I've found that the easiest way to do this is with apktool . 我发现最简单的方法是使用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. 一旦安装了apktool,就可以将其指向一个apk文件,然后您将为应用程序中包含的每个类取回一个smali文件。 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). 您可以通过从新的Java源代码生成smali来读取和修改smali甚至完全替换类(为此,您可以使用javac将.java源代码编译为.class文件,然后使用Android的源代码将.class文件转换为.dex文件。 dx编译器,然后使用baksmali(smali反汇编程序)将.dex转换为.smali文件,如本问题所述 。此处可能有一个快捷方式)。 Once you're done, you can easily package the apk back up with apktool again. 完成后,您可以轻松地再次用apktool将apk打包打包。 Note that apktool does not sign the resulting apk, so you'll need to take care of that just like any other Android application . 请注意,apktool不会对生成的apk进行签名,因此您需要对待其他任何Android应用程序一样进行处理

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. 简而言之,您的选择要么是反编译为更易读但很可能不可逆的Java,要么是反汇编为smali(难于阅读,但更灵活地进行更改和重新打包已修改的应用)。 Which approach you choose would depend on what you're looking to achieve. 您选择哪种方法取决于您要实现的目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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