简体   繁体   English

任何高级字节码编辑器?

[英]Any high-level byte-code editor?

Suppose I have a the following in Scala 假设我在Scala中有以下内容

object Foo {
  var functions: List[String => String] = Nil // can be any type to any type.
  def addFunc(f:String => String) = functions = f :: functions
}

At runtime, I am given Foo with some functions added. 在运行时,为Foo添加了一些功能。 I now want to construct a new .class file implementing something like following in Scala: 我现在想构造一个新的.class文件,该文件在Scala中实现如下所示:

object MyObject { 
  def process1(s:String) = // call Foo.functions(1)
}

I then want to save MyObject in bytecode that can be executed later on even when Foo is not there. 然后,我想将MyObject保存为字节码,即使Foo不存在,该字节码也可以在以后执行。

The above is just an example to show what I want to do . 上面只是一个例子,展示了我想做的。 I am given the names MyObject , process1 , and I have to generate an executable file MyObject.class . 我被命名为MyObjectprocess1 ,并且我必须生成一个可执行文件MyObject.class The source of MyObject is not needed (it could well have been Java source). MyObject的源不是必需的(它很可能是Java源)。

So, at a high level, we need to take memory "snapshot" of Foo.function(1) , convert that snapshot into bytecode to store, and generate bytecode of MyObject using this. 因此,在较高级别上,我们需要获取Foo.function(1)内存“快照”,将该快照转换为字节码进行存储,并使用此快照生成MyObject字节码。

All the bytecode engineering libraries I found are too low-level, so I was wondering if there is a higher level library that lets me deal with abstract objects such as functions etc. 我发现的所有字节码工程库都太低级了,所以我想知道是否有一个更高级别的库可以让我处理诸如函数等的抽象对象。

Have you looked at the Tree model of ASM ? 您是否看过ASM的Tree模型? I've only used the Event model before, but the Tree sounds like just what you're looking for. 我以前只使用过Event模型,但是Tree听起来就像您要找的东西一样。 You'll find an overview in section 1.2.2 of the ASM user guide (a PDF--I don't think there's an HTML version, or I'd link that). 您可以在ASM用户指南的 1.2.2节中找到概述(PDF-我认为没有HTML版本,或者我链接了该版本)。

I will also recommend ASM framework. 我还将推荐ASM框架。 There is a paper from AOSD'07 about implementing common bytecode transformation patterns with ASM. AOSD'07上有一篇关于使用ASM实现常见字节码转换模式的论文。 Sections "Merging Two Classes into One" and "Inline Method" describing bytecode transformations very close to yours. “将两个类合并为一个”和“内联方法”两节描述了非常接近您的字节码转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM