using X86Disassembler.X86; using X86Disassembler.X86.Operands; namespace X86DisassemblerTests.InstructionTests; /// /// Tests for DEC instruction handlers /// public class DecInstructionTests { /// /// Tests the DEC EAX instruction (0x48) /// [Fact] public void TestDecEax() { // Arrange byte[] code = { 0x48 }; // DEC EAX // Act Disassembler disassembler = new Disassembler(code, 0x1000); var instructions = disassembler.Disassemble(); // Assert Assert.Single(instructions); var instruction = instructions[0]; Assert.Equal(InstructionType.Dec, instruction.Type); // Check that we have one operand Assert.Single(instruction.StructuredOperands); // Check the operand (EAX) var eaxOperand = instruction.StructuredOperands[0]; Assert.IsType(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) } /// /// Tests the DEC ECX instruction (0x49) /// [Fact] public void TestDecEcx() { // Arrange byte[] code = { 0x49 }; // DEC ECX // Act Disassembler disassembler = new Disassembler(code, 0x1000); var instructions = disassembler.Disassemble(); // Assert Assert.Single(instructions); var instruction = instructions[0]; Assert.Equal(InstructionType.Dec, instruction.Type); // Check that we have one operand Assert.Single(instruction.StructuredOperands); // Check the operand (ECX) var ecxOperand = instruction.StructuredOperands[0]; Assert.IsType(ecxOperand); var registerOperand = (RegisterOperand)ecxOperand; Assert.Equal(RegisterIndex.C, registerOperand.Register); Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (ECX) } /// /// Tests the DEC EDI instruction (0x4F) /// [Fact] public void TestDecEdi() { // Arrange byte[] code = { 0x4F }; // DEC EDI // Act Disassembler disassembler = new Disassembler(code, 0x1000); var instructions = disassembler.Disassemble(); // Assert Assert.Single(instructions); var instruction = instructions[0]; Assert.Equal(InstructionType.Dec, instruction.Type); // Check that we have one operand Assert.Single(instruction.StructuredOperands); // Check the operand (EDI) var ediOperand = instruction.StructuredOperands[0]; Assert.IsType(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) } }