Skip to content

Commit

Permalink
use: DeviceInfoBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Jul 25, 2023
1 parent 4f53312 commit 367c5ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
kotlin("jvm") version "1.7.22"
kotlin("plugin.serialization") version "1.7.22"

id("net.mamoe.mirai-console") version "2.15.0-M1"
id("net.mamoe.mirai-console") version "2.15.0"
id("me.him188.maven-central-publish") version "1.0.0-dev-3"
}

Expand All @@ -28,7 +28,7 @@ repositories {
dependencies {
testImplementation(kotlin("test"))
//
implementation(platform("net.mamoe:mirai-bom:2.15.0-M1"))
implementation(platform("net.mamoe:mirai-bom:2.15.0"))
compileOnly("net.mamoe:mirai-core-utils")
compileOnly("net.mamoe:mirai-console-compiler-common")
}
Expand Down
42 changes: 17 additions & 25 deletions src/main/kotlin/xyz/cssxsh/mirai/device/MiraiDeviceGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import kotlinx.serialization.builtins.*
import kotlinx.serialization.json.*
import net.mamoe.mirai.*
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.DeviceInfo.Companion.loadAsDeviceInfo
import kotlin.random.*

public class MiraiDeviceGenerator {
Expand Down Expand Up @@ -46,35 +45,27 @@ public class MiraiDeviceGenerator {
file.writeText(DeviceInfoManager.serialize(it))
}
}
// 23/05/08 fix: DeviceInfoManager.deserialize(file.readText())
return file.loadAsDeviceInfo()
return DeviceInfoManager.deserialize(file.readText())
}

public fun generate(): DeviceInfo {
val model = models.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.model.ifBlank { model.device }.toByteArray(),
bootloader = "unknown".toByteArray(),
fingerprint = model.finger(sdk).toByteArray(),
bootId = generateUUID(getRandomByteArray(16, random).md5()).toByteArray(),
procVersion = model.proc().toByteArray(),
baseBand = model.baseBand.hexToBytes(),
version = sdk.toDeviceVersion(),
simInfo = "T-Mobile".toByteArray(),
osType = "android".toByteArray(),
macAddress = model.mac().toByteArray(),
wifiBSSID = "02:00:00:00:00:00".toByteArray(),
wifiSSID = "<unknown ssid>".toByteArray(),
imsiMd5 = getRandomByteArray(16, random).md5(),
imei = model.imei(),
apn = "wifi".toByteArray()
)

return DeviceInfoBuilder.fromRandom()
.display(model.display)
.product(model.name)
.device(model.device)
.board(model.board)
.brand(model.brand)
.model(model.model.ifEmpty { model.device })
.fingerprint(model.finger(sdk))
.procVersion(model.proc())
.baseBand(model.baseBand.hexToBytes())
.version(sdk.toDeviceVersion())
.macAddress(model.mac())
.imei(model.imei())
.build()
}

// ro.build.fingerprint
Expand Down Expand Up @@ -146,6 +137,7 @@ public class MiraiDeviceGenerator {
val board: String,
// device ~ model ro.product.model
val device: String,
//
val model: String = "",
// 操作系统版本号
val display: String,
Expand Down

0 comments on commit 367c5ae

Please sign in to comment.