From 918dc95bdbd8459630244174f6ed4e4a9a61be78 Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Thu, 11 Aug 2016 23:09:02 -0400 Subject: [PATCH] Extended Web IDE functionality to include Value setting --- Knight.py | 5 ++--- User_Interface.py | 18 +++++++++++++----- wrapper.c | 10 ++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Knight.py b/Knight.py index 6589d7a..27117cf 100755 --- a/Knight.py +++ b/Knight.py @@ -16,13 +16,12 @@ class StringGenerator(object): return "Out of range" if int(value, 16) > 255: return "Too big" - + UI.Set_Memory(int(col)+(int(row) * 16) + UI.Current_Page , int(value, 16)) return UI.returnPage() @cherrypy.expose def Register(self, Reg="", value=0): - index = int(Reg[1:]) - registers = int(value, 16) + UI.Set_Register(int(Reg[1:]), int(value, 16)) return UI.returnPage() @cherrypy.expose diff --git a/User_Interface.py b/User_Interface.py index 03d736a..f79e536 100644 --- a/User_Interface.py +++ b/User_Interface.py @@ -5,6 +5,11 @@ import re subprocess.call("./bin/dis foo | sponge z_disassembled", shell=True) vm = ctypes.CDLL('./libvm.so') +vm.get_memory.argtype = ctypes.c_uint +vm.get_memory.restype = ctypes.c_char_p +vm.step_lilith.restype = ctypes.c_uint +vm.set_register.argtype = (ctypes.c_uint, ctypes.c_uint) +vm.set_memory.argtype = (ctypes.c_uint, ctypes.c_ubyte) def Reset_lilith(): vm.initialize_lilith() @@ -14,19 +19,22 @@ def Reset_lilith(): Watchpoints = {0} vm.load_lilith(ctypes.create_string_buffer("foo".encode('ascii'))) - def Step_lilith(): global Current_IP - vm.step_lilith.restype = ctypes.c_uint Current_IP = vm.step_lilith() return +def Set_Memory(address, value): + vm.set_memory(address, value) + return + +def Set_Register(register, value): + vm.set_register(register, value) + return + def returnPage(): return get_header() + (vm.get_memory(Current_Page)).decode('utf-8') + get_spacer1() + get_registers(0) + get_registers(8) + get_spacer2() + get_disassembled() + get_footer() -vm.get_memory.argtype = ctypes.c_uint -vm.get_memory.restype = ctypes.c_char_p - hexlookup = { 0 : '0', 1 : '1', 2 : '2', 3 : '3', 4 : '4', 5 : '5', 6 : '6', 7 : '7', 8 : '8', 9 : '9', 10 : 'A', 11 : 'B', 12 : 'C', 13 : 'D', 14 : 'E', 15 : 'F' } def formatByte(a): diff --git a/wrapper.c b/wrapper.c index d025683..c1e60b6 100644 --- a/wrapper.c +++ b/wrapper.c @@ -57,6 +57,16 @@ unsigned int get_register(unsigned int reg) return Globalvm->reg[reg]; } +void set_register(unsigned int reg, unsigned int value) +{ + Globalvm->reg[reg] = value; +} + +void set_memory(unsigned int address, unsigned char value) +{ + Globalvm->memory[address] = value; +} + unsigned char get_byte(unsigned int add) { return Globalvm->memory[add];