Skip to content

Commit 2ced559

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 7948734 + 3d5f3af commit 2ced559

File tree

6 files changed

+69
-18
lines changed

6 files changed

+69
-18
lines changed

app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ public static Activity getCurrentConversation() {
352352
if (mCurrentActivity == null) return null;
353353
Class<?> conversation = XposedHelpers.findClass("com.whatsapp.Conversation", mCurrentActivity.getClassLoader());
354354
if (conversation.isInstance(mCurrentActivity)) return mCurrentActivity;
355+
356+
// for tablet UI, they're using HomeActivity instead of Conversation
357+
// TODO: Add more checks for ConversationFragment
358+
Class<?> home = XposedHelpers.findClass("com.whatsapp.HomeActivity", mCurrentActivity.getClassLoader());
359+
if (mCurrentActivity.getResources().getConfiguration().smallestScreenWidthDp >= 600 && home.isInstance(mCurrentActivity)) return mCurrentActivity;
355360
return null;
356361
}
357362

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,13 @@ public synchronized static Method loadMenuStatusMethod(ClassLoader loader) throw
537537
public synchronized static Field loadStatusDownloadFileField(ClassLoader classLoader) throws Exception {
538538
return UnobfuscatorCache.getInstance().getField(classLoader, () -> {
539539
var clazz = loadStatusDownloadMediaClass(classLoader);
540-
var clazz2 = clazz.getField("A01").getType();
541-
var field = ReflectionUtils.getFieldByType(clazz2, File.class);
542-
if (field == null) throw new Exception("StatusDownloadFile field not found");
543-
return field;
540+
for (Field clazzField : clazz.getFields()) {
541+
var clazz2 = clazzField.getType();
542+
var field = ReflectionUtils.getFieldByType(clazz2, File.class);
543+
if (field != null) return field;
544+
}
545+
546+
throw new Exception("StatusDownloadFile field not found");
544547
});
545548
}
546549

@@ -1073,9 +1076,15 @@ public synchronized static Method loadGetEditMessageMethod(ClassLoader loader) t
10731076
if (methodData == null) throw new RuntimeException("GetEditMessage method not found");
10741077
var invokes = methodData.getInvokes();
10751078
for (var invoke : invokes) {
1079+
// pre 21.xx method
10761080
if (invoke.getParamTypes().isEmpty() && Objects.equals(invoke.getDeclaredClass(), methodData.getParamTypes().get(0))) {
10771081
return invoke.getMethodInstance(loader);
10781082
}
1083+
1084+
// 21.xx+ method (static)
1085+
if (Modifier.isStatic(invoke.getMethodInstance(loader).getModifiers()) && Objects.equals(invoke.getParamTypes().get(0), methodData.getParamTypes().get(0))) {
1086+
return invoke.getMethodInstance(loader);
1087+
}
10791088
}
10801089
throw new RuntimeException("GetEditMessage method not found");
10811090
});

app/src/main/java/com/wmods/wppenhacer/xposed/features/general/ShowEditMessage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.wmods.wppenhacer.xposed.utils.ResId;
2929
import com.wmods.wppenhacer.xposed.utils.Utils;
3030

31+
import java.lang.reflect.Modifier;
3132
import java.util.ArrayList;
3233
import java.util.Objects;
3334

@@ -65,7 +66,10 @@ public void doHook() throws Throwable {
6566
XposedBridge.hookMethod(onMessageEdit, new XC_MethodHook() {
6667
@Override
6768
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
68-
var editMessage = getEditMessage.invoke(param.args[0]);
69+
// for 21.xx, getEditMessage is static
70+
var editMessage = Modifier.isStatic(getEditMessage.getModifiers())
71+
? getEditMessage.invoke(null, param.args[0])
72+
: getEditMessage.invoke(param.args[0]);
6973
if (editMessage == null) return;
7074
long timestamp = XposedHelpers.getLongField(editMessage, "A00");
7175
var fMessage = new FMessageWpp(param.args[0]);

app/src/main/java/com/wmods/wppenhacer/xposed/features/media/StatusDownload.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ private void sharedStatus(FMessageWpp fMessageWpp) {
100100

101101
private void downloadFile(FMessageWpp fMessage) {
102102
try {
103-
var fileData = XposedHelpers.getObjectField(fMessage.getObject(), "A01");
104-
if (!fieldFile.getDeclaringClass().isInstance(fileData)) {
103+
Field fieldFileInMessage = ReflectionUtils.getFieldByType(fMessage.getObject().getClass(), fieldFile.getDeclaringClass());
104+
if (fieldFileInMessage == null) {
105105
Utils.showToast(Utils.getApplication().getString(ResId.string.msg_text_status_not_downloadable), Toast.LENGTH_SHORT);
106106
return;
107107
}
108+
109+
var fileData = XposedHelpers.getObjectField(fMessage.getObject(), fieldFileInMessage.getName());
108110
var file = (File) ReflectionUtils.getField(fieldFile, fileData);
109111
var userJid = fMessage.getUserJid();
110112
var fileType = file.getName().substring(file.getName().lastIndexOf(".") + 1);

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

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
import java.io.IOException;
1111
import java.lang.reflect.Method;
1212
import java.net.URLEncoder;
13+
import java.util.ArrayList;
14+
import java.util.List;
1315
import java.util.Locale;
1416
import java.util.concurrent.CompletableFuture;
1517

1618
import de.robv.android.xposed.XC_MethodHook;
19+
import de.robv.android.xposed.XC_MethodReplacement;
1720
import de.robv.android.xposed.XSharedPreferences;
1821
import de.robv.android.xposed.XposedBridge;
1922
import de.robv.android.xposed.XposedHelpers;
@@ -46,18 +49,43 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
4649
}
4750
});
4851

49-
XposedHelpers.findAndHookMethod("com.whatsapp.messagetranslation.UnityMessageTranslation", classLoader, "translate", classLoader.loadClass("java.lang.String"),
50-
new XC_MethodHook() {
51-
@Override
52-
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
53-
var texto = (String) param.args[0];
54-
var currentMethod = (Method) param.method;
55-
var unityTranslationResultClass = currentMethod.getReturnType();
56-
var translation = translateGoogle(texto, Locale.getDefault().getLanguage()).get();
57-
var unityTranslationResult = unityTranslationResultClass.getConstructor(String.class, float.class, int.class).newInstance(translation, 1, 0);
58-
param.setResult(unityTranslationResult);
52+
Class<?> translatorClazz = XposedHelpers.findClass("com.whatsapp.messagetranslation.UnityMessageTranslation", classLoader);
53+
54+
var pre21Method = XposedHelpers.findMethodExactIfExists(translatorClazz, "translate", String.class);
55+
if (pre21Method != null) {
56+
XposedHelpers.findAndHookMethod(translatorClazz, pre21Method.getName(), String.class, new XC_MethodReplacement() {
57+
@Override
58+
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
59+
var texto = (String) param.args[0];
60+
var currentMethod = (Method) param.method;
61+
var unityTranslationResultClass = currentMethod.getReturnType();
62+
var translation = translateGoogle(texto, Locale.getDefault().getLanguage()).get();
63+
return unityTranslationResultClass.getConstructor(String.class, float.class, int.class).newInstance(translation, 1, 0);
64+
}
65+
});
66+
}
67+
68+
var newMethod = XposedHelpers.findMethodExactIfExists(translatorClazz, "translate", List.class);
69+
if (newMethod != null) {
70+
XposedHelpers.findAndHookMethod(translatorClazz, "translate", List.class, new XC_MethodReplacement() {
71+
@Override
72+
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
73+
var list = (List) param.args[0];
74+
var translated = new ArrayList<String>();
75+
76+
for (var texto : list) {
77+
var translation = translateGoogle((String) texto, Locale.getDefault().getLanguage()).get();
78+
translated.add(translation);
5979
}
60-
});
80+
81+
var currentMethod = (Method) param.method;
82+
var unityTranslationResultClass = currentMethod.getReturnType();
83+
return unityTranslationResultClass.getConstructor(String[].class, float.class, int.class).newInstance(translated.toArray(new String[0]), 1, 0);
84+
}
85+
});
86+
}
87+
88+
if (pre21Method == null && newMethod == null) throw new Exception("GoogleTranslate method not found");
6189
}
6290

6391
public CompletableFuture<String> translateGoogle(String text, String languageDest) {

app/src/main/res/values/arrays.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,15 @@
120120
<item>2.24.18.xx</item>
121121
<item>2.24.19.xx</item>
122122
<item>2.24.20.xx</item>
123+
<item>2.24.21.xx</item>
123124
</string-array>
124125
<string-array name="supported_versions_business">
125126
<item>2.24.16.xx</item>
126127
<item>2.24.17.xx</item>
127128
<item>2.24.18.xx</item>
128129
<item>2.24.19.xx</item>
130+
<item>2.24.20.xx</item>
131+
<item>2.24.21.xx</item>
129132
</string-array>
130133
<string-array name="image_picker">
131134
<item>image/*</item>

0 commit comments

Comments
 (0)