Tutorial by Examples

Bytecode is the set of instructions used by the JVM. To illustrate this let's take this Hello World program. public static void main(String[] args){ System.out.println("Hello World"); } This is what it turns into when compiled into bytecode. public static main([Ljava/lang/String...
Firstly the classes from the jar need to be loaded. We'll use three methods for this process: loadClasses(File) readJar(JarFile, JarEntry, Map) getNode(byte[]) Map<String, ClassNode> loadClasses(File jarFile) throws IOException { Map<String, ClassNode> classes = new HashMap&...
/** * Load a class by from a ClassNode * * @param cn * ClassNode to load * @return */ public static Class<?> load(ClassNode cn) { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); return new ClassDefiner(ClassLoader.getSystemClassLoader()).get(cn....
public static void main(String[] args) throws Exception { File jarFile = new File("Input.jar"); Map<String, ClassNode> nodes = JarUtils.loadClasses(jarFile); Map<String, byte[]> out = JarUtils.loadNonClassEntries(jarFile); Map<String, String> map...
Javassist is a bytecode instrumentation library that allows you to modify bytecode injecting Java code that will be converted to bytecode by Javassist and added to the instrumented class/method at runtime. Lets write the first transformer that actually take an hypothetical class "com.my.to.be....

Page 1 of 1