No need to implement Method.invoke ourselves (#1831)
This commit is contained in:
parent
ec5f7847e9
commit
9e3a3ac2b2
|
|
@ -11,7 +11,6 @@ public class HookBridge {
|
|||
|
||||
public static native boolean deoptimizeMethod(Executable method);
|
||||
|
||||
@FastNative
|
||||
public static native Object invokeOriginalMethod(Executable method, Object thisObject, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException;
|
||||
|
||||
@FastNative
|
||||
|
|
|
|||
|
|
@ -38,8 +38,7 @@ std::shared_mutex hooked_lock;
|
|||
// Rehashing invalidates iterators, changes ordering between elements, and changes which buckets elements appear in, but does not invalidate pointers or references to elements.
|
||||
std::unordered_map<jmethodID, HookItem> hooked_methods;
|
||||
|
||||
jobject (*native_invoke)(JNIEnv* env, jobject javaMethod, jobject javaReceiver,
|
||||
jobjectArray javaArgs);
|
||||
jmethodID invoke = nullptr;
|
||||
}
|
||||
|
||||
namespace lspd {
|
||||
|
|
@ -167,7 +166,7 @@ LSP_DEF_NATIVE_METHOD(jobject, HookBridge, invokeOriginalMethod, jobject hookMet
|
|||
if (hook_item && hook_item->backup) {
|
||||
to_call = hook_item->backup;
|
||||
}
|
||||
return native_invoke(env, to_call, thiz, args);
|
||||
return env->CallObjectMethod(to_call, invoke, thiz, args);
|
||||
}
|
||||
|
||||
LSP_DEF_NATIVE_METHOD(jboolean, HookBridge, instanceOf, jobject object, jclass expected_class) {
|
||||
|
|
@ -184,11 +183,9 @@ static JNINativeMethod gMethods[] = {
|
|||
|
||||
void RegisterHookBridge(JNIEnv *env) {
|
||||
auto method = env->FindClass("java/lang/reflect/Method");
|
||||
auto invoke = env->GetMethodID(
|
||||
invoke = env->GetMethodID(
|
||||
method, "invoke",
|
||||
"(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
native_invoke = reinterpret_cast<decltype(native_invoke)>(
|
||||
lsplant::GetNativeFunction(env, env->ToReflectedMethod(method, invoke, false)));
|
||||
env->DeleteLocalRef(method);
|
||||
REGISTER_LSP_NATIVE_METHODS(HookBridge);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue