Created
February 23, 2022 01:15
-
-
Save Jongy/56f33f4b8a3e04b41d1afb85b47121a1 to your computer and use it in GitHub Desktop.
Required glibc version of a binary
This file contains 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
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