mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 21:15:53 +08:00
Feat: Add JuiceAgentFacade
This commit is contained in:
1 parent
db6433158f
commit
e4935580fb
1 file changed
+69
@@ -0,0 +1,69 @@
|
||||
package cn.xiaozhou233.orangex.utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class JuiceAgentFacade {
|
||||
|
||||
private static final Class<?> JL;
|
||||
private static final Method GET_CLASS_BYTES;
|
||||
private static final Method REDEFINE_CLASS;
|
||||
private static final Method GET_LOADED_CLASSES;
|
||||
private static final Method RETRANSFORM_CLASS;
|
||||
|
||||
static {
|
||||
try {
|
||||
JL = Class.forName(
|
||||
"cn.xiaozhou233.juiceagent.api.JuiceAgent",
|
||||
true,
|
||||
ClassLoader.getSystemClassLoader()
|
||||
);
|
||||
|
||||
GET_CLASS_BYTES = JL.getMethod("getClassBytes", Class.class);
|
||||
REDEFINE_CLASS = JL.getMethod(
|
||||
"redefineClass",
|
||||
Class.class,
|
||||
byte[].class,
|
||||
int.class
|
||||
);
|
||||
GET_LOADED_CLASSES = JL.getMethod("getLoadedClasses");
|
||||
RETRANSFORM_CLASS = JL.getMethod("retransformClass", Class.class, byte[].class, int.class);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to init JuiceFacade", e);
|
||||
}
|
||||
}
|
||||
|
||||
private JuiceAgentFacade() {}
|
||||
|
||||
public static byte[] getClassBytes(Class<?> clazz) {
|
||||
try {
|
||||
return (byte[]) GET_CLASS_BYTES.invoke(null, clazz);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean redefineClass(Class<?> clazz, byte[] bytes) {
|
||||
try {
|
||||
return (boolean) REDEFINE_CLASS.invoke(null, clazz, bytes, bytes.length);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?>[] getLoadedClasses() {
|
||||
try {
|
||||
return (Class<?>[]) GET_LOADED_CLASSES.invoke(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean retransformClass(Class<?> clazz, byte[] bytes) {
|
||||
try {
|
||||
return (boolean) RETRANSFORM_CLASS.invoke(null, clazz, bytes, bytes.length);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user