Skip to content

Commit 3faffbe

Browse files
committed
Fix bug in show last seen in homescreen
1 parent 136c971 commit 3faffbe

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -916,22 +916,11 @@ public synchronized static Method loadStatusUserMethod(ClassLoader loader) throw
916916

917917
public synchronized static Method loadSendPresenceMethod(ClassLoader loader) throws Exception {
918918
return UnobfuscatorCache.getInstance().getMethod(loader, () -> {
919-
var method = findFirstMethodUsingStrings(loader, StringMatchType.Contains, "app/send-presence-subscription jid=");
920-
if (method == null) throw new Exception("SendPresence method not found");
921-
922-
// for 22.xx, method returns wrong one
923-
var methodData = dexkit.getMethodData(method);
924-
var groupJidClass = XposedHelpers.findClass("com.whatsapp.jid.GroupJid", loader);
925-
var classCheckMethod = dexkit.findMethod(FindMethod.create()
926-
.searchInClass(Collections.singletonList(methodData.getDeclaredClass()))
927-
.matcher(MethodMatcher.create().returnType(groupJidClass)))
928-
.singleOrNull();
929-
if (classCheckMethod == null) {
930-
var newMethod = methodData.getCallers().singleOrNull(method1 -> method1.getParamCount() == 4);
931-
if (newMethod == null) throw new Exception("SendPresence method not found 2");
932-
return newMethod.getMethodInstance(loader);
933-
}
934-
return method;
919+
var methodData = dexkit.findMethod(FindMethod.create().matcher(MethodMatcher.create().addUsingString("app/send-presence-subscription jid=")));
920+
if (methodData.isEmpty()) throw new Exception("SendPresence method not found");
921+
var newMethod = methodData.get(0).getCallers().singleOrNull(method1 -> method1.getParamCount() == 4);
922+
if (newMethod == null) throw new Exception("SendPresence method not found 2");
923+
return newMethod.getMethodInstance(loader);
935924
});
936925
}
937926

@@ -1940,4 +1929,8 @@ public static Class[] loadProximitySensorListenerClasses(ClassLoader classLoader
19401929
public static Class<?> loadRefreshStatusClass(ClassLoader classLoader) throws Exception {
19411930
return UnobfuscatorCache.getInstance().getClass(classLoader, () -> findFirstClassUsingStrings(classLoader, StringMatchType.Contains, "Report tab open only once per session"));
19421931
}
1932+
1933+
public static Method loadTcTokenMethod(ClassLoader classLoader) throws Exception {
1934+
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> findFirstMethodUsingStrings(classLoader, StringMatchType.Contains, "GET_RECEIVED_TOKEN_AND_TIMESTAMP_BY_JID"));
1935+
}
19431936
}

app/src/main/java/com/wmods/wppenhacer/xposed/features/customization/ShowOnline.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
110110
logDebug(Unobfuscator.getMethodDescriptor(getStatusUser));
111111
var sendPresenceMethod = Unobfuscator.loadSendPresenceMethod(classLoader);
112112
logDebug(Unobfuscator.getMethodDescriptor(sendPresenceMethod));
113-
113+
var tcTokenMethod = Unobfuscator.loadTcTokenMethod(classLoader);
114114
var absViewHolderClass = Unobfuscator.loadAbsViewHolder(classLoader);
115115

116116

@@ -128,6 +128,11 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
128128
}
129129
});
130130

131+
// load methods
132+
var tokenClass = sendPresenceMethod.getParameterTypes()[2];
133+
var fieldTokenDBInstance = ReflectionUtils.getFieldByExtendType(sendPresenceMethod.getDeclaringClass(), tcTokenMethod.getDeclaringClass());
134+
135+
131136
XposedBridge.hookMethod(onChangeStatus, new XC_MethodHook() {
132137
@Override
133138
@SuppressLint("ResourceType")
@@ -148,15 +153,12 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
148153
var jidObject = jidFiled.get(object);
149154
var jid = WppCore.getRawString(jidObject);
150155
if (WppCore.isGroup(jid)) return;
151-
Class<?> JidClass = classLoader.loadClass("com.whatsapp.jid.Jid");
152-
var method = ReflectionUtils.findMethodUsingFilter(sendPresenceMethod.getDeclaringClass(), method1 -> method1.getParameterCount() == 2 && JidClass.isAssignableFrom(method1.getParameterTypes()[0]) && method1.getParameterTypes()[1] == sendPresenceMethod.getDeclaringClass());
153-
var instance = ReflectionUtils.callMethod(method, null, jidObject, mInstancePresence); //XposedHelpers.newInstance(clazz, new Object[]{null, null});
154-
// for 22.xx, the parameter count is 4
155-
if (sendPresenceMethod.getParameterCount() == 4) {
156-
sendPresenceMethod.invoke(null, jidObject, null, instance, mInstancePresence);
157-
} else {
158-
sendPresenceMethod.invoke(null, jidObject, instance, mInstancePresence);
159-
}
156+
157+
var tokenDBInstance = fieldTokenDBInstance.get(mInstancePresence);
158+
var tokenData = ReflectionUtils.callMethod(tcTokenMethod, tokenDBInstance, jidObject);
159+
var tokenObj = tokenClass.getConstructors()[0].newInstance(tokenData == null ? null : XposedHelpers.getObjectField(tokenData, "A01"));
160+
sendPresenceMethod.invoke(null, jidObject, null, tokenObj, mInstancePresence);
161+
160162
var status = (String) ReflectionUtils.callMethod(getStatusUser, mStatusUser, object, false);
161163
var currentPosition = (int) ReflectionUtils.callMethod(getAdapterPositionMethod, viewHolder);
162164
if (currentPosition != position) return;

0 commit comments

Comments
 (0)