@@ -289,9 +289,46 @@ std::string WiresharkField::wiresharkTvbRangeAccessImpl() const
289289 return strings::genEmptyString ();
290290}
291291
292+ std::string WiresharkField::wiresharkDissectLengthCheckImpl () const
293+ {
294+ static const std::string Templ =
295+ " #^#MIN#$#\n "
296+ " #^#MAX#$#\n "
297+ ;
298+
299+ static const std::string LenTempl =
300+ " if offset_limit < (offset + #^#LEN#$#) then\n "
301+ " return #^#ERROR#$#, offset\n "
302+ " end\n "
303+ ;
304+
305+ auto & wiresharkGenerator = WiresharkGenerator::wiresharkCast (m_genField.genGenerator ());
306+ util::GenReplacementMap repl = {
307+ {" ERROR" , Wireshark::wiresharkStatusCodeStr (wiresharkGenerator, Wireshark::StatusCode::NotEnoughData)},
308+ };
309+
310+ auto parseObj = m_genField.genParseObj ();
311+ if (0 < parseObj.parseMinLength ()) {
312+ auto minRepl = repl;
313+ minRepl[" LEN" ] = std::to_string (parseObj.parseMinLength ());
314+ repl[" MIN" ] = util::genProcessTemplate (LenTempl, minRepl);
315+ }
316+
317+ if ((parseObj.parseMaxLength () != commsdsl::parse::ParseField::parseMaxPossibleLength ()) &&
318+ (parseObj.parseMaxLength () != parseObj.parseMinLength ())) {
319+ auto maxRepl = repl;
320+ maxRepl[" LEN" ] = std::to_string (parseObj.parseMaxLength ());
321+ repl[" MAX" ] = util::genProcessTemplate (LenTempl, maxRepl);
322+ }
323+
324+ return util::genProcessTemplate (Templ, repl);
325+ }
326+
292327std::string WiresharkField::wiresharkDissectBodyImpl () const
293328{
294- return strings::genEmptyString ();
329+ // TODO
330+ return " -- TODO: not implemented" ;
331+ // return strings::genEmptyString();
295332}
296333
297334std::string WiresharkField::wiresharkFieldRefName (const WiresharkField* refField) const
@@ -520,9 +557,11 @@ std::string WiresharkField::wiresharkDissectBodyInternal(const WiresharkField* r
520557{
521558 static const std::string Templ =
522559 " field = field or #^#FIELD#$#\n "
560+ " #^#LENGTH#$#\n "
523561 " local result = #^#ERROR#$#\n "
524562 " local next_offset = offset\n "
525563 " #^#REST#$#\n "
564+ " #^#VALID#$#\n "
526565 " return result, next_offset\n "
527566 ;
528567
@@ -531,6 +570,8 @@ std::string WiresharkField::wiresharkDissectBodyInternal(const WiresharkField* r
531570 {" FIELD" , wiresharkFieldObjName (refField)},
532571 {" ERROR" , Wireshark::wiresharkStatusCodeStr (wiresharkGenerator, Wireshark::StatusCode::InvalidMsgData)},
533572 {" REST" , wiresharkDissectBodyImpl ()},
573+ {" LENGTH" , wiresharkDissectLengthCheckImpl ()},
574+ {" VALID" , wiresharkDissectValidCheckInternal ()},
534575 };
535576
536577 return util::genProcessTemplate (Templ, repl);
@@ -563,4 +604,15 @@ std::string WiresharkField::wiresharkCustomNameCodeInternal(bool& hasRealCode) c
563604 return wiresharkGenerator.genReadCodeInjectCode (replaceFileName, " Replace name value" , &hasRealCode);
564605}
565606
607+ std::string WiresharkField::wiresharkDissectValidCheckInternal () const
608+ {
609+ auto parseObj = m_genField.genParseObj ();
610+ if (!parseObj.parseIsFailOnInvalid ()) {
611+ return strings::genEmptyString ();
612+ }
613+
614+ // TODO:
615+ return " -- TODO: implement validity check" ;
616+ }
617+
566618} // namespace commsdsl2wireshark
0 commit comments