forked from mgerhardy/simpleai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwireshark-dissector.lua
285 lines (246 loc) · 10.1 KB
/
wireshark-dissector.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
-- Packet dissector for the SimpleAI remote debugger protocol
-- Copy this to $HOME/.wireshark/plugins/
local default_settings = {
port = 10001,
}
-- message id lookup table
PROTO = {}
PROTO[0] = "PROTO_PING"
PROTO[1] = "PROTO_STATE"
PROTO[2] = "PROTO_CHARACTER_STATIC"
PROTO[3] = "PROTO_CHARACTER_DETAILS"
PROTO[4] = "PROTO_SELECT"
PROTO[5] = "PROTO_PAUSE"
PROTO[6] = "PROTO_CHANGE"
PROTO[7] = "PROTO_NAMES"
PROTO[8] = "PROTO_RESET"
PROTO[9] = "PROTO_STEP"
PROTO[10] = "PROTO_UPDATENODE"
PROTO[11] = "PROTO_DELETENODE"
PROTO[12] = "PROTO_ADDNODE"
MINLENGTH = {}
MINLENGTH[0] = 1
MINLENGTH[1] = 27
MINLENGTH[2] = 9
MINLENGTH[3] = 24
MINLENGTH[4] = 5
MINLENGTH[5] = 2
MINLENGTH[6] = 2
MINLENGTH[7] = 5
MINLENGTH[8] = 1
MINLENGTH[9] = 9
MINLENGTH[10] = 12
MINLENGTH[11] = 9
MINLENGTH[12] = 12
simpleai = Proto("simpleai", "SimpleAI remote debugger")
simpleai.prefs.port = Pref.uint("Port number", default_settings.port, "The TCP port number for the simpleai debug server")
function disPingMessage(buffer, tree)
-- Nothing to do here
end
function disStateMessage(buffer, tree)
tree:add(simpleai.fields.fieldStatesAmount, buffer(1, 4))
local count = buffer(1, 4):uint()
local offset = 5
for i = 1, count do
tree:add(simpleai.fields.fieldStatesId, buffer(offset, 4))
offset = offset + 4;
tree:add(simpleai.fields.fieldStatesX, buffer(offset, 4))
offset = offset + 4;
tree:add(simpleai.fields.fieldStatesY, buffer(offset, 4))
offset = offset + 4;
tree:add(simpleai.fields.fieldStatesZ, buffer(offset, 4))
offset = offset + 4;
tree:add(simpleai.fields.fieldStatesOrientation, buffer(offset, 4))
offset = offset + 4;
local attributesCount = buffer(offset, 2):uint()
tree:add(simpleai.fields.fieldStatesAttributesCount, buffer(offset, 2))
offset = offset + 2;
for i = 1, attributesCount do
tree:add(simpleai.fields.fieldStatesAttributesKey, buffer(offset))
offset = offset + buffer(offset):stringz():len()
tree:add(simpleai.fields.fieldStatesAttributesValue, buffer(offset))
offset = offset + buffer(offset):stringz():len()
end
end
end
function disCharacterStaticMessage(buffer, tree)
tree:add(simpleai.fields.fieldStaticCharacterId, buffer(1, 4))
local count = buffer(5, 4):uint()
tree:add(simpleai.fields.fieldStaticNodeCount, buffer(5, 4))
local offset = 9
for i = 1, count do
tree:add(simpleai.fields.fieldStaticNodeId, buffer(offset, 4))
offset = offset + 4;
tree:add(simpleai.fields.fieldStaticNodeName, buffer(offset))
offset = offset + buffer(offset):stringz():len()
tree:add(simpleai.fields.fieldStaticNodeType, buffer(offset))
offset = offset + buffer(offset):stringz():len()
tree:add(simpleai.fields.fieldStaticParameters, buffer(offset))
offset = offset + buffer(offset):stringz():len()
tree:add(simpleai.fields.fieldStaticConditionType, buffer(offset))
offset = offset + buffer(offset):stringz():len()
tree:add(simpleai.fields.fieldStaticConditionParameters, buffer(offset))
offset = offset + buffer(offset):stringz():len()
end
end
function disCharacterDetailsMessageNode(buffer, tree, offset)
tree:add(simpleai.fields.fieldDetailsNodeId, buffer(offset, 4))
offset = offset + 4
tree:add(simpleai.fields.fieldDetailsNodeCondition, buffer(offset))
offset = offset + buffer(offset):stringz():len()
tree:add(simpleai.fields.fieldDetailsNodeLastRun, buffer(offset, 8))
offset = offset + 8
local childrenCount = buffer(offset, 2):uint()
tree:add(simpleai.fields.fieldDetailsChildrenCount, buffer(offset, 2))
offset = offset + 2
for i = 1, childrenCount do
fields.advance = disCharacterDetailsMessageNode(buffer, tree, offset)
offset = offset + advance
end
return offset
end
function disCharacterDetailsMessage(buffer, tree)
tree:add(simpleai.fields.fieldDetailsCharacterId, buffer(1, 4))
-- read the aggro
local aggroCount = buffer(5, 2):uint()
tree:add(simpleai.fields.fieldDetailsAggroCount, buffer(5, 2))
local offset = 7
for i = 1, aggroCount do
tree:add(simpleai.fields.fieldDetailsAggroChrId, buffer(offset, 4))
offset = offset + 4
tree:add(simpleai.fields.fieldDetailsAggroAmount, buffer(offset, 4))
offset = offset + 4
end
-- now read the nodes
disCharacterDetailsMessageNode(buffer, tree, offset)
end
function disSelectMessage(buffer, tree)
tree:add(simpleai.fields.fieldSelectCharacterId, buffer(1, 4))
end
function disPauseMessage(buffer, tree)
tree:add(simpleai.fields.fieldPauseState, buffer(1, 1))
end
function disChangeMessage(buffer, tree)
tree:add(simpleai.fields.fieldChangeName, buffer(1))
end
function disNamesMessage(buffer, tree)
tree:add(simpleai.fields.fieldZoneNamesAmount, buffer(1, 4))
local count = buffer(1, 4):uint()
local offset = 5
for i = 1, count do
tree:add(simpleai.fields.fieldZoneNamesName, buffer(offset))
offset = offset + buffer(offset):stringz():len()
end
end
function disResetMessage(buffer, tree)
-- Nothing to do here
end
function disStepMessage(buffer, tree)
tree:add(simpleai.fields.fieldStepMillis, buffer(1, 8))
end
function disUpdateNodeMessage(buffer, tree)
end
function disDeleteNodeMessage(buffer, tree)
end
function disAddNodeMessage(buffer, tree)
end
function simpleai.dissector(buffer, pinfo, tree)
local subtree = tree:add(simpleai, buffer())
local id = buffer(0, 1):uint()
local name = PROTO[id]
if name == nil then
subtree:add_expert_info(PI_MALFORMED, PI_ERROR, "Unknown message type " .. id)
return
end
local minlen = MINLENGTH[id]
if minlen == nil then
subtree:add_expert_info(PI_MALFORMED, PI_ERROR, "No length given for message type " .. id)
return
end
if buffer:reported_length_remaining() >= minlen then
subtree:add_expert_info(PI_UNDECODED, PI_INFO, "Only part of this packet was captured, unable to decode.")
return
elseif buffer:len() < minlen then
subtree:add_expert_info(PI_MALFORMED, PI_ERROR, "Message is too short")
return
end
pinfo.cols.protocol = simpleai.name
pinfo.cols.info = "Type: " .. name
subtree:set_len(minlen)
subtree:set_text("SimpleAI: " .. name)
if id == 0 then
disPingMessage(buffer, subtree)
elseif id == 1 then
disStateMessage(buffer, subtree)
elseif id == 2 then
disCharacterStaticMessage(buffer, subtree)
elseif id == 3 then
disCharacterDetailsMessage(buffer, subtree)
elseif id == 4 then
disSelectMessage(buffer, subtree)
elseif id == 5 then
disPauseMessage(buffer, subtree)
elseif id == 6 then
disChangeMessage(buffer, subtree)
elseif id == 7 then
disNamesMessage(buffer, subtree)
elseif id == 8 then
disResetMessage(buffer, subtree)
elseif id == 9 then
disStepMessage(buffer, subtree)
elseif id == 10 then
disUpdateNodeMessage(buffer, subtree)
elseif id == 11 then
disDeleteNodeMessage(buffer, subtree)
elseif id == 12 then
disAddNodeMessage(buffer, subtree)
end
end
function simpleai.prefs_changed()
if default_settings.port ~= simpleai.prefs.port then
if default_settings.port ~= 0 then
DissectorTable.get("tcp.port"):remove(default_settings.port, simpleai)
end
default_settings.port = simpleai.prefs.port
if default_settings.port ~= 0 then
DissectorTable.get("tcp.port"):add(default_settings.port, simpleai)
end
end
end
function simpleai.init()
local fields = simpleai.fields
fields.msgid = ProtoField.uint8("simpleai.msgid", "Message Id")
fields.fieldZoneNamesAmount = ProtoField.uint32("simpleai.zonenames.amount", "Number of zone names")
fields.fieldZoneNamesName = ProtoField.string("simpleai.zonenames.name", "Zone name")
fields.fieldStatesAmount = ProtoField.uint32("simpleai.states.amount", "Number of states")
fields.fieldStatesId = ProtoField.uint32("simpleai.states.id", "Node id")
fields.fieldStatesX = ProtoField.float("simpleai.states.x", "X position of the entity")
fields.fieldStatesY = ProtoField.float("simpleai.states.y", "Y position of the entity")
fields.fieldStatesZ = ProtoField.float("simpleai.states.z", "Z position of the entity")
fields.fieldStateOrientation = ProtoField.float("simpleai.states.orientation", "Orientation of the entity")
fields.fieldStatesAttributesCount = ProtoField.uint16("simpleai.states.attribcount", "Attribute count")
fields.fieldStatesAttributesKey = ProtoField.stringz("simpleai.states.attribkey", "Key")
fields.fieldStatesAttributesValue = ProtoField.stringz("simpleai.states.attribvalue", "Value")
fields.fieldStaticCharacterId = ProtoField.uint32("simpleai.static.chrid", "Character id")
fields.fieldStaticNodeCount = ProtoField.uint32("simpleai.static.count", "Static node data count")
fields.fieldStaticNodeId = ProtoField.uint32("simpleai.static.id", "Node id")
fields.fieldStaticNodeName = ProtoField.stringz("simpleai.static.name", "Node name")
fields.fieldStaticNodeType = ProtoField.stringz("simpleai.static.type", "Node type")
fields.fieldStaticParameters = ProtoField.stringz("simpleai.static.parameters", "Node parameters")
fields.fieldStaticConditionType = ProtoField.stringz("simpleai.static.conditiontype", "Character type")
fields.fieldStaticConditionParameters = ProtoField.stringz("simpleai.static.conditionparameters", "Condition parameters")
fields.fieldDetailsCharacterId = ProtoField.stringz("simpleai.detail.chrid", "Character id")
fields.fieldDetailsAggroCount = ProtoField.uint16("simpleai.details.aggrocount", "Aggro entries")
fields.fieldDetailsAggroChrId = ProtoField.uint32("simpleai.details.aggrochrid", "Character id")
fields.fieldDetailsAggroAmount = ProtoField.float("simpleai.details.aggroamount", "Aggro amount")
fields.fieldDetailsNodeId = ProtoField.uint32("simpleai.details.id", "Node id")
fields.fieldDetailsNodeCondition = ProtoField.stringz("simpleai.details.condition", "Condition")
fields.fieldDetailsNodeLastRun = ProtoField.int64("simpleai.details.lastrun", "Last run")
fields.fieldDetailsChildrenCount = ProtoField.int64("simpleai.details.childrencount", "Amount of children")
fields.fieldSelectCharacterId = ProtoField.uint32("simpleai.select.chrid", "Character id")
fields.fieldPauseState = ProtoField.bool("simpleai.pause.state", "Pause state")
fields.fieldChangeName = ProtoField.stringz("simpleai.change.name", "Zone name")
fields.fieldStepMillis = ProtoField.int64("simpleai.step.millis", "Milliseconds")
simpleai_table = DissectorTable.get("tcp.port")
simpleai_table:add(default_settings.port, simpleai)
end