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
ffe8339c
Commit
ffe8339c
authored
Oct 24, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure that ResponsePacket will be sent
parent
d5bf51a3
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
34 additions
and
33 deletions
+34
-33
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt
...core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt
+1
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
....mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
+4
-5
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/ActionPacketHandler.kt
...mirai/network/protocol/tim/handler/ActionPacketHandler.kt
+3
-9
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/PacketHandler.kt
...mamoe.mirai/network/protocol/tim/handler/PacketHandler.kt
+1
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/TemporaryPacketHandler.kt
...ai/network/protocol/tim/handler/TemporaryPacketHandler.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/OutgoingPacket.kt
...mamoe.mirai/network/protocol/tim/packet/OutgoingPacket.kt
+3
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MessageEventPackets.kt
.../network/protocol/tim/packet/event/MessageEventPackets.kt
+3
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/SKey.kt
...net.mamoe.mirai/network/protocol/tim/packet/login/SKey.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/Touch.kt
...et.mamoe.mirai/network/protocol/tim/packet/login/Touch.kt
+5
-5
mirai-debug/src/main/java/DecryptTest.kt
mirai-debug/src/main/java/DecryptTest.kt
+4
-2
mirai-debug/src/main/java/PacketDebuger.kt
mirai-debug/src/main/java/PacketDebuger.kt
+8
-5
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt
View file @
ffe8339c
...
...
@@ -4,7 +4,6 @@ package net.mamoe.mirai.event
import
kotlinx.coroutines.CoroutineExceptionHandler
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.newCoroutineContext
import
kotlinx.coroutines.withContext
import
net.mamoe.mirai.contact.Contact
import
net.mamoe.mirai.event.internal.broadcastInternal
...
...
@@ -59,7 +58,7 @@ interface Cancellable {
@Suppress
(
"UNCHECKED_CAST"
)
@JvmOverloads
suspend
fun
<
E
:
Event
>
E
.
broadcast
(
context
:
CoroutineContext
=
EmptyCoroutineContext
):
E
{
return
withContext
(
EventScope
.
newCoroutineContext
(
context
)
)
{
this
@
broadcast
.
broadcastInternal
()
}
return
withContext
(
EventScope
.
coroutineContext
+
context
)
{
this
@
broadcast
.
broadcastInternal
()
}
}
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
View file @
ffe8339c
...
...
@@ -164,7 +164,7 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
loginResult
.
complete
(
LoginResult
.
TIMEOUT
)
}
}
sendPacket
(
Outgoing
TouchPacket
(
bot
.
qqAccount
,
this
.
serverIp
))
sendPacket
(
TouchPacket
(
bot
.
qqAccount
,
this
.
serverIp
))
return
loginResult
.
await
()
}
...
...
@@ -206,16 +206,15 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
}
if
(
packet
is
ServerEventPacket
)
{
//no need to sync acknowledgement packets
launch
{
//must ensure the response packet is sent
sendPacket
(
packet
.
ResponsePacket
(
bot
.
qqAccount
,
sessionKey
))
}
}
if
(
ServerPacketReceivedEvent
(
bot
,
packet
).
broadcast
().
cancelled
)
{
return
@
coroutineScope
}
//they should be called in sequence otherwise because packet is lock-free
loginHandler
.
onPacketReceived
(
packet
)
this
@TIMBotNetworkHandler
.
forEach
{
it
.
instance
.
onPacketReceived
(
packet
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/ActionPacketHandler.kt
View file @
ffe8339c
...
...
@@ -15,7 +15,6 @@ import net.mamoe.mirai.network.protocol.tim.packet.event.ServerEventPacket
import
net.mamoe.mirai.network.protocol.tim.packet.login.RequestSKeyPacket
import
net.mamoe.mirai.network.qqAccount
import
net.mamoe.mirai.utils.log
import
kotlin.coroutines.CoroutineContext
/**
* 动作: 获取好友列表, 点赞, 踢人等.
...
...
@@ -24,9 +23,6 @@ import kotlin.coroutines.CoroutineContext
* @author Him188moe
*/
class
ActionPacketHandler
(
session
:
BotSession
)
:
PacketHandler
(
session
)
{
override
val
coroutineContext
:
CoroutineContext
get
()
=
session
.
NetworkScope
.
coroutineContext
companion
object
Key
:
PacketHandler
.
Key
<
ActionPacketHandler
>
...
...
@@ -71,14 +67,14 @@ class ActionPacketHandler(session: BotSession) : PacketHandler(session) {
}
private
suspend
fun
requestSKey
()
=
with
(
session
)
{
withContext
(
coroutineContext
)
{
withContext
(
NetworkScope
.
coroutineContext
)
{
socket
.
sendPacket
(
RequestSKeyPacket
())
}
}
suspend
fun
requestAccountInfo
()
=
with
(
session
)
{
withContext
(
coroutineContext
)
{
withContext
(
NetworkScope
.
coroutineContext
)
{
socket
.
sendPacket
(
RequestAccountInfoPacket
(
qqAccount
,
sessionKey
))
}
}
...
...
@@ -89,5 +85,3 @@ class ActionPacketHandler(session: BotSession) : PacketHandler(session) {
}
}
\ No newline at end of file
private
val
UninitializedPacketId
:
UShort
=
0
u
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/PacketHandler.kt
View file @
ffe8339c
package
net.mamoe.mirai.network.protocol.tim.handler
import
kotlinx.coroutines.CoroutineScope
import
net.mamoe.mirai.network.BotSession
import
net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
import
kotlin.reflect.KClass
...
...
@@ -10,7 +9,7 @@ import kotlin.reflect.KClass
*/
abstract
class
PacketHandler
(
val
session
:
BotSession
)
:
CoroutineScope
{
)
{
abstract
suspend
fun
onPacketReceived
(
packet
:
ServerPacket
)
interface
Key
<
T
:
PacketHandler
>
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/handler/TemporaryPacketHandler.kt
View file @
ffe8339c
...
...
@@ -10,7 +10,7 @@ import kotlin.reflect.KClass
* 临时数据包处理器
* ```kotlin
* session.addHandler<ClientTouchResponsePacket>{
* toSend {
Outgoing
TouchPacket() }
* toSend { TouchPacket() }
* onExpect {//it: ClientTouchResponsePacket
* //do sth.
* }
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/OutgoingPacket.kt
View file @
ffe8339c
...
...
@@ -6,6 +6,7 @@ import kotlinx.atomicfu.atomic
import
kotlinx.io.core.*
import
net.mamoe.mirai.network.protocol.tim.TIMProtocol
import
net.mamoe.mirai.utils.io.writeHex
import
kotlin.jvm.JvmStatic
/**
* 发给服务器的数据包. 必须有 [PacketId] 注解或 `override` [id]. 否则将会抛出 [IllegalStateException]
...
...
@@ -23,6 +24,7 @@ abstract class OutgoingPacket : Packet(), Closeable {
}
companion
object
{
@JvmStatic
private
val
sequenceIdInternal
=
atomic
(
1
)
internal
fun
atomicNextSequenceId
()
=
sequenceIdInternal
.
getAndIncrement
().
toUShort
()
}
...
...
@@ -58,6 +60,7 @@ abstract class OutgoingPacket : Packet(), Closeable {
}
}
@Suppress
(
"unused"
)
@MustBeDocumented
@Target
(
AnnotationTarget
.
FUNCTION
,
AnnotationTarget
.
CLASS
)
@Retention
(
AnnotationRetention
.
SOURCE
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/event/MessageEventPackets.kt
View file @
ffe8339c
...
...
@@ -50,8 +50,10 @@ class ServerGroupMessageEventPacket(input: ByteReadPacket, eventIdentity: EventP
//管理员 子map= {5=00 00 00 03, 8=00 00 00 04, 2=65 6F 6D 38 38 31 6D 69 48, 3=02, 4=00 00 00 10}
//群成员 子map= {5=00 00 00 03, 8=00 00 00 04, 2=65 6F 6D 38 38 31 6D 69 48, 3=02}
tlv
.
printTLVMap
(
"Child TLV map"
)
senderPermission
=
when
(
val
value0x03
=
tlv
.
getValue
(
0
x03
)[
0
].
toUInt
())
{
0
x04u
->
SenderPermission
.
OWNER
0
x03u
->
SenderPermission
.
MEMBER
0
x02u
->
{
if
(!
tlv
.
containsKey
(
0
x04
))
{
SenderPermission
.
MEMBER
...
...
@@ -64,8 +66,8 @@ class ServerGroupMessageEventPacket(input: ByteReadPacket, eventIdentity: EventP
0
x01u
->
SenderPermission
.
MEMBER
else
->
{
tlv
.
printTLVMap
(
"Child TLV map"
)
error
(
"Could not determine member permission, unknown TLV(key=0x03,value=$value0x03;)"
)
//{5=00 00 00 01, 8=00 00 00 01, 1=48 69 6D 31 38 38 6D 6F 65, 3=03}
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/SKey.kt
View file @
ffe8339c
...
...
@@ -41,7 +41,7 @@ class RequestSKeyPacket(
//debugDiscardExact(2)
sKey
=
this
.
readString
(
10
)
//16??
DebugLogger
.
logPurple
(
"SKey=$sKey"
)
DebugLogger
.
logPurple
(
"S
key
包后面${this.readRemainingBytes().toUHexString()}"
)
DebugLogger
.
logPurple
(
"S
Key
包后面${this.readRemainingBytes().toUHexString()}"
)
}
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/login/Touch.kt
View file @
ffe8339c
...
...
@@ -15,7 +15,7 @@ import net.mamoe.mirai.utils.toUHexString
/**
* The packet received when logging in, used to redirect server address
*
* @see
OutgoingTouch
RedirectionPacket
* @see RedirectionPacket
* @see SubmitPasswordPacket
*
* @author Him188moe
...
...
@@ -62,7 +62,7 @@ class TouchResponsePacket(input: ByteReadPacket) : ServerPacket(input) {
* @author Him188moe
*/
@PacketId
(
0
x08_25u
)
class
Outgoing
TouchPacket
(
private
val
bot
:
UInt
,
private
val
serverIp
:
String
)
:
OutgoingPacket
()
{
class
TouchPacket
(
private
val
bot
:
UInt
,
private
val
serverIp
:
String
)
:
OutgoingPacket
()
{
override
fun
encode
(
builder
:
BytePacketBuilder
)
=
with
(
builder
)
{
this
.
writeQQ
(
bot
)
this
.
writeHex
(
TIMProtocol
.
fixVer
)
...
...
@@ -86,16 +86,16 @@ class OutgoingTouchPacket(private val bot: UInt, private val serverIp: String) :
* @author Him188moe
*/
@PacketId
(
0
x08_25u
)
class
OutgoingTouchRedirectionPacket
(
private
val
serverIP
:
String
,
private
val
qq
:
UInt
)
:
OutgoingPacket
()
{
class
RedirectionPacket
(
private
val
bot
:
UInt
,
private
val
serverIP
:
String
)
:
OutgoingPacket
()
{
override
fun
encode
(
builder
:
BytePacketBuilder
)
=
with
(
builder
)
{
this
.
writeQQ
(
qq
)
this
.
writeQQ
(
bot
)
this
.
writeHex
(
TIMProtocol
.
fixVer
)
this
.
writeHex
(
TIMProtocol
.
touchKey
)
//redirection key
this
.
encryptAndWrite
(
TIMProtocol
.
touchKey
)
{
this
.
writeHex
(
TIMProtocol
.
constantData1
)
this
.
writeHex
(
TIMProtocol
.
constantData2
)
this
.
writeQQ
(
qq
)
this
.
writeQQ
(
bot
)
this
.
writeHex
(
"00 01 00 00 03 09 00 0C 00 01"
)
this
.
writeIP
(
serverIP
)
this
.
writeHex
(
"01 6F A1 58 22 01 00 36 00 12 00 02 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 14 00 1D 01 03 00 19"
)
...
...
mirai-debug/src/main/java/DecryptTest.kt
View file @
ffe8339c
@
file
:
Suppress
(
"UNUSED_VARIABLE"
)
import
net.mamoe.mirai.utils.hexToBytes
import
net.mamoe.mirai.utils.io.stringOfWitch
import
net.mamoe.mirai.utils.io.toUHexString
...
...
mirai-debug/src/main/java/PacketDebuger.kt
View file @
ffe8339c
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
,
"MemberVisibilityCanBePrivate"
,
"EXPERIMENTAL_UNSIGNED_LITERALS"
)
import
Main.localIp
import
Main.qq
import
Main.sessionKey
import
jpcap.JpcapCaptor
import
jpcap.packet.IPPacket
import
jpcap.packet.UDPPacket
...
...
@@ -19,13 +22,12 @@ import net.mamoe.mirai.utils.io.*
import
net.mamoe.mirai.utils.toUHexString
/**
* 抓包分析器
* 抓包分析器.
* 设置好 [sessionKey], [localIp] 和 [qq] 后运行即可开始抓包和自动解密
*
* @author Him188moe
*/
object
Main
{
const
val
localIp
=
"192.168.3."
@JvmStatic
fun
main
(
args
:
Array
<
String
>)
{
val
devices
=
JpcapCaptor
.
getDeviceList
()
...
...
@@ -77,8 +79,9 @@ object Main {
* 6. 运行到 `mov eax,dword ptr ss:[ebp+10]`
* 7. 查看内存, 从 `eax` 开始的 16 bytes 便是 `sessionKey`
*/
val
sessionKey
:
ByteArray
=
"B7 E2 A6 3D 90 4F 4F 74 7D 55 9C 0E 91 20 40 A5"
.
hexToBytes
()
val
qq
:
UInt
=
1040400290
u
val
sessionKey
:
ByteArray
=
"1D 1E 71 68 B9 41 FD 5B F3 5A 3F 71 87 B5 86 CB"
.
hexToBytes
()
const
val
qq
:
UInt
=
1040400290
u
const
val
localIp
=
"192.168.3."
fun
dataReceived
(
data
:
ByteArray
)
{
//println("raw = " + data.toUHexString())
...
...
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