mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
- add Java tests for getClassBytes(ByName), redefineClass(ByName), retransformClass(ByName) and defineClass - ignore tests/tmp/ directory for captured bytecode output
35 lines
979 B
Java
35 lines
979 B
Java
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();
|
|
}
|
|
}
|
|
}
|