diff --git a/Knight.py b/Knight.py index f8cb61f..5bb7178 100755 --- a/Knight.py +++ b/Knight.py @@ -4,6 +4,7 @@ import array import time import cherrypy import User_Interface as UI +import sys class StringGenerator(object): @cherrypy.expose @@ -38,6 +39,7 @@ class StringGenerator(object): @cherrypy.expose def STOP(self): + print("Stopping after: " + str(UI.Count) + " Instructions" ) return UI.returnPage() @cherrypy.expose @@ -68,9 +70,12 @@ class StringGenerator(object): UI.Step_lilith() while UI.Current_IP not in UI.Watchpoints: UI.Step_lilith() + if UI.Count >= UI.Debug_Point: + break return UI.returnPage() if __name__ == '__main__': + UI.main(sys.argv[1:]) conf = { '/': { 'tools.sessions.on': True, @@ -87,7 +92,6 @@ if __name__ == '__main__': } } - webapp = StringGenerator() webapp.generator = StringGenerator() cherrypy.quickstart(webapp, '/', conf) diff --git a/User_Interface.py b/User_Interface.py index b7bce45..e5576be 100644 --- a/User_Interface.py +++ b/User_Interface.py @@ -1,8 +1,8 @@ import subprocess import ctypes import re +import sys, getopt -subprocess.call("./bin/dis rom | sponge z_disassembled", shell=True) vm = ctypes.CDLL('./libvm.so') vm.get_memory.argtype = ctypes.c_uint @@ -17,7 +17,8 @@ def Reset_lilith(): Current_IP = 0 global Watchpoints Watchpoints = {0} - vm.load_lilith(ctypes.create_string_buffer("rom".encode('ascii'))) + global ROM_Name + vm.load_lilith(ctypes.create_string_buffer(ROM_Name.encode('ascii'))) def Step_lilith(): global Current_IP @@ -171,8 +172,30 @@ def get_footer(): """ +def main(argv): + global Debug_Point + try: + opts, args = getopt.getopt(argv,"R:D:",["ROM=","DEBUG="]) + except getopt.GetoptError: + print ('Knight.py ROM=$NAME DEBUG=$NUMBER\n') + sys.exit(2) + for opt, arg in opts: + if opt == '-h': + print ('Knight.py ROM=$NAME DEBUG=$NUMBER\n') + sys.exit() + elif opt in ("-R", "--ROM"): + global ROM_Name + ROM_Name = arg + elif opt in ("-D", "--DEBUG"): + global Debug_Point + Debug_Point = int(arg) + + subprocess.call("./bin/dis " + ROM_Name + " | sponge z_disassembled", shell=True) + Current_IP = 0 Current_Page = 0 Watchpoints = {0} Count=0 +Debug_Point = 0 +ROM_Name = "rom" Reset_lilith()