Skip to content

Instantly share code, notes, and snippets.

@Jongy
Created February 23, 2022 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jongy/56f33f4b8a3e04b41d1afb85b47121a1 to your computer and use it in GitHub Desktop.
Save Jongy/56f33f4b8a3e04b41d1afb85b47121a1 to your computer and use it in GitHub Desktop.
Required glibc version of a binary
import subprocess
import sys
from packaging.version import Version
def main(argv):
if len(argv) != 2:
print(f"usage: {argv[0]} <elf>")
sys.exit(1)
try:
res = subprocess.run(f"set -eu; objdump -T {argv[1]} | awk '{{print $5}}' | grep GLIBC | sort -u", shell=True, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
print(e.stdout)
print(e.stderr)
raise
glibc_ver = []
glibcxx_ver = []
for version in res.stdout.splitlines():
if version.startswith("GLIBCXX_"):
glibcxx_ver.append(Version(version[len("GLIBCXX_"):]))
elif version.startswith("GLIBC_"):
glibc_ver.append(Version(version[len("GLIBC_"):]))
else:
raise ValueError(f"unexpected version: {version}")
print("glibc version:", max(glibc_ver))
print("glibcxx version:", max(glibcxx_ver))
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment