From: Eli Bendersky Date: Thu, 22 Sep 2011 03:37:07 +0000 (+0300) Subject: some fixes in relocation printing. INFO STILL PRINTED ENDIAN-REVERSED -- WTF??? X-Git-Tag: v0.10~101 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7c1ffa6c34ac3553ec3db4d29fff8a8399a4c1d3;p=pyelftools.git some fixes in relocation printing. INFO STILL PRINTED ENDIAN-REVERSED -- WTF??? --- diff --git a/elftools/elf/structs.py b/elftools/elf/structs.py index 8105206..a8d3497 100644 --- a/elftools/elf/structs.py +++ b/elftools/elf/structs.py @@ -11,7 +11,7 @@ from ..construct import ( UBInt8, UBInt16, UBInt32, UBInt64, ULInt8, ULInt16, ULInt32, ULInt64, SBInt32, SLInt32, SBInt64, SLInt64, - Struct, Array, Enum, Padding, BitStruct, BitField, + Struct, Array, Enum, Padding, BitStruct, BitField, Value, ) from .enums import * @@ -148,13 +148,22 @@ class ELFStructs(object): Padding(24), BitField('type', 8)) + # Since the raw value of r_info is also needed, it's being re-computed + # in 'r_info_raw' + r_info_raw = Value('r_info_raw', + lambda ctx: + (ctx['r_info']['sym'] << 8 if self.elfclass == 32 else 32) + + ctx['r_info']['type']) + self.Elf_Rel = Struct('Elf_Rel', self.Elf_addr('r_offset'), r_info_struct, + r_info_raw, ) self.Elf_Rela = Struct('Elf_Rela', self.Elf_addr('r_offset'), r_info_struct, + r_info_raw, self.Elf_sxword('r_addend'), ) diff --git a/scripts/readelf.py b/scripts/readelf.py index eb2c550..46caa11 100755 --- a/scripts/readelf.py +++ b/scripts/readelf.py @@ -276,9 +276,14 @@ class ReadElf(object): has_relocation_sections = True self._emitline("\nRelocation section '%s' at offset %s contains %s entries:" % ( - 1, 2, 3)) + section.name, + self._format_hex(section['sh_offset']), + section.num_relocations())) for rel in section.iter_relocations(): - print rel, rel.entry + self._emitline('%s %s' % ( + self._format_hex(rel['r_offset'], fullhex=True, lead0x=False), + self._format_hex(rel['r_info_raw'], fullhex=True, lead0x=False))) + #print rel, rel.entry if not has_relocation_sections: self._emitline('\nThere are no relocations in this file.')