From 494c70f2f862677f88bf667015ccc21c5dd2d6f7 Mon Sep 17 00:00:00 2001 From: Simplxs Date: Thu, 11 Apr 2024 00:54:43 +0800 Subject: [PATCH] update kritor --- kritor/kritor | 2 +- .../java/kritor/service/DeveloperService.kt | 25 +++++ .../main/java/kritor/service/QsignService.kt | 7 ++ .../internals/GlobalEventTransmitter.kt | 101 ++++++++++++------ .../java/qq/service/file/GroupFileHelper.kt | 2 +- .../java/qq/service/internals/AioListener.kt | 6 +- .../qq/service/internals/PrimitiveListener.kt | 16 +-- 7 files changed, 111 insertions(+), 48 deletions(-) diff --git a/kritor/kritor b/kritor/kritor index a7dfcf9a..27669a8f 160000 --- a/kritor/kritor +++ b/kritor/kritor @@ -1 +1 @@ -Subproject commit a7dfcf9aa9692f78f387919034f76e0130f6c12e +Subproject commit 27669a8f5704a8876658a47cc976f1fb3e9cc2f4 diff --git a/xposed/src/main/java/kritor/service/DeveloperService.kt b/xposed/src/main/java/kritor/service/DeveloperService.kt index 2a1f772c..8e83fc45 100644 --- a/xposed/src/main/java/kritor/service/DeveloperService.kt +++ b/xposed/src/main/java/kritor/service/DeveloperService.kt @@ -2,12 +2,37 @@ package kritor.service import com.google.protobuf.ByteString import io.kritor.developer.* +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import kotlinx.coroutines.withTimeoutOrNull import moe.fuqiuluo.shamrock.utils.FileUtils import moe.fuqiuluo.shamrock.utils.MMKVFetcher import moe.fuqiuluo.shamrock.utils.PlatformUtils import qq.service.QQInterfaces +import java.io.File internal object DeveloperService: DeveloperServiceGrpcKt.DeveloperServiceCoroutineImplBase() { + @Grpc("DeveloperService", "Shell") + override suspend fun shell(request: ShellRequest): ShellResponse { + if (request.commandList.isEmpty()) return ShellResponse.newBuilder().setIsSuccess(false).build() + val runtime = Runtime.getRuntime() + val result = withTimeoutOrNull(5000L) { + withContext(Dispatchers.IO) { + runtime.exec(request.commandList.toTypedArray(), null, File(request.directory)).apply { waitFor() } + } + } + return ShellResponse.newBuilder().apply { + if (result == null) { + isSuccess = false + } else { + isSuccess = true + result.inputStream.use { + data = it.readBytes().toString(Charsets.UTF_8) + } + } + }.build() + } + @Grpc("DeveloperService", "ClearCache") override suspend fun clearCache(request: ClearCacheRequest): ClearCacheResponse { FileUtils.clearCache() diff --git a/xposed/src/main/java/kritor/service/QsignService.kt b/xposed/src/main/java/kritor/service/QsignService.kt index 90ef9a4e..d8cb0b27 100644 --- a/xposed/src/main/java/kritor/service/QsignService.kt +++ b/xposed/src/main/java/kritor/service/QsignService.kt @@ -23,4 +23,11 @@ internal object QsignService: QsignServiceGrpcKt.QsignServiceCoroutineImplBase() this.result = ByteString.copyFrom(Dandelion.getInstance().fly(request.data, request.salt.toByteArray())) }.build() } + + @Grpc("QsignService", "GetCmdWhitelist") + override suspend fun getCmdWhitelist(request: GetCmdWhitelistRequest): GetCmdWhitelistResponse { + return GetCmdWhitelistResponse.newBuilder().apply { + addAllCommands(FEKit.getInstance().cmdWhiteList) + }.build() + } } \ No newline at end of file diff --git a/xposed/src/main/java/moe/fuqiuluo/shamrock/internals/GlobalEventTransmitter.kt b/xposed/src/main/java/moe/fuqiuluo/shamrock/internals/GlobalEventTransmitter.kt index 6c12f61c..9aa13cb0 100644 --- a/xposed/src/main/java/moe/fuqiuluo/shamrock/internals/GlobalEventTransmitter.kt +++ b/xposed/src/main/java/moe/fuqiuluo/shamrock/internals/GlobalEventTransmitter.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.FlowCollector import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.launch import qq.service.QQInterfaces +import qq.service.contact.ContactHelper import qq.service.msg.toKritorEventMessages internal object GlobalEventTransmitter : QQInterfaces() { @@ -46,7 +47,7 @@ internal object GlobalEventTransmitter : QQInterfaces() { this.messageSeq = record.msgSeq this.contact = Contact.newBuilder().apply { this.scene = Scene.GROUP - this.peer = record.peerUin.toString() + this.peer = record.senderUid this.subPeer = record.peerUid }.build() this.sender = Sender.newBuilder().apply { @@ -69,7 +70,7 @@ internal object GlobalEventTransmitter : QQInterfaces() { this.messageSeq = record.msgSeq this.contact = Contact.newBuilder().apply { this.scene = Scene.FRIEND - this.peer = record.senderUin.toString() + this.peer = record.senderUid this.subPeer = record.senderUid }.build() this.sender = Sender.newBuilder().apply { @@ -94,7 +95,7 @@ internal object GlobalEventTransmitter : QQInterfaces() { this.messageSeq = record.msgSeq this.contact = Contact.newBuilder().apply { this.scene = if (groupCode > 0) Scene.STRANGER_FROM_GROUP else Scene.STRANGER - this.peer = record.senderUin.toString() + this.peer = record.senderUid this.subPeer = groupCode.toString() }.build() this.sender = Sender.newBuilder().apply { @@ -140,7 +141,8 @@ internal object GlobalEventTransmitter : QQInterfaces() { */ suspend fun transPrivateFileEvent( msgTime: Long, - userId: Long, + senderUid: String, + senderUin: Long, fileId: String, fileSubId: String, fileName: String, @@ -149,12 +151,13 @@ internal object GlobalEventTransmitter : QQInterfaces() { url: String ): Boolean { pushNotice(NoticeEvent.newBuilder().apply { - this.type = NoticeEvent.NoticeType.FRIEND_FILE_COME + this.type = NoticeEvent.NoticeType.PRIVATE_FILE_UPLOADED this.time = msgTime.toInt() - this.friendFileUploaded = FriendFileUploadedNotice.newBuilder().apply { + this.privateFileUploaded = PrivateFileUploadedNotice.newBuilder().apply { this.fileId = fileId this.fileName = fileName - this.operatorUin = userId + this.operatorUid = senderUid + this.operatorUin = senderUin this.fileSize = fileSize this.expireTime = expireTime.toInt() this.fileSubId = fileSubId @@ -169,7 +172,8 @@ internal object GlobalEventTransmitter : QQInterfaces() { */ suspend fun transGroupFileEvent( msgTime: Long, - userId: Long, + senderUid: String, + senderUin: Long, groupId: Long, uuid: String, fileName: String, @@ -178,11 +182,12 @@ internal object GlobalEventTransmitter : QQInterfaces() { url: String ): Boolean { pushNotice(NoticeEvent.newBuilder().apply { - this.type = NoticeEvent.NoticeType.GROUP_FILE_COME + this.type = NoticeEvent.NoticeType.GROUP_FILE_UPLOADED this.time = msgTime.toInt() this.groupFileUploaded = GroupFileUploadedNotice.newBuilder().apply { this.groupId = groupId - this.operatorUin = userId + this.operatorUid = senderUid + this.operatorUin = senderUin this.fileId = uuid this.fileName = fileName this.fileSize = fileSize @@ -201,19 +206,19 @@ internal object GlobalEventTransmitter : QQInterfaces() { suspend fun transGroupSign( time: Long, target: Long, - action: String?, - rankImg: String?, + action: String, + rankImg: String, groupCode: Long ): Boolean { pushNotice(NoticeEvent.newBuilder().apply { - this.type = NoticeEvent.NoticeType.GROUP_SIGN + this.type = NoticeEvent.NoticeType.GROUP_SIGN_IN this.time = time.toInt() this.groupSignIn = GroupSignInNotice.newBuilder().apply { this.groupId = groupCode + this.targetUid = ContactHelper.getUidByUinAsync(target) this.targetUin = target - this.action = action ?: "" - this.suffix = "" - this.rankImage = rankImg ?: "" + this.action = action + this.rankImage = rankImg }.build() }.build()) return true @@ -223,9 +228,9 @@ internal object GlobalEventTransmitter : QQInterfaces() { time: Long, operator: Long, target: Long, - action: String?, - suffix: String?, - actionImg: String?, + action: String, + suffix: String, + actionImg: String, groupCode: Long ): Boolean { pushNotice(NoticeEvent.newBuilder().apply { @@ -233,11 +238,13 @@ internal object GlobalEventTransmitter : QQInterfaces() { this.time = time.toInt() this.groupPoke = GroupPokeNotice.newBuilder().apply { this.groupId = groupCode - this.action = action ?: "" + this.action = action + this.targetUid = ContactHelper.getUidByUinAsync(target) this.targetUin = target + this.operatorUid = ContactHelper.getUidByUinAsync(operator) this.operatorUin = operator - this.suffix = suffix ?: "" - this.actionImage = actionImg ?: "" + this.suffix = suffix + this.actionImage = actionImg }.build() }.build()) return true @@ -301,7 +308,7 @@ internal object GlobalEventTransmitter : QQInterfaces() { pushNotice(NoticeEvent.newBuilder().apply { this.type = NoticeEvent.NoticeType.GROUP_ADMIN_CHANGED this.time = msgTime.toInt() - this.groupAdminChange = GroupAdminChangedNotice.newBuilder().apply { + this.groupAdminChanged = GroupAdminChangedNotice.newBuilder().apply { this.groupId = groupCode this.targetUid = targetUid this.targetUin = target @@ -313,8 +320,9 @@ internal object GlobalEventTransmitter : QQInterfaces() { suspend fun transGroupWholeBan( msgTime: Long, - operator: Long, groupCode: Long, + operatorUid: String, + operator: Long, isOpen: Boolean ): Boolean { pushNotice(NoticeEvent.newBuilder().apply { @@ -323,6 +331,7 @@ internal object GlobalEventTransmitter : QQInterfaces() { this.groupWholeBan = GroupWholeBanNotice.newBuilder().apply { this.groupId = groupCode this.isBan = isOpen + this.operatorUid = operatorUid this.operatorUin = operator }.build() }.build()) @@ -339,7 +348,7 @@ internal object GlobalEventTransmitter : QQInterfaces() { duration: Int ): Boolean { pushNotice(NoticeEvent.newBuilder().apply { - this.type = NoticeEvent.NoticeType.GROUP_MEMBER_BANNED + this.type = NoticeEvent.NoticeType.GROUP_MEMBER_BAN this.time = msgTime.toInt() this.groupMemberBan = GroupMemberBanNotice.newBuilder().apply { this.groupId = groupCode @@ -401,7 +410,7 @@ internal object GlobalEventTransmitter : QQInterfaces() { suspend fun transTitleChange( time: Long, - targetId: Long, + targetUin: Long, title: String, groupId: Long ): Boolean { @@ -410,7 +419,8 @@ internal object GlobalEventTransmitter : QQInterfaces() { this.time = time.toInt() this.groupMemberUniqueTitleChanged = GroupUniqueTitleChangedNotice.newBuilder().apply { this.groupId = groupId - this.target = targetId + this.targetUid = ContactHelper.getUidByUinAsync(targetUin) + this.targetUin = targetUin this.title = title }.build() }.build()) @@ -431,9 +441,11 @@ internal object GlobalEventTransmitter : QQInterfaces() { this.groupEssenceChanged = GroupEssenceMessageNotice.newBuilder().apply { this.groupId = groupId this.messageId = msgId.toString() + this.targetUid = ContactHelper.getUidByUinAsync(targetUin) this.targetUin = senderUin + this.operatorUid = ContactHelper.getUidByUinAsync(operatorUin) this.operatorUin = operatorUin - this.subType = subType.toInt() + this.isSet = subType.toInt() == 1 }.build() }.build()) return true @@ -447,16 +459,16 @@ internal object GlobalEventTransmitter : QQInterfaces() { suspend fun transPrivatePoke( msgTime: Long, operator: Long, - target: Long, action: String?, suffix: String?, actionImg: String? ): Boolean { pushNotice(NoticeEvent.newBuilder().apply { - this.type = NoticeEvent.NoticeType.FRIEND_POKE + this.type = NoticeEvent.NoticeType.PRIVATE_POKE this.time = msgTime.toInt() - this.friendPoke = FriendPokeNotice.newBuilder().apply { + this.privatePoke = PrivatePokeNotice.newBuilder().apply { this.action = action ?: "" + this.operatorUid = ContactHelper.getUidByUinAsync(operator) this.operatorUin = operator this.suffix = suffix ?: "" this.actionImage = actionImg ?: "" @@ -467,9 +479,9 @@ internal object GlobalEventTransmitter : QQInterfaces() { suspend fun transPrivateRecall(time: Long, operator: Long, msgId: Long, tipText: String): Boolean { pushNotice(NoticeEvent.newBuilder().apply { - this.type = NoticeEvent.NoticeType.FRIEND_RECALL + this.type = NoticeEvent.NoticeType.PRIVATE_RECALL this.time = time.toInt() - this.friendRecall = FriendRecallNotice.newBuilder().apply { + this.privateRecall = PrivateRecallNotice.newBuilder().apply { this.operatorUin = operator this.messageId = msgId.toString() this.tipText = tipText @@ -484,12 +496,13 @@ internal object GlobalEventTransmitter : QQInterfaces() { * 请求 通知器 */ object RequestTransmitter { - suspend fun transFriendApp(time: Long, operator: Long, tipText: String, flag: String): Boolean { + suspend fun transFriendApp(time: Long, applierUid: String, operator: Long, tipText: String, flag: String): Boolean { pushRequest(RequestEvent.newBuilder().apply { this.type = RequestEvent.RequestType.FRIEND_APPLY this.time = time.toInt() this.requestId = flag this.friendApply = FriendApplyRequest.newBuilder().apply { + this.applierUid = applierUid this.applierUin = operator this.message = tipText }.build() @@ -518,6 +531,26 @@ internal object GlobalEventTransmitter : QQInterfaces() { }.build()) return true } + + suspend fun transGroupInvite( + time: Long, + inviterUid: String, + inviterUin: Long, + groupCode: Long, + flag: String + ): Boolean { + pushRequest(RequestEvent.newBuilder().apply { + this.type = RequestEvent.RequestType.GROUP_APPLY + this.time = time.toInt() + this.requestId = flag + this.invitedGroup = InvitedJoinGroupRequest.newBuilder().apply { + this.inviterUid = inviterUid + this.inviterUin = inviterUin + this.groupId = groupCode + }.build() + }.build()) + return true + } } suspend inline fun onMessageEvent(collector: FlowCollector>) { diff --git a/xposed/src/main/java/qq/service/file/GroupFileHelper.kt b/xposed/src/main/java/qq/service/file/GroupFileHelper.kt index 07799f29..e9198782 100644 --- a/xposed/src/main/java/qq/service/file/GroupFileHelper.kt +++ b/xposed/src/main/java/qq/service/file/GroupFileHelper.kt @@ -117,7 +117,7 @@ internal object GroupFileHelper: QQInterfaces() { this.fileSize = fileInfo.uint64_file_size.get() this.busId = fileInfo.uint32_bus_id.get() this.uploadTime = fileInfo.uint32_upload_time.get() - this.deadTime = fileInfo.uint32_dead_time.get() + this.expireTime = fileInfo.uint32_dead_time.get() this.modifyTime = fileInfo.uint32_modify_time.get() this.downloadTimes = fileInfo.uint32_download_times.get() this.uploader = fileInfo.uint64_uploader_uin.get() diff --git a/xposed/src/main/java/qq/service/internals/AioListener.kt b/xposed/src/main/java/qq/service/internals/AioListener.kt index 83188725..ecd581a5 100644 --- a/xposed/src/main/java/qq/service/internals/AioListener.kt +++ b/xposed/src/main/java/qq/service/internals/AioListener.kt @@ -97,7 +97,6 @@ object AioListener : SimpleKernelMsgListener() { } private suspend fun onC2CFileMsg(record: MsgRecord) { - val userId = record.senderUin val fileMsg = record.elements.firstOrNull { it.elementType == MsgConstant.KELEMTYPEFILE }?.fileElement ?: kotlin.run { @@ -113,7 +112,7 @@ object AioListener : SimpleKernelMsgListener() { val url = RichProtoSvc.getC2CFileDownUrl(fileId, fileSubId) if (!GlobalEventTransmitter.FileNoticeTransmitter - .transPrivateFileEvent(record.msgTime, userId, fileId, fileSubId, fileName, fileSize, expireTime, url) + .transPrivateFileEvent(record.msgTime, record.senderUid, record.senderUin, fileId, fileSubId, fileName, fileSize, expireTime, url) ) { LogCenter.log("私聊文件消息推送失败 -> FileNoticeTransmitter", Level.WARN) } @@ -121,7 +120,6 @@ object AioListener : SimpleKernelMsgListener() { private suspend fun onGroupFileMsg(record: MsgRecord) { val groupId = record.peerUin - val userId = record.senderUin val fileMsg = record.elements.firstOrNull { it.elementType == MsgConstant.KELEMTYPEFILE }?.fileElement ?: kotlin.run { @@ -137,7 +135,7 @@ object AioListener : SimpleKernelMsgListener() { val url = RichProtoSvc.getGroupFileDownUrl(record.peerUin, uuid, bizId) if (!GlobalEventTransmitter.FileNoticeTransmitter - .transGroupFileEvent(record.msgTime, userId, groupId, uuid, fileName, fileSize, bizId, url) + .transGroupFileEvent(record.msgTime, record.senderUid, record.senderUin, groupId, uuid, fileName, fileSize, bizId, url) ) { LogCenter.log("群聊文件消息推送失败 -> FileNoticeTransmitter", Level.WARN) } diff --git a/xposed/src/main/java/qq/service/internals/PrimitiveListener.kt b/xposed/src/main/java/qq/service/internals/PrimitiveListener.kt index 539da50c..88f39fe2 100644 --- a/xposed/src/main/java/qq/service/internals/PrimitiveListener.kt +++ b/xposed/src/main/java/qq/service/internals/PrimitiveListener.kt @@ -126,7 +126,7 @@ internal object PrimitiveListener { LogCenter.log("私聊戳一戳: $operation $action $target $suffix") if (!GlobalEventTransmitter.PrivateNoticeTransmitter - .transPrivatePoke(msgTime, operation.toLong(), target.toLong(), action, suffix, actionImg) + .transPrivatePoke(msgTime, operation.toLong(), action, suffix, actionImg) ) { LogCenter.log("私聊戳一戳推送失败!", Level.WARN) } @@ -161,7 +161,7 @@ internal object PrimitiveListener { } LogCenter.log("来自$applier 的好友申请:$msg ($source)") if (!GlobalEventTransmitter.RequestTransmitter - .transFriendApp(msgTime, applier, msg, flag) + .transFriendApp(msgTime, applierUid, applier, msg, flag) ) { LogCenter.log("好友申请推送失败!", Level.WARN) } @@ -320,8 +320,8 @@ internal object PrimitiveListener { it.key to it.value } - val target = params["uin_str2"] ?: params["mqq_uin"] ?: return - val operation = params["uin_str1"] ?: return + val target = params["uin_str2"] ?: params["mqq_uin"] ?: "" + val operator = params["uin_str1"] ?: "" val suffix = params["suffix_str"] ?: "" val actionImg = params["action_img_url"] ?: "" val action = params["alt_str1"] @@ -332,9 +332,9 @@ internal object PrimitiveListener { when (detail.type) { 1061u -> { - LogCenter.log("群戳一戳($groupId): $operation $action $target $suffix") + LogCenter.log("群戳一戳($groupId): $operator $action $target $suffix") if (!GlobalEventTransmitter.GroupNoticeTransmitter - .transGroupPoke(time, operation.toLong(), target.toLong(), action, suffix, actionImg, groupId) + .transGroupPoke(time, operator.toLong(), target.toLong(), action, suffix, actionImg, groupId) ) { LogCenter.log("群戳一戳推送失败!", Level.WARN) } @@ -506,7 +506,7 @@ internal object PrimitiveListener { if (wholeBan) { LogCenter.log("群全员禁言($groupCode): $operator -> ${if (rawDuration != 0) "开启" else "关闭"}") if (!GlobalEventTransmitter.GroupNoticeTransmitter - .transGroupWholeBan(msgTime, groupCode, operator, rawDuration != 0) + .transGroupWholeBan(msgTime, groupCode, operatorUid, operator, rawDuration != 0) ) { LogCenter.log("群禁言推送失败!", Level.WARN) } @@ -657,7 +657,7 @@ internal object PrimitiveListener { "$time;$groupCode;$uin" } if (!GlobalEventTransmitter.RequestTransmitter - .transGroupApply(time, invitor, invitorUid, "", groupCode, flag) + .transGroupInvite(time, invitorUid, invitor, groupCode, flag) ) { LogCenter.log("邀请入群推送失败!", Level.WARN) }