2025-04-14 22:08:50 +03:00
|
|
|
using X86Disassembler.X86.Operands;
|
|
|
|
|
2025-04-13 04:07:37 +03:00
|
|
|
namespace X86Disassembler.X86.Handlers.And;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Handler for AND EAX, imm32 instruction (0x25)
|
|
|
|
/// </summary>
|
|
|
|
public class AndEaxImmHandler : InstructionHandler
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the AndEaxImmHandler class
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
2025-04-14 22:08:50 +03:00
|
|
|
public AndEaxImmHandler(InstructionDecoder decoder)
|
|
|
|
: base(decoder)
|
2025-04-13 04:07:37 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if this handler can decode the given opcode
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="opcode">The opcode to check</param>
|
|
|
|
/// <returns>True if this handler can decode the opcode</returns>
|
|
|
|
public override bool CanHandle(byte opcode)
|
|
|
|
{
|
|
|
|
return opcode == 0x25;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Decodes an AND EAX, imm32 instruction
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="opcode">The opcode of the instruction</param>
|
|
|
|
/// <param name="instruction">The instruction object to populate</param>
|
|
|
|
/// <returns>True if the instruction was successfully decoded</returns>
|
|
|
|
public override bool Decode(byte opcode, Instruction instruction)
|
|
|
|
{
|
2025-04-14 22:08:50 +03:00
|
|
|
// Set the instruction type
|
|
|
|
instruction.Type = InstructionType.And;
|
|
|
|
|
|
|
|
// Create the destination register operand (EAX)
|
|
|
|
var destinationOperand = OperandFactory.CreateRegisterOperand(RegisterIndex.A, 32);
|
2025-04-14 01:08:14 +03:00
|
|
|
|
2025-04-13 04:07:37 +03:00
|
|
|
// Read immediate value
|
2025-04-14 01:08:14 +03:00
|
|
|
if (!Decoder.CanReadUInt())
|
2025-04-13 04:07:37 +03:00
|
|
|
{
|
2025-04-14 22:08:50 +03:00
|
|
|
return false;
|
2025-04-13 04:07:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read immediate value
|
|
|
|
uint imm32 = Decoder.ReadUInt32();
|
|
|
|
|
2025-04-14 22:08:50 +03:00
|
|
|
// Create the source immediate operand
|
|
|
|
var sourceOperand = OperandFactory.CreateImmediateOperand(imm32, 32);
|
|
|
|
|
|
|
|
// Set the structured operands
|
|
|
|
instruction.StructuredOperands =
|
|
|
|
[
|
|
|
|
destinationOperand,
|
|
|
|
sourceOperand
|
|
|
|
];
|
2025-04-13 04:07:37 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|