From d80243fad9fe2a0bb2437a025cb532d3cc82d68e Mon Sep 17 00:00:00 2001 From: waynee95 <32349344+waynee95@users.noreply.github.com> Date: Tue, 8 Aug 2023 00:43:20 +0200 Subject: [PATCH 1/3] Add missing instrs to x86 parser --- interp_x86/parser_x86.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interp_x86/parser_x86.py b/interp_x86/parser_x86.py index ef158e4..3e0c9f1 100644 --- a/interp_x86/parser_x86.py +++ b/interp_x86/parser_x86.py @@ -25,6 +25,9 @@ | "setge" arg -> setge | "movzbq" arg "," arg -> movzbq | "xorq" arg "," arg -> xorq + | "andq" arg "," arg -> andq + | "salq" arg "," arg -> salq + | "sarq" arg "," arg -> sarq | "callq" CNAME -> callq | "callq" "*" arg -> indirect_callq | "pushq" arg -> pushq @@ -81,6 +84,9 @@ | "movzbq" arg "," arg -> movzbq | "xorq" arg "," arg -> xorq | "callq" CNAME -> callq + | "andq" arg "," arg -> andq + | "salq" arg "," arg -> salq + | "sarq" arg "," arg -> sarq | "callq" "*" arg -> indirect_callq | "pushq" arg -> pushq | "popq" arg -> popq From 2827a215cbd485e57757c3d571c0dc7936251368 Mon Sep 17 00:00:00 2001 From: waynee95 <32349344+waynee95@users.noreply.github.com> Date: Tue, 8 Aug 2023 00:46:55 +0200 Subject: [PATCH 2/3] Add missing instrs to eval_x86 --- interp_x86/eval_x86.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/interp_x86/eval_x86.py b/interp_x86/eval_x86.py index a1a9b6a..478ba26 100644 --- a/interp_x86/eval_x86.py +++ b/interp_x86/eval_x86.py @@ -406,6 +406,24 @@ def eval_instrs(self, instrs, blocks, output): self.eval_instrs(blocks[target], blocks, output) return # after jumping, toss continuation + elif instr.data == 'andq': + a1, a2 = instr.children + v1 = self.eval_arg(a1) + v2 = self.eval_arg(a2) + self.store_arg(a2, and64(v1, v2)) + + elif instr.data == 'salq': + a1, a2 = instr.children + v1 = self.eval_arg(a1) + v2 = self.eval_arg(a2) + self.store_arg(a2, v2 << v1) + + elif instr.data == 'sarq': + a1, a2 = instr.children + v1 = self.eval_arg(a1) + v2 = self.eval_arg(a2) + self.store_arg(a2, v2 >> v1) + else: raise RuntimeError(f'Unknown instruction: {instr.data}') From cf013aa4436f69502e3dbf24316ac79d84f202ef Mon Sep 17 00:00:00 2001 From: waynee95 <32349344+waynee95@users.noreply.github.com> Date: Tue, 8 Aug 2023 00:47:59 +0200 Subject: [PATCH 3/3] Add and64 to utils.py --- utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils.py b/utils.py index 8399df4..1fb32d0 100644 --- a/utils.py +++ b/utils.py @@ -1087,6 +1087,9 @@ def neg64(x): def xor64(x,y): return to_signed(x^y) +def and64(x,y): + return to_singed(x&y) + def is_int64(x) -> bool: return isinstance(x,int) and (x >= min_int64 and x <= max_int64)