Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
refactor send_forward_msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Simplxss committed Feb 28, 2024
1 parent 4dc83fd commit ec56e32
Show file tree
Hide file tree
Showing 24 changed files with 891 additions and 534 deletions.
18 changes: 13 additions & 5 deletions protobuf/src/main/java/protobuf/message/Ptt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import kotlinx.serialization.protobuf.ProtoNumber
data class Ptt(
@ProtoNumber(1) var fileType: UInt?=null,
@ProtoNumber(2) var srcUin: ULong?=null,
@ProtoNumber(3) var fileUuid: ByteArray?=null,
@ProtoNumber(3) var fileUuid: String?=null,
@ProtoNumber(4) var fileMd5: ByteArray?=null,
@ProtoNumber(5) var fileName: ByteArray?=null,
@ProtoNumber(5) var fileName: String?=null,
@ProtoNumber(6) var fileSize: UInt?=null,
@ProtoNumber(7) var reserve: ByteArray?=null,
@ProtoNumber(8) var fileId: UInt?=null,
Expand All @@ -22,11 +22,19 @@ data class Ptt(
@ProtoNumber(15) var magicPttIndex: UInt?=null,
@ProtoNumber(16) var voiceSwitch: UInt?=null,
@ProtoNumber(17) var pttUrl: ByteArray?=null,
@ProtoNumber(18) var groupFileKey: ByteArray?=null,
@ProtoNumber(18) var groupFileKey: String?=null,
@ProtoNumber(19) var time: UInt?=null,
@ProtoNumber(20) var downPara: ByteArray?=null,
@ProtoNumber(29) var format: UInt?=null,
@ProtoNumber(30) var pbReserve: ByteArray?=null,
@ProtoNumber(30) var pbReserve: PbReserve?=null,
@ProtoNumber(31) var rptPttUrls: List<String>? = null,
@ProtoNumber(32) var downloadFlag: UInt?=null,
)
){
companion object{
@Serializable
data class PbReserve(
@ProtoNumber(2) var magic: Int?=null,
@ProtoNumber(7) var reserve: Int?=null,
)
}
}
2 changes: 1 addition & 1 deletion protobuf/src/main/java/protobuf/message/RichText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.serialization.protobuf.ProtoNumber
@Serializable
data class RichText(
@ProtoNumber(1) val attr: Attr? = null,
@ProtoNumber(2) val elements: List<Elem>? = null,
@ProtoNumber(2) var elements: List<Elem>? = null,
@ProtoNumber(3) val not_online_file: NotOnlineFile? = null,
@ProtoNumber(4) val ptt: Ptt? = null,
@ProtoNumber(5) val tmp_ptt: TmpPtt? = null,
Expand Down
247 changes: 211 additions & 36 deletions xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/MsgSvc.kt

Large diffs are not rendered by default.

33 changes: 17 additions & 16 deletions xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/PacketSvc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,18 @@ import io.ktor.utils.io.core.writeInt
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withTimeoutOrNull
import moe.fuqiuluo.qqinterface.servlet.msg.MessageTempHandler

import moe.fuqiuluo.shamrock.remote.action.handlers.GetHistoryMsg
import moe.fuqiuluo.shamrock.remote.service.listener.AioListener
import moe.fuqiuluo.shamrock.tools.broadcast
import moe.fuqiuluo.shamrock.utils.DeflateTools
import protobuf.message.element.LightAppElem
import protobuf.message.PushMsgBody
import protobuf.message.ContentHead
import protobuf.message.Elem
import protobuf.message.RichText
import protobuf.message.ResponseHead
import protobuf.message.MsgBody
import protobuf.push.MessagePush
import mqq.app.MobileQQ
import protobuf.auto.toByteArray
import protobuf.message.*
import protobuf.message.element.LightAppElem
import protobuf.push.MessagePush
import kotlin.coroutines.resume
import kotlin.text.toByteArray

internal object PacketSvc: BaseSvc() {
internal object PacketSvc : BaseSvc() {
/**
* 伪造收到Json卡片消息
*/
Expand All @@ -36,15 +30,20 @@ internal object PacketSvc: BaseSvc() {
listOf(
Elem(
lightApp = LightAppElem((byteArrayOf(1) + DeflateTools.compress(content.toByteArray())))
)
)
)
}
}

private suspend fun fakeReceiveSelfMsg(msgService: IKernelMsgService, builder: () -> List<Elem>): Long {
val latestMsg = withTimeoutOrNull(3000) {
suspendCancellableCoroutine {
msgService.getMsgs(Contact(MsgConstant.KCHATTYPEC2C, app.currentUid, ""), 0L, 1, true) { code, why, msgs ->
msgService.getMsgs(
Contact(MsgConstant.KCHATTYPEC2C, app.currentUid, ""),
0L,
1,
true
) { code, why, msgs ->
it.resume(GetHistoryMsg.GetMsgResult(code, why, msgs))
}
}
Expand Down Expand Up @@ -72,9 +71,11 @@ internal object PacketSvc: BaseSvc() {
u4 = msgSeq - 2,
u5 = msgSeq
),
body = MsgBody(RichText(
elements = builder()
))
body = MsgBody(
RichText(
elements = builder()
)
)
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
package moe.fuqiuluo.qqinterface.servlet.msg

import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
import com.tencent.qqnt.kernel.nativeinterface.MsgElement
import moe.fuqiuluo.qqinterface.servlet.msg.converter.ElemConverter
import moe.fuqiuluo.qqinterface.servlet.msg.converter.NtMsgElementConverter
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
import moe.fuqiuluo.shamrock.helper.Level
import moe.fuqiuluo.shamrock.helper.LogCenter
import moe.fuqiuluo.shamrock.helper.MessageHelper
import moe.fuqiuluo.shamrock.tools.toHexString
import protobuf.message.Elem
import protobuf.message.RichText

@JvmName("elemListToSegments")
internal suspend fun List<Elem>.toSegments(
@JvmName("richTextToSegments")
internal suspend fun RichText.toSegments(
chatType: Int,
peerId: String,
subPeer: String
): List<MessageSegment> {
val messageData = arrayListOf<MessageSegment>()
this.forEach { msg ->
if (ptt != null) {
val md5 = ptt!!.fileMd5!!
messageData.add(
MessageSegment(
"record", mapOf(
"file" to md5.toHexString(),
"url" to when (chatType) {
MsgConstant.KCHATTYPEC2C -> RichProtoSvc.getC2CPttDownUrl("0", ptt!!.fileUuid!!)
MsgConstant.KCHATTYPEGROUP, MsgConstant.KCHATTYPEGUILD -> RichProtoSvc.getGroupPttDownUrl(
"0",
md5,
ptt!!.groupFileKey!!
)

else -> throw UnsupportedOperationException("Not supported chat type: $chatType")
},
"magic" to ptt!!.pbReserve?.magic,
)
)
)
}
elements?.forEach { msg ->
kotlin.runCatching {
val elementType = if (msg.text != null) {
1
Expand All @@ -29,7 +54,7 @@ internal suspend fun List<Elem>.toSegments(
37
} else if (msg.srcMsg != null) {
45
} else if (msg.lightApp != null) {
} else if (msg.lightApp != null) {
51
} else if (msg.commonElem != null) {
53
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ internal data class MessageSegment(
) {
fun toJson(): JsonObject {
return mapOf(
"type" to type.json,
"data" to data.json
"type" to type,
"data" to data
).json
}
}
Expand All @@ -29,6 +29,6 @@ internal fun List<MessageSegment>.toListMap(): List<Map<String, JsonElement>> {
mapOf(
"type" to it.type.json,
"data" to it.data.json
).json
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import moe.fuqiuluo.shamrock.helper.LogCenter
import moe.fuqiuluo.shamrock.helper.db.ImageDB
import moe.fuqiuluo.shamrock.helper.db.ImageMapping
import moe.fuqiuluo.shamrock.helper.db.MessageDB
import moe.fuqiuluo.shamrock.tools.asJsonArray
import moe.fuqiuluo.shamrock.utils.DeflateTools
import moe.fuqiuluo.shamrock.tools.asJsonObject
import moe.fuqiuluo.shamrock.tools.asString
import moe.fuqiuluo.shamrock.tools.toHexString
import moe.fuqiuluo.symbols.decodeProtobuf
import moe.fuqiuluo.shamrock.tools.slice
import protobuf.message.Elem
import protobuf.message.element.commelem.ButtonExtra
import protobuf.message.element.commelem.MarkdownExtra
Expand Down Expand Up @@ -335,18 +337,19 @@ internal object ElemConverter {
element: Elem
): MessageSegment {
val data = element.lightApp!!.data!!
val jsonStr =
(if (data[0].toInt() == 1) DeflateTools.uncompress(data.sliceArray(1 until data.size)) else data.sliceArray(
1 until data.size
)).toString()
val jsonStr = String(if (data[0].toInt() == 1) DeflateTools.uncompress(data.slice(1)) else data.slice(1))
LogCenter.log(jsonStr, Level.DEBUG)
val json = jsonStr.asJsonObject
return when (json["app"].asString) {
"com.tencent.multimsg" -> {
val info = json["meta"].asJsonObject["detail"].asJsonObject
MessageSegment(
type = "forward",
data = mapOf(
"id" to info["resid"].asString
"id" to info["resid"].asString,
"filename" to info["uniseq"].asString,
"summary" to info["summary"].asString,
"desc" to info["news"].asJsonArray.joinToString("\n") { it.asJsonObject["text"].asString }
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package moe.fuqiuluo.qqinterface.servlet.msg.converter

import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
import com.tencent.qqnt.kernel.nativeinterface.MsgElement
import kotlinx.serialization.json.add
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import kotlinx.serialization.json.putJsonArray
import moe.fuqiuluo.qqinterface.servlet.msg.MessageSegment
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
import moe.fuqiuluo.shamrock.helper.ContactHelper
Expand All @@ -15,6 +11,7 @@ import moe.fuqiuluo.shamrock.helper.MessageHelper
import moe.fuqiuluo.shamrock.helper.db.ImageDB
import moe.fuqiuluo.shamrock.helper.db.ImageMapping
import moe.fuqiuluo.shamrock.helper.db.MessageDB
import moe.fuqiuluo.shamrock.tools.asJsonArray
import moe.fuqiuluo.shamrock.tools.asJsonObject
import moe.fuqiuluo.shamrock.tools.asString
import moe.fuqiuluo.shamrock.tools.hex2ByteArray
Expand Down Expand Up @@ -242,16 +239,10 @@ internal object NtMsgElementConverter {
data = hashMapOf(
"file" to md5,
"url" to when (chatType) {
MsgConstant.KCHATTYPEGROUP -> RichProtoSvc.getGroupPttDownUrl(
"0",
record.md5HexStr,
record.fileUuid
)

MsgConstant.KCHATTYPEC2C -> RichProtoSvc.getC2CPttDownUrl("0", record.fileUuid)
MsgConstant.KCHATTYPEGUILD -> RichProtoSvc.getGroupPttDownUrl(
MsgConstant.KCHATTYPEGROUP, MsgConstant.KCHATTYPEGUILD -> RichProtoSvc.getGroupPttDownUrl(
"0",
record.md5HexStr,
md5.hex2ByteArray(),
record.fileUuid
)

Expand Down Expand Up @@ -343,7 +334,10 @@ internal object NtMsgElementConverter {
MessageSegment(
type = "forward",
data = mapOf(
"id" to info["resid"].asString
"id" to info["resid"].asString,
"filename" to info["uniseq"].asString,
"summary" to info["summary"].asString,
"desc" to info["news"].asJsonArray.joinToString("\n") { it.asJsonObject["text"].asString }
)
)
}
Expand Down
Loading

0 comments on commit ec56e32

Please sign in to comment.