Skip to content

Commit 4f964a2

Browse files
authored
Fix incorrect operand in disassembled instruction (#2401) (#2403)
Disassembling the "slwi", "srwi" and "rldicr" PowerPC instructions with the "-d" option displays the wrong operands in the detailed view. This is due to an incorrect break condition in the "PPC_insert_detail_op_imm_at" function. This patch fixes #2401.
1 parent 5ba4ca4 commit 4f964a2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

arch/PowerPC/PPCMapping.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ void PPC_insert_detail_op_imm_at(MCInst *MI, unsigned index, int64_t Val,
639639

640640
cs_ppc_op *ops = PPC_get_detail(MI)->operands;
641641
int i = PPC_get_detail(MI)->op_count - 1;
642-
for (; i >= 0; --i) {
642+
for (; i >= index; --i) {
643643
ops[i + 1] = ops[i];
644644
if (i == index)
645645
break;

tests/cs_details/issue.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@
204204
!# CS_ARCH_ARM, CS_MODE_ARM, CS_OPT_DETAIL
205205
0xef,0xf3,0x11,0x85 == ldrhi pc, [r1, #-0x3ef] ; op_count: 2 ; operands[0].type: REG = r15 ; operands[0].access: WRITE ; operands[1].type: MEM ; operands[1].mem.base: REG = r1 ; operands[1].mem.disp: 0x3ef ; operands[1].access: READ ; Code condition: 8 ; Registers read: cpsr r1 ; Registers modified: r15 ; Groups: IsARM jump
206206

207+
!# issue 0 PPC operand groups 0x54,0x22,0xe0,0x06 == slwi r2, r1, 0x1c
208+
!# CS_ARCH_PPC, CS_MODE_32 | CS_MODE_BIG_ENDIAN, CS_OPT_DETAIL
209+
0x54,0x22,0xe0,0x06 == slwi r2, r1, 0x1c ; op_count: 3 ; operands[0].type: REG = r2 ; operands[1].type: REG = r1 ; operands[2].type: IMM = 0x1c
210+
211+
!# issue 0 PPC operand groups 0x54,0x66,0xf0,0xbe == srwi r6, r3, 2
212+
!# CS_ARCH_PPC, CS_MODE_32 | CS_MODE_BIG_ENDIAN, CS_OPT_DETAIL
213+
0x54,0x66,0xf0,0xbe == srwi r6, r3, 2 ; op_count: 3 ; operands[0].type: REG = r6 ; operands[1].type: REG = r3 ; operands[2].type: IMM = 0x2
214+
215+
!# issue 0 PPC operand groups 0x78,0x62,0x26,0xe4 == sldi r2, r3, 4
216+
!# CS_ARCH_PPC, CS_MODE_32 | CS_MODE_BIG_ENDIAN, CS_OPT_DETAIL
217+
0x78,0x62,0x26,0xe4 == sldi r2, r3, 4 ; op_count: 3 ; operands[0].type: REG = r2 ; operands[1].type: REG = r3 ; operands[2].type: IMM = 0x4
218+
207219
!# issue 0 RISCV operand groups 0x37,0x34,0x00,0x00 == lui s0, 3
208220
!# CS_ARCH_RISCV, CS_MODE_RISCV32, CS_OPT_DETAIL
209221
0x37,0x34,0x00,0x00 == lui s0, 3 ; op_count: 2 ; operands[0].type: REG = s0 ; operands[0].access: WRITE ; operands[1].type: IMM = 0x3 ; operands[1].access: READ

0 commit comments

Comments
 (0)