x86: use effective address size for the loop counter register - #3025
Open
phverg wants to merge 1 commit into
Open
x86: use effective address size for the loop counter register#3025phverg wants to merge 1 commit into
phverg wants to merge 1 commit into
Conversation
The implicit counter register of loop/loope/loopne (and its regs_read/ regs_write detail) was chosen from the CPU mode alone (CX/ECX/RCX for 16/32/64-bit), ignoring a 0x67 address-size prefix. In 64-bit mode `67 e2 c2` (loop) therefore reported rcx instead of ecx. Select the counter register from the effective address size (insn->detail->x86.addr_size), which the 0x67 prefix already accounts for, while the instruction-pointer register keeps following the mode. Fixes capstone-engine#2823
Collaborator
|
@hainest Would you mind taking a look? |
Rot127
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2823.
The implicit counter register of
loop/loope/loopne(and itsregs_read/regs_writedetail) was selected from the CPU mode alone (CX/ECX/RCX for 16/32/64-bit), ignoring a0x67address-size prefix. The loop counter register is chosen by the effective address size, so67 e2 c2(loop) in 64-bit mode reportedrcxinstead ofecx.This selects the counter register from the effective address size (
insn->detail->x86.addr_size, which the0x67prefix already accounts for), while the instruction-pointer register keeps following the mode.Before:
After:
The fix also corrects the 16-bit and 32-bit cases where
0x67changes the effective address size (16-bit +0x67→ ECX, 32-bit +0x67→ CX). The three affectedtests/details/x86.yamlfixtures (which carried# BUG: should be ecxmarkers) are updated toecx, andcstestpasses (40/40 cases).