Skip to content

Commit

Permalink
refactor: optimize BaseBubbleBuilderHook performance
Browse files Browse the repository at this point in the history
  • Loading branch information
cinit committed Jul 16, 2023
1 parent fb4a46b commit 587b9df
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions app/src/main/java/me/ketal/dispacher/BaseBubbleBuilderHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,20 @@ package me.ketal.dispacher

import android.view.View
import android.view.ViewGroup
import cc.hicore.QApp.QAppUtils
import cc.ioctl.hook.msg.MultiForwardAvatarHook
import cc.ioctl.util.HostInfo
import com.github.kyuubiran.ezxhelper.utils.hookBefore
import com.github.kyuubiran.ezxhelper.utils.hookAfter
import com.github.kyuubiran.ezxhelper.utils.paramCount
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
import de.robv.android.xposed.XC_MethodHook
import io.github.qauxv.base.annotation.FunctionHookEntry
import io.github.qauxv.hook.BasePersistBackgroundHook
import io.github.qauxv.util.Initiator
import io.github.qauxv.util.QQVersion
import me.ketal.hook.ChatItemShowQQUin
import me.ketal.hook.ShowMsgAt
import me.singleneuron.data.MsgRecordData
import xyz.nextalone.hook.HideTroopLevel
import xyz.nextalone.util.hookAfter
import xyz.nextalone.util.invoke
import xyz.nextalone.util.method
import java.lang.reflect.Method
import java.lang.reflect.Modifier
Expand All @@ -59,28 +57,28 @@ object BaseBubbleBuilderHook : BasePersistBackgroundHook() {

@Throws(Exception::class)
override fun initOnce(): Boolean {
if (HostInfo.requireMinQQVersion(QQVersion.QQ_8_9_63)) {
if (QAppUtils.isQQnt()) {
val kBaseContentComponent = Initiator.loadClass("com.tencent.mobileqq.aio.msglist.holder.component.BaseContentComponent")
val getView = kBaseContentComponent.declaredMethods.singleOrNull { it.name == "onCreateView" }!!
getView.hookAfter(this) {param->
// Log.d("BaseContentComponent.onCreateView")
if (param.result == null) return@hookAfter
val rootView = param.result as ViewGroup
var clz = param.thisObject.javaClass.superclass
while (clz != kBaseContentComponent) {
clz = clz.superclass
}
// onCreateView时AIOMsgItem还没被设置
clz.method { it.paramCount == 1 && it.parameterTypes[0].name == "com.tencent.mobileqq.aio.msg.AIOMsgItem" }!!.hookBefore {
val item = it.args[0]
val msg = item.invoke("getMsgRecord")!! as MsgRecord
// Log.i("get!!!!!!")
for (decorator in decorators) {
try {
decorator.onGetViewNt(rootView, msg, it)
} catch (e: Exception) {
traceError(e)
}
val kAbsAIOMsgItemComponent = kBaseContentComponent.superclass
val containerViewField = kAbsAIOMsgItemComponent.declaredFields.single {
it.type == View::class.java
}.also {
it.isAccessible = true
}
val kAIOMsgItem = Initiator.loadClass("com.tencent.mobileqq.aio.msg.AIOMsgItem")
val setAIOMsgItem = kBaseContentComponent.method {
it.returnType == Void.TYPE && it.paramCount == 1 && it.parameterTypes[0] == kAIOMsgItem
}
val getMsgRecord = kAIOMsgItem.getMethod("getMsgRecord")
setAIOMsgItem!!.hookAfter {
val item = it.args[0]
val rootView = containerViewField.get(it.thisObject) as ViewGroup
val msg = getMsgRecord.invoke(item) as MsgRecord
for (decorator in decorators) {
try {
decorator.onGetViewNt(rootView, msg, it)
} catch (e: Exception) {
traceError(e)
}
}
}
Expand Down

0 comments on commit 587b9df

Please sign in to comment.