aboutsummaryrefslogtreecommitdiff
path: root/example/dump-traffic.lua
blob: f003c745b17ddf6b2e07df2856eec11dcfb9a220 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env hydra-dragonfire
local escapes = require("escapes")
local base64 = require("base64")
local client = require("client")()

client:enable("pkts")
client.pkts:wildcard(true)

client:connect()

local function dump(val, indent)
	local t = type(val)
	local mt = getmetatable(val)

	if t ~= "table" or mt and mt.__tostring then
		if t == "string" then
			val = val:gsub("\n", "\\n")
		end
		print(val)
	else
		print()

		local idt = (indent or "") .. "  "
		for k, v in pairs(val) do
			io.write(idt .. k .. " ")
			dump(v, idt)
		end
	end
end

while true do
	local evt = client:poll()

	if not evt or evt.type == "disconnect" or evt.type == "interrupt" then
		break
	elseif evt.type == "error" then
		print(evt.error)
	elseif evt.type == "pkt" then
		local type, data = evt.pkt_type, evt.pkt_data

		if type == "srp_bytes_salt_b" then
			data.b = base64.encode(data.b)
			data.salt = base64.encode(data.salt)
		end

		if type == "chat_msg" then
			data.text = escapes.strip_all(data.text)
		end

		if type == "blk_data" then
			data.blk.param0 = {}
			data.blk.param1 = {}
			data.blk.param2 = {}
		end

		io.write(type)
		dump(data)
	end
end

client:close()