Check backup nullptr (#2237)

This commit is contained in:
LoveSy 2022-11-25 09:24:35 +08:00 committed by GitHub
parent d5c52a50df
commit c5918f7886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -219,7 +219,10 @@ public final class XposedBridge {
throw new IllegalArgumentException("callback should not be null!");
}
HookBridge.hookMethod((Executable) hookMethod, AdditionalHookInfo.class, callback.priority, callback);
if (!HookBridge.hookMethod((Executable) hookMethod, AdditionalHookInfo.class, callback.priority, callback)) {
log("Failed to hook " + hookMethod);
return null;
}
return callback.new Unhook(hookMethod);
}

View File

@ -101,7 +101,9 @@ LSP_DEF_NATIVE_METHOD(jboolean, HookBridge, unhookMethod, jobject hookMethod, jo
}
}
if (!hook_item) return JNI_FALSE;
JNIMonitor monitor(env, hook_item->backup);
auto backup = hook_item->backup;
if (!backup) return JNI_FALSE;
JNIMonitor monitor(env, backup);
for (auto i = hook_item->callbacks.begin(); i != hook_item->callbacks.end(); ++i) {
if (env->IsSameObject(i->second, callback)) {
hook_item->callbacks.erase(i);
@ -151,7 +153,9 @@ LSP_DEF_NATIVE_METHOD(jobjectArray, HookBridge, callbackSnapshot, jobject method
}
}
if (!hook_item) return nullptr;
JNIMonitor monitor(env, hook_item->backup);
auto backup = hook_item->backup;
if (!backup) return nullptr;
JNIMonitor monitor(env, backup);
auto res = env->NewObjectArray((jsize) hook_item->callbacks.size(), env->FindClass("java/lang/Object"), nullptr);
for (jsize i = 0; auto callback: hook_item->callbacks) {
env->SetObjectArrayElement(res, i++, env->NewLocalRef(callback.second));