How can I reassemble java bytecode generated by javap? [duplicate]

天大地大妈咪最大 提交于 2019-12-02 01:08:26

问题


I want to be able to edit bytecode and recompile into executable class files. I have no idea how to do this. I have tried decompiling with javap -c and -v, edit something, and change it back to my Class file, but I get an error "Error: Could not find or load main class Test.class". I would also like to generate java source from the bytecode. Any help? I want to do this myself without the use of outside programs. I want to do it myself if at all possible.


回答1:


The output from javap is not suitable input for an assembler. If you want to disassemble and reassemble Java bytecode, you will need to do one of the following:

  1. Use third-party tools with a third-party assembler format.
  2. Write your own tools that (dis)assemble a third-party assembler format.
  3. Write your own tools that use your own assembler format.

I would take a look at Soot and Krakatau, both of which have full (dis)assembling capabilities. Soot supports a handful of intermediate representations for bytecode. Krakatau, I believe, uses a representation based on the popular Jasmin (though the tool itself is written in Python).




回答2:


The java platform (as in JDK) does not offer tools to compile byte code source to class files (it doesn't even really specify an assembler syntax in the JLS).

You can use bytecode like assembler with the help of a bytecode assembler. Take a look at Jasmin: http://jasmin.sourceforge.net/ (the syntax isn't exactly the same as that output by javap though).




回答3:


Javassist (Java programming assistant) is a load-time reflective system for Java. It is a class library for editing bytecodes in Java; it enables Java programs to define a new class at runtime and to modify a class file before the JVM loads it. http://java-source.net/open-source/bytecode-libraries



来源:https://stackoverflow.com/questions/19772897/how-can-i-reassemble-java-bytecode-generated-by-javap

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