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
9 changes: 6 additions & 3 deletions dlinject.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,23 @@ def locate_dl_open(process_maps, mod_name):
else:
return fail

if "libc" in mod_name:
if "libc" in mod_name or "libdl" in mod_name:
dl_open_offset = lookup_elf_symbol(mod_path, "dlopen")
elif "ld-linux" in mod_name:
dl_open_offset = lookup_elf_symbol(mod_path, "_dl_open")
else:
return fail


if dl_open_offset is None:
return fail

return (True, mod_base, mod_path, dl_open_offset)


def dlinject(pid, lib_path, stopmethod="sigstop"):
log("searching for dlopen...")
process_maps = f"/proc/{pid}/maps"
for mod in ["libc", "ld-linux"]:
for mod in ["libc", "libdl", "ld-linux"]:
status, mod_base, mod_path, dl_open_offset = locate_dl_open(process_maps, mod)
if status:
mod_name = mod
Expand Down
4 changes: 2 additions & 2 deletions example_prog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ libhello.so: libhello.c
gcc libhello.c -fPIC -shared -o libhello.so

test: test.c
gcc test.c -o test
gcc test.c -ldl -o test

test_threaded: test_threaded.c
gcc test_threaded.c -o test_threaded -lpthread
gcc test_threaded.c -ldl -o test_threaded -lpthread