Skip to content

Commit e589299

Browse files
authored
Merge pull request #17 from WindySha/master
Fix bug: calling invokeOriginalMethod method caused a crash
2 parents 1315a5a + c8d5fe5 commit e589299

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

java/com/lody/whale/xposed/XposedBridge.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public final class XposedBridge {
4141
// built-in handlers
4242
private static final Map<Member, CopyOnWriteSortedSet<XC_MethodHook>> sHookedMethodCallbacks = new HashMap<>();
4343

44+
private static final Map<Member, Long> sHookedMethodSlotMap = new HashMap<>();
45+
4446
/**
4547
* Writes a message to the logcat error log.
4648
*
@@ -101,6 +103,9 @@ public static XC_MethodHook.Unhook hookMethod(final Member hookMethod, final XC_
101103
if (slot <= 0) {
102104
throw new IllegalStateException("Failed to hook method: " + hookMethod);
103105
}
106+
synchronized (sHookedMethodSlotMap) {
107+
sHookedMethodSlotMap.put(hookMethod, slot);
108+
}
104109
}
105110

106111
return callback.new Unhook(hookMethod);
@@ -114,6 +119,9 @@ public static XC_MethodHook.Unhook hookMethod(final Member hookMethod, final XC_
114119
*/
115120
@SuppressWarnings("all")
116121
public static void unhookMethod(final Member hookMethod, final XC_MethodHook callback) {
122+
synchronized (sHookedMethodSlotMap) {
123+
sHookedMethodSlotMap.remove(hookMethod);
124+
}
117125
CopyOnWriteSortedSet<XC_MethodHook> callbacks;
118126
synchronized (sHookedMethodCallbacks) {
119127
callbacks = sHookedMethodCallbacks.get(hookMethod);
@@ -283,7 +291,7 @@ public static Object handleHookedMethod(Member method, long slot, Object additio
283291
public static Object invokeOriginalMethod(final Member method, final Object thisObject,
284292
final Object[] args)
285293
throws NullPointerException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
286-
long slot = WhaleRuntime.getMethodSlot(method);
294+
long slot = sHookedMethodSlotMap.get(method);
287295
return WhaleRuntime.invokeOriginalMethodNative(slot, thisObject, args);
288296
}
289297

0 commit comments

Comments
 (0)