Skip to content

Commit

Permalink
在NTQQ上使用新版逻辑进行发送消息(有回调更可靠)
Browse files Browse the repository at this point in the history
  • Loading branch information
teble committed Aug 3, 2024
1 parent 8ef1512 commit c6ca3e3
Show file tree
Hide file tree
Showing 23 changed files with 214 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
-keep class me.teble.xposed.autodaily.hook.function.proxy.* {
<methods>;
}
-keep class * extends me.teble.xposed.autodaily.hook.function.BaseFunction {
-keep class * extends me.teble.xposed.autodaily.hook.function.base.BaseFunction {
<methods>;
}
# ByteBuddy混淆
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/me/teble/xposed/autodaily/hook/QLogHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class QLogHook : BaseHook() {
get() = BuildConfig.DEBUG

override val enabled: Boolean
get() = false
get() = true

private val qTagFilter = setOf<String>(
// "PublicAccountManager",
Expand All @@ -31,6 +31,8 @@ class QLogHook : BaseHook() {
// "mqq",
// "TicketManager",
// "PskeyManagerImpl",
// "ChatActivityFacade",
"AIOMsgService"
)

private val ignoreTagFilter = setOf<String>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class XAClassLoader(
"com.tencent.mobileqq.",
"com.tencent.qphone.base.",
"com.tencent.widget.",
"com.tencent.qqnt.",
"mqq.",
"oicq.",
"tencent.im",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.teble.xposed.autodaily.hook.function

import me.teble.xposed.autodaily.hook.function.base.BaseFunction

abstract class BaseSendMessage(TAG: String): BaseFunction(TAG) {
abstract fun sendTextMessage(uin: String, msg: String, isGroup: Boolean)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.teble.xposed.autodaily.hook.function
package me.teble.xposed.autodaily.hook.function.base

import me.teble.xposed.autodaily.hook.notification.XANotification
import me.teble.xposed.autodaily.hook.utils.ToastUtil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.teble.xposed.autodaily.hook.function
package me.teble.xposed.autodaily.hook.function.base

import me.teble.xposed.autodaily.utils.BaseException

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import com.github.kyuubiran.ezxhelper.utils.paramCount
import com.tencent.qphone.base.remote.FromServiceMsg
import com.tencent.qphone.base.remote.ToServiceMsg
import me.teble.xposed.autodaily.hook.base.load
import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.base.BaseFunction
import me.teble.xposed.autodaily.hook.inject.ServletPool.favoriteServlet
import me.teble.xposed.autodaily.hook.inject.servlets.FavoriteServlet
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil.appInterface
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil.currentUin
import me.teble.xposed.autodaily.task.model.VoterInfo
import me.teble.xposed.autodaily.utils.*
import me.teble.xposed.autodaily.utils.LogUtil
import me.teble.xposed.autodaily.utils.TimeUtil
import me.teble.xposed.autodaily.utils.fieldValue
import me.teble.xposed.autodaily.utils.getFields
import me.teble.xposed.autodaily.utils.getMethods
import java.lang.reflect.Method
import java.util.*
import java.util.Date

open class FavoriteManager : BaseFunction(
TAG = "FavoriteManager"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.teble.xposed.autodaily.hook.function.impl

import me.teble.xposed.autodaily.hook.base.load
import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.FunctionInitException
import me.teble.xposed.autodaily.hook.function.base.BaseFunction
import me.teble.xposed.autodaily.hook.function.base.FunctionInitException
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil
import me.teble.xposed.autodaily.task.model.Friend
import me.teble.xposed.autodaily.utils.field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.tencent.qphone.base.remote.FromServiceMsg
import com.tencent.qphone.base.remote.ToServiceMsg
import me.teble.xposed.autodaily.hook.base.hostVersionName
import me.teble.xposed.autodaily.hook.base.load
import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.base.BaseFunction
import me.teble.xposed.autodaily.hook.inject.ServletPool.troopClockInServlet
import me.teble.xposed.autodaily.hook.inject.servlets.TroopClockInServlet
import me.teble.xposed.autodaily.hook.oidb.cmd.oidb_0xeb7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import me.teble.xposed.autodaily.config.MiniAppGetLoginCodeServlet
import me.teble.xposed.autodaily.config.MsfService
import me.teble.xposed.autodaily.hook.FromServiceMsgHook
import me.teble.xposed.autodaily.hook.base.load
import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.base.BaseFunction
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil.currentUin
import me.teble.xposed.autodaily.hook.utils.WupUtil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import me.teble.xposed.autodaily.config.MiniAppGetProfileServlet
import me.teble.xposed.autodaily.config.MsfService
import me.teble.xposed.autodaily.hook.FromServiceMsgHook
import me.teble.xposed.autodaily.hook.base.load
import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.base.BaseFunction
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil.currentUin
import me.teble.xposed.autodaily.hook.utils.WupUtil
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package me.teble.xposed.autodaily.hook.function.impl

import com.tencent.mobileqq.qroute.QRoute
import com.tencent.qqnt.kernel.nativeinterface.IOperateCallback
import com.tencent.qqnt.kernel.nativeinterface.MsgAttributeInfo
import com.tencent.qqnt.kernel.nativeinterface.TextElement
import me.teble.xposed.autodaily.hook.base.load
import me.teble.xposed.autodaily.hook.base.loadAs
import me.teble.xposed.autodaily.hook.function.BaseSendMessage
import me.teble.xposed.autodaily.hook.utils.NtUidUtil
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil.appRuntime
import me.teble.xposed.autodaily.utils.LogUtil
import me.teble.xposed.autodaily.utils.getMethods
import me.teble.xposed.autodaily.utils.invoke
import me.teble.xposed.autodaily.utils.new
import java.lang.reflect.Method
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit


open class NtSendMessageManager : BaseSendMessage(
TAG = "NtSendMessageManager"
) {
private lateinit var msgService: Any
private lateinit var msgUtilApi: Any
private lateinit var contactClass: Class<*>

// NtQQ 8.9.30+
private var generateMsgUniqueIdMethod: Method? = null
// lower nt qq
private var getMsgUniqueIdMethod: Method? = null

override fun init() {
val kernelService = appRuntime.getRuntimeService(loadAs("com.tencent.qqnt.kernel.api.IKernelService"), "all")
msgService = kernelService.invoke("getMsgService")!!
val msgServiceMethods = msgService.getMethods(false)
generateMsgUniqueIdMethod = msgServiceMethods.firstOrNull {
it.returnType == Long::class.javaObjectType
&& it.parameterTypes.size == 1 && it.parameterTypes[0] == Int::class.java
}
generateMsgUniqueIdMethod ?: run {
getMsgUniqueIdMethod = msgServiceMethods.firstOrNull {
it.returnType == Long::class.javaObjectType && it.parameterTypes.isEmpty()
}
}

msgUtilApi = QRoute.api(loadAs("com.tencent.qqnt.msg.api.IMsgUtilApi"))
contactClass = load("com.tencent.qqnt.kernelpublic.nativeinterface.Contact")
?: load("com.tencent.qqnt.kernel.nativeinterface.Contact")!!
}

override fun sendTextMessage(uin: String, msg: String, isGroup: Boolean) {
val chatType = if (isGroup) 2 else 1
val peerUid = if (isGroup) {
uin
} else {
NtUidUtil.getUidFromUin(uin)
}
val guildId = ""
val contact = contactClass.new(chatType, peerUid, guildId)

val textElement = TextElement()
textElement.content = msg
val msgElement = msgUtilApi.invoke("createTextElement", textElement)!!
val msgElements = arrayListOf(msgElement)

val msgUniqueId = getMsgUniqueId(chatType)

LogUtil.d("msgId: $msgUniqueId, contact: $contact, msgElements: $msgElements")

val countDownLatch = CountDownLatch(1)

msgService.invoke(
"sendMsg",
msgUniqueId,
contact,
msgElements,
HashMap<Int, MsgAttributeInfo>(),
object : IOperateCallback {
override fun onResult(result: Int, msg: String) {
countDownLatch.countDown()
}
}
)

countDownLatch.await(10, TimeUnit.SECONDS)
}

private fun getMsgUniqueId(chatType: Int): Long {
val ret = generateMsgUniqueIdMethod?.invoke(msgService, chatType)
?: getMsgUniqueIdMethod!!.invoke(msgService)
return ret as Long
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package me.teble.xposed.autodaily.hook.function.impl
import com.tencent.mobileqq.mp.mobileqq_mp
import me.teble.xposed.autodaily.config.StQWebReq
import me.teble.xposed.autodaily.hook.base.load
import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.base.BaseFunction
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil.currentUin
import me.teble.xposed.autodaily.hook.utils.ServletUtil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import android.os.Parcelable
import me.teble.xposed.autodaily.config.ChatActivityFacade
import me.teble.xposed.autodaily.config.SessionInfo
import me.teble.xposed.autodaily.hook.base.load
import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.BaseSendMessage
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil
import me.teble.xposed.autodaily.utils.LogUtil
import me.teble.xposed.autodaily.utils.new
import java.lang.reflect.Method

open class SendMessageManager : BaseFunction(
open class SendMessageManager : BaseSendMessage(
TAG = "SendMessageManager"
) {
private lateinit var sendMsgMethod: Method
Expand Down Expand Up @@ -59,8 +59,8 @@ open class SendMessageManager : BaseFunction(
return ret as Parcelable
}

open fun sendMessage(uin: String, msg: String, isGroup: Boolean = false): LongArray {
return sendMessage(
override fun sendTextMessage(uin: String, msg: String, isGroup: Boolean) {
sendMessage(
QApplicationUtil.appInterface,
QApplicationUtil.application,
createSessionInfo(uin, isGroup),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.teble.xposed.autodaily.hook.function.impl

import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.base.BaseFunction
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil
import mqq.manager.TicketManager

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ package me.teble.xposed.autodaily.hook.function.proxy

import android.content.Context
import me.teble.xposed.autodaily.hook.base.hostContext
import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.impl.*
import me.teble.xposed.autodaily.hook.function.BaseSendMessage
import me.teble.xposed.autodaily.hook.function.base.BaseFunction
import me.teble.xposed.autodaily.hook.function.impl.FavoriteManager
import me.teble.xposed.autodaily.hook.function.impl.FriendsManager
import me.teble.xposed.autodaily.hook.function.impl.GroupSignInManager
import me.teble.xposed.autodaily.hook.function.impl.MiniLoginManager
import me.teble.xposed.autodaily.hook.function.impl.MiniProfileManager
import me.teble.xposed.autodaily.hook.function.impl.NtSendMessageManager
import me.teble.xposed.autodaily.hook.function.impl.PublicAccountManager
import me.teble.xposed.autodaily.hook.function.impl.SendMessageManager
import me.teble.xposed.autodaily.hook.function.impl.TicketManager
import me.teble.xposed.autodaily.hook.function.impl.TroopManager
import me.teble.xposed.autodaily.hook.utils.QApplicationUtil
import net.bytebuddy.ByteBuddy
import net.bytebuddy.android.AndroidClassLoadingStrategy
import net.bytebuddy.implementation.MethodDelegation
Expand All @@ -19,6 +30,7 @@ object FunctionPool {
FriendsManager::class.java,
TroopManager::class.java,
MiniLoginManager::class.java,
NtSendMessageManager::class.java,
SendMessageManager::class.java,
GroupSignInManager::class.java,
MiniProfileManager::class.java,
Expand Down Expand Up @@ -53,21 +65,27 @@ object FunctionPool {
@Suppress("UNCHECKED_CAST")
fun <T : BaseFunction> getFunction(functionClass: Class<T>) = functionMap[functionClass] as T

val favoriteManager = getFunction(FavoriteManager::class.java)
val favoriteManager by lazy { getFunction(FavoriteManager::class.java) }

val ticketManager = getFunction(TicketManager::class.java)
val ticketManager by lazy { getFunction(TicketManager::class.java) }

val friendsManager = getFunction(FriendsManager::class.java)
val friendsManager by lazy { getFunction(FriendsManager::class.java) }

val troopManager = getFunction(TroopManager::class.java)
val troopManager by lazy { getFunction(TroopManager::class.java) }

val miniLoginManager = getFunction(MiniLoginManager::class.java)
val miniLoginManager by lazy { getFunction(MiniLoginManager::class.java) }

val sendMessageManager = getFunction(SendMessageManager::class.java)
val sendMessageManager: BaseSendMessage by lazy {
if (QApplicationUtil.isNtQQ()) {
getFunction(NtSendMessageManager::class.java)
} else {
getFunction(SendMessageManager::class.java)
}
}

val groupSignInManager = getFunction(GroupSignInManager::class.java)
val groupSignInManager by lazy { getFunction(GroupSignInManager::class.java) }

val miniProfileManager = getFunction(MiniProfileManager::class.java)
val miniProfileManager by lazy { getFunction(MiniProfileManager::class.java) }

val publicAccountManager = getFunction(PublicAccountManager::class.java)
val publicAccountManager by lazy { getFunction(PublicAccountManager::class.java) }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.teble.xposed.autodaily.hook.function.proxy

import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.base.BaseFunction
import net.bytebuddy.implementation.bind.annotation.*
import java.lang.reflect.Method
import java.util.concurrent.Callable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.teble.xposed.autodaily.hook.utils

import com.tencent.mobileqq.qroute.QRoute
import me.teble.xposed.autodaily.hook.base.loadAs
import me.teble.xposed.autodaily.utils.invokeAs

object NtUidUtil {
private val relationNTUinAndUidApi by lazy {
QRoute.api(loadAs("com.tencent.relation.common.api.IRelationNTUinAndUidApi"))
}

@JvmStatic
fun getUidFromUin(uin: String): String {
return relationNTUinAndUidApi.invokeAs("getUidFromUin", uin)!!
}

@JvmStatic
fun getUinFromUid(uid: String): String {
return relationNTUinAndUidApi.invokeAs("getUinFromUid", uid)!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ object QApplicationUtil {
fun send(toServiceMsg: ToServiceMsg) {
msf.invoke("sendMsg", toServiceMsg)
}

fun isNtQQ(): Boolean {
return load("com.tencent.qqnt.base.BaseActivity") != null
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.teble.xposed.autodaily.task.request.impl

import me.teble.xposed.autodaily.hook.function.BaseFunction
import me.teble.xposed.autodaily.hook.function.base.BaseFunction
import me.teble.xposed.autodaily.hook.function.proxy.FunctionPool.favoriteManager
import me.teble.xposed.autodaily.hook.function.proxy.FunctionPool.groupSignInManager
import me.teble.xposed.autodaily.hook.function.proxy.FunctionPool.publicAccountManager
Expand Down Expand Up @@ -69,13 +69,13 @@ object FuncTaskReqUtil : ITaskReqUtil {
val uin = paramMap["uin"]!!
val data = paramMap["msg"]!!
manager = sendMessageManager
sendMessageManager.sendMessage(uin, data, false)
sendMessageManager.sendTextMessage(uin, data, false)
}
url.startsWith("xa://SendMessageManager/sendMessage/group") -> {
val uin = paramMap["uin"]!!
val data = paramMap["msg"]!!
manager = sendMessageManager
sendMessageManager.sendMessage(uin, data, true)
sendMessageManager.sendTextMessage(uin, data, true)
}
url.startsWith("xa://GroupSignInManager/signIn") -> {
val groupUin = paramMap["uin"]!!
Expand Down
Loading

0 comments on commit c6ca3e3

Please sign in to comment.