From 8b21d1e5df2d06ddec9e9bad6cc06c5822bf8a44 Mon Sep 17 00:00:00 2001 From: hd <1839732296@qq.com> Date: Sun, 7 Jul 2024 06:17:39 +0800 Subject: [PATCH] fix: GagInfoDisclosure getUid and adapt QQ9.0.73~9.0.75 --- .../cc/ioctl/hook/chat/GagInfoDisclosure.kt | 99 +++++++++++-------- .../github/qauxv/util/dexkit/DexKitTarget.kt | 7 ++ 2 files changed, 67 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/cc/ioctl/hook/chat/GagInfoDisclosure.kt b/app/src/main/java/cc/ioctl/hook/chat/GagInfoDisclosure.kt index 692f682730..f4bbe1344b 100644 --- a/app/src/main/java/cc/ioctl/hook/chat/GagInfoDisclosure.kt +++ b/app/src/main/java/cc/ioctl/hook/chat/GagInfoDisclosure.kt @@ -23,6 +23,7 @@ package cc.ioctl.hook.chat import cc.hicore.QApp.QAppUtils +import cc.ioctl.util.hookAfterIfEnabled import cc.ioctl.util.hookBeforeIfEnabled import io.github.qauxv.base.annotation.FunctionHookEntry import io.github.qauxv.base.annotation.UiItemAgentEntry @@ -39,9 +40,10 @@ import io.github.qauxv.util.Log import io.github.qauxv.util.QQVersion import io.github.qauxv.util.SyncUtils import io.github.qauxv.util.dexkit.CMessageRecordFactory +import io.github.qauxv.util.dexkit.DexKit +import io.github.qauxv.util.dexkit.Hd_GagInfoDisclosure_Method import io.github.qauxv.util.dexkit.NContactUtils_getBuddyName import io.github.qauxv.util.dexkit.NContactUtils_getDiscussionMemberShowName -import io.github.qauxv.util.hostInfo import io.github.qauxv.util.requireMinQQVersion import xyz.nextalone.util.get @@ -54,6 +56,7 @@ object GagInfoDisclosure : CommonSwitchFunctionHook( CMessageRecordFactory, NContactUtils_getDiscussionMemberShowName, NContactUtils_getBuddyName, + Hd_GagInfoDisclosure_Method, ) ) { @@ -62,6 +65,10 @@ object GagInfoDisclosure : CommonSwitchFunctionHook( override val uiItemLocation = FunctionEntryRouter.Locations.Auxiliary.CHAT_CATEGORY override val isAvailable = QAppUtils.isQQnt() + private fun getLongData(bArr: ByteArray, i: Int): Long { + return (((bArr[i].toInt() and 255) shl 24) + ((bArr[i + 1].toInt() and 255) shl 16) + ((bArr[i + 2].toInt() and 255) shl 8) + ((bArr[i + 3].toInt() and 255) shl 0)).toLong() + } + private fun getSecStr(sec: Long): String { val (min, hour, day) = Triple("分", "时", "天") val d = sec / 86400 @@ -75,15 +82,62 @@ object GagInfoDisclosure : CommonSwitchFunctionHook( } private fun NtGrayTipHelper.NtGrayTipJsonBuilder.appendUserItem(uin: String, name: String) { - val uid = RelationNTUinAndUidApi.getUidFromUin(uin).takeIf { it.isNullOrEmpty() } ?: "u_0000000000000000000000" + val uid = RelationNTUinAndUidApi.getUidFromUin(uin).takeIf { it.isNullOrEmpty().not() } ?: "u_0000000000000000000000" this.append(NtGrayTipHelper.NtGrayTipJsonBuilder.UserItem(uin, uid, name)) } + private fun addGagTipMsg(selfUin: String, troopUin: String, opUin: String, victimUin: String, victimTime: Long) { + val opName = ContactUtils.getTroopMemberNick(troopUin, opUin) + val victimName = ContactUtils.getTroopMemberNick(troopUin, victimUin) + val builder = NtGrayTipHelper.NtGrayTipJsonBuilder() + when (victimUin) { + "0" -> { + if (opUin == selfUin) builder.appendUserItem(selfUin, "你") else builder.appendUserItem(opUin, opName) + builder.appendText(if (victimTime == 0L) "关闭了全员禁言" else "开启了全员禁言") + } + + selfUin -> { + builder.appendUserItem(selfUin, "你") + builder.appendText("被") + builder.appendUserItem(opUin, opName) + builder.appendText(if (victimTime == 0L) "解除禁言" else "禁言${getSecStr(victimTime)}") + } + + else -> { + builder.appendUserItem(victimUin, victimName) + builder.appendText("被") + if (opUin == selfUin) builder.appendUserItem(selfUin, "你") else builder.appendUserItem(opUin, opName) + builder.appendText(if (victimTime == 0L) "解除禁言" else "禁言${getSecStr(victimTime)}") + } + } + NtGrayTipHelper.addLocalJsonGrayTipMsg( + AppRuntimeHelper.getAppRuntime()!!, + ContactCompat(ChatTypeConstants.GROUP, troopUin, ""), + NtGrayTipHelper.createLocalJsonElement(NtGrayTipHelper.AIO_AV_GROUP_NOTICE.toLong(), builder.build().toString(), ""), + true, + true + ) { result, uin -> + if (result != 0) { + Log.e("GagInfoDisclosure error: addLocalJsonGrayTipMsg failed, result=$result, uin=$uin") + } + } + } + override fun initOnce(): Boolean { if (requireMinQQVersion(QQVersion.QQ_9_0_73)) { - throw RuntimeException("Unsupported Version: ${hostInfo.versionName}") - // TODO 待适配QQ9.0.73~9.0.75 - // val troopGagClass = Initiator.loadClass("com.tencent.qqnt.troop.impl.TroopGagUtils") + hookAfterIfEnabled(DexKit.requireMethodFromCache(Hd_GagInfoDisclosure_Method)) { param -> + val msgInfo = param.args[1] + val vMsg = msgInfo.get("vMsg") as ByteArray? ?: return@hookAfterIfEnabled + if (vMsg[4].toInt() == 12) { + val selfUin = AppRuntimeHelper.getAccount() + val troopUin = getLongData(vMsg, 0).toString() + val opUin = getLongData(vMsg, 6).toString() + val victimUinTmp = getLongData(vMsg, 16) + val victimUin = (victimUinTmp.takeIf { it > 0 } ?: (victimUinTmp and 0xFFFFFFFFL)).toString() + val victimTime = getLongData(vMsg, 20) + addGagTipMsg(selfUin, troopUin, opUin, victimUin, victimTime) + } + } } else { val troopGagClass = Initiator.loadClass("com.tencent.mobileqq.troop.utils.TroopGagMgr") val method = troopGagClass.declaredMethods.single { method -> @@ -99,43 +153,10 @@ object GagInfoDisclosure : CommonSwitchFunctionHook( val selfUin = AppRuntimeHelper.getAccount() val troopUin = param.args[1].toString() val opUin = param.args[2].toString() - val opName = ContactUtils.getTroopMemberNick(troopUin, opUin) val pushParams = param.args[4] as ArrayList<*> val victimUin = pushParams[0].get("uin") as String - val victimName = ContactUtils.getTroopMemberNick(troopUin, victimUin) val victimTime = pushParams[0].get("gagLength") as Long - val builder = NtGrayTipHelper.NtGrayTipJsonBuilder() - when (victimUin) { - "0" -> { - if (opUin == selfUin) builder.appendUserItem(selfUin, "你") else builder.appendUserItem(opUin, opName) - builder.appendText(if (victimTime == 0L) "关闭了全员禁言" else "开启了全员禁言") - } - - selfUin -> { - builder.appendUserItem(selfUin, "你") - builder.appendText("被") - builder.appendUserItem(opUin, opName) - builder.appendText(if (victimTime == 0L) "解除禁言" else "禁言${getSecStr(victimTime)}") - } - - else -> { - builder.appendUserItem(victimUin, victimName) - builder.appendText("被") - if (opUin == selfUin) builder.appendUserItem(selfUin, "你") else builder.appendUserItem(opUin, opName) - builder.appendText(if (victimTime == 0L) "解除禁言" else "禁言${getSecStr(victimTime)}") - } - } - NtGrayTipHelper.addLocalJsonGrayTipMsg( - AppRuntimeHelper.getAppRuntime()!!, - ContactCompat(ChatTypeConstants.GROUP, troopUin, ""), - NtGrayTipHelper.createLocalJsonElement(NtGrayTipHelper.AIO_AV_GROUP_NOTICE.toLong(), builder.build().toString(), ""), - true, - true - ) { result, uin -> - if (result != 0) { - Log.e("GagInfoDisclosure error: addLocalJsonGrayTipMsg failed, result=$result, uin=$uin") - } - } + addGagTipMsg(selfUin, troopUin, opUin, victimUin, victimTime) } } return true diff --git a/app/src/main/java/io/github/qauxv/util/dexkit/DexKitTarget.kt b/app/src/main/java/io/github/qauxv/util/dexkit/DexKitTarget.kt index 94dcc628e9..4b3158dc3f 100644 --- a/app/src/main/java/io/github/qauxv/util/dexkit/DexKitTarget.kt +++ b/app/src/main/java/io/github/qauxv/util/dexkit/DexKitTarget.kt @@ -995,3 +995,10 @@ data object Hd_DisableGrowHalfLayer_Method : DexKitTarget.UsingStringVector() { m.returnType == Void.TYPE && m.paramCount == 3 } } + +data object Hd_GagInfoDisclosure_Method : DexKitTarget.UsingStr() { + override val findMethod = true + override val traitString = arrayOf("<---0x2dc push groupCode:") + override val declaringClass = "com.tencent.imcore.message" + override val filter = DexKitFilter.strInClsName("com/tencent/imcore/message/") +}