Java Agents are used to replace code when the application is running. When you are debugging with IntelliJ, Eclipse etc. and you saving / rebuilding your code, an agent will be loaded to do it.
The environment has to be a Java Development Kit (not a Java Runtime Enviroment) to inject
the code at runtime. If you want to apply the agent with -javaagent:<agent-jar>
it will work
for both.
Furthermore the agent can only add classes and change method contents at runtime. It can't:
- Change Field / Method access
- Add Fields or Fethods
- Change Class's Version
- etc.
Here are some use cases where this can come to handy:
- To impress
- When you want to change the behaviour of your added code depending on the program's state
- For debugging
To make code injection easier I made some tools:
asm-delta is a tool to calculate the difference between two jars on bytecode level. It also detects if the changes are valid for an agent and if it isn't it tells you what the problem is.
Link: https://github.com/superblaubeere27/asm-delta
asm-delta-agent is the corresponding agent for asm-delta. It applies an asm-delta patch file at runtime.
Link: https://github.com/superblaubeere27/asm-delta-agent
Just a simple tool that searches for a running Minecraft Session, attaches itself to it and loads the agent.
Link: https://gist.github.com/superblaubeere27/97cba0f22d06232cb98033d28c21d37b
If you have problems or questions you can join my discord server: https://gist.github.com/superblaubeere27/bc2f3ed5694c78efa812d6fbeb4d241c
download