File: openbsd-gen.py

package info (click to toggle)
radare2 0.9.6-3.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 17,496 kB
  • ctags: 45,959
  • sloc: ansic: 240,999; sh: 3,645; makefile: 2,520; python: 1,212; asm: 312; ruby: 214; awk: 209; perl: 188; lisp: 169; java: 23; xml: 17; php: 6
file content (54 lines) | stat: -rw-r--r-- 1,396 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# Auto-generate radare syscall profile for OpenBSD from syscall.h
# (c) Edd Barrett 2011

import sys
import copy

f = open("/usr/include/sys/syscall.h", "r")

rec = { "name" : None, "args" : None }
recs = {}

for line in f:
    if line.startswith("/* syscall:"):
        # extract syscall name
        openq = line.find('"')
        closeq = line.find('"', openq + 1)
        rec["name"] = line[openq+1:closeq]

        # extract number of args
        args = line.find("args:")
        args = args + len("args: ")
        rec["args"] = line[args:].count('"') / 2
    elif line.startswith("#define"):

        if "SYS_MAXSYSCALL" in line:
            continue

        # extract syscall number
        sp = line.split("\t")
        callnum = sp[2].rstrip()

        # check required info is there
        for i in rec:
            if i == None:
                print("missing info for %s" % str(rec))
                sys.exit(1)
            
        recs[int(callnum)] = (copy.copy(rec))
        rec = { "name" : None, "args" : None }
f.close()


out = open("openbsd.c", "w")
out.write("#include \"r_syscall.h\"\n\n/* syscall-openbsd */\n")
out.write("RSyscallItem syscalls_openbsd_x86[] = {\n")

keys = recs.keys()
for call in keys:
    out.write("  { \"%s\", 0x80, %d, %d },\n" % 
            (recs[call]["name"], call, recs[call]["args"]))

out.write("};\n")
out.close()