Skip to content
Merged
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
2 changes: 2 additions & 0 deletions cle/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ def find_symbol(self, thing, fuzzy=False) -> Symbol | None:
if so is self._extern_object:
continue
sym = so.get_symbol(thing)
if isinstance(sym, list):
sym = sym[0]
if sym is None:
continue

Expand Down
18 changes: 18 additions & 0 deletions tests/test_macho.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,23 @@ def test_describe_addr():
assert ld.describe_addr(ld.main_object.entry) == "_main+0x0 in fauxware.macho (0x100000de0)"


def test_find_symbol():
machofile = os.path.join(TEST_BASE, "tests", "x86_64", "fauxware.macho")
ld = cle.Loader(machofile, auto_load_libs=False)

# Test finding a user defined symbol
sym = ld.find_symbol("_main")
assert sym is not None
assert sym.name == "_main"
assert sym.rebased_addr == 0x100000DE0

# Test finding an imported symbol
sym = ld.find_symbol("_printf")
assert sym is not None
assert sym.name == "_printf"
assert sym.rebased_addr == 0x100100028


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
test_dummy()
Expand All @@ -230,3 +247,4 @@ def test_describe_addr():
test_find_section_containing()
test_find_region_containing()
test_describe_addr()
test_find_symbol()
Loading