mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
Added complete set of OR instruction handlers with tests
This commit is contained in:
60
X86Disassembler/X86/Handlers/Or/OrEaxImmHandler.cs
Normal file
60
X86Disassembler/X86/Handlers/Or/OrEaxImmHandler.cs
Normal file
@ -0,0 +1,60 @@
|
||||
namespace X86Disassembler.X86.Handlers.Or;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for OR EAX, imm32 instruction (0x0D)
|
||||
/// </summary>
|
||||
public class OrEaxImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the OrEaxImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public OrEaxImmHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
return opcode == 0x0D;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes an OR EAX, imm32 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
if (position + 3 >= Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the immediate dword (little-endian)
|
||||
byte b0 = CodeBuffer[position++];
|
||||
byte b1 = CodeBuffer[position++];
|
||||
byte b2 = CodeBuffer[position++];
|
||||
byte b3 = CodeBuffer[position++];
|
||||
uint imm32 = (uint)(b0 | (b1 << 8) | (b2 << 16) | (b3 << 24));
|
||||
Decoder.SetPosition(position);
|
||||
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "or";
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"eax, 0x{imm32:X8}";
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user