-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
656 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import com.tencent.mobileqq.dt.model.FEBound | ||
import io.ktor.serialization.kotlinx.json.* | ||
import io.ktor.server.application.* | ||
import io.ktor.server.engine.* | ||
import io.ktor.server.netty.* | ||
import io.ktor.server.plugins.contentnegotiation.* | ||
import io.ktor.server.plugins.statuspages.* | ||
import io.ktor.server.request.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import kotlinx.serialization.json.Json | ||
import moe.fuqiuluo.api.* | ||
import moe.fuqiuluo.comm.CommonConfigExt | ||
import moe.fuqiuluo.comm.QSignConfig | ||
import moe.fuqiuluo.comm.checkIllegal | ||
import moe.fuqiuluo.comm.invoke | ||
import java.io.File | ||
|
||
private val API_LIST = arrayOf( | ||
Routing::index, | ||
Routing::sign, | ||
Routing::energy, | ||
Routing::submit, | ||
Routing::requestToken, | ||
Routing::register, | ||
) | ||
|
||
private val json1 = Json { | ||
encodeDefaults = true | ||
prettyPrint = true | ||
ignoreUnknownKeys = true | ||
} | ||
|
||
fun main(args: Array<String>) { | ||
val file = File("qsign.json") | ||
val s = if (file.exists()) file.readText() else "{}" | ||
val cfg = json1.decodeFromString(CommonConfigExt.serializer(), s) | ||
cfg.apply() | ||
file.writeText(json1.encodeToString(CommonConfigExt.serializer(), cfg)) | ||
|
||
args().also { | ||
val baseDir = File(it["basePath", "Lack of basePath."]).also { | ||
BASE_PATH = it | ||
} | ||
if (!baseDir.exists() || | ||
!baseDir.isDirectory || | ||
!baseDir.resolve("libfekit.so").exists() || | ||
!baseDir.resolve("config.json").exists() | ||
|| !baseDir.resolve("dtconfig.json").exists() | ||
) { | ||
error("The base path is invalid, perhaps it is not a directory or something is missing inside.") | ||
} else { | ||
val json = Json { ignoreUnknownKeys = true } | ||
FEBound.initAssertConfig(baseDir) | ||
println("FEBond sum = ${FEBound.checkCurrent()}") | ||
CONFIG = json.decodeFromString<QSignConfig>(baseDir.resolve("config.json").readText()) | ||
.apply { checkIllegal() } | ||
println("Load Package = ${CONFIG.protocol}") | ||
} | ||
} | ||
CONFIG.server.also { | ||
embeddedServer(Netty, host = it.host, port = it.port, module = Application::init) | ||
.start(wait = true) | ||
} | ||
|
||
} | ||
|
||
fun Application.init() { | ||
install(ContentNegotiation) { | ||
json(Json { | ||
prettyPrint = true | ||
isLenient = true | ||
ignoreUnknownKeys = true | ||
}) | ||
} | ||
install(StatusPages) { | ||
exception<Throwable> { call, cause -> | ||
if (CONFIG.unidbg.debug) { | ||
cause.printStackTrace() | ||
} | ||
call.respond(APIResult(1, cause.message ?: cause.javaClass.name, call.request.uri)) | ||
} | ||
} | ||
routing { | ||
API_LIST.forEach { it(this) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package moe.fuqiuluo.api | ||
|
||
import io.ktor.server.application.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import moe.fuqiuluo.ext.fetchGet | ||
import moe.fuqiuluo.ext.hex2ByteArray | ||
import moe.fuqiuluo.ext.toHexString | ||
|
||
fun Routing.energy() { | ||
get("/custom_energy") { | ||
val uin = fetchGet("uin")!!.toLong() | ||
val data = fetchGet("data")!! | ||
val salt = fetchGet("salt")!!.hex2ByteArray() | ||
|
||
val androidId = fetchGet("android_id", def = "") | ||
val guid = fetchGet("guid", def = "") | ||
val sign = kotlin.runCatching { | ||
UnidbgFetchQSign.customEnergy(uin, data, salt, androidId, guid) | ||
}.onFailure { | ||
it.printStackTrace() | ||
}.getOrNull() | ||
|
||
if (sign == null) { | ||
call.respond(APIResult(-1, "failed", null)) | ||
} else { | ||
call.respond(APIResult(0, "success", sign.toHexString())) | ||
} | ||
} | ||
|
||
get("/energy") { | ||
val uin = fetchGet("uin")!!.toLong() | ||
|
||
val data = fetchGet("data")!! | ||
val androidId = fetchGet("android_id", def = "") | ||
val guid = fetchGet("guid", def = null)?.hex2ByteArray() | ||
val version = fetchGet("version", def = null) | ||
val phone = fetchGet("phone", def = null)?.toByteArray() // 86-xxx | ||
val receipt = fetchGet("receipt", def = null)?.toByteArray() | ||
val sign = kotlin.runCatching { | ||
UnidbgFetchQSign.energy(uin, data, null, version, guid, androidId, phone, receipt) | ||
}.onFailure { | ||
it.printStackTrace() | ||
}.getOrNull() | ||
|
||
if (sign == null) { | ||
call.respond(APIResult(-1, "failed", null)) | ||
} else { | ||
call.respond(APIResult(0, "success", sign.toHexString())) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package moe.fuqiuluo.api | ||
|
||
object SessionNotFoundError : RuntimeException("Uin is not registered.") | ||
|
||
object WrongKeyError : RuntimeException("Wrong API key.") | ||
|
||
object MissingKeyError : RuntimeException("First use must be submitted with android_id and guid.") | ||
|
||
object BlackListError : RuntimeException("Blacklist uin.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package moe.fuqiuluo.api | ||
|
||
import CONFIG | ||
import io.ktor.server.application.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import kotlinx.serialization.Contextual | ||
import kotlinx.serialization.Serializable | ||
import moe.fuqiuluo.comm.Protocol | ||
import top.mrxiaom.qsign.BuildConstants | ||
import java.lang.management.ManagementFactory | ||
|
||
@Serializable | ||
data class APIResult<T>( | ||
val code: Int, | ||
val msg: String = "", | ||
@Contextual | ||
val data: T? = null | ||
) | ||
|
||
@Serializable | ||
data class APIInfo( | ||
val version: String, | ||
val protocol: Protocol, | ||
val pid: Int | ||
) | ||
|
||
fun Routing.index() { | ||
get("/") { | ||
call.respond( | ||
APIResult( | ||
0, "IAA 云天明 章北海 猫", APIInfo( | ||
version = BuildConstants.VERSION, | ||
protocol = CONFIG.protocol, | ||
pid = runCatching { ManagementFactory.getRuntimeMXBean().name.split("@")[0].toInt() }.getOrNull() | ||
?: -1 | ||
) | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package moe.fuqiuluo.api | ||
|
||
import CONFIG | ||
import com.tencent.mobileqq.channel.SsoPacket | ||
import io.ktor.server.application.* | ||
import io.ktor.server.request.* | ||
import io.ktor.server.response.* | ||
import io.ktor.server.routing.* | ||
import io.ktor.util.pipeline.* | ||
import kotlinx.serialization.Serializable | ||
import moe.fuqiuluo.ext.fetchGet | ||
import moe.fuqiuluo.ext.fetchPost | ||
import moe.fuqiuluo.ext.hex2ByteArray | ||
import moe.fuqiuluo.ext.toHexString | ||
|
||
fun Routing.sign() { | ||
get("/sign") { | ||
val uin = fetchGet("uin")!! | ||
val qua = fetchGet("qua", CONFIG.protocol.qua)!! | ||
val cmd = fetchGet("cmd")!! | ||
val seq = fetchGet("seq")!!.toInt() | ||
val buffer = fetchGet("buffer")!!.hex2ByteArray() | ||
val qimei36 = fetchGet("qimei36", def = "")!! | ||
|
||
val androidId = fetchGet("android_id", def = "")!! | ||
val guid = fetchGet("guid", def = "")!! | ||
|
||
requestSign(cmd, uin, qua, seq, buffer, qimei36, androidId, guid) | ||
} | ||
|
||
post("/sign") { | ||
val param = call.receiveParameters() | ||
val uin = fetchPost(param, "uin")!! | ||
val qua = fetchPost(param, "qua", CONFIG.protocol.qua)!! | ||
val cmd = fetchPost(param, "cmd")!! | ||
val seq = fetchPost(param, "seq")!!.toInt() | ||
val buffer = fetchPost(param, "buffer")!!.hex2ByteArray() | ||
val qimei36 = fetchPost(param, "qimei36", def = "")!! | ||
|
||
val androidId = param["android_id"] ?: "" | ||
val guid = param["guid"] ?: "" | ||
|
||
requestSign(cmd, uin, qua, seq, buffer, qimei36, androidId, guid) | ||
} | ||
} | ||
|
||
@Serializable | ||
private data class Sign( | ||
val token: String, | ||
val extra: String, | ||
val sign: String, | ||
val o3did: String, | ||
val requestCallback: List<SsoPacket> | ||
) | ||
|
||
private suspend fun PipelineContext<Unit, ApplicationCall>.requestSign( | ||
cmd: String, | ||
uin: String, | ||
qua: String, | ||
seq: Int, | ||
buffer: ByteArray, | ||
qimei36: String, | ||
androidId: String, | ||
guid: String | ||
) { | ||
val sign = runCatching { | ||
UnidbgFetchQSign.sign(cmd, uin.toLong(), seq, buffer, qua, qimei36, androidId, guid) | ||
}.onFailure { | ||
it.printStackTrace() | ||
}.getOrNull() | ||
|
||
if (sign == null) { | ||
call.respond(APIResult(-1, "failed", null)) | ||
} else { | ||
call.respond( | ||
APIResult( | ||
0, "success", Sign( | ||
sign.token.toHexString(), | ||
sign.extra.toHexString(), | ||
sign.sign.toHexString(), sign.o3did, sign.requestCallback | ||
) | ||
) | ||
) | ||
} | ||
} |
Oops, something went wrong.