Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion reccmp/compare/asm/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ def patch_mov_commutative(orig: list[str], recomp: list[str]) -> set[int]:
orig_ops = _split_operands(orig[inst_index])
recomp_ops = _split_operands(recomp[inst_index])

if len(orig_mov_ops) < 2 or len(recomp_mov_ops) < 2:
# We expect these instructions to all have two operands.
if any(
len(operands) != 2
for operands in (orig_mov_ops, recomp_mov_ops, orig_ops, recomp_ops)
):
return set()

# MOV destination must be the same register in both versions.
Expand Down
20 changes: 20 additions & 0 deletions tests/test_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,26 @@ def test_fix_mov_imul_swap_valid():
assert is_effective is True


def test_fix_mov_imul_single_operand_imul():
"""Should not crash with IndexError if single operand IMUL is used.
The desination is presumed to be EAX/AX/AL, so this example could be considered a match.
"""

orig_asm = [
"mov ax, word ptr [ebp - 0x4]",
"imul word ptr [ebp - 0x8]",
]
recomp_asm = [
"mov ax, word ptr [ebp - 0x8]",
"imul word ptr [ebp - 0x4]",
]

diff = difflib.SequenceMatcher(None, orig_asm, recomp_asm)
is_effective = find_effective_match(diff.get_opcodes(), orig_asm, recomp_asm)

assert is_effective is False


def test_fix_mov_add_swap_valid():

orig_asm = [
Expand Down