Skip to content

Instantly share code, notes, and snippets.

@Jongy
Created December 17, 2019 17:21
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/30de14fa02474924c70856e030b9b33c to your computer and use it in GitHub Desktop.
Save Jongy/30de14fa02474924c70856e030b9b33c to your computer and use it in GitHub Desktop.
Simple Python implementation of "modinfo"
#!/usr/bin/env python3
import sys
import subprocess
import tempfile
def get_modinfo(module):
with tempfile.NamedTemporaryFile("r") as tf:
subprocess.check_call(["objcopy", "-O", "binary", "--only-section=.modinfo", module, tf.name])
modinfo = tf.read()
return filter(lambda item: len(item) == 2, [item.split('=', 1) for item in modinfo.split('\0')])
def main(argv):
if len(argv) != 2:
print("usage: {} module".format(argv[0]))
modinfo = get_modinfo(argv[1])
for item in modinfo:
type_, value = item
print(type_, "=", value)
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment