Optimize record pending

This commit is contained in:
LoveSy 2021-01-29 16:07:12 +08:00
parent d54008040d
commit 62fb91a469
6 changed files with 16 additions and 8 deletions

View File

@ -65,7 +65,7 @@ namespace art {
"_ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv",
bool, ShouldUseInterpreterEntrypoint, (void * art_method,
const void *quick_code), {
if (quick_code != nullptr && UNLIKELY(lspd::isHooked(art_method))) {
if (quick_code != nullptr && UNLIKELY(lspd::isHooked(art_method) || lspd::IsMethodPending(art_method))) {
return false;
}
return backup(art_method, quick_code);

View File

@ -12,6 +12,7 @@
namespace lspd {
namespace {
std::unordered_set<const void *> pending_classes_;
std::unordered_set<const void *> pending_methods_;
std::unordered_set<const void *> hooked_methods_;
}
@ -20,6 +21,10 @@ namespace lspd {
return pending_classes_.count(clazz);
}
bool IsMethodPending(void* art_method) {
return pending_methods_.erase(art_method) > 0;
}
void DonePendingHook(void *clazz) {
pending_classes_.erase(clazz);
}
@ -31,7 +36,7 @@ namespace lspd {
if (auto def = mirror_class.GetClassDef(); LIKELY(def)) {
LOGD("record pending: %p (%s) with %p", class_ptr, mirror_class.GetDescriptor().c_str(), method);
// Add it for ShouldUseInterpreterEntrypoint
recordHooked(method);
pending_methods_.insert(method);
pending_classes_.insert(def);
} else {
LOGW("fail to record pending for : %p (%s)", class_ptr,
@ -40,7 +45,7 @@ namespace lspd {
}
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(PendingHooks, recordPendingMethodNative, "(Ljava/lang/reflect/Member;Ljava/lang/Class;)V"),
NATIVE_METHOD(PendingHooks, recordPendingMethodNative, "(Ljava/lang/reflect/Method;Ljava/lang/Class;)V"),
};
void RegisterPendingHooks(JNIEnv *env) {

View File

@ -15,4 +15,6 @@ namespace lspd {
void DonePendingHook(void *clazz);
bool IsMethodPending(void* art_method);
} // namespace lspd

View File

@ -1,6 +1,7 @@
package de.robv.android.xposed;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
@ -22,7 +23,7 @@ public final class PendingHooks {
}
}
public synchronized static void recordPendingMethod(Member hookMethod,
public synchronized static void recordPendingMethod(Method hookMethod,
XposedBridge.AdditionalHookInfo additionalInfo) {
ConcurrentHashMap<Member, XposedBridge.AdditionalHookInfo> pending =
sPendingHooks.computeIfAbsent(hookMethod.getDeclaringClass(),
@ -41,5 +42,5 @@ public final class PendingHooks {
sPendingHooks.clear();
}
private static native void recordPendingMethodNative(Member hookMethod, Class clazz);
private static native void recordPendingMethodNative(Method hookMethod, Class clazz);
}

View File

@ -241,7 +241,7 @@ public final class XposedBridge {
if (reflectMethod != null) {
hookMethodNative(reflectMethod, declaringClass, slot, additionalInfo);
} else {
PendingHooks.recordPendingMethod(hookMethod, additionalInfo);
PendingHooks.recordPendingMethod((Method)hookMethod, additionalInfo);
}
}

View File

@ -2,8 +2,8 @@ package io.github.lsposed.lspd.util;
import android.os.Build;
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import de.robv.android.xposed.XposedHelpers;
@ -46,7 +46,7 @@ public class ClassUtils {
}
public static boolean shouldDelayHook(Member hookMethod) {
if (hookMethod == null || hookMethod instanceof Constructor) {
if (!(hookMethod instanceof Method)) {
return false;
}
Class declaringClass = hookMethod.getDeclaringClass();