Skip to content

Commit

Permalink
capstone_disassembler: Add support for MIPS (although utested)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKagstrom committed Jul 6, 2024
1 parent 0db880a commit 80e2714
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/disassembly/capstone_disassembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class CapstoneInstruction : public IInstruction
case cs_arch::CS_ARCH_ARM64:
ProcessArm64(insn);
break;
case cs_arch::CS_ARCH_MIPS:
ProcessMips(insn);
break;
default:
break;
}
Expand Down Expand Up @@ -212,6 +215,38 @@ class CapstoneInstruction : public IInstruction
}
}

void ProcessMips(const cs_insn* insn)
{
if (insn->id == mips_insn::MIPS_INS_JAL || insn->id == mips_insn::MIPS_INS_BAL)
{
m_refers_to = IInstruction::Referer {
nullptr, static_cast<uint64_t>(insn->detail->mips.operands[0].imm), nullptr};
}
else if (IsJump(insn) && insn->detail->mips.op_count > 0 &&
insn->detail->mips.operands[0].type == MIPS_OP_IMM)
{
m_refers_to = IInstruction::Referer {
&m_section, static_cast<uint64_t>(insn->detail->mips.operands[0].imm), nullptr};
}

for (auto i = 0u; i < insn->detail->mips.op_count; i++)
{
const auto& op = insn->detail->mips.operands[i];
if (op.type == MIPS_OP_REG)
{
m_used_registers.emplace_back(cs_reg_name(m_handle, op.reg));
}
if (op.type == MIPS_OP_MEM)
{
if (op.mem.base != MIPS_REG_INVALID)
{
m_used_registers.emplace_back(cs_reg_name(m_handle, op.mem.base));
}
}
}
}


bool IsJump(const cs_insn* insn) const
{
return m_type == IInstruction::InstructionType::kBranch;
Expand Down

0 comments on commit 80e2714

Please sign in to comment.