简体   繁体   中英

ByteBuddy intercept the calls toward specific class instances inside the bytecode of a method

I have a class A with a method m() and a class B with a method n(). In AI have a field b of type B. In m() there is at some point a call to bn(). I need to change the code of A with ByteBuddy in order to do some action before and after the bn() call. I need some advice/tips/hint to attack the problem.

Thanks in advance,

Radu

You can only do this in Byte Buddy by writing custom byte code using the underlying ASM API. Byte Buddy does not offer any high-level constructs to alter any code within a method.

The API is exposed by registering an AsmVisitorWrapper.

Alternatively, you could create a subclass of Bn() where you add this interception logic and set it as the field of A. This would however affect all invokations via A.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM