mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 22:30:47 +08:00
Fix missing params
This commit is contained in:
parent
48850d7389
commit
d6e4c0ee70
@ -27,7 +27,7 @@ internal inline class PrivateKey(override val value: ByteArray) : DecrypterByteA
|
|||||||
|
|
||||||
internal inline class SubmitPasswordResponseDecrypter(private val privateKey: PrivateKey) : Decrypter {
|
internal inline class SubmitPasswordResponseDecrypter(private val privateKey: PrivateKey) : Decrypter {
|
||||||
override fun decrypt(input: ByteReadPacket, offset: Int, length: Int): ByteReadPacket {
|
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 {
|
(decrypted.remaining).let {
|
||||||
if (it.toInt() % 8 == 0 && it >= 16) {
|
if (it.toInt() % 8 == 0 && it >= 16) {
|
||||||
decrypted = try {
|
decrypted = try {
|
||||||
@ -263,7 +263,7 @@ internal object SubmitPasswordPacket : PacketFactory<SubmitPasswordPacket.LoginR
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal inline class SessionResponseDecryptionKey(private val delegate: IoBuffer) : Decrypter {
|
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"
|
override fun toString(): String = "SessionResponseDecryptionKey"
|
||||||
|
|
||||||
|
@ -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.HeartbeatPacket
|
||||||
import net.mamoe.mirai.timpc.network.packet.login.ShareKey
|
import net.mamoe.mirai.timpc.network.packet.login.ShareKey
|
||||||
import net.mamoe.mirai.timpc.network.packet.login.TouchKey
|
import net.mamoe.mirai.timpc.network.packet.login.TouchKey
|
||||||
import net.mamoe.mirai.utils.cryptor.Decrypter
|
import net.mamoe.mirai.utils.cryptor.*
|
||||||
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.io.*
|
import net.mamoe.mirai.utils.io.*
|
||||||
import org.pcap4j.core.BpfProgram.BpfCompileMode
|
import org.pcap4j.core.BpfProgram.BpfCompileMode
|
||||||
import org.pcap4j.core.PacketListener
|
import org.pcap4j.core.PacketListener
|
||||||
|
@ -45,11 +45,14 @@ object NoDecrypter : Decrypter, DecrypterType<NoDecrypter> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Decrypter.decrypt(input: ByteReadPacket): ByteReadPacket = this.decrypt(input, 0, input.remaining.toInt())
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解密器
|
* 解密器
|
||||||
*/
|
*/
|
||||||
interface Decrypter {
|
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] 解密
|
* 连接后将会先用 this 解密, 再用 [another] 解密
|
||||||
*/
|
*/
|
||||||
|
@ -94,21 +94,19 @@ fun IoBuffer.decryptBy(key: ByteArray, offset: Int = 0, length: Int = readRemain
|
|||||||
|
|
||||||
// region ByteReadPacket extension
|
// 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 {
|
ByteArrayPool.useInstance {
|
||||||
val length = remaining.toInt()
|
readFully(it, offset, length)
|
||||||
readFully(it, 0, length)
|
|
||||||
consumer(it.decryptBy(key, length))
|
consumer(it.decryptBy(key, length))
|
||||||
}.also { close() }
|
}.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 {
|
ByteArrayPool.useInstance {
|
||||||
val length = remaining.toInt()
|
readFully(it, offset, length)
|
||||||
readFully(it, 0, length)
|
|
||||||
consumer(it.decryptBy(key, length))
|
consumer(it.decryptBy(key, length))
|
||||||
}.also { close() }
|
}.also { close() }
|
||||||
|
|
||||||
|
@ -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 =
|
inline fun BytePacketBuilder.writeIntLVPacket(tag: UByte? = null, lengthOffset: ((Long) -> Long) = {it}, builder: BytePacketBuilder.() -> Unit): Int =
|
||||||
BytePacketBuilder().apply(builder).build().use {
|
BytePacketBuilder().apply(builder).build().use {
|
||||||
if (tag != null) writeUByte(tag)
|
if (tag != null) writeUByte(tag)
|
||||||
val length = (lengthOffset.invoke(it.remaining) ?: it.remaining).coerceAtMostOrFail(0xFFFFL)
|
val length = lengthOffset.invoke(it.remaining).coerceAtMostOrFail(0xFFFFL)
|
||||||
writeInt(length.toInt())
|
writeInt(length.toInt())
|
||||||
writePacket(it)
|
writePacket(it)
|
||||||
return length.toInt()
|
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 =
|
inline fun BytePacketBuilder.writeShortLVPacket(tag: UByte? = null, lengthOffset: ((Long) -> Long) = {it}, builder: BytePacketBuilder.() -> Unit): Int =
|
||||||
BytePacketBuilder().apply(builder).build().use {
|
BytePacketBuilder().apply(builder).build().use {
|
||||||
if (tag != null) writeUByte(tag)
|
if (tag != null) writeUByte(tag)
|
||||||
val length = (lengthOffset.invoke(it.remaining) ?: it.remaining).coerceAtMostOrFail(0xFFFFL)
|
val length = lengthOffset.invoke(it.remaining).coerceAtMostOrFail(0xFFFFL)
|
||||||
writeUShort(length.toUShort())
|
writeUShort(length.toUShort())
|
||||||
writePacket(it)
|
writePacket(it)
|
||||||
return length.toInt()
|
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) =
|
inline fun BytePacketBuilder.writeUVarIntLVPacket(tag: UByte? = null, lengthOffset: ((Long) -> Long) = {it}, builder: BytePacketBuilder.() -> Unit) =
|
||||||
BytePacketBuilder().apply(builder).build().use {
|
BytePacketBuilder().apply(builder).build().use {
|
||||||
if (tag != null) writeUByte(tag)
|
if (tag != null) writeUByte(tag)
|
||||||
writeUVarInt((lengthOffset.invoke(it.remaining) ?: it.remaining).coerceAtMostOrFail(0xFFFFL))
|
writeUVarInt(lengthOffset.invoke(it.remaining).coerceAtMostOrFail(0xFFFFL))
|
||||||
writePacket(it)
|
writePacket(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user