0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-08-04 02:16:33 +03:00

Updated instruction handlers to use factory methods instead of directly setting Size property

This commit is contained in:
bird_egop
2025-04-16 01:39:23 +03:00
parent e06ea2beb3
commit d4eb920e2f
10 changed files with 89 additions and 48 deletions

View File

@@ -51,13 +51,23 @@ public class MovMemRegHandler : InstructionHandler
// For MOV r/m32, r32 (0x89) or MOV r/m8, r8 (0x88):
// - The r/m field with mod specifies the destination operand (register or memory)
// - The reg field specifies the source register
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM();
// Adjust the operand size based on the opcode
destinationOperand.Size = operandSize;
// Create the source register operand
var sourceOperand = OperandFactory.CreateRegisterOperand(reg, operandSize);
Operand destinationOperand;
Operand sourceOperand;
if (operandSize == 8)
{
// For 8-bit operands, use the 8-bit ModR/M decoder and factory methods
var (_, reg8, _, destOperand8) = ModRMDecoder.ReadModRM8();
destinationOperand = destOperand8;
sourceOperand = OperandFactory.CreateRegisterOperand8(reg8);
}
else
{
// For 32-bit operands, use the standard ModR/M decoder
var (_, regStd, _, destOperandStd) = ModRMDecoder.ReadModRM();
destinationOperand = destOperandStd;
sourceOperand = OperandFactory.CreateRegisterOperand(regStd, operandSize);
}
// Set the structured operands
instruction.StructuredOperands =

View File

@@ -50,13 +50,23 @@ public class MovRegMemHandler : InstructionHandler
// For MOV r32, r/m32 (0x8B) or MOV r8, r/m8 (0x8A):
// - The reg field specifies the destination register
// - The r/m field with mod specifies the source operand (register or memory)
var (_, reg, _, sourceOperand) = ModRMDecoder.ReadModRM();
// Adjust the operand size based on the opcode
sourceOperand.Size = operandSize;
// Create the destination register operand
var destinationOperand = OperandFactory.CreateRegisterOperand(reg, operandSize);
Operand sourceOperand;
Operand destinationOperand;
if (operandSize == 8)
{
// For 8-bit operands, use the 8-bit ModR/M decoder and factory methods
var (_, reg8, _, srcOperand8) = ModRMDecoder.ReadModRM8();
sourceOperand = srcOperand8;
destinationOperand = OperandFactory.CreateRegisterOperand8(reg8);
}
else
{
// For 32-bit operands, use the standard ModR/M decoder
var (_, regStd, _, srcOperandStd) = ModRMDecoder.ReadModRM();
sourceOperand = srcOperandStd;
destinationOperand = OperandFactory.CreateRegisterOperand(regStd, operandSize);
}
// Set the structured operands
instruction.StructuredOperands =

View File

@@ -47,7 +47,7 @@ public class MovRm8Imm8Handler : InstructionHandler
// For MOV r/m8, imm8 (0xC6):
// - The r/m field with mod specifies the destination operand (register or memory)
// - The immediate value is the source operand
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM();
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM8();
// MOV r/m8, imm8 only uses reg=0
if (reg != 0)
@@ -55,8 +55,7 @@ public class MovRm8Imm8Handler : InstructionHandler
return false;
}
// Adjust the operand size to 8-bit
destinationOperand.Size = 8;
// Note: The operand size is already set to 8-bit by the ReadModRM8 method
// Read the immediate value
if (!Decoder.CanReadByte())