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

unbreak tests

This commit is contained in:
bird_egop
2025-04-14 23:08:52 +03:00
parent 685eeda03d
commit 9117830ff1
41 changed files with 3820 additions and 736 deletions

View File

@ -1,4 +1,5 @@
using X86Disassembler.X86;
using X86Disassembler.X86.Operands;
namespace X86DisassemblerTests.InstructionTests;
@ -22,8 +23,24 @@ public class LeaInstructionTests
// Assert
Assert.Single(instructions);
Assert.Equal("lea", instructions[0].Mnemonic);
Assert.Equal("eax, [eax]", instructions[0].Operands);
var instruction = instructions[0];
Assert.Equal(InstructionType.Lea, 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.A, memoryOperand.BaseRegister);
}
/// <summary>
@ -41,18 +58,35 @@ public class LeaInstructionTests
// Assert
Assert.Single(instructions);
Assert.Equal("lea", instructions[0].Mnemonic);
Assert.Equal("edi, [esi-0x04]", instructions[0].Operands);
var instruction = instructions[0];
Assert.Equal(InstructionType.Lea, instruction.Type);
// Check that we have two operands
Assert.Equal(2, instruction.StructuredOperands.Count);
// Check the first operand (EDI)
var ediOperand = instruction.StructuredOperands[0];
Assert.IsType<RegisterOperand>(ediOperand);
var registerOperand = (RegisterOperand)ediOperand;
Assert.Equal(RegisterIndex.Di, registerOperand.Register);
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EDI)
// Check the second operand (memory operand with displacement)
var memOperand = instruction.StructuredOperands[1];
Assert.IsType<DisplacementMemoryOperand>(memOperand);
var displacementMemoryOperand = (DisplacementMemoryOperand)memOperand;
Assert.Equal(RegisterIndex.Si, displacementMemoryOperand.BaseRegister);
Assert.Equal(-4, displacementMemoryOperand.Displacement);
}
/// <summary>
/// Tests the LEA r32, m instruction (0x8D) with SIB byte
/// </summary>
[Fact]
public void TestLeaR32M_WithSIB()
public void TestLeaR32M_WithSib()
{
// Arrange
byte[] code = { 0x8D, 0x04, 0x11 }; // LEA EAX, [ECX+EDX]
byte[] code = { 0x8D, 0x04, 0x8D, 0x00, 0x00, 0x00, 0x00 }; // LEA EAX, [ECX*4]
// Act
Disassembler disassembler = new Disassembler(code, 0x1000);
@ -60,8 +94,26 @@ public class LeaInstructionTests
// Assert
Assert.Single(instructions);
Assert.Equal("lea", instructions[0].Mnemonic);
Assert.Equal("eax, [ecx+edx]", instructions[0].Operands);
var instruction = instructions[0];
Assert.Equal(InstructionType.Lea, 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 (scaled index memory operand)
var memOperand = instruction.StructuredOperands[1];
Assert.IsType<ScaledIndexMemoryOperand>(memOperand);
var scaledIndexMemoryOperand = (ScaledIndexMemoryOperand)memOperand;
Assert.Equal(RegisterIndex.C, scaledIndexMemoryOperand.IndexRegister);
Assert.Equal(4, scaledIndexMemoryOperand.Scale);
Assert.Equal(0, scaledIndexMemoryOperand.Displacement);
}
/// <summary>
@ -71,7 +123,7 @@ public class LeaInstructionTests
public void TestLeaR32M_Complex()
{
// Arrange
byte[] code = { 0x8D, 0x44, 0x8A, 0x10 }; // LEA EAX, [EDX + ECX*4 + 0x10]
byte[] code = { 0x8D, 0x84, 0x88, 0x78, 0x56, 0x34, 0x12 }; // LEA EAX, [EAX+ECX*4+0x12345678]
// Act
Disassembler disassembler = new Disassembler(code, 0x1000);
@ -79,7 +131,26 @@ public class LeaInstructionTests
// Assert
Assert.Single(instructions);
Assert.Equal("lea", instructions[0].Mnemonic);
Assert.Equal("eax, [edx+ecx*4+0x10]", instructions[0].Operands);
var instruction = instructions[0];
Assert.Equal(InstructionType.Lea, 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 (complex memory operand)
var memOperand = instruction.StructuredOperands[1];
Assert.IsType<ScaledIndexMemoryOperand>(memOperand);
var scaledIndexMemoryOperand = (ScaledIndexMemoryOperand)memOperand;
Assert.Equal(RegisterIndex.A, scaledIndexMemoryOperand.BaseRegister);
Assert.Equal(RegisterIndex.C, scaledIndexMemoryOperand.IndexRegister);
Assert.Equal(4, scaledIndexMemoryOperand.Scale);
Assert.Equal(0x12345678, scaledIndexMemoryOperand.Displacement);
}
}