Skip to content

Commit

Permalink
Add realpath to resolve symblink links
Browse files Browse the repository at this point in the history
* Resolve symbolic links for the libraries
* Make the list of libraries unique
* Change the prompt to sqlelf>
  • Loading branch information
fzakaria committed Sep 10, 2023
1 parent d4ffd4f commit 96f0c82
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sqlelf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ def start(args=sys.argv[1:], stdin=sys.stdin):
# the binary would load as well.
if args.recursive:
shared_libraries = [ldd.libraries(binary).values() for binary in binaries]
binaries = binaries + [
lief.parse(library) for sub_list in shared_libraries for library in sub_list
]
# We want to readlink on the libraries to resolve symlinks such as libm -> libc
# also make this is a set in the case that multiple binaries use the same
shared_libraries = set(
[
os.path.realpath(library)
for sub_list in shared_libraries
for library in sub_list
]
)
binaries = binaries + [lief.parse(library) for library in shared_libraries]

# forward sqlite logs to logging module
apsw.bestpractice.apply(apsw.bestpractice.recommended)
Expand All @@ -84,6 +91,7 @@ def start(args=sys.argv[1:], stdin=sys.stdin):
instruction.register(connection, binaries)

shell = apsw.shell.Shell(db=connection, stdin=stdin)
shell.command_prompt(["sqlelf> "])

if args.sql:
for sql in args.sql:
Expand Down
5 changes: 5 additions & 0 deletions sqlelf/elf/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def generator() -> Iterator[dict[str, Any]]:
"exported": symbol.exported,
"section": elf_section_name(section_name),
"size": symbol.size,
# TODO(fzakaria): Better understand why is it auxiliary?
# this returns versions like GLIBC_2.2.5
"version": symbol.symbol_version.symbol_version_auxiliary.name
if symbol.symbol_version.symbol_version_auxiliary
else None,
}

return generator
Expand Down

0 comments on commit 96f0c82

Please sign in to comment.