mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-19 20:01:17 +03:00
cleanup
This commit is contained in:
parent
3cc6d27e33
commit
f658f4384c
@ -7,7 +7,7 @@ public class Int32OperationHandler : FloatingPointBaseHandler
|
|||||||
{
|
{
|
||||||
// DA opcode - operations on int32
|
// DA opcode - operations on int32
|
||||||
private static readonly string[] Mnemonics =
|
private static readonly string[] Mnemonics =
|
||||||
{
|
[
|
||||||
"fiadd",
|
"fiadd",
|
||||||
"fimul",
|
"fimul",
|
||||||
"ficom",
|
"ficom",
|
||||||
@ -15,8 +15,8 @@ public class Int32OperationHandler : FloatingPointBaseHandler
|
|||||||
"fisub",
|
"fisub",
|
||||||
"fisubr",
|
"fisubr",
|
||||||
"fidiv",
|
"fidiv",
|
||||||
"fidivr",
|
"fidivr"
|
||||||
};
|
];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the Int32OperationHandler class
|
/// Initializes a new instance of the Int32OperationHandler class
|
||||||
|
@ -18,7 +18,7 @@ namespace X86Disassembler.X86.Handlers;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class InstructionHandlerFactory
|
public class InstructionHandlerFactory
|
||||||
{
|
{
|
||||||
private readonly List<IInstructionHandler> _handlers = new();
|
private readonly List<IInstructionHandler> _handlers = [];
|
||||||
private readonly byte[] _codeBuffer;
|
private readonly byte[] _codeBuffer;
|
||||||
private readonly InstructionDecoder _decoder;
|
private readonly InstructionDecoder _decoder;
|
||||||
private readonly int _length;
|
private readonly int _length;
|
||||||
|
@ -6,11 +6,11 @@ namespace X86Disassembler.X86.Handlers.Jump;
|
|||||||
public class ConditionalJumpHandler : InstructionHandler
|
public class ConditionalJumpHandler : InstructionHandler
|
||||||
{
|
{
|
||||||
// Mnemonics for conditional jumps
|
// Mnemonics for conditional jumps
|
||||||
private static readonly string[] ConditionalJumpMnemonics = new string[]
|
private static readonly string[] Mnemonics =
|
||||||
{
|
[
|
||||||
"jo", "jno", "jb", "jnb", "jz", "jnz", "jbe", "jnbe",
|
"jo", "jno", "jb", "jnb", "jz", "jnz", "jbe", "jnbe",
|
||||||
"js", "jns", "jp", "jnp", "jl", "jnl", "jle", "jnle"
|
"js", "jns", "jp", "jnp", "jl", "jnl", "jle", "jnle"
|
||||||
};
|
];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the ConditionalJumpHandler class
|
/// Initializes a new instance of the ConditionalJumpHandler class
|
||||||
@ -44,7 +44,7 @@ public class ConditionalJumpHandler : InstructionHandler
|
|||||||
{
|
{
|
||||||
// Get the mnemonic from the table
|
// Get the mnemonic from the table
|
||||||
int index = opcode - 0x70;
|
int index = opcode - 0x70;
|
||||||
instruction.Mnemonic = ConditionalJumpMnemonics[index];
|
instruction.Mnemonic = Mnemonics[index];
|
||||||
|
|
||||||
// Get the current position in the code buffer
|
// Get the current position in the code buffer
|
||||||
int position = Decoder.GetPosition();
|
int position = Decoder.GetPosition();
|
||||||
|
@ -6,11 +6,11 @@ namespace X86Disassembler.X86.Handlers.Jump;
|
|||||||
public class TwoByteConditionalJumpHandler : InstructionHandler
|
public class TwoByteConditionalJumpHandler : InstructionHandler
|
||||||
{
|
{
|
||||||
// Mnemonics for conditional jumps
|
// Mnemonics for conditional jumps
|
||||||
private static readonly string[] ConditionalJumpMnemonics = new string[]
|
private static readonly string[] ConditionalJumpMnemonics =
|
||||||
{
|
[
|
||||||
"jo", "jno", "jb", "jnb", "jz", "jnz", "jbe", "jnbe",
|
"jo", "jno", "jb", "jnb", "jz", "jnz", "jbe", "jnbe",
|
||||||
"js", "jns", "jp", "jnp", "jl", "jnl", "jle", "jnle"
|
"js", "jns", "jp", "jnp", "jl", "jnl", "jle", "jnle"
|
||||||
};
|
];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the TwoByteConditionalJumpHandler class
|
/// Initializes a new instance of the TwoByteConditionalJumpHandler class
|
||||||
|
@ -23,7 +23,7 @@ public class Instruction
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the raw bytes of the instruction
|
/// Gets or sets the raw bytes of the instruction
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] RawBytes { get; set; } = Array.Empty<byte>();
|
public byte[] RawBytes { get; set; } = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a string representation of the instruction
|
/// Returns a string representation of the instruction
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace X86Disassembler.X86;
|
namespace X86Disassembler.X86;
|
||||||
|
|
||||||
using X86Disassembler.X86.Handlers;
|
using Handlers;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Decodes x86 instructions from a byte buffer
|
/// Decodes x86 instructions from a byte buffer
|
||||||
@ -25,7 +25,7 @@ public class InstructionDecoder
|
|||||||
private bool _segmentOverridePrefix;
|
private bool _segmentOverridePrefix;
|
||||||
private bool _lockPrefix;
|
private bool _lockPrefix;
|
||||||
private bool _repPrefix;
|
private bool _repPrefix;
|
||||||
private string _segmentOverride = string.Empty;
|
private string _segmentOverride;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the InstructionDecoder class
|
/// Initializes a new instance of the InstructionDecoder class
|
||||||
@ -37,7 +37,7 @@ public class InstructionDecoder
|
|||||||
_codeBuffer = codeBuffer;
|
_codeBuffer = codeBuffer;
|
||||||
_length = length;
|
_length = length;
|
||||||
_position = 0;
|
_position = 0;
|
||||||
_segmentOverride = string.Empty;
|
_segmentOverride = "";
|
||||||
|
|
||||||
// Create the instruction handler factory
|
// Create the instruction handler factory
|
||||||
_handlerFactory = new InstructionHandlerFactory(_codeBuffer, this, _length);
|
_handlerFactory = new InstructionHandlerFactory(_codeBuffer, this, _length);
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
namespace X86Disassembler.X86;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents the different types of x86 instructions
|
|
||||||
/// </summary>
|
|
||||||
public enum InstructionType
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Unknown or unrecognized instruction
|
|
||||||
/// </summary>
|
|
||||||
Unknown,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Data transfer instructions (e.g., MOV, PUSH, POP, XCHG)
|
|
||||||
/// </summary>
|
|
||||||
DataTransfer,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Arithmetic instructions (e.g., ADD, SUB, MUL, DIV)
|
|
||||||
/// </summary>
|
|
||||||
Arithmetic,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Logical instructions (e.g., AND, OR, XOR, NOT)
|
|
||||||
/// </summary>
|
|
||||||
Logical,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Shift and rotate instructions (e.g., SHL, SHR, ROL, ROR)
|
|
||||||
/// </summary>
|
|
||||||
ShiftRotate,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Control flow instructions (e.g., JMP, CALL, RET)
|
|
||||||
/// </summary>
|
|
||||||
ControlFlow,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Conditional jump instructions (e.g., JE, JNE, JG, JL)
|
|
||||||
/// </summary>
|
|
||||||
ConditionalJump,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// String instructions (e.g., MOVS, CMPS, SCAS)
|
|
||||||
/// </summary>
|
|
||||||
String,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// I/O instructions (e.g., IN, OUT)
|
|
||||||
/// </summary>
|
|
||||||
IO,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Flag control instructions (e.g., STC, CLC, CMC)
|
|
||||||
/// </summary>
|
|
||||||
FlagControl,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Processor control instructions (e.g., HLT, WAIT)
|
|
||||||
/// </summary>
|
|
||||||
ProcessorControl,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Floating-point instructions (e.g., FADD, FSUB, FMUL)
|
|
||||||
/// </summary>
|
|
||||||
FloatingPoint,
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// SIMD instructions (e.g., MMX, SSE, AVX)
|
|
||||||
/// </summary>
|
|
||||||
SIMD
|
|
||||||
}
|
|
@ -239,34 +239,4 @@ public class ModRMDecoder
|
|||||||
_ => RegisterNames32[index]
|
_ => RegisterNames32[index]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the 8-bit register name based on the register number
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="reg">The register number (0-7)</param>
|
|
||||||
/// <returns>The register name</returns>
|
|
||||||
public static string GetRegister8(int reg)
|
|
||||||
{
|
|
||||||
if (reg >= 0 && reg < RegisterNames8.Length)
|
|
||||||
{
|
|
||||||
return RegisterNames8[reg];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $"r{reg}?";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the 32-bit register name based on the register number
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="reg">The register number (0-7)</param>
|
|
||||||
/// <returns>The register name</returns>
|
|
||||||
public static string GetRegister32(int reg)
|
|
||||||
{
|
|
||||||
if (reg >= 0 && reg < RegisterNames32.Length)
|
|
||||||
{
|
|
||||||
return RegisterNames32[reg];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $"r{reg}?";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ namespace X86Disassembler.X86;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides mapping between opcodes and their mnemonics
|
/// Provides mapping between opcodes and their mnemonics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OpcodeMap
|
public static class OpcodeMap
|
||||||
{
|
{
|
||||||
// One-byte opcode map
|
// One-byte opcode map
|
||||||
private static readonly string[] OneByteOpcodes = new string[256];
|
private static readonly string[] OneByteOpcodes = new string[256];
|
||||||
@ -14,16 +14,6 @@ public class OpcodeMap
|
|||||||
"s", "ns", "p", "np", "l", "ge", "le", "g"
|
"s", "ns", "p", "np", "l", "ge", "le", "g"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Group 1 operations (used with opcodes 0x80, 0x81, 0x83)
|
|
||||||
public static readonly string[] Group1Operations = {
|
|
||||||
"add", "or", "adc", "sbb", "and", "sub", "xor", "cmp"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Group 3 operations (used with opcodes 0xF6, 0xF7)
|
|
||||||
public static readonly string[] Group3Operations = {
|
|
||||||
"test", "???", "not", "neg", "mul", "imul", "div", "idiv"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Static constructor to initialize the opcode maps
|
// Static constructor to initialize the opcode maps
|
||||||
static OpcodeMap()
|
static OpcodeMap()
|
||||||
{
|
{
|
||||||
@ -138,34 +128,4 @@ public class OpcodeMap
|
|||||||
{
|
{
|
||||||
return OneByteOpcodes[opcode];
|
return OneByteOpcodes[opcode];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks if the opcode is a Group 1 opcode
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="opcode">The opcode to check</param>
|
|
||||||
/// <returns>True if the opcode is a Group 1 opcode</returns>
|
|
||||||
public static bool IsGroup1Opcode(byte opcode)
|
|
||||||
{
|
|
||||||
return opcode == 0x80 || opcode == 0x81 || opcode == 0x83;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks if the opcode is a Group 3 opcode
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="opcode">The opcode to check</param>
|
|
||||||
/// <returns>True if the opcode is a Group 3 opcode</returns>
|
|
||||||
public static bool IsGroup3Opcode(byte opcode)
|
|
||||||
{
|
|
||||||
return opcode == 0xF6 || opcode == 0xF7;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Checks if the opcode is a floating-point instruction
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="opcode">The opcode to check</param>
|
|
||||||
/// <returns>True if the opcode is a floating-point instruction</returns>
|
|
||||||
public static bool IsFloatingPointOpcode(byte opcode)
|
|
||||||
{
|
|
||||||
return opcode >= 0xD8 && opcode <= 0xDF;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user