Is there a utility similar to OllyDbg / SoftICE for java? I.e. execute class (from jar / with class path) and, without source code, show the disassembly of the intermediate code with ability to step through / step over / search for references / edit specific intermediate code in memory / apply edit to file...
If not, is it even possible to write something like this (assuming we're willing to live without hotspot for the debug duration)?
Edit: I'm not talking about JAD or JD or Cavaj. These are fine decompilers, but I don't want a decompiler for several reasons, most notable is that their output is incorrect (at best, sometimes just plain wrong). I'm not looking for a magical "compiled bytes to java code" - I want to see the actual bytes that are about to be executed. Also, I'd like the ability to change those bytes (just like in an assembly debugger) and, hopefully, write the changed part back to the class file.
Edit2: I know javap exists - but it does only one way (and without any sort of analysis).
Example (code taken from the vmspec documentation):
From java code, we use "javac" to compile this:
void setIt(int value) {
i = value;
}
int getIt() {
return i;
}
to a java .class file. Using javap -c I can get this output:
Method void setIt(int)
0 aload_0
1 iload_1
2 putfield #4
5 return
Method int getIt()
0 aload_0
1 getfield #4
4 ireturn
This is OK for the disassembly part (not really good without analysis - "field #4 is Example.i"), but I can't find the two other "tools":
- A debugger that goes over the instructions themselves (with stack, memory dumps, etc), allowing me to examine the actual code and environment.
- A way to reverse the process - edit the disassembled code and recreate the .class file (with the edited code).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…