Skip to content

Commit

Permalink
refactor: refine base hook logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cinit committed Oct 30, 2024
1 parent 68628e2 commit 732db33
Show file tree
Hide file tree
Showing 33 changed files with 196 additions and 31 deletions.
16 changes: 15 additions & 1 deletion app/src/main/java/cc/hicore/message/chat/SessionHooker.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
package cc.hicore.message.chat;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import cc.hicore.QApp.QAppUtils;
import cc.hicore.ReflectUtil.XField;
import cc.hicore.hook.RepeaterPlus;
import cc.hicore.hook.stickerPanel.Hooker.StickerPanelEntryHooker;
import com.google.common.collect.Lists;
import io.github.qauxv.base.ITraceableDynamicHook;
import io.github.qauxv.base.RuntimeErrorTracer;
import io.github.qauxv.base.annotation.EntityAgentEntry;
import io.github.qauxv.util.xpcompat.XC_MethodHook;
import io.github.qauxv.util.xpcompat.XposedBridge;
import io.github.qauxv.base.IDynamicHook;
Expand All @@ -37,9 +42,12 @@
import io.github.qauxv.util.dexkit.AIO_Destroy_QQNT;
import io.github.qauxv.util.dexkit.DexKit;
import io.github.qauxv.util.dexkit.DexKitTarget;
import java.util.Collections;
import java.util.List;
import java.util.Stack;
import me.ketal.hook.MultiActionHook;

@EntityAgentEntry
@FunctionHookEntry
public class SessionHooker extends BaseHookDispatcher<SessionHooker.IAIOParamUpdate> {

Expand Down Expand Up @@ -106,8 +114,14 @@ public boolean isEnabled() {
return QAppUtils.isQQnt() && super.isEnabled();
}

public interface IAIOParamUpdate extends IDynamicHook {
public interface IAIOParamUpdate extends ITraceableDynamicHook {

void onAIOParamUpdate(Object AIOParam);

@Nullable
@Override
default List<RuntimeErrorTracer> getRuntimeErrorDependentComponents() {
return Lists.asList(SessionHooker.INSTANCE, RuntimeErrorTracer.EMPTY_ARRAY);
}
}
}
14 changes: 11 additions & 3 deletions app/src/main/java/cc/ioctl/hook/experimental/CardMsgSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@
import androidx.annotation.Nullable;
import cc.hicore.QApp.QAppUtils;
import cc.hicore.message.chat.SessionUtils;
import com.google.common.collect.Lists;
import com.tencent.qqnt.kernel.nativeinterface.ArkElement;
import com.tencent.qqnt.kernel.nativeinterface.MsgElement;
import io.github.qauxv.base.IDynamicHook;
import io.github.qauxv.base.RuntimeErrorTracer;
import io.github.qauxv.base.annotation.FunctionHookEntry;
import io.github.qauxv.base.annotation.UiItemAgentEntry;
import io.github.qauxv.bridge.AppRuntimeHelper;
import io.github.qauxv.bridge.kernelcompat.ContactCompat;
import io.github.qauxv.dsl.FunctionEntryRouter.Locations.Auxiliary;
import io.github.qauxv.remote.TransactionHelper;
import io.github.qauxv.router.decorator.BaseSwitchFunctionDecorator;
import io.github.qauxv.router.decorator.IBaseChatPieDecorator;
import io.github.qauxv.router.decorator.IInputButtonDecorator;
import io.github.qauxv.router.dispacher.InputButtonHookDispatcher;
import io.github.qauxv.util.SyncUtils;
Expand All @@ -53,6 +56,7 @@
import io.github.qauxv.util.dexkit.NBaseChatPie_init;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import me.singleneuron.data.CardMsgCheckResult;
import me.singleneuron.util.KotlinUtilsKt;
import mqq.app.AppRuntime;
Expand Down Expand Up @@ -162,14 +166,14 @@ public boolean onFunBtnLongClick(@NonNull String text,
@NonNull
private static MsgElement getArkMsgElement(@NonNull String text) {
MsgElement msgElement = new MsgElement();
ArkElement arkElement = new ArkElement(text,null,null);
ArkElement arkElement = new ArkElement(text, null, null);
msgElement.setArkElement(arkElement);
msgElement.setElementType(10);
return msgElement;
}

private void sendCard(String text, View sendBtn, EditText input, Context ctx1, AppRuntime qqApp, Parcelable session) throws Exception {
if (QAppUtils.isQQnt()){
if (QAppUtils.isQQnt()) {
try {
new JSONObject(text);
CardMsgCheckResult check = KotlinUtilsKt.checkCardMsg(text);
Expand Down Expand Up @@ -205,7 +209,11 @@ private void sendCard(String text, View sendBtn, EditText input, Context ctx1, A

}


@Nullable
@Override
public List<RuntimeErrorTracer> getRuntimeErrorDependentComponents() {
return Lists.newArrayList(InputButtonHookDispatcher.INSTANCE);
}

@SuppressWarnings("JavaJniMissingFunction")
static native boolean ntSendCardMsg(AppRuntime rt, Parcelable session, String msg) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import cc.ioctl.fragment.FakeBatteryConfigFragment;
import cc.ioctl.util.HostInfo;
import io.github.qauxv.base.IEntityAgent;
import io.github.qauxv.base.RuntimeErrorTracer;
import io.github.qauxv.util.xpcompat.XC_MethodHook;
import io.github.qauxv.util.xpcompat.XposedBridge;
import io.github.qauxv.util.xpcompat.XposedHelpers;
Expand All @@ -60,6 +61,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
Expand Down Expand Up @@ -446,4 +448,10 @@ public Function2<IUiItemAgent, Context, String[]> getExtraSearchKeywordProvider(
return null;
}
};

@Nullable
@Override
public List<RuntimeErrorTracer> getRuntimeErrorDependentComponents() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import io.github.qauxv.activity.SettingsUiFragmentHostActivity.Companion.startFr
import io.github.qauxv.base.IEntityAgent
import io.github.qauxv.base.ISwitchCellAgent
import io.github.qauxv.base.IUiItemAgent
import io.github.qauxv.base.RuntimeErrorTracer
import io.github.qauxv.base.annotation.FunctionHookEntry
import io.github.qauxv.base.annotation.UiItemAgentEntry
import io.github.qauxv.bridge.AppRuntimeHelper
Expand All @@ -53,6 +54,7 @@ object FriendDeletionNotification : BaseFunctionHook(defaultEnabled = true), IUi
override var isEnabled = true
override val onClickListener: ((IUiItemAgent, Activity, View) -> Unit)? = null
override val extraSearchKeywordProvider: ((IUiItemAgent, Context) -> Array<String>?)? = null
override val runtimeErrorDependentComponents: List<RuntimeErrorTracer>? = null

override val switchProvider by lazy {
object : ISwitchCellAgent {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/cc/ioctl/hook/notification/AntiMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package cc.ioctl.hook.notification

import cc.ioctl.util.msg.MessageReceiver
import cc.ioctl.util.MsgRecordUtil
import io.github.qauxv.base.RuntimeErrorTracer
import io.github.qauxv.base.annotation.UiItemAgentEntry
import io.github.qauxv.dsl.FunctionEntryRouter
import io.github.qauxv.util.QQVersion
Expand Down Expand Up @@ -57,6 +58,12 @@ object AntiMessage : MultiItemDelayableHook("qn_anti_message_items"), MessageRec
return false
}

override fun initOnce(): Boolean {
return MessageInterception.initialize()
}

override val runtimeErrorDependentComponents: List<RuntimeErrorTracer> = listOf(MessageInterception)

override val isAvailable: Boolean get() = requireMinQQVersion(QQVersion.QQ_8_2_0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,35 @@ package cc.ioctl.hook.notification

import cc.ioctl.util.Reflex
import cc.ioctl.util.msg.MessageManager
import io.github.qauxv.util.xpcompat.XC_MethodHook
import cc.ioctl.util.msg.MessageReceiver
import cn.lliiooll.hook.AntiRobotMessage
import io.github.qauxv.base.annotation.EntityAgentEntry
import io.github.qauxv.base.annotation.FunctionHookEntry
import io.github.qauxv.hook.BasePersistBackgroundHook
import io.github.qauxv.hook.BaseHookDispatcher
import io.github.qauxv.util.Initiator
import io.github.qauxv.util.QQVersion
import io.github.qauxv.util.hostInfo
import io.github.qauxv.util.requireMinQQVersion
import io.github.qauxv.util.xpcompat.XC_MethodHook
import me.singleneuron.data.MsgRecordData
import me.singleneuron.hook.decorator.RegexAntiMeg
import xyz.nextalone.util.clazz
import xyz.nextalone.util.hookAfter
import xyz.nextalone.util.method
import xyz.nextalone.util.methodWithSuper
import xyz.nextalone.util.throwOrTrue

@EntityAgentEntry
@FunctionHookEntry
object MessageInterception : BasePersistBackgroundHook() {
object MessageInterception : BaseHookDispatcher<MessageReceiver>(arrayOf()) {

override val decorators: Array<MessageReceiver> = arrayOf(
// 在这里添加消息处理
RegexAntiMeg,
AntiMessage,
AntiRobotMessage,
)

override fun initOnce() = throwOrTrue {
val callback: (XC_MethodHook.MethodHookParam) -> Unit = { param ->
val msgRecordData = MsgRecordData(param.args[0])
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/cc/ioctl/hook/ui/chat/RepeaterHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import cc.ioctl.util.LayoutHelper;
import cc.ioctl.util.Reflex;
import io.github.qauxv.base.IEntityAgent;
import io.github.qauxv.base.RuntimeErrorTracer;
import io.github.qauxv.util.xpcompat.XC_MethodHook;
import io.github.qauxv.base.ISwitchCellAgent;
import io.github.qauxv.base.IUiItemAgent;
Expand All @@ -68,6 +69,8 @@
import io.github.qauxv.util.dexkit.CFaceDe;
import io.github.qauxv.util.dexkit.DexKitTarget;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;
Expand Down Expand Up @@ -598,4 +601,10 @@ public static View findView(String Name, ViewGroup vg)
}
return null;
}

@Nullable
@Override
public List<RuntimeErrorTracer> getRuntimeErrorDependentComponents() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.github.qauxv.base.IEntityAgent;
import io.github.qauxv.base.ISwitchCellAgent;
import io.github.qauxv.base.IUiItemAgent;
import io.github.qauxv.base.RuntimeErrorTracer;
import io.github.qauxv.base.annotation.FunctionHookEntry;
import io.github.qauxv.base.annotation.UiItemAgentEntry;
import io.github.qauxv.config.ConfigManager;
Expand Down Expand Up @@ -320,4 +321,10 @@ public boolean isEnabled() {
public void setEnabled(boolean value) {
// unsupported
}

@Nullable
@Override
public List<RuntimeErrorTracer> getRuntimeErrorDependentComponents() {
return null;
}
}
12 changes: 2 additions & 10 deletions app/src/main/java/cc/ioctl/util/msg/MessageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,15 @@
package cc.ioctl.util.msg;

import androidx.annotation.NonNull;
import cc.ioctl.hook.notification.AntiMessage;
import cn.lliiooll.hook.AntiRobotMessage;
import cc.ioctl.hook.notification.MessageInterception;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import me.singleneuron.hook.decorator.RegexAntiMeg;
import me.singleneuron.data.MsgRecordData;

public class MessageManager {

private static final Map<Long, Long> MSG = new ConcurrentHashMap<>();

private static final MessageReceiver[] receivers = {
// 在这里添加消息处理
RegexAntiMeg.INSTANCE,
AntiMessage.INSTANCE,
AntiRobotMessage.INSTANCE,
};
public static Class<?> intType = int.class;
public static Class<?> booleanType = boolean.class;

Expand All @@ -54,7 +46,7 @@ public static void call(@NonNull MsgRecordData data) {
}

// 以上是为了防止消息重复广播
for (MessageReceiver receiver : receivers) {
for (MessageReceiver receiver : MessageInterception.INSTANCE.getDecorators()) {
if (receiver.onReceive(data)) {
// 返回true退出遍历
break;
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/cc/ioctl/util/msg/MessageReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@

package cc.ioctl.util.msg;

import androidx.annotation.Nullable;
import cc.ioctl.hook.notification.MessageInterception;
import com.google.common.collect.Lists;
import io.github.qauxv.base.ITraceableDynamicHook;
import io.github.qauxv.base.RuntimeErrorTracer;
import java.util.List;
import me.singleneuron.data.MsgRecordData;

public interface MessageReceiver {
public interface MessageReceiver extends ITraceableDynamicHook {

/**
* 当拦截到消息时会调用此方法
Expand All @@ -33,4 +39,11 @@ public interface MessageReceiver {
* @return 如果返回为真将不会向下传递拦截到的消息
*/
boolean onReceive(MsgRecordData data);

@Nullable
@Override
default List<RuntimeErrorTracer> getRuntimeErrorDependentComponents() {
return Lists.asList(MessageInterception.INSTANCE, RuntimeErrorTracer.EMPTY_ARRAY);
}

}
13 changes: 8 additions & 5 deletions app/src/main/java/cn/lliiooll/hook/AntiRobotMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package cn.lliiooll.hook

import cc.ioctl.hook.notification.MessageInterception
import cc.ioctl.util.msg.MessageReceiver
import io.github.qauxv.base.RuntimeErrorTracer
import io.github.qauxv.util.xpcompat.XposedHelpers
import io.github.qauxv.base.annotation.FunctionHookEntry
import io.github.qauxv.base.annotation.UiItemAgentEntry
Expand All @@ -36,7 +37,7 @@ import xyz.nextalone.util.invoke
// 自动已读群机器人消息
@FunctionHookEntry
@UiItemAgentEntry
object AntiRobotMessage : CommonSwitchFunctionHook("ll_anti_robot_message"),MessageReceiver {
object AntiRobotMessage : CommonSwitchFunctionHook("ll_anti_robot_message"), MessageReceiver {
override val name: String
get() = "自动已读群机器人消息"

Expand All @@ -48,14 +49,16 @@ object AntiRobotMessage : CommonSwitchFunctionHook("ll_anti_robot_message"),Mess
get() = FunctionEntryRouter.Locations.Auxiliary.NOTIFICATION_CATEGORY

override fun onReceive(data: MsgRecordData?): Boolean {
if (data != null && isEnabled){
if (data != null && isEnabled) {
val runtime = AppRuntimeHelper.getAppRuntime()
val service = runtime?.invoke("getRuntimeService","com.tencent.mobileqq.troop.robot.api.ITroopRobotService".clazz!!,Class::class.java)
val isRobot = service?.invoke("isRobotUin", data.senderUin!!,String::class.java)as Boolean
if (isRobot){
val service = runtime?.invoke("getRuntimeService", "com.tencent.mobileqq.troop.robot.api.ITroopRobotService".clazz!!, Class::class.java)
val isRobot = service?.invoke("isRobotUin", data.senderUin!!, String::class.java) as Boolean
if (isRobot) {
XposedHelpers.setBooleanField(data.msgRecord, "isread", true)
}
}
return false
}

override val runtimeErrorDependentComponents: List<RuntimeErrorTracer> = listOf(MessageInterception)
}
4 changes: 4 additions & 0 deletions app/src/main/java/com/xiaoniu/hook/CtrlEnterToSend.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import cc.hicore.QApp.QAppUtils
import io.github.qauxv.base.RuntimeErrorTracer
import io.github.qauxv.base.annotation.FunctionHookEntry
import io.github.qauxv.base.annotation.UiItemAgentEntry
import io.github.qauxv.dsl.FunctionEntryRouter
import io.github.qauxv.hook.CommonSwitchFunctionHook
import io.github.qauxv.router.decorator.IBaseChatPieInitDecorator
import io.github.qauxv.router.dispacher.InputButtonHookDispatcher
import mqq.app.AppRuntime


Expand Down Expand Up @@ -67,4 +69,6 @@ object CtrlEnterToSend : CommonSwitchFunctionHook(), IBaseChatPieInitDecorator {

}

override val runtimeErrorDependentComponents: List<RuntimeErrorTracer> = listOf(InputButtonHookDispatcher.INSTANCE)

}
10 changes: 10 additions & 0 deletions app/src/main/java/io/github/qauxv/base/RuntimeErrorTracer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
package io.github.qauxv.base

interface RuntimeErrorTracer {

val runtimeErrors: List<Throwable>

val runtimeErrorDependentComponents: List<RuntimeErrorTracer>?

fun traceError(e: Throwable)

companion object {
@JvmField
val EMPTY_ARRAY = arrayOf<RuntimeErrorTracer>()
}

}
Loading

0 comments on commit 732db33

Please sign in to comment.