Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用ASM在调用方法的位置插入try/catch块_Android_Try Catch_Java Bytecode Asm - Fatal编程技术网

Android 如何使用ASM在调用方法的位置插入try/catch块

Android 如何使用ASM在调用方法的位置插入try/catch块,android,try-catch,java-bytecode-asm,Android,Try Catch,Java Bytecode Asm,如何使用ASM在调用方法的位置插入try cache块,例如: 原始代码: public class Test { public void funA(int i) { Log.i("TAG", " + i") int n = a + 1; int r = funB(n); Log.i("result", r + ""); } p

如何使用ASM在调用方法的位置插入try cache块,例如: 原始代码:

public class Test {
    public void funA(int i) {
        Log.i("TAG", " + i")
        int n = a + 1;
        int r = funB(n);
        Log.i("result", r + "");
    }

    public int funB(int c) {
        int result = c + 2;
        return result;
    }
}
ASM处理后,预期结果为:

public class Test {
    public void funA(int i) {
        Log.i("TAG", " + i")
        int n = a + 1;
        try {
            int r = funB(n);
            Log.i("result", r + "");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    public int funB(int c) {
        int result = c + 2;
        return result;
    }
}