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:
xiaozhou233 committed 2026-08-17 19:42:12 +08:00
1 parent 63dd69abc6
commit 4833b512f5
8 files changed
+182 -1

No files matched your search

+34
View File
@@ -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();
}
}
}