Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 332
tycoon177 Avatar asked Feb 15 '23 19:02

tycoon177


1 Answers

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).

like image 171
Mike Strobel Avatar answered Feb 17 '23 09:02

Mike Strobel