2025-04-13 02:51:51 +03:00
|
|
|
namespace X86DisassemblerTests;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using Xunit;
|
|
|
|
using X86Disassembler.X86;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Tests for instruction boundary detection
|
|
|
|
/// </summary>
|
|
|
|
public class InstructionBoundaryTests
|
|
|
|
{
|
|
|
|
/// <summary>
|
2025-04-13 03:38:50 +03:00
|
|
|
/// Tests that the disassembler correctly handles instruction boundaries
|
|
|
|
/// </summary>
|
2025-04-13 02:51:51 +03:00
|
|
|
[Fact]
|
|
|
|
public void Disassembler_HandlesInstructionBoundaries_Correctly()
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
// This is the sequence from the problematic example:
|
|
|
|
// 08 83 C1 04 50 E8 42 01 00 00
|
|
|
|
byte[] codeBuffer = new byte[] { 0x08, 0x83, 0xC1, 0x04, 0x50, 0xE8, 0x42, 0x01, 0x00, 0x00 };
|
|
|
|
var disassembler = new Disassembler(codeBuffer, 0);
|
|
|
|
|
|
|
|
// Act
|
|
|
|
var instructions = disassembler.Disassemble();
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.True(instructions.Count >= 3, $"Expected at least 3 instructions, but got {instructions.Count}");
|
|
|
|
|
|
|
|
// First instruction should be OR r/m8, r8 (but might be incomplete)
|
|
|
|
Assert.Equal("or", instructions[0].Mnemonic);
|
|
|
|
|
|
|
|
// Second instruction should be ADD ecx, 0x04
|
|
|
|
Assert.Equal("add", instructions[1].Mnemonic);
|
2025-04-13 03:38:50 +03:00
|
|
|
Assert.Equal("ecx, 0x00000004", instructions[1].Operands);
|
2025-04-13 02:51:51 +03:00
|
|
|
|
|
|
|
// Third instruction should be PUSH eax
|
|
|
|
Assert.Equal("push", instructions[2].Mnemonic);
|
|
|
|
Assert.Equal("eax", instructions[2].Operands);
|
|
|
|
}
|
|
|
|
}
|