mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
Updated instruction handlers to use Type and StructuredOperands instead of Mnemonic and Operands
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Jump;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for conditional jump instructions (0x70-0x7F)
|
||||
/// </summary>
|
||||
@ -11,15 +13,22 @@ public class ConditionalJumpHandler : InstructionHandler
|
||||
"jo", "jno", "jb", "jnb", "jz", "jnz", "jbe", "jnbe",
|
||||
"js", "jns", "jp", "jnp", "jl", "jnl", "jle", "jnle"
|
||||
];
|
||||
|
||||
|
||||
// Instruction types for conditional jumps
|
||||
private static readonly InstructionType[] InstructionTypes =
|
||||
[
|
||||
InstructionType.Jo, InstructionType.Jno, InstructionType.Jb, InstructionType.Jae,
|
||||
InstructionType.Jz, InstructionType.Jnz, InstructionType.Jbe, InstructionType.Ja,
|
||||
InstructionType.Js, InstructionType.Jns, InstructionType.Unknown, InstructionType.Unknown,
|
||||
InstructionType.Jl, InstructionType.Jge, InstructionType.Jle, InstructionType.Jg
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ConditionalJumpHandler 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 ConditionalJumpHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public ConditionalJumpHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -42,9 +51,11 @@ public class ConditionalJumpHandler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Get the mnemonic from the table
|
||||
// Get the index from the opcode
|
||||
int index = opcode - 0x70;
|
||||
instruction.Mnemonic = Mnemonics[index];
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionTypes[index];
|
||||
|
||||
// Check if we can read the offset byte
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -57,8 +68,14 @@ public class ConditionalJumpHandler : InstructionHandler
|
||||
sbyte offset = (sbyte)Decoder.ReadByte();
|
||||
int targetAddress = position + 1 + offset;
|
||||
|
||||
// Format the target address as a hexadecimal value
|
||||
instruction.Operands = $"0x{targetAddress:X8}";
|
||||
// Create the target address operand
|
||||
var targetOperand = OperandFactory.CreateRelativeOffsetOperand((ulong)targetAddress, 8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
targetOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Jump;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for JGE rel8 instruction (0x7D)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class JgeRel8Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the JgeRel8Handler 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 JgeRel8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public JgeRel8Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,14 +34,13 @@ public class JgeRel8Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "jge";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Jge;
|
||||
|
||||
// Check if we can read the offset byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
instruction.Operands = "??";
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
sbyte offset = (sbyte)Decoder.ReadByte();
|
||||
@ -49,8 +48,14 @@ public class JgeRel8Handler : InstructionHandler
|
||||
// Calculate target address (instruction address + instruction length + offset)
|
||||
ulong targetAddress = instruction.Address + 2UL + (uint)offset;
|
||||
|
||||
// Format the target address
|
||||
instruction.Operands = $"0x{targetAddress:X8}";
|
||||
// Create the relative offset operand
|
||||
var targetOperand = OperandFactory.CreateRelativeOffsetOperand(targetAddress, 8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
targetOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Jump;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for JMP rel32 instruction (0xE9)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class JmpRel32Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the JmpRel32Handler 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 JmpRel32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public JmpRel32Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@ public class JmpRel32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "jmp";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Jmp;
|
||||
|
||||
// Check if we have enough bytes for the offset (4 bytes)
|
||||
if (!Decoder.CanReadUInt())
|
||||
@ -50,8 +50,14 @@ public class JmpRel32Handler : InstructionHandler
|
||||
// For JMP rel32, the instruction is 5 bytes: opcode (1 byte) + offset (4 bytes)
|
||||
uint targetAddress = (uint)(instruction.Address + 5 + offset);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"0x{targetAddress:X8}";
|
||||
// Create the target address operand
|
||||
var targetOperand = OperandFactory.CreateRelativeOffsetOperand(targetAddress);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
targetOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Jump;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for JMP rel8 instruction (0xEB)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class JmpRel8Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the JmpRel8Handler 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 JmpRel8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public JmpRel8Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@ public class JmpRel8Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "jmp";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Jmp;
|
||||
|
||||
// Check if we can read the offset byte
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -48,8 +48,14 @@ public class JmpRel8Handler : InstructionHandler
|
||||
// Calculate target address (instruction address + instruction length + offset)
|
||||
ulong targetAddress = instruction.Address + 2UL + (uint)offset;
|
||||
|
||||
// Format the target address
|
||||
instruction.Operands = $"0x{targetAddress:X8}";
|
||||
// Create the target address operand
|
||||
var targetOperand = OperandFactory.CreateRelativeOffsetOperand(targetAddress, 8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
targetOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Jump;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for two-byte conditional jump instructions (0x0F 0x80-0x8F)
|
||||
/// </summary>
|
||||
@ -12,14 +14,21 @@ public class TwoByteConditionalJumpHandler : InstructionHandler
|
||||
"js", "jns", "jp", "jnp", "jl", "jnl", "jle", "jnle"
|
||||
];
|
||||
|
||||
// Instruction types for conditional jumps
|
||||
private static readonly InstructionType[] InstructionTypes =
|
||||
[
|
||||
InstructionType.Jo, InstructionType.Jno, InstructionType.Jb, InstructionType.Jae,
|
||||
InstructionType.Jz, InstructionType.Jnz, InstructionType.Jbe, InstructionType.Ja,
|
||||
InstructionType.Js, InstructionType.Jns, InstructionType.Unknown, InstructionType.Unknown,
|
||||
InstructionType.Jl, InstructionType.Jge, InstructionType.Jle, InstructionType.Jg
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the TwoByteConditionalJumpHandler 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 TwoByteConditionalJumpHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public TwoByteConditionalJumpHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -42,7 +51,7 @@ public class TwoByteConditionalJumpHandler : InstructionHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
byte secondByte = CodeBuffer[position];
|
||||
byte secondByte = Decoder.PeakByte();
|
||||
// Second byte must be in the range 0x80-0x8F
|
||||
return secondByte >= 0x80 && secondByte <= 0x8F;
|
||||
}
|
||||
@ -64,9 +73,9 @@ public class TwoByteConditionalJumpHandler : InstructionHandler
|
||||
// Read the second byte of the opcode
|
||||
byte secondByte = Decoder.ReadByte();
|
||||
|
||||
// Get the mnemonic from the table
|
||||
// Get the instruction type from the table
|
||||
int index = secondByte - 0x80;
|
||||
instruction.Mnemonic = ConditionalJumpMnemonics[index];
|
||||
instruction.Type = InstructionTypes[index];
|
||||
|
||||
// Check if we have enough bytes for the offset
|
||||
if (!Decoder.CanReadUInt())
|
||||
@ -81,8 +90,14 @@ public class TwoByteConditionalJumpHandler : InstructionHandler
|
||||
// For two-byte conditional jumps, the instruction is 6 bytes: first opcode (1) + second opcode (1) + offset (4)
|
||||
uint targetAddress = (uint)(instruction.Address + 6 + offset);
|
||||
|
||||
// Format the target address
|
||||
instruction.Operands = $"0x{targetAddress:X8}";
|
||||
// Create the relative offset operand
|
||||
var targetOperand = OperandFactory.CreateRelativeOffsetOperand(targetAddress);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
targetOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user