Skip to content

Commit

Permalink
Fix #2233
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Feb 6, 2024
1 parent cb2b879 commit ada0a0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions arch/ARM/ARMMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,27 @@ static void check_pop_return(MCInst *MI) {
}
}

/// Check if PC is directly written.Those instructions
/// are considered of group BRANCH.
static void check_writes_to_pc(MCInst *MI) {
if (!MI->flat_insn->detail)
return;
for (size_t i = 0; i < ARM_get_detail(MI)->op_count; ++i) {
cs_arm_op *op = &ARM_get_detail(MI)->operands[i];
if (op->type == ARM_OP_REG && op->reg == ARM_REG_PC && (op->access & CS_AC_WRITE)) {
add_group(MI, ARM_GRP_JUMP);
return;
}
}
}

/// Adds group to the instruction which are not defined in LLVM.
static void ARM_add_cs_groups(MCInst *MI)
{
if (!MI->flat_insn->detail)
return;
check_pop_return(MI);
check_writes_to_pc(MI);
unsigned Opcode = MI->flat_insn->id;
switch (Opcode) {
default:
Expand Down
3 changes: 3 additions & 0 deletions suite/cstest/issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,3 +1047,6 @@
!# CS_ARCH_AARCH64, CS_MODE_ARM, None
0x0: 0x00,0x00,0x00,0x4c == st4 { v0.16b, v1.16b, v2.16b, v3.16b }, [x0]

!# issue 2233 ARM write to PC is branch
!# CS_ARCH_ARM, CS_MODE_THUMB, CS_OPT_DETAIL
0x87,0x46 == mov pc, r0 ; Groups: IsThumb jump

0 comments on commit ada0a0a

Please sign in to comment.