Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
32e854db
Commit
32e854db
authored
Feb 14, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve DeviceInfo
parent
bf7189fd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
34 deletions
+103
-34
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
...roidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
+12
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt
...mmonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt
...src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt
+4
-5
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/SystemDeviceInfo.kt
...mmonMain/kotlin/net.mamoe.mirai/utils/SystemDeviceInfo.kt
+4
-4
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
+82
-23
No files found.
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
View file @
32e854db
...
@@ -14,13 +14,23 @@ import android.net.wifi.WifiManager
...
@@ -14,13 +14,23 @@ import android.net.wifi.WifiManager
import
android.os.Build
import
android.os.Build
import
android.telephony.TelephonyManager
import
android.telephony.TelephonyManager
import
kotlinx.io.core.toByteArray
import
kotlinx.io.core.toByteArray
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.Transient
import
java.io.File
import
java.io.File
/**
/**
* 部分引用指向 [Build].
* 部分引用指向 [Build].
* 部分需要权限, 若无权限则会使用默认值.
* 部分需要权限, 若无权限则会使用默认值.
*/
*/
actual
open
class
SystemDeviceInfo
actual
constructor
(
context
:
Context
)
:
DeviceInfo
(
context
)
{
@Serializable
actual
open
class
SystemDeviceInfo
actual
constructor
()
:
DeviceInfo
()
{
actual
constructor
(
context
:
Context
)
:
this
()
{
this
.
context
=
context
}
@Transient
final
override
lateinit
var
context
:
Context
override
val
display
:
ByteArray
get
()
=
Build
.
DISPLAY
.
toByteArray
()
override
val
display
:
ByteArray
get
()
=
Build
.
DISPLAY
.
toByteArray
()
override
val
product
:
ByteArray
get
()
=
Build
.
PRODUCT
.
toByteArray
()
override
val
product
:
ByteArray
get
()
=
Build
.
PRODUCT
.
toByteArray
()
override
val
device
:
ByteArray
get
()
=
Build
.
DEVICE
.
toByteArray
()
override
val
device
:
ByteArray
get
()
=
Build
.
DEVICE
.
toByteArray
()
...
@@ -88,6 +98,7 @@ actual open class SystemDeviceInfo actual constructor(context: Context) : Device
...
@@ -88,6 +98,7 @@ actual open class SystemDeviceInfo actual constructor(context: Context) : Device
override
val
androidId
:
ByteArray
get
()
=
Build
.
ID
.
toByteArray
()
override
val
androidId
:
ByteArray
get
()
=
Build
.
ID
.
toByteArray
()
override
val
apn
:
ByteArray
get
()
=
"wifi"
.
toByteArray
()
override
val
apn
:
ByteArray
get
()
=
"wifi"
.
toByteArray
()
@Serializable
object
Version
:
DeviceInfo
.
Version
{
object
Version
:
DeviceInfo
.
Version
{
override
val
incremental
:
ByteArray
get
()
=
Build
.
VERSION
.
INCREMENTAL
.
toByteArray
()
override
val
incremental
:
ByteArray
get
()
=
Build
.
VERSION
.
INCREMENTAL
.
toByteArray
()
override
val
release
:
ByteArray
get
()
=
Build
.
VERSION
.
RELEASE
.
toByteArray
()
override
val
release
:
ByteArray
get
()
=
Build
.
VERSION
.
RELEASE
.
toByteArray
()
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt
View file @
32e854db
...
@@ -45,7 +45,7 @@ class BotConfiguration {
...
@@ -45,7 +45,7 @@ class BotConfiguration {
*/
*/
var
networkLoggerSupplier
:
((
BotNetworkHandler
)
->
MiraiLogger
)
=
{
DefaultLogger
(
"Network(${it.bot.uin})"
)
}
var
networkLoggerSupplier
:
((
BotNetworkHandler
)
->
MiraiLogger
)
=
{
DefaultLogger
(
"Network(${it.bot.uin})"
)
}
/**
/**
* 设备信息覆盖
* 设备信息覆盖
. 默认使用随机的设备信息.
*/
*/
var
deviceInfo
:
((
Context
)
->
DeviceInfo
)?
=
null
var
deviceInfo
:
((
Context
)
->
DeviceInfo
)?
=
null
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt
View file @
32e854db
...
@@ -11,16 +11,15 @@ package net.mamoe.mirai.utils
...
@@ -11,16 +11,15 @@ package net.mamoe.mirai.utils
import
kotlinx.serialization.SerialId
import
kotlinx.serialization.SerialId
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.Transient
import
kotlinx.serialization.protobuf.ProtoBuf
import
kotlinx.serialization.protobuf.ProtoBuf
import
net.mamoe.mirai.utils.cryptor.contentToString
/**
/**
* 设备信息. 可通过继承 [SystemDeviceInfo] 来在默认的基础上修改
* 设备信息. 可通过继承 [SystemDeviceInfo] 来在默认的基础上修改
*/
*/
abstract
class
DeviceInfo
internal
constructor
(
abstract
class
DeviceInfo
{
context
:
Context
@Transient
)
{
abstract
val
context
:
Context
val
context
:
Context
by
context
.
unsafeWeakRef
()
abstract
val
display
:
ByteArray
abstract
val
display
:
ByteArray
abstract
val
product
:
ByteArray
abstract
val
product
:
ByteArray
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/SystemDeviceInfo.kt
View file @
32e854db
...
@@ -9,13 +9,13 @@
...
@@ -9,13 +9,13 @@
package
net.mamoe.mirai.utils
package
net.mamoe.mirai.utils
import
net.mamoe.mirai.utils.Context
import
net.mamoe.mirai.utils.DeviceInfo
/**
/**
* 通过本机信息来获取设备信息.
* 通过本机信息来获取设备信息.
*
*
* Android: 获取手机信息, 与 QQ 官方相同.
* Android: 获取手机信息, 与 QQ 官方相同.
* JVM: 部分为常量, 部分为随机
* JVM: 部分为常量, 部分为随机
*/
*/
open
expect
class
SystemDeviceInfo
(
context
:
Context
)
:
DeviceInfo
expect
open
class
SystemDeviceInfo
:
DeviceInfo
{
\ No newline at end of file
constructor
()
constructor
(
context
:
Context
)
}
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
View file @
32e854db
...
@@ -10,38 +10,97 @@
...
@@ -10,38 +10,97 @@
package
net.mamoe.mirai.utils
package
net.mamoe.mirai.utils
import
kotlinx.io.core.toByteArray
import
kotlinx.io.core.toByteArray
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.Transient
import
kotlinx.serialization.UnstableDefault
import
kotlinx.serialization.json.Json
import
net.mamoe.mirai.utils.io.getRandomByteArray
import
net.mamoe.mirai.utils.io.getRandomByteArray
import
net.mamoe.mirai.utils.io.getRandomString
import
net.mamoe.mirai.utils.io.getRandomString
import
java.io.File
/**
* 加载或创建一个设备信息.
*/
@UseExperimental
(
UnstableDefault
::
class
)
fun
File
.
loadAsDeviceInfo
(
context
:
Context
=
ContextImpl
()):
DeviceInfo
{
if
(!
this
.
exists
()
||
this
.
length
()
==
0L
)
{
return
SystemDeviceInfo
(
context
).
also
{
this
.
writeText
(
Json
.
plain
.
stringify
(
SystemDeviceInfo
.
serializer
(),
it
))
}
}
return
Json
.
nonstrict
.
parse
(
DeviceInfoData
.
serializer
(),
this
.
readText
()).
also
{
it
.
context
=
context
}
}
@Serializable
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
actual
open
class
SystemDeviceInfo
actual
constructor
(
context
:
Context
)
:
DeviceInfo
(
context
)
{
actual
open
class
SystemDeviceInfo
actual
constructor
()
:
DeviceInfo
()
{
override
val
display
:
ByteArray
get
()
=
"MIRAI.200122.001"
.
toByteArray
()
actual
constructor
(
context
:
Context
)
:
this
()
{
override
val
product
:
ByteArray
get
()
=
"mirai"
.
toByteArray
()
this
.
context
=
context
override
val
device
:
ByteArray
get
()
=
"mirai"
.
toByteArray
()
}
override
val
board
:
ByteArray
get
()
=
"mirai"
.
toByteArray
()
override
val
brand
:
ByteArray
get
()
=
"mamoe"
.
toByteArray
()
@Transient
override
val
model
:
ByteArray
get
()
=
"mirai"
.
toByteArray
()
final
override
lateinit
var
context
:
Context
override
val
bootloader
:
ByteArray
get
()
=
"unknown"
.
toByteArray
()
override
val
fingerprint
:
ByteArray
get
()
=
"mamoe/mirai/mirai:10/MIRAI.200122.001/5891938:user/release-keys"
.
toByteArray
()
override
val
display
:
ByteArray
=
"MIRAI.200122.001"
.
toByteArray
()
override
val
product
:
ByteArray
=
"mirai"
.
toByteArray
()
override
val
device
:
ByteArray
=
"mirai"
.
toByteArray
()
override
val
board
:
ByteArray
=
"mirai"
.
toByteArray
()
override
val
brand
:
ByteArray
=
"mamoe"
.
toByteArray
()
override
val
model
:
ByteArray
=
"mirai"
.
toByteArray
()
override
val
bootloader
:
ByteArray
=
"unknown"
.
toByteArray
()
override
val
fingerprint
:
ByteArray
=
"mamoe/mirai/mirai:10/MIRAI.200122.001/${getRandomString(7, '0'..'9')}:user/release-keys"
.
toByteArray
()
override
val
bootId
:
ByteArray
=
ExternalImage
.
generateUUID
(
md5
(
getRandomByteArray
(
16
))).
toByteArray
()
override
val
bootId
:
ByteArray
=
ExternalImage
.
generateUUID
(
md5
(
getRandomByteArray
(
16
))).
toByteArray
()
override
val
procVersion
:
ByteArray
get
()
=
"Linux version 3.0.31-g6fb96c9
(android-build@xxx.xxx.xxx.xxx.com)"
.
toByteArray
()
override
val
procVersion
:
ByteArray
=
"Linux version 3.0.31-${getRandomString(8)}
(android-build@xxx.xxx.xxx.xxx.com)"
.
toByteArray
()
override
val
baseBand
:
ByteArray
get
()
=
byteArrayOf
()
override
val
baseBand
:
ByteArray
=
byteArrayOf
()
override
val
version
:
DeviceInfo
.
Version
get
()
=
Version
override
val
version
:
DeviceInfo
.
Version
get
()
=
Version
override
val
simInfo
:
ByteArray
get
()
=
"T-Mobile"
.
toByteArray
()
override
val
simInfo
:
ByteArray
=
"T-Mobile"
.
toByteArray
()
override
val
osType
:
ByteArray
get
()
=
"android"
.
toByteArray
()
override
val
osType
:
ByteArray
=
"android"
.
toByteArray
()
override
val
macAddress
:
ByteArray
get
()
=
"02:00:00:00:00:00"
.
toByteArray
()
override
val
macAddress
:
ByteArray
=
"02:00:00:00:00:00"
.
toByteArray
()
override
val
wifiBSSID
:
ByteArray
?
get
()
=
"02:00:00:00:00:00"
.
toByteArray
()
override
val
wifiBSSID
:
ByteArray
?
=
"02:00:00:00:00:00"
.
toByteArray
()
override
val
wifiSSID
:
ByteArray
?
get
()
=
"<unknown ssid>"
.
toByteArray
()
override
val
wifiSSID
:
ByteArray
?
=
"<unknown ssid>"
.
toByteArray
()
override
val
imsiMd5
:
ByteArray
get
()
=
md5
(
getRandomByteArray
(
16
))
override
val
imsiMd5
:
ByteArray
=
md5
(
getRandomByteArray
(
16
))
override
val
imei
:
String
get
()
=
getRandomString
(
15
,
'0'
..
'9'
)
override
val
imei
:
String
=
getRandomString
(
15
,
'0'
..
'9'
)
override
val
ipAddress
:
ByteArray
get
()
=
localIpAddress
().
split
(
"."
).
map
{
it
.
toUByte
().
toByte
()
}.
takeIf
{
it
.
size
==
4
}
?.
toByteArray
()
?:
byteArrayOf
()
override
val
ipAddress
:
ByteArray
get
()
=
localIpAddress
().
split
(
"."
).
map
{
it
.
toUByte
().
toByte
()
}.
takeIf
{
it
.
size
==
4
}
?.
toByteArray
()
?:
byteArrayOf
()
override
val
androidId
:
ByteArray
get
()
=
display
override
val
androidId
:
ByteArray
get
()
=
display
override
val
apn
:
ByteArray
get
()
=
"wifi"
.
toByteArray
()
override
val
apn
:
ByteArray
=
"wifi"
.
toByteArray
()
@Serializable
object
Version
:
DeviceInfo
.
Version
{
object
Version
:
DeviceInfo
.
Version
{
override
val
incremental
:
ByteArray
get
()
=
"5891938"
.
toByteArray
()
override
val
incremental
:
ByteArray
=
"5891938"
.
toByteArray
()
override
val
release
:
ByteArray
get
()
=
"10"
.
toByteArray
()
override
val
release
:
ByteArray
=
"10"
.
toByteArray
()
override
val
codename
:
ByteArray
get
()
=
"REL"
.
toByteArray
()
override
val
codename
:
ByteArray
=
"REL"
.
toByteArray
()
override
val
sdk
:
Int
get
()
=
29
override
val
sdk
:
Int
=
29
}
}
}
@Serializable
class
DeviceInfoData
(
override
val
display
:
ByteArray
,
override
val
product
:
ByteArray
,
override
val
device
:
ByteArray
,
override
val
board
:
ByteArray
,
override
val
brand
:
ByteArray
,
override
val
model
:
ByteArray
,
override
val
bootloader
:
ByteArray
,
override
val
fingerprint
:
ByteArray
,
override
val
bootId
:
ByteArray
,
override
val
procVersion
:
ByteArray
,
override
val
baseBand
:
ByteArray
,
override
val
version
:
Version
,
override
val
simInfo
:
ByteArray
,
override
val
osType
:
ByteArray
,
override
val
macAddress
:
ByteArray
,
override
val
wifiBSSID
:
ByteArray
?,
override
val
wifiSSID
:
ByteArray
?,
override
val
imsiMd5
:
ByteArray
,
override
val
imei
:
String
,
override
val
ipAddress
:
ByteArray
,
override
val
androidId
:
ByteArray
,
override
val
apn
:
ByteArray
)
:
DeviceInfo
()
{
@Transient
override
lateinit
var
context
:
Context
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment