-
Notifications
You must be signed in to change notification settings - Fork 0
/
asheronscall.lua
146 lines (117 loc) · 4.33 KB
/
asheronscall.lua
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
local HEADER_SIZE = 20
local ac = Proto("AC", "Asheron's Call Protocol")
local packet = {
sequence_number = ProtoField.uint32("ac.packet.sequence_number", "Sequence Number"),
flags = ProtoField.uint32("ac.packet.flags", "Flags", base.HEX),
crc = ProtoField.uint32("ac.packet.crc", "CRC", base.HEX),
id = ProtoField.uint16("ac.packet.id", "ID"),
time = ProtoField.uint16("ac.packet.time", "Time"),
size = ProtoField.uint16("ac.packet.size", "Size"),
table = ProtoField.uint16("ac.packet.table", "Table")
}
local packet_flags = {
resent = {
mask = 0x00000001,
pfield = ProtoField.bool("ac.packet.flags.resent", "Resent", 32, nil, 0x00000001)
},
crc = {
mask = 0x00000002,
pfield = ProtoField.bool("ac.packet.flags.crc", "CRC", 32, nil, 0x00000002)
},
fragment = {
mask = 0x00000004,
pfield = ProtoField.bool("ac.packet.flags.fragment", "Fragment", 32, nil, 0x00000004)
},
server_switch = {
mask = 0x00000100,
pfield = ProtoField.bool("ac.packet.flags.server_switch", "Server Switch", 32, nil, 0x00000100)
},
referral = {
mask = 0x00000800,
pfield = ProtoField.bool("ac.packet.flags.referral", "Referral", 32, nil, 0x00000800)
},
request_retransmit = {
mask = 0x00001000,
pfield = ProtoField.bool("ac.packet.flags.request_retransmit", "Request Retransmit", 32, nil, 0x00001000)
},
reject_retransmit = {
mask = 0x00002000,
pfield = ProtoField.bool("ac.packet.flags.reject_retransmit", "Reject Retransmit", 32, nil, 0x00002000)
},
ack_sequence = {
mask = 0x00004000,
pfield = ProtoField.bool("ac.packet.flags.ack_sequence", "ACK sequence", 32, nil, 0x00004000)
},
disconnect = {
mask = 0x00008000,
pfield = ProtoField.bool("ac.packet.flags.disconnect", "Disconnect", 32, nil, 0x00008000)
},
login_request = {
mask = 0x00010000,
pfield = ProtoField.bool("ac.packet.flags.login_request", "Login Request", 32, nil, 0x00010000)
},
world_login_request = {
mask = 0x00020000,
pfield = ProtoField.bool("ac.packet.flags.world_login_request", "World Login Request", 32, nil, 0x00020000)
},
connect_request = {
mask = 0x00040000,
pfield = ProtoField.bool("ac.packet.flags.connect_request", "Connect Request", 32, nil, 0x00040000)
},
connect_response = {
mask = 0x00080000,
pfield = ProtoField.bool("ac.packet.flags.connect_response", "Connect Response", 32, nil, 0x00080000)
},
ci_command = {
mask = 0x00400000,
pfield = ProtoField.bool("ac.packet.flags.ci_command", "CI Command", 32, nil, 0x00400000)
},
time_sync = {
mask = 0x01000000,
pfield = ProtoField.bool("ac.packet.flags.time_sync", "Time Sync", 32, nil, 0x01000000)
},
echorequest = {
mask = 0x02000000,
pfield = ProtoField.bool("ac.packet.flags.echo_request", "Echo Request", 32, nil, 0x02000000)
},
echoresponse = {
mask = 0x04000000,
pfield = ProtoField.bool("ac.packet.flags.echo_response", "Echo Response", 32, nil, 0x04000000)
},
flow = {
mask = 0x08000000,
pfield = ProtoField.bool("ac.packet.flags.flow", "Flow", 32, nil, 0x08000000)
}
}
for _,field in pairs(packet) do
ac.fields[#ac.fields+1] = field
end
for _,flag in pairs(packet_flags) do
ac.fields[#ac.fields+1] = flag.pfield
end
function ac.dissector(buf, pinfo, root)
local tree = root:add(ac, buf(), "Asheron's Call Protocol")
tree:add_le(packet["sequence_number"], buf(0,4))
local flag_tree = tree:add_le(packet["flags"], buf(4,4))
local flags_value = buf(4,4):le_uint()
for _,flag in pairs(packet_flags) do
addIfFlagSet(flag_tree, flags_value, flag, buf(4,4))
end
tree:add_le(packet["crc"], buf( 8,4))
tree:add_le(packet["id"], buf(12,2))
tree:add_le(packet["time"], buf(14,2))
tree:add_le(packet["size"], buf(16,2))
tree:add_le(packet["table"], buf(18,2))
end
udp_table = DissectorTable.get("udp.port")
udp_table:add(9000, ac)
udp_table:add(9001, ac)
udp_table:add(9008, ac)
udp_table:add(9009, ac)
function addIfFlagSet(tree, value, flag, ...)
-- BUG(ccressent): doing it this way makes it so flags that are unset cannot
-- be filtered. Need to find a function to toggle visibility of tree items.
if bit.band(value, flag.mask) == flag.mask then
tree:add_le(flag.pfield, ...)
end
end