是否有某种方法可以使用 JNI 动态添加 native Hook ?我的意思是,我想重写类(或新类)中的一些方法,以便重写调用我的 native 代码,而无需为此编写任何 Java 代码。
最佳答案
如果您指的是 native
方法,也许注册可能是您的答案。
例如,这里我正在注册原生方法
JNIEXPORT jint JNICALL addOne(JNIEnv *env, jclass obj, jint a) {
return a + 1;
}
...
...
static JNINativeMethod methods[] = {
{"addOne", "(I)I", (void *)&addOne}
};
...
...
(*env)->RegisterNatives(env, cls_Main,
methods, sizeof(methods)/sizeof(methods[0]));
将被分配到类(class)
public class Main {
public static native int addOne(int a);
...
...
}
完整示例:https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo052
关于java - 动态添加原生钩子(Hook),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57590496/