using X86Disassembler.X86.Operands; namespace X86Disassembler.X86.Handlers.Lea; /// /// Handler for LEA r32, m instruction (0x8D) /// public class LeaR32MHandler : InstructionHandler { /// /// Initializes a new instance of the LeaR32MHandler class /// /// The instruction decoder that owns this handler public LeaR32MHandler(InstructionDecoder decoder) : base(decoder) { } /// /// Checks if this handler can decode the given opcode /// /// The opcode to check /// True if this handler can decode the opcode public override bool CanHandle(byte opcode) { return opcode == 0x8D; } /// /// Decodes a LEA r32, m instruction /// /// The opcode of the instruction /// The instruction object to populate /// True if the instruction was successfully decoded public override bool Decode(byte opcode, Instruction instruction) { // Check if we have enough bytes for the ModR/M byte if (!Decoder.CanReadByte()) { return false; } // Read the ModR/M byte var (mod, reg, rm, sourceOperand) = ModRMDecoder.ReadModRM(); // LEA only works with memory operands, not registers if (mod == 3) { return false; } // Set the instruction type instruction.Type = InstructionType.Lea; // Create the destination register operand var destinationOperand = OperandFactory.CreateRegisterOperand((RegisterIndex)reg, 32); // For LEA, we don't care about the size of the memory operand // as we're only interested in the effective address calculation // Set the structured operands instruction.StructuredOperands = [ destinationOperand, sourceOperand ]; return true; } }