From fa8b7b5bb9a79549a0b887750c550733c691b69d Mon Sep 17 00:00:00 2001 From: cssxsh Date: Thu, 27 Jan 2022 16:55:20 +0800 Subject: [PATCH] feat: mac --- README.md | 1 + .../xyz/cssxsh/mirai/MiraiDeviceGenerator.kt | 43 +++++++++++++++---- .../cssxsh/mirai/plugin/MiraiDevicePlugin.kt | 21 +++++---- .../xyz/cssxsh/mirai/plugin/mac.json | 8 ++++ .../xyz/cssxsh/mirai/plugin/models.json | 35 +++++++++++++++ .../xyz/cssxsh/mirai/plugin/sdks.json | 8 ++++ 6 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 src/main/resources/xyz/cssxsh/mirai/plugin/mac.json create mode 100644 src/main/resources/xyz/cssxsh/mirai/plugin/models.json create mode 100644 src/main/resources/xyz/cssxsh/mirai/plugin/sdks.json diff --git a/README.md b/README.md index 6caa556..935a965 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ | name | board | |:----:|:-------:| +| 888 | sm8350 | | 835 | msm8998 | | 820 | msm8996 | | 750G | sm7225 | diff --git a/src/main/kotlin/xyz/cssxsh/mirai/MiraiDeviceGenerator.kt b/src/main/kotlin/xyz/cssxsh/mirai/MiraiDeviceGenerator.kt index 6c11016..aa5f349 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/MiraiDeviceGenerator.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/MiraiDeviceGenerator.kt @@ -7,6 +7,7 @@ import net.mamoe.mirai.utils.* import kotlin.random.* @OptIn(MiraiExperimentalApi::class) +@Suppress("unused") public class MiraiDeviceGenerator : DeviceInfoService { override val priority: Int get() = super.priority - 1 @@ -43,6 +44,10 @@ public class MiraiDeviceGenerator : DeviceInfoService { ) ) + internal var addr = mapOf( + "Xiaomi" to listOf("c4:6a:b7") + ) + @Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER") public override fun load(bot: Bot): DeviceInfo { val file = bot.configuration.workingDir.resolve("device.json") @@ -56,23 +61,23 @@ public class MiraiDeviceGenerator : DeviceInfoService { public override fun generate(): DeviceInfo { val model = models.random(random) - val sdk = sdks.random(random) + val sdk = model.sdks.randomOrNull(random) ?: sdks.random(random) return DeviceInfo( display = model.display.toByteArray(), product = model.name.toByteArray(), device = model.device.toByteArray(), board = model.board.toByteArray(), brand = model.brand.toByteArray(), - model = model.name.toByteArray(), + model = model.model.ifBlank { model.name }.toByteArray(), bootloader = "unknown".toByteArray(), - fingerprint = model.finger().toByteArray(), + fingerprint = model.finger(sdk).toByteArray(), bootId = generateUUID(getRandomByteArray(16, random).md5()).toByteArray(), procVersion = model.proc().toByteArray(), - baseBand = byteArrayOf(), + baseBand = model.baseBand.hexToBytes(), version = sdk.toDeviceVersion(), simInfo = "T-Mobile".toByteArray(), osType = "android".toByteArray(), - macAddress = "02:00:00:00:00:00".toByteArray(), + macAddress = model.mac().toByteArray(), wifiBSSID = "02:00:00:00:00:00".toByteArray(), wifiSSID = "".toByteArray(), imsiMd5 = getRandomByteArray(16, random).md5(), @@ -81,8 +86,8 @@ public class MiraiDeviceGenerator : DeviceInfoService { ) } - internal fun Model.finger(): String { - return "${brand}/${device}/${device}:10/${display}/${getRandomIntString(7, random)}:user/release-keys" + internal fun Model.finger(sdk: SdkVersion): String { + return "${brand}/${device}/${device}:${sdk.release}/${display}/${sdk.incremental}:user/release-keys" } internal fun Model.imei(): String { @@ -92,7 +97,22 @@ public class MiraiDeviceGenerator : DeviceInfoService { } internal fun Model.proc(): String { - return "Linux version 3.0.31-${getRandomString(8, random)} (android-build@xxx.xxx.xxx.xxx.com)" + return proc.ifBlank { + "Linux version 3.0.31-${getRandomString(8, random)} (android-build@xxx.xxx.xxx.xxx.com)" + } + } + + internal fun Model.mac(): String { + return if (mac.isNotBlank()) { + mac + ':' + getRandomByteArray(3, random).toUHexString(separator = ":") + } else { + val head = addr[brand]?.randomOrNull(random) + if (head != null) { + head + ':' + getRandomByteArray(3, random).toUHexString(separator = ":") + } else { + "02:00:00:00:00:00" + } + } } internal fun SdkVersion.toDeviceVersion(): DeviceInfo.Version { @@ -121,7 +141,12 @@ public class MiraiDeviceGenerator : DeviceInfoService { val fac: String, val board: String, val device: String, - val display: String + val display: String, + val model: String = "", + val mac: String = "", + val baseBand: String = "", + val proc: String = "", + val sdks: List = emptyList(), ) @Serializable diff --git a/src/main/kotlin/xyz/cssxsh/mirai/plugin/MiraiDevicePlugin.kt b/src/main/kotlin/xyz/cssxsh/mirai/plugin/MiraiDevicePlugin.kt index a4e46b2..bcf35ea 100644 --- a/src/main/kotlin/xyz/cssxsh/mirai/plugin/MiraiDevicePlugin.kt +++ b/src/main/kotlin/xyz/cssxsh/mirai/plugin/MiraiDevicePlugin.kt @@ -32,19 +32,24 @@ public object MiraiDevicePlugin : KotlinPlugin( val json = Json { prettyPrint = true } with(dataFolder.resolve("models.json")) { - if (exists()) { - generator.models = json.decodeFromString(readText()) - } else { - writeText(json.encodeToString(generator.models)) + if (exists().not()) { + writeText(getResource("models.json") ?: throw NoSuchElementException("models.json")) } + generator.models = json.decodeFromString(readText()) } with(dataFolder.resolve("sdks.json")) { - if (exists()) { - generator.sdks = json.decodeFromString(readText()) - } else { - writeText(json.encodeToString(generator.sdks)) + if (exists().not()) { + writeText(getResource("sdks.json") ?: throw NoSuchElementException("sdks.json")) } + generator.sdks = json.decodeFromString(readText()) + } + + with(dataFolder.resolve("mac.json")) { + if (exists().not()) { + writeText(getResource("mac.json") ?: throw NoSuchElementException("mac.json")) + } + generator.addr = json.decodeFromString(readText()) } launch { diff --git a/src/main/resources/xyz/cssxsh/mirai/plugin/mac.json b/src/main/resources/xyz/cssxsh/mirai/plugin/mac.json new file mode 100644 index 0000000..e26a55c --- /dev/null +++ b/src/main/resources/xyz/cssxsh/mirai/plugin/mac.json @@ -0,0 +1,8 @@ +{ + "Huawei": [ + "4c:50:77" + ], + "Xiaomi": [ + "c4:6a:b7" + ] +} \ No newline at end of file diff --git a/src/main/resources/xyz/cssxsh/mirai/plugin/models.json b/src/main/resources/xyz/cssxsh/mirai/plugin/models.json new file mode 100644 index 0000000..1a35f1f --- /dev/null +++ b/src/main/resources/xyz/cssxsh/mirai/plugin/models.json @@ -0,0 +1,35 @@ +[ + { + "name": "Redmi Note 9 Pro 5G", + "brand": "Xiaomi", + "tac": "864365", + "fac": "05", + "board": "sm7225", + "device": "sagit", + "display": "OPR1.170623.027" + }, + { + "name": "Redmi Note 8", + "brand": "Xiaomi", + "tac": "863971", + "fac": "05", + "board": "msm8953", + "device": "sagit", + "display": "OPR1.170623.027" + }, + { + "name": "MI 11 PRO", + "brand": "Xiaomi", + "tac": "861033", + "fac": "05", + "board": "sm8350", + "device": "mars", + "display": "SKQ1.211006.001", + "proc": "Linux version 5.4.86-qgki-gda9f45eed743 (builder@bj.idc.xiaomi.com)", + "sdk": { + "incremental": "22.1.17", + "release": "12", + "codename": "REL" + } + } +] \ No newline at end of file diff --git a/src/main/resources/xyz/cssxsh/mirai/plugin/sdks.json b/src/main/resources/xyz/cssxsh/mirai/plugin/sdks.json new file mode 100644 index 0000000..e529f55 --- /dev/null +++ b/src/main/resources/xyz/cssxsh/mirai/plugin/sdks.json @@ -0,0 +1,8 @@ +[ + { + "incremental": "5891938", + "release": "10", + "codename": "REL", + "sdk": 29 + } +] \ No newline at end of file