From dcf9262db53f06575c73a55ae1eb4bac0c2cc72c Mon Sep 17 00:00:00 2001 From: klxiaoniu Date: Mon, 26 Jun 2023 17:06:00 +0800 Subject: [PATCH] fix: DefaultBubbleHook for QQNT --- .../cc/ioctl/hook/chat/DefaultBubbleHook.java | 170 ++++-------------- 1 file changed, 33 insertions(+), 137 deletions(-) diff --git a/app/src/main/java/cc/ioctl/hook/chat/DefaultBubbleHook.java b/app/src/main/java/cc/ioctl/hook/chat/DefaultBubbleHook.java index c32a709b98..9044f3ae5d 100644 --- a/app/src/main/java/cc/ioctl/hook/chat/DefaultBubbleHook.java +++ b/app/src/main/java/cc/ioctl/hook/chat/DefaultBubbleHook.java @@ -21,34 +21,24 @@ */ package cc.ioctl.hook.chat; -import android.app.Activity; -import android.app.Application; -import android.content.Context; -import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import cc.hicore.QApp.QAppUtils; +import cc.ioctl.util.HookUtils; import cc.ioctl.util.HostInfo; -import io.github.qauxv.util.SyncUtils; -import io.github.qauxv.base.IDynamicHook; -import io.github.qauxv.base.ISwitchCellAgent; -import io.github.qauxv.base.IUiItemAgent; -import io.github.qauxv.base.IUiItemAgentProvider; +import cc.ioctl.util.Reflex; +import com.tencent.qqnt.kernel.nativeinterface.VASMsgBubble; import io.github.qauxv.base.annotation.FunctionHookEntry; import io.github.qauxv.base.annotation.UiItemAgentEntry; import io.github.qauxv.dsl.FunctionEntryRouter.Locations.Simplify; -import io.github.qauxv.step.Step; +import io.github.qauxv.hook.CommonSwitchFunctionHook; +import io.github.qauxv.util.Initiator; import java.io.File; -import java.util.Collections; -import java.util.List; -import kotlin.Unit; -import kotlin.jvm.functions.Function1; -import kotlin.jvm.functions.Function2; -import kotlin.jvm.functions.Function3; -import kotlinx.coroutines.flow.MutableStateFlow; +import java.lang.reflect.Method; @FunctionHookEntry @UiItemAgentEntry -public class DefaultBubbleHook implements IDynamicHook, IUiItemAgentProvider, IUiItemAgent { +public class DefaultBubbleHook extends CommonSwitchFunctionHook { public static final DefaultBubbleHook INSTANCE = new DefaultBubbleHook(); @@ -63,22 +53,26 @@ public boolean isAvailable() { } @Override - public boolean isEnabled() { - if (HostInfo.isTim()) { - return false; - } - Application app = HostInfo.getApplication(); - for (String path : paths) { - File dir = new File(app.getFilesDir().getAbsolutePath() + path); - if (dir.exists()) { - return !dir.canRead(); + protected boolean initOnce() throws Exception { + if (QAppUtils.isQQnt()) { + HookUtils.hookBeforeIfEnabled(this,VASMsgBubble.class.getDeclaredMethod("getBubbleId"),param -> param.setResult(0)); + HookUtils.hookBeforeIfEnabled(this,VASMsgBubble.class.getDeclaredMethod("getSubBubbleId"),param -> param.setResult(0)); + } else { + updateChmod(true); + Class kAIOMsgItem = Initiator.load("com.tencent.mobileqq.aio.msg.AIOMsgItem"); + Class kAIOBubbleSkinInfo = Initiator.load("com.tencent.mobileqq.aio.msglist.holder.skin.AIOBubbleSkinInfo"); + if (kAIOMsgItem != null && kAIOBubbleSkinInfo != null) { + Method m = Reflex.findSingleMethod(kAIOMsgItem, void.class, false, kAIOBubbleSkinInfo); + HookUtils.hookBeforeIfEnabled(this, m, param -> { + param.args[0] = null; + param.setResult(null); + }); } } - return false; + return true; } - @Override - public void setEnabled(boolean enabled) { + private static void updateChmod(boolean enabled) { for (String path : paths) { File dir = new File(HostInfo.getApplication().getFilesDir().getAbsolutePath() + path); boolean curr = !dir.exists() || !dir.canRead(); @@ -95,119 +89,26 @@ public void setEnabled(boolean enabled) { } } } - - } - - private final ISwitchCellAgent switchCellAgent = new ISwitchCellAgent() { - @Override - public boolean isChecked() { - return isEnabled(); - } - - @Override - public void setChecked(boolean isChecked) { - setEnabled(isChecked); - } - - @Override - public boolean isCheckable() { - return true; - } - }; - - @Override - public boolean isInitialized() { - return true; - } - - @Override - public boolean isInitializationSuccessful() { - return isInitialized(); - } - - @Override - public boolean initialize() { - return true; - } - - @NonNull - @Override - public List getRuntimeErrors() { - return Collections.emptyList(); - } - - @Override - public int getTargetProcesses() { - return SyncUtils.PROC_MAIN; - } - - @Override - public boolean isTargetProcess() { - return SyncUtils.isMainProcess(); - } - - @Override - public boolean isPreparationRequired() { - return false; } - @Nullable @Override - public Step[] makePreparationSteps() { - return null; - } - - @Override - public boolean isApplicationRestartRequired() { - return false; + public void setEnabled(boolean value) { + super.setEnabled(value); + if (!value) { + updateChmod(false); + } } @NonNull @Override - public Function1 getTitleProvider() { - return agent -> "强制使用默认消息气泡"; - } - - @Nullable - @Override - public Function2 getSummaryProvider() { - return null; - } - - @Nullable - @Override - public MutableStateFlow getValueState() { - return null; - } - - @Nullable - @Override - public Function1 getValidator() { - return null; + public String getName() { + return "强制使用默认消息气泡"; } @Nullable @Override - public ISwitchCellAgent getSwitchProvider() { - return switchCellAgent; - } - - @Nullable - @Override - public Function3 getOnClickListener() { - return null; - } - - @Nullable - @Override - public Function2 getExtraSearchKeywordProvider() { - return null; - } - - @NonNull - @Override - public IUiItemAgent getUiItemAgent() { - return this; + public String[] getExtraSearchKeywords() { + return new String[]{"默认气泡"}; } @NonNull @@ -216,9 +117,4 @@ public String[] getUiItemLocation() { return Simplify.CHAT_DECORATION; } - @NonNull - @Override - public String getItemAgentProviderUniqueIdentifier() { - return getClass().getName(); - } }