Skip to content

rucko24/Instrumentacion-con-bytebuddy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Instrumentation with ByteBuddy

Here a simple example with the use of bytebuddy is done instrumentation to the constructor of a class at runtime by changing the value of a variable.

Executing the premain and agentmain method

Instrumentation-with-bytebuddy-execute-premain-method

Usuario: pran-u375177

The premain method

The agentmain method

To implement a class, as in this case, elhacker.User, this class is loaded before our agent implements.

The only way it works is that we load our agent just when it asks for the user's ID.

Instrument User class inside Program class

image

(1) The User instance is not yet instantiated, so the dialog input is displayed.

(2) Here, the user instance is created.

When the instrumentation works

Point (1)

The class to implement is not yet instantiated, and allows us to load our agent, the User class is loaded in the main main method, but without instantiating, at that time if we load our agent the instrumentation works.

instrument-user-class

When the instrumentation has not been applied

Point (2)

The User instance has been loaded to the JVM before our agent, so we cannot implement it.

no-instrumentation

And there, the instrumentation will be applied to the User class.