Created
July 12, 2011 16:14
-
-
Save vext01/1078317 to your computer and use it in GitHub Desktop.
Hacky way to get syscall args from an openbsd syscallargs.h
This file contains hidden or 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 python2.7 | |
import re; | |
def r2_type(typ, name): | |
typ = typ.replace(" ", ""); | |
# anything which is size dependent upon arch is a 'p' | |
if typ.endswith("char*"): | |
return "z" | |
elif typ.endswith("int") and name.endswith("flags"): | |
return "x" | |
elif typ.endswith("sigset_t"): | |
return "x" | |
elif typ.endswith("int"): | |
return "i" | |
elif typ.endswith("long"): | |
return "p" | |
elif typ.endswith("caddr_t"): | |
return "p" | |
elif typ in ["size_t", "off_t"]: | |
return "p" | |
elif typ in ["key_t", "dev_t", "id_t", "mode_t", "uid_t", "gid_t", "clockid_t", "pid_t", \ | |
"socklen_t"]: | |
return "i" | |
elif "*" in typ: | |
return "p" | |
else: | |
return "?" | |
def get_args(): | |
# this is an openbsd syscallargs.h stripped to contain args | |
# structs only | |
sca_h = open("syscallargs.h", "r") | |
skip = 0 | |
arg_tab = {} | |
cur_func = None | |
for line in sca_h: | |
line = line.strip() | |
if len(line) == 0: | |
continue | |
if (line.startswith("struct sys_")): | |
skip = 0 | |
cur_func = re.match("^struct sys_(.*)_args {$", line).group(1) | |
print("Found call: %s" % (cur_func)) | |
arg_tab[cur_func] = "" | |
continue | |
if line.startswith("syscallarg(") and skip == 0: | |
matches = re.match("^syscallarg\((.*)\) (.*);$", line) | |
typ = matches.group(1) | |
name = matches.group(2) | |
print("Found type: %s" % typ) | |
arg_tab[cur_func] = arg_tab[cur_func] + r2_type(typ, name) | |
continue | |
if line.startswith("struct "): | |
skip = 1 | |
sca_h.close() | |
return arg_tab | |
if __name__ == "__main__": | |
for (k, v) in get_args().items(): | |
print("%s(%s)" % (k, v)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment