In Java,source code is compiled into bytecode which is actually Class file. Is it possible that we can view bytecode of Class file? If it possible, Can we edit it?
Is there any eclipse plugin available?
-Abhishek Jain
In Java,source code is compiled into bytecode which is actually Class file. Is it possible that we can view bytecode of Class file? If it possible, Can we edit it?
Is there any eclipse plugin available?
-Abhishek Jain
The JDK comes with javap which is a tool to disassemble the byte code inside a class file. Editing on byte code level is possible. Have a look at BCEL, a java library designed to read, manipulate and write class files.
A list of tool and libraries to edit byte code can be found on java-net. For example JBE, a Java Byte Code editor that even comes with a GUI.
To my experience, jclasslib is one of the best bytecode viewers.
As for editors, there are two types: bytecode manipulation libraries, and editors with GUIs. This question has been asked few times on SO, you could check the answers and the links that were provided.
Just be careful that editing bytecode in not as straightforward as you think. The JVMS imposes many restrictions on how class files should be, and there is a great chance that one of your edit will violate one of them.
Check these other questions:
Editing a .class file directly, playing around with opcodes
To view the bytecodes
Forget javap! The best plugin I have ever used is the "ASM - Bytecode Outline plugin for Eclipse"
http://asm.ow2.org/eclipse/index.html
It is from ASM (a bytecode manipulation framework).
It shows the bytecodes (that you asked for), stack elements (jvm style), and how to generate the same result (to produce the same bytecodes) using the asm framework methods.
Better still is the fact that it does so while you have the source code selected. You don't have to find the .class file in the bin directory to inspect it's bytecode.
To edit them
Using code:
By hand: JBE