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
4d346a2c
Commit
4d346a2c
authored
Oct 19, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix SendFriendMessage due to TIM update
parent
05e590c9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
17 deletions
+65
-17
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageType.kt
.../commonMain/kotlin/net.mamoe.mirai/message/MessageType.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMProtocol.kt
...otlin/net.mamoe.mirai/network/protocol/tim/TIMProtocol.kt
+2
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/ClientSendFriendMessagePacket.kt
...otocol/tim/packet/action/ClientSendFriendMessagePacket.kt
+40
-8
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/HexComparator.kt
...src/jvmMain/kotlin/net/mamoe/mirai/utils/HexComparator.kt
+0
-2
mirai-debug/src/main/java/PacketDebuger.kt
mirai-debug/src/main/java/PacketDebuger.kt
+4
-2
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
+18
-3
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageType.kt
View file @
4d346a2c
...
...
@@ -5,7 +5,7 @@ package net.mamoe.mirai.message
@Suppress
(
"unused"
)
enum
class
MessageType
(
val
value
:
UByte
)
{
PLAIN_TEXT
(
0
x0
3
u
),
PLAIN_TEXT
(
0
x0
1
u
),
AT
(
0
x06u
),
FACE
(
0
x02u
),
IMAGE
(
0
x03u
),
//may be 0x06?
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMProtocol.kt
View file @
4d346a2c
...
...
@@ -31,7 +31,7 @@ object TIMProtocol {
*/
const
val
fixVer2
=
"02 00 00 00 01 01 01 00 00 68 20"
// 02 38 03 00 CD 48 68 3E 03 3F A2 02 00 00 00
// 02 00 00 00 01 2E 01 00 00 69 35
const
val
versionNewest
=
"02 00 00 00 01 2E 01 00 00 69 35"
const
val
constantData1
=
"00 18 00 16 00 01 "
const
val
constantData2
=
"00 00 04 53 00 00 00 01 00 00 15 85 "
...
...
@@ -92,5 +92,6 @@ object TIMProtocol {
* length=15
*/
const
val
messageConst1
=
"00 00 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91"
const
val
messageConstNewest
=
"22 00 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91"
// TIM最新 22 00 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91
}
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/action/ClientSendFriendMessagePacket.kt
View file @
4d346a2c
@
file
:
Suppress
(
"EXPERIMENTAL_UNSIGNED_LITERALS"
)
@
file
:
Suppress
(
"EXPERIMENTAL_UNSIGNED_LITERALS"
,
"EXPERIMENTAL_API_USAGE"
)
package
net.mamoe.mirai.network.protocol.tim.packet.action
import
kotlinx.io.core.*
import
net.mamoe.mirai.message.MessageChain
import
net.mamoe.mirai.message.internal.toPacket
import
net.mamoe.mirai.message.toChain
import
net.mamoe.mirai.message.toMessage
import
net.mamoe.mirai.network.protocol.tim.TIMProtocol
import
net.mamoe.mirai.network.protocol.tim.packet.ClientPacket
import
net.mamoe.mirai.network.protocol.tim.packet.PacketId
import
net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
import
net.mamoe.mirai.utils.*
fun
main
()
{
println
(
"牛逼"
.
toMessage
().
toChain
().
toPacket
().
readBytes
().
toUHexString
())
}
@PacketId
(
0
x00_CDu
)
class
ClientSendFriendMessagePacket
(
...
...
@@ -19,29 +24,55 @@ class ClientSendFriendMessagePacket(
private
val
sessionKey
:
ByteArray
,
private
val
message
:
MessageChain
)
:
ClientPacket
()
{
override
fun
encode
(
builder
:
BytePacketBuilder
)
=
with
(
builder
)
{
writeQQ
(
botQQ
)
writeHex
(
TIMProtocol
.
fixVer2
)
writeHex
(
TIMProtocol
.
versionNewest
)
encryptAndWrite
(
sessionKey
)
{
//TIM最新
//3E 03 3F A2
//76 E4 B8 DD
//00 00 00 08 00 01 00 04 00 00 00 00
//38 03
//3E 03 3F A2
//76 E4 B8 DD
//C6 FB 06 30 0C 69 0C AD C6 AD 14 BF 0B C6 38 EA
//00 0B
//3D 7F
//5D AA A8 E2
//01 1D
// 00 00 00 00
//01
// 00
// 00
//00 01 4D 53 47 00 00 00 00 00
//5D AA A8 E2
//E2 AE 94 2D
//00 00 00 00 0C 00 86
//22 00 0C E5 BE AE E8 BD AF E9 9B 85 E9 BB 91
//00 00
//
//01 00 09 01 00 06 E7 89 9B E9 80 BC
writeQQ
(
botQQ
)
writeQQ
(
targetQQ
)
writeHex
(
"00 00 00 08 00 01 00 04 00 00 00 00"
)
writeHex
(
"3
7 0F
"
)
//TIM最新: 38 03
writeHex
(
"3
8 03
"
)
//TIM最新: 38 03
writeQQ
(
botQQ
)
writeQQ
(
targetQQ
)
writeFully
(
md5
(
buildPacket
{
writeQQ
(
targetQQ
);
writeFully
(
sessionKey
)
}.
readBytes
()))
writeHex
(
"00 0B"
)
writeRandom
(
2
)
writeTime
()
writeHex
(
"0
0 00
"
+
"00 00 00 00"
)
writeHex
(
"0
1 1D
"
+
"
00 00 00 00"
)
//消息过多要分包发送
//如果只有一个
writeByte
(
0
x01
)
writeByte
(
0
)
//第几个包
write
Byte
(
0
)
write
UByte
(
0
x00u
)
//如果大于一个,
//writeByte(0x02)//数量
//writeByte(0)//第几个包
...
...
@@ -50,10 +81,11 @@ class ClientSendFriendMessagePacket(
writeHex
(
"00 01 4D 53 47 00 00 00 00 00"
)
writeTime
()
writeRandom
(
4
)
writeHex
(
"00 00 00 00 0
9
00 86"
)
//TIM最新 0C 00 86
writeHex
(
TIMProtocol
.
messageConst
1
)
//... 85 E9 BB 91
writeHex
(
"00 00 00 00 0
C
00 86"
)
//TIM最新 0C 00 86
writeHex
(
TIMProtocol
.
messageConst
Newest
)
//... 85 E9 BB 91
writeZero
(
2
)
message
.
toPacket
().
debugPrint
(
"CHAIN"
)
writePacket
(
message
.
toPacket
())
/*
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/HexComparator.kt
View file @
4d346a2c
...
...
@@ -43,8 +43,6 @@ internal object HexComparator {
val
群 = "群".
toByteArray
().
toUHexString
()
val
你好 = "你好".
toByteArray
().
toUHexString
()
val
SINGLE_PLAIN_MESSAGE_HEAD
=
"00 00 01 00 09 01"
val
MESSAGE_TAIL_10404
=
"0E 00 07 01 00 04 00 00 00 09 19 00 18 01 00 15 AA 02 12 9A 01 0F 80 01 01 C8 01 00 F0 01 00 F8 01 00 90 02 00"
.
replace
(
" "
,
" "
)
...
...
mirai-debug/src/main/java/PacketDebuger.kt
View file @
4d346a2c
...
...
@@ -5,6 +5,7 @@ import jpcap.packet.IPPacket
import
jpcap.packet.UDPPacket
import
kotlinx.io.core.discardExact
import
kotlinx.io.core.readBytes
import
kotlinx.io.core.readUInt
import
net.mamoe.mirai.message.internal.readMessageChain
import
net.mamoe.mirai.network.protocol.tim.TIMProtocol
import
net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
...
...
@@ -71,7 +72,7 @@ object Main {
* 6. 运行到 `mov eax,dword ptr ss:[ebp+10]`
* 7. 查看内存, 从 `eax` 开始的 16 bytes 便是 `sessionKey`
*/
val
sessionKey
:
ByteArray
=
"99
91 B9 8B 79 45 FD CF 51 4A B9 DE 14 61 ED E3
"
.
hexToBytes
()
val
sessionKey
:
ByteArray
=
"99
82 67 D4 62 20 CA 5D 81 F8 6F 83 EE 8A F7 68
"
.
hexToBytes
()
fun
dataReceived
(
data
:
ByteArray
)
{
println
(
"--------------"
)
...
...
@@ -121,7 +122,8 @@ object Main {
discardExact
(
3
)
//head
val
idHex
=
readBytes
(
4
).
toUHexString
()
println
(
"发出包ID = $idHex"
)
discardExact
(
TIMProtocol
.
fixVer2
.
hexToBytes
().
size
+
1
+
5
-
3
+
1
)
readUInt
()
//客户端登录的qq
println
(
"TIM的fixVer2="
+
readBytes
(
TIMProtocol
.
fixVer2
.
hexToBytes
().
size
).
toUHexString
())
val
encryptedBody
=
readRemainingBytes
()
println
(
"解密body = ${encryptedBody.decryptBy(sessionKey).toUHexString()}"
)
...
...
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
View file @
4d346a2c
...
...
@@ -13,15 +13,30 @@ import net.mamoe.mirai.message.Image
import
net.mamoe.mirai.message.PlainText
import
net.mamoe.mirai.network.protocol.tim.packet.login.LoginResult
import
net.mamoe.mirai.utils.BotAccount
import
net.mamoe.mirai.utils.Console
import
net.mamoe.mirai.utils.MiraiLogger
import
net.mamoe.mirai.utils.PlatformLogger
import
java.io.File
private
fun
readTestAccount
():
BotAccount
?
{
val
file
=
File
(
"testAccount.txt"
)
if
(!
file
.
exists
()
||
!
file
.
canRead
())
{
return
null
}
val
lines
=
file
.
readLines
()
return
try
{
BotAccount
(
lines
[
0
].
toLong
(),
lines
[
1
])
}
catch
(
e
:
IndexOutOfBoundsException
)
{
null
}
}
@Suppress
(
"UNUSED_VARIABLE"
)
suspend
fun
main
()
{
val
bot
=
Bot
(
BotAccount
(
//填写你的账号
val
bot
=
Bot
(
readTestAccount
()
?:
BotAccount
(
//填写你的账号
account
=
1994701121
,
password
=
"123456"
),
Console
())
),
PlatformLogger
())
bot
.
login
{
randomDeviceName
=
true
...
...
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