-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsniffer.proxy.kts
43 lines (35 loc) · 1.29 KB
/
sniffer.proxy.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@file:Import("packetFilter.kt")
import me.marvin.proxy.networking.*
import me.marvin.proxy.networking.packet.*
import me.marvin.proxy.utils.*
import io.netty.buffer.*
import io.netty.channel.*
import java.util.*
object Constants {
const val HEADER = " +-------------------------------------------------+"
val VALIDATOR: Validator = Validator.PhaseValidator(ProtocolPhase.LOGIN) or
Validator.TypeValidator(
PacketTypes.Play.Client.PLUGIN_MESSAGE,
PacketTypes.Play.Server.PLUGIN_MESSAGE,
PacketTypes.Login.Client.LOGIN_PLUGIN_RESPONSE,
PacketTypes.Login.Server.LOGIN_PLUGIN_REQUEST,
)
}
object Sniffer : PacketListener {
override fun priority(): Byte = 0
override fun handle(type: PacketType, buf: ByteBuf, send: Channel, recv: ChannelHandlerContext, version: Version): Tristate {
val prefix = if (type.direction() == ProtocolDirection.CLIENT) "C->S" else "S->C"
if (Constants.VALIDATOR.validate(type)) {
println("$prefix ${type.phase()}.$type -> ${ByteBufUtil.prettyHexDump(buf).replace(Constants.HEADER, "")}")
}
return Tristate.NOT_SET
}
}
@Entrypoint
fun entry() {
proxy.registerListeners(Sniffer)
}
@Destructor
fun destruct() {
proxy.unregisterListener(Sniffer)
}