Skip to content

Instantly share code, notes, and snippets.

@cocoastorm
Last active August 12, 2019 21:48
Show Gist options
  • Save cocoastorm/9509cb9875e6522b889a7201597098bf to your computer and use it in GitHub Desktop.
Save cocoastorm/9509cb9875e6522b889a7201597098bf to your computer and use it in GitHub Desktop.
Script to Search /usr/lib Files

check.py

Given a needed.txt file with required dependencies, search thorough these given directories for them:

  • /usr/lib
  • /usr/lib32
  • /usr/lib64

Following this stackoverflow post:

objdump -p /path/to/binary/here | grep NEEDED | awk '{ print $2 }' > needed.txt
#!/usr/bin/env python
import os
def list_libs():
libs = []
lib_paths = ['/usr/lib', '/usr/lib32', '/usr/lib64']
for lib_path in lib_paths:
for root, dirs, files in os.walk(lib_path):
for name in files:
#filepath = os.path.join(root, name)
libs.append(name)
return libs
def read_file():
deps = []
with open('needed.txt') as f:
for line in f:
dep = line.strip()
deps.append(dep)
return deps
def check():
needed = []
have = []
libs = list_libs()
deps = read_file()
for dep in deps:
if dep in libs:
have.append(dep)
else:
needed.append(dep)
print("HAVE:")
for a in have:
print(a)
print()
print("NEED:")
for req in needed:
print(req)
return needed
check()
libnode.so
libpthread.so.0
libgtk-x11-2.0.so.0
libgdk-x11-2.0.so.0
libpangocairo-1.0.so.0
libatk-1.0.so.0
libcairo.so.2
libgdk_pixbuf-2.0.so.0
libgio-2.0.so.0
libpango-1.0.so.0
libgobject-2.0.so.0
libfontconfig.so.1
libfreetype.so.6
libdbus-1.so.3
libX11-xcb.so.1
libxcb.so.1
libXi.so.6
libXcursor.so.1
libXdamage.so.1
libXrandr.so.2
libXcomposite.so.1
libXext.so.6
libXfixes.so.3
libXrender.so.1
libX11.so.6
libXtst.so.6
libXss.so.1
libgconf-2.so.4
libgmodule-2.0.so.0
libglib-2.0.so.0
libnss3.so
libnssutil3.so
libsmime3.so
libnspr4.so
libffmpeg.so
libasound.so.2
libcups.so.2
librt.so.1
libdl.so.2
libexpat.so.1
libstdc++.so.6
libm.so.6
libgcc_s.so.1
libc.so.6
ld-linux-x86-64.so.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment