是否有一个用于java的反汇编程序+调试器(ala OllyDbg / SoftICE for汇编程序)? [英] Is there a disassembler + debugger for java (ala OllyDbg / SoftICE for assembler)?

查看:179
本文介绍了是否有一个用于java的反汇编程序+调试器(ala OllyDbg / SoftICE for汇编程序)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有类似于OllyDbg / SoftICE的实用程序?即执行类(从jar /类路径),并且没有源代码,可以显示中间代码的反汇编,能够逐步执行/转移/搜索引用/编辑内存中的特定中间代码/应用编辑到文件...

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

编辑:我不是在说JAD或JD或Cavaj。这些都是精细的反编译器,但是我不希望有一个反编译器的原因,最值得注意的是它们的输出是不正确的(最好是有时只是一个简单的错误)。我不是在寻找一个神奇的编译的字节到java代码 - 我想看到将要执行的实际字节。此外,我希望能够更改这些字节(就像在一个装配调试器中),希望将更改的部分写回到类文件。

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 :我知道javap存在 - 但它只有一种方式(没有任何分析)。
示例(从vmspec文档中获取的代码)
从java代码,我们使用javac来编译:

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;
}

到一个java .class文件。使用javap -c我可以得到这个输出:

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

这对反汇编部分是没有问题的(没有分析,真不错,#4是Example.i),但是我找不到其他两个工具:

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":


  1. 一个调试器,它自己(使用堆栈,内存转储等) ),允许我检查实际的代码和环境。

  2. 一种反向过程的方法 - 编辑反汇编代码并重新创建.class文件(使用编辑过的代码)。 >
  1. A debugger that goes over the instructions themselves (with stack, memory dumps, etc), allowing me to examine the actual code and environment.
  2. A way to reverse the process - edit the disassembled code and recreate the .class file (with the edited code).


推荐答案

我不认为这是一个完整的答案,但可能提供一些可行的指针:

I don't think this is really a full answer, but some pointers that may provide something workable:

(1)在查看和直接使用字节码方面,旧的 BCEL类构建工具可以是有用的(它是我知道的字节码的唯一GUI编辑器)。

(1) In terms of viewing and directly working with bytecode the old BCEL Class Construction Kit can be useful (it's the only GUI editor for bytecode I'm aware of).

(2)在调试和逐步通过字节码方面,这个Eclipse插件,它与Eclipse的调试器集成可以满足您的需求。

(2) In terms of debugging and stepping through the bytecode, this Eclipse plugin, which integrates with Eclipse's debugger may meet your needs.

我不知道任何可以组合的实用程序这些功能并允许您在执行代码时操纵字节码(至少与OllyDbg中的方法相同)。但是,Java 调试器API 应该是能够支持在运行时处理代码(尽管如此,鉴于HotSpot和JIT的性质,一般来说,我不知道是否可以在调用指令之前重写一个指令 - 当前执行的字节码操作码真的是解释器选择实现op的抽象,与反汇编的操作码实际上是发送到CPU的指令的本地代码不同)。或者,您可以查看 Java Instrumentation API ,它提供了一种在运行时重新定义字节码的方法。当然,任何各种开源字节码操作库可能是能够帮助或提供灵感。

I'm not aware of any utilities that would combine these features and allow you to manipulate bytecode while the code is being executed (at least in the same way you can in OllyDbg, etc.). However, the Java debugger API should be able to support manipulating the code at runtime (though, given the nature of HotSpot and JIT in general, I don't know if it would be possible to rewrite an instruction just before it is invoked --- the currently executing bytecode opcode is really an abstraction for how the interpreter chooses to implement the op, unlike native code where the disassembled opcode is, in fact, the instruction sent to the CPU). Alternatively, you could look into the Java Instrumentation API which provides a way to redefine byte code at runtime. And, of course, any of the various open source bytecode manipulation libraries may be able to help or provide inspiration.

当然,总是可以绕过整个JVM基础架构,只需将调试器附加到JVM进程。有关这个此问题从该问题链接的这个页面

And, of course, there is always the option of of circumventing the whole JVM infrastructure and simply attaching a debugger to the JVM process. There's some discussion of this in this question and on this page linked from that question.

然而,底线是,你似乎试图完成什么,在本地代码世界中,在Java世界中并不是常见的一种做法(使用Java的一部分原因是从所有血液细节中抽象出来)。这和字节码反编译(相对于C ++)相对琐碎的性质导致了这种类型的需求很少的情况,这种类型的工具也是这样。

The bottom line, however, is, that what you seem to be trying to accomplish, while common-place in the world of native code, is not all that common a practice in the Java world (part of the reason for using Java is abstraction from all the gory details). This, and the relatively trivial nature of byte code decompilation (compared with, say C++) has lead to a situation where this type of requirement is scarce and so is this type of tooling.

这篇关于是否有一个用于java的反汇编程序+调试器(ala OllyDbg / SoftICE for汇编程序)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆