From 5db2966261e095bf247e6befa86a7af2cda0f1ad Mon Sep 17 00:00:00 2001 From: Yann Rouillard Date: Sat, 11 May 2013 19:00:45 +0200 Subject: [PATCH] add syminfo boundto description function --- elftools/elf/descriptions.py | 10 ++++++++++ elftools/elf/enums.py | 9 +++++++++ elftools/elf/structs.py | 2 +- scripts/elfdump.py | 12 +++--------- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/elftools/elf/descriptions.py b/elftools/elf/descriptions.py index baf4205..2fb7074 100644 --- a/elftools/elf/descriptions.py +++ b/elftools/elf/descriptions.py @@ -100,6 +100,9 @@ def describe_syminfo_flags(x): s += _DESCR_SYMINFO_FLAGS[flag] if (x & flag) else '' return s +def describe_symbol_boundto(x): + return _DESCR_SYMINFO_BOUNDTO.get(x, '%3s' % x) + #------------------------------------------------------------------------------- _unknown = '' @@ -265,6 +268,13 @@ _DESCR_SYMINFO_FLAGS = { SYMINFO_FLAGS.SYMINFO_FLG_DEFERRED: 'P', } +_DESCR_SYMINFO_BOUNDTO = dict( + SYMINFO_BT_SELF='', + SYMINFO_BT_PARENT='', + SYMINFO_BT_NONE='', + SYMINFO_BT_EXTERN='', +) + _DESCR_RELOC_TYPE_i386 = dict( (v, k) for k, v in iteritems(ENUM_RELOC_TYPE_i386)) diff --git a/elftools/elf/enums.py b/elftools/elf/enums.py index aca085f..2c30282 100644 --- a/elftools/elf/enums.py +++ b/elftools/elf/enums.py @@ -447,3 +447,12 @@ ENUM_RELOC_TYPE_x64 = dict( _default_=Pass, ) +# Syminfo Bound To special values +ENUM_SYMINFO_BOUNDTO = dict( + SYMINFO_BT_SELF=0xffff, + SYMINFO_BT_PARENT=0xfffe, + SYMINFO_BT_NONE=0xfffd, + SYMINFO_BT_EXTERN=0xfffc, + _default_=Pass, +) + diff --git a/elftools/elf/structs.py b/elftools/elf/structs.py index 7b9365f..93edd13 100644 --- a/elftools/elf/structs.py +++ b/elftools/elf/structs.py @@ -206,6 +206,6 @@ class ELFStructs(object): def _create_syminfo(self): self.Elf_Syminfo = Struct('Elf_Syminfo', - self.Elf_half('si_boundto'), + Enum(self.Elf_half('si_boundto'), **ENUM_SYMINFO_BOUNDTO), self.Elf_half('si_flags'), ) diff --git a/scripts/elfdump.py b/scripts/elfdump.py index eb149dd..3eb7ffc 100755 --- a/scripts/elfdump.py +++ b/scripts/elfdump.py @@ -35,7 +35,7 @@ from elftools.elf.descriptions import ( describe_sh_type, describe_sh_flags, describe_symbol_type, describe_symbol_bind, describe_symbol_visibility, describe_symbol_shndx, describe_reloc_type, describe_dyn_tag, - describe_syminfo_flags, + describe_syminfo_flags, describe_symbol_boundto, ) from elftools.dwarf.dwarfinfo import DWARFInfo from elftools.dwarf.descriptions import ( @@ -95,14 +95,8 @@ class Elfdump(object): index = '' if syminfo['si_flags'] & SYMINFO_FLAGS.SYMINFO_FLG_CAP: boundto = '' - elif syminfo['si_boundto'] == 0xffff: - boundto = '' - elif syminfo['si_boundto'] == 0xfffe: - boundto = '' - elif syminfo['si_boundto'] == 0xfffc: - boundto = '' - elif syminfo['si_boundto'] == 0xfffd: - boundto = '' + elif not isinstance(syminfo['si_boundto'], int): + boundto = describe_symbol_boundto(syminfo['si_boundto']) else: dyn_tag = dyntable.get_tag(syminfo['si_boundto']) if syminfo['si_flags'] & SYMINFO_FLAGS.SYMINFO_FLG_FILTER: -- 2.30.2