diff options
| author | Andrew Lamoureux <andrew@vector35.com> | 2019-03-23 23:48:07 -0400 |
|---|---|---|
| committer | Andrew Lamoureux <andrew@vector35.com> | 2019-03-23 23:48:07 -0400 |
| commit | 3bf96e91b8c25d83676501b631a2dabbbc7ce664 (patch) | |
| tree | 9a772f0352e57ea3447cee6b1adc10ae7802bab1 /python/examples | |
| parent | 9a0fd047a92e41507d60575ffecba86637101b0a (diff) | |
kaitai: two-pass on struct fields to entice out "_m_XXX" fields
this should fix issues where program_headers[X] and
section_headers[X] was not getting their start/end range populated
correctly in elf files
Diffstat (limited to 'python/examples')
| -rw-r--r-- | python/examples/kaitai/kshelpers.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/python/examples/kaitai/kshelpers.py b/python/examples/kaitai/kshelpers.py index 1deeef59..283c90d7 100644 --- a/python/examples/kaitai/kshelpers.py +++ b/python/examples/kaitai/kshelpers.py @@ -304,7 +304,10 @@ def buildQtree(ksobj): qwi = KaitaiTreeWidgetItem() qwi.setKaitaiObject(ksobj) - fieldNames = [] + fieldNames = set() + + # first pass: access fields that may be properties, which could compute + # internal results (often '_m_XXX' fields) for candidate in dir(ksobj): if candidate.startswith('_') and (not candidate.startswith('_m_')): continue @@ -312,15 +315,25 @@ def buildQtree(ksobj): continue try: if getattr(ksobj, candidate, False): - fieldNames.append(candidate) + fieldNames.add(candidate) except Exception: pass - for fieldName in fieldNames: - if ('_m_'+fieldName) in fieldNames: - # favor the '_m_' version which seems to get the debug info - continue + # second pass: collect the '_m_XXX' fields which have the debug start/end + # marks, remove the 'XXX' counterpart, if it exists + for candidate in filter(lambda x: x.startswith('_m_'), dir(ksobj)): + try: + if not getattr(ksobj, candidate, False): + continue + fieldNames.add(candidate) + if candidate[3:] in fieldNames: + fieldNames.remove(candidate[3:]) + + except Exception: + pass + + for fieldName in fieldNames: subObj = getattr(ksobj, fieldName) child = None |
