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

Commit

Permalink
Shamrock: Remove rkey cache
Browse files Browse the repository at this point in the history
Signed-off-by: 白池 <[email protected]>
  • Loading branch information
whitechi73 committed Feb 23, 2024
1 parent 9ad66f2 commit bd6d4f0
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,14 @@ internal object MsgElementConverter {
"file" to md5,
"url" to when (chatType) {
MsgConstant.KCHATTYPEDISC, MsgConstant.KCHATTYPEGROUP -> RichProtoSvc.getGroupPicDownUrl(
originalUrl,
md5
originalUrl = originalUrl,
md5 = md5,
fileId = image.fileUuid,
width = image.picWidth.toUInt(),
height = image.picHeight.toUInt(),
sha = "",
fileSize = image.fileSize.toULong(),
peer = peerId
)

MsgConstant.KCHATTYPEC2C -> RichProtoSvc.getC2CPicDownUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import kotlinx.coroutines.withTimeoutOrNull
import moe.fuqiuluo.shamrock.utils.MD5
import moe.fuqiuluo.shamrock.xposed.helper.AppRuntimeFetcher
import mqq.app.AppRuntime
import mqq.app.MobileQQ
import java.io.File
import kotlin.coroutines.resume
import kotlin.math.abs
Expand Down Expand Up @@ -162,6 +161,17 @@ internal abstract class FileTransfer {
const val BUSI_TYPE_VIDEO_EMOTICON_PIC = 1022
const val BUSI_TYPE_VIDEO_EMOTICON_VIDEO = 1021

const val TRANSFILE_TYPE_PIC = 1
const val TRANSFILE_TYPE_PIC_EMO = 65538
const val TRANSFILE_TYPE_PIC_THUMB = 65537
const val TRANSFILE_TYPE_PISMA = 49
const val TRANSFILE_TYPE_RAWPIC = 131075

const val TRANSFILE_TYPE_PROFILE_COVER = 35
const val TRANSFILE_TYPE_PTT = 2
const val TRANSFILE_TYPE_PTT_SLICE_TO_TEXT = 327696
const val TRANSFILE_TYPE_QQHEAD_PIC = 131074

internal fun createMessageUniseq(time: Long = System.currentTimeMillis()): Long {
var uniseq = (time / 1000).toInt().toLong()
uniseq = uniseq shl 32 or abs(Random.nextInt()).toLong()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import com.tencent.mobileqq.transfile.FileMsg
import com.tencent.mobileqq.transfile.api.IProtoReqManager
import com.tencent.mobileqq.transfile.protohandler.RichProto
import com.tencent.mobileqq.transfile.protohandler.RichProtoProc
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.serialization.ExperimentalSerializationApi

import moe.fuqiuluo.qqinterface.servlet.BaseSvc
import moe.fuqiuluo.shamrock.helper.ContactHelper
import moe.fuqiuluo.shamrock.helper.Level
Expand Down Expand Up @@ -43,7 +41,7 @@ private const val MULTIMEDIA_DOMAIN = "multimedia.nt.qq.com.cn"
private const val C2C_PIC = "c2cpicdw.qpic.cn"

internal object RichProtoSvc: BaseSvc() {
var multiMediaRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"
//var multiMediaRKey = "CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64"

suspend fun getGuildFileDownUrl(peerId: String, channelId: String, fileId: String, bizId: Int): String {
val buffer = sendOidbAW("OidbSvcTrpcTcp.0xfc2_0", 4034, 0, Oidb0xfc2ReqBody(
Expand Down Expand Up @@ -156,15 +154,33 @@ internal object RichProtoSvc: BaseSvc() {
}
}

fun getGroupPicDownUrl(
suspend fun getGroupPicDownUrl(
originalUrl: String,
md5: String,
peer: String = "",
fileId: String = "",
sha: String = "",
fileSize: ULong = 0uL,
width: UInt = 0u,
height: UInt = 0u
): String {
val isNtServer = originalUrl.startsWith("/download")
val domain = if (isNtServer) MULTIMEDIA_DOMAIN else GPRO_PIC
if (originalUrl.isNotEmpty()) {
if (isNtServer && !originalUrl.contains("rkey=")) {
return "https://$domain$originalUrl&rkey=$multiMediaRKey"
getC2CNtPicRKey(
peer = peer,
fileId = fileId,
md5 = md5,
sha = sha,
fileSize = fileSize,
width = width,
height = height
).onSuccess {
return "https://$domain$originalUrl$it"
}.onFailure {
LogCenter.log("getGroupPicDownUrl: ${it.stackTraceToString()}", Level.WARN)
}
}
return "https://$domain$originalUrl"
}
Expand Down Expand Up @@ -198,28 +214,88 @@ internal object RichProtoSvc: BaseSvc() {
}
}
if (isNtServer && !originalUrl.contains("rkey=")) {
return "https://$domain$originalUrl&rkey=$multiMediaRKey"
return "https://$domain$originalUrl&rkey="
}
return "https://$domain$originalUrl"
}
return "https://$$domain/offpic_new/0/123-0-${md5}/0?term=2"
}

fun getGuildPicDownUrl(
suspend fun getGuildPicDownUrl(
originalUrl: String,
md5: String
md5: String,
peer: String = "",
fileId: String = "",
sha: String = "",
fileSize: ULong = 0uL,
width: UInt = 0u,
height: UInt = 0u
): String {
val isNtServer = originalUrl.startsWith("/download")
val domain = if (isNtServer) MULTIMEDIA_DOMAIN else GPRO_PIC
if (originalUrl.isNotEmpty()) {
if (isNtServer && !originalUrl.contains("rkey=")) {
return "https://$domain$originalUrl&rkey=$multiMediaRKey"
getC2CNtPicRKey(
peer = peer,
fileId = fileId,
md5 = md5,
sha = sha,
fileSize = fileSize,
width = width,
height = height
).onSuccess {
return "https://$domain$originalUrl$it"
}.onFailure {
LogCenter.log("getGuildPicDownUrl: ${it.stackTraceToString()}", Level.WARN)
}
return "https://$domain$originalUrl&rkey="
}
return "https://$domain$originalUrl"
}
return "https://$domain/qmeetpic/0/0-0-${md5.uppercase()}/0?term=2"
}

/*
@Deprecated("use getC2CPicDownUrl instead")
suspend fun getC2CPicDownUrl(
peerId: String,
md5: String,
): String {
return suspendCancellableCoroutine {
val runtime = AppRuntimeFetcher.appRuntime
val richProtoReq = RichProto.RichProtoReq()
val downReq: RichProto.RichProtoReq.C2CPicDownReq = RichProto.RichProtoReq.C2CPicDownReq()
downReq.selfUin = runtime.currentAccountUin
downReq.peerUin = peerId
downReq.secondUin = peerId
downReq.uuid = "$md5.jpg"
downReq.msgTime = 0
//downReq.storageSource = "picplatform"
richProtoReq.protoKey = "ftn"
//richProtoReq.protoKey = "multimedia"
downReq.isContact = true
downReq.protocolType = 0
downReq.fileType = FileTransfer.TRANSFILE_TYPE_RAWPIC
richProtoReq.callback = RichProtoProc.RichProtoCallback { _, resp ->
if (resp.resps.isEmpty() || resp.resps.first().errCode != 0) {
LogCenter.log("requestDownPrivateVideo: ${resp.resps.firstOrNull()?.errCode}", Level.WARN)
it.resume("")
} else {
val downResp = resp.resps.first() as RichProto.RichProtoResp.PicDownResp
val url = StringBuilder()
url.append(downResp.mIpList.random().getServerUrl("https://"))
url.append(downResp.urlPath.substring(1))
it.resume(url.toString())
}
}
richProtoReq.protoKey = RichProtoProc.C2C_PIC_DW
richProtoReq.reqs.add(downReq)
richProtoReq.protoReqMgr = runtime.getRuntimeService(IProtoReqManager::class.java, "all")
RichProtoProc.procRichProtoReq(richProtoReq)
}
}*/

suspend fun getC2CNtPicRKey(
peer: String,
fileId: String,
Expand All @@ -229,58 +305,62 @@ internal object RichProtoSvc: BaseSvc() {
width: UInt,
height: UInt
): Result<String> {
val req = run {
Oidb0x11c5Req(
MultiMediaRoutingHead(
request = MultiMediaRoutingHead.Companion.Request(u1 = 2u, u2 = 200u),
peerUser = MultiMediaRoutingHead.Companion.PeerUser(u1 = 2u, u2 = 1u, u3 = 1u, peer = MultiMediaRoutingHead.Companion.Peer(
u1 = 2u,
uid = peer
)),
u1 = MultiMediaRoutingHead.Companion.U1(2u)
),
MultiMediaDataInfo(
MultiMediaDataInfo.Companion.MultiMedia(
MultiMediaDataInfo.Companion.Picture(
size = fileSize,
md5 = md5.lowercase(),
sha = sha.lowercase(),
fileName = "${md5}.jpg",
u1 = MultiMediaDataInfo.Companion.U3(
u1 = 1u,
u2 = 1000u,
u3 = 0u,
u4 = 0u
runCatching {
val req = run {
Oidb0x11c5Req(
MultiMediaRoutingHead(
request = MultiMediaRoutingHead.Companion.Request(u1 = 2u, u2 = 200u),
peerUser = MultiMediaRoutingHead.Companion.PeerUser(u1 = 2u, u2 = 1u, u3 = 1u, peer = MultiMediaRoutingHead.Companion.Peer(
u1 = 2u,
uid = peer
)),
u1 = MultiMediaRoutingHead.Companion.U1(2u)
),
MultiMediaDataInfo(
MultiMediaDataInfo.Companion.MultiMedia(
MultiMediaDataInfo.Companion.Picture(
size = fileSize,
md5 = md5.lowercase(),
sha = sha.lowercase(),
fileName = "${md5}.jpg",
u1 = MultiMediaDataInfo.Companion.U3(
u1 = 1u,
u2 = 1000u,
u3 = 0u,
u4 = 0u
),
width = width,
height = height,
u2 = 0u,
u3 = 1u
),
width = width,
height = height,
fileId = fileId,
u1 = 1u,
u2 = 0u,
u3 = 1u
u3 = 0u,
u4 = 0u
),
fileId = fileId,
u1 = 1u,
u2 = 0u,
u3 = 0u,
u4 = 0u
),
MultiMediaDataInfo.Companion.EXT(
u1 = MultiMediaDataInfo.Companion.U1(
u1 = 0u,
u2 = 0u,
u3 = MultiMediaDataInfo.Companion.U2(
u1 = EMPTY_BYTE_ARRAY,
u2 = EMPTY_BYTE_ARRAY,
u3 = EMPTY_BYTE_ARRAY
),
u4 = 1u
MultiMediaDataInfo.Companion.EXT(
u1 = MultiMediaDataInfo.Companion.U1(
u1 = 0u,
u2 = 0u,
u3 = MultiMediaDataInfo.Companion.U2(
u1 = EMPTY_BYTE_ARRAY,
u2 = EMPTY_BYTE_ARRAY,
u3 = EMPTY_BYTE_ARRAY
),
u4 = 1u
)
)
)
)
)
}.toByteArray()
val buffer = sendOidbAW("OidbSvcTrpcTcp.0x11c5_200", 0x11c5, 200, req, true)?.slice(4)
buffer?.decodeProtobuf<TrpcOidb>()?.buffer?.decodeProtobuf<Oidb0x11c5Resp>()?.result?.rkeyParam?.let {
return Result.success(it)
}.toByteArray()
val buffer = sendOidbAW("OidbSvcTrpcTcp.0x11c5_200", 0x11c5, 200, req, true)?.slice(4)
buffer?.decodeProtobuf<TrpcOidb>()?.buffer?.decodeProtobuf<Oidb0x11c5Resp>()?.result?.rkeyParam?.let {
return Result.success(it)
}
}.onFailure {
return Result.failure(it)
}
return Result.failure(Exception("unable to get c2c nt pic"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal object PrimitiveListener {
}

private fun onGroupMessage(msgTime: Long, body: MessageBody) {
runCatching {
/*runCatching {
body.rich?.elements?.filter {
it.comm != null && it.comm!!.type == 48
}?.map {
Expand All @@ -126,8 +126,7 @@ internal object PrimitiveListener {
}
}
}

}
}*/
}

private suspend fun onC2CPoke(msgTime: Long, richMsg: MessageBody) {
Expand Down

0 comments on commit bd6d4f0

Please sign in to comment.