Update tests

This commit is contained in:
Gabriel Tofvesson 2021-01-26 06:01:26 +01:00
parent ac9b3079ab
commit 5301efd2a7
3 changed files with 39 additions and 5 deletions

View File

@ -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;
}
*/

View File

@ -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;
}

View File

@ -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<TypeSignature> 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");