Skip to content

Commit 3263bb4

Browse files
committed
Refactor GroupAdmin feature with DexKit
1 parent af6b871 commit 3263bb4

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,11 +1347,10 @@ public synchronized static Method loadAudioProximitySensorMethod(ClassLoader loa
13471347

13481348
public synchronized static Method loadGroupAdminMethod(ClassLoader loader) throws Exception {
13491349
return UnobfuscatorCache.getInstance().getMethod(loader, () -> {
1350-
var method = findFirstMethodUsingStrings(loader, StringMatchType.Contains, "P Message");
1351-
if (method == null)
1352-
method = findFirstMethodUsingStrings(loader, StringMatchType.Contains, "ConversationRow/setUpUsernameInGroupViewContainer/not allowed state");
1353-
if (method == null) throw new RuntimeException("GroupAdmin method not found");
1354-
return method;
1350+
var method = dexkit.findMethod(FindMethod.create().matcher(MethodMatcher.create().name("setupUsernameInGroupViewContainer")));
1351+
if (method.isEmpty())
1352+
throw new RuntimeException("GroupAdmin method not found");
1353+
return method.get(0).getMethodInstance(loader);
13551354
});
13561355
}
13571356

@@ -1365,12 +1364,25 @@ public synchronized static Method loadJidFactory(ClassLoader loader) throws Exce
13651364

13661365
public synchronized static Method loadGroupCheckAdminMethod(ClassLoader loader) throws Exception {
13671366
return UnobfuscatorCache.getInstance().getMethod(loader, () -> {
1368-
var clazz = findFirstClassUsingStrings(loader, StringMatchType.Contains, "saveGroupParticipants/INSERT_GROUP_PARTICIPANT_USER");
1369-
var userJidClass = XposedHelpers.findClass("com.whatsapp.jid.UserJid", loader);
1370-
var methods = ReflectionUtils.findAllMethodsUsingFilter(clazz, m -> m.getParameterCount() == 2 && m.getParameterTypes()[1].equals(userJidClass) && m.getReturnType().equals(boolean.class));
1371-
if (methods == null || methods.length == 0)
1367+
var classData = dexkit.findClass(FindClass.create().matcher(ClassMatcher.create().addUsingString("saveGroupParticipants/INSERT_GROUP_PARTICIPANT_USER")));
1368+
var resultMethod = classData.findMethod(
1369+
FindMethod.create().matcher(MethodMatcher.create().paramCount(2).paramTypes(null, "com.whatsapp.jid.UserJid")
1370+
.opNames(List.of(
1371+
"const/4",
1372+
"invoke-static",
1373+
"const/4",
1374+
"invoke-static",
1375+
"invoke-virtual",
1376+
"move-result-object",
1377+
"const/4",
1378+
"invoke-virtual",
1379+
"move-result-object",
1380+
"if-nez"
1381+
), OpCodeMatchType.StartsWith)
1382+
)).singleOrNull();
1383+
if (resultMethod == null)
13721384
throw new RuntimeException("GroupCheckAdmin method not found");
1373-
return methods[methods.length - 1];
1385+
return resultMethod.getMethodInstance(loader);
13741386
});
13751387
}
13761388

app/src/main/java/com/wmods/wppenhacer/xposed/features/others/GroupAdmin.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010

1111
import com.wmods.wppenhacer.xposed.core.Feature;
1212
import com.wmods.wppenhacer.xposed.core.WppCore;
13+
import com.wmods.wppenhacer.xposed.core.components.FMessageWpp;
1314
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
15+
import com.wmods.wppenhacer.xposed.utils.DebugUtils;
1416
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
1517
import com.wmods.wppenhacer.xposed.utils.ResId;
1618
import com.wmods.wppenhacer.xposed.utils.Utils;
1719

20+
import java.lang.reflect.Method;
21+
1822
import de.robv.android.xposed.XC_MethodHook;
1923
import de.robv.android.xposed.XSharedPreferences;
2024
import de.robv.android.xposed.XposedBridge;
@@ -36,20 +40,16 @@ public void doHook() throws Throwable {
3640
@SuppressLint("ResourceType")
3741
@Override
3842
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
39-
var targetObj = param.thisObject != null
40-
? param.thisObject
41-
: param.args[1];
42-
43-
var fMessage = XposedHelpers.callMethod(targetObj, "getFMessage");
44-
var userJidClass = XposedHelpers.findClass("com.whatsapp.jid.UserJid", classLoader);
45-
var methodResult = ReflectionUtils.findMethodUsingFilter(fMessage.getClass(), method -> method.getReturnType() == userJidClass && method.getParameterCount() == 0);
46-
var userJid = ReflectionUtils.callMethod(methodResult, fMessage);
43+
var targetObj = param.thisObject != null ? param.thisObject : param.args[1];
44+
Object fMessageObj = XposedHelpers.callMethod(targetObj, "getFMessage");
45+
var fMessage = new FMessageWpp(fMessageObj);
46+
var userJid = fMessage.getUserJid();
4747
var chatCurrentJid = WppCore.getCurrentUserJid();
4848
if (!chatCurrentJid.isGroup()) return;
4949
var field = ReflectionUtils.getFieldByType(targetObj.getClass(), grpcheckAdmin.getDeclaringClass());
5050
var grpParticipants = field.get(targetObj);
51-
var jidGrp = jidFactory.invoke(null, chatCurrentJid.lid);
52-
var result = ReflectionUtils.callMethod(grpcheckAdmin, grpParticipants, jidGrp, userJid);
51+
var jidGrp = jidFactory.invoke(null, chatCurrentJid.getRawLidString());
52+
var result = grpcheckAdmin.invoke(grpParticipants, jidGrp, userJid.jid);
5353
var view = (View) targetObj;
5454
var context = view.getContext();
5555
ImageView iconAdmin;

0 commit comments

Comments
 (0)