mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-21 12:51:18 +03:00
Simplified XorImmWithRm16Handler by improving boundary checking and removing redundant code
This commit is contained in:
parent
4567465570
commit
f54dc10596
@ -27,11 +27,10 @@ public class XorImmWithRm16Handler : InstructionHandler
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check if the reg field of the ModR/M byte is 6 (XOR)
|
// Check if the reg field of the ModR/M byte is 6 (XOR)
|
||||||
int position = Decoder.GetPosition();
|
if (!Decoder.CanReadByte())
|
||||||
if (position >= Length)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
byte modRM = CodeBuffer[position];
|
byte modRM = CodeBuffer[Decoder.GetPosition()];
|
||||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||||
|
|
||||||
return reg == 6; // 6 = XOR
|
return reg == 6; // 6 = XOR
|
||||||
@ -48,53 +47,40 @@ public class XorImmWithRm16Handler : InstructionHandler
|
|||||||
// Set the mnemonic
|
// Set the mnemonic
|
||||||
instruction.Mnemonic = "xor";
|
instruction.Mnemonic = "xor";
|
||||||
|
|
||||||
int position = Decoder.GetPosition();
|
// Check if we have enough bytes for the ModR/M byte
|
||||||
|
if (!Decoder.CanReadByte())
|
||||||
if (position >= Length)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the ModR/M byte
|
// Read the ModR/M byte
|
||||||
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||||
|
|
||||||
// For the first operand, handle based on addressing mode
|
// For direct register addressing (mod == 3), use the correct 16-bit register name
|
||||||
string rmOperand;
|
if (mod == 3)
|
||||||
if (mod == 3) // Register addressing mode
|
|
||||||
{
|
{
|
||||||
// Get 16-bit register name for the operand
|
destOperand = ModRMDecoder.GetRegisterName(rm, 16);
|
||||||
rmOperand = ModRMDecoder.GetRegisterName(rm, 16);
|
|
||||||
}
|
}
|
||||||
else // Memory addressing mode
|
else
|
||||||
{
|
{
|
||||||
// For memory operands, replace "dword ptr" with "word ptr"
|
// For memory operands, ensure we have the correct size prefix
|
||||||
if (memOperand.StartsWith("dword ptr "))
|
destOperand = destOperand.Replace("dword ptr", "word ptr");
|
||||||
{
|
|
||||||
rmOperand = memOperand.Replace("dword ptr", "word ptr");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rmOperand = memOperand;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the updated position after ModR/M decoding
|
// Check if we have enough bytes for the immediate value
|
||||||
position = Decoder.GetPosition();
|
if (!Decoder.CanReadUShort())
|
||||||
|
|
||||||
// Read the immediate value
|
|
||||||
if (position + 1 >= Length)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the immediate value using the decoder
|
// Read the immediate value
|
||||||
ushort imm16 = Decoder.ReadUInt16();
|
ushort imm16 = Decoder.ReadUInt16();
|
||||||
|
|
||||||
// Format the immediate value
|
// Format the immediate value
|
||||||
string immStr = $"0x{imm16:X4}";
|
string immStr = $"0x{imm16:X4}";
|
||||||
|
|
||||||
// Set the operands
|
// Set the operands
|
||||||
instruction.Operands = $"{rmOperand}, {immStr}";
|
instruction.Operands = $"{destOperand}, {immStr}";
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user