summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2015-07-03 09:13:37 +0100
committerFrediano Ziglio <fziglio@redhat.com>2017-10-03 15:07:50 +0100
commit647c8651b477b173026cb9518a34abedf3426f49 (patch)
treeebfd54cee651cb693774d753ad3cb7bcf32a020e
parentc494b7352811fc103044fc079f4693719927547a (diff)
dissector: Handle pointers
Read the pointer and if not 0 create a function to parse it and call it. Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--python_modules/dissector.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 0456ab8..db5d364 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -358,9 +358,58 @@ def write_array(writer, container, member, nelements, array, dest, scope):
assert(element_type.is_struct())
write_struct(writer, member, element_type, index, dest, scope)
+
+def write_ptr_function(writer, target_type, container, member, dest, scope):
+ nelements = ''
+ if target_type.is_array():
+ parse_function = "parse_array_%s" % target_type.element_type.primitive_type()
+ nelements = ', guint32 nelements'
+ else:
+ parse_function = "parse_struct_%s" % target_type.c_type()
+ if writer.is_generated("parser", parse_function):
+ return '%s(glb, %s, offset)' % (parse_function, dest.level.tree)
+
+ writer.set_is_generated("parser", parse_function)
+
+ writer = writer.function_helper()
+ scope = writer.function(parse_function, "guint32", "GlobalInfo *glb _U_, proto_tree *tree _U_%s, guint32 offset" % nelements, True)
+
+ writer.newline()
+
+ dest = RootDestination(scope)
+ dest.is_helper = True
+ if target_type.is_array():
+ write_array(writer, None, None, "nelements", target_type, dest, scope)
+ else:
+ write_container_parser(writer, target_type, dest)
+
+ writer.statement("return offset")
+
+ writer.end_block()
+
+ return '%s(glb, %s, offset)' % (parse_function, dest.level.tree)
+
+def read_ptr(writer, t):
+ writer.assign('ptr', '%s(glb->tvb, offset)' % primitive_read_func(t))
+ writer.increment('offset', str(t.get_fixed_nw_size()))
+
def write_pointer(writer, container, member, t, dest, scope):
assert(t.is_pointer())
+ if not scope.variable_defined('ptr'):
+ scope.variable_def('guint32', 'ptr')
+ read_ptr(writer, t)
+ with writer.if_block('ptr'):
+ writer.variable_def('guint32', 'save_offset = offset')
+ writer.assign('offset', 'ptr + glb->message_offset')
+ if t.target_type.is_array():
+ nelements = read_array_len(writer, member.name, t.target_type, dest, scope, True)
+ write_array(writer, container, member, nelements, t.target_type, dest, scope)
+ else:
+ stmt = write_ptr_function(writer, t.target_type, container, member, dest, scope)
+ writer.statement(stmt)
+ writer.assign('offset', 'save_offset')
+
def write_struct_func(writer, t, func_name, index):
func_name = 'dissect_spice_struct_' + t.name