Search code examples
javacode-injectionbytecodejava-bytecode-asm

is this possible with Java's ASM library?


Im looking to use ASM to modify a running jar file and wanted to ask some questions. First with ASM can I 'live' edit and what I mean is, can I edit a jar which is currently being run e.g. a game and then inject my code into the jars class files and have it stick untill the jar is closed? So it will still be called in the games run loop etc? As from what I've tryed I can only get my code to run the once... Thanks


Solution

  • You can use reflections to change code behavior in runtime. It will not stay in the "jar", and at least while the classes you need are loaded, all will be well.

    You need to, then, provide the mechanism to inject your changes using reflections in your program. Or that's the way I'd go about it, anyway.

    Furthermore: the answer to this question has even more flexible options for runtime modding. If you use its third option, you can code in javascript (or other languages) (related info, a blog dedicated to scripting in java) using the facilities defined in JSR-223.