Created
September 7, 2021 21:13
-
-
Save Jongy/1036a7b4a21546f33905ee7e04bd206e to your computer and use it in GitHub Desktop.
List symbols & their CRCs in a Linux kernel module file
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
#!/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