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
d5c2c19c
Commit
d5c2c19c
authored
Mar 21, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rearrange tests
parent
3e6c7bc6
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
0 additions
and
1210 deletions
+0
-1210
mirai-core-qqandroid/src/jvmTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceDecoderTest.kt
....mamoe.mirai.qqandroid.io.serialization/JceDecoderTest.kt
+0
-317
mirai-core-qqandroid/src/jvmTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/TestRequesetPacket.kt
...oe.mirai.qqandroid.io.serialization/TestRequesetPacket.kt
+0
-26
mirai-core-qqandroid/src/jvmTest/kotlin/test/DataClassGenerator.kt
...e-qqandroid/src/jvmTest/kotlin/test/DataClassGenerator.kt
+0
-89
mirai-core-qqandroid/src/jvmTest/kotlin/test/JceDataClassGenerator.kt
...qandroid/src/jvmTest/kotlin/test/JceDataClassGenerator.kt
+0
-190
mirai-core-qqandroid/src/jvmTest/kotlin/test/ProtoBufDataClassGenerator.kt
...oid/src/jvmTest/kotlin/test/ProtoBufDataClassGenerator.kt
+0
-406
mirai-core-qqandroid/src/jvmTest/kotlin/test/QLogReader.kt
mirai-core-qqandroid/src/jvmTest/kotlin/test/QLogReader.kt
+0
-68
mirai-core-qqandroid/src/jvmTest/kotlin/test/dumpProtobufId.kts
...core-qqandroid/src/jvmTest/kotlin/test/dumpProtobufId.kts
+0
-12
mirai-core-qqandroid/src/jvmTest/kotlin/test/protoBuf.kt
mirai-core-qqandroid/src/jvmTest/kotlin/test/protoBuf.kt
+0
-102
No files found.
mirai-core-qqandroid/src/jvmTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceDecoderTest.kt
deleted
100644 → 0
View file @
3e6c7bc6
This diff is collapsed.
Click to expand it.
mirai-core-qqandroid/src/jvmTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/TestRequesetPacket.kt
deleted
100644 → 0
View file @
3e6c7bc6
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.qqandroid.io.serialization
import
net.mamoe.mirai.qqandroid.network.protocol.data.jce.RequestPacket
import
net.mamoe.mirai.utils.io.hexToBytes
class
TestRequesetPacket
{
companion
object
{
@JvmStatic
fun
main
(
args
:
Array
<
String
>)
{
val
data
=
"10 03 2C 3C 4C 56 0B 50 75 73 68 53 65 72 76 69 63 65 66 0E 53 76 63 52 65 71 52 65 67 69 73 74 65 72 7D 00 01 D6 00 08 00 01 06 0E 53 76 63 52 65 71 52 65 67 69 73 74 65 72 1D 00 01 BE 00 0A 02 DD B8 E4 76 10 07 2C 36 00 40 0B 5C 6C 7C 8C 9C AC B0 1D C0 01 D6 00 EC FD 10 00 00 10 07 EA 76 78 FD EB 06 C3 33 B2 18 80 32 15 09 BA F1 11 04 08 FC 12 F6 13 19 41 6E 64 72 6F 69 64 20 53 44 4B 20 62 75 69 6C 74 20 66 6F 72 20 78 38 36 F6 14 19 41 6E 64 72 6F 69 64 20 53 44 4B 20 62 75 69 6C 74 20 66 6F 72 20 78 38 36 F6 15 02 31 30 F0 16 01 F1 17 0F 06 FC 18 FC 1A F3 1B A9 00 FE 00 66 00 82 00 FC 1D F6 1E 04 4D 49 55 49 F6 1F 14 3F 4F 4E 45 50 4C 55 53 20 41 35 30 30 30 5F 32 33 5F 31 37 FD 21 00 00 0D 0A 04 08 2E 10 00 0A 05 08 9B 02 10 00 FC 22 FC 24 0B 8C 98 0C A8 0C"
.
hexToBytes
()
println
(
data
.
loadAs
(
RequestPacket
.
serializer
(),
JceCharset
.
UTF8
))
}
}
}
\ No newline at end of file
mirai-core-qqandroid/src/jvmTest/kotlin/test/DataClassGenerator.kt
deleted
100644 → 0
View file @
3e6c7bc6
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
test
import
java.util.*
import
kotlin.concurrent.thread
fun
main
()
{
val
inputs
=
LinkedList
<
String
>()
thread
{
while
(
true
){
val
x
=
readLine
()
if
(
x
!=
null
)
inputs
.
offer
(
x
)
}
}
tailrec
fun
getNext
():
String
{
val
x
=
inputs
.
poll
()
if
(
x
==
null
){
Thread
.
sleep
(
100
)
return
getNext
()
}
return
x
;
}
fun
getAll
():
String
{
val
b
=
StringBuilder
(
getNext
())
Thread
.
sleep
(
500
)
while
(
true
){
val
c
=
inputs
.
poll
();
if
(
c
===
null
)
break
;
b
.
append
(
"\n"
).
append
(
c
)
}
return
b
.
toString
();
}
while
(
true
){
println
(
"-proto || -jce"
)
val
x
=
getNext
()
if
(
x
.
contains
(
"proto"
,
true
)){
//proto
println
(
"..Copy file content below, after each file is submited, click enter, after all file are in, input \'end'\'"
)
val
y
=
mutableListOf
<
String
>()
while
(
true
){
val
z
=
getAll
()
if
(
z
.
toLowerCase
()
==
"end"
||
z
.
toLowerCase
()
==
"end\n"
){
println
(
"received file content: "
+
y
.
size
+
", start generating ProtoBuf"
)
break
;
}
y
.
add
(
z
)
println
(
"received, "
)
}
println
(
"======================>protoBuf output<==========================="
)
println
()
println
()
println
(
y
.
map
{
it
.
generateProtoBufDataClass
()
}.
toMutableList
().
arrangeClasses
().
joinToString
(
"\n\n"
));
println
()
println
()
println
(
"======================>protoBuf output<==========================="
)
}
if
(
x
.
contains
(
"jce"
,
true
)){
println
(
"..Copy the WHOLE file below"
)
while
(
true
){
val
z
=
getAll
()
println
(
"======================>JCE output<==========================="
)
println
()
println
()
println
(
toJCEInfo
(
z
).
toString
())
println
()
println
()
println
(
"======================>JCE output<==========================="
)
break
;
}
}
}
}
mirai-core-qqandroid/src/jvmTest/kotlin/test/JceDataClassGenerator.kt
deleted
100644 → 0
View file @
3e6c7bc6
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
test;
import
java.io.File
fun
main
()
{
println
(
"import kotlinx.serialization.SerialId\n"
+
"import kotlinx.serialization.Serializable\n"
+
"import net.mamoe.mirai.qqandroid.io.JceStruct\n"
)
File
(
"""
E:\Projects\QQAndroidFF\app\src\main\java\ConfigPush
"""
.
trimIndent
()
).
listFiles
()
!!
.
forEach
{
try
{
println
(
toJCEInfo
(
it
.
readText
()).
toString
())
}
catch
(
e
:
Exception
)
{
println
(
"when processing ${it.path}"
)
throw
e
}
}
}
/**
* 不支持叠加中
*/
class
JCEInfo
(
){
lateinit
var
className
:
String
var
parents
:
List
<
String
>?
=
null
//seems useless
lateinit
var
properties
:
List
<
Property
>
override
fun
toString
():
String
{
properties
=
properties
.
sortedBy
{
it-
>
it
.
jceID
}
val
max
=
(
properties
.
size
-
1
).
toString
().
length
val
builder
:
StringBuilder
=
StringBuilder
(
"@Serializable"
)
builder
.
append
(
"\n"
).
append
(
"internal class "
).
append
(
className
).
append
(
"("
)
properties
.
forEach
{
builder
.
append
(
","
).
append
(
"\n"
).
append
(
it
.
toStringWithSpacing
(
max
))
}
builder
.
append
(
"\n"
).
append
(
"): JceStruct"
)
return
builder
.
toString
().
replace
(
"(,"
,
"("
)
}
}
class
Property
(
var
name
:
String
,
var
type
:
String
,
var
defaultValue
:
String
?
=
null
){
var
isRequired
:
Boolean
=
true
var
jceID
:
Int
=
-
1
//convert type/default value to kotlin format
init
{
type
=
type
.
replace
(
"byte[]"
,
"ByteArray"
)
.
replace
(
"ArrayList"
,
"List"
)
.
replace
(
"byte"
,
"Byte"
)
.
replace
(
"int"
,
"Int"
)
.
replace
(
"short"
,
"Short"
)
.
replace
(
"long"
,
"Long"
)
if
(
name
.
length
>
1
&&
name
.
get
(
1
).
isUpperCase
()){
if
(
name
.
get
(
0
)
==
'l'
||
name
.
get
(
0
)
==
'c'
||
name
.
get
(
0
)
==
'b'
){
name
=
name
.
substring
(
1
)
}
}
if
(
name
.
startsWith
(
"str"
)
||
name
.
startsWith
(
"bytes"
)){
name
=
name
.
replace
(
"str"
,
""
).
replace
(
"bytes"
,
""
)
}
if
(
name
.
contains
(
"_"
)){
val
x
=
name
.
split
(
"_"
)
name
=
x
.
get
(
0
);
var
z
=
1
;
repeat
(
x
.
size-1
){
name
+=
""
+
x
.
get
(
z
).
get
(
0
).
toUpperCase
()
+
x
.
get
(
z
).
substring
(
1
).
toLowerCase
()
++
z
;
}
}
name
=
""
+
name
.
get
(
0
).
toLowerCase
()
+
""
+
name
.
substring
(
1
)
}
//@SerialId(1) val iVersion: Short = 3,
override
fun
toString
():
String
{
if
(
defaultValue
!=
null
)
{
return
"@SerialId("
+
jceID
+
") val "
+
name
+
":"
+
type
+
" = "
+
defaultValue
}
return
"@SerialId("
+
jceID
+
") val "
+
name
+
":"
+
type
+
"? = null"
}
fun
toStringWithSpacing
(
maxIDLength
:
Int
):
String
{
val
space
=
" "
.
repeat
((
maxIDLength
-
(
jceID
.
toString
().
length
)).
coerceAtLeast
(
0
))
var
base
=
" @SerialId("
+
jceID
+
") "
+
space
+
"val "
+
name
+
":"
+
type
+
""
if
(!
isRequired
){
if
(
defaultValue
==
null
)
{
base
+=
"? = null"
}
else
{
base
+=
"? = $defaultValue"
}
}
else
{
if
(
defaultValue
!=
null
)
{
base
+=
" = "
+
defaultValue
}
}
return
base
}
}
fun
toJCEInfo
(
source
:
String
):
JCEInfo
{
val
info
=
JCEInfo
()
val
allProperties
=
mutableMapOf
<
String
,
Property
>()
var
inputStreamVariableRegix
:
String
?
=
null
// println(source)
source
.
split
(
"\n"
).
forEach
{
when
{
it
.
contains
(
"class"
)
->
{
var
var0
=
it
.
substringBetween
(
"class"
,
"{"
).
trim
()
if
(
var0
.
contains
(
"extends"
)){
info
.
parents
=
var0
.
substringAfter
(
"extends"
).
split
(
","
).
map
{
it
.
trim
()
}.
toList
()
var0
=
var0
.
substringBefore
(
" extends"
)
}
//println("class name: $var0" )
info
.
className
=
var0
}
(
it
.
contains
(
"public"
)
&&
it
.
contains
(
";"
)
&&
(!
it
.
contains
(
"static"
)))
->
{
val
var1
=
it
.
replace
(
", "
,
","
).
trim
().
split
(
" "
)
if
(
var1
.
size
==
5
){
allProperties
.
put
(
var1
[
2
],
Property
(
var1
[
2
],
var1
[
1
].
replace
(
","
,
", "
),
var1
[
4
].
replace
(
";"
,
""
)
)
)
}
else
{
allProperties
.
put
(
var1
[
2
].
replace
(
";"
,
""
),
Property
(
var1
[
2
].
replace
(
";"
,
""
),
var1
[
1
].
replace
(
","
,
", "
)
)
)
}
}
(
inputStreamVariableRegix
==
null
&&
it
.
contains
(
"public void readFrom"
))
->
{
// public void readFrom(JceInputStream var1) {
inputStreamVariableRegix
=
it
.
trim
().
substringBetween
(
"(JceInputStream "
,
")"
)
+
".read"
//println("inputStreamVariableRegix: " + inputStreamVariableRegix )
}
(
inputStreamVariableRegix
!=
null
&&
it
.
contains
(
inputStreamVariableRegix
!!
))
->
{
val
key
=
it
.
substringBetween
(
"this."
,
" = "
)
if
(!
allProperties
.
containsKey
(
key
)){
println
(
key
+
" is found in readFrom but not in properties"
)
}
val
src
=
it
.
replace
(
".readString("
,
".read(\" \","
)
.
substringBetween
(
"("
,
");"
)
.
split
(
","
)
with
(
allProperties
.
get
(
key
)
!!
){
this
.
jceID
=
src
[
1
].
trim
().
toInt
()
this
.
isRequired
=
src
[
2
].
trim
().
toBoolean
()
}
}
}
}
info
.
properties
=
allProperties
.
values
.
toList
();
return
info
;
}
\ No newline at end of file
mirai-core-qqandroid/src/jvmTest/kotlin/test/ProtoBufDataClassGenerator.kt
deleted
100644 → 0
View file @
3e6c7bc6
This diff is collapsed.
Click to expand it.
mirai-core-qqandroid/src/jvmTest/kotlin/test/QLogReader.kt
deleted
100644 → 0
View file @
3e6c7bc6
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
test
import
java.io.ByteArrayInputStream
import
java.io.ByteArrayOutputStream
import
java.io.File
import
java.util.zip.InflaterInputStream
object
QLogReader
{
@JvmStatic
fun
main
(
args
:
Array
<
String
>)
{
println
(
readQLog
(
File
(
"/Users/jiahua.liu/Downloads/wtlogin_20200129.log"
)))
}
fun
readQLog
(
file
:
File
):
String
{
return
(
decompress
(
file
.
readBytes
()))
}
fun
readQLog
(
file
:
ByteArray
):
String
{
return
(
decompress
(
file
))
}
fun
decompress
(
array
:
ByteArray
):
String
{
return
buildString
{
if
(
array
.
isNotEmpty
())
{
var
i
=
0
var
n
=
0
while
(
array
.
size
>
n
+
3
)
{
val
buf_to_int32
:
Int
=
buf_to_int32
(
array
,
n
)
if
(
array
.
size
<=
n
+
buf_to_int32
+
3
)
{
break
}
val
buf
=
ByteArray
(
buf_to_int32
)
System
.
arraycopy
(
array
,
n
+
4
,
buf
,
0
,
buf_to_int32
)
n
+=
4
+
buf_to_int32
++
i
val
byteArrayOutputStream
=
ByteArrayOutputStream
()
val
`in`
=
ByteArrayInputStream
(
buf
)
val
inflaterInputStream
=
InflaterInputStream
(
`in`
)
val
array2
=
ByteArray
(
1024
)
while
(
true
)
{
val
read
=
inflaterInputStream
.
read
(
array2
)
if
(
read
==
-
1
)
{
break
}
byteArrayOutputStream
.
write
(
array2
,
0
,
read
)
}
append
(
byteArrayOutputStream
.
toString
())
}
}
}
}
private
fun
buf_to_int32
(
array
:
ByteArray
,
n
:
Int
):
Int
{
return
(
array
[
n
].
toInt
()
shl
24
and
-
0
x1000000
)
+
(
array
[
n
+
1
].
toInt
()
shl
16
and
0
xFF0000
)
+
(
array
[
n
+
2
].
toInt
()
shl
8
and
0
xFF00
)
+
(
array
[
n
+
3
].
toInt
()
shl
0
and
0
xFF
)
}
}
\ No newline at end of file
mirai-core-qqandroid/src/jvmTest/kotlin/test/dumpProtobufId.kts
deleted
100644 → 0
View file @
3e6c7bc6
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
)
package
test
import
net.mamoe.mirai.utils.cryptor.protoFieldNumber
import
net.mamoe.mirai.utils.cryptor.protoType
intArrayOf
(
8
,
16
,
24
,
32
,
40
,
48
,
56
,
64
,
74
,
82
).
forEach
{
println
(
protoFieldNumber
(
it
.
toUInt
()).
toString
()
+
" -> "
+
protoType
(
it
.
toUInt
()))
}
\ No newline at end of file
mirai-core-qqandroid/src/jvmTest/kotlin/test/protoBuf.kt
deleted
100644 → 0
View file @
3e6c7bc6
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
,
"unused"
,
"NO_REFLECTION_IN_CLASS_PATH"
)
package
net.mamoe.mirai.utils.cryptor
import
net.mamoe.mirai.utils.MiraiDebugAPI
// ProtoBuf utilities
@Suppress
(
"FunctionName"
,
"SpellCheckingInspection"
)
/*
* Type Meaning Used For
* 0 Varint int32, int64, uint32, uint64, sint32, sint64, bool, enum
* 1 64-bit fixed64, sfixed64, double
* 2 Length-delimi string, bytes, embedded messages, packed repeated fields
* 3 Start group Groups (deprecated)
* 4 End group Groups (deprecated)
* 5 32-bit fixed32, sfixed32, float
*
* https://www.jianshu.com/p/f888907adaeb
*/
@MiraiDebugAPI
fun
ProtoFieldId
(
serializedId
:
UInt
):
ProtoFieldId
=
ProtoFieldId
(
protoFieldNumber
(
serializedId
),
protoType
(
serializedId
)
)
@MiraiDebugAPI
data class
ProtoFieldId
(
val
fieldNumber
:
Int
,
val
type
:
ProtoType
)
{
override
fun
toString
():
String
=
"$type $fieldNumber"
}
@Suppress
(
"SpellCheckingInspection"
)
@MiraiDebugAPI
enum
class
ProtoType
(
val
value
:
Byte
,
private
val
typeName
:
String
)
{
/**
* int32, int64, uint32, uint64, sint32, sint64, bool, enum
*/
VAR_INT
(
0
x00
,
"varint"
),
/**
* fixed64, sfixed64, double
*/
BIT_64
(
0
x01
,
" 64bit"
),
/**
* string, bytes, embedded messages, packed repeated fields
*/
LENGTH_DELIMI
(
0
x02
,
"delimi"
),
/**
* Groups (deprecated)
*/
START_GROUP
(
0
x03
,
"startg"
),
/**
* Groups (deprecated)
*/
END_GROUP
(
0
x04
,
" endg"
),
/**
* fixed32, sfixed32, float
*/
BIT_32
(
0
x05
,
" 32bit"
),
;
override
fun
toString
():
String
=
this
.
typeName
companion
object
{
fun
valueOf
(
value
:
Byte
):
ProtoType
=
values
().
firstOrNull
{
it
.
value
==
value
}
?:
error
(
"Unknown ProtoType $value"
)
}
}
/**
* 由 ProtoBuf 序列化后的 id 得到类型
*
* serializedId = (fieldNumber << 3) | wireType
*/
@MiraiDebugAPI
fun
protoType
(
number
:
UInt
):
ProtoType
=
ProtoType
.
valueOf
(
number
.
toInt
().
shl
(
29
).
ushr
(
29
).
toByte
())
/**
* ProtoBuf 序列化后的 id 转为序列前标记的 id
*
* serializedId = (fieldNumber << 3) | wireType
*/
@MiraiDebugAPI
fun
protoFieldNumber
(
number
:
UInt
):
Int
=
number
.
toInt
().
ushr
(
3
)
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