0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-20 08:18:36 +03:00

more refactoring

This commit is contained in:
bird_egop
2025-04-14 01:08:14 +03:00
parent f54dc10596
commit 99b93523a4
78 changed files with 379 additions and 594 deletions

View File

@ -37,9 +37,7 @@ public class XorAlImmHandler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}

View File

@ -37,10 +37,8 @@ public class XorAxImm16Handler : InstructionHandler
{
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position + 1 >= Length)
if (!Decoder.CanReadUShort())
{
return false;
}

View File

@ -37,9 +37,7 @@ public class XorEaxImmHandler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position + 4 > Length)
if (!Decoder.CanReadUInt())
{
return false;
}

View File

@ -27,11 +27,10 @@ public class XorImmWithRm16SignExtendedHandler : InstructionHandler
return false;
// Check if the reg field of the ModR/M byte is 6 (XOR)
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
return false;
byte modRM = CodeBuffer[position];
byte modRM = CodeBuffer[Decoder.GetPosition()];
byte reg = (byte)((modRM & 0x38) >> 3);
return reg == 6; // 6 = XOR
@ -48,9 +47,7 @@ public class XorImmWithRm16SignExtendedHandler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
@ -78,16 +75,12 @@ public class XorImmWithRm16SignExtendedHandler : InstructionHandler
}
}
// Get the updated position after ModR/M decoding
position = Decoder.GetPosition();
// Read the immediate value (sign-extended from 8 to 16 bits)
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
// Read the immediate value and sign-extend it to 16 bits
short imm16 = (sbyte)Decoder.ReadByte();
// Format the immediate value

View File

@ -27,11 +27,10 @@ public class XorImmWithRm32Handler : InstructionHandler
return false;
// Check if the reg field of the ModR/M byte is 6 (XOR)
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
return false;
byte modRM = CodeBuffer[position];
byte modRM = CodeBuffer[Decoder.GetPosition()];
byte reg = (byte)((modRM & 0x38) >> 3);
return reg == 6; // 6 = XOR
@ -48,9 +47,7 @@ public class XorImmWithRm32Handler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
@ -58,16 +55,12 @@ public class XorImmWithRm32Handler : InstructionHandler
// Read the ModR/M byte
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Get the updated position after ModR/M decoding
position = Decoder.GetPosition();
// Read the immediate value
if (position + 3 >= Length)
if (!Decoder.CanReadUInt())
{
return false;
}
// Read the immediate value using the decoder
var imm = Decoder.ReadUInt32();
// Format the immediate value

View File

@ -27,11 +27,10 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
return false;
// Check if the reg field of the ModR/M byte is 6 (XOR)
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
return false;
byte modRM = CodeBuffer[position];
byte modRM = CodeBuffer[Decoder.GetPosition()];
byte reg = (byte)((modRM & 0x38) >> 3);
return reg == 6; // 6 = XOR
@ -48,9 +47,7 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
@ -58,11 +55,8 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
// Read the ModR/M byte
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Get the updated position after ModR/M decoding
position = Decoder.GetPosition();
// Read the immediate value (sign-extended from 8 to 32 bits)
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}

View File

@ -27,11 +27,10 @@ public class XorImmWithRm8Handler : InstructionHandler
return false;
// Check if the reg field of the ModR/M byte is 6 (XOR)
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
return false;
byte modRM = CodeBuffer[position];
byte modRM = CodeBuffer[Decoder.GetPosition()];
byte reg = (byte)((modRM & 0x38) >> 3);
return reg == 6; // 6 = XOR
@ -48,9 +47,7 @@ public class XorImmWithRm8Handler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
@ -58,9 +55,6 @@ public class XorImmWithRm8Handler : InstructionHandler
// Read the ModR/M byte
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Advance past the ModR/M byte
Decoder.SetPosition(position + 1);
// If mod == 3, then the r/m field specifies a register
if (mod == 3)
{
@ -69,17 +63,12 @@ public class XorImmWithRm8Handler : InstructionHandler
}
else
{
// For memory operands, use the ModRMDecoder to get the full operand string
// Replace "dword ptr" with "byte ptr" to indicate 8-bit operation
destOperand = destOperand.Replace("dword ptr", "byte ptr");
}
// Get the updated position after ModR/M decoding
position = Decoder.GetPosition();
// Read the immediate value
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}

View File

@ -37,9 +37,7 @@ public class XorMemRegHandler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}

View File

@ -38,9 +38,7 @@ public class XorR16Rm16Handler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}

View File

@ -37,18 +37,13 @@ public class XorR8Rm8Handler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Advance past the ModR/M byte
Decoder.SetPosition(position + 1);
// Get register name (8-bit)
string regName = ModRMDecoder.GetRegisterName(reg, 8);

View File

@ -36,14 +36,12 @@ public class XorRegMemHandler : InstructionHandler
{
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte
var (mod, reg, rm, srcOperand) = ModRMDecoder.ReadModRM();

View File

@ -38,9 +38,7 @@ public class XorRm16R16Handler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}

View File

@ -37,18 +37,13 @@ public class XorRm8R8Handler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "xor";
int position = Decoder.GetPosition();
if (position >= Length)
if (!Decoder.CanReadByte())
{
return false;
}
// Read the ModR/M byte
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Advance past the ModR/M byte
Decoder.SetPosition(position + 1);
// Get register name (8-bit)
string regName = ModRMDecoder.GetRegisterName(reg, 8);