Skip to content

Instantly share code, notes, and snippets.

@steelcowboy
Created June 12, 2018 00:34
Show Gist options
  • Save steelcowboy/a657945a3d293bef382e9b0daa819148 to your computer and use it in GitHub Desktop.
Save steelcowboy/a657945a3d293bef382e9b0daa819148 to your computer and use it in GitHub Desktop.
Get an executable's Arch Linux dependencies
#!/usr/bin/env python3
import sys
import os
import subprocess
def main():
sop = subprocess.PIPE
pkgs = []
binfile = sys.argv[1]
ldd = subprocess.Popen(["ldd", binfile], stdout=sop)
bins = subprocess.Popen(["awk", "{print $3}"], stdin=ldd.stdout, stdout=sop)
outp = bins.communicate()[0]
outp = outp.decode("utf-8")
outp_l = outp.split("\n")
outp_l = [x for x in outp_l if x != '']
for line in outp_l:
pkg_owner = subprocess.Popen(["pacman", "-Qo", line], stdout=sop)
pkg_line = pkg_owner.communicate()[0].decode("utf-8")
pkg_p = pkg_line.split()[4]
pkgs.append(pkg_p)
# Filter dups
pkgs = sorted(list(set(pkgs)))
for p in pkgs:
print(p)
if __name__ == "__main__":
if len(sys.argv) != 2:
prog = os.path.basename(sys.argv[0])
print(f"Usage: {prog} <binary file to analyze>")
print("Find what packages a binary is dependent on")
print("Gets the linked libraries from ldd and uses pacman")
print("to determine which packages provide each file")
sys.exit(1)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment