如何更改asm中的返回值?

问题描述

由于某种原因,我需要在asm中更改返回值。

原始代码

    public int getIndex() {
    index = 10;
    Log.e("lmf","getIndex>>>>>>>>>>>>>begin");
    Log.e("lmf","getIndex>>>>>>>>>>>>>" + index);
    Log.e("lmf","getIndex>>>>>>>>>>>>>end");


    return index;
}

所以我写了这个注入代码

    @Override
public void visitInsn(int opcode) {
    System.out.println(">>>>>>>opcode>>>>"+opcode);
    if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) {
        mv.visitvarInsn(Opcodes.ALOAD,0);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC,"com/didi/global/Mocklocation/TargetLocationHelper","fakeTarget","(Lcom/didi/global/Mocklocation/TargetLocation;)V",false);

    }
    super.visitInsn(opcode);

}

然后我得到了

    public int getIndex() {
    this.index = 10;
    Log.e("lmf","getIndex>>>>>>>>>>>>>" + this.index);
    Log.e("lmf","getIndex>>>>>>>>>>>>>end");
    
    //I don't kNow,why this code appears. Because this I can't change the return value.
    int var10000 = this.index;

    //this is My inject code
    TargetLocationHelper.fakeTarget(this);

    return var10000;
}

如何避免int var10000 = this.index;出现?为何出现此代码

最后,如何更改asm中的返回值?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)