Skip to content

Commit 9aaf2c6

Browse files
authored
Merge pull request #81 from hakril/ljmpx86
Add simplex_86 ljmp with standard parameter format handling for ptr16:32
2 parents e4ca049 + 8d5bb5c commit 9aaf2c6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

tests/test_simple_x86.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ def test_assembler():
236236
CheckInstr(Jmp)(mem('[EAX]'))
237237
CheckInstr(Jmp)(mem('[EAX + 2]'))
238238
CheckInstr(Jmp)(mem('[0x12345678]'))
239+
# Ljmp testing
240+
CheckInstr(Ljmp)(0x33, 0x12345678)
241+
CheckInstr(Ljmp, expected_result="ljmp 0x23:0x11223344")("0x23:0x11223344")
242+
assert Ljmp(0x33, 0x12345678).get_code() == Ljmp("0x33:0x12345678").get_code()
239243

240244
assert x86.Test(mem('[ECX + 0x100]'), 'ECX').get_code() == x86.Test('ECX', mem('[ECX + 0x100]')).get_code()
241245
assert Xchg('EAX', 'ECX').get_code() == Xchg('ECX', 'EAX').get_code()

windows/native_exec/simple_x86.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,16 @@ def accept_arg(self, args, instr_state):
400400

401401
class SegmentSelectorAbsoluteAddr(object):
402402
def accept_arg(self, args, instr_state):
403+
# Special case ptr 16:32
404+
if isinstance(args[0], str) and args[0].count(":") == 1:
405+
imm16, imm32 = [int(x, 0) for x in args[0].split(":")]
406+
sizess, datass = UImm16().accept_arg([imm16], instr_state)
407+
sizeabs, dataabs = Imm32().accept_arg([imm32], instr_state)
408+
if sizess is None or sizeabs is None:
409+
return None, None
410+
# We only consumed 1 args as it was the same string
411+
return (1, dataabs + datass)
412+
403413
sizess, datass = UImm16().accept_arg(args, instr_state)
404414
if sizess is None:
405415
return None, None
@@ -711,6 +721,10 @@ class Jmp(JmpType):
711721
(RawBits.from_int(8, 0xff), Slash(4)),
712722
(RawBits.from_int(8, 0xea), SegmentSelectorAbsoluteAddr())]
713723

724+
# Allow a second mnemonic for the longjump
725+
class Ljmp(JmpType):
726+
encoding = [(RawBits.from_int(8, 0xea), SegmentSelectorAbsoluteAddr())]
727+
714728

715729
class Jz(JmpType):
716730
encoding = [(RawBits.from_int(8, 0x74), JmpImm8(2)),

0 commit comments

Comments
 (0)