From: gerthmar Date: Thu, 15 Jun 2017 13:51:32 +0000 (+0200) Subject: NULL termination with IAR Embedded Workbench compiler (#146) X-Git-Tag: v0.25~42 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=737f17eb920a7612ff5a7dd3f6c2ce8886727688;p=pyelftools.git NULL termination with IAR Embedded Workbench compiler (#146) * Exectued changes for IAR Embedded Workbench output .elf File * applied review findings --- diff --git a/elftools/dwarf/die.py b/elftools/dwarf/die.py old mode 100644 new mode 100755 index 1b42066..2c04362 --- a/elftools/dwarf/die.py +++ b/elftools/dwarf/die.py @@ -192,6 +192,19 @@ class DIE(object): raw_value=raw_value, offset=attr_offset) + # count and then consume any null termination bytes to avoid wrong die size calculation + zero_term = 0 + with preserve_stream_pos(self.stream): + while True: + b = self.stream.read(1) + if b == 0: + zero_term += 1 + else: + break + if zero_term > 0: + # there was at least one zero termination -> consume all of them + self.stream.read(zero_term) + self.size = self.stream.tell() - self.offset def _translate_attr_value(self, form, raw_value): diff --git a/elftools/dwarf/structs.py b/elftools/dwarf/structs.py index 562cccd..b21bd93 100644 --- a/elftools/dwarf/structs.py +++ b/elftools/dwarf/structs.py @@ -203,7 +203,7 @@ class DWARFStructs(object): DW_FORM_flag_present = StaticField('', 0), DW_FORM_sec_offset = self.Dwarf_offset(''), DW_FORM_exprloc = self._make_block_struct(self.Dwarf_uleb128), - DW_FORM_ref_sig8 = self.Dwarf_offset(''), + DW_FORM_ref_sig8 = self.Dwarf_uint64(''), DW_FORM_GNU_strp_alt=self.Dwarf_offset(''), DW_FORM_GNU_ref_alt=self.Dwarf_offset(''),