Skip to content

Commit

Permalink
fix: GagInfoDisclosure getUid and adapt QQ9.0.73~9.0.75
Browse files Browse the repository at this point in the history
  • Loading branch information
HdShare committed Jul 6, 2024
1 parent c48f448 commit 8b21d1e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 39 deletions.
99 changes: 60 additions & 39 deletions app/src/main/java/cc/ioctl/hook/chat/GagInfoDisclosure.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -54,6 +56,7 @@ object GagInfoDisclosure : CommonSwitchFunctionHook(
CMessageRecordFactory,
NContactUtils_getDiscussionMemberShowName,
NContactUtils_getBuddyName,
Hd_GagInfoDisclosure_Method,
)
) {

Expand All @@ -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
Expand All @@ -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 ->
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/io/github/qauxv/util/dexkit/DexKitTarget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
}

0 comments on commit 8b21d1e

Please sign in to comment.