Update test files

This commit is contained in:
Gabriel Tofvesson 2021-01-28 17:05:11 +01:00
parent b2246c6960
commit 00ccca408c
2 changed files with 8 additions and 52 deletions

View File

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

View File

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