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

Commit

Permalink
Merge pull request #271 from PisLuanyao/master
Browse files Browse the repository at this point in the history
fix termination by PullConfig for Emu
  • Loading branch information
whitechi73 authored Mar 1, 2024
2 parents 61ffb37 + 8ca0a38 commit 265fff3
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import moe.fuqiuluo.shamrock.remote.HTTPServer
import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig
import moe.fuqiuluo.shamrock.utils.MMKVFetcher
import moe.fuqiuluo.shamrock.utils.PlatformUtils
import moe.fuqiuluo.shamrock.xposed.loader.tmpnativehelper.PutDefaultConfig
import moe.fuqiuluo.shamrock.xposed.helper.internal.DataRequester
import moe.fuqiuluo.shamrock.xposed.helper.internal.DynamicReceiver
import moe.fuqiuluo.shamrock.xposed.helper.internal.IPCRequest
Expand Down Expand Up @@ -70,6 +72,7 @@ class PullConfig: IAction {
DataRequester.request("init", onFailure = {
if (!ShamrockConfig.isInit()) {
ctx.toast("请启动Shamrock主进程以初始化服务,进程将退出。")
PutDefaultConfig.putSettings()
thread {
Thread.sleep(3000)
exitProcess(1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package moe.fuqiuluo.shamrock.xposed.loader.tmpnativehelper

import de.robv.android.xposed.XposedBridge
import kotlinx.serialization.decodeFromString
import moe.fuqiuluo.shamrock.remote.service.config.ConnectionConfig
import moe.fuqiuluo.shamrock.remote.service.config.ServiceConfig
import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig
import moe.fuqiuluo.shamrock.tools.GlobalJson5
import moe.fuqiuluo.shamrock.utils.MMKVFetcher
import mqq.app.MobileQQ
import kotlin.concurrent.thread
import kotlin.system.exitProcess

class PutDefaultConfig {
companion object {
private val configDir = MobileQQ.getContext().getExternalFilesDir(null)!!
.parentFile!!.resolve("Tencent/Shamrock").also {
if (it.exists()) it.delete()
it.mkdirs()
}

private val config = kotlin.runCatching {
GlobalJson5.decodeFromString<ServiceConfig>(configDir.resolve("config.json").also {
if (!it.exists()) it.writeText("{}")
}.readText())
}.onFailure {
XposedBridge.log("[Shamrock] 配置文件有误: ${it.stackTraceToString()}")
}.getOrElse {
ServiceConfig()
}

fun putSettings() {
val mmkv = MMKVFetcher.mmkvWithId("shamrock_config")
if ((!ShamrockConfig.isInit()) && (!mmkv.getBoolean("isEmergencyInitBefore", false))){
mmkv.apply {
putBoolean("tablet", false) // 强制平板模式
putInt("port", 5700) // 主动HTTP端口
putBoolean("ws", false) // 主动WS开关
putBoolean("http", false) // HTTP回调开关
putString("http_addr", null) // WebHook回调地址
putBoolean("ws_client", false) // 被动WS开关
putBoolean("use_cqcode", false) // 使用CQ码
putBoolean("inject_packet", false) // 拦截无用包
putBoolean("debug", false) // 调试模式
putString("key_store", null) // 证书路径
putString("ssl_pwd", null) // 证书密码
putString("ssl_private_pwd", null) // 证书私钥密码
putString("ssl_alias", null) // 证书别名
putInt("ssl_port", 5701) // 主动HTTP端口
putBoolean("alive_reply", true) // 自回复测试
putBoolean("enable_self_msg", false) // 推送自己发的消息
putBoolean("shell", false) // 开启Shell接口
putBoolean("enable_sync_msg_as_sent_msg", true) // 推送同步消息
putBoolean("forbid_useless_process", false) // 禁用QQ生成无用进程
putBoolean("enable_old_bdh", false) // 启用旧版BDH
putBoolean("antiTrace", false)
putBoolean("super_anti", true)
config.defaultToken = null
// config.antiTrace = true
val wsPort = 5800
config.activeWebSocket =
if (config.activeWebSocket == null) ConnectionConfig(
address = "0.0.0.0",
port = wsPort,
) else config.activeWebSocket?.also {
it.port = wsPort
}
config.passiveWebSocket = null
putBoolean("isInit", true)
putBoolean("isEmergencyInitBefore", true)
}
XposedBridge.log("[Shamrock] 强制初始化配置完成,请重新打开QQ")
} else {
XposedBridge.log("[Shamrock] 程序逻辑错误或错误地多次强制初始化")
mmkv.putBoolean("isEmergencyInitBefore", false)
XposedBridge.log("[Shamrock] 如果执意要再次强制初始化,请重新执行程序")
}
}
}
}

0 comments on commit 265fff3

Please sign in to comment.