Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import itertools
- import subprocess
- import re
- import pprint
- import json
- def ldd(executable):
- p = subprocess.Popen(["ldd", executable], stdout = subprocess.PIPE)
- values = p.stdout.read()
- libs = [i.split("\t")[1] for i in values.split("\n")[:-1]]
- return libs
- def parse(libs):
- pathes = []
- print("\n\n\nLinker defined such shared libraries:")
- for lib in libs:
- print(lib)
- try:
- match = re.search('=>(.*)\(', lib)
- path = match.group(1).strip()
- except Exception, e:
- print("Failed to parse: {0} {1}".format(lib, e))
- else:
- pathes.append(path)
- #print(pathes)
- return pathes
- def dependence(pathes):
- packages = {}
- for path in pathes:
- p = subprocess.Popen(["rpm", "-q", "--whatprovides", path], stdout = subprocess.PIPE)
- package = p.stdout.read().strip()
- if package == "no package provides":
- print("{0} - no such package".format(path))
- packages[path] = package
- return packages
- def packages_only(packages):
- print("\n\n\nList of unique packages:")
- unique = sorted(set(packages.values()))
- pprint.pprint(unique)
- return unique
- if __name__ == "__main__":
- libs = ldd(sys.argv[1])
- pathes = parse(libs)
- packages = dependence(pathes)
- unique = packages_only(packages)
- with open(sys.argv[1].split('/')[-1],"w") as f:
- json.dump(unique, f, indent = 4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement