From 25267279319573c88af65b7a7edac597b5c3fb7e Mon Sep 17 00:00:00 2001 From: Clement Rouault Date: Wed, 29 Jun 2016 15:07:14 +0200 Subject: [PATCH] Add __mul__ on Instruction + x64 on test_code --- samples/test_code.py | 4 +++- windows/native_exec/simple_x64.py | 8 ++++++++ windows/native_exec/simple_x86.py | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/samples/test_code.py b/samples/test_code.py index abb5810..58a8137 100644 --- a/samples/test_code.py +++ b/samples/test_code.py @@ -85,7 +85,6 @@ class CodeTesteur(dbg.Debugger): exc_code = x.ExceptionRecord.ExceptionCode exc_addr = x.ExceptionRecord.ExceptionAddress if not self.init_breakpoint and exc_code == EXCEPTION_BREAKPOINT: - print("Init breakpoint") self.init_breakpoint = True return ctx = self.current_thread.context @@ -161,6 +160,9 @@ if len(sys.argv) < 2: if sys.argv[1] == "-x64": sys.argv.remove("-x64") test_code_x64() +elif sys.argv[1] == "--raw": + sys.argv.remove("--raw") + pass else: test_code_x86() diff --git a/windows/native_exec/simple_x64.py b/windows/native_exec/simple_x64.py index 33fa3cf..1cbfaf0 100644 --- a/windows/native_exec/simple_x64.py +++ b/windows/native_exec/simple_x64.py @@ -735,6 +735,14 @@ class Instruction(object): prefix_opcode = b"".join(chr(p.PREFIX_VALUE) for p in self.prefix) return prefix_opcode + bytes(self.value.dump()) + def __mul__(self, value): + if not isinstance(value, (int, long)): + return NotImplemented + res = MultipleInstr() + for i in range(value): + res += self + return res + class DelayedJump(object): def __init__(self, type, label): diff --git a/windows/native_exec/simple_x86.py b/windows/native_exec/simple_x86.py index 4275a2d..1060c57 100644 --- a/windows/native_exec/simple_x86.py +++ b/windows/native_exec/simple_x86.py @@ -529,6 +529,20 @@ class Instruction(object): prefix_opcode = b"".join(chr(p.PREFIX_VALUE) for p in self.prefix) return prefix_opcode + bytes(self.value.dump()) + #def __add__(self, other): + # res = MultipleInstr() + # res += self + # res += other + # return res + + def __mul__(self, value): + if not isinstance(value, (int, long)): + return NotImplemented + res = MultipleInstr() + for i in range(value): + res += self + return res + # Jump helpers class DelayedJump(object):