Convert .Java file to .Smali file

时间秒杀一切 提交于 2019-11-30 03:03:02

问题


I reverse engineered an Android application with APKTool and got .Smali files as source code output. I converted the .Smali files with an application to .Java files. I was able to succesfully edit the .Java files but now I want to convert them back to .Smali so I can recompile the application with the new .Smali files. When I just leave the .Java file there it doesn't recompile it and gives some errors. I couldn't find anything about compiling .Java to .Smali on the internet so I hope you guys could help me.

Thank you in advance,


回答1:


You can compile the java classes using a normal java compiler, and then use Android's 'dx' utility to convert the compiled .class files to a dex file. And then run baksmali on the dex file to produce the smali files.

For example, let's say you have the following code in a java file named "HelloWorld.java":

public class HelloWorld {
    public static void main(String[] args) {
         System.out.println("Hello World!");
    }
}

To convert it to smali:

javac HelloWorld.java
dx --dex --output=classes.dex HelloWorld.class
baksmali classes.dex



回答2:


Try java2smali: https://github.com/ollide/intellij-java2smali

It is an application used to convert Java to Smali.



来源:https://stackoverflow.com/questions/29051781/convert-java-file-to-smali-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!