Skip to content

Instantly share code, notes, and snippets.

@Jongy
Created September 7, 2021 21:13
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/1036a7b4a21546f33905ee7e04bd206e to your computer and use it in GitHub Desktop.
Save Jongy/1036a7b4a21546f33905ee7e04bd206e to your computer and use it in GitHub Desktop.
List symbols & their CRCs in a Linux kernel module file
#!/usr/bin/env python3
import sys
import subprocess
import tempfile
import struct
def get_modversions(module):
with tempfile.NamedTemporaryFile("rb") as tf:
subprocess.check_call(["objcopy", "-O", "binary", "--only-section=__versions", module, tf.name])
versions = tf.read()
for b in [versions[i:i+64] for i in range(0, len(versions), 64)]:
# struct modversion_info
crc, sym = struct.unpack("L56s", b)
yield sym.rstrip(b'\x00').decode(), crc
def main(argv):
if len(argv) != 2:
print("usage: {} module".format(argv[0]))
for symbol, crc in get_modversions(argv[1]):
print("{:30s} 0x{:08x}".format(symbol, crc))
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment