mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-14 07:10:09 +08:00
update
This commit is contained in:
parent
30e0d76c82
commit
de239cffb3
@ -53,7 +53,7 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return this.javaClass.simpleName + this.javaClass.declaredFields.joinToString(", ", "{", "}") { it.trySetAccessible(); it.name + "=" + it.get(this) }
|
||||
return this.javaClass.simpleName + this.getAllDeclaredFields().joinToString(", ", "{", "}") { it.trySetAccessible(); it.name + "=" + it.get(this) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import net.mamoe.mirai.network.packet.client.toHexString
|
||||
import net.mamoe.mirai.network.packet.server.login.*
|
||||
import net.mamoe.mirai.network.packet.server.touch.ServerTouchResponsePacket
|
||||
import net.mamoe.mirai.network.packet.server.touch.ServerTouchResponsePacketEncrypted
|
||||
import net.mamoe.mirai.util.getAllDeclaredFields
|
||||
import net.mamoe.mirai.util.toHexString
|
||||
import java.io.DataInputStream
|
||||
|
||||
@ -168,7 +169,7 @@ DataArrived >> AnalyMessage
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return this.javaClass.simpleName + this.javaClass.declaredFields.joinToString(", ", "{", "}") { it.trySetAccessible(); it.name + "=" + it.get(this) }
|
||||
return this.javaClass.simpleName + this.getAllDeclaredFields().joinToString(", ", "{", "}") { it.trySetAccessible(); it.name + "=" + it.get(this) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
package net.mamoe.mirai.util
|
||||
|
||||
import net.mamoe.mirai.network.Protocol
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
import java.lang.reflect.Field
|
||||
import java.util.*
|
||||
import java.util.zip.CRC32
|
||||
|
||||
@ -47,6 +50,7 @@ fun Byte.toHexString(): String = this.toUByte().toString(16)
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
fun String.hexToBytes(): ByteArray = Protocol.hexToBytes(this)
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
fun String.hexToUBytes(): UByteArray = Protocol.hexToUBytes(this)
|
||||
|
||||
@ -71,4 +75,38 @@ fun getRandomKey(length: Int): ByteArray {
|
||||
return bytes.toByteArray();
|
||||
}
|
||||
|
||||
fun getCrc32(key: ByteArray): Int = CRC32().let { it.update(key); it.value.toInt() }
|
||||
fun getCrc32(key: ByteArray): Int = CRC32().let { it.update(key); it.value.toInt() }
|
||||
|
||||
|
||||
/**
|
||||
* 获取类的所有字段(类成员变量), 包括父类的和私有的. <br></br>
|
||||
* 相当于将这个类和它所有父类的 [Class.getDeclaredFields] 都合并成一个 [List] <br></br>
|
||||
* 不会排除重名的字段. <br></br>
|
||||
*
|
||||
* @param clazz class
|
||||
*
|
||||
* @return field list
|
||||
*/
|
||||
@Throws(SecurityException::class)
|
||||
fun Any.getAllDeclaredFields(): List<Field> {
|
||||
val clazz: Class<out Any> = this.javaClass;
|
||||
val list = LinkedList<Field>()
|
||||
loop@ do {
|
||||
list.addAll(listOf(*clazz.declaredFields))
|
||||
if (this.javaClass == DataOutputStream::class) {
|
||||
continue
|
||||
}
|
||||
|
||||
when (this.javaClass) {
|
||||
DataOutputStream::class, ByteArrayDataOutputStream::class, DataInputStream::class, ByteArrayInputStream::class -> {
|
||||
break@loop;
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
|
||||
//clazz = clazz.superclass!!
|
||||
} while (clazz != Any::class.java)
|
||||
|
||||
return list
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user