Skip to content

Commit

Permalink
Add Broadcast icon from messages
Browse files Browse the repository at this point in the history
Signed-off-by: Dev4Mod <[email protected]>
  • Loading branch information
Dev4Mod committed Jan 13, 2025
1 parent 7a60eec commit ff026a7
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
import com.wmods.wppenhacer.xposed.features.privacy.HideChat;
import com.wmods.wppenhacer.xposed.features.privacy.HideReceipt;
import com.wmods.wppenhacer.xposed.features.privacy.HideSeen;
import com.wmods.wppenhacer.xposed.features.privacy.HideTagForward;
import com.wmods.wppenhacer.xposed.features.privacy.TagMessage;
import com.wmods.wppenhacer.xposed.features.privacy.TypingPrivacy;
import com.wmods.wppenhacer.xposed.features.privacy.ViewOnce;
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
Expand Down Expand Up @@ -282,7 +282,7 @@ private static void plugins(@NonNull ClassLoader loader, @NonNull XSharedPrefere
HideChat.class,
HideReceipt.class,
HideSeen.class,
HideTagForward.class,
TagMessage.class,
HideTabs.class,
IGStatus.class,
LiteMode.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class FMessageWpp {
private static Field mediaTypeField;
private static Method getOriginalMessageKey;
private static Class abstractMediaMessageClass;
private static Field broadcastField;
private final Object fmessage;

public FMessageWpp(Object fMessage) {
Expand Down Expand Up @@ -51,6 +52,7 @@ public static void init(ClassLoader classLoader) throws Exception {
mediaTypeField = Unobfuscator.loadMediaTypeField(classLoader);
getOriginalMessageKey = Unobfuscator.loadOriginalMessageKey(classLoader);
abstractMediaMessageClass = Unobfuscator.loadAbstractMediaMessageClass(classLoader);
broadcastField = Unobfuscator.loadBroadcastTagField(classLoader);
}

public Object getUserJid() {
Expand Down Expand Up @@ -99,6 +101,15 @@ public Key getOriginalKey() {
return null;
}

public boolean isBroadcast() {
try {
return (boolean) broadcastField.get(fmessage);
} catch (Exception e) {
XposedBridge.log(e);
}
return false;
}

public Object getObject() {
return fmessage;
}
Expand Down Expand Up @@ -152,10 +163,10 @@ public int getMediaType() {
public static class Key {
public static Class<?> TYPE;

public final Object thisObject;
public final String messageID;
public final boolean isFromMe;
public final Object remoteJid;
public Object thisObject;
public String messageID;
public boolean isFromMe;
public Object remoteJid;

public Key(Object key) {
this.thisObject = key;
Expand All @@ -164,6 +175,20 @@ public Key(Object key) {
this.remoteJid = XposedHelpers.getObjectField(key, "A00");
}

public void setIsFromMe(boolean value) {
XposedHelpers.setBooleanField(thisObject, "A02", value);
this.isFromMe = value;
}

public void setRemoteJid(Object value) {
XposedHelpers.setObjectField(thisObject, "A00", value);
this.remoteJid = value;
}

public void setMessageID(String messageID) {
XposedHelpers.setObjectField(thisObject, "A01", messageID);
this.messageID = messageID;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,39 @@ public synchronized static Method loadForwardTagMethod(ClassLoader classLoader)
});
}

public synchronized static Field loadBroadcastTagField(ClassLoader classLoader) throws Exception {
return UnobfuscatorCache.getInstance().getField(classLoader, () -> {
var fmessage = loadFMessageClass(classLoader);
var clazzData = dexkit.findClass(FindClass.create().matcher(ClassMatcher.create().addUsingString("UPDATE_MESSAGE_MAIN_BROADCAST_SCAN_SQL")));
if (clazzData.isEmpty()) return new Exception("BroadcastTag class not found");
var methodData = dexkit.findMethod(FindMethod.create().searchInClass(clazzData).matcher(MethodMatcher.create().usingStrings("participant_hash", "view_mode", "broadcast")));
if (methodData.isEmpty()) throw new Exception("BroadcastTag method support not found");
var usingFields = methodData.get(0).getUsingFields();
for (var ufield : usingFields) {
var field = ufield.getField();
if (field.getDeclaredClass().getName().equals(fmessage.getName()) &&
field.getType().getName().equals(boolean.class.getName())
) {
return field.getFieldInstance(classLoader);
}
}
throw new Exception("BroadcastTag field not found");
});
}

public synchronized static Method loadBroadcastTagMethod(ClassLoader classLoader) throws Exception {
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> {
var field = loadBroadcastTagField(classLoader);
var clazzData = dexkit.findClass(FindClass.create().matcher(ClassMatcher.create().addUsingString("ConversationRow/setUpUserNameInGroupView")));
if (clazzData.isEmpty())
throw new Exception("BroadcastTag: ConversationRow Class not found");
var method = dexkit.findMethod(FindMethod.create().searchInClass(clazzData).matcher(MethodMatcher.create().addUsingField(DexSignUtil.getFieldDescriptor(field))));
if (method.isEmpty())
throw new Exception("BroadcastTag: ConversationRow Method not found");
return method.get(0).getMethodInstance(classLoader);
});
}

public synchronized static Class<?> loadForwardClassMethod(ClassLoader classLoader) throws Exception {
return UnobfuscatorCache.getInstance().getClass(classLoader, () -> findFirstClassUsingStrings(classLoader, StringMatchType.Contains, "UserActions/userActionForwardMessage"));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.wmods.wppenhacer.xposed.features.privacy;

import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.wmods.wppenhacer.xposed.core.Feature;
import com.wmods.wppenhacer.xposed.core.components.FMessageWpp;
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
import com.wmods.wppenhacer.xposed.utils.Utils;

import java.lang.reflect.Method;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

public class TagMessage extends Feature {
public TagMessage(ClassLoader loader, XSharedPreferences preferences) {
super(loader, preferences);
}

@Override
public void doHook() throws Exception {

Method method = Unobfuscator.loadForwardTagMethod(classLoader);
logDebug(Unobfuscator.getMethodDescriptor(method));
Class<?> forwardClass = Unobfuscator.loadForwardClassMethod(classLoader);
logDebug("ForwardClass: " + forwardClass.getName());

XposedBridge.hookMethod(method, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!prefs.getBoolean("hidetag", false)) return;
var arg = (long) param.args[0];
logDebug("arg: " + arg);
if (arg == 1) {
if (ReflectionUtils.isCalledFromClass(forwardClass)) {
param.args[0] = 0;
}
}
}
});

if (prefs.getBoolean("broadcast_tag", false)) {
hookBroadcastView();
}
}

private void hookBroadcastView() throws Exception {
Method method1 = Unobfuscator.loadBroadcastTagMethod(classLoader);

XposedBridge.hookMethod(method1, new XC_MethodHook() {
private FMessageWpp.Key keyObj;

@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
keyObj = null;
var fmessage = new FMessageWpp(param.args[0]);
var key = fmessage.getKey();
if (!key.isFromMe && fmessage.isBroadcast()) {
var view = (ViewGroup) param.thisObject;
var res = view.findViewById((int) param.args[1]);
if (res == null) {
var dateWrapper = (ViewGroup) view.findViewById(Utils.getID("date_wrapper", "id"));
var broadcast = new ImageView(view.getContext());
broadcast.setId((int) param.args[1]);
dateWrapper.addView(broadcast, 0);
}
key.setIsFromMe(true);
keyObj = key;
}
}

protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (keyObj != null) {
var find = XposedHelpers.getObjectField(param.thisObject, "A2u");
keyObj.setIsFromMe(false);
}
}

});
}

@NonNull
@Override
public String getPluginName() {
return "Tag Message";
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,6 @@
<string name="change_default_dpi">Change Default DPI</string>
<string name="change_default_dpi_sum">Change the DPI setting for the application. Use 0 to reset to default.</string>
<string name="no_contact_with_custom_privacy">No contact with custom privacy!</string>
<string name="show_chat_broadcast_icon">Show chat broadcast icon</string>
<string name="show_chat_broadcast_icon_sum">Shows an icon if the contact sent a message via broadcast</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/preference_general_conversation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
app:summary="@string/antidisappearing_sum"
app:title="@string/antidisappearing" />

<rikka.material.preference.MaterialSwitchPreference
app:key="broadcast_tag"
app:summary="@string/show_chat_broadcast_icon_sum"
app:title="@string/show_chat_broadcast_icon" />

<rikka.material.preference.MaterialSwitchPreference
app:key="pinnedlimit"
app:summary="@string/disable_pinned_limit_sum"
Expand Down

0 comments on commit ff026a7

Please sign in to comment.