[Spice-devel] [PATCH 33/33] Handle flags
Frediano Ziglio
fziglio at redhat.com
Wed Jul 1 10:10:25 PDT 2015
Instead of only show the hexadecimal value show all bits.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
python_modules/dissector.py | 77 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 73 insertions(+), 4 deletions(-)
diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 7070c3a..8a15fd1 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -275,10 +275,15 @@ def write_wireshark_field(writer, container, member, t, tree, size, encoding='EN
base = 'BASE_DEC'
f_type = get_primitive_ft_type(t)
if isinstance(t, ptypes.FlagsType):
- # show flag as hexadecimal for now
- base = 'BASE_HEX'
- assert(t.has_name())
- vals = 'VALS(%s_vs)' % codegen.prefix_underscore_lower(t.name)
+ # if the attribute unique_flag is not set must compute
+ # all flags writing a HF for each bit
+ if t.has_attr('unique_flag'):
+ base = 'BASE_HEX'
+ assert(t.has_name())
+ vals = 'VALS(%s_vs)' % codegen.prefix_underscore_lower(t.name)
+ else:
+ write_flags(writer, member, t, tree)
+ return
elif isinstance(t, ptypes.EnumType) or isinstance(t, ptypes.EnumBaseType):
base = 'BASE_DEC'
assert(t.has_name())
@@ -509,6 +514,70 @@ def write_struct(writer, member, t, index, dest, scope):
write_struct_func(writer, t, func_name, index)
writer.assign('offset', '%s(glb, tree%d, offset, %s)' % (func_name, dest.level, index))
+
+def write_flags_func(writer, t, hf_name):
+ func_name = 'dissect_flags_' + t.name
+
+ if writer.is_generated("flags", t.name):
+ return func_name
+ writer.set_is_generated("flags", t.name)
+
+ writer = writer.function_helper()
+ scope = writer.function(func_name, "void", "GlobalInfo *glb _U_, proto_tree *tree _U_, guint32 offset, int hf", True)
+ dest = RootDestination(scope)
+
+ size = t.get_fixed_nw_size()
+
+ fix_attributes(t)
+
+ desc = t.attributes.get('ws_desc', [t.name])[0] # TODO how to handle member ??
+ hf = HF(hf_name, desc)
+ hf.ws_name = '%s_flags' % (t.name.lower())
+ hf.f_type = get_primitive_ft_type(t)
+ hf.base = 'BASE_HEX' # TODO
+ hf.vals = 'NULL'
+ hf.create(writer)
+
+ with writer.if_block('hf >= 0'):
+ writer.variable_def('proto_item *', 'ti')
+ writer.newline()
+ writer.assign('ti', 'proto_tree_add_item(tree, hf, glb->tvb, offset, %d, ENC_LITTLE_ENDIAN)' % size)
+ writer.assign('tree', 'proto_item_add_subtree(ti, %s)' % new_ett(writer))
+
+ values = list(t.names.keys())
+ values.sort()
+ values.reverse()
+ bits = max(values) + 1
+ for v in values:
+ name = hf_name + '_' + t.names[v].lower()
+
+ desc = t.descs[v] if t.descs[v] else t.names[v]
+ hf = HF(name, desc)
+ hf.ws_name = '%s_%s' % (t.name, t.names[v].lower())
+ hf.f_type = 'FT_BOOLEAN'
+ hf.base = str(bits)
+ hf.vals = 'TFS(&tfs_set_notset)'
+ hf.mask = t.c_enumname(v)
+ hf.create(writer)
+
+ writer.statement('proto_tree_add_item(tree, %s, glb->tvb, offset, %d, ENC_LITTLE_ENDIAN)' % (name, size))
+
+ writer.end_block()
+
+ return func_name
+
+
+def write_flags(writer, member, t, tree):
+ # TODO check size
+
+ # TODO if some txt are defined as member use another item, not default ones
+
+ # write a function to dissect the type
+ hf_name = 'hf_%s_flag' % t.name
+ fname = write_flags_func(writer, t, hf_name)
+ writer.statement('%s(glb, %s, offset, %s)' % (fname, tree, hf_name))
+
+
def write_member_primitive(writer, container, member, t, dest, scope):
assert(t.is_primitive())
--
2.1.0
More information about the Spice-devel
mailing list