Android Studio通过ASM Bytecode Outline插件生成ASM插桩代码

(1)在Android Studio中安装ASM Bytecode Outline插件

(2)安装后,在Android Studio中,选中代码行,点击右键,选择Show Bytecode outLine

(3)在ASM标签中选择ASMified,即可在右侧看到当前类对应的ASM代码(可以忽略Label相关的代码)

原始代码:

Log.i("yezhou", this.getClass().getName() + ": onCreate");

相关代码:

Label l2 = new Label();
mv.visitLabel(l2);
mv.visitLineNumber(15, l2);
mv.visitLdcInsn("yezhou");
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitLdcInsn(": onCreate");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKESTATIC, "android/util/Log", "i", "(Ljava/lang/String;Ljava/lang/String;)I", false);
mv.visitInsn(POP);

有效代码:

mv.visitLdcInsn("yezhou");
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitLdcInsn(": onCreate");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
mv.visitMethodInsn(INVOKESTATIC, "android/util/Log", "i", "(Ljava/lang/String;Ljava/lang/String;)I", false);
mv.visitInsn(POP);

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/28/android-studio-generates-asm-instrumentation-code-through-the-asm-bytecode-outline-plugin/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Android Studio通过ASM Bytecode Outline插件生成ASM插桩代码
(1)在Android Studio中安装ASM Bytecode Outline插件 (2)安装后,在Android Studio中,选中代码行,点击右键,选择Show Bytecode outLine (3)在ASM标签……
<<上一篇
下一篇>>
文章目录
关闭
目 录