Created
March 25, 2018 13:08
-
-
Save Ddorda/4fc00de9545bfa080f6ead8a680e432a to your computer and use it in GitHub Desktop.
Get Syscalls numbers dynamically from header files
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
UNISTD_PATH = '/usr/include/x86_64-linux-gnu/asm/unistd_64.h' | |
def get_syscall_numbers(unistd_path=UNISTD_PATH): | |
d = {} | |
with open(unistd_path, 'r') as f: | |
for line in f.readlines(): | |
if line.startswith('#define __NR_'): | |
try: | |
syscall_data = line.strip().split() | |
d[syscall_data[1].replace('__NR_', '')] = int(syscall_data[2]) | |
except: | |
pass | |
return d | |
SYSCALLS = get_syscall_numbers() | |
print SYSCALLS['perf_event_open'] | |
# can be used with: | |
# import ctypes | |
# libc = ctypes.CDLL(None) | |
# syscall = libc.syscall | |
# syscal(SYSCALLS['perf_event_open'], ....) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment