Skip to content

Commit 602609b

Browse files
committed
Fix custom privacy
Signed-off-by: Dev4Mod <wellingtonmods@gmail.com>
1 parent bb2eba0 commit 602609b

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

app/src/main/java/com/wmods/wppenhacer/xposed/core/devkit/Unobfuscator.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ public synchronized static Method loadOnChangeStatus(ClassLoader loader) throws
872872
if (declaringClassData == null)
873873
throw new Exception("OnChangeStatus method not found");
874874

875-
Class<?> arg1Class = findFirstClassUsingStrings(loader, StringMatchType.Contains, "problematic contact:");
875+
Class<?> arg1Class = loadWaContactClass(loader);
876876
MethodDataList methodData = declaringClassData.findMethod(
877877
FindMethod.create().matcher(MethodMatcher.create().paramCount(6, 8)));
878878

@@ -2010,4 +2010,27 @@ public static Class loadVoipManager(ClassLoader classLoader) throws Exception {
20102010
}
20112011
throw new ClassNotFoundException("VoipManager Class not found");
20122012
}
2013+
2014+
public static Class loadWaContactClass(ClassLoader classLoader) throws Exception {
2015+
return UnobfuscatorCache.getInstance().getClass(classLoader, () -> findFirstClassUsingStrings(classLoader, StringMatchType.Contains, "problematic contact:"));
2016+
2017+
}
2018+
2019+
2020+
public static Field loadWaContactFromContactInfo(ClassLoader classLoader) throws Exception {
2021+
return UnobfuscatorCache.getInstance().getField(classLoader, () -> {
2022+
var classData = dexkit.getClassData("com.whatsapp.chatinfo.ContactInfoActivity");
2023+
var waContactData = dexkit.getClassData(loadWaContactClass(classLoader));
2024+
if (waContactData != null && classData != null) {
2025+
for (var field : classData.getFields()) {
2026+
if (field.getTypeName().equals(waContactData.getName())) {
2027+
// For some reason Class Contactinfoactivity returns an error when trying to list the available fields
2028+
return XposedHelpers.findField(classData.getInstance(classLoader), field.getName());
2029+
}
2030+
}
2031+
}
2032+
throw new NoSuchFieldException("WaContact Field not found in ContactInfoActivity");
2033+
});
2034+
2035+
}
20132036
}

app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/CustomPrivacy.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.wmods.wppenhacer.xposed.core.Feature;
2222
import com.wmods.wppenhacer.xposed.core.WppCore;
2323
import com.wmods.wppenhacer.xposed.core.components.AlertDialogWpp;
24+
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
2425
import com.wmods.wppenhacer.xposed.features.others.MenuHome;
2526
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
2627
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
@@ -29,6 +30,7 @@
2930

3031
import org.json.JSONObject;
3132

33+
import java.lang.reflect.Field;
3234
import java.lang.reflect.Method;
3335
import java.util.ArrayList;
3436
import java.util.Objects;
@@ -40,6 +42,7 @@
4042
public class CustomPrivacy extends Feature {
4143
private Method chatUserJidMethod;
4244
private Method groupUserJidMethod;
45+
private Field waContactField;
4346

4447
public CustomPrivacy(@NonNull ClassLoader classLoader, @NonNull XSharedPreferences preferences) {
4548
super(classLoader, preferences);
@@ -60,6 +63,7 @@ public void doHook() throws Throwable {
6063
Class<?> userJidClass = XposedHelpers.findClass("com.whatsapp.jid.UserJid", classLoader);
6164
Class<?> groupJidClass = XposedHelpers.findClass("com.whatsapp.jid.GroupJid", classLoader);
6265

66+
waContactField = Unobfuscator.loadWaContactFromContactInfo(classLoader);
6367
chatUserJidMethod = ReflectionUtils.findMethodUsingFilter(ContactInfoActivityClass, method -> method.getParameterCount() == 0 && userJidClass.isAssignableFrom(method.getReturnType()));
6468
groupUserJidMethod = ReflectionUtils.findMethodUsingFilter(GroupInfoActivityClass, method -> method.getParameterCount() == 0 && groupJidClass.isAssignableFrom(method.getReturnType()));
6569

@@ -224,7 +228,14 @@ private void showPrivacyDialog(Activity activity, boolean isChat) {
224228

225229
private Object getUserJid(Activity activity, boolean isChat) {
226230
if (isChat) {
227-
return ReflectionUtils.callMethod(chatUserJidMethod, activity);
231+
var userJid = ReflectionUtils.callMethod(chatUserJidMethod, activity);
232+
if (Objects.requireNonNullElse(WppCore.getRawString(userJid), "").contains("@lid")) {
233+
var waContact = ReflectionUtils.getObjectField(waContactField, activity);
234+
Class<?> phoneUserJidClass = XposedHelpers.findClass("com.whatsapp.jid.PhoneUserJid", classLoader);
235+
Field phoneUserJidField = ReflectionUtils.getFieldByType(waContact.getClass(), phoneUserJidClass);
236+
return ReflectionUtils.getObjectField(phoneUserJidField, waContact);
237+
}
238+
return userJid;
228239
} else {
229240
return ReflectionUtils.callMethod(groupUserJidMethod, activity);
230241
}

app/src/main/java/com/wmods/wppenhacer/xposed/utils/ReflectionUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ public static Object getDefaultValue(Class<?> paramType) {
173173
return null;
174174
}
175175

176-
public static Object getObjectField(Field loadProfileInfoField, Object thisObject) {
176+
public static Object getObjectField(Field field, Object thisObject) {
177177
try {
178-
return loadProfileInfoField.get(thisObject);
178+
return field.get(thisObject);
179179
} catch (Exception e) {
180180
return null;
181181
}

0 commit comments

Comments
 (0)