给定以下方法:
public static boolean check(String name){
return true;
}
我想添加一个 if 指令,returns true
仅当名称等于 bcel 时,即:
public static boolean check(String name){
if(name.equals("bcel"))
return true;
return false;
}
我知道我应该使用IFEQ
,IRETURN
和ICONST_0
.. 但我不知道确切的语法。
这是我试图完成的方法的一部分:
for (h=il.getStart(); h!=il.getEnd();h=h.getNext()) // il: InstructionList, h: InstructionHandle
{
Instruction inst = h.getInstruction();
il.insert(h,InstructionFactory.ICONST_0);
il.insert(h,InstructionFactory.IRETURN);
..
..
try{
h=h.getNext();
}
catch(Exception e){}}
请帮忙。
附加信息:
第一个代码的字节码:
iconst_1
ireturn
第二个代码的 BYTECODE:
aload_0
ldc #2<bcel>
invokevirtual #3<java/lang/Sting/equals(<java/lang/object;)z>
ifeq 11 (+5)
iconst_1
ireturn
iconst_0
ireturn