3 ms·
In Java, you can write an agent and intercept when the bytecode for a class is loaded by the JVM by the Class Loader. ASM is just a bytecode reader/writer/visi
by danmg 6y ago
In Java, you can write an agent and intercept when the bytecode for a class is loaded by the JVM by the Class Loader.
ASM is just a bytecode reader/writer/visitor library that can then modify it. You could also just do it statically by having the bytecode you want injected ready to go in an array or resource.
if (className.equals("a/b/c/d$e"))
return fixedClassBytecode;
else
return bytecode;
It's possible to create custom loaders (e.g., loading a class from an encrypted zip-file, or one that creates custom bytecode on the fly) and things which are trying to obfuscate what they're doing will have custom loaders, but this is a choke point that every class that's read in and instantiated must pass through.