Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
大家好,我要获取同步块参数,比如
String obj; synchronized(obj){ ... }
如何使用 Javassist 在字节码级别获取参数“obj”?欢迎任何建议。
您将不得不使用 Javassist 或 ASM 的低级 API 来分析字节码指令以执行您想要的操作。
Object obj; synchronized(obj){ //... }
翻译成
0: aload_0 1: getfield #2; //Field obj:Ljava/lang/Object; 4: dup 5: astore_1 6: monitorenter ...
monitorenter指令是同步块的开始,而 astore_1 指令就在此之前将 obj 字段值放在堆栈顶部 - 这就是您要查找的值。