mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Test: add bytecode API integration tests
- add Java tests for getClassBytes(ByName), redefineClass(ByName), retransformClass(ByName) and defineClass - ignore tests/tmp/ directory for captured bytecode output
This commit is contained in:
1 parent
63dd69abc6
commit
4833b512f5
8 files changed
+182
-1
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class DefineClass {
|
||||
public static void main(String[] args) throws IOException {
|
||||
System.load(new File("resources/libagent.dll").getAbsolutePath());
|
||||
JuiceAgent.init("");
|
||||
|
||||
ClassLoader cl = new ClassLoader() {};
|
||||
|
||||
invokeTest(cl);
|
||||
|
||||
byte[] bytes = Files.readAllBytes(new File("out/production/injection/Injection.class").toPath());
|
||||
System.out.println("Read bytes: " + bytes.length);
|
||||
|
||||
JuiceAgent.defineClass(cl, bytes);
|
||||
|
||||
invokeTest(cl);
|
||||
|
||||
}
|
||||
|
||||
public static void invokeTest(ClassLoader cl) {
|
||||
try {
|
||||
Class<?> clazz = cl.loadClass("Injection");
|
||||
clazz.getMethod("test").invoke(null);
|
||||
System.out.println("ClassLoader: " + clazz.getClassLoader().toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user