mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
Updated instruction handlers to use Type and StructuredOperands instead of Mnemonic and Operands
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Or;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for OR r/m32, imm8 (sign-extended) instruction (0x83 /1)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class OrImmToRm32SignExtendedHandler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the OrImmToRm32SignExtendedHandler class
|
||||
/// </summary>
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public OrImmToRm32SignExtendedHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public OrImmToRm32SignExtendedHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class OrImmToRm32SignExtendedHandler : InstructionHandler
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[Decoder.GetPosition()];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte) ((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 1; // 1 = OR
|
||||
@ -44,12 +44,10 @@ public class OrImmToRm32SignExtendedHandler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "or";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Or;
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
if (position >= Length)
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -58,16 +56,23 @@ public class OrImmToRm32SignExtendedHandler : InstructionHandler
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Read the immediate value (sign-extended from 8 to 32 bits)
|
||||
if (position >= Length)
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sign-extend to 32 bits
|
||||
int imm32 = (sbyte) Decoder.ReadByte();
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{destOperand}, 0x{imm32:X8}";
|
||||
sbyte imm8 = (sbyte) Decoder.ReadByte();
|
||||
|
||||
// Create the immediate operand with sign extension
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destOperand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user