gpt4 book ai didi

java - 使用ASM进行字节码分析

转载 作者:行者123 更新时间:2023-12-02 03:55:13 24 4
gpt4 key购买 nike

我正在评估使用 ASM 作为框架来实现一些字节码分析的可能性。到目前为止,我已经尝试了一些示例,但有一些事情我需要解决:1)我不明白如何使用 MethodVisitor 类检测方法的完整签名(完整的参数类型名称和正式名称)。

2) 如果正在分析的 .class 文件具有关联的 java 源代码,如何将字节码指令与源代码中的行号链接起来

3) 如何区分 ClassVisitor 中的实例字段和静态字段

最佳答案

1) I don't see how I can detect a method fully signature with the MethodVisitor class (full argument type names and formal names).

你不能。 ClassVisitor 收到类似的调用

public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) 

在返回 MethodVistor 之前,您需要从您感兴趣的参数中捕获信息。

如果代码是用调试信息编译的,则可以通过visitLocalVariable获取参数和局部变量名。

2) In case the .class file being analysed has the java source associated, how to link bytecode instructions with the line numbers in the source

方法中的代码将以访问标签的形式具有源信息“指令”

3) How to differentiate between instance fields and static fields in a ClassVisitor

access修饰符。使用Modifier.isStatic(access)

关于java - 使用ASM进行字节码分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35553646/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com