Skip to content

How To; Customize Instructions' Mnemonic

Ahmed Garhy edited this page Jan 12, 2019 · 2 revisions

Overview

Often, you might be interested in customizing disassembled instructions' mnemonic. Capstone supports this in a relatively simple way. Let's look at an example:

using Gee.External.Capstone;
using Gee.External.Capstone.Arm;

using (CapstoneArmDisassembler disassembler = CapstoneDisassembler.CreateArmDisassembler(ArmDisassembleMode.Arm)) {
    disassembler.EnableInstructionDetails = true;
    disassembler.DisassembleSyntax = DisassembleSyntax.Intel;

    // ...
    //
    // Just for fun, let's change the mnemonic of the "AND" instruction to "YES". During this lifetime of
    // the disassembler or until we reset the mnemonic to its default value, any such instruction
    // disassembled will have a mnemonic of "YES".
    disassembler.SetInstructionMnemonic(ArmInstructionId.ARM_INS_AND, "YES");

    var binaryCode = new byte[] {0xed, 0x00, 0x00, 0x00};
    ArmInstruction[] instructions = disassembler.Disassemble(binaryCode);

    // ...
    //
    // Let's reset the mnemonic of the "AND" instruction to its default value.
    disassembler.ResetInstructionMnemonic(ArmInstructionId.ARM_INS_AND);
}