Skip to content

Commit

Permalink
Add more tasker events
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev4Mod committed Jun 15, 2024
1 parent 812cb04 commit 93df56f
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 79 deletions.
15 changes: 3 additions & 12 deletions app/src/main/java/com/wmods/wppenhacer/xposed/core/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
debugMethods(param.thisObject.getClass(), param.thisObject);
}
if (printTrace) {
XposedBridge.log(new Exception("print trace"));
for (var trace : Thread.currentThread().getStackTrace()) {
XposedBridge.log("TRACE: " + trace.toString());
}
}
XposedBridge.log("-----------------HOOKED DEBUG END-----------------------------\n\n");
}
Expand All @@ -142,17 +144,6 @@ public static void debugMethods(Class<?> cls, Object thisObject) {
}
}


public static void setWritePermissions(File file) {
try {
file.setWritable(true, false);
file.setReadable(true, false);
file.setExecutable(true, false);
} catch (Exception e) {
e.printStackTrace();
}
}

public static String getDestination(SharedPreferences prefs, File file, String name) {
var folderPath = prefs.getString("localdownload", Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download") + "/WhatsApp/Wa Enhancer/" + name + "/";
var filePath = new File(folderPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundl

@Override
public void onActivityStarted(@NonNull Activity activity) {
checkIsConversation(activity, WppCore.ObjectOnChangeListener.TYPE_START);
checkIsConversation(activity, WppCore.ObjectOnChangeListener.ChangeType.START);
}

@SuppressLint("ApplySharedPref")
Expand All @@ -41,23 +41,23 @@ public void onActivityResumed(@NonNull Activity activity) {
} catch (Exception ignored) {
}
}
checkIsConversation(activity, WppCore.ObjectOnChangeListener.TYPE_RESUME);
checkIsConversation(activity, WppCore.ObjectOnChangeListener.ChangeType.RESUME);
}

@Override
public void onActivityPaused(@NonNull Activity activity) {
checkIsConversation(activity, WppCore.ObjectOnChangeListener.TYPE_PAUSE);
checkIsConversation(activity, WppCore.ObjectOnChangeListener.ChangeType.PAUSE);
}

@Override
public void onActivityStopped(@NonNull Activity activity) {
checkIsConversation(activity, WppCore.ObjectOnChangeListener.TYPE_END);
checkIsConversation(activity, WppCore.ObjectOnChangeListener.ChangeType.END);
}

private static void checkIsConversation(@NonNull Activity activity, int type) {
private static void checkIsConversation(@NonNull Activity activity, WppCore.ObjectOnChangeListener.ChangeType type) {
Class<?> conversation = XposedHelpers.findClass("com.whatsapp.Conversation", activity.getClassLoader());
if (conversation.isInstance(activity)) {
WppCore.mConversation = type == WppCore.ObjectOnChangeListener.TYPE_PAUSE || WppCore.ObjectOnChangeListener.TYPE_END == type ? null : activity;
WppCore.mConversation = type == WppCore.ObjectOnChangeListener.ChangeType.PAUSE || WppCore.ObjectOnChangeListener.ChangeType.END == type ? null : activity;
for (WppCore.ObjectOnChangeListener listener : WppCore.listenerChat) {
listener.onChange(activity, type);
}
Expand Down
25 changes: 11 additions & 14 deletions app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ public class WppCore {
public static void addMenuItemClass(Class<?> aClass, OnMenuCreate listener) {
var list = listenerMenu.computeIfAbsent(aClass, k -> new ArrayList<>());
list.add(listener);
}

public static void addMenuItemString(String className, OnMenuCreate listener) {
var classLoader = Utils.getApplication().getClassLoader();
var aClass = XposedHelpers.findClass(className, classLoader);
var list = listenerMenu.computeIfAbsent(aClass, k -> new ArrayList<>());
list.add(listener);
}

// public static void addMenuItemString(String className, OnMenuCreate listener) {
// var classLoader = Utils.getApplication().getClassLoader();
// var aClass = XposedHelpers.findClass(className, classLoader);
// var list = listenerMenu.computeIfAbsent(aClass, k -> new ArrayList<>());
// list.add(listener);
// }

public static Object getConversation() {
return mConversation;
}
Expand Down Expand Up @@ -91,13 +92,12 @@ public static void sendMessage(String number, String message) {


public interface ObjectOnChangeListener {
public static int TYPE_START = 0;
public static int TYPE_END = 1;
public static int TYPE_RESUME = 2;
public static int TYPE_PAUSE = 3;

void onChange(Object object, int type);
void onChange(Object object, ChangeType type);

enum ChangeType {
START, END, RESUME, PAUSE
}
}

public static void Initialize(ClassLoader loader) throws Exception {
Expand Down Expand Up @@ -174,11 +174,8 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
mActionUser = param.thisObject;
XposedBridge.log("mActionUser: " + mActionUser);
}
});


}

public static int getDefaultTheme() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ private int antiRevoke(Object objMessage) {
}

private void showToast(Object fMessage) {
if (!prefs.getBoolean("toastdeleted", false)) return;
var jidAuthor = getJidAuthor(fMessage);

var messageSuffix = Utils.getApplication().getString(ResId.string.deleted_message);
if (Objects.equals(stripJID(jidAuthor), "status")) {
var isStatus = Objects.equals(stripJID(jidAuthor), "status");
if (isStatus) {
messageSuffix = Utils.getApplication().getString(ResId.string.deleted_status);
var getUserJid = ReflectionUtils.findMethodUsingFilter(fieldMessageKey.getDeclaringClass(), method -> method.getReturnType().equals(XposedHelpers.findClass("com.whatsapp.jid.UserJid", classLoader)));
jidAuthor = WppCore.getRawString(ReflectionUtils.callMethod(getUserJid, fMessage));
Expand All @@ -273,7 +273,10 @@ private void showToast(Object fMessage) {
name = stripJID(jidAuthor);
}
String message = name + " " + messageSuffix;
Utils.showToast(message, Toast.LENGTH_SHORT);
if (prefs.getBoolean("toastdeleted", false)) {
Utils.showToast(message, Toast.LENGTH_SHORT);
}
Tasker.sendTaskerEvent(WppCore.stripJID(jidAuthor), isStatus ? "status_deleted" : "message_deleted");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public CallPrivacy(@NonNull ClassLoader loader, @NonNull XSharedPreferences pref
public void doHook() throws Throwable {

var onCallReceivedMethod = Unobfuscator.loadAntiRevokeOnCallReceivedMethod(classLoader);
// var callEndMethod = Unobfuscator.loadAntiRevokeCallEndMethod(loader);
// var callState = Enum.valueOf((Class<Enum>) XposedHelpers.findClass("com.whatsapp.voipcalling.CallState", loader), "ACTIVE");

XposedBridge.hookMethod(onCallReceivedMethod, new XC_MethodHook() {
@Override
Expand All @@ -40,6 +38,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
var userJid = XposedHelpers.callMethod(callinfo, "getPeerJid");
var callId = XposedHelpers.callMethod(callinfo, "getCallId");
var type = Integer.parseInt(prefs.getString("call_privacy", "0"));
Tasker.sendTaskerEvent(WppCore.stripJID(WppCore.getRawString(userJid)), "call_received");
var block = false;
switch (type) {
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ public void doHook() throws Exception {
addgrpAdminIcon();
}

if (showOnline) {
showOnline();
}
showOnline(showOnline);

if (filter_itens != null) {
filterItens(filter_itens);
Expand All @@ -171,9 +169,8 @@ public void doHook() throws Exception {
autoNextStatus();
}

if (toast_viewed_status | toast_viewed_message) {
toast_viewed(toast_viewed_status, toast_viewed_message);
}
toast_viewed(toast_viewed_status, toast_viewed_message);

}

private void toast_viewed(boolean toast_viewed_status, boolean toast_viewed_message) throws Exception {
Expand All @@ -196,15 +193,19 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
var sql = MessageStore.database.getReadableDatabase();
try (var result = sql.query("status", null, "message_table_id = ?", new String[]{String.valueOf(id)}, null, null, null)) {
if (result.moveToNext()) {
if (toast_viewed_status)
if (toast_viewed_status) {
Utils.showToast(String.format("%s viewed your status", contactName), Toast.LENGTH_LONG);
} else if (toast_viewed_message && !Objects.equals(WppCore.getCurrentRawJID(), raw)) {
}
Tasker.sendTaskerEvent(WppCore.stripJID(raw), "status_viewed");
} else if (!Objects.equals(WppCore.getCurrentRawJID(), raw)) {
try (var result2 = sql.query("message", null, "_id = ?", new String[]{String.valueOf(id)}, null, null, null)) {
if (result2.moveToNext()) {
var chat_id = result2.getLong(result2.getColumnIndexOrThrow("chat_row_id"));
try (var result3 = sql.query("chat", null, "_id = ? AND subject IS NULL", new String[]{String.valueOf(chat_id)}, null, null, null)) {
if (result3.moveToNext()) {
Utils.showToast(String.format("%s viewed your message", contactName), Toast.LENGTH_LONG);
if (toast_viewed_message)
Utils.showToast(String.format("%s viewed your message", contactName), Toast.LENGTH_LONG);
Tasker.sendTaskerEvent(WppCore.stripJID(raw), "message_viewed");
}
}
}
Expand Down Expand Up @@ -259,7 +260,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
});
}

private void showOnline() throws Exception {
private void showOnline(boolean showOnline) throws Exception {
var checkOnlineMethod = Unobfuscator.loadCheckOnlineMethod(classLoader);
XposedBridge.hookMethod(checkOnlineMethod, new XC_MethodHook() {
@Override
Expand All @@ -271,7 +272,9 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (WppCore.isGroup(jid)) return;
var name = WppCore.getContactName(WppCore.createUserJid(jid));
name = TextUtils.isEmpty(name) ? WppCore.stripJID(jid) : name;
Utils.showToast(String.format(Utils.getApplication().getString(ResId.string.toast_online), name), Toast.LENGTH_SHORT);
if (showOnline)
Utils.showToast(String.format(Utils.getApplication().getString(ResId.string.toast_online), name), Toast.LENGTH_SHORT);
Tasker.sendTaskerEvent(WppCore.stripJID(jid), "contact_online");
}
});
}
Expand Down Expand Up @@ -434,10 +437,16 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
var item = menu.add(0, 0, 0, "Save");
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
var icon = DesignUtils.getDrawableByName("ic_action_download");
icon.setTint(Color.WHITE);
item.setIcon(icon);
if (icon != null) {
icon.setTint(Color.WHITE);
item.setIcon(icon);
}
item.setOnMenuItemClickListener(menuItem -> {
var subCls = param.thisObject.getClass().getSuperclass();
if (subCls == null) {
log(new Exception("SubClass is null"));
return true;
}
var field = Unobfuscator.getFieldByType(subCls, loadProfileInfoField.getDeclaringClass());
var jidObj = ReflectionUtils.getField(loadProfileInfoField, ReflectionUtils.getField(field, param.thisObject));
var jid = WppCore.stripJID(WppCore.getRawString(jidObj));
Expand Down Expand Up @@ -498,15 +507,6 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
});
}

// private static void restartApp(Activity home) {
// Intent intent = Utils.getApplication().getPackageManager().getLaunchIntentForPackage(Utils.getApplication().getPackageName());
// if (intent != null) {
// home.finishAffinity();
// Utils.getApplication().startActivity(intent);
// }
// Runtime.getRuntime().exit(0);
// }

private void hookStickers() throws Exception {
var sendStickerMethod = Unobfuscator.loadSendStickerMethod(classLoader);
XposedBridge.hookMethod(sendStickerMethod, new XC_MethodHook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
Expand All @@ -21,14 +22,16 @@

public class Tasker extends Feature {
private static Object fMessage;
private static boolean taskerEnabled;

public Tasker(@NonNull ClassLoader classLoader, @NonNull XSharedPreferences preferences) {
super(classLoader, preferences);
}

@Override
public void doHook() throws Throwable {
if (!prefs.getBoolean("tasker", false)) return;
taskerEnabled = prefs.getBoolean("tasker", false);
if (!taskerEnabled) return;
hookReceiveMessage();
registerSenderMessage();
}
Expand All @@ -44,6 +47,27 @@ private void registerSenderMessage() {
ContextCompat.registerReceiver(Utils.getApplication(), new SenderMessageBroadcastReceiver(), filter, ContextCompat.RECEIVER_EXPORTED);
}

public static void sendTaskerEvent(String number, String event) {
if (!taskerEnabled) return;
Intent intent = new Intent("com.wmods.wppenhacer.EVENT");
intent.putExtra("number", number);
intent.putExtra("event", event);
Utils.getApplication().sendBroadcast(intent);
}

public static class SenderMessageBroadcastReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
XposedBridge.log("Message sent");
var number = intent.getStringExtra("number");
var message = intent.getStringExtra("message");
if (number == null || message == null) return;
number = number.replaceAll("\\D", "");
WppCore.sendMessage(number, message);
}
}

public void hookReceiveMessage() throws Throwable {
var method = Unobfuscator.loadReceiptMethod(classLoader);
var method2 = Unobfuscator.loadReceiptOutsideChat(classLoader);
Expand All @@ -66,6 +90,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
var rawJid = WppCore.getRawString(userJid);
var number = WppCore.stripJID(rawJid);
var msg = (String) newMessageMethod.invoke(fMessage);
if (TextUtils.isEmpty(msg) || TextUtils.isEmpty(number)) return;
new Handler(Utils.getApplication().getMainLooper()).post(() -> {
Intent intent = new Intent("com.wmods.wppenhacer.MESSAGE_RECEIVED");
intent.putExtra("number", number);
Expand All @@ -77,18 +102,4 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

}

public static class SenderMessageBroadcastReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
XposedBridge.log("Message sent");
var number = intent.getStringExtra("number");
var message = intent.getStringExtra("message");
if (number == null || message == null) return;
number = number.replaceAll("\\D", "");
WppCore.sendMessage(number, message);
}
}


}
14 changes: 9 additions & 5 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[DISABLE AUTO SKIP STATUS]
* Fix bug in skip pages
[TASKER]
added the event "com.wmods.wppenhacer.EVENT" with the parameters "%number" and "%event" with the following events:
viewed_message: message read
deleted_message: message deleted
viewed_status: status viewed
deleted_status: deleted status
contact_online: online contact
call_received: received call

[TOAST ON EVENT]
* Add function to show toast on viewed your message
* Add function to show toast on viewed your status
NOTE: it works even if an event option is disabled in Wa Enhancer so you can create your own custom toast

0 comments on commit 93df56f

Please sign in to comment.