PF_MASKOS=0x00FF0000
PF_MASKPROC=0xFF000000
+
+# symbol info flags for entries
+# in the .SUNW_syminfo section
+class SYMINF0_FLAGS(object):
+ """ Flags for the si_flags field of entries
+ in the .SUNW_syminfo section
+ """
+ SYMINFO_FLG_DIRECT=0x1
+ SYMINFO_FLG_FILTER=0x2
+ SYMINFO_FLG_COPY=0x4
+ SYMINFO_FLG_LAZYLOAD=0x8
+ SYMINFO_FLG_DIRECTBIND=0x10
+ SYMINFO_FLG_NOEXTDIRECT=0x20
+ SYMINFO_FLG_AUXILIARY=0x40
+ SYMINFO_FLG_INTERPOSE=0x80
+ SYMINFO_FLG_CAP=0x100
+ SYMINFO_FLG_DEFERRED=0x200
from .enums import (
ENUM_D_TAG, ENUM_E_VERSION, ENUM_RELOC_TYPE_i386, ENUM_RELOC_TYPE_x64
)
-from .constants import P_FLAGS, SH_FLAGS
+from .constants import P_FLAGS, SH_FLAGS, SYMINF0_FLAGS
from ..common.py3compat import iteritems
return _DESCR_D_TAG.get(x, _unknown)
+def describe_syminfo_flags(x):
+ s = ''
+ for flag in (
+ SYMINF0_FLAGS.SYMINFO_FLG_DIRECT,
+ SYMINF0_FLAGS.SYMINFO_FLG_DIRECTBIND,
+ SYMINF0_FLAGS.SYMINFO_FLG_COPY,
+ SYMINF0_FLAGS.SYMINFO_FLG_LAZYLOAD,
+ SYMINF0_FLAGS.SYMINFO_FLG_NOEXTDIRECT,
+ SYMINF0_FLAGS.SYMINFO_FLG_AUXILIARY,
+ SYMINF0_FLAGS.SYMINFO_FLG_FILTER,
+ SYMINF0_FLAGS.SYMINFO_FLG_INTERPOSE,
+ SYMINF0_FLAGS.SYMINFO_FLG_CAP,
+ SYMINF0_FLAGS.SYMINFO_FLG_DEFERRED):
+ s += _DESCR_SYMINFO_FLAGS[flag] if (x & flag) else ''
+ return s
+
#-------------------------------------------------------------------------------
_unknown = '<unknown>'
SHN_COMMON='COM',
)
+_DESCR_SYMINFO_FLAGS = {
+ SYMINF0_FLAGS.SYMINFO_FLG_DIRECT: 'D',
+ SYMINF0_FLAGS.SYMINFO_FLG_DIRECTBIND: 'B',
+ SYMINF0_FLAGS.SYMINFO_FLG_COPY: 'C',
+ SYMINF0_FLAGS.SYMINFO_FLG_LAZYLOAD: 'L',
+ SYMINF0_FLAGS.SYMINFO_FLG_NOEXTDIRECT: 'N',
+ SYMINF0_FLAGS.SYMINFO_FLG_AUXILIARY: 'A',
+ SYMINF0_FLAGS.SYMINFO_FLG_FILTER: 'F',
+ SYMINF0_FLAGS.SYMINFO_FLG_INTERPOSE: 'I',
+ SYMINF0_FLAGS.SYMINFO_FLG_CAP: 'S',
+ SYMINF0_FLAGS.SYMINFO_FLG_DEFERRED: 'P',
+}
+
_DESCR_RELOC_TYPE_i386 = dict(
(v, k) for k, v in iteritems(ENUM_RELOC_TYPE_i386))
from ..construct import ConstructError
from .structs import ELFStructs
from .sections import (
- Section, StringTableSection, SymbolTableSection, NullSection)
+ Section, StringTableSection, SymbolTableSection,
+ SUNWSyminfoTableSection, NullSection)
from .dynamic import DynamicSection, DynamicSegment
from .relocation import RelocationSection, RelocationHandler
from .segments import Segment, InterpSegment
return NullSection(section_header, name, self.stream)
elif sectype in ('SHT_SYMTAB', 'SHT_DYNSYM'):
return self._make_symbol_table_section(section_header, name)
+ elif sectype == 'SHT_SUNW_syminfo':
+ return self._make_sunwsyminfo_table_section(section_header, name)
elif sectype in ('SHT_REL', 'SHT_RELA'):
return RelocationSection(
section_header, name, self.stream, self)
elffile=self,
stringtable=strtab_section)
+ def _make_sunwsyminfo_table_section(self, section_header, name):
+ """ Create a SymbolTableSection
+ """
+ linked_strtab_index = section_header['sh_link']
+ strtab_section = self.get_section(linked_strtab_index)
+ return SUNWSyminfoTableSection(
+ section_header, name, self.stream,
+ elffile=self,
+ symboltable=strtab_section)
+
def _get_segment_header(self, n):
""" Find the header of segment #n, parse it and return the struct
"""
SHT_LOUSER=0x80000000,
SHT_HIUSER=0xffffffff,
SHT_AMD64_UNWIND=0x70000001,
+ SHT_SUNW_syminfo=0x6ffffffc,
_default_=Pass,
)
return self.entry[name]
+class SUNWSyminfoTableSection(Section):
+ """ ELF .SUNW Syminfo table section.
+ Has an associated SymbolTableSection that's passed in the constructor.
+ """
+ def __init__(self, header, name, stream, elffile, symboltable):
+ super(SUNWSyminfoTableSection, self).__init__(header, name, stream)
+ self.elffile = elffile
+ self.elfstructs = self.elffile.structs
+ self.symboltable = symboltable
+
+ def num_symbols(self):
+ """ Number of symbols in the table
+ """
+ return self['sh_size'] // self['sh_entsize'] - 1
+
+ def get_symbol(self, n):
+ """ Get the symbol at index #n from the table (Symbol object)
+ It begins at 1 and not 0 since the first entry is used to
+ store the current version of the syminfo table
+ """
+ # Grab the symbol's entry from the stream
+ entry_offset = self['sh_offset'] + n * self['sh_entsize']
+ entry = struct_parse(
+ self.elfstructs.Elf_Syminfo,
+ self.stream,
+ stream_pos=entry_offset)
+ # Find the symbol name in the associated symbol table
+ name = self.symboltable.get_symbol(n).name
+ return Symbol(entry, name)
+
+ def iter_symbols(self):
+ """ Yield all the symbols in the table
+ """
+ for i in range(1, self.num_symbols() + 1):
+ yield self.get_symbol(i)
self._create_sym()
self._create_rel()
self._create_dyn()
+ self._create_syminfo()
def _create_ehdr(self):
self.Elf_Ehdr = Struct('Elf_Ehdr',
self.Elf_xword('st_size'),
)
-
-
+ def _create_syminfo(self):
+ self.Elf_Syminfo = Struct('Elf_Syminfo',
+ self.Elf_half('si_boundto'),
+ self.Elf_half('si_flags'),
+ )