summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2015-07-08 10:30:45 +0100
committerFrediano Ziglio <fziglio@redhat.com>2017-10-03 15:07:50 +0100
commit593e703b08bbc81895eaaa6fda1b971b83bd2a85 (patch)
treeda9c9e03182ae99c804b33cdcb98b3163b72acfb
parent647c8651b477b173026cb9518a34abedf3426f49 (diff)
dissector: Introduce a class to handle wireshark attributes
This class will allow to handle wireshark attributes in a simpler way. This as different elements handle attributes in a slightly different way so handle the logic in a single class. Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--python_modules/dissector.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index db5d364..5ccdbbe 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -26,6 +26,43 @@ hf_writer = None
hf_defs = None
+# handle wireshark attributes
+# is quite complex as attributes ca come from
+# member or array
+# - pointers, have their attributes
+# - array, get from member
+# - primitive or structure from array, specific attributes or type
+# - primitive or structure not in array, member or type
+class WSAttributes:
+ def __init__(self, t, other=None):
+ self.add_attrs = other
+ self.attrs = t.attributes
+
+ def _getattr(self, name, default=[None,None]):
+ if self.add_attrs and name in self.add_attrs:
+ return self.add_attrs[name]
+ return self.attrs.get(name, default)
+
+ def __getattr__(self, name):
+ if name == 'name':
+ val = self._getattr('ws')[1]
+ elif name == 'desc':
+ val = self._getattr('ws_desc')[0]
+ if val is None:
+ val = self._getattr('ws')[0]
+ elif name in {'type', 'base'}:
+ val = self._getattr('ws_' + name)[0]
+ elif name in {'txt', 'txt_n'}:
+ val = self._getattr('ws_' + name,None)
+ else:
+ raise AttributeError('Attribute %s not supported' % name)
+ self.__dict__[name] = val
+ return val
+
+ def has_txts(self):
+ return self.txt is not None or self.txt_n is not None
+
+
def write_parser_helpers(writer):
if writer.is_generated("helper", "demarshaller"):
return