在Java字节码中获取堆栈操作数的arrayref

时间:2022-12-22 17:20:57

I work with ASM API for Java bytecode instrumantation, and I'd like to be able to determine which array is accessed (by the array's name) in each access to any array.

我使用ASM API进行Java字节码指令,我希望能够在每次访问任何数组时确定访问哪个数组(通过数组名称)。

I have two problems with it: - let's take for example the iastore instrution. the arrayref is placed in the operand stack under two other variables - value and index. How do I get the arrayref without ruining the stack (I can't duplicate more than two top variables in the stack)? I thought of pop index and value from the stack and save them somewhere and then to get the arrayref and finally push index and value back to the stack but I don't really know how to do this...

我有两个问题: - 让我们以iastore指令为例。 arrayref被置于操作数堆栈中的另外两个变量 - 值和索引。如何在不破坏堆栈的情况下获取arrayref(我不能在堆栈中复制两个以上的*变量)?我想到了堆栈中的pop索引和值并将它们保存在某处然后获取arrayref并最终将索引和值推回堆栈但我真的不知道如何执行此操作...

  • I would like to get from the arrayref (once I have it) the name of the array (the name that the user declared that array called it).
  • 我想从arrayref(一旦我拥有它)获取数组的名称(用户声明该数组称为它的名称)。

thanks in advance.

提前致谢。

1 个解决方案

#1


0  

dup2_x1, pop2, dup_x2 and you now have arrayref at the top of the stack. But in general it's simpler to use local variables and the end result after JIT should be no different.

dup2_x1,pop2,dup_x2,你现在在堆栈的顶部有arrayref。但总的来说,使用局部变量更简单,JIT之后的最终结果应该没有什么不同。

As others commented, your 2nd part of the question doesn't make much sense. Objects aren't necessary in variables, and you can allocate and use an array without ever storing it into any variable.

正如其他人评论的那样,问题的第二部分没有多大意义。变量中不需要对象,您可以分配和使用数组,而无需将其存储到任何变量中。

But I suspect your intent is to track access like x[0]=1 and attribute that to x, and that can be achieved by the dataflow analysis. You'll track aload and where those values are used, and if your arrayref turns out to be straight from aload, you know that array came from a variable.

但我怀疑你的意图是跟踪x [0] = 1之类的访问并将其归因于x,这可以通过数据流分析来实现。你将跟踪aload以及这些值的使用位置,如果你的arrayref直接来自aload,你知道该数组来自一个变量。

#1


0  

dup2_x1, pop2, dup_x2 and you now have arrayref at the top of the stack. But in general it's simpler to use local variables and the end result after JIT should be no different.

dup2_x1,pop2,dup_x2,你现在在堆栈的顶部有arrayref。但总的来说,使用局部变量更简单,JIT之后的最终结果应该没有什么不同。

As others commented, your 2nd part of the question doesn't make much sense. Objects aren't necessary in variables, and you can allocate and use an array without ever storing it into any variable.

正如其他人评论的那样,问题的第二部分没有多大意义。变量中不需要对象,您可以分配和使用数组,而无需将其存储到任何变量中。

But I suspect your intent is to track access like x[0]=1 and attribute that to x, and that can be achieved by the dataflow analysis. You'll track aload and where those values are used, and if your arrayref turns out to be straight from aload, you know that array came from a variable.

但我怀疑你的意图是跟踪x [0] = 1之类的访问并将其归因于x,这可以通过数据流分析来实现。你将跟踪aload以及这些值的使用位置,如果你的arrayref直接来自aload,你知道该数组来自一个变量。