Skip to content

Instantly share code, notes, and snippets.

@Jongy
Last active December 29, 2019 00:14
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/7c8f164be9138bf85545e9baf734abb1 to your computer and use it in GitHub Desktop.
Save Jongy/7c8f164be9138bf85545e9baf734abb1 to your computer and use it in GitHub Desktop.
Print all open()ed files on the system
from kernel_ffi import kprobe, KP_ARGS_WATCH, str as s
from struct_access import partial_struct
filename = partial_struct("filename")
def do_filp_open_hook(dfd, fn): # don't have to receive all args if you don't need
print("do_filp_open: fd {} name {!r}".format(dfd, s(int(filename(fn).name))))
kp = kprobe("do_filp_open", KP_ARGS_WATCH, do_filp_open_hook)
# when you're done:
kp.rm()
# if kp goes out of scope, the gc finalizer will also remove it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment