Skip to content
Open
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
18 changes: 12 additions & 6 deletions arch/X86/X86Mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
case X86_INS_LOOP:
case X86_INS_LOOPE:
case X86_INS_LOOPNE:
// The instruction pointer register follows the mode.
switch (h->mode) {
default:
break;
Expand All @@ -969,24 +970,30 @@ void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
insn->detail->regs_write,
insn->detail->regs_write_count,
X86_REG_EIP, X86_REG_IP);
break;
case CS_MODE_64:
arr_replace(
insn->detail->regs_read,
insn->detail->regs_read_count,
X86_REG_ECX, X86_REG_CX);
X86_REG_EIP, X86_REG_RIP);
arr_replace(
insn->detail->regs_write,
insn->detail->regs_write_count,
X86_REG_ECX, X86_REG_CX);
X86_REG_EIP, X86_REG_RIP);
break;
case CS_MODE_64:
}
// The loop counter register follows the effective address
// size, which a 0x67 address-size prefix can override.
if (insn->detail->x86.addr_size == 2) {
arr_replace(
insn->detail->regs_read,
insn->detail->regs_read_count,
X86_REG_EIP, X86_REG_RIP);
X86_REG_ECX, X86_REG_CX);
arr_replace(
insn->detail->regs_write,
insn->detail->regs_write_count,
X86_REG_EIP, X86_REG_RIP);
X86_REG_ECX, X86_REG_CX);
} else if (insn->detail->x86.addr_size == 8) {
arr_replace(
insn->detail->regs_read,
insn->detail->regs_read_count,
Expand All @@ -995,7 +1002,6 @@ void X86_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
insn->detail->regs_write,
insn->detail->regs_write_count,
X86_REG_ECX, X86_REG_RCX);
break;
}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/details/x86.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6053,8 +6053,8 @@ test_cases:
x86:
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_ADDRSIZE ]
opcode: [ 0xe2, 0x00, 0x00, 0x00 ]
regs_read: [ rip, rcx ]
regs_write: [ rip, rcx ] # BUG: should be ecx
regs_read: [ rip, ecx ]
regs_write: [ rip, ecx ]
-
asm_text: "loope 0x34"
details:
Expand All @@ -6081,8 +6081,8 @@ test_cases:
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_ADDRSIZE ]
opcode: [ 0xe1, 0x00, 0x00, 0x00 ]
eflags: [ X86_EFLAGS_TEST_ZF ]
regs_read: [ rip, rcx, rflags ]
regs_write: [ rip, rcx ] # BUG: should be ecx
regs_read: [ rip, ecx, rflags ]
regs_write: [ rip, ecx ]
-
asm_text: "loopne 0x34"
details:
Expand All @@ -6109,8 +6109,8 @@ test_cases:
prefix: [ X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_0, X86_PREFIX_ADDRSIZE ]
opcode: [ 0xe0, 0x00, 0x00, 0x00 ]
eflags: [ X86_EFLAGS_TEST_ZF ]
regs_read: [ rip, rcx, rflags ]
regs_write: [ rip, rcx ] # BUG: should be ecx
regs_read: [ rip, ecx, rflags ]
regs_write: [ rip, ecx ]

-
input:
Expand Down
Loading