Skip to content

let's accept reality, and make the Auto Load Libs value False! #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion cle/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Loader:
def __init__(
self,
main_binary: str | BinaryIO | Path | Backend,
auto_load_libs: bool = True,
auto_load_libs: bool = False,
concrete_target=None,
force_load_libs: Iterable[str | BinaryIO | Path] = (),
skip_libs: Iterable[str] = (),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aarch64_relocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_aarch64_relocs():
"""
test_location = str(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "binaries", "tests"))
path = os.path.join(test_location, "aarch64", "aarch64-relocs.o")
loader = cle.Loader(path, main_opts={"base_addr": 0x210120})
loader = cle.Loader(path, main_opts={"base_addr": 0x210120}, auto_load_libs=True)
relocations = loader.main_object.relocs
aarch64_backend = cle.backends.elf.relocation.arm64

Expand Down
2 changes: 1 addition & 1 deletion tests/test_arch_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestArchPcodeDetect(unittest.TestCase):

def test_elf_m68k(self):
binpath = os.path.join(test_location, "m68k/mul_add_sub_xor_m68k_be")
ld = cle.Loader(binpath)
ld = cle.Loader(binpath, auto_load_libs=True)
arch = ld.main_object.arch
assert isinstance(arch, archinfo.ArchPcode)
assert arch.name == "68000:BE:32:default"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_arm_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_empty_segements():
:return:
"""
path = os.path.join(test_location, "armel", "efm32gg.elf")
cle.Loader(path, rebase_granularity=0x1000)
cle.Loader(path, rebase_granularity=0x1000, auto_load_libs=True)
# If we survive this, we're doing OK!


Expand All @@ -30,7 +30,7 @@ def test_thumb_object():
:return:
"""
path = os.path.join(test_location, "armel", "i2c_api.o")
loader = cle.Loader(path, rebase_granularity=0x1000)
loader = cle.Loader(path, rebase_granularity=0x1000, auto_load_libs=True)
for r in loader.main_object.relocs:
if r.__class__ == cle.backends.elf.relocation.arm.R_ARM_THM_JUMP24:
if r.symbol.name == "HAL_I2C_ER_IRQHandler":
Expand Down
2 changes: 2 additions & 0 deletions tests/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_blob_0():
"entry_point": ENTRYPOINT,
"arch": "ARM",
},
auto_load_libs=True,
)

assert ld.main_object.linked_base == BASE_ADDR
Expand Down Expand Up @@ -55,6 +56,7 @@ def test_blob_1():
"arch": "ARM",
"offset": offset,
},
auto_load_libs=True,
)

assert ld.main_object.linked_base == BASE_ADDR
Expand Down
4 changes: 2 additions & 2 deletions tests/test_coff.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestCoff(unittest.TestCase):

def test_x86(self):
exe = os.path.join(TEST_BASE, "tests", "x86", "fauxware.obj")
ld = cle.Loader(exe)
ld = cle.Loader(exe, auto_load_libs=True)
symbol_names = {sym.name for sym in ld.main_object.symbols}
assert "_main" in symbol_names
assert "_accepted" in symbol_names
Expand All @@ -25,7 +25,7 @@ def test_x86(self):

def test_x86_64(self):
exe = os.path.join(TEST_BASE, "tests", "x86_64", "fauxware.obj")
ld = cle.Loader(exe)
ld = cle.Loader(exe, auto_load_libs=True)
symbol_names = {sym.name for sym in ld.main_object.symbols}
assert "main" in symbol_names
assert "accepted" in symbol_names
Expand Down
12 changes: 10 additions & 2 deletions tests/test_elfcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ def test_remote_file_mapping():
"/tmp/foobar/does-not-exist/libc.so.6": f"{get_binary_directory()}/libc.so.6",
"/tmp/foobar/does-not-exist/ld-linux-x86-64.so.2": f"{get_binary_directory()}/ld-linux-x86-64.so.2",
}
ld = cle.Loader(get_coredump_file(), main_opts={"backend": "elfcore", "remote_file_mapping": remote_file_mapping})
ld = cle.Loader(
get_coredump_file(),
main_opts={"backend": "elfcore", "remote_file_mapping": remote_file_mapping},
auto_load_libs=True,
)
check_objects_loaded(ld)


Expand All @@ -39,5 +43,9 @@ def test_remote_file_mapper():
def remote_file_mapper(x):
return x.replace("/tmp/foobar/does-not-exist", directory_for_binaries)

ld = cle.Loader(get_coredump_file(), main_opts={"backend": "elfcore", "remote_file_mapper": remote_file_mapper})
ld = cle.Loader(
get_coredump_file(),
main_opts={"backend": "elfcore", "remote_file_mapper": remote_file_mapper},
auto_load_libs=True,
)
check_objects_loaded(ld)
4 changes: 2 additions & 2 deletions tests/test_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def check_addrs(ld):

def test_info_proc_maps():
mappath = os.path.join(test_location, "../tests_data/test_gdb_plugin/procmap")
ld = cle.Loader(binpath, **cle.convert_info_proc_maps(mappath))
ld = cle.Loader(binpath, **cle.convert_info_proc_maps(mappath), auto_load_libs=True)
check_addrs(ld)


def test_info_sharedlibrary():
mappath = os.path.join(test_location, "../tests_data/test_gdb_plugin/info_sharedlibs")
ld = cle.Loader(binpath, **cle.convert_info_sharedlibrary(mappath))
ld = cle.Loader(binpath, **cle.convert_info_sharedlibrary(mappath), auto_load_libs=True)
check_addrs(ld)


Expand Down
2 changes: 1 addition & 1 deletion tests/test_got.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_ppc(self):
def test_mipsel(self):
ping = os.path.join(self.test_location, "mipsel", "darpa_ping")
skip = ["libgcc_s.so.1", "libresolv.so.0"]
ld = cle.Loader(ping, skip_libs=skip)
ld = cle.Loader(ping, skip_libs=skip, auto_load_libs=True)
dep = set(ld._satisfied_deps)
loadedlibs = set(ld.shared_objects)

Expand Down
6 changes: 4 additions & 2 deletions tests/test_macho_dyld.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def test_fixups():
Tests the pointer format DYLD_CHAINED_PTR_64_OFFSET
:return:
"""
binary: MachO = cast(MachO, cle.Loader(str(TEST_BASE / "tests" / "aarch64" / "dyld_ios15.macho")).main_object)
binary: MachO = cast(
MachO, cle.Loader(str(TEST_BASE / "tests" / "aarch64" / "dyld_ios15.macho"), auto_load_libs=True).main_object
)
expected = {
0x100008100: 0x100007A40,
0x1000081E0: 0x1000072B0,
Expand Down Expand Up @@ -46,7 +48,7 @@ def test_fixups():


def test_symbols():
loader = cle.Loader(str(TEST_BASE / "tests" / "aarch64" / "dyld_ios15.macho"))
loader = cle.Loader(str(TEST_BASE / "tests" / "aarch64" / "dyld_ios15.macho"), auto_load_libs=True)
binary: MachO = cast(MachO, loader.main_object)

expected = [
Expand Down
11 changes: 9 additions & 2 deletions tests/test_macho_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def test_library_15():
:return:
"""

ld = cle.Loader(TEST_BASE / "FrameWorkApp.app_15" / "Frameworks" / "dynamicLibrary.framework" / "dynamicLibrary")
ld = cle.Loader(
TEST_BASE / "FrameWorkApp.app_15" / "Frameworks" / "dynamicLibrary.framework" / "dynamicLibrary",
auto_load_libs=True,
)
lib = ld.main_object
assert isinstance(lib, MachO)
# The base address should be 0 until full rebasing support is implemented
Expand All @@ -30,7 +33,10 @@ def test_library_14():
Test some basics about loading any kind of library
:return:
"""
ld = cle.Loader(TEST_BASE / "FrameWorkApp.app_14" / "Frameworks" / "dynamicLibrary.framework" / "dynamicLibrary")
ld = cle.Loader(
TEST_BASE / "FrameWorkApp.app_14" / "Frameworks" / "dynamicLibrary.framework" / "dynamicLibrary",
auto_load_libs=True,
)
lib = ld.main_object
assert isinstance(lib, MachO)
# The base address should be 0 until full rebasing support is implemented
Expand All @@ -51,6 +57,7 @@ def test_framework_ios15():
force_load_libs=(
TEST_BASE / "FrameWorkApp.app_15" / "Frameworks" / "dynamicLibrary.framework" / "dynamicLibrary",
),
auto_load_libs=True,
)

assert isinstance(ld.main_object, MachO)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_macho_reloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_basic_reloc_functionality():

def test_chained_fixups_relocs():
machofile = os.path.join(TEST_BASE, "tests", "aarch64", "dyld_ios15.macho")
ld = cle.Loader(machofile)
ld = cle.Loader(machofile, auto_load_libs=True)
for reloc in ld.main_object.relocs:
if not isinstance(reloc, MachOPointerRelocation):
continue
Expand Down Expand Up @@ -555,6 +555,7 @@ def test_all_relocs():
ld = cle.Loader(
ONESIGNAL_BASE / "Frameworks" / "OneSignalLocation.framework" / "OneSignalLocation",
main_opts={"base_addr": 0x1_0000_0000},
auto_load_libs=True,
)
lib = ld.main_object
assert isinstance(lib, MachO)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_namedregion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def test_basic_named_region():
bin_path = os.path.join(test_location, "armel", "lwip_udpecho_bm.elf")
loader = Loader(bin_path)
loader = Loader(bin_path, auto_load_libs=True)
# Standard CortexM regions
mmio = NamedRegion("mmio", 0x40000000, 0x50000000)
sys = NamedRegion("sys", 0xE000E000, 0xE0010000)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_patched_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ def test_patched_stream():


def test_malformed_sections():
ld = cle.Loader(os.path.join(tests_path, "i386", "oxfoo1m3"))
ld = cle.Loader(os.path.join(tests_path, "i386", "oxfoo1m3"), auto_load_libs=True)
assert len(ld.main_object.segments) == 1
assert len(ld.main_object.sections) == 0
1 change: 1 addition & 0 deletions tests/test_plt.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def test_plt_full_relro():
ld = cle.Loader(
os.path.join(TESTS_BASE, "tests/i386/full-relro.bin"),
main_opts={"base_addr": 0x400000},
auto_load_libs=True,
)
assert ld.main_object.plt == {"__libc_start_main": 0x400390}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ppc_relocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup():
"""
test_location = str(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "binaries", "tests"))
path = os.path.join(test_location, "ppc", "partial.o")
loader = cle.Loader(path)
loader = cle.Loader(path, auto_load_libs=True)
relocations = loader.main_object.relocs
ppc_backend = cle.backends.elf.relocation.ppc

Expand Down
9 changes: 5 additions & 4 deletions tests/test_relocated.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_relocated():
os.path.dirname(os.path.realpath(__file__)),
"../../binaries/tests/i386/prelinked",
)
ld = cle.Loader(filename, ld_path=[shared], rebase_granularity=0x1000000)
ld = cle.Loader(filename, ld_path=[shared], rebase_granularity=0x1000000, auto_load_libs=True)
assert ld.main_object.mapped_base == 0x8048000
assert [x.mapped_base for x in ld.all_elf_objects] == [
0x8048000,
Expand All @@ -26,7 +26,7 @@ def test_relocated():
def test_first_fit():
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../binaries/tests/x86_64/cfg_0")

ld = cle.Loader(filename)
ld = cle.Loader(filename, auto_load_libs=True)
assert ld.main_object.mapped_base < ld.shared_objects["libc.so.6"].mapped_base
assert ld.shared_objects["libc.so.6"].mapped_base < ld.shared_objects["ld-linux-x86-64.so.2"].mapped_base

Expand All @@ -35,7 +35,7 @@ def test_first_fit():
# <ELF Object ld-linux-x86-64.so.2, maps [0x2000000:0x22241c7]>,
# <ELFTLSObj Object ##cle_tls##, maps [0x3000000:0x3030000]>]

ld = cle.Loader(filename, lib_opts={"libc.so.6": {"base_addr": 0x1234000}})
ld = cle.Loader(filename, lib_opts={"libc.so.6": {"base_addr": 0x1234000}}, auto_load_libs=True)
assert ld.main_object.mapped_base < ld.shared_objects["ld-linux-x86-64.so.2"].mapped_base
assert ld.shared_objects["ld-linux-x86-64.so.2"].mapped_base < ld.shared_objects["libc.so.6"].mapped_base

Expand All @@ -50,6 +50,7 @@ def test_first_fit():
"libc.so.6": {"base_addr": 0x1234000},
"ld-linux-x86-64.so.2": {"base_addr": 0},
},
auto_load_libs=True,
)
assert ld.shared_objects["ld-linux-x86-64.so.2"].mapped_base < ld.main_object.mapped_base
assert ld.main_object.mapped_base < ld.shared_objects["libc.so.6"].mapped_base
Expand All @@ -65,7 +66,7 @@ def test_local_symbol_reloc():
os.path.dirname(os.path.realpath(__file__)),
"../../binaries/tests/armel/btrfs.ko",
)
ld = cle.Loader(filename)
ld = cle.Loader(filename, auto_load_libs=True)

# readelf -r btrfs.ko
# Relocation section '.rel.init.text' at offset 0xfe318 contains 94 entries
Expand Down
2 changes: 1 addition & 1 deletion tests/test_runpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_runpath():

shutil.copy(runpath_file, relocated_file)

loader = cle.Loader(relocated_file, except_missing_libs=True)
loader = cle.Loader(relocated_file, except_missing_libs=True, auto_load_libs=True)
assert loader.all_objects[1].binary in expected_libs
assert loader.all_objects[2].binary in expected_libs
finally:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_simdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_progname():

def test_got_relocation():
filename = os.path.join(test_location, "x86_64", "multiarch_main_main.o")
ld = cle.Loader(filename)
ld = cle.Loader(filename, auto_load_libs=True)

reloc = ld.main_object.relocs[1]
assert reloc.symbol.name == "vex_failure_exit"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_stream():
lib1path = os.path.join(dirpath, "libc.so.6")
lib2path = os.path.join(dirpath, "ld-linux.so.2")

path_ld = cle.Loader(filepath)
path_ld = cle.Loader(filepath, auto_load_libs=True)
stream_ld = cle.Loader(
open(filepath, "rb"),
auto_load_libs=False,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tls_resiliency.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestTlsResiliency(TestCase):
@staticmethod
def test_tls_pe_incorrect_tls_data_start():
p = os.path.join(test_location, "i386", "windows", "2.exe")
path_ld = cle.Loader(p)
path_ld = cle.Loader(p, auto_load_libs=True)
assert path_ld is not None
th = path_ld.tls.new_thread()
assert th is not None
Expand Down
1 change: 1 addition & 0 deletions tests/test_unpackword.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_unpackword():
"arch": "x86",
"offset": 0,
},
auto_load_libs=True,
)

# little endian
Expand Down
Loading