From f386abdc1f55d17b0b14d21918dd784122a4b1a0 Mon Sep 17 00:00:00 2001 From: Dev4Mod Date: Mon, 13 Jan 2025 10:44:27 -0300 Subject: [PATCH] Fix bug in Call Privacy Signed-off-by: Dev4Mod --- .../xposed/core/devkit/Unobfuscator.java | 2 +- .../xposed/features/privacy/CallPrivacy.java | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/wmods/wppenhacer/xposed/core/devkit/Unobfuscator.java b/app/src/main/java/com/wmods/wppenhacer/xposed/core/devkit/Unobfuscator.java index 1e7d9203..78026ae4 100644 --- a/app/src/main/java/com/wmods/wppenhacer/xposed/core/devkit/Unobfuscator.java +++ b/app/src/main/java/com/wmods/wppenhacer/xposed/core/devkit/Unobfuscator.java @@ -813,7 +813,7 @@ public synchronized static Method[] loadArchiveHideViewMethod(ClassLoader loader public synchronized static Method loadAntiRevokeOnCallReceivedMethod(ClassLoader loader) throws Exception { return UnobfuscatorCache.getInstance().getMethod(loader, () -> { - var method = findFirstMethodUsingStrings(loader, StringMatchType.Contains, "VoiceService:callStateChangedOnUiThread"); + var method = findFirstMethodUsingStrings(loader, StringMatchType.Contains, "voip/callStateChangedOnUIThread"); if (method == null) throw new Exception("OnCallReceiver method not found"); return method; }); diff --git a/app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/CallPrivacy.java b/app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/CallPrivacy.java index 1880b0b0..5b930c08 100644 --- a/app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/CallPrivacy.java +++ b/app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/CallPrivacy.java @@ -14,6 +14,7 @@ import com.wmods.wppenhacer.xposed.utils.Utils; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.stream.Collectors; @@ -31,6 +32,10 @@ public class CallPrivacy extends Feature { @Override public void doHook() throws Throwable { + var clazzVoip = XposedHelpers.findClass("com.whatsapp.voipcalling.Voip", classLoader); + var endCallMethod = ReflectionUtils.findMethodUsingFilter(clazzVoip, m -> m.getName().equals("endCall")); + var rejectCallMethod = ReflectionUtils.findMethodUsingFilter(clazzVoip, m -> m.getName().equals("rejectCall")); + var onCallReceivedMethod = Unobfuscator.loadAntiRevokeOnCallReceivedMethod(classLoader); XposedBridge.hookMethod(onCallReceivedMethod, new XC_MethodHook() { @@ -54,23 +59,28 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable { Tasker.sendTaskerEvent(WppCore.getContactName(userJid), WppCore.stripJID(WppCore.getRawString(userJid)), "call_received"); var blockCall = checkCallBlock(userJid, PrivacyType.getByValue(type)); if (!blockCall) return; - var clazzVoip = XposedHelpers.findClass("com.whatsapp.voipcalling.Voip", classLoader); var rejectType = prefs.getString("call_type", "no_internet"); + + // Need Instance of VoipManager from WhatsApp 2.24.24.XX + Object voipManager = null; + if (!Modifier.isStatic(endCallMethod.getModifiers())) { + var fieldVoipManager = ReflectionUtils.findFieldUsingFilterIfExists(param.thisObject.getClass(), field -> clazzVoip.isInstance(ReflectionUtils.getObjectField(field, param.thisObject))); + voipManager = fieldVoipManager == null ? null : fieldVoipManager.get(param.thisObject); + } switch (rejectType) { case "uncallable": case "declined": - var rejectCallMethod = ReflectionUtils.findMethodUsingFilter(clazzVoip, m -> m.getName().equals("rejectCall")); var params = ReflectionUtils.initArray(rejectCallMethod.getParameterTypes()); params[0] = callId; params[1] = "declined".equals(rejectType) ? null : rejectType; - ReflectionUtils.callMethod(rejectCallMethod, null, params); + ReflectionUtils.callMethod(rejectCallMethod, voipManager, params); + param.setResult(true); break; case "ended": - try { - XposedHelpers.callStaticMethod(clazzVoip, "endCall", true); - } catch (NoSuchMethodError e) { - XposedHelpers.callStaticMethod(clazzVoip, "endCall", true, 0); - } + var params1 = ReflectionUtils.initArray(endCallMethod.getParameterTypes()); + params1[0] = true; + ReflectionUtils.callMethod(endCallMethod, voipManager, params1); + param.setResult(true); break; default: }