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
7541437e
Commit
7541437e
authored
Nov 10, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix packet debugger
parent
7569395d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
28 deletions
+50
-28
mirai-debug/src/main/kotlin/PacketDebuger.kt
mirai-debug/src/main/kotlin/PacketDebuger.kt
+50
-28
No files found.
mirai-debug/src/main/kotlin/PacketDebuger.kt
View file @
7541437e
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
,
"MemberVisibilityCanBePrivate"
,
"EXPERIMENTAL_UNSIGNED_LITERALS"
)
import
Main.dataReceived
import
Main.dataSent
import
Main.localIp
import
Main.qq
import
Main.sessionKey
import
kotlinx.coroutines.*
import
PacketDebugger.dataSent
import
PacketDebugger.localIp
import
PacketDebugger.qq
import
PacketDebugger.sessionKey
import
kotlinx.coroutines.GlobalScope
import
kotlinx.io.core.discardExact
import
kotlinx.io.core.readBytes
import
kotlinx.io.core.readUInt
...
...
@@ -30,38 +29,61 @@ import net.mamoe.mirai.utils.decryptBy
import
net.mamoe.mirai.utils.io.*
import
org.pcap4j.core.BpfProgram.BpfCompileMode
import
org.pcap4j.core.PacketListener
import
org.pcap4j.core.PcapNetworkInterface
import
org.pcap4j.core.PcapNetworkInterface.PromiscuousMode
import
org.pcap4j.core.Pcaps
import
kotlin.concurrent.thread
import
kotlin.coroutines.CoroutineContext
suspend
fun
main
()
{
val
nif
:
PcapNetworkInterface
=
Pcaps
.
findAllDevs
()[
0
]
println
(
nif
.
name
+
"("
+
nif
.
addresses
+
")"
)
/**
* 需使用 32 位 JDK
*/
fun
main
()
{
/*
check(System.getProperty("os.arch") == "x86") { "Jpcap can only work with x86 JDK" }
val
sender
=
nif
.
openLive
(
65536
,
PromiscuousMode
.
PROMISCUOUS
,
3000
)
val
sendListener
=
GlobalScope
.
launch
{
sender
.
setFilter
(
"src $localIp && udp port 8000"
,
BpfCompileMode
.
OPTIMIZE
)
withContext
(
Dispatchers
.
IO
)
{
sender
.
loop
(
Int
.
MAX_VALUE
,
PacketListener
{
dataSent
(
it
.
rawData
.
drop
(
42
).
toByteArray
())
})
}
JpcapCaptor.getDeviceList().forEach {
println(it)
}
JpcapCaptor.openDevice(JpcapCaptor.getDeviceList()[0], 65535, true, 1000).loopPacket(Int.MAX_VALUE) {
println(it)
}*/
val
receiver
=
nif
.
openLive
(
65536
,
PromiscuousMode
.
PROMISCUOUS
,
3000
)
val
receiveListener
=
GlobalScope
.
launch
{
receiver
.
setFilter
(
"dst $localIp && udp port 8000"
,
BpfCompileMode
.
OPTIMIZE
)
withContext
(
Dispatchers
.
IO
)
{
receiver
.
loop
(
Int
.
MAX_VALUE
,
PacketListener
{
runBlocking
{
dataReceived
(
it
.
rawData
.
drop
(
42
).
toByteArray
())
listenDevice
()
}
private
fun
listenDevice
()
{
thread
{
val
sender
=
Pcaps
.
findAllDevs
().
first
{
it
.
addresses
.
any
{
it
.
address
.
hostAddress
==
localIp
}
}.
openLive
(
65536
,
PromiscuousMode
.
PROMISCUOUS
,
10
)
sender
.
setFilter
(
"src $localIp && udp port 8000"
,
BpfCompileMode
.
OPTIMIZE
)
println
(
"sendListener started"
)
try
{
sender
.
loop
(
999999
,
PacketListener
{
if
(
it
.
length
()
==
0
)
{
println
(
"EMPTY PACKET!"
)
}
try
{
println
(
it
.
rawData
.
toUHexString
())
dataSent
(
it
.
rawData
.
drop
(
42
).
toByteArray
())
}
catch
(
e
:
Throwable
)
{
e
.
printStackTrace
()
}
})
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
joinAll
(
sendListener
,
receiveListener
)
/*
thread {
val receiver = Pcaps.findAllDevs().first { it.addresses.any { it.address.hostAddress == localIp } }.openLive(65536, PromiscuousMode.PROMISCUOUS, 10)
receiver.setFilter("dst $localIp && udp port 8000", BpfCompileMode.OPTIMIZE)
println("receiveListener started")
receiver.loop(Int.MAX_VALUE, PacketListener {
runBlocking {
dataReceived(it.rawData.drop(42).toByteArray())
}
})
}*/
}
/**
...
...
@@ -70,7 +92,7 @@ suspend fun main() {
*
* @author Him188moe
*/
object
Main
{
object
PacketDebugger
{
/**
* 会话密匙, 用于解密数据.
* 在一次登录中会话密匙不会改变.
...
...
@@ -85,7 +107,7 @@ object Main {
* 7. 运行完 `mov eax,dword ptr ss:[ebp+10]`
* 8. 查看内存, `eax` 到 `eax+10` 的 16 字节就是 `sessionKey`
*/
val
sessionKey
:
ByteArray
=
"
98 BA DE 20 53 AB EC B5 F5 50 26 E9 6D 41 B6 05
"
.
hexToBytes
()
val
sessionKey
:
ByteArray
=
"
F9 37 23 8F E7 04 AF 52 6D B9 94 13 E1 3A BD 4A
"
.
hexToBytes
()
const
val
qq
:
UInt
=
1040400290
u
const
val
localIp
=
"192.168.3.10"
...
...
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