From 8d5bb5c0325597175e5877f284fb802b2c61d788 Mon Sep 17 00:00:00 2001 From: hakril Date: Mon, 30 Jun 2025 15:48:59 +0200 Subject: [PATCH] Add simplex_86 ljmp with standard parameter format handling for ptr16:32 --- tests/test_simple_x86.py | 4 ++++ windows/native_exec/simple_x86.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/test_simple_x86.py b/tests/test_simple_x86.py index ac56a33b..845f2185 100644 --- a/tests/test_simple_x86.py +++ b/tests/test_simple_x86.py @@ -236,6 +236,10 @@ def test_assembler(): CheckInstr(Jmp)(mem('[EAX]')) CheckInstr(Jmp)(mem('[EAX + 2]')) CheckInstr(Jmp)(mem('[0x12345678]')) + # Ljmp testing + CheckInstr(Ljmp)(0x33, 0x12345678) + CheckInstr(Ljmp, expected_result="ljmp 0x23:0x11223344")("0x23:0x11223344") + assert Ljmp(0x33, 0x12345678).get_code() == Ljmp("0x33:0x12345678").get_code() assert x86.Test(mem('[ECX + 0x100]'), 'ECX').get_code() == x86.Test('ECX', mem('[ECX + 0x100]')).get_code() assert Xchg('EAX', 'ECX').get_code() == Xchg('ECX', 'EAX').get_code() diff --git a/windows/native_exec/simple_x86.py b/windows/native_exec/simple_x86.py index 29df64d9..afb704a5 100644 --- a/windows/native_exec/simple_x86.py +++ b/windows/native_exec/simple_x86.py @@ -400,6 +400,16 @@ def accept_arg(self, args, instr_state): class SegmentSelectorAbsoluteAddr(object): def accept_arg(self, args, instr_state): + # Special case ptr 16:32 + if isinstance(args[0], str) and args[0].count(":") == 1: + imm16, imm32 = [int(x, 0) for x in args[0].split(":")] + sizess, datass = UImm16().accept_arg([imm16], instr_state) + sizeabs, dataabs = Imm32().accept_arg([imm32], instr_state) + if sizess is None or sizeabs is None: + return None, None + # We only consumed 1 args as it was the same string + return (1, dataabs + datass) + sizess, datass = UImm16().accept_arg(args, instr_state) if sizess is None: return None, None @@ -711,6 +721,10 @@ class Jmp(JmpType): (RawBits.from_int(8, 0xff), Slash(4)), (RawBits.from_int(8, 0xea), SegmentSelectorAbsoluteAddr())] +# Allow a second mnemonic for the longjump +class Ljmp(JmpType): + encoding = [(RawBits.from_int(8, 0xea), SegmentSelectorAbsoluteAddr())] + class Jz(JmpType): encoding = [(RawBits.from_int(8, 0x74), JmpImm8(2)),