diff --git a/test/MergeInject.java b/test/MergeInject.java index ab9a3fb..d03bf06 100644 --- a/test/MergeInject.java +++ b/test/MergeInject.java @@ -12,20 +12,33 @@ public class MergeInject extends MergeTest implements Runnable { // Dummy field String s; + /* @Inject MergeInject() { s = "Hello"; number = 10; } + */ + @Inject(value = AFTER, target = "stackTest()I", acceptOriginalReturn = true) + public int stackTest(int arg) { + Runnable r = () -> { + System.out.println(arg / 15); + System.out.println("Heyo"); + }; + r.run(); + return 69; + } + @Inject(value = AFTER, target = "test()Ljava/lang/String;", acceptOriginalReturn = true) public String test(String retVal){ + System.out.println("Got retval: "+retVal); if (retVal.endsWith("e!!Test")) { @@ -45,21 +58,28 @@ public class MergeInject extends MergeTest implements Runnable { System.out.println(s); + + if(s.endsWith("e!!")) { System.out.println("Special!"); return "ASDF"; } - System.out.println(number); + + + System.out.println(s); + return "Modified"; } + /* @Inject(value = AFTER, target = "test()Ljava/lang/String;", acceptOriginalReturn = true) public String test_inject$1(String retVal) { System.out.println("Another injection: "+retVal); return retVal; } + */ diff --git a/test/MergeTest.java b/test/MergeTest.java index 6817a17..a20b3f5 100644 --- a/test/MergeTest.java +++ b/test/MergeTest.java @@ -16,6 +16,7 @@ public class MergeTest { public String test(){ Class c = Merger.class; Runnable r = () -> { + System.out.println("Sick"); System.out.println(c.getName()); }; @@ -28,11 +29,11 @@ public class MergeTest { return s; } - public void stackTest() { + public int stackTest() { String str = Integer.toString(getNumber() * 23); if ("69".equals(str)) { - int k = Integer.getInteger(str); + int k = Integer.parseInt(str); System.out.println(k + str + (k * k)); getNumber(); @@ -43,6 +44,8 @@ public class MergeTest { System.out.println(f + str + (f * f)); multiArg(str, f, f == 5f, "69".equals(str) ? f * f : (f + 1.0), f < 6f ? (int)f : 7); + + return getNumber() * 5; } diff --git a/test/Test.java b/test/Test.java index 93c4331..4a00df8 100644 --- a/test/Test.java +++ b/test/Test.java @@ -6,6 +6,8 @@ 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 java.io.IOException; import java.util.Stack; @@ -19,16 +21,25 @@ public class Test { Stack stack = FrameState.getFrameStateAt(stackTest.instructions.getLast().getPrevious().getPrevious().getPrevious().getPrevious().getPrevious(), stackTest.localVariables); - GraftSource source = new GraftSource(target); + 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(); - System.out.println("Asdf"); + new MergeTest().test(); + + System.out.println(new MergeTest().stackTest()); /* Merger m = new Merger("MergeTest");