字节码检测生成 java 验证器错误
我使用 ASM 来为 Java 程序进行字节码检测。我所做的很简单 - 在检测方法时,如果指令是 PUTFIELD,只需在指令之前执行 DUP_X1,然后访问 PUTFIELD 并使用包含 DUP 堆栈条目的参数注入函数调用。
public void visitFieldInsn(
int opcode,
String owner, // owner of this field...
String name,
String desc) {
boolean did_dup = false;
if(opcode == Opcodes.PUTFIELD) {
if(!owner.equals("java/lang/System")) {
if (desc.startsWith("L")) {
mv.visitInsn(Opcodes.DUP_X1);
did_dup = true;
}
}
}
mv.visitFieldInsn(opcode, owner, name, desc);
if (did_dup) {
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "com/amir/ASide", "updateG", "(Ljava/lang/Object;Ljava/lang/Object;)V");
}
}
代码在检测之前和之后分别看起来像这样:
public void setA(ClassA classa)
{
refA = classa;
eyeColor = classa.eyeColor;
}
public void setA(ClassA classa)
{
ASide.updateG(refA = classa, this);
ASide.updateG(eyeColor = classa.eyeColor, this);
}
但是当我运行检测代码时,我得到:
java.lang.VerifyError: Expecting to find object/array on stack
你能提供这方面的任何帮助吗?
I am using ASM in order to do bytecode instrumentation for Java programs. What I'm doing is simple - When instrumenting a method, if the instruction is a PUTFIELD, simply do a DUP_X1 right before the instruction, then visit the PUTFIELD and inject a function call with an argument that includes the DUP'ed stack entry.
public void visitFieldInsn(
int opcode,
String owner, // owner of this field...
String name,
String desc) {
boolean did_dup = false;
if(opcode == Opcodes.PUTFIELD) {
if(!owner.equals("java/lang/System")) {
if (desc.startsWith("L")) {
mv.visitInsn(Opcodes.DUP_X1);
did_dup = true;
}
}
}
mv.visitFieldInsn(opcode, owner, name, desc);
if (did_dup) {
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "com/amir/ASide", "updateG", "(Ljava/lang/Object;Ljava/lang/Object;)V");
}
}
The code looks like this BEFORE and AFTER instrumentation, respectively :
public void setA(ClassA classa)
{
refA = classa;
eyeColor = classa.eyeColor;
}
public void setA(ClassA classa)
{
ASide.updateG(refA = classa, this);
ASide.updateG(eyeColor = classa.eyeColor, this);
}
But when I run the instrumented code, I get :
java.lang.VerifyError: Expecting to find object/array on stack
Can you offer has any help on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的仪器有一些漏洞。例如,它不会检查您是否在静态方法内,因此存在此变量。
There is some holes in your instrumentation. For instance, it doesn't check if you are inside static method, so this variable is present.