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,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Sub;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class SubImmFromRm16Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SubImmFromRm16Handler 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 SubImmFromRm16Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public SubImmFromRm16Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class SubImmFromRm16Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Check if the reg field is 5 (SUB)
|
||||
byte modRM = CodeBuffer[Decoder.GetPosition()];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 5; // 5 = SUB
|
||||
@ -50,8 +50,8 @@ public class SubImmFromRm16Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "sub";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Sub;
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -59,15 +59,14 @@ public class SubImmFromRm16Handler : InstructionHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
// Extract the fields from the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
// Read the ModR/M byte
|
||||
// For SUB r/m16, imm16 (0x81 /5 with 0x66 prefix):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The immediate value is the source operand
|
||||
var (mod, reg, rm, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// For memory operands, replace "dword" with "word"
|
||||
string destination = destOperand;
|
||||
if (mod != 3) // Memory operand
|
||||
{
|
||||
destination = destOperand.Replace("dword", "word");
|
||||
}
|
||||
// Adjust the operand size to 16-bit
|
||||
destinationOperand.Size = 16;
|
||||
|
||||
// Check if we have enough bytes for the immediate value
|
||||
if (!Decoder.CanReadUShort())
|
||||
@ -78,8 +77,15 @@ public class SubImmFromRm16Handler : InstructionHandler
|
||||
// Read the immediate value (16-bit)
|
||||
ushort immediate = Decoder.ReadUInt16();
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{destination}, 0x{immediate:X4}";
|
||||
// Create the source immediate operand
|
||||
var sourceOperand = OperandFactory.CreateImmediateOperand(immediate, 16);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user