mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-21 21:01:17 +03:00
Added tests for previously untested DataTransferHandler methods and fixed NOP instruction handling
This commit is contained in:
parent
759d28f9a7
commit
d5bcd56774
@ -8,4 +8,12 @@
|
|||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMemory_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FAdmin_003FAppData_003FLocal_003FSymbols_003Fsrc_003Fdotnet_003Fruntime_003F5535e31a712343a63f5d7d796cd874e563e5ac14_003Fsrc_003Flibraries_003FSystem_002EPrivate_002ECoreLib_003Fsrc_003FSystem_003FMemory_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMemory_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FAdmin_003FAppData_003FLocal_003FSymbols_003Fsrc_003Fdotnet_003Fruntime_003F5535e31a712343a63f5d7d796cd874e563e5ac14_003Fsrc_003Flibraries_003FSystem_002EPrivate_002ECoreLib_003Fsrc_003FSystem_003FMemory_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASingle_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FAdmin_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc99a63bcf3d2a18c20ee19e58ac875ab1edf2a147c8b92ffeed185ab8a44b4_003FSingle_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASingle_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FAdmin_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc99a63bcf3d2a18c20ee19e58ac875ab1edf2a147c8b92ffeed185ab8a44b4_003FSingle_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003Aud_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FAdmin_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa494e0aa381c41ff9484df33e5edb42535e00_003F15_003F87bd9007_003Fud_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003Aud_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FAdmin_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa494e0aa381c41ff9484df33e5edb42535e00_003F15_003F87bd9007_003Fud_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003Audis86_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FAdmin_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa494e0aa381c41ff9484df33e5edb42535e00_003F95_003F953bbb0f_003Fudis86_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003Audis86_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FAdmin_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa494e0aa381c41ff9484df33e5edb42535e00_003F95_003F953bbb0f_003Fudis86_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/Environment/Highlighting/HighlightingSourceSnapshotLocation/@EntryValue">C:\Users\Admin\AppData\Local\JetBrains\Rider2024.3\resharper-host\temp\Rider\vAny\CoverageData\_ParkanPlayground.1073341822\Snapshot\snapshot.utdcvr</s:String>
|
||||||
|
|
||||||
|
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=87a33e46_002D2816_002D434f_002D972a_002D703eb7a78476/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="Session" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
|
||||||
|
<And>
|
||||||
|
<Namespace>X86DisassemblerTests</Namespace>
|
||||||
|
<Project Location="C:\Projects\CSharp\ParkanPlayground\X86DisassemblerTests" Presentation="&lt;X86DisassemblerTests&gt;" />
|
||||||
|
</And>
|
||||||
|
</SessionState></s:String></wpf:ResourceDictionary>
|
@ -316,6 +316,14 @@ public class DataTransferHandler : InstructionHandler
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private bool DecodeXCHGEAXReg(byte opcode, Instruction instruction)
|
private bool DecodeXCHGEAXReg(byte opcode, Instruction instruction)
|
||||||
{
|
{
|
||||||
|
// Special case for NOP (XCHG EAX, EAX)
|
||||||
|
if (opcode == 0x90)
|
||||||
|
{
|
||||||
|
instruction.Mnemonic = "nop";
|
||||||
|
instruction.Operands = "";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Register is encoded in the low 3 bits of the opcode
|
// Register is encoded in the low 3 bits of the opcode
|
||||||
int reg = opcode & 0x07;
|
int reg = opcode & 0x07;
|
||||||
string regName = ModRMDecoder.GetRegisterName(reg, 32);
|
string regName = ModRMDecoder.GetRegisterName(reg, 32);
|
||||||
|
@ -72,6 +72,26 @@ public class DataTransferInstructionTests
|
|||||||
Assert.Equal("eax, 0x12345678", instruction.Operands);
|
Assert.Equal("eax, 0x12345678", instruction.Operands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the DataTransferHandler for decoding MOV r8, imm8 instruction (DecodeMOVRegImm8)
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void DataTransferHandler_DecodesMovR8Imm8_Correctly()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
// MOV AL, 0x42 (B0 42) - Register is encoded in the low 3 bits of the opcode
|
||||||
|
byte[] codeBuffer = new byte[] { 0xB0, 0x42 };
|
||||||
|
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var instruction = decoder.DecodeInstruction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(instruction);
|
||||||
|
Assert.Equal("mov", instruction.Mnemonic);
|
||||||
|
Assert.Equal("al, 0x42", instruction.Operands);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests the DataTransferHandler for decoding MOV EAX, moffs32 instruction
|
/// Tests the DataTransferHandler for decoding MOV EAX, moffs32 instruction
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -153,6 +173,46 @@ public class DataTransferInstructionTests
|
|||||||
Assert.Equal("eax", instruction.Operands);
|
Assert.Equal("eax", instruction.Operands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the DataTransferHandler for decoding PUSH imm32 instruction (DecodePUSHImm32)
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void DataTransferHandler_DecodesPushImm32_Correctly()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
// PUSH 0x12345678 (68 78 56 34 12)
|
||||||
|
byte[] codeBuffer = new byte[] { 0x68, 0x78, 0x56, 0x34, 0x12 };
|
||||||
|
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var instruction = decoder.DecodeInstruction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(instruction);
|
||||||
|
Assert.Equal("push", instruction.Mnemonic);
|
||||||
|
Assert.Equal("0x12345678", instruction.Operands);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the DataTransferHandler for decoding PUSH imm8 instruction (DecodePUSHImm8)
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void DataTransferHandler_DecodesPushImm8_Correctly()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
// PUSH 0x42 (6A 42)
|
||||||
|
byte[] codeBuffer = new byte[] { 0x6A, 0x42 };
|
||||||
|
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var instruction = decoder.DecodeInstruction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(instruction);
|
||||||
|
Assert.Equal("push", instruction.Mnemonic);
|
||||||
|
Assert.Equal("0x42", instruction.Operands);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests the DataTransferHandler for decoding POP r32 instruction
|
/// Tests the DataTransferHandler for decoding POP r32 instruction
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -172,4 +232,44 @@ public class DataTransferInstructionTests
|
|||||||
Assert.Equal("pop", instruction.Mnemonic);
|
Assert.Equal("pop", instruction.Mnemonic);
|
||||||
Assert.Equal("ecx", instruction.Operands);
|
Assert.Equal("ecx", instruction.Operands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the DataTransferHandler for decoding XCHG EAX, r32 instruction (DecodeXCHGEAXReg)
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void DataTransferHandler_DecodesXchgEaxReg_Correctly()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
// XCHG EAX, ECX (91) - Register is encoded in the low 3 bits of the opcode
|
||||||
|
byte[] codeBuffer = new byte[] { 0x91 };
|
||||||
|
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var instruction = decoder.DecodeInstruction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(instruction);
|
||||||
|
Assert.Equal("xchg", instruction.Mnemonic);
|
||||||
|
Assert.Equal("eax, ecx", instruction.Operands);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the DataTransferHandler for decoding NOP instruction (special case of XCHG EAX, EAX)
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void DataTransferHandler_DecodesNop_Correctly()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
// NOP (90) - This is actually XCHG EAX, EAX which is treated as NOP
|
||||||
|
byte[] codeBuffer = new byte[] { 0x90 };
|
||||||
|
var decoder = new InstructionDecoder(codeBuffer, codeBuffer.Length);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var instruction = decoder.DecodeInstruction();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(instruction);
|
||||||
|
Assert.Equal("nop", instruction.Mnemonic);
|
||||||
|
Assert.Equal("", instruction.Operands);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user