From 53d45414f84c05d88b24824b28c9ce5f4a575556 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Wed, 16 Dec 2015 02:09:04 +0100 Subject: [PATCH] Added minor functionality, --- infernal.py | 12 +++++++++--- tests/test_fib.py | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/infernal.py b/infernal.py index 11f20ec..17094b5 100644 --- a/infernal.py +++ b/infernal.py @@ -96,11 +96,17 @@ class Emulator: for line in iter(source_text.splitlines()): index = self.processSourceLine(line, index) - def setStack (self, *stack_list): - i = 0 + def setStack (self, *stack_list, **kwargs): + """ + Sets various stack elements, starting from 0 and going up. + Automatically sets rsp. This can be disabled by passing set_rsp=False. + """ + i = -1 for element in stack_list: - self.stack[i] = element i += 1 + self.stack[i] = element + if (not 'set_rsp' in kwargs) or kwargs['set_rsp']: + self.setRegs(rsp=i) def setRegs (self, **reg_dict): for reg_name, reg_val in reg_dict.iteritems(): diff --git a/tests/test_fib.py b/tests/test_fib.py index bfaf14e..041588e 100644 --- a/tests/test_fib.py +++ b/tests/test_fib.py @@ -60,10 +60,10 @@ if __name__ == "__main__": printf("Running for fib({})", a) # Setup - emu = infernal.Emulator(fib_prog) + emu = infernal.Emulator(fib_prog) #infernal.Emulator(fib_iter_prog) painter = infernal.TikzPainter() - emu.setStack("junk...","calling eip") - emu.setRegs( rip = 0, rbp = 'old bp', rsp = 1, rdi = a ) + emu.setStack("junk...", "calling eip") + emu.setRegs( rip = 0, rbp = 'old bp', rdi = a ) painter.drawState(emu) for line_nr in emu: