Skip to content

Commit 2e548e5

Browse files
committed
Added support to <value> frame layer in commsdsl2wireshark.
1 parent 94dac36 commit 2e548e5

10 files changed

Lines changed: 274 additions & 91 deletions

app/commsdsl2wireshark/src/WiresharkBundleField.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,23 @@ std::string WiresharkBundleField::wiresharkDissectBodyImpl([[maybe_unused]] cons
130130
}
131131

132132
static const std::string Templ =
133-
"local #^#RANGE#$# = #^#TVB#$#(#^#OFFSET#$#, -1)\n"
133+
"local #^#RANGE#$# = #^#TVB#$#(#^#OFFSET#$#, #^#LIMIT#$# - #^#OFFSET#$#)\n"
134134
"local #^#SUBTREE#$# = #^#TREE#$#:add(#^#FIELD#$#, #^#RANGE#$#)\n"
135135
"#^#MEMBERS#$#\n"
136-
"#^#SUBTREE#$#:set_len(#^#NEXT_OFFSET#$# - #^#OFFSET#$#)\n"
136+
"local members_len = #^#NEXT_OFFSET#$# - #^#OFFSET#$#\n"
137+
"#^#SUBTREE#$#:set_len(members_len)\n"
138+
"if members_len == 0 then"
139+
" #^#SUBTREE#$#:set_hidden(true)\n"
140+
" #^#SUBTREE#$# = #^#TREE#$#:add(#^#FIELD#$#, #^#TVB#$#(#^#OFFSET#$#, 0))\n"
141+
"end\n"
137142
;
138143

139144
util::GenReplacementMap repl = {
140145
{"RANGE", wiresharkRangeStr()},
141146
{"LEN", std::to_string(parseObj.parseMaxLength())},
142147
{"SUBTREE", wiresharkFieldSubtreeStr()},
143148
{"OFFSET", wiresharkOffsetStr()},
149+
{"LIMIT", wiresharkOffsetLimitStr()},
144150
{"NEXT_OFFSET", wiresharkNextOffsetStr()},
145151
{"MEMBERS", util::genStrListToString(members, "\n", "")},
146152
{"FIELD", wiresharkFieldStr()},

app/commsdsl2wireshark/src/WiresharkField.cpp

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,66 @@ std::pair<const WiresharkField*, std::string> WiresharkField::wiresharkSplitMemb
642642
return std::make_pair(*iter, std::move(splitInfo.second));
643643
}
644644

645+
const std::string& WiresharkField::wiresharkRangeStr()
646+
{
647+
static const std::string Str("range");
648+
return Str;
649+
}
650+
651+
const std::string& WiresharkField::wiresharkFieldSubtreeStr()
652+
{
653+
static const std::string Str("field_subtree");
654+
return Str;
655+
}
656+
657+
const std::string& WiresharkField::wiresharkValStr()
658+
{
659+
static const std::string Str("val");
660+
return Str;
661+
}
662+
663+
const std::string& WiresharkField::wiresharkFieldStr()
664+
{
665+
static const std::string Str("field");
666+
return Str;
667+
}
668+
669+
const std::string& WiresharkField::wiresharkNextOffsetStr()
670+
{
671+
static const std::string Str("next_offset");
672+
return Str;
673+
}
674+
675+
const std::string& WiresharkField::wiresharkOffsetStr()
676+
{
677+
static const std::string Str("offset");
678+
return Str;
679+
}
680+
681+
const std::string& WiresharkField::wiresharkOffsetLimitStr()
682+
{
683+
static const std::string Str("offset_limit");
684+
return Str;
685+
}
686+
687+
const std::string& WiresharkField::wiresharkResultStr()
688+
{
689+
static const std::string Str("result");
690+
return Str;
691+
}
692+
693+
const std::string& WiresharkField::wiresharkTvbStr()
694+
{
695+
static const std::string Str("tvb");
696+
return Str;
697+
}
698+
699+
const std::string& WiresharkField::wiresharkTreeStr()
700+
{
701+
static const std::string Str("tree");
702+
return Str;
703+
}
704+
645705
std::string WiresharkField::wiresharkDissectNameImpl(const WiresharkField* refField) const
646706
{
647707
const auto* genField = &m_genField;
@@ -1324,66 +1384,6 @@ const WiresharkInterface& WiresharkField::wiresharkInterface() const
13241384
return *interface;
13251385
}
13261386

1327-
const std::string& WiresharkField::wiresharkRangeStr()
1328-
{
1329-
static const std::string Str("range");
1330-
return Str;
1331-
}
1332-
1333-
const std::string& WiresharkField::wiresharkFieldSubtreeStr()
1334-
{
1335-
static const std::string Str("field_subtree");
1336-
return Str;
1337-
}
1338-
1339-
const std::string& WiresharkField::wiresharkValStr()
1340-
{
1341-
static const std::string Str("val");
1342-
return Str;
1343-
}
1344-
1345-
const std::string& WiresharkField::wiresharkFieldStr()
1346-
{
1347-
static const std::string Str("field");
1348-
return Str;
1349-
}
1350-
1351-
const std::string& WiresharkField::wiresharkNextOffsetStr()
1352-
{
1353-
static const std::string Str("next_offset");
1354-
return Str;
1355-
}
1356-
1357-
const std::string& WiresharkField::wiresharkOffsetStr()
1358-
{
1359-
static const std::string Str("offset");
1360-
return Str;
1361-
}
1362-
1363-
const std::string& WiresharkField::wiresharkOffsetLimitStr()
1364-
{
1365-
static const std::string Str("offset_limit");
1366-
return Str;
1367-
}
1368-
1369-
const std::string& WiresharkField::wiresharkResultStr()
1370-
{
1371-
static const std::string Str("result");
1372-
return Str;
1373-
}
1374-
1375-
const std::string& WiresharkField::wiresharkTvbStr()
1376-
{
1377-
static const std::string Str("tvb");
1378-
return Str;
1379-
}
1380-
1381-
const std::string& WiresharkField::wiresharkTreeStr()
1382-
{
1383-
static const std::string Str("tree");
1384-
return Str;
1385-
}
1386-
13871387
bool WiresharkField::wiresharkCopyCodeFromInternal()
13881388
{
13891389
auto obj = m_genField.genParseObj();

app/commsdsl2wireshark/src/WiresharkField.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ class WiresharkField
9797
static std::pair<std::string, std::string> wiresharkSplitAccStr(const std::string& accStr);
9898
static std::pair<const WiresharkField*, std::string> wiresharkSplitMemberAccStr(const std::string& accStr, const WiresharkFieldsList& fields);
9999

100+
static const std::string& wiresharkRangeStr();
101+
static const std::string& wiresharkFieldSubtreeStr();
102+
static const std::string& wiresharkValStr();
103+
static const std::string& wiresharkFieldStr();
104+
static const std::string& wiresharkNextOffsetStr();
105+
static const std::string& wiresharkOffsetStr();
106+
static const std::string& wiresharkOffsetLimitStr();
107+
static const std::string& wiresharkResultStr();
108+
static const std::string& wiresharkTvbStr();
109+
static const std::string& wiresharkTreeStr();
110+
100111
protected:
101112
virtual std::string wiresharkDissectNameImpl(const WiresharkField* refField) const;
102113
virtual std::string wiresharkValidFuncNameImpl(const WiresharkField* refField) const;
@@ -140,17 +151,6 @@ class WiresharkField
140151
std::string wiresharkProcessFloatValue(const std::string& val) const;
141152
const WiresharkInterface& wiresharkInterface() const;
142153

143-
static const std::string& wiresharkRangeStr();
144-
static const std::string& wiresharkFieldSubtreeStr();
145-
static const std::string& wiresharkValStr();
146-
static const std::string& wiresharkFieldStr();
147-
static const std::string& wiresharkNextOffsetStr();
148-
static const std::string& wiresharkOffsetStr();
149-
static const std::string& wiresharkOffsetLimitStr();
150-
static const std::string& wiresharkResultStr();
151-
static const std::string& wiresharkTvbStr();
152-
static const std::string& wiresharkTreeStr();
153-
154154
private:
155155
using WiresharkCustomCodeFunc = std::string (WiresharkField::*)(bool& hasCode) const;
156156

app/commsdsl2wireshark/src/WiresharkLayer.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bool WiresharkLayer::wiresharkNeedsOptionalModeDefinition() const
137137

138138
std::string WiresharkLayer::wiresharkDissectBodyImpl() const
139139
{
140-
return strings::genEmptyString();
140+
return "-- TODO: implement";
141141
}
142142

143143
bool WiresharkLayer::wiresharkIsInterfaceSupportedImpl([[maybe_unused]] const WiresharkInterface& iFace) const
@@ -159,16 +159,22 @@ std::string WiresharkLayer::wiresharkDissectFieldCode() const
159159
}
160160

161161
static const std::string Templ =
162-
"result, next_offset = #^#NAME#$#(tvb, tree, offset, offset_limit)\n"
163-
"if result ~= #^#SUCCESS#$# then\n"
164-
" return result, next_offset\n"
162+
"#^#RESULT#$#, #^#NEXT_OFFSET#$# = #^#NAME#$#(#^#TVB#$#, #^#TREE#$#, #^#OFFSET#$#, #^#LIMIT#$#)\n"
163+
"if #^#RESULT#$# ~= #^#SUCCESS#$# then\n"
164+
" return #^#RESULT#$#, #^#NEXT_OFFSET#$#\n"
165165
"end\n"
166166
;
167167

168168
auto& wiresharkGenerator = WiresharkGenerator::wiresharkCast(m_genLayer.genGenerator());
169169
util::GenReplacementMap repl = {
170170
{"NAME", field->wiresharkDissectName()},
171171
{"SUCCESS", Wireshark::wiresharkStatusCodeStr(wiresharkGenerator, Wireshark::WiresharkStatusCode::Success)},
172+
{"RESULT", WiresharkField::wiresharkResultStr()},
173+
{"NEXT_OFFSET", WiresharkField::wiresharkNextOffsetStr()},
174+
{"TVB", WiresharkField::wiresharkTvbStr()},
175+
{"TREE", WiresharkField::wiresharkTreeStr()},
176+
{"OFFSET", WiresharkField::wiresharkOffsetStr()},
177+
{"LIMIT", WiresharkField::wiresharkOffsetLimitStr()},
172178
};
173179

174180
return util::genProcessTemplate(Templ, repl);
@@ -181,13 +187,19 @@ std::string WiresharkLayer::wiresharkNextFuncCode() const
181187
"if next_func == #^#NIL#$# then\n"
182188
" return #^#ERROR#$#, offset\n"
183189
"end\n"
184-
"result, next_offset = next_func(tvb, tree, offset, offset_limit, funcs, next_idx + 1, msg)\n"
190+
"#^#RESULT#$#, #^#NEXT_OFFSET#$# = next_func(#^#TVB#$#, #^#TREE#$#, #^#OFFSET#$#, #^#LIMIT#$#, funcs, next_idx + 1, msg)\n"
185191
;
186192

187193
auto& wiresharkGenerator = WiresharkGenerator::wiresharkCast(m_genLayer.genGenerator());
188194
util::GenReplacementMap repl = {
189195
{"NIL", strings::genNilStr()},
190196
{"ERROR", Wireshark::wiresharkStatusCodeStr(wiresharkGenerator, Wireshark::WiresharkStatusCode::CodegenError)},
197+
{"RESULT", WiresharkField::wiresharkResultStr()},
198+
{"NEXT_OFFSET", WiresharkField::wiresharkNextOffsetStr()},
199+
{"TVB", WiresharkField::wiresharkTvbStr()},
200+
{"TREE", WiresharkField::wiresharkTreeStr()},
201+
{"OFFSET", WiresharkField::wiresharkOffsetStr()},
202+
{"LIMIT", WiresharkField::wiresharkOffsetLimitStr()},
191203
};
192204

193205
return util::genProcessTemplate(Templ, repl);

app/commsdsl2wireshark/src/WiresharkListField.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ std::string WiresharkListField::wiresharkDissectBodyImpl([[maybe_unused]] const
178178

179179
static const std::string Templ =
180180
"local count = 0\n"
181-
"local #^#SUBTREE#$# = #^#TREE#$#:add(#^#FIELD#$#, #^#TVB#$#(#^#NEXT_OFFSET#$#, -1))\n"
181+
"local #^#SUBTREE#$# = #^#TREE#$#:add(#^#FIELD#$#, #^#TVB#$#(#^#NEXT_OFFSET#$#, #^#LIMIT#$# - #^#OFFSET#$#))\n"
182182
"#^#READ#$#\n"
183183
"#^#NAME#$#_size_rec_set(#^#FIELD#$#, count)\n"
184184
"#^#SUBTREE#$#:set_len(#^#NEXT_OFFSET#$# - #^#OFFSET#$#)\n"
@@ -190,6 +190,7 @@ std::string WiresharkListField::wiresharkDissectBodyImpl([[maybe_unused]] const
190190
{"TVB", wiresharkTvbStr()},
191191
{"NEXT_OFFSET", wiresharkNextOffsetStr()},
192192
{"OFFSET", wiresharkOffsetStr()},
193+
{"LIMIT", wiresharkOffsetLimitStr()},
193194
{"NAME", wiresharkFieldObjName()},
194195
{"TREE", wiresharkTreeStr()},
195196
};

app/commsdsl2wireshark/src/WiresharkPayloadLayer.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "WiresharkPayloadLayer.h"
1717

1818
#include "Wireshark.h"
19+
#include "WiresharkField.h"
1920
#include "WiresharkGenerator.h"
2021

2122
#include "commsdsl/gen/comms.h"
@@ -39,32 +40,42 @@ std::string WiresharkPayloadLayer::wiresharkDissectBodyImpl() const
3940
{
4041
static const std::string Templ =
4142
"if not msg then\n"
42-
" tree:add_expert_info(PI_MALFORMED, PI_WARN, \"Invalid message id\")\n"
43-
" return #^#SUCCESS#$#, offset_limit\n"
43+
" #^#TREE#$#:add_expert_info(PI_MALFORMED, PI_WARN, \"Invalid message id\")\n"
44+
" return #^#SUCCESS#$#, #^#LIMIT#$#\n"
4445
"end\n"
4546
"\n"
46-
"local result = #^#SUCCESS#$#\n"
47-
"local next_offset = offset_limit\n"
47+
"local #^#RESULT#$# = #^#SUCCESS#$#\n"
48+
"local #^#NEXT_OFFSET#$# = #^#LIMIT#$#\n"
4849
"-- msg is a list of dissect functions\n"
4950
"for _, f in ipairs(msg) do\n"
50-
" local data_subtree = tree:add(#^#FIELD#$#, tvb(offset, offset_limit - offset))\n"
51-
" result, next_offset = f(tvb, data_subtree, offset, offset_limit)\n"
52-
" data_subtree:set_len(next_offset - offset)\n"
53-
" if result == #^#SUCCESS#$# then\n"
54-
" return result, next_offset\n"
51+
" local data_subtree = #^#TREE#$#:add(#^#FIELD#$#, tvb(#^#OFFSET#$#, #^#LIMIT#$# - #^#OFFSET#$#))\n"
52+
" #^#RESULT#$#, #^#NEXT_OFFSET#$# = f(tvb, data_subtree, #^#OFFSET#$#, #^#LIMIT#$#)\n"
53+
" local data_len = #^#NEXT_OFFSET#$# - #^#OFFSET#$#\n"
54+
" data_subtree:set_len(data_len)\n"
55+
" if #^#RESULT#$# == #^#SUCCESS#$# then\n"
56+
" if data_len == 0 then\n"
57+
" data_subtree:set_hidden(true)\n"
58+
" data_subtree = #^#TREE#$#:add(#^#FIELD#$#, tvb(#^#OFFSET#$#, 0))\n"
59+
" end\n"
60+
" return #^#RESULT#$#, #^#NEXT_OFFSET#$#\n"
5561
" end\n"
5662
"\n"
5763
" -- Do not show partially dissected malformed data\n"
5864
" data_subtree:set_hidden(true)\n"
5965
"end\n"
60-
"tree:add_expert_info(PI_MALFORMED, PI_WARN, \"Invalid message data\")\n"
61-
"result, next_offset = #^#SUCCESS#$#, offset_limit\n"
66+
"#^#TREE#$#:add_expert_info(PI_MALFORMED, PI_WARN, \"Invalid message data\")\n"
67+
"#^#RESULT#$#, #^#NEXT_OFFSET#$# = #^#SUCCESS#$#, #^#LIMIT#$#\n"
6268
;
6369

6470
auto& wiresharkGenerator = WiresharkGenerator::wiresharkCast(genGenerator());
6571
util::GenReplacementMap repl = {
6672
{"FIELD", wiresharkDissectFieldNameInternal()},
6773
{"SUCCESS", Wireshark::wiresharkStatusCodeStr(wiresharkGenerator, Wireshark::WiresharkStatusCode::Success)},
74+
{"TREE", WiresharkField::wiresharkTreeStr()},
75+
{"LIMIT", WiresharkField::wiresharkOffsetLimitStr()},
76+
{"RESULT", WiresharkField::wiresharkResultStr()},
77+
{"NEXT_OFFSET", WiresharkField::wiresharkNextOffsetStr()},
78+
{"OFFSET", WiresharkField::wiresharkOffsetStr()},
6879
};
6980

7081
return util::genProcessTemplate(Templ, repl);

0 commit comments

Comments
 (0)