Skip to content

Commit

Permalink
Fix bug in Call Privacy
Browse files Browse the repository at this point in the history
Signed-off-by: Dev4Mod <[email protected]>
  • Loading branch information
Dev4Mod committed Jan 13, 2025
1 parent ff026a7 commit f386abd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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:
}
Expand Down

0 comments on commit f386abd

Please sign in to comment.