简体   繁体   中英

How to change bytecode with Byte Buddy?

I load a bytecode of class file into a byte array.

I want to change to change with Byte Buddy in order to add the profiler inteceptor.

I google out mang examples. But the examples are rebase(aClass) , redefine(aClass) or subclass(aClass) . No one is parse the bytecode.

The agent builder is near by my idea. But it is used in the agent. I want to use it in the ClassLoader .

BTW: I can change the bytecode with ASM.

You can use a ClassFileLocator in combination with a TypePool to create a type description that you can provide to Byte Buddy.

The type pool will query the class file locator for other classes that are linked by the instrumented class if this is necessary. Therefore, you cannot provide a raw byte array only but need to supply a richer structure.

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