Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cle/backends/elf/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1508,8 +1508,7 @@ def __analyze_comments(self, data):
self.compiler = compiler, version

def __register_section_symbols(self, sec_re):
for sym_re in sec_re.iter_symbols():
self.symbols.add(self.get_symbol(sym_re))
self.symbols.update(self.get_symbol(sym_re) for sym_re in sec_re.iter_symbols())

def __relocate_mips(self, symtab):
if "DT_MIPS_BASE_ADDRESS" not in self._dynamic:
Expand Down
17 changes: 4 additions & 13 deletions cle/backends/elf/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cle.address_translator import AT
from cle.backends.symbol import Symbol, SymbolType

from .symbol_type import ELFSymbolType
from .symbol_type import ELFSymbolType, parse_symbol_type


def maybedecode(string):
Expand All @@ -23,20 +23,11 @@ class ELFSymbol(Symbol):

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" in owner.os:
arch_list.insert(1, "gnu")
for arch in arch_list:
try:
self._subtype = ELFSymbolType((subtype_num, arch))
except ValueError:
pass
else:
self._type = self._subtype.to_base_type()
break
arches = (owner.arch.name, "gnu", None)
else:
self._subtype = None
self._type = SymbolType.TYPE_OTHER
arches = (owner.arch.name, None)
self._subtype, self._type = parse_symbol_type(subtype_num, arches)

sec_ndx, value = symb.entry.st_shndx, symb.entry.st_value

Expand Down
13 changes: 13 additions & 0 deletions cle/backends/elf/symbol_type.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from functools import cache

from cle.backends.symbol import SymbolSubType, SymbolType


Expand Down Expand Up @@ -142,3 +144,14 @@ def __ELFSymbolTypeArchParser(cls, value):


setattr(ELFSymbolType, "__new__", __ELFSymbolTypeArchParser)


@cache
def parse_symbol_type(elf_value: int, arches: tuple[str | None, ...]) -> tuple[ELFSymbolType | None, SymbolType]:
for arch in arches:
try:
subtype = ELFSymbolType((elf_value, arch))
except ValueError:
continue
return subtype, subtype.to_base_type()
return None, SymbolType.TYPE_OTHER
Loading