0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-05-19 11:51:17 +03:00
ParkanPlayground/X86DisassemblerTests/TestFromFileEntry.cs

88 lines
2.7 KiB
C#
Raw Normal View History

2025-04-13 17:02:46 +03:00
using CsvHelper.Configuration;
2025-04-14 23:08:52 +03:00
using X86Disassembler.X86;
using X86Disassembler.X86.Operands;
2025-04-13 17:02:46 +03:00
namespace X86DisassemblerTests;
public class TestFromFileEntry
{
public string RawBytes { get; set; } = string.Empty;
public List<TestFromFileInstruction> Instructions { get; set; } = new();
public TestFromFileEntry()
{
}
public TestFromFileEntry(string rawBytes, List<TestFromFileInstruction> instructions)
{
RawBytes = rawBytes;
Instructions = instructions;
}
}
public class TestFromFileInstruction
{
2025-04-14 23:08:52 +03:00
// Keep the old properties for CSV deserialization
2025-04-13 17:02:46 +03:00
public string Mnemonic { get; set; } = string.Empty;
public string Operands { get; set; } = string.Empty;
2025-04-14 23:08:52 +03:00
// Add new properties for comparison with actual Instruction objects
public InstructionType Type => ConvertMnemonicToType(Mnemonic);
2025-04-13 17:02:46 +03:00
// Parameterless constructor required by CsvHelper
public TestFromFileInstruction()
{
}
public TestFromFileInstruction(string mnemonic, string operands)
{
Mnemonic = mnemonic;
Operands = operands;
}
2025-04-14 23:08:52 +03:00
// Helper method to convert mnemonic string to InstructionType
private InstructionType ConvertMnemonicToType(string mnemonic)
{
// Convert mnemonic to InstructionType
return mnemonic.ToLowerInvariant() switch
{
"add" => InstructionType.Add,
"adc" => InstructionType.Adc,
"and" => InstructionType.And,
"call" => InstructionType.Call,
"cmp" => InstructionType.Cmp,
"dec" => InstructionType.Dec,
"inc" => InstructionType.Inc,
"int3" => InstructionType.Int,
"jmp" => InstructionType.Jmp,
"jz" => InstructionType.Jz,
"jnz" => InstructionType.Jnz,
"jge" => InstructionType.Jge,
"lea" => InstructionType.Lea,
"mov" => InstructionType.Mov,
"nop" => InstructionType.Nop,
"or" => InstructionType.Or,
"pop" => InstructionType.Pop,
"push" => InstructionType.Push,
"ret" => InstructionType.Ret,
"sbb" => InstructionType.Sbb,
"sub" => InstructionType.Sub,
"test" => InstructionType.Test,
"xchg" => InstructionType.Xchg,
"xor" => InstructionType.Xor,
_ => InstructionType.Unknown
};
}
2025-04-13 17:02:46 +03:00
}
public sealed class TestFromFileEntryMap : ClassMap<TestFromFileEntry>
{
public TestFromFileEntryMap()
{
Map(m => m.RawBytes)
.Name("RawBytes");
Map(m => m.Instructions)
.Name("Instructions")
.TypeConverter<CsvJsonConverter<List<TestFromFileInstruction>>>();
}
}