Skip to content

Commit 3d269bc

Browse files
committed
Improve loadSenderPlayedMethod in Unobfuscator
Signed-off-by: Dev4Mod <[email protected]>
1 parent ece72cd commit 3d269bc

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

app/src/main/java/com/wmods/wppenhacer/xposed/core/components/FMessageWpp.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import de.robv.android.xposed.XposedBridge;
1111
import de.robv.android.xposed.XposedHelpers;
1212

13-
/** @noinspection unused*/
13+
/**
14+
* @noinspection unused
15+
*/
1416
public class FMessageWpp {
1517

1618
public static Class<?> TYPE;
@@ -55,6 +57,17 @@ public static void initialize(ClassLoader classLoader) {
5557
}
5658
}
5759

60+
public static boolean checkUnsafeIsFMessage(ClassLoader classLoader, Class<?> clazz) throws Exception {
61+
Class<?> FmessageClass = Unobfuscator.loadFMessageClass(classLoader);
62+
if (FmessageClass.isAssignableFrom(clazz)) return true;
63+
var interfaces = FmessageClass.getInterfaces();
64+
for (Class<?> anInterface : interfaces) {
65+
if (anInterface == clazz) return true;
66+
}
67+
return false;
68+
}
69+
70+
5871
public Object getUserJid() {
5972
try {
6073
return userJidMethod.invoke(fmessage);
@@ -127,7 +140,9 @@ public String getMessageStr() {
127140
}
128141
}
129142

130-
/** @noinspection BooleanMethodIsAlwaysInverted*/
143+
/**
144+
* @noinspection BooleanMethodIsAlwaysInverted
145+
*/
131146
public boolean isMediaFile() {
132147
try {
133148
return abstractMediaMessageClass.isInstance(fmessage);
@@ -177,7 +192,9 @@ public boolean isViewOnce() {
177192
return (media_type == 82 || media_type == 42 || media_type == 43);
178193
}
179194

180-
/** @noinspection unused*/
195+
/**
196+
* @noinspection unused
197+
*/
181198
public static class Key {
182199
public static Class<?> TYPE;
183200

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,8 @@ public synchronized static Method loadBlueOnReplayWaJobManagerMethod(ClassLoader
832832
public synchronized static Class loadArchiveChatClass(ClassLoader loader) throws Exception {
833833
return UnobfuscatorCache.getInstance().getClass(loader, () -> {
834834
var clazz = findFirstClassUsingStrings(loader, StringMatchType.Contains, "archive/set-content-indicator-to-empty");
835-
if (clazz == null) clazz = findFirstClassUsingStrings(loader, StringMatchType.Contains, "archive/Unsupported mode in ArchivePreviewView:");
835+
if (clazz == null)
836+
clazz = findFirstClassUsingStrings(loader, StringMatchType.Contains, "archive/Unsupported mode in ArchivePreviewView:");
836837
if (clazz == null) throw new Exception("ArchiveHideView method not found");
837838
return clazz;
838839
});
@@ -911,9 +912,11 @@ public synchronized static Method loadSendPresenceMethod(ClassLoader loader) thr
911912
if (methodCallers.isEmpty()) {
912913
var method = methodData.get(0);
913914
var superMethodInterfaces = method.getDeclaredClass().getInterfaces();
914-
if (superMethodInterfaces.isEmpty()) throw new Exception("SendPresence method interface list empty");
915+
if (superMethodInterfaces.isEmpty())
916+
throw new Exception("SendPresence method interface list empty");
915917
var superMethod = superMethodInterfaces.get(0).findMethod(FindMethod.create().matcher(MethodMatcher.create().name(method.getName()))).firstOrNull();
916-
if (superMethod == null) throw new Exception("SendPresence method interface method not found");
918+
if (superMethod == null)
919+
throw new Exception("SendPresence method interface method not found");
917920
methodCallers = superMethod.getCallers();
918921
}
919922
var newMethod = methodCallers.firstOrNull(method1 -> method1.getParamCount() == 4);
@@ -1677,16 +1680,28 @@ public synchronized static Class<?> loadSenderPlayedClass(ClassLoader classLoade
16771680
public synchronized static Method loadSenderPlayedMethod(ClassLoader classLoader) throws Exception {
16781681
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> {
16791682
var clazz = loadSenderPlayedClass(classLoader);
1680-
var fmessageClass = loadFMessageClass(classLoader);
1683+
var abstractMediaMessageClass = Unobfuscator.loadAbstractMediaMessageClass(classLoader);
1684+
var interfaces = abstractMediaMessageClass.getInterfaces();
1685+
1686+
ArrayList<Class> interfacesList = new ArrayList<>();
1687+
interfacesList.add(abstractMediaMessageClass);
1688+
interfacesList.addAll(Arrays.asList(interfaces));
1689+
16811690
Method methodResult = null;
1691+
main_loop:
16821692
for (var method : clazz.getMethods()) {
1683-
if (method.getParameterCount() == 1 && fmessageClass.isAssignableFrom(method.getParameterTypes()[0])) {
1684-
methodResult = method;
1685-
break;
1693+
if (method.getParameterCount() != 1) continue;
1694+
var parameterType = method.getParameterTypes()[0];
1695+
for (var interfaceClass : interfacesList) {
1696+
if (interfaceClass.isAssignableFrom(parameterType)) {
1697+
methodResult = method;
1698+
break main_loop;
1699+
}
16861700
}
16871701
}
16881702

16891703
// 2.25.19.xx, they refactored the SenderPlayed class
1704+
var fmessageClass = Unobfuscator.loadFMessageClass(classLoader);
16901705
if (methodResult == null) {
16911706
var method = findFirstMethodUsingStrings(classLoader, StringMatchType.Contains, "mediaHash and fileType not both present for upload URL generation");
16921707
if (method != null) {
@@ -1708,7 +1723,6 @@ public synchronized static Method loadSenderPlayedMethod(ClassLoader classLoader
17081723
return methodResult;
17091724
});
17101725
}
1711-
17121726
public synchronized static Method loadSenderPlayedBusiness(ClassLoader classLoader) throws Exception {
17131727
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> {
17141728
var loadSenderPlayed = loadSenderPlayedClass(classLoader);

0 commit comments

Comments
 (0)