Created
August 25, 2012 09:37
-
-
Save tangrs/3463006 to your computer and use it in GitHub Desktop.
Resolves system calls to their addresses for Ndless
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
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