diff --git a/test/MergeInject.java b/test/MergeInject.java index b662b9c..4c244ea 100644 --- a/test/MergeInject.java +++ b/test/MergeInject.java @@ -6,7 +6,7 @@ import java.util.concurrent.ThreadLocalRandom; import static dev.w1zzrd.asm.InPlaceInjection.*; -@InjectClass(value = MergeTest.class) +@InjectClass(MergeTest.class) public class MergeInject extends MergeTest implements Runnable { @Inject diff --git a/test/Test.java b/test/Test.java index cc23695..ce8fd49 100644 --- a/test/Test.java +++ b/test/Test.java @@ -1,64 +1,20 @@ -import dev.w1zzrd.asm.Combine; -import dev.w1zzrd.asm.GraftSource; -import dev.w1zzrd.asm.Loader; -import dev.w1zzrd.asm.analysis.FrameState; -import dev.w1zzrd.asm.signature.TypeSignature; -import jdk.internal.org.objectweb.asm.tree.ClassNode; -import jdk.internal.org.objectweb.asm.tree.MethodNode; - -import java.io.File; -import java.io.FileOutputStream; +import dev.w1zzrd.asm.Injector; import java.io.IOException; -import java.util.Stack; public class Test { public static void main(String... args) throws IOException { + // Load target class, inject all annotated classes and load compiled bytecode into JVM + Injector.injectAll("MergeTest").compile(); - ClassNode target = Loader.getClassNode("MergeTest"); - ClassNode inject = Loader.getClassNode("MergeInject"); - - MethodNode stackTest = target.methods.stream().filter(it -> it.name.equals("stackTest")).findFirst().get(); - - Stack stack = FrameState.getFrameStateAt(stackTest.instructions.getLast().getPrevious().getPrevious().getPrevious().getPrevious().getPrevious(), stackTest.localVariables); - - GraftSource source = new GraftSource(inject); - - Combine combine = new Combine(target); - for (MethodNode method : source.getInjectMethods()) { - combine.inject(method, source); - } - - File f = new File("MergeTest.class"); - if(f.isFile() && f.delete() && f.createNewFile()) { - FileOutputStream fos = new FileOutputStream(f); - fos.write(combine.toByteArray()); - fos.close(); - } - - combine.compile(); - + // Run simple injection tests new MergeTest().test(); + // Run test of more complex stack arrangement System.out.println(new MergeTest().stackTest()); - /* - Merger m = new Merger("MergeTest"); - m.inject("MergeInject"); - - // Save injected data - File f = new File("out.class"); - if(f.isFile() && f.delete() && f.createNewFile()) { - FileOutputStream fos = new FileOutputStream(f); - fos.write(m.toByteArray()); - fos.close(); - } - - // Compile and run - m.compile(); - - Runnable r = (Runnable)new MergeTest("Constructor message"); + // Injected interface + Runnable r = (Runnable) new MergeTest(); r.run(); - */ } }