mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 00:18:02 +03:00
unbreak tests
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using X86Disassembler.X86;
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86DisassemblerTests.InstructionTests;
|
||||
|
||||
@ -16,15 +17,33 @@ public class StringInstructionHandlerTests
|
||||
// Arrange
|
||||
// REP MOVS (F3 A5)
|
||||
byte[] codeBuffer = new byte[] { 0xF3, 0xA5 };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
var disassembler = new Disassembler(codeBuffer, 0);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
var instructions = disassembler.Disassemble();
|
||||
|
||||
// Assert
|
||||
Assert.Single(instructions);
|
||||
var instruction = instructions[0];
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("rep movs", instruction.Mnemonic);
|
||||
Assert.Equal("dword ptr [edi], dword ptr [esi]", instruction.Operands);
|
||||
Assert.Equal(InstructionType.RepMovsD, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (destination memory operand)
|
||||
var destOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<BaseRegisterMemoryOperand>(destOperand);
|
||||
var destMemoryOperand = (BaseRegisterMemoryOperand)destOperand;
|
||||
Assert.Equal(RegisterIndex.Di, destMemoryOperand.BaseRegister);
|
||||
Assert.Equal(32, destMemoryOperand.Size); // Validate that it's a 32-bit memory reference
|
||||
|
||||
// Check the second operand (source memory operand)
|
||||
var srcOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<BaseRegisterMemoryOperand>(srcOperand);
|
||||
var srcMemoryOperand = (BaseRegisterMemoryOperand)srcOperand;
|
||||
Assert.Equal(RegisterIndex.Si, srcMemoryOperand.BaseRegister);
|
||||
Assert.Equal(32, srcMemoryOperand.Size); // Validate that it's a 32-bit memory reference
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -36,15 +55,33 @@ public class StringInstructionHandlerTests
|
||||
// Arrange
|
||||
// REPNE SCAS (F2 AF)
|
||||
byte[] codeBuffer = new byte[] { 0xF2, 0xAF };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
var disassembler = new Disassembler(codeBuffer, 0);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
var instructions = disassembler.Disassemble();
|
||||
|
||||
// Assert
|
||||
Assert.Single(instructions);
|
||||
var instruction = instructions[0];
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("repne scas", instruction.Mnemonic);
|
||||
Assert.Equal("eax, dword ptr [edi]", instruction.Operands);
|
||||
Assert.Equal(InstructionType.RepNE, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (EAX)
|
||||
var eaxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(eaxOperand);
|
||||
var registerOperand = (RegisterOperand)eaxOperand;
|
||||
Assert.Equal(RegisterIndex.A, registerOperand.Register);
|
||||
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EAX)
|
||||
|
||||
// Check the second operand (memory operand)
|
||||
var memOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<BaseRegisterMemoryOperand>(memOperand);
|
||||
var memoryOperand = (BaseRegisterMemoryOperand)memOperand;
|
||||
Assert.Equal(RegisterIndex.Di, memoryOperand.BaseRegister);
|
||||
Assert.Equal(32, memoryOperand.Size); // Validate that it's a 32-bit memory reference
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -56,19 +93,37 @@ public class StringInstructionHandlerTests
|
||||
// Arrange
|
||||
// MOVS (A5)
|
||||
byte[] codeBuffer = new byte[] { 0xA5 };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
var disassembler = new Disassembler(codeBuffer, 0);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
var instructions = disassembler.Disassemble();
|
||||
|
||||
// Assert
|
||||
Assert.Single(instructions);
|
||||
var instruction = instructions[0];
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("movs", instruction.Mnemonic);
|
||||
Assert.Equal("dword ptr [edi], dword ptr [esi]", instruction.Operands);
|
||||
Assert.Equal(InstructionType.MovsD, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (destination memory operand)
|
||||
var destOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<BaseRegisterMemoryOperand>(destOperand);
|
||||
var destMemoryOperand = (BaseRegisterMemoryOperand)destOperand;
|
||||
Assert.Equal(RegisterIndex.Di, destMemoryOperand.BaseRegister);
|
||||
Assert.Equal(32, destMemoryOperand.Size); // Validate that it's a 32-bit memory reference
|
||||
|
||||
// Check the second operand (source memory operand)
|
||||
var srcOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<BaseRegisterMemoryOperand>(srcOperand);
|
||||
var srcMemoryOperand = (BaseRegisterMemoryOperand)srcOperand;
|
||||
Assert.Equal(RegisterIndex.Si, srcMemoryOperand.BaseRegister);
|
||||
Assert.Equal(32, srcMemoryOperand.Size); // Validate that it's a 32-bit memory reference
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the StringInstructionHandler for decoding STOS instruction without prefix
|
||||
/// Tests the StringInstructionHandler for decoding STOSB instruction
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void StringInstructionHandler_DecodesStosb_Correctly()
|
||||
@ -76,19 +131,37 @@ public class StringInstructionHandlerTests
|
||||
// Arrange
|
||||
// STOSB (AA)
|
||||
byte[] codeBuffer = new byte[] { 0xAA };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
var disassembler = new Disassembler(codeBuffer, 0);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
var instructions = disassembler.Disassemble();
|
||||
|
||||
// Assert
|
||||
Assert.Single(instructions);
|
||||
var instruction = instructions[0];
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("stos", instruction.Mnemonic);
|
||||
Assert.Equal("byte ptr [edi], al", instruction.Operands);
|
||||
Assert.Equal(InstructionType.StosB, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (memory operand)
|
||||
var memOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<BaseRegisterMemoryOperand>(memOperand);
|
||||
var memoryOperand = (BaseRegisterMemoryOperand)memOperand;
|
||||
Assert.Equal(RegisterIndex.Di, memoryOperand.BaseRegister);
|
||||
Assert.Equal(8, memoryOperand.Size); // Validate that it's an 8-bit memory reference
|
||||
|
||||
// Check the second operand (AL)
|
||||
var alOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<RegisterOperand>(alOperand);
|
||||
var registerOperand = (RegisterOperand)alOperand;
|
||||
Assert.Equal(RegisterIndex.A, registerOperand.Register);
|
||||
Assert.Equal(8, registerOperand.Size); // Validate that it's an 8-bit register (AL)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the StringInstructionHandler for decoding LODS instruction without prefix
|
||||
/// Tests the StringInstructionHandler for decoding LODSD instruction
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void StringInstructionHandler_DecodesLodsd_Correctly()
|
||||
@ -96,19 +169,37 @@ public class StringInstructionHandlerTests
|
||||
// Arrange
|
||||
// LODSD (AD)
|
||||
byte[] codeBuffer = new byte[] { 0xAD };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
var disassembler = new Disassembler(codeBuffer, 0);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
var instructions = disassembler.Disassemble();
|
||||
|
||||
// Assert
|
||||
Assert.Single(instructions);
|
||||
var instruction = instructions[0];
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("lods", instruction.Mnemonic);
|
||||
Assert.Equal("eax, dword ptr [esi]", instruction.Operands);
|
||||
Assert.Equal(InstructionType.LodsD, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (EAX)
|
||||
var eaxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(eaxOperand);
|
||||
var registerOperand = (RegisterOperand)eaxOperand;
|
||||
Assert.Equal(RegisterIndex.A, registerOperand.Register);
|
||||
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EAX)
|
||||
|
||||
// Check the second operand (memory operand)
|
||||
var memOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<BaseRegisterMemoryOperand>(memOperand);
|
||||
var memoryOperand = (BaseRegisterMemoryOperand)memOperand;
|
||||
Assert.Equal(RegisterIndex.Si, memoryOperand.BaseRegister);
|
||||
Assert.Equal(32, memoryOperand.Size); // Validate that it's a 32-bit memory reference
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the StringInstructionHandler for decoding SCAS instruction without prefix
|
||||
/// Tests the StringInstructionHandler for decoding SCASB instruction
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void StringInstructionHandler_DecodesScasb_Correctly()
|
||||
@ -116,14 +207,32 @@ public class StringInstructionHandlerTests
|
||||
// Arrange
|
||||
// SCASB (AE)
|
||||
byte[] codeBuffer = new byte[] { 0xAE };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
var disassembler = new Disassembler(codeBuffer, 0);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
var instructions = disassembler.Disassemble();
|
||||
|
||||
// Assert
|
||||
Assert.Single(instructions);
|
||||
var instruction = instructions[0];
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("scas", instruction.Mnemonic);
|
||||
Assert.Equal("al, byte ptr [edi]", instruction.Operands);
|
||||
Assert.Equal(InstructionType.ScasB, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (AL)
|
||||
var alOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(alOperand);
|
||||
var registerOperand = (RegisterOperand)alOperand;
|
||||
Assert.Equal(RegisterIndex.A, registerOperand.Register);
|
||||
Assert.Equal(8, registerOperand.Size); // Validate that it's an 8-bit register (AL)
|
||||
|
||||
// Check the second operand (memory operand)
|
||||
var memOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<BaseRegisterMemoryOperand>(memOperand);
|
||||
var memoryOperand = (BaseRegisterMemoryOperand)memOperand;
|
||||
Assert.Equal(RegisterIndex.Di, memoryOperand.BaseRegister);
|
||||
Assert.Equal(8, memoryOperand.Size); // Validate that it's an 8-bit memory reference
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user