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

Replaced Assert.Contains with strict Assert.Equal in tests for better validation

This commit is contained in:
bird_egop
2025-04-13 03:33:51 +03:00
parent b718745d7a
commit 0d271abdcb
3 changed files with 303 additions and 0 deletions

View File

@ -46,4 +46,125 @@ public class MovRm32Imm32Tests
Assert.Equal("mov", instructions[0].Mnemonic);
Assert.Equal("dword ptr [eax], 0x12345678", instructions[0].Operands);
}
/// <summary>
/// Tests the MOV m32, imm32 instruction (0xC7) with SIB byte addressing
/// </summary>
[Fact]
public void TestMovM32Imm32_WithSIB()
{
// Arrange
// MOV DWORD PTR [ESP+0x10], 0x00000000
byte[] code = { 0xC7, 0x44, 0x24, 0x10, 0x00, 0x00, 0x00, 0x00 };
// Act
Disassembler disassembler = new Disassembler(code, 0x1000);
var instructions = disassembler.Disassemble();
// Assert
Assert.Single(instructions);
Assert.Equal("mov", instructions[0].Mnemonic);
Assert.Equal("dword ptr [esp+0x10], 0x00000000", instructions[0].Operands);
}
/// <summary>
/// Tests the MOV m32, imm32 instruction (0xC7) with complex SIB byte addressing
/// </summary>
[Fact]
public void TestMovM32Imm32_WithComplexSIB()
{
// Arrange
// MOV DWORD PTR [EAX+ECX*4+0x12345678], 0xAABBCCDD
byte[] code = { 0xC7, 0x84, 0x88, 0x78, 0x56, 0x34, 0x12, 0xDD, 0xCC, 0xBB, 0xAA };
// Act
Disassembler disassembler = new Disassembler(code, 0x1000);
var instructions = disassembler.Disassemble();
// Assert
Assert.Single(instructions);
Assert.Equal("mov", instructions[0].Mnemonic);
Assert.Equal("dword ptr [eax+ecx*4+0x12345678], 0xAABBCCDD", instructions[0].Operands);
}
/// <summary>
/// Tests the MOV m32, imm32 instruction (0xC7) with consecutive instructions
/// </summary>
[Fact]
public void TestMovM32Imm32_ConsecutiveInstructions()
{
// Arrange
// MOV DWORD PTR [ESP+0x10], 0x00000000
// MOV DWORD PTR [ESP+0x14], 0x00000000
byte[] code = {
0xC7, 0x44, 0x24, 0x10, 0x00, 0x00, 0x00, 0x00,
0xC7, 0x44, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00
};
// Act
Disassembler disassembler = new Disassembler(code, 0x1000);
var instructions = disassembler.Disassemble();
// Assert
Assert.Equal(2, instructions.Count);
// First instruction
Assert.Equal("mov", instructions[0].Mnemonic);
Assert.Equal("dword ptr [esp+0x10], 0x00000000", instructions[0].Operands);
// Second instruction
Assert.Equal("mov", instructions[1].Mnemonic);
Assert.Equal("dword ptr [esp+0x14], 0x00000000", instructions[1].Operands);
}
/// <summary>
/// Tests the MOV m32, imm32 instruction (0xC7) with incomplete immediate value
/// </summary>
[Fact]
public void TestMovM32Imm32_IncompleteImmediate()
{
// Arrange
// MOV DWORD PTR [EAX], ?? (incomplete immediate)
byte[] code = { 0xC7, 0x00, 0x78, 0x56 }; // Missing 2 bytes of immediate
// Act
Disassembler disassembler = new Disassembler(code, 0x1000);
var instructions = disassembler.Disassemble();
// Assert
Assert.True(instructions.Count > 0, "Expected at least one instruction");
Assert.Equal("mov", instructions[0].Mnemonic);
Assert.Equal("??", instructions[0].Operands);
}
/// <summary>
/// Tests the MOV m32, imm32 instruction (0xC7) with instruction boundary detection
/// </summary>
[Fact]
public void TestMovM32Imm32_InstructionBoundaryDetection()
{
// Arrange
// This is the sequence from address 0x00002441 that was problematic
// MOV DWORD PTR [ESP+0x10], 0x00000000
// MOV DWORD PTR [ESP+0x14], 0x00000000
byte[] code = {
0xC7, 0x44, 0x24, 0x10, 0x00, 0x00, 0x00, 0x00,
0xC7, 0x44, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00
};
// Act
Disassembler disassembler = new Disassembler(code, 0x2441);
var instructions = disassembler.Disassemble();
// Assert
Assert.Equal(2, instructions.Count);
// First instruction
Assert.Equal("mov", instructions[0].Mnemonic);
Assert.Equal("dword ptr [esp+0x10], 0x00000000", instructions[0].Operands);
// Second instruction
Assert.Equal("mov", instructions[1].Mnemonic);
Assert.Equal("dword ptr [esp+0x14], 0x00000000", instructions[1].Operands);
}
}