Pregunta

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

¿Fue útil?

Solución 3

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.

Otros consejos

Take a look at the java.lang.instrument package. You could write a Java agent that registers a ClassFileTransformer.

The transformer can use ASM to process bytecode from class files, transform them to what you want, and return the new bytecode from ASM. There's also potential for modifying class files after they have already been loaded, but this can be a bit hit-and-miss as you have to make sure not to change signatures, etc.

You should hack that jar's ClassLoader as well

and return the the modified Class when findClass is called

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top