Shamrock: Using the NT kernel to upload resources

Signed-off-by: 白池 <whitechi73@outlook.com>
This commit is contained in:
白池 2024-02-24 12:31:51 +08:00
parent 46ed966c18
commit 605f58da47
6 changed files with 81 additions and 47 deletions

View File

@ -17,7 +17,7 @@ android {
minSdk = 27
targetSdk = 34
versionCode = getVersionCode()
versionName = "1.0.8" + ".r${getGitCommitCount()}." + getVersionName()
versionName = "1.0.9" + ".r${getGitCommitCount()}." + getVersionName()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {

View File

@ -299,6 +299,16 @@ object ShamrockConfig {
return preferences.getBoolean("enable_self_msg", false)
}
fun enableOldBDH(ctx: Context): Boolean {
val preferences = ctx.getSharedPreferences("config", 0)
return preferences.getBoolean("enable_old_bdh", false)
}
fun setEnableOldBDH(ctx: Context, v: Boolean) {
val preferences = ctx.getSharedPreferences("config", 0)
preferences.edit().putBoolean("enable_old_bdh", v).apply()
}
fun enableSyncMsgAsSentMsg(ctx: Context): Boolean {
val preferences = ctx.getSharedPreferences("config", 0)
return preferences.getBoolean("enable_sync_msg_as_sent_msg", false)
@ -334,7 +344,6 @@ object ShamrockConfig {
"inject_packet" to preferences.getBoolean("inject_packet", false),
"debug" to preferences.getBoolean("debug", false),
"anti_qq_trace" to preferences.getBoolean("anti_qq_trace", true),
//"auto_clear" to preferences.getBoolean("auto_clear", false),
"ssl_private_pwd" to preferences.getString("ssl_private_pwd", ""),
"key_store" to preferences.getString("key_store", ""),
"enable_self_msg" to preferences.getBoolean("enable_self_msg", false),
@ -343,7 +352,8 @@ object ShamrockConfig {
"alive_reply" to preferences.getBoolean("alive_reply", false),
"enable_sync_msg_as_sent_msg" to preferences.getBoolean("enable_sync_msg_as_sent_msg", false),
"disable_auto_sync_setting" to preferences.getBoolean("disable_auto_sync_setting", false),
"forbid_useless_process" to preferences.getBoolean("forbid_useless_process", false)
"forbid_useless_process" to preferences.getBoolean("forbid_useless_process", false),
"enable_old_bdh" to preferences.getBoolean("enable_old_bdh", false),
)
}

View File

@ -102,7 +102,7 @@ fun LabFragment() {
Function(
title = "禁止无用进程",
desc = "禁止QQ生成无用进程浪费内存",
desc = "禁止QQ生成无用进程浪费内存,可能造成部分功能闪退。",
descColor = color,
isSwitch = ShamrockConfig.isForbidUselessProcess(ctx)
) {
@ -221,7 +221,7 @@ fun LabFragment() {
}.onSuccess {
Function(
title = "反检测加强",
desc = "可能导致某些设备频繁闪退",
desc = "可能导致某些设备频繁闪退,将拦截环境包上报。",
descColor = color,
isSwitch = it.getBoolean("super_anti", false)
) { v ->
@ -295,17 +295,16 @@ fun LabFragment() {
return@Function true
}
/*
Function(
title = "使用纯数字ECHO",
desc = "在部分强类型语言框架,需要打开此开关。",
title = "启用旧版资源上传系统",
desc = "如果NT内核无法上传资源请打开本开关。",
descColor = it,
isSwitch = ShamrockConfig.isEchoNumber(ctx)
isSwitch = ShamrockConfig.enableOldBDH(ctx)
) {
ShamrockConfig.setEchoNumber(ctx, it)
ShamrockConfig.setEnableOldBDH(ctx, it)
ShamrockConfig.pushUpdate(ctx)
return@Function true
}*/
}
}
}
}

View File

@ -37,6 +37,7 @@ import moe.fuqiuluo.shamrock.helper.LogicException
import moe.fuqiuluo.shamrock.helper.MessageHelper
import moe.fuqiuluo.shamrock.helper.MusicHelper
import moe.fuqiuluo.shamrock.helper.ParamsException
import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig
import moe.fuqiuluo.shamrock.tools.*
import moe.fuqiuluo.shamrock.utils.AudioUtils
import moe.fuqiuluo.shamrock.utils.FileUtils
@ -714,11 +715,13 @@ internal object MsgElementMaker {
AudioUtils.obtainVideoCover(file.absolutePath, thumbPath!!)
}
Transfer with when (chatType) {
MsgConstant.KCHATTYPEGROUP -> Troop(peerId)
MsgConstant.KCHATTYPEC2C -> Private(peerId)
else -> error("Not supported chatType($chatType) for VideoMsg")
} trans VideoResource(file, File(thumbPath.toString()))
if (ShamrockConfig.enableOldBDH()) {
Transfer with when (chatType) {
MsgConstant.KCHATTYPEGROUP -> Troop(peerId)
MsgConstant.KCHATTYPEC2C -> Private(peerId)
else -> error("Not supported chatType($chatType) for VideoMsg")
} trans VideoResource(file, File(thumbPath.toString()))
}
video.fileTime = AudioUtils.getVideoTime(file)
video.fileSize = file.length()
@ -848,36 +851,53 @@ internal object MsgElementMaker {
else -> {
LogCenter.log({ "Audio To SILK: $file" }, Level.DEBUG)
val result = AudioUtils.audioToSilk(file)
ptt.duration = result.first
ptt.duration = runCatching {
QRoute.api(IAIOPttApi::class.java)
.getPttFileDuration(result.second.absolutePath)
}.getOrElse {
result.first
}
file = result.second
ptt.formatType = MsgConstant.KPTTFORMATTYPESILK
}
}
//val msgService = NTServiceFetcher.kernelService.msgService!!
//val originalPath = msgService.getRichMediaFilePathForMobileQQSend(RichMediaFilePathInfo(
// MsgConstant.KELEMTYPEPTT, 0, ptt.md5HexStr, file.name, 1, 0, null, "", true
//))!!
//if (!QQNTWrapperUtil.CppProxy.fileIsExist(originalPath) || QQNTWrapperUtil.CppProxy.getFileSize(originalPath) != file.length()) {
// QQNTWrapperUtil.CppProxy.copyFile(file.absolutePath, originalPath)
//}
if (!(Transfer with when (chatType) {
MsgConstant.KCHATTYPEGROUP -> Troop(peerId)
MsgConstant.KCHATTYPEC2C -> Private(peerId)
MsgConstant.KCHATTYPETEMPC2CFROMGROUP -> Private(peerId)
else -> error("Not supported chatType($chatType) for RecordMsg")
} trans VoiceResource(file))
) {
return Result.failure(RuntimeException("上传语音失败: $file"))
}
val elem = MsgElement()
elem.elementType = MsgConstant.KELEMTYPEPTT
ptt.md5HexStr = QQNTWrapperUtil.CppProxy.genFileMd5Hex(file.absolutePath)
ptt.fileName = file.name
ptt.filePath = file.absolutePath
ptt.fileSize = file.length()
if (ShamrockConfig.enableOldBDH()) {
if (!(Transfer with when (chatType) {
MsgConstant.KCHATTYPEGROUP -> Troop(peerId)
MsgConstant.KCHATTYPEC2C -> Private(peerId)
MsgConstant.KCHATTYPETEMPC2CFROMGROUP -> Private(peerId)
else -> error("Not supported chatType($chatType) for RecordMsg")
} trans VoiceResource(file))
) {
return Result.failure(RuntimeException("上传语音失败: $file"))
}
ptt.filePath = file.absolutePath
} else {
val msgService = NTServiceFetcher.kernelService.msgService!!
val originalPath = msgService.getRichMediaFilePathForMobileQQSend(RichMediaFilePathInfo(
MsgConstant.KELEMTYPEPTT, 0, ptt.md5HexStr, file.name, 1, 0, null, "", true
))
if (!QQNTWrapperUtil.CppProxy.fileIsExist(originalPath) || QQNTWrapperUtil.CppProxy.getFileSize(originalPath) != file.length()) {
QQNTWrapperUtil.CppProxy.copyFile(file.absolutePath, originalPath)
}
if (originalPath != null) {
ptt.filePath = originalPath
} else {
ptt.filePath = file.absolutePath
}
}
ptt.canConvert2Text = true
ptt.fileId = 0
ptt.fileUuid = ""
ptt.text = ""
if (!isMagic) {
ptt.voiceType = MsgConstant.KPTTVOICETYPESOUNDRECORD
@ -887,11 +907,6 @@ internal object MsgElementMaker {
ptt.voiceChangeType = MsgConstant.KPTTVOICECHANGETYPEECHO
}
ptt.canConvert2Text = false
ptt.fileId = 0
ptt.fileUuid = ""
ptt.text = ""
elem.pttElement = ptt
return Result.success(elem)
@ -926,11 +941,13 @@ internal object MsgElementMaker {
}
requireNotNull(file)
Transfer with when (chatType) {
MsgConstant.KCHATTYPEGROUP -> Troop(peerId)
MsgConstant.KCHATTYPEC2C -> Private(peerId)
else -> error("Not supported chatType($chatType) for PictureMsg")
} trans PictureResource(file)
if (ShamrockConfig.enableOldBDH()) {
Transfer with when (chatType) {
MsgConstant.KCHATTYPEGROUP -> Troop(peerId)
MsgConstant.KCHATTYPEC2C -> Private(peerId)
else -> error("Not supported chatType($chatType) for PictureMsg")
} trans PictureResource(file)
}
val elem = MsgElement()
elem.elementType = MsgConstant.KELEMTYPEPIC

View File

@ -77,6 +77,7 @@ internal object ShamrockConfig {
putBoolean("shell", intent.getBooleanExtra("shell", false)) // 开启Shell接口
putBoolean("enable_sync_msg_as_sent_msg", intent.getBooleanExtra("enable_sync_msg_as_sent_msg", false)) // 推送同步消息
putBoolean("forbid_useless_process", intent.getBooleanExtra("forbid_useless_process", false)) // 禁用QQ生成无用进程
putBoolean("enable_old_bdh", intent.getBooleanExtra("enable_old_bdh", false)) // 启用旧版BDH
}
Config.defaultToken = intent.getStringExtra("token")
Config.antiTrace = intent.getBooleanExtra("anti_qq_trace", true)
@ -175,6 +176,10 @@ internal object ShamrockConfig {
return mmkv.getBoolean("inject_packet", false)
}
fun enableOldBDH(): Boolean {
return mmkv.getBoolean("enable_old_bdh", false)
}
fun isDebug(): Boolean {
return mmkv.getBoolean("debug", false)
}

View File

@ -117,6 +117,9 @@ internal class HookWrapperCodec: IAction {
//from.serviceCmd = "ShamrockInjectedCmd_${from.serviceCmd}"
from.setBusinessFail(1)
from.putWupBuffer(EMPTY_BYTE_ARRAY)
} else if (from.serviceCmd.startsWith("trpc.o3.") && ShamrockConfig.isInjectPacket()) {
from.setBusinessFail(1)
from.putWupBuffer(EMPTY_BYTE_ARRAY)
} else {
pushOnReceive(from)
}