0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-05-19 20:01:17 +03:00

57 lines
1.5 KiB
C#
Raw Normal View History

namespace X86Disassembler.X86;
/// <summary>
/// Represents an x86 instruction
/// </summary>
public class Instruction
{
/// <summary>
/// Gets or sets the address of the instruction
/// </summary>
public uint Address { get; set; }
/// <summary>
/// Gets or sets the mnemonic of the instruction
/// </summary>
public string Mnemonic { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the operands of the instruction
/// </summary>
public string Operands { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the raw bytes of the instruction
/// </summary>
2025-04-12 23:40:48 +03:00
public byte[] RawBytes { get; set; } = [];
/// <summary>
/// Returns a string representation of the instruction
/// </summary>
/// <returns>A string representation of the instruction</returns>
public override string ToString()
{
// Format the address
string addressStr = $"{Address:X8}";
// Format the raw bytes
string bytesStr = string.Empty;
foreach (byte b in RawBytes)
{
bytesStr += $"{b:X2} ";
}
// Pad the bytes string to a fixed width
bytesStr = bytesStr.PadRight(30);
// Format the instruction
string instructionStr = Mnemonic;
if (!string.IsNullOrEmpty(Operands))
{
instructionStr += " " + Operands;
}
return $" {addressStr} {bytesStr}{instructionStr}";
}
}