-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for loading recursively all shared libraries by a library. This is useful if you want to inspect symbol resolution for instance. * add pytest * added some simple unit tests as scaffolding * updated the README
- Loading branch information
Showing
9 changed files
with
126 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import re | ||
from collections import OrderedDict | ||
from typing import Dict | ||
|
||
import lief | ||
from sh import Command # pyright: ignore | ||
|
||
|
||
def libraries(binary: lief.Binary) -> Dict[str, str]: | ||
"""Use the interpreter in a binary to determine the path of each linked library""" | ||
interpreter = Command(binary.interpreter) # pyright: ignore | ||
resolution = interpreter("--list", binary.name) | ||
result = OrderedDict() | ||
# TODO: Figure out why `--list` and `ldd` produce different outcomes | ||
# specifically for the interpreter. | ||
# https://gist.github.com/fzakaria/3dc42a039401598d8e0fdbc57f5e7eae | ||
for line in resolution.splitlines(): # pyright: ignore | ||
m = re.match(r"\s*([^ ]+) => ([^ ]+)", line) | ||
if not m: | ||
continue | ||
soname, lib = m.group(1), m.group(2) | ||
result[soname] = lib | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from sqlelf import ldd | ||
import lief | ||
|
||
def test_simple_binary(): | ||
binary = lief.parse("/bin/ls") | ||
result = ldd.libraries(binary) | ||
print(result) | ||
assert len(result) > 0 |