1515
1616#include " Wireshark.h"
1717
18+ #include " WiresharkFrame.h"
1819#include " WiresharkGenerator.h"
1920#include " WiresharkSchema.h"
2021
@@ -123,13 +124,6 @@ std::string Wireshark::wiresharkDissectFuncInternal() const
123124 const std::string Templ =
124125 " -- Main Dissector Entry Point\n "
125126 " function #^#NAME#$#.dissector(tvb, pinfo, tree)\n "
126- " #^#REPLACE#$#\n "
127- " if tvb:len() == 0 then\n "
128- " return\n "
129- " end\n "
130- " \n "
131- " pinfo.cols.protocol = #^#NAME#$#.name\n "
132- " \n "
133127 " #^#BODY#$#\n "
134128 " end\n "
135129 ;
@@ -140,11 +134,11 @@ std::string Wireshark::wiresharkDissectFuncInternal() const
140134
141135 util::GenReplacementMap repl = {
142136 {" NAME" , wiresharkProtocolObjName (m_wiresharkGenerator)},
143- {" REPLACE " , std::move (replaceCode)},
137+ {" BODY " , std::move (replaceCode)},
144138 };
145139
146140 if (!bodyReplaced) {
147- // TODO: Add frame function
141+ repl[ " BODY " ] = wiresharkDissectFuncBodyInternal ();
148142 }
149143
150144 return util::genProcessTemplate (Templ, repl);
@@ -186,5 +180,56 @@ std::string Wireshark::wiresharkCodeInternal() const
186180 return util::genStrListToString (elems, " \n " , " " );
187181}
188182
183+ std::string Wireshark::wiresharkDissectFuncBodyInternal () const
184+ {
185+ util::GenStringsList elems;
186+ auto frames = m_wiresharkGenerator.genProtocolSchema ().genGetAllFrames ();
187+ for (auto * f : frames) {
188+ assert (f != nullptr );
189+ auto & wiresharkFrame = WiresharkFrame::wiresharkCast (*f);
190+ static const std::string FrameTempl =
191+ " result, next_offset = #^#NAME#$#(tvb, tree)\n "
192+ " if result then\n "
193+ " break\n "
194+ " end\n "
195+ ;
196+
197+ util::GenReplacementMap frameRepl = {
198+ {" NAME" , wiresharkFrame.wiresharkDissectName ()}
199+ };
200+
201+ elems.push_back (util::genProcessTemplate (FrameTempl, frameRepl));
202+ }
203+
204+ const std::string Templ =
205+ " if tvb:len() == 0 then\n "
206+ " return\n "
207+ " end\n "
208+ " \n "
209+ " pinfo.cols.protocol = #^#NAME#$#.name\n "
210+ " \n "
211+ " local result = false\n "
212+ " local next_offset = 0\n "
213+ " repeat\n "
214+ " #^#FRAMES#$#\n "
215+ " until true\n "
216+ " \n "
217+ " if not result then\n "
218+ " return\n "
219+ " end\n "
220+ " \n "
221+ " if next_offset < tvb:len() then\n "
222+ " pinfo.desegment_offset = next_offset\n "
223+ " pinfo.desegment_len = DESEGMENT_ONE_MORE_SEGMENT\n "
224+ " end\n "
225+ ;
226+
227+ util:: GenReplacementMap repl = {
228+ {" FRAMES" , util::genStrListToString (elems, " \n " , " " )}
229+ };
230+
231+ return util::genProcessTemplate (Templ, repl);
232+ }
233+
189234} // namespace commsdsl2wireshark
190235
0 commit comments