Created
January 2, 2019 16:25
-
-
Save af-inet/47caf5a206dcbdf8fe5b08bb9e731929 to your computer and use it in GitHub Desktop.
find libraries in your ld path (linux)
This file contains hidden or 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
| #!/usr/bin/env python | |
| import os | |
| import os.path | |
| import argparse | |
| DEFAULT_LIBRARY_PATH = "/usr/lib/x86_64-linux-gnu" | |
| LIBRARY_PATH = os.environ.get("LD_LIBRARY_PATH", DEFAULT_LIBRARY_PATH) | |
| def parse_args(): | |
| parser = argparse.ArgumentParser(description='find ld path libraries') | |
| parser.add_argument('name', type=str) | |
| return parser.parse_args() | |
| def find_libraries_by_name(name): | |
| directories = LIBRARY_PATH.split(":") | |
| if len(directories) == 0: | |
| print("no library path(s) found.") | |
| return | |
| for directory_name in LIBRARY_PATH.split(":"): | |
| if not os.path.isdir(directory_name): | |
| print("[!] %s is not a directory" % directory_name) | |
| continue | |
| for root, _, filenames in os.walk(directory_name): | |
| for path in filenames: | |
| full_path = os.path.join(root, path) | |
| if len(path.split(".")) > 1: | |
| if ( | |
| os.path.isfile(full_path) | |
| and not os.path.islink(full_path) | |
| and path[0:3] == "lib" | |
| and path.split(".")[1] == "so" | |
| and name.lower() == path[3:].split(".")[0].lower() | |
| ): | |
| print(full_path) | |
| def main(): | |
| args = parse_args() | |
| find_libraries_by_name(args.name) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment