Skip to content

Commit

Permalink
feat: mac
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Jan 27, 2022
1 parent 4056561 commit fa8b7b5
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

| name | board |
|:----:|:-------:|
| 888 | sm8350 |
| 835 | msm8998 |
| 820 | msm8996 |
| 750G | sm7225 |
Expand Down
43 changes: 34 additions & 9 deletions src/main/kotlin/xyz/cssxsh/mirai/MiraiDeviceGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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 = "<unknown ssid>".toByteArray(),
imsiMd5 = getRandomByteArray(16, random).md5(),
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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<SdkVersion> = emptyList(),
)

@Serializable
Expand Down
21 changes: 13 additions & 8 deletions src/main/kotlin/xyz/cssxsh/mirai/plugin/MiraiDevicePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/xyz/cssxsh/mirai/plugin/mac.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Huawei": [
"4c:50:77"
],
"Xiaomi": [
"c4:6a:b7"
]
}
35 changes: 35 additions & 0 deletions src/main/resources/xyz/cssxsh/mirai/plugin/models.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
8 changes: 8 additions & 0 deletions src/main/resources/xyz/cssxsh/mirai/plugin/sdks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"incremental": "5891938",
"release": "10",
"codename": "REL",
"sdk": 29
}
]

0 comments on commit fa8b7b5

Please sign in to comment.