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
cf052614
Commit
cf052614
authored
Oct 19, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Klock
parent
244996ac
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
51 additions
and
50 deletions
+51
-50
build.gradle
build.gradle
+1
-0
dependencies.gradle
dependencies.gradle
+1
-0
mirai-core/build.gradle
mirai-core/build.gradle
+2
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt
...i-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt
+0
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
....mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
+4
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMProtocol.kt
...otlin/net.mamoe.mirai/network/protocol/tim/TIMProtocol.kt
+4
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/PasswordSubmission.kt
...i/network/protocol/tim/packet/login/PasswordSubmission.kt
+9
-8
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/ServerLoginResponse.kt
.../network/protocol/tim/packet/login/ServerLoginResponse.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotNetworkConfiguration.kt
...n/kotlin/net.mamoe.mirai/utils/BotNetworkConfiguration.kt
+5
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
+3
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/TypeConvertion.kt
...commonMain/kotlin/net.mamoe.mirai/utils/TypeConvertion.kt
+9
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
+0
-2
mirai-debug/build.gradle
mirai-debug/build.gradle
+3
-3
mirai-debug/src/main/java/PacketDebuger.kt
mirai-debug/src/main/java/PacketDebuger.kt
+6
-23
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
+0
-1
settings.gradle
settings.gradle
+3
-1
No files found.
build.gradle
View file @
cf052614
...
...
@@ -19,6 +19,7 @@ allprojects {
version
=
"1.0"
repositories
{
jcenter
()
//klock
google
()
maven
{
url
"https://mirrors.huaweicloud.com/repository/maven/"
}
}
...
...
dependencies.gradle
View file @
cf052614
...
...
@@ -30,4 +30,5 @@ ext {
kotlinxIOJS
=
"org.jetbrains.kotlinx:kotlinx-io-js:$kotlinx_io_version"
kotlinxIONative
=
"org.jetbrains.kotlinx:kotlinx-io-native:$kotlinx_io_version"
klock
=
"com.soywiz.korlibs.klock:klock:1.7.0"
}
mirai-core/build.gradle
View file @
cf052614
...
...
@@ -35,6 +35,7 @@ kotlin {
implementation
rootProject
.
ext
.
atomicFUCommon
implementation
rootProject
.
ext
.
kotlinxIOCommon
implementation
rootProject
.
ext
.
klock
}
}
...
...
@@ -51,6 +52,7 @@ kotlin {
implementation
'org.yaml:snakeyaml:1.18'
implementation
'org.jsoup:jsoup:1.12.1'
implementation
'org.ini4j:ini4j:0.5.2'
implementation
rootProject
.
ext
.
klock
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt
View file @
cf052614
...
...
@@ -14,8 +14,6 @@ import net.mamoe.mirai.utils.toUHexString
/**
* The mirror of functions in inner classes of [Bot]
*
* @author Him188moe
*/
//Contacts
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
View file @
cf052614
...
...
@@ -147,7 +147,7 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
val
expect
=
expectPacket
<
ServerTouchResponsePacket
>()
NetworkScope
.
launch
{
processReceive
()
}
NetworkScope
.
launch
{
if
(
withTimeoutOrNull
(
configuration
.
touchTimeout
Millis
)
{
expect
.
join
()
}
==
null
)
{
if
(
withTimeoutOrNull
(
configuration
.
touchTimeout
.
millisecondsLong
)
{
expect
.
join
()
}
==
null
)
{
loginResult
.
complete
(
LoginResult
.
TIMEOUT
)
}
}
...
...
@@ -342,7 +342,7 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
this
.
token00BA
=
packet
.
token00BA
this
.
captchaCache
=
packet
.
captchaPart1
if
(
packet
.
unknownBoolean
==
true
)
{
if
(
packet
.
unknownBoolean
)
{
this
.
captchaSectionId
=
1
socket
.
sendPacket
(
ClientCaptchaTransmissionRequestPacket
(
bot
.
qqAccount
,
this
.
token0825
,
this
.
captchaSectionId
++,
packet
.
token00BA
))
}
...
...
@@ -403,11 +403,11 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
heartbeatJob
=
NetworkScope
.
launch
{
while
(
socket
.
isOpen
)
{
delay
(
configuration
.
heartbeatPeriod
Millis
)
delay
(
configuration
.
heartbeatPeriod
.
millisecondsLong
)
with
(
session
)
{
class
HeartbeatTimeoutException
:
CancellationException
(
"heartbeat timeout"
)
if
(
withTimeoutOrNull
(
configuration
.
heartbeatTimeout
Millis
)
{
if
(
withTimeoutOrNull
(
configuration
.
heartbeatTimeout
.
millisecondsLong
)
{
ClientHeartbeatPacket
(
bot
.
qqAccount
,
sessionKey
).
sendAndExpect
<
ServerHeartbeatResponsePacket
>
{}
}
==
null
)
{
bot
.
logPurple
(
"Heartbeat timed out"
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMProtocol.kt
View file @
cf052614
...
...
@@ -20,7 +20,7 @@ object TIMProtocol {
).
forEach
{
list
.
add
(
solveIpAddress
(
it
))
}
list
.
toList
()
}()
}()
//不使用lazy是为了在启动时就加载.
const
val
head
=
"02"
const
val
ver
=
"37 13"
...
...
@@ -36,6 +36,9 @@ object TIMProtocol {
const
val
constantData1
=
"00 18 00 16 00 01 "
const
val
constantData2
=
"00 00 04 53 00 00 00 01 00 00 15 85 "
//todo 使用 byte array
/**
* Touch 发出时写入, 并用于加密, 接受 sendTouch response 时解密.
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/PasswordSubmission.kt
View file @
cf052614
...
...
@@ -22,22 +22,23 @@ class ClientPasswordSubmissionPacket constructor(
private
val
loginIP
:
String
,
private
val
privateKey
:
ByteArray
,
private
val
token0825
:
ByteArray
,
private
val
token00BA
:
ByteArray
?
=
null
,
//
private
val
token00BA
:
ByteArray
?
=
null
,
private
val
randomDeviceName
:
Boolean
=
false
,
private
val
tlv0006
:
IoBuffer
?
=
null
)
:
ClientPacket
()
{
override
fun
encode
(
builder
:
BytePacketBuilder
)
=
with
(
builder
)
{
this
.
writeQQ
(
bot
)
this
.
writeHex
(
TIMProtocol
.
passwordSubmissionTLV1
)
writeQQ
(
bot
)
writeHex
(
TIMProtocol
.
passwordSubmissionTLV1
)
this
.
writeShort
(
25
)
this
.
writeHex
(
TIMProtocol
.
publicKey
)
//
25
writeShort
(
25
)
writeHex
(
TIMProtocol
.
publicKey
)
//=
25
this
.
writeHex
(
"00 00 00 10"
)
//=16
this
.
writeHex
(
TIMProtocol
.
key0836
)
//16
writeZero
(
2
)
writeShort
(
16
)
writeHex
(
TIMProtocol
.
key0836
)
//=16
//TODO shareKey 极大可能为 publicKey, key0836 计算得到
this
.
encryptAndWrite
(
TIMProtocol
.
shareKey
.
hexToBytes
()
)
{
encryptAndWrite
(
TIMProtocol
.
shareKey
)
{
writePart1
(
bot
,
password
,
loginTime
,
loginIP
,
privateKey
,
token0825
,
randomDeviceName
,
tlv0006
)
if
(
token00BA
!=
null
)
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/ServerLoginResponse.kt
View file @
cf052614
...
...
@@ -127,7 +127,7 @@ class ServerLoginResponseCaptchaInitPacket(input: ByteReadPacket) : ServerLoginR
lateinit
var
captchaPart1
:
IoBuffer
lateinit
var
token00BA
:
ByteArray
var
unknownBoolean
:
Boolean
?
=
null
var
unknownBoolean
:
Boolean
by
Delegates
.
notNull
()
@Tested
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotNetworkConfiguration.kt
View file @
cf052614
package
net.mamoe.mirai.utils
import
com.soywiz.klock.TimeSpan
import
com.soywiz.klock.seconds
import
net.mamoe.mirai.network.protocol.tim.packet.login.ServerTouchResponsePacket
/**
...
...
@@ -9,7 +11,7 @@ class BotNetworkConfiguration {
/**
* 等待 [ServerTouchResponsePacket] 的时间
*/
var
touchTimeout
Millis
:
Long
=
2000
var
touchTimeout
:
TimeSpan
=
2
.
seconds
/**
* 是否使用随机的设备名.
...
...
@@ -21,13 +23,13 @@ class BotNetworkConfiguration {
/**
* 心跳周期. 过长会导致被服务器断开连接.
*/
var
heartbeatPeriod
Millis
:
Long
=
1
*
60
*
1000
var
heartbeatPeriod
:
TimeSpan
=
60
.
seconds
/**
* 每次心跳时等待结果的时间.
* 一旦心跳超时, 整个网络服务将会重启 (将消耗约 1s). 除正在进行的任务 (如图片上传) 会被中断外, 事件和插件均不受影响.
*/
var
heartbeatTimeout
Millis
:
Long
=
2000
var
heartbeatTimeout
:
TimeSpan
=
2
.
seconds
companion
object
{
val
Default
=
BotNetworkConfiguration
()
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/PlatformUtils.kt
View file @
cf052614
package
net.mamoe.mirai.utils
import
com.soywiz.klock.DateTime
/**
* 时间戳
*/
expect
val
currentTime
:
Long
val
currentTime
:
Long
=
DateTime
.
nowUnixLong
()
/**
* 设备名
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/TypeConvertion.kt
View file @
cf052614
...
...
@@ -41,13 +41,22 @@ fun UInt.toByteArray(): ByteArray = byteArrayOf(
fun
Int
.
toUHexString
(
separator
:
String
=
" "
):
String
=
this
.
toByteArray
().
toUHexString
(
separator
)
fun
Byte
.
toUHexString
():
String
=
this
.
toUByte
().
toString
(
16
).
toUpperCase
()
fun
String
.
hexToBytes
():
ByteArray
=
HexCache
.
hexToBytes
(
this
)
/**
* 将 Hex 转为 UByteArray, 有根据 hex 的 [hashCode] 建立的缓存.
*/
fun
String
.
hexToUBytes
():
UByteArray
=
HexCache
.
hexToUBytes
(
this
)
fun
String
.
hexToInt
():
Int
=
hexToBytes
().
toUInt
().
toInt
()
fun
getRandomByteArray
(
length
:
Int
):
ByteArray
=
ByteArray
(
length
)
{
Random
.
nextInt
(
0
..
255
).
toByte
()
}
fun
ByteArray
.
toUInt
():
UInt
=
this
[
0
].
toUInt
().
and
(
255
u
).
shl
(
24
)
+
this
[
1
].
toUInt
().
and
(
255
u
).
shl
(
16
)
+
this
[
2
].
toUInt
().
and
(
255
u
).
shl
(
8
)
+
this
[
3
].
toUInt
().
and
(
255
u
).
shl
(
0
)
fun
ByteArray
.
toIoBuffer
():
IoBuffer
=
IoBuffer
.
Pool
.
borrow
().
let
{
it
.
writeFully
(
this
);
it
}
/**
* Hex 转换 [ByteArray] 和 [UByteArray] 缓存.
* 为 [net.mamoe.mirai.network.protocol.tim.TIMProtocol] 的 hex 常量使用
*/
internal
object
HexCache
{
private
val
hexToByteArrayCacheMap
:
MutableMap
<
Int
,
ByteArray
>
=
mutableMapOf
()
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
View file @
cf052614
...
...
@@ -8,8 +8,6 @@ import java.net.InetAddress
import
java.security.MessageDigest
import
java.util.zip.CRC32
actual
val
currentTime
:
Long
=
System
.
currentTimeMillis
()
actual
val
deviceName
:
String
=
InetAddress
.
getLocalHost
().
hostName
...
...
mirai-debug/build.gradle
View file @
cf052614
...
...
@@ -5,9 +5,9 @@ dependencies {
implementation
project
(
':mirai-core'
)
compile
files
(
'./lib/jpcap.jar'
)
compile
rootProject
.
ext
.
coroutineCommon
compile
rootProject
.
ext
.
kotlinJvm
compile
rootProject
.
ext
.
kotlinxIOJvm
implementation
rootProject
.
ext
.
coroutineCommon
implementation
rootProject
.
ext
.
kotlinJvm
implementation
rootProject
.
ext
.
kotlinxIOJvm
}
tasks
.
withType
(
JavaCompile
)
{
...
...
mirai-debug/src/main/java/PacketDebuger.kt
View file @
cf052614
...
...
@@ -23,32 +23,11 @@ object Main {
@JvmStatic
fun
main
(
args
:
Array
<
String
>)
{
/*-------------- 第一步绑定网络设备 --------------*/
val
devices
=
JpcapCaptor
.
getDeviceList
()
/*
\Device\NPF_{0E7103E4-BF96-4B66-A23B-F6F630D814CD} | Microsoft
\Device\NPF_{2CCA31E2-93D5-42F2-92C1-5882E18A8E95} | VMware Virtual Ethernet Adapter
\Device\NPF_{A12C8971-858B-4BC8-816C-4077E1636AC5} | VMware Virtual Ethernet Adapter
\Device\NPF_{231C4E27-AF20-4362-BCA3-107236CB8A2E} | MS NDIS 6.0 LoopBack Driver
\Device\NPF_{500B5537-AA10-4E2F-8F7D-E6BD365BDCD1} | Microsoft
\Device\NPF_{A177317B-903A-45B5-8AEA-3698E423ABD6} | Microsoft
*/
/*
for (n in devices) {
println(n.name + " | " + n.description)
}
println("-------------------------------------------")
exitProcess(0)*/
val
jpcap
:
JpcapCaptor
?
val
caplen
=
4096
val
promiscCheck
=
true
jpcap
=
JpcapCaptor
.
openDevice
(
devices
[
0
],
caplen
,
promiscCheck
,
50
)
/*----------第二步抓包-----------------*/
while
(
true
)
{
assert
(
jpcap
!=
null
)
val
pk
=
jpcap
!!
.
packet
...
...
@@ -60,7 +39,11 @@ object Main {
}
if
(
localIp
in
pk
.
dst_ip
.
hostAddress
)
{
//接受
dataReceived
(
pk
.
data
)
try
{
dataReceived
(
pk
.
data
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
else
{
try
{
dataSent
(
pk
.
data
)
...
...
@@ -88,7 +71,7 @@ object Main {
* 6. 运行到 `mov eax,dword ptr ss:[ebp+10]`
* 7. 查看内存, 从 `eax` 开始的 16 bytes 便是 `sessionKey`
*/
val
sessionKey
:
ByteArray
=
"
F1 68 24 ED A8 6D 33 6E 5C B7 E0 F4 45 77 21 04
"
.
hexToBytes
()
val
sessionKey
:
ByteArray
=
"
99 91 B9 8B 79 45 FD CF 51 4A B9 DE 14 61 ED E3
"
.
hexToBytes
()
fun
dataReceived
(
data
:
ByteArray
)
{
println
(
"--------------"
)
...
...
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
View file @
cf052614
...
...
@@ -24,7 +24,6 @@ suspend fun main() {
),
Console
())
bot
.
login
{
touchTimeoutMillis
=
2000
randomDeviceName
=
true
}.
let
{
if
(
it
!=
LoginResult
.
SUCCESS
)
{
...
...
settings.gradle
View file @
cf052614
...
...
@@ -5,4 +5,6 @@ include(':mirai-api')
include
(
':mirai-demos:mirai-demo-1'
)
include
(
':mirai-demos'
)
include
(
':mirai-debug'
)
project
(
':mirai-demos:mirai-demo-1'
).
projectDir
=
file
(
'mirai-demos/mirai-demo-1'
)
\ No newline at end of file
project
(
':mirai-demos:mirai-demo-1'
).
projectDir
=
file
(
'mirai-demos/mirai-demo-1'
)
enableFeaturePreview
(
'GRADLE_METADATA'
)
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