1515
1616#include " WiresharkFrame.h"
1717
18+ #include " Wireshark.h"
1819#include " WiresharkGenerator.h"
1920#include " WiresharkInterface.h"
2021#include " WiresharkNamespace.h"
@@ -48,6 +49,7 @@ std::string WiresharkFrame::wiresharkDissectCode() const
4849{
4950 static const std::string Templ =
5051 " #^#LAYERS#$#\n "
52+ " #^#FUNC_LIST#$#\n "
5153 " #^#PREPEND#$#\n "
5254 " local function #^#NAME#$##^#SUFFIX#$#(tvb, tree)\n "
5355 " #^#REPLACE#$#\n "
@@ -70,6 +72,7 @@ std::string WiresharkFrame::wiresharkDissectCode() const
7072 {" REPLACE" , wiresharkGenerator.genReadCodeInjectCode (replaceFileName, " Replace this function body" , &replaced)},
7173 {" PREPEND" , wiresharkGenerator.genReadCodeInjectCode (prependFileName, " Prepend here" )},
7274 {" EXTEND" , wiresharkGenerator.genReadCodeInjectCode (extendFileName, " Extend function above" , &extended)},
75+ {" FUNC_LIST" , wiresharkLayerFuncsListInternal ()},
7376 };
7477
7578 if (!replaced) {
@@ -119,8 +122,30 @@ bool WiresharkFrame::genPrepareImpl()
119122
120123std::string WiresharkFrame::wiresharkDissectBodyInternal () const
121124{
122- // TODO:
123- return std::string ();
125+ static const std::string Templ =
126+ " local result = true\n "
127+ " local offset = 0\n "
128+ " local len = tvb:len()\n "
129+ " while result and (offset < len) do\n "
130+ " local frame_subtree = tree:add(#^#PROTO_NAME#$#, tvb(offset, -1), \" #^#FRAME_NAME#$#\" )\n "
131+ " local layer_func = #^#LIST_NAME#$#[1]\n "
132+ " local next_offset = 0\n "
133+ " result, next_offset = layer_func(tvb, frame_subtree, offset, len, #^#LIST_NAME#$#, 2, #^#NIL#$#)\n "
134+ " frame_subtree:set_len(next_offset - offset)\n "
135+ " offset = next_offset\n "
136+ " end\n "
137+ " return result, offset\n "
138+ ;
139+
140+ auto parseObj = genParseObj ();
141+ util::GenReplacementMap repl = {
142+ {" PROTO_NAME" , Wireshark::wiresharkProtocolObjName (WiresharkGenerator::wiresharkCast (genGenerator ()))},
143+ {" FRAME_NAME" , util::genDisplayName (parseObj.parseDisplayName (), parseObj.parseName ())},
144+ {" LIST_NAME" , wiresharkLayerFuncsListNameInternal ()},
145+ {" NIL" , strings::genNilStr ()},
146+ };
147+
148+ return util::genProcessTemplate (Templ, repl);
124149}
125150
126151std::string WiresharkFrame::wiresharkLayersDissectCodeInternal () const
@@ -147,4 +172,31 @@ const WiresharkInterface* WiresharkFrame::wiresharkInterfaceInternal() const
147172 return parentNs->wiresharkInterface ();
148173}
149174
175+ std::string WiresharkFrame::wiresharkLayerFuncsListInternal () const
176+ {
177+ static const std::string Templ =
178+ " local #^#NAME#$# = {\n "
179+ " #^#LAYERS#$#\n "
180+ " }\n "
181+ ;
182+
183+ util::GenStringsList layers;
184+ for (auto * l : m_wiresharkLayers) {
185+ layers.push_back (l->wiresharkDissectName ());
186+ }
187+
188+ util::GenReplacementMap repl = {
189+ {" NAME" , wiresharkLayerFuncsListNameInternal ()},
190+ {" LAYERS" , util::genStrListToString (layers, " ,\n " , " " )},
191+ };
192+
193+ return util::genProcessTemplate (Templ, repl);
194+ }
195+
196+ std::string WiresharkFrame::wiresharkLayerFuncsListNameInternal () const
197+ {
198+ auto & wiresharkGenerator = WiresharkGenerator::wiresharkCast (genGenerator ());
199+ return wiresharkGenerator.wiresharkFuncNameFor (*this , " _layers" );
200+ }
201+
150202} // namespace commsdsl2wireshark
0 commit comments