Skip to content

Instantly share code, notes, and snippets.

@tangrs
Created August 25, 2012 09:37
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 tangrs/3463006 to your computer and use it in GitHub Desktop.
Save tangrs/3463006 to your computer and use it in GitHub Desktop.
Resolves system calls to their addresses for Ndless
import sys, os
if (len(sys.argv) < 2):
print sys.argv[0],"<syscalls.c>"
quit()
addressList = []
with open(sys.argv[1]) as f:
next(f) # Ignore comment line
next(f) # Ignore type declaration
for line in f:
if ("};" in line): break
addressList.append(line[3:13])
syscallMap = {}
with open(os.path.dirname(sys.argv[1])+"/../include/syscalls.h") as f:
while "// START_OF_LIST" not in f.readline():
pass
while True:
line = f.readline()
if ("// END_OF_LIST" in line): break
components = line.split(" ")
if (len(components) == 3 and int(components[2]) < len(addressList)):
syscallMap[components[1][2:]] = addressList[int(components[2])]
while True:
line = raw_input("lookup> ")
if (line == "/exit"): break
if (line == ""): continue
if (line == "/list"):
for key,symbol in syscallMap.items():
print key,"==>",symbol
else:
try:
addr = syscallMap[line]
print line,"==>",addr
except:
print "Symbol",line,"not found"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment