Optimize record pending
This commit is contained in:
parent
d54008040d
commit
62fb91a469
|
|
@ -65,7 +65,7 @@ namespace art {
|
||||||
"_ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv",
|
"_ZN3art11ClassLinker30ShouldUseInterpreterEntrypointEPNS_9ArtMethodEPKv",
|
||||||
bool, ShouldUseInterpreterEntrypoint, (void * art_method,
|
bool, ShouldUseInterpreterEntrypoint, (void * art_method,
|
||||||
const void *quick_code), {
|
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 false;
|
||||||
}
|
}
|
||||||
return backup(art_method, quick_code);
|
return backup(art_method, quick_code);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
namespace lspd {
|
namespace lspd {
|
||||||
namespace {
|
namespace {
|
||||||
std::unordered_set<const void *> pending_classes_;
|
std::unordered_set<const void *> pending_classes_;
|
||||||
|
std::unordered_set<const void *> pending_methods_;
|
||||||
|
|
||||||
std::unordered_set<const void *> hooked_methods_;
|
std::unordered_set<const void *> hooked_methods_;
|
||||||
}
|
}
|
||||||
|
|
@ -20,6 +21,10 @@ namespace lspd {
|
||||||
return pending_classes_.count(clazz);
|
return pending_classes_.count(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsMethodPending(void* art_method) {
|
||||||
|
return pending_methods_.erase(art_method) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
void DonePendingHook(void *clazz) {
|
void DonePendingHook(void *clazz) {
|
||||||
pending_classes_.erase(clazz);
|
pending_classes_.erase(clazz);
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +36,7 @@ namespace lspd {
|
||||||
if (auto def = mirror_class.GetClassDef(); LIKELY(def)) {
|
if (auto def = mirror_class.GetClassDef(); LIKELY(def)) {
|
||||||
LOGD("record pending: %p (%s) with %p", class_ptr, mirror_class.GetDescriptor().c_str(), method);
|
LOGD("record pending: %p (%s) with %p", class_ptr, mirror_class.GetDescriptor().c_str(), method);
|
||||||
// Add it for ShouldUseInterpreterEntrypoint
|
// Add it for ShouldUseInterpreterEntrypoint
|
||||||
recordHooked(method);
|
pending_methods_.insert(method);
|
||||||
pending_classes_.insert(def);
|
pending_classes_.insert(def);
|
||||||
} else {
|
} else {
|
||||||
LOGW("fail to record pending for : %p (%s)", class_ptr,
|
LOGW("fail to record pending for : %p (%s)", class_ptr,
|
||||||
|
|
@ -40,7 +45,7 @@ namespace lspd {
|
||||||
}
|
}
|
||||||
|
|
||||||
static JNINativeMethod gMethods[] = {
|
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) {
|
void RegisterPendingHooks(JNIEnv *env) {
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,6 @@ namespace lspd {
|
||||||
|
|
||||||
void DonePendingHook(void *clazz);
|
void DonePendingHook(void *clazz);
|
||||||
|
|
||||||
|
bool IsMethodPending(void* art_method);
|
||||||
|
|
||||||
} // namespace lspd
|
} // namespace lspd
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package de.robv.android.xposed;
|
package de.robv.android.xposed;
|
||||||
|
|
||||||
import java.lang.reflect.Member;
|
import java.lang.reflect.Member;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Function;
|
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) {
|
XposedBridge.AdditionalHookInfo additionalInfo) {
|
||||||
ConcurrentHashMap<Member, XposedBridge.AdditionalHookInfo> pending =
|
ConcurrentHashMap<Member, XposedBridge.AdditionalHookInfo> pending =
|
||||||
sPendingHooks.computeIfAbsent(hookMethod.getDeclaringClass(),
|
sPendingHooks.computeIfAbsent(hookMethod.getDeclaringClass(),
|
||||||
|
|
@ -41,5 +42,5 @@ public final class PendingHooks {
|
||||||
sPendingHooks.clear();
|
sPendingHooks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native void recordPendingMethodNative(Member hookMethod, Class clazz);
|
private static native void recordPendingMethodNative(Method hookMethod, Class clazz);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ public final class XposedBridge {
|
||||||
if (reflectMethod != null) {
|
if (reflectMethod != null) {
|
||||||
hookMethodNative(reflectMethod, declaringClass, slot, additionalInfo);
|
hookMethodNative(reflectMethod, declaringClass, slot, additionalInfo);
|
||||||
} else {
|
} else {
|
||||||
PendingHooks.recordPendingMethod(hookMethod, additionalInfo);
|
PendingHooks.recordPendingMethod((Method)hookMethod, additionalInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ package io.github.lsposed.lspd.util;
|
||||||
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Member;
|
import java.lang.reflect.Member;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import de.robv.android.xposed.XposedHelpers;
|
import de.robv.android.xposed.XposedHelpers;
|
||||||
|
|
@ -46,7 +46,7 @@ public class ClassUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldDelayHook(Member hookMethod) {
|
public static boolean shouldDelayHook(Member hookMethod) {
|
||||||
if (hookMethod == null || hookMethod instanceof Constructor) {
|
if (!(hookMethod instanceof Method)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Class declaringClass = hookMethod.getDeclaringClass();
|
Class declaringClass = hookMethod.getDeclaringClass();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue