[docs]classELFSymbol(Symbol):""" Represents a symbol for the ELF format. :ivar str binding: The binding of this symbol as an ELF enum string :ivar section: The section associated with this symbol, or None :ivar _subtype: The ELFSymbolType of this symbol """
[docs]def__init__(self,owner,symb):subtype_num=ENUM_ST_INFO_TYPE.get(symb.entry.st_info.type,symb.entry.st_info.type)arch_list=[owner.arch.name,None]if"UNIX"inowner.os:arch_list.insert(1,"gnu")forarchinarch_list:try:self._subtype=ELFSymbolType((subtype_num,arch))exceptValueError:passelse:self._type=self._subtype.to_base_type()breakelse:self._subtype=Noneself._type=SymbolType.TYPE_OTHERsec_ndx,value=symb.entry.st_shndx,symb.entry.st_value# A relocatable object's symbol's value is relative to its section's addr.ifowner.is_relocatableandisinstance(sec_ndx,int):value+=owner.sections[sec_ndx].remap_offsetsuper().__init__(owner,maybedecode(symb.name),AT.from_lva(value,owner).to_rva(),symb.entry.st_size,self.type)self.version=Noneself.binding=symb.entry.st_info.bindself.is_hidden=symb.entry["st_other"]["visibility"]=="STV_HIDDEN"self.section=sec_ndxifnotisinstance(sec_ndx,str)elseNoneself.is_static=self._type==SymbolType.TYPE_SECTIONorsec_ndx=="SHN_ABS"self.is_common=sec_ndx=="SHN_COMMON"self.is_weak=self.binding=="STB_WEAK"self.is_local=self.binding=="STB_LOCAL"self.is_import=sec_ndx=="SHN_UNDEF"andself.bindingin("STB_GLOBAL","STB_WEAK")self.is_export=(self.sectionisnotNoneorself.is_common)andself.bindingin("STB_GLOBAL","STB_WEAK")