Skip to content

Commit

Permalink
build: 更新 mirai 版本至 v2.15.0-RC
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Jun 29, 2023
1 parent 6b9a8c3 commit 6f8246c
Showing 1 changed file with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,34 @@ public fun simbotMiraiDeviceInfo(c: Long, s: Long = DEFAULT_SIMBOT_MIRAI_DEVICE_
wifiBSSID = "02:00:00:00:00:00".toByteArray(),
wifiSSID = "<unknown ssid>".toByteArray(),
imsiMd5 = md5 { digest(getRandomByteArray(r)) },
imei = getRandomString(15, '0'..'9', r),
apn = "wifi".toByteArray()

imei = "86" + getRandomString(15, '0'..'9', r),
apn = "wifi".toByteArray(),
androidId = getRandomByteArray(8, r).toUHexString("").lowercase().encodeToByteArray()

)
}


/*
* 以下源代码修改自
* net.mamoe.mirai.utils.SystemDeviceInfo.kt、
* net.mamoe.mirai.utils.ExternalImage.kt
* net.mamoe.mirai.utils.ExternalImage.kt、
* net.mamoe.mirai.utils.Bytes.kt
*
* Copyright 2019-2023 Mamoe Technologies and contributors.
*
* 原源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/

/**
* 生成长度为 16, 元素为随机 `0..255` 的 [ByteArray]
*/
private fun getRandomByteArray(r: Random): ByteArray = ByteArray(16) { r.nextInt(0..255).toByte() }
private fun getRandomByteArray(r: Random): ByteArray = getRandomByteArray(16, r)

private fun getRandomByteArray(length: Int, r: Random): ByteArray = ByteArray(length) { r.nextInt(0..255).toByte() }


private val defaultRanges: Array<CharRange> = arrayOf('a'..'z', 'A'..'Z', '0'..'9')

Expand Down Expand Up @@ -102,3 +109,45 @@ private fun Byte.fixToString(): String {
}
}

private fun ByteArray.toUHexString(
separator: String = " ",
offset: Int = 0,
length: Int = this.size - offset
): String {
this.checkOffsetAndLength(offset, length)
if (length == 0) {
return ""
}
val lastIndex = offset + length
return buildString(length * 2) {
this@toUHexString.forEachIndexed { index, it ->
if (index in offset until lastIndex) {
val ret = it.toUByte().toString(16).uppercase()
if (ret.length == 1) append('0')
append(ret)
if (index < lastIndex - 1) append(separator)
}
}
}
}

private fun ByteArray.checkOffsetAndLength(offset: Int, length: Int) {
require(offset >= 0) { "offset shouldn't be negative: $offset" }
require(length >= 0) { "length shouldn't be negative: $length" }
require(offset + length <= this.size) { "offset ($offset) + length ($length) > array.size (${this.size})" }
}

private fun luhn(imei: String): Int {
var odd = false
val zero = '0'
val sum = imei.sumOf { char ->
odd = !odd
if (odd) {
char.code - zero.code
} else {
val s = (char.code - zero.code) * 2
s % 10 + s / 10
}
}
return (10 - sum % 10) % 10
}

0 comments on commit 6f8246c

Please sign in to comment.