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
d6e4c0ee
Commit
d6e4c0ee
authored
Jan 06, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix missing params
parent
48850d73
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
18 deletions
+16
-18
mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/network/packet/login/PasswordSubmission.kt
...oe.mirai.timpc/network/packet/login/PasswordSubmission.kt
+2
-2
mirai-core-timpc/src/jvmTest/kotlin/PacketDebugger.kt
mirai-core-timpc/src/jvmTest/kotlin/PacketDebugger.kt
+1
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/Decrypters.kt
...onMain/kotlin/net.mamoe.mirai/utils/cryptor/Decrypters.kt
+4
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/TEA.kt
...rc/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/TEA.kt
+6
-8
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/OutputUtils.kt
...commonMain/kotlin/net.mamoe.mirai/utils/io/OutputUtils.kt
+3
-3
No files found.
mirai-core-timpc/src/commonMain/kotlin/net.mamoe.mirai.timpc/network/packet/login/PasswordSubmission.kt
View file @
d6e4c0ee
...
...
@@ -27,7 +27,7 @@ internal inline class PrivateKey(override val value: ByteArray) : DecrypterByteA
internal
inline
class
SubmitPasswordResponseDecrypter
(
private
val
privateKey
:
PrivateKey
)
:
Decrypter
{
override
fun
decrypt
(
input
:
ByteReadPacket
,
offset
:
Int
,
length
:
Int
):
ByteReadPacket
{
var
decrypted
=
ShareKey
.
decrypt
(
input
)
var
decrypted
=
ShareKey
.
decrypt
(
input
,
offset
,
length
)
(
decrypted
.
remaining
).
let
{
if
(
it
.
toInt
()
%
8
==
0
&&
it
>=
16
)
{
decrypted
=
try
{
...
...
@@ -263,7 +263,7 @@ internal object SubmitPasswordPacket : PacketFactory<SubmitPasswordPacket.LoginR
}
internal
inline
class
SessionResponseDecryptionKey
(
private
val
delegate
:
IoBuffer
)
:
Decrypter
{
override
fun
decrypt
(
input
:
ByteReadPacket
,
offset
:
Int
,
length
:
Int
):
ByteReadPacket
=
input
.
decryptBy
(
delegate
)
override
fun
decrypt
(
input
:
ByteReadPacket
,
offset
:
Int
,
length
:
Int
):
ByteReadPacket
=
input
.
decryptBy
(
delegate
,
offset
,
length
)
override
fun
toString
():
String
=
"SessionResponseDecryptionKey"
...
...
mirai-core-timpc/src/jvmTest/kotlin/PacketDebugger.kt
View file @
d6e4c0ee
...
...
@@ -24,10 +24,7 @@ import net.mamoe.mirai.timpc.network.packet.login.CaptchaKey
import
net.mamoe.mirai.timpc.network.packet.login.HeartbeatPacket
import
net.mamoe.mirai.timpc.network.packet.login.ShareKey
import
net.mamoe.mirai.timpc.network.packet.login.TouchKey
import
net.mamoe.mirai.utils.cryptor.Decrypter
import
net.mamoe.mirai.utils.cryptor.DecryptionFailedException
import
net.mamoe.mirai.utils.cryptor.NoDecrypter
import
net.mamoe.mirai.utils.cryptor.decryptBy
import
net.mamoe.mirai.utils.cryptor.*
import
net.mamoe.mirai.utils.io.*
import
org.pcap4j.core.BpfProgram.BpfCompileMode
import
org.pcap4j.core.PacketListener
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/Decrypters.kt
View file @
d6e4c0ee
...
...
@@ -45,11 +45,14 @@ object NoDecrypter : Decrypter, DecrypterType<NoDecrypter> {
}
}
fun
Decrypter
.
decrypt
(
input
:
ByteReadPacket
):
ByteReadPacket
=
this
.
decrypt
(
input
,
0
,
input
.
remaining
.
toInt
())
/**
* 解密器
*/
interface
Decrypter
{
fun
decrypt
(
input
:
ByteReadPacket
,
offset
:
Int
=
0
,
length
:
Int
=
(
input
.
remaining
-
offset
).
toInt
()):
ByteReadPacket
// do not write with default args. NoSuchMethodError when inline classes override this function
fun
decrypt
(
input
:
ByteReadPacket
,
offset
:
Int
,
length
:
Int
):
ByteReadPacket
/**
* 连接后将会先用 this 解密, 再用 [another] 解密
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/cryptor/TEA.kt
View file @
d6e4c0ee
...
...
@@ -94,21 +94,19 @@ fun IoBuffer.decryptBy(key: ByteArray, offset: Int = 0, length: Int = readRemain
// region ByteReadPacket extension
fun
ByteReadPacket
.
decryptBy
(
key
:
ByteArray
,
offset
:
Int
=
0
,
length
:
Int
=
key
.
size
-
offset
):
ByteReadPacket
=
decryptAsByteArray
(
key
)
{
data
->
ByteReadPacket
(
data
,
offset
,
length
)
}
fun
ByteReadPacket
.
decryptBy
(
key
:
ByteArray
,
offset
:
Int
=
0
,
length
:
Int
=
key
.
size
-
offset
):
ByteReadPacket
=
decryptAsByteArray
(
key
,
offset
,
length
)
{
data
->
ByteReadPacket
(
data
)
}
fun
ByteReadPacket
.
decryptBy
(
key
:
IoBuffer
,
offset
:
Int
=
0
,
length
:
Int
=
key
.
readRemaining
-
offset
):
ByteReadPacket
=
decryptAsByteArray
(
key
)
{
data
->
ByteReadPacket
(
data
,
offset
,
length
)
}
fun
ByteReadPacket
.
decryptBy
(
key
:
IoBuffer
,
offset
:
Int
=
0
,
length
:
Int
=
key
.
readRemaining
-
offset
):
ByteReadPacket
=
decryptAsByteArray
(
key
,
offset
,
length
)
{
data
->
ByteReadPacket
(
data
)
}
inline
fun
<
R
>
ByteReadPacket
.
decryptAsByteArray
(
key
:
ByteArray
,
consumer
:
(
ByteArray
)
->
R
):
R
=
inline
fun
<
R
>
ByteReadPacket
.
decryptAsByteArray
(
key
:
ByteArray
,
offset
:
Int
=
0
,
length
:
Int
=
key
.
size
-
offset
,
consumer
:
(
ByteArray
)
->
R
):
R
=
ByteArrayPool
.
useInstance
{
val
length
=
remaining
.
toInt
()
readFully
(
it
,
0
,
length
)
readFully
(
it
,
offset
,
length
)
consumer
(
it
.
decryptBy
(
key
,
length
))
}.
also
{
close
()
}
inline
fun
<
R
>
ByteReadPacket
.
decryptAsByteArray
(
key
:
IoBuffer
,
consumer
:
(
ByteArray
)
->
R
):
R
=
inline
fun
<
R
>
ByteReadPacket
.
decryptAsByteArray
(
key
:
IoBuffer
,
offset
:
Int
=
0
,
length
:
Int
=
key
.
readRemaining
-
offset
,
consumer
:
(
ByteArray
)
->
R
):
R
=
ByteArrayPool
.
useInstance
{
val
length
=
remaining
.
toInt
()
readFully
(
it
,
0
,
length
)
readFully
(
it
,
offset
,
length
)
consumer
(
it
.
decryptBy
(
key
,
length
))
}.
also
{
close
()
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/OutputUtils.kt
View file @
d6e4c0ee
...
...
@@ -47,7 +47,7 @@ fun BytePacketBuilder.writeShortLVByteArray(byteArray: ByteArray): Int {
inline
fun
BytePacketBuilder
.
writeIntLVPacket
(
tag
:
UByte
?
=
null
,
lengthOffset
:
((
Long
)
->
Long
)
=
{
it
},
builder
:
BytePacketBuilder
.()
->
Unit
):
Int
=
BytePacketBuilder
().
apply
(
builder
).
build
().
use
{
if
(
tag
!=
null
)
writeUByte
(
tag
)
val
length
=
(
lengthOffset
.
invoke
(
it
.
remaining
)
?:
it
.
remaining
).
coerceAtMostOrFail
(
0
xFFFFL
)
val
length
=
lengthOffset
.
invoke
(
it
.
remaining
).
coerceAtMostOrFail
(
0
xFFFFL
)
writeInt
(
length
.
toInt
())
writePacket
(
it
)
return
length
.
toInt
()
...
...
@@ -56,7 +56,7 @@ inline fun BytePacketBuilder.writeIntLVPacket(tag: UByte? = null, lengthOffset:
inline
fun
BytePacketBuilder
.
writeShortLVPacket
(
tag
:
UByte
?
=
null
,
lengthOffset
:
((
Long
)
->
Long
)
=
{
it
},
builder
:
BytePacketBuilder
.()
->
Unit
):
Int
=
BytePacketBuilder
().
apply
(
builder
).
build
().
use
{
if
(
tag
!=
null
)
writeUByte
(
tag
)
val
length
=
(
lengthOffset
.
invoke
(
it
.
remaining
)
?:
it
.
remaining
).
coerceAtMostOrFail
(
0
xFFFFL
)
val
length
=
lengthOffset
.
invoke
(
it
.
remaining
).
coerceAtMostOrFail
(
0
xFFFFL
)
writeUShort
(
length
.
toUShort
())
writePacket
(
it
)
return
length
.
toInt
()
...
...
@@ -65,7 +65,7 @@ inline fun BytePacketBuilder.writeShortLVPacket(tag: UByte? = null, lengthOffset
inline
fun
BytePacketBuilder
.
writeUVarIntLVPacket
(
tag
:
UByte
?
=
null
,
lengthOffset
:
((
Long
)
->
Long
)
=
{
it
},
builder
:
BytePacketBuilder
.()
->
Unit
)
=
BytePacketBuilder
().
apply
(
builder
).
build
().
use
{
if
(
tag
!=
null
)
writeUByte
(
tag
)
writeUVarInt
(
(
lengthOffset
.
invoke
(
it
.
remaining
)
?:
it
.
remaining
).
coerceAtMostOrFail
(
0
xFFFFL
))
writeUVarInt
(
lengthOffset
.
invoke
(
it
.
remaining
).
coerceAtMostOrFail
(
0
xFFFFL
))
writePacket
(
it
)
}
...
...
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