简体   繁体   English

从apk反编译jar文件,编辑Java代码单个变量,然后重新编译为类和jar

[英]Decompile jar file from apk, edit java code single variable, and recompile into class and into jar

There is an old android apk file which is no longer supported by the manufacturer. 制造商不再支持旧的android apk文件。

I figured out what could be wrong it is because it is calling a method from java: 我发现这可能是错误的,因为它正在从Java调用方法:

In one of the java files (viewed after dex2jar and viewing with jd-gui) 在其中一个Java文件中(在dex2jar之后查看,并使用jd-gui查看)

import com.htc.buletoothconfirm; 导入com.htc.buletoothconfirm;

All I want to do is to change that to 我要做的就是将其更改为

import com.htc.bluetoothconfirm; 导入com.htc.bluetoothconfirm;

Then recompile it into a .class file . 然后将其重新编译.class文件 Then reinsert that .class file into a .jar file. 然后将该.class文件 重新插入 .jar文件。 Then I will rebuild the .apk file. 然后,我将重建 .apk文件。

The thing is I can't change anything with jd-gui. 问题是我无法使用jd-gui进行任何更改。

If I try to compile a single .java file with javac, it will give me import errors (there are a lot of imports in the file). 如果我尝试用javac编译单个.java文件,它将给我导入错误(文件中有很多导入)。

I have tried using jad to decompile the class file, and this is what I'm working with. 我尝试使用jad反编译类文件,这就是我正在使用的。

Although it gave a lot of "cannot fully decompile" errors. 尽管它给出了很多“无法完全反编译”的错误。

What I think I want to do is just copy & paste the entire java file content from jd-gui into notepad, save it as .java, then compile it into .class, and reinsert it into the .jar file. 我想做的就是将jd-gui中的整个java文件内容复制并粘贴到记事本中,另存为.java,然后将其编译为.class,然后将其重新插入.jar文件中。

But its easier said than done. 但是说起来容易做起来难。 I don't know how to compile this new .java file into a .class file, because of all the imports. 由于所有导入,我不知道如何将这个新的.java文件编译成.class文件。 (eg. where do I get import android.content.intent; etc? and do i really need to keep the directory structures and so on?) (例如,我在哪里导入android.content.intent;等等?我真的需要保留目录结构等等吗?)

Is there an easier way? 有更容易的方法吗? I am just trying to change a single line. 我只是想更改一行。 All the rest can be kept the same. 其余所有内容都可以保持不变。

You should decompile apk file with some tools like ASM-Android , or Dedexer . 您应该使用ASM-AndroidDedexer之类的工具反编译apk文件。 If you want to generate a class, you could generate on-device using sdcard and then create a dex. 如果要生成类,则可以使用sdcard在设备上生成,然后创建一个dex。 file and its corresponding .jar. 文件及其对应的.jar。 I used BCEL and ASM to generate Bytecode on-device. 我使用BCEL和ASM在设备上生成字节码。

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

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