mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 00:18:02 +03:00
Added comprehensive tests for various instruction handlers. Created test files for Jump, Return, XOR, Group1, Group3, and Call instructions. Fixed ConditionalJumpHandler test to use 'jz' instead of 'je' since they are equivalent in x86.
This commit is contained in:
94
X86DisassemblerTests/XorInstructionTests.cs
Normal file
94
X86DisassemblerTests/XorInstructionTests.cs
Normal file
@ -0,0 +1,94 @@
|
||||
namespace X86DisassemblerTests;
|
||||
|
||||
using System;
|
||||
using Xunit;
|
||||
using X86Disassembler.X86;
|
||||
using X86Disassembler.X86.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for XOR instruction handlers
|
||||
/// </summary>
|
||||
public class XorInstructionTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests the XorRegMemHandler for decoding XOR r32, r/m32 instruction
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void XorRegMemHandler_DecodesXorR32Rm32_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
// XOR EAX, ECX (33 C1) - ModR/M byte C1 = 11 000 001 (mod=3, reg=0, rm=1)
|
||||
// mod=3 means direct register addressing, reg=0 is EAX, rm=1 is ECX
|
||||
byte[] codeBuffer = new byte[] { 0x33, 0xC1 };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("xor", instruction.Mnemonic);
|
||||
Assert.Equal("eax, ecx", instruction.Operands);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the XorMemRegHandler for decoding XOR r/m32, r32 instruction
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void XorMemRegHandler_DecodesXorRm32R32_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
// XOR ECX, EAX (31 C1) - ModR/M byte C1 = 11 000 001 (mod=3, reg=0, rm=1)
|
||||
// mod=3 means direct register addressing, reg=0 is EAX, rm=1 is ECX
|
||||
byte[] codeBuffer = new byte[] { 0x31, 0xC1 };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("xor", instruction.Mnemonic);
|
||||
Assert.Equal("ecx, eax", instruction.Operands);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the XorAlImmHandler for decoding XOR AL, imm8 instruction
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void XorAlImmHandler_DecodesXorAlImm8_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
// XOR AL, 0x42 (34 42)
|
||||
byte[] codeBuffer = new byte[] { 0x34, 0x42 };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("xor", instruction.Mnemonic);
|
||||
Assert.Equal("al, 0x42", instruction.Operands);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the XorEaxImmHandler for decoding XOR EAX, imm32 instruction
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void XorEaxImmHandler_DecodesXorEaxImm32_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
// XOR EAX, 0x12345678 (35 78 56 34 12)
|
||||
byte[] codeBuffer = new byte[] { 0x35, 0x78, 0x56, 0x34, 0x12 };
|
||||
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||
|
||||
// Act
|
||||
var instruction = decoder.DecodeInstruction();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(instruction);
|
||||
Assert.Equal("xor", instruction.Mnemonic);
|
||||
Assert.Equal("eax, 0x12345678", instruction.Operands);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user