mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
unbreak tests
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using X86Disassembler.X86;
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86DisassemblerTests.InstructionTests;
|
||||
|
||||
@ -17,15 +18,32 @@ public class Group1InstructionTests
|
||||
// ADD AL, 0x42 (80 C0 42) - ModR/M byte C0 = 11 000 000 (mod=3, reg=0, rm=0)
|
||||
// mod=3 means direct register addressing, reg=0 indicates ADD operation, rm=0 is AL
|
||||
byte[] codeBuffer = new byte[] { 0x80, 0xC0, 0x42 };
|
||||
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("add", instruction.Mnemonic);
|
||||
Assert.Equal("al, 0x42", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Add, 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 (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x42U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -38,15 +56,32 @@ public class Group1InstructionTests
|
||||
// ADD ECX, 0x12345678 (81 C1 78 56 34 12) - ModR/M byte C1 = 11 000 001 (mod=3, reg=0, rm=1)
|
||||
// mod=3 means direct register addressing, reg=0 indicates ADD operation, rm=1 is ECX
|
||||
byte[] codeBuffer = new byte[] { 0x81, 0xC1, 0x78, 0x56, 0x34, 0x12 };
|
||||
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("add", instruction.Mnemonic);
|
||||
Assert.Equal("ecx, 0x12345678", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Add, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (ECX)
|
||||
var ecxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(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)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x12345678U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -59,15 +94,32 @@ public class Group1InstructionTests
|
||||
// OR BL, 0x42 (80 CB 42) - ModR/M byte CB = 11 001 011 (mod=3, reg=1, rm=3)
|
||||
// mod=3 means direct register addressing, reg=1 indicates OR operation, rm=3 is BL
|
||||
byte[] codeBuffer = new byte[] { 0x80, 0xCB, 0x42 };
|
||||
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("or", instruction.Mnemonic);
|
||||
Assert.Equal("bl, 0x42", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Or, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (BL)
|
||||
var blOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(blOperand);
|
||||
var registerOperand = (RegisterOperand)blOperand;
|
||||
Assert.Equal(RegisterIndex.B, registerOperand.Register);
|
||||
Assert.Equal(8, registerOperand.Size); // Validate that it's an 8-bit register (BL)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x42U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -80,15 +132,32 @@ public class Group1InstructionTests
|
||||
// SUB EDX, 0x12345678 (81 EA 78 56 34 12) - ModR/M byte EA = 11 101 010 (mod=3, reg=5, rm=2)
|
||||
// mod=3 means direct register addressing, reg=5 indicates SUB operation, rm=2 is EDX
|
||||
byte[] codeBuffer = new byte[] { 0x81, 0xEA, 0x78, 0x56, 0x34, 0x12 };
|
||||
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("sub", instruction.Mnemonic);
|
||||
Assert.Equal("edx, 0x12345678", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Sub, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (EDX)
|
||||
var edxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(edxOperand);
|
||||
var registerOperand = (RegisterOperand)edxOperand;
|
||||
Assert.Equal(RegisterIndex.D, registerOperand.Register);
|
||||
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EDX)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x12345678U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -101,15 +170,32 @@ public class Group1InstructionTests
|
||||
// CMP EBX, 0x12345678 (81 FB 78 56 34 12) - ModR/M byte FB = 11 111 011 (mod=3, reg=7, rm=3)
|
||||
// mod=3 means direct register addressing, reg=7 indicates CMP operation, rm=3 is EBX
|
||||
byte[] codeBuffer = new byte[] { 0x81, 0xFB, 0x78, 0x56, 0x34, 0x12 };
|
||||
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("cmp", instruction.Mnemonic);
|
||||
Assert.Equal("ebx, 0x12345678", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Cmp, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (EBX)
|
||||
var ebxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(ebxOperand);
|
||||
var registerOperand = (RegisterOperand)ebxOperand;
|
||||
Assert.Equal(RegisterIndex.B, registerOperand.Register);
|
||||
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EBX)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x12345678U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -122,15 +208,32 @@ public class Group1InstructionTests
|
||||
// ADC ECX, 0x12345678 (81 D1 78 56 34 12) - ModR/M byte D1 = 11 010 001 (mod=3, reg=2, rm=1)
|
||||
// mod=3 means direct register addressing, reg=2 indicates ADC operation, rm=1 is ECX
|
||||
byte[] codeBuffer = new byte[] { 0x81, 0xD1, 0x78, 0x56, 0x34, 0x12 };
|
||||
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("adc", instruction.Mnemonic);
|
||||
Assert.Equal("ecx, 0x12345678", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Adc, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (ECX)
|
||||
var ecxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(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)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x12345678U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -144,15 +247,32 @@ public class Group1InstructionTests
|
||||
// mod=3 means direct register addressing, reg=2 indicates ADC operation, rm=1 is ECX
|
||||
// The immediate value 0x42 is sign-extended to 32 bits
|
||||
byte[] codeBuffer = new byte[] { 0x83, 0xD1, 0x42 };
|
||||
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("adc", instruction.Mnemonic);
|
||||
Assert.Equal("ecx, 0x00000042", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Adc, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (ECX)
|
||||
var ecxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(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)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x42U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -165,15 +285,32 @@ public class Group1InstructionTests
|
||||
// SBB EDX, 0x12345678 (81 DA 78 56 34 12) - ModR/M byte DA = 11 011 010 (mod=3, reg=3, rm=2)
|
||||
// mod=3 means direct register addressing, reg=3 indicates SBB operation, rm=2 is EDX
|
||||
byte[] codeBuffer = new byte[] { 0x81, 0xDA, 0x78, 0x56, 0x34, 0x12 };
|
||||
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("sbb", instruction.Mnemonic);
|
||||
Assert.Equal("edx, 0x12345678", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Sbb, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (EDX)
|
||||
var edxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(edxOperand);
|
||||
var registerOperand = (RegisterOperand)edxOperand;
|
||||
Assert.Equal(RegisterIndex.D, registerOperand.Register);
|
||||
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EDX)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x12345678U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -187,15 +324,32 @@ public class Group1InstructionTests
|
||||
// mod=3 means direct register addressing, reg=3 indicates SBB operation, rm=2 is EDX
|
||||
// The immediate value 0x42 is sign-extended to 32 bits
|
||||
byte[] codeBuffer = new byte[] { 0x83, 0xDA, 0x42 };
|
||||
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("sbb", instruction.Mnemonic);
|
||||
Assert.Equal("edx, 0x00000042", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Sbb, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (EDX)
|
||||
var edxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(edxOperand);
|
||||
var registerOperand = (RegisterOperand)edxOperand;
|
||||
Assert.Equal(RegisterIndex.D, registerOperand.Register);
|
||||
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EDX)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x42U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -208,15 +362,32 @@ public class Group1InstructionTests
|
||||
// AND EBX, 0x12345678 (81 E3 78 56 34 12) - ModR/M byte E3 = 11 100 011 (mod=3, reg=4, rm=3)
|
||||
// mod=3 means direct register addressing, reg=4 indicates AND operation, rm=3 is EBX
|
||||
byte[] codeBuffer = new byte[] { 0x81, 0xE3, 0x78, 0x56, 0x34, 0x12 };
|
||||
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("and", instruction.Mnemonic);
|
||||
Assert.Equal("ebx, 0x12345678", instruction.Operands);
|
||||
Assert.Equal(InstructionType.And, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (EBX)
|
||||
var ebxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(ebxOperand);
|
||||
var registerOperand = (RegisterOperand)ebxOperand;
|
||||
Assert.Equal(RegisterIndex.B, registerOperand.Register);
|
||||
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EBX)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x12345678U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -230,15 +401,32 @@ public class Group1InstructionTests
|
||||
// mod=3 means direct register addressing, reg=4 indicates AND operation, rm=3 is EBX
|
||||
// The immediate value 0x42 is sign-extended to 32 bits
|
||||
byte[] codeBuffer = new byte[] { 0x83, 0xE3, 0x42 };
|
||||
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("and", instruction.Mnemonic);
|
||||
Assert.Equal("ebx, 0x00000042", instruction.Operands);
|
||||
Assert.Equal(InstructionType.And, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (EBX)
|
||||
var ebxOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(ebxOperand);
|
||||
var registerOperand = (RegisterOperand)ebxOperand;
|
||||
Assert.Equal(RegisterIndex.B, registerOperand.Register);
|
||||
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (EBX)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x42U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -251,15 +439,32 @@ public class Group1InstructionTests
|
||||
// XOR ESI, 0x12345678 (81 F6 78 56 34 12) - ModR/M byte F6 = 11 110 110 (mod=3, reg=6, rm=6)
|
||||
// mod=3 means direct register addressing, reg=6 indicates XOR operation, rm=6 is ESI
|
||||
byte[] codeBuffer = new byte[] { 0x81, 0xF6, 0x78, 0x56, 0x34, 0x12 };
|
||||
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("xor", instruction.Mnemonic);
|
||||
Assert.Equal("esi, 0x12345678", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Xor, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (ESI)
|
||||
var esiOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(esiOperand);
|
||||
var registerOperand = (RegisterOperand)esiOperand;
|
||||
Assert.Equal(RegisterIndex.Si, registerOperand.Register);
|
||||
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (ESI)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x12345678U, immediateOperand.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -273,14 +478,31 @@ public class Group1InstructionTests
|
||||
// mod=3 means direct register addressing, reg=6 indicates XOR operation, rm=6 is ESI
|
||||
// The immediate value 0x42 is sign-extended to 32 bits
|
||||
byte[] codeBuffer = new byte[] { 0x83, 0xF6, 0x42 };
|
||||
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("xor", instruction.Mnemonic);
|
||||
Assert.Equal("esi, 0x42", instruction.Operands);
|
||||
Assert.Equal(InstructionType.Xor, instruction.Type);
|
||||
|
||||
// Check that we have two operands
|
||||
Assert.Equal(2, instruction.StructuredOperands.Count);
|
||||
|
||||
// Check the first operand (ESI)
|
||||
var esiOperand = instruction.StructuredOperands[0];
|
||||
Assert.IsType<RegisterOperand>(esiOperand);
|
||||
var registerOperand = (RegisterOperand)esiOperand;
|
||||
Assert.Equal(RegisterIndex.Si, registerOperand.Register);
|
||||
Assert.Equal(32, registerOperand.Size); // Validate that it's a 32-bit register (ESI)
|
||||
|
||||
// Check the second operand (immediate value)
|
||||
var immOperand = instruction.StructuredOperands[1];
|
||||
Assert.IsType<ImmediateOperand>(immOperand);
|
||||
var immediateOperand = (ImmediateOperand)immOperand;
|
||||
Assert.Equal(0x42U, immediateOperand.Value);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user