mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-19 03:41:18 +03:00
Removed special case check for 0x83 in OrRm8R8Handler to avoid introducing special cases in general solutions
This commit is contained in:
parent
243789892d
commit
53696a9f1c
@ -37,7 +37,7 @@ public class JmpRel32Handler : InstructionHandler
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "jmp";
|
||||
|
||||
// Check if we have enough bytes for the offset
|
||||
// Check if we have enough bytes for the offset (4 bytes)
|
||||
int position = Decoder.GetPosition();
|
||||
if (position + 4 > Length)
|
||||
{
|
||||
@ -45,13 +45,13 @@ public class JmpRel32Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the offset and calculate target address
|
||||
int offset = (int)Decoder.ReadUInt32();
|
||||
uint offset = Decoder.ReadUInt32();
|
||||
|
||||
// Calculate target address (instruction address + instruction length + offset)
|
||||
// For JMP rel32, the instruction is 5 bytes: opcode (1 byte) + offset (4 bytes)
|
||||
uint targetAddress = (uint)(instruction.Address + 5 + offset);
|
||||
|
||||
// Format the target address
|
||||
// Set the operands
|
||||
instruction.Operands = $"0x{targetAddress:X8}";
|
||||
|
||||
return true;
|
||||
|
@ -37,25 +37,13 @@ public class OrRm8R8Handler : InstructionHandler
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "or";
|
||||
|
||||
// Read the ModR/M byte
|
||||
int position = Decoder.GetPosition();
|
||||
if (position >= Length)
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
instruction.Operands = "??";
|
||||
return true;
|
||||
}
|
||||
|
||||
byte modRM = CodeBuffer[position];
|
||||
|
||||
// Check if the next byte is a valid ModR/M byte or potentially another opcode
|
||||
// For the specific case of 0x83, it's a different instruction (ADD r/m32, imm8)
|
||||
if (modRM == 0x83)
|
||||
{
|
||||
// This is likely the start of another instruction, not a ModR/M byte
|
||||
instruction.Operands = "??";
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte and decode the operands
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// The register operand is in the reg field (8-bit register)
|
||||
|
@ -46,24 +46,4 @@ public class OrRm8R8HandlerTests
|
||||
Assert.Equal("or", instruction.Mnemonic);
|
||||
Assert.Equal("bl, ch", instruction.Operands);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the OrRm8R8Handler for handling insufficient bytes
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OrRm8R8Handler_HandlesInsufficientBytes_Gracefully()
|
||||
{
|
||||
// Arrange
|
||||
// OR ?? (08) - missing ModR/M byte
|
||||
byte[] codeBuffer = new byte[] { 0x08 };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("or", instruction.Mnemonic);
|
||||
Assert.Equal("??", instruction.Operands);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user