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
e85014e7
Commit
e85014e7
authored
Aug 09, 2019
by
liujiahua123123
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
eeed2859
43595db0
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
612 additions
and
50 deletions
+612
-50
mirai-core/src/main/java/net/mamoe/mirai/network/Protocol.java
...-core/src/main/java/net/mamoe/mirai/network/Protocol.java
+61
-0
mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/ClientHeartbeatPacket.java
...oe/mirai/network/packet/client/ClientHeartbeatPacket.java
+14
-2
mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/ClientLoginPacket.java
.../mamoe/mirai/network/packet/client/ClientLoginPacket.java
+32
-2
mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/ClientPacket.java
...a/net/mamoe/mirai/network/packet/client/ClientPacket.java
+28
-44
mirai-core/src/main/java/net/mamoe/mirai/util/TEAEncryption.java
...ore/src/main/java/net/mamoe/mirai/util/TEAEncryption.java
+12
-2
mirai-core/src/main/java/net/mamoe/mirai/util/_TEAEncryption.java
...re/src/main/java/net/mamoe/mirai/util/_TEAEncryption.java
+456
-0
mirai-native/src/main/java/net/mamoe/mirai/util/TeaEncryption.java
...ive/src/main/java/net/mamoe/mirai/util/TeaEncryption.java
+9
-0
No files found.
mirai-core/src/main/java/net/mamoe/mirai/network/Protocol.java
0 → 100644
View file @
e85014e7
package
net.mamoe.mirai.network
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* @author Him188moe @ Mirai Project
*/
public
interface
Protocol
{
List
<
String
>
SERVER_IP
=
new
ArrayList
<>()
{{
add
(
"183.60.56.29"
);
List
.
of
(
"sz2.tencent.com"
,
"sz3.tencent.com"
,
"sz4.tencent.com"
,
"sz5.tencent.com"
,
"sz6.tencent.com"
,
"sz8.tencent.com"
,
"sz9.tencent.com"
).
forEach
(
s
->
{
try
{
SERVER_IP
.
add
(
InetAddress
.
getByName
(
s
).
getHostAddress
());
}
catch
(
UnknownHostException
ignored
)
{
}
});
}};
String
head
=
"02"
;
String
ver
=
"37 13 "
;
String
fixVer
=
"03 00 00 00 01 2E 01 00 00 68 52 00 00 00 00 "
;
String
tail
=
" 03"
;
String
_fixVer
=
"02 00 00 00 01 01 01 00 00 68 20 "
;
String
_0825data0
=
"00 18 00 16 00 01 "
;
String
_0825data2
=
"00 00 04 53 00 00 00 01 00 00 15 85 "
;
String
_0825key
=
"A4 F1 91 88 C9 82 14 99 0C 9E 56 55 91 23 C8 3D"
;
String
redirectionKey
=
"A8 F2 14 5F 58 12 60 AF 07 63 97 D6 76 B2 1A 3B"
;
String
publicKey
=
"02 6D 28 41 D2 A5 6F D2 FC 3E 2A 1F 03 75 DE 6E 28 8F A8 19 3E 5F 16 49 D3"
;
String
shareKey
=
"1A E9 7F 7D C9 73 75 98 AC 02 E0 80 5F A9 C6 AF"
;
String
_0836fix
=
"06 A9 12 97 B7 F8 76 25 AF AF D3 EA B4 C8 BC E7 "
;
String
_00BaKey
=
"C1 9C B8 C8 7B 8C 81 BA 9E 9E 7A 89 E1 7A EC 94"
;
String
_00BaFixKey
=
"69 20 D1 14 74 F5 B3 93 E4 D5 02 B3 71 1A CD 2A"
;
String
encryptKey
=
"“BA 42 FF 01 CF B4 FF D2 12 F0 6E A7 1B 7C B3 08”"
;
static
byte
[]
hexToBytes
(
String
hex
)
{
var
list
=
Arrays
.
stream
(
hex
.
split
(
" "
)).
map
(
String:
:
trim
).
map
(
s
->
Byte
.
valueOf
(
s
,
16
)).
collect
(
Collectors
.
toList
());
var
buff
=
new
byte
[
list
.
size
()];
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
buff
[
i
]
=
list
.
get
(
i
);
}
return
buff
;
}
}
mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/ClientHeartbeatPacket.java
View file @
e85014e7
package
net.mamoe.mirai.network.packet.client
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
net.mamoe.mirai.network.Protocol
;
import
net.mamoe.mirai.network.packet.PacketId
;
import
net.mamoe.mirai.util.TEAEncryption
;
import
java.io.IOException
;
/**
* @author Him188moe @ Mirai Project
*/
@PacketId
(
0x0058
)
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@PacketId
(
0x00_58
)
public
class
ClientHeartbeatPacket
extends
ClientPacket
{
public
long
qq
;
public
byte
[]
sessionKey
;
//登录后获得
@Override
public
void
encode
()
throws
IOException
{
this
.
writeRandom
(
2
);
this
.
writeQQ
(
qq
);
this
.
writeHex
(
Protocol
.
fixVer
);
this
.
write
(
TEAEncryption
.
encrypt
(
new
byte
[]{
0x00
,
0x01
,
0x00
,
0x01
},
sessionKey
));
}
}
mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/ClientLoginPacket.java
View file @
e85014e7
package
net.mamoe.mirai.network.packet.client
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
net.mamoe.mirai.network.Protocol
;
import
net.mamoe.mirai.network.packet.PacketId
;
import
net.mamoe.mirai.util.TEAEncryption
;
import
java.io.IOException
;
/**
* @author Him188moe @ Mirai Project
*/
@PacketId
(
0x08_25_31_01
)
// TODO: 2019/8/8
@EqualsAndHashCode
(
callSuper
=
true
)
@Data
@PacketId
(
0x08_25_31_01
)
public
class
ClientLoginPacket
extends
ClientPacket
{
public
long
qq
;
@Override
public
void
encode
()
{
public
void
encode
()
throws
IOException
{
this
.
writeQQ
(
qq
);
this
.
writeHex
(
Protocol
.
fixVer
);
this
.
writeHex
(
Protocol
.
_0825key
);
//TEA 加密
var
data
=
new
ClientPacket
()
{
@Override
public
void
encode
()
throws
IOException
{
this
.
writeHex
(
Protocol
.
_0825data0
);
this
.
writeHex
(
Protocol
.
_0825data2
);
this
.
writeQQ
(
qq
);
this
.
writeHex
(
"00 00 00 00 03 09 00 08 00 01"
);
this
.
writeIp
(
Protocol
.
SERVER_IP
.
get
(
2
));
this
.
writeHex
(
"00 02 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 02 00 19"
);
this
.
writeHex
(
Protocol
.
publicKey
);
}
};
data
.
encode
();
this
.
write
(
TEAEncryption
.
encrypt
(
data
.
toByteArray
(),
Protocol
.
hexToBytes
(
Protocol
.
_0825key
)));
}
}
mirai-core/src/main/java/net/mamoe/mirai/network/packet/client/ClientPacket.java
View file @
e85014e7
package
net.mamoe.mirai.network.packet.client
;
import
lombok.Getter
;
import
net.mamoe.mirai.network.Protocol
;
import
net.mamoe.mirai.network.packet.Packet
;
import
net.mamoe.mirai.network.packet.PacketId
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.util.Arrays
;
/**
* @author Him188moe @ Mirai Project
...
...
@@ -25,60 +25,38 @@ public abstract class ClientPacket extends DataOutputStream implements Packet {
packageId
=
annotation
.
value
();
try
{
writeHead
(
);
writeVersion
(
);
this
.
writeHex
(
Protocol
.
head
);
this
.
writeHex
(
Protocol
.
ver
);
writePacketId
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
var
pk
=
new
ClientPacket
()
{
@Override
public
void
encode
()
throws
IOException
{
writeHead
();
}
};
pk
.
encode
();
System
.
out
.
println
(
Arrays
.
toString
(((
ByteArrayOutputStream
)
pk
.
out
).
toByteArray
()));
}
protected
void
writeHead
()
throws
IOException
{
this
.
writeByte
(
0x02
);
}
protected
void
writeVersion
()
throws
IOException
{
this
.
writeByte
(
0x37_13
);
protected
void
writeIp
(
String
ip
)
throws
IOException
{
for
(
String
s
:
ip
.
split
(
"\\."
))
{
this
.
writeInt
(
Integer
.
parseInt
(
s
));
}
}
protected
void
writePacketId
()
throws
IOException
{
this
.
write
Byte
(
this
.
packageId
);
this
.
write
Int
(
this
.
packageId
);
}
protected
void
writeFixVer
()
throws
IOException
{
this
.
writeByte
(
0x03
);
this
.
writeByte
(
0x00
);
this
.
writeByte
(
0x00
);
this
.
writeByte
(
0x00
);
this
.
writeByte
(
0x01
);
this
.
writeByte
(
0x2E
);
this
.
writeByte
(
0x01
);
this
.
writeByte
(
0x00
);
this
.
writeByte
(
0x00
);
this
.
writeByte
(
0x68
);
this
.
writeByte
(
0x52
);
this
.
writeByte
(
0x00
);
this
.
writeByte
(
0x00
);
this
.
writeByte
(
0x00
);
this
.
writeByte
(
0x00
);
protected
void
writeHex
(
String
hex
)
throws
IOException
{
for
(
String
s
:
hex
.
split
(
" "
))
{
s
=
s
.
trim
();
if
(
s
.
isEmpty
())
{
continue
;
}
this
.
writeByte
(
Byte
.
valueOf
(
s
,
16
));
}
}
protected
void
write0825Key
()
throws
IOException
{
this
.
writeLong
(
0xA4_F1_91_88
);
this
.
writeLong
(
0xC9_82_14_99
);
this
.
writeLong
(
0x0C_9E_56_55
);
this
.
writeLong
(
0x91_23_C8_3D
);
protected
void
writeRandom
(
int
length
)
throws
IOException
{
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
this
.
writeByte
((
byte
)
(
int
)
(
Math
.
random
()
*
255
));
}
}
protected
void
writeQQ
(
long
qq
)
throws
IOException
{
...
...
@@ -87,7 +65,13 @@ public abstract class ClientPacket extends DataOutputStream implements Packet {
/**
* Encode this packet
*/
* Encode this packet.
* <p>
* Before sending the packet, an {@linkplain Protocol#tail tail} will be added.
*/
// TODO: 2019/8/9 添加 tail
public
abstract
void
encode
()
throws
IOException
;
public
byte
[]
toByteArray
()
{
return
((
ByteArrayOutputStream
)
this
.
out
).
toByteArray
();
}
}
mirai-core/src/main/java/net/mamoe/mirai/util/TEAEncryption.java
View file @
e85014e7
package
net.mamoe.mirai.util
;
/**
* TEA encryption
*
* @author Him188moe @ Mirai Project
*/
public
final
class
TEAEncryption
{
public
static
byte
[]
encrypt
(
byte
[]
source
,
byte
[]
key
)
{
return
new
_TEAEncryption
().
encrypt
(
source
,
key
);
}
public
byte
[]
decrypt
(
byte
[]
source
,
byte
[]
key
)
{
return
new
_TEAEncryption
().
decrypt
(
source
,
key
);
}
public
byte
[]
decrypt
(
byte
[]
source
,
int
offset
,
int
length
,
byte
[]
key
)
{
return
new
_TEAEncryption
().
decrypt
(
source
,
offset
,
length
,
key
);
}
}
mirai-core/src/main/java/net/mamoe/mirai/util/_TEAEncryption.java
0 → 100644
View file @
e85014e7
This diff is collapsed.
Click to expand it.
mirai-native/src/main/java/net/mamoe/mirai/util/TeaEncryption.java
0 → 100644
View file @
e85014e7
package
net.mamoe.mirai.util
;
/**
* @author Him188moe @ Mirai Project
*/
public
final
class
TeaEncryption
{
public
static
native
int
Decrypt
();
}
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