@@ -41,6 +41,8 @@ public final class XposedBridge {
41
41
// built-in handlers
42
42
private static final Map <Member , CopyOnWriteSortedSet <XC_MethodHook >> sHookedMethodCallbacks = new HashMap <>();
43
43
44
+ private static final Map <Member , Long > sHookedMethodSlotMap = new HashMap <>();
45
+
44
46
/**
45
47
* Writes a message to the logcat error log.
46
48
*
@@ -101,6 +103,9 @@ public static XC_MethodHook.Unhook hookMethod(final Member hookMethod, final XC_
101
103
if (slot <= 0 ) {
102
104
throw new IllegalStateException ("Failed to hook method: " + hookMethod );
103
105
}
106
+ synchronized (sHookedMethodSlotMap ) {
107
+ sHookedMethodSlotMap .put (hookMethod , slot );
108
+ }
104
109
}
105
110
106
111
return callback .new Unhook (hookMethod );
@@ -114,6 +119,9 @@ public static XC_MethodHook.Unhook hookMethod(final Member hookMethod, final XC_
114
119
*/
115
120
@ SuppressWarnings ("all" )
116
121
public static void unhookMethod (final Member hookMethod , final XC_MethodHook callback ) {
122
+ synchronized (sHookedMethodSlotMap ) {
123
+ sHookedMethodSlotMap .remove (hookMethod );
124
+ }
117
125
CopyOnWriteSortedSet <XC_MethodHook > callbacks ;
118
126
synchronized (sHookedMethodCallbacks ) {
119
127
callbacks = sHookedMethodCallbacks .get (hookMethod );
@@ -283,7 +291,7 @@ public static Object handleHookedMethod(Member method, long slot, Object additio
283
291
public static Object invokeOriginalMethod (final Member method , final Object thisObject ,
284
292
final Object [] args )
285
293
throws NullPointerException , IllegalAccessException , IllegalArgumentException , InvocationTargetException {
286
- long slot = WhaleRuntime . getMethodSlot (method );
294
+ long slot = sHookedMethodSlotMap . get (method );
287
295
return WhaleRuntime .invokeOriginalMethodNative (slot , thisObject , args );
288
296
}
289
297
0 commit comments