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
3e451344
Commit
3e451344
authored
Aug 17, 2019
by
Him188moe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
0b87253d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
30 deletions
+109
-30
mirai-core/src/main/java/net/mamoe/mirai/network/Protocol.kt
mirai-core/src/main/java/net/mamoe/mirai/network/Protocol.kt
+3
-0
mirai-core/src/main/java/net/mamoe/mirai/network/packet/PacketId.java
...rc/main/java/net/mamoe/mirai/network/packet/PacketId.java
+1
-1
mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/Client0836_622Packet.kt
...mamoe/mirai/network/packet/client/Client0836_622Packet.kt
+68
-19
mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/ClientPacket.kt
...ava/net/mamoe/mirai/network/packet/client/ClientPacket.kt
+37
-9
mirai-core/src/main/java/net/mamoe/mirai/network/packet/server/ServerPacket.kt
...ava/net/mamoe/mirai/network/packet/server/ServerPacket.kt
+0
-1
No files found.
mirai-core/src/main/java/net/mamoe/mirai/network/Protocol.kt
View file @
3e451344
...
@@ -44,6 +44,9 @@ interface Protocol {
...
@@ -44,6 +44,9 @@ interface Protocol {
const
val
encryptKey
=
"“BA 42 FF 01 CF B4 FF D2 12 F0 6E A7 1B 7C B3 08”"
const
val
encryptKey
=
"“BA 42 FF 01 CF B4 FF D2 12 F0 6E A7 1B 7C B3 08”"
const
val
_0836_622_fix2
=
"00 15 00 30 00 01 01 27 9B C7 F5 00 10 65 03 FD 8B 00 00 00 00 00 00 00 00 00 00 00 00 02 90 49 55 33 00 10 15 74 C4 89 85 7A 19 F5 5E A9 C9 A3 5E 8A 5A 9B"
;
const
val
_0836_622_fix1
=
"03 00 00 00 01 01 01 00 00 68 20 00 00 00 00 00 01 01 03 00 19"
;
const
val
_0836key1
=
"EF 4A 36 6A 16 A8 E6 3D 2E EA BD 1F 98 C1 3C DA"
@ExperimentalUnsignedTypes
@ExperimentalUnsignedTypes
fun
hexToBytes
(
hex
:
String
):
ByteArray
=
hexToUBytes
(
hex
).
toByteArray
()
fun
hexToBytes
(
hex
:
String
):
ByteArray
=
hexToUBytes
(
hex
).
toByteArray
()
...
...
mirai-core/src/main/java/net/mamoe/mirai/network/packet/PacketId.java
View file @
3e451344
...
@@ -14,5 +14,5 @@ public @interface PacketId {
...
@@ -14,5 +14,5 @@ public @interface PacketId {
/**
/**
* 获取用于识别的包 ID
* 获取用于识别的包 ID
*/
*/
int
value
();
String
value
();
}
}
mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/Client0836_622Packet.kt
View file @
3e451344
package
net.mamoe.mirai.network.packet.client
package
net.mamoe.mirai.network.packet.client
import
net.mamoe.mirai.network.Protocol
import
net.mamoe.mirai.network.Protocol
import
net.mamoe.mirai.network.packet.PacketId
import
net.mamoe.mirai.util.TEACryptor
import
net.mamoe.mirai.util.TEACryptor
import
net.mamoe.mirai.util.getCrc32
import
net.mamoe.mirai.util.getRandomKey
import
net.mamoe.mirai.util.hexToBytes
import
net.mamoe.mirai.util.hexToBytes
import
java.io.IOException
import
java.io.IOException
import
java.net.InetAddress
import
java.net.InetAddress
...
@@ -9,38 +12,84 @@ import java.net.InetAddress
...
@@ -9,38 +12,84 @@ import java.net.InetAddress
/**
/**
* @author Him188moe @ Mirai Project
* @author Him188moe @ Mirai Project
*/
*/
@PacketId
(
"08 36"
)
@ExperimentalUnsignedTypes
@ExperimentalUnsignedTypes
class
Client0836_622Packet
(
private
val
qq
:
Int
,
private
val
seq
:
String
,
private
val
token0825
:
ByteArray
)
:
ClientPacket
()
{
class
Client0836_622Packet
(
private
val
qq
:
Int
,
private
val
password
:
String
,
private
val
tgtgtKey
:
ByteArray
,
private
val
seq
:
String
,
private
val
token0825
:
ByteArray
)
:
ClientPacket
()
{
@ExperimentalUnsignedTypes
@ExperimentalUnsignedTypes
override
fun
encode
()
{
override
fun
encode
()
{
val
hostName
:
String
=
InetAddress
.
getLocalHost
().
hostName
.
let
{
it
.
substring
(
0
,
it
.
length
-
3
)
};
this
.
writeQQ
(
System
.
currentTimeMillis
().
toInt
())
//that's correct
this
.
writeHex
(
"01 12"
);
//tag
this
.
writeHex
(
"00 38"
);
//length
this
.
write
(
token0825
);
//length
this
.
writeHex
(
"03 0F"
);
//tag
this
.
writeShort
(
hostName
.
length
/
2
);
//todo check that
this
.
writeShort
(
hostName
.
length
);
this
.
writeBytes
(
hostName
)
this
.
writeHex
(
"00 05 00 06 00 02"
)
this
.
writeQQ
(
qq
)
this
.
writeHex
(
"00 06"
)
//tag
this
.
writeHex
(
"00 78"
)
//length
//TEA 加密
//TEA 加密
this
.
write
(
TEACryptor
.
encrypt
(
object
:
ClientPacket
()
{
this
.
write
(
TEACryptor
.
encrypt
(
object
:
ClientPacket
()
{
@Throws
(
IOException
::
class
)
@Throws
(
IOException
::
class
)
override
fun
encode
()
{
override
fun
encode
()
{
val
hostName
:
String
=
InetAddress
.
getLocalHost
().
hostName
.
let
{
it
.
substring
(
0
,
it
.
length
-
3
)
};
this
.
writeQQ
(
System
.
currentTimeMillis
().
toInt
())
//that's correct
this
.
writeHex
(
"01 12"
);
//tag
this
.
writeHex
(
"00 38"
);
//length
this
.
write
(
token0825
);
//length
this
.
writeHex
(
"03 0F"
);
//tag
this
.
writeShort
(
hostName
.
length
/
2
);
//todo check that
this
.
writeShort
(
hostName
.
length
);
this
.
writeBytes
(
hostName
)
this
.
writeHex
(
"00 05 00 06 00 02"
)
this
.
writeQQ
(
qq
)
this
.
writeHex
(
"00 06"
)
//tag
this
.
writeHex
(
"00 78"
)
//length
this
.
writeTLV0006
(
qq
,
password
)
//fix
this
.
writeHex
(
Protocol
.
_0836_622_fix2
)
this
.
writeHex
(
"00 1A"
)
//tag
this
.
writeHex
(
"00 40"
)
//length
this
.
write
(
TEACryptor
.
encrypt
(
Protocol
.
_0836_622_fix2
.
hexToBytes
(),
tgtgtKey
))
this
.
writeHex
(
Protocol
.
_0825data0
)
this
.
writeHex
(
Protocol
.
_0825data0
)
this
.
writeHex
(
Protocol
.
_0825data2
)
this
.
writeHex
(
Protocol
.
_0825data2
)
this
.
writeQQ
(
qq
)
this
.
writeQQ
(
qq
)
this
.
writeHex
(
"00 01 00 00 03 09 00 0C 00 01"
)
this
.
writeZero
(
4
)
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"
)
this
.
writeHex
(
"01 03"
)
//tag
this
.
writeHex
(
Protocol
.
publicKey
)
this
.
writeHex
(
"00 14"
)
//length
this
.
writeHex
(
"00 01"
)
//tag
this
.
writeHex
(
"00 10"
)
//length
this
.
writeHex
(
"60 C9 5D A7 45 70 04 7F 21 7D 84 50 5C 66 A5 C6"
)
//key
this
.
writeHex
(
"03 12"
)
//tag
this
.
writeHex
(
"00 05"
)
//length
this
.
writeHex
(
"01 00 00 00 01"
)
//value
this
.
writeHex
(
"05 08"
)
//tag
this
.
writeHex
(
"00 05"
)
//length
this
.
writeHex
(
"10 00 00 00 00"
)
//value
this
.
writeHex
(
"03 13"
)
//tag
this
.
writeHex
(
"00 19"
)
//length
this
.
writeHex
(
"01"
)
//value
this
.
writeHex
(
"01 02"
)
//tag
this
.
writeHex
(
"00 10"
)
//length
this
.
writeHex
(
"04 EA 78 D1 A4 FF CD CC 7C B8 D4 12 7D BB 03 AA"
)
//key
this
.
writeZero
(
3
)
this
.
writeByte
(
0
)
//maybe 00, 0F, 1F
this
.
writeHex
(
"01 02"
)
//tag
this
.
writeHex
(
"00 62"
)
//length
this
.
writeHex
(
"00 01"
)
//word?
this
.
writeHex
(
"04 EB B7 C1 86 F9 08 96 ED 56 84 AB 50 85 2E 48"
)
//key
this
.
writeHex
(
"00 38"
)
//length
//value
this
.
writeHex
(
"E9 AA 2B 4D 26 4C 76 18 FE 59 D5 A9 82 6A 0C 04 B4 49 50 D7 9B B1 FE 5D 97 54 8D 82 F3 22 C2 48 B9 C9 22 69 CA 78 AD 3E 2D E9 C9 DF A8 9E 7D 8C 8D 6B DF 4C D7 34 D0 D3"
)
this
.
writeHex
(
"00 14"
)
//length
getRandomKey
(
16
).
let
{
write
(
it
)
//key
writeLong
(
getCrc32
(
it
))
//todo may be int? check that.
}
}
}
}.
encodeToByteArray
(),
Protocol
.
redirectionKey
.
hexToBytes
()))
}.
encodeToByteArray
(),
Protocol
.
redirectionKey
.
hexToBytes
()))
}
}
}
}
\ No newline at end of file
mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/ClientPacket.kt
View file @
3e451344
...
@@ -5,8 +5,11 @@ import net.mamoe.mirai.network.Protocol
...
@@ -5,8 +5,11 @@ import net.mamoe.mirai.network.Protocol
import
net.mamoe.mirai.network.packet.Packet
import
net.mamoe.mirai.network.packet.Packet
import
net.mamoe.mirai.network.packet.PacketId
import
net.mamoe.mirai.network.packet.PacketId
import
net.mamoe.mirai.util.ByteArrayDataOutputStream
import
net.mamoe.mirai.util.ByteArrayDataOutputStream
import
net.mamoe.mirai.util.TEACryptor
import
net.mamoe.mirai.util.hexToBytes
import
java.io.DataOutputStream
import
java.io.DataOutputStream
import
java.io.IOException
import
java.io.IOException
import
java.security.MessageDigest
/**
/**
* @author Him188moe @ Mirai Project
* @author Him188moe @ Mirai Project
...
@@ -14,7 +17,7 @@ import java.io.IOException
...
@@ -14,7 +17,7 @@ import java.io.IOException
@ExperimentalUnsignedTypes
@ExperimentalUnsignedTypes
abstract
class
ClientPacket
:
ByteArrayDataOutputStream
(),
Packet
{
abstract
class
ClientPacket
:
ByteArrayDataOutputStream
(),
Packet
{
@Getter
@Getter
val
packageId
:
Int
val
packageId
:
String
init
{
init
{
val
annotation
=
this
.
javaClass
.
getAnnotation
(
PacketId
::
class
.
java
)
val
annotation
=
this
.
javaClass
.
getAnnotation
(
PacketId
::
class
.
java
)
...
@@ -32,7 +35,7 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
...
@@ -32,7 +35,7 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
@Throws
(
IOException
::
class
)
@Throws
(
IOException
::
class
)
fun
writePacketId
()
{
fun
writePacketId
()
{
this
.
write
Int
(
this
@ClientPacket
.
packageId
)
this
.
write
Hex
(
this
@ClientPacket
.
packageId
)
}
}
/**
/**
...
@@ -74,15 +77,40 @@ fun DataOutputStream.writeHex(hex: String) {
...
@@ -74,15 +77,40 @@ fun DataOutputStream.writeHex(hex: String) {
@ExperimentalUnsignedTypes
@ExperimentalUnsignedTypes
@Throws
(
IOException
::
class
)
@Throws
(
IOException
::
class
)
fun
DataOutputStream
.
writeTLV0006
(
qq
:
Int
,
password
:
String
)
{
fun
DataOutputStream
.
writeTLV0006
(
qq
:
Int
,
password
:
String
,
loginTime
:
ByteArray
,
loginIP
:
ByteArray
,
tgtgtKey
:
ByteArray
)
{
this
.
writeRandom
(
4
)
ByteArrayDataOutputStream
().
let
{
this
.
writeHex
(
"00 02"
)
it
.
writeRandom
(
4
)
this
.
writeQQ
(
qq
)
it
.
writeHex
(
"00 02"
)
this
.
writeHex
(
Protocol
.
_0825data2
)
it
.
writeQQ
(
qq
)
this
.
writeHex
(
"00 00 01"
)
it
.
writeHex
(
Protocol
.
_0825data2
)
this
.
writeHex
()
it
.
writeHex
(
"00 00 01"
)
val
md5_1
:
ByteArray
=
md5
(
password
);
val
md5_2
=
md5
(
md5_1
+
"00 00 00 00"
.
hexToBytes
()
+
qq
.
toBytes
())
it
.
write
(
md5_1
)
it
.
write
(
loginTime
)
//FIXED 12(maybe 11???) bytes
it
.
writeByte
(
0
);
it
.
writeZero
(
4
*
3
)
it
.
write
(
loginIP
)
it
.
writeHex
(
"00 10"
)
it
.
writeHex
(
"15 74 C4 89 85 7A 19 F5 5E A9 C9 A3 5E 8A 5A 9B"
)
it
.
write
(
tgtgtKey
)
this
.
write
(
TEACryptor
.
encrypt
(
md5_2
,
it
.
toByteArray
()))
}
}
}
private
fun
Int
.
toBytes
():
ByteArray
=
byteArrayOf
(
(
this
.
ushr
(
24
)
and
0
xFF
).
toByte
(),
(
this
.
ushr
(
16
)
and
0
xFF
).
toByte
(),
(
this
.
ushr
(
8
)
and
0
xFF
).
toByte
(),
(
this
.
ushr
(
0
)
and
0
xFF
).
toByte
()
)
private
fun
md5
(
str
:
String
):
ByteArray
=
MessageDigest
.
getInstance
(
"MD5"
).
digest
(
str
.
toByteArray
())
private
fun
md5
(
byteArray
:
ByteArray
):
ByteArray
=
MessageDigest
.
getInstance
(
"MD5"
).
digest
(
byteArray
)
@ExperimentalUnsignedTypes
@ExperimentalUnsignedTypes
@Throws
(
IOException
::
class
)
@Throws
(
IOException
::
class
)
fun
DataOutputStream
.
writeZero
(
count
:
Int
)
{
fun
DataOutputStream
.
writeZero
(
count
:
Int
)
{
...
...
mirai-core/src/main/java/net/mamoe/mirai/network/packet/server/ServerPacket.kt
View file @
3e451344
package
net.mamoe.mirai.network.packet.server
package
net.mamoe.mirai.network.packet.server
import
net.mamoe.mirai.network.packet.Packet
import
net.mamoe.mirai.network.packet.Packet
import
java.io.DataInputStream
import
java.io.DataInputStream
/**
/**
...
...
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