From 1442fd706059033b0f8e80616560d8c84b7b8eae Mon Sep 17 00:00:00 2001 From: bird_egop Date: Sat, 12 Apr 2025 20:14:28 +0300 Subject: [PATCH] Removed obsolete Group1Handler and Group3Handler classes --- X86Disassembler/X86/Handlers/Group1Handler.cs | 104 ------------------ X86Disassembler/X86/Handlers/Group3Handler.cs | 99 ----------------- 2 files changed, 203 deletions(-) delete mode 100644 X86Disassembler/X86/Handlers/Group1Handler.cs delete mode 100644 X86Disassembler/X86/Handlers/Group3Handler.cs diff --git a/X86Disassembler/X86/Handlers/Group1Handler.cs b/X86Disassembler/X86/Handlers/Group1Handler.cs deleted file mode 100644 index 80a6460..0000000 --- a/X86Disassembler/X86/Handlers/Group1Handler.cs +++ /dev/null @@ -1,104 +0,0 @@ -namespace X86Disassembler.X86.Handlers; - -/// -/// Handler for Group 1 instructions (ADD, OR, ADC, SBB, AND, SUB, XOR, CMP) -/// -public class Group1Handler : InstructionHandler -{ - /// - /// Initializes a new instance of the Group1Handler class - /// - /// The buffer containing the code to decode - /// The instruction decoder that owns this handler - /// The length of the buffer - public Group1Handler(byte[] codeBuffer, InstructionDecoder decoder, int length) - : base(codeBuffer, decoder, length) - { - } - - /// - /// Checks if this handler can decode the given opcode - /// - /// The opcode to check - /// True if this handler can decode the opcode - public override bool CanHandle(byte opcode) - { - return opcode == 0x80 || opcode == 0x81 || opcode == 0x83; - } - - /// - /// Decodes a Group 1 instruction - /// - /// The opcode of the instruction - /// The instruction object to populate - /// True if the instruction was successfully decoded - public override bool Decode(byte opcode, Instruction instruction) - { - int position = Decoder.GetPosition(); - - if (position >= Length) - { - return false; - } - - // Read the ModR/M byte - var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM(); - - // Determine the operation based on reg field - instruction.Mnemonic = OpcodeMap.Group1Operations[reg]; - - // Read the immediate value based on opcode - string immOperand; - position = Decoder.GetPosition(); - - switch (opcode) - { - case 0x80: // 8-bit immediate - if (position < Length) - { - byte imm8 = CodeBuffer[position]; - Decoder.SetPosition(position + 1); - immOperand = $"0x{imm8:X2}"; - } - else - { - immOperand = "???"; - } - break; - - case 0x81: // 32-bit immediate - if (position + 4 <= Length) - { - uint imm32 = BitConverter.ToUInt32(CodeBuffer, position); - Decoder.SetPosition(position + 4); - immOperand = $"0x{imm32:X8}"; - } - else - { - immOperand = "???"; - } - break; - - case 0x83: // 8-bit sign-extended immediate - if (position < Length) - { - sbyte imm8 = (sbyte)CodeBuffer[position]; - Decoder.SetPosition(position + 1); - immOperand = $"0x{imm8:X2}"; - } - else - { - immOperand = "???"; - } - break; - - default: - return false; - } - - // Set the operands - instruction.Operands = $"{destOperand}, {immOperand}"; - - return true; - } -} diff --git a/X86Disassembler/X86/Handlers/Group3Handler.cs b/X86Disassembler/X86/Handlers/Group3Handler.cs deleted file mode 100644 index 219e1f9..0000000 --- a/X86Disassembler/X86/Handlers/Group3Handler.cs +++ /dev/null @@ -1,99 +0,0 @@ -namespace X86Disassembler.X86.Handlers; - -/// -/// Handler for Group 3 instructions (TEST, NOT, NEG, MUL, IMUL, DIV, IDIV) -/// -public class Group3Handler : InstructionHandler -{ - /// - /// Initializes a new instance of the Group3Handler class - /// - /// The buffer containing the code to decode - /// The instruction decoder that owns this handler - /// The length of the buffer - public Group3Handler(byte[] codeBuffer, InstructionDecoder decoder, int length) - : base(codeBuffer, decoder, length) - { - } - - /// - /// Checks if this handler can decode the given opcode - /// - /// The opcode to check - /// True if this handler can decode the opcode - public override bool CanHandle(byte opcode) - { - return OpcodeMap.IsGroup3Opcode(opcode); - } - - /// - /// Decodes a Group 3 instruction - /// - /// The opcode of the instruction - /// The instruction object to populate - /// True if the instruction was successfully decoded - public override bool Decode(byte opcode, Instruction instruction) - { - int position = Decoder.GetPosition(); - - if (position >= Length) - { - return false; - } - - // Read the ModR/M byte - var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM(); - - // Determine the operation based on reg field - instruction.Mnemonic = OpcodeMap.Group3Operations[reg]; - - // For TEST instruction (reg = 0), we need to read an immediate value - if (reg == 0) // TEST - { - position = Decoder.GetPosition(); - string immOperand; - - switch (opcode) - { - case 0xF6: // 8-bit TEST - if (position < Length) - { - byte imm8 = CodeBuffer[position]; - Decoder.SetPosition(position + 1); - immOperand = $"0x{imm8:X2}"; - } - else - { - immOperand = "???"; - } - break; - - case 0xF7: // 32-bit TEST - if (position + 3 < Length) - { - uint imm32 = BitConverter.ToUInt32(CodeBuffer, position); - Decoder.SetPosition(position + 4); - immOperand = $"0x{imm32:X8}"; - } - else - { - immOperand = "???"; - } - break; - - default: - return false; - } - - // Set the operands - instruction.Operands = $"{destOperand}, {immOperand}"; - } - else - { - // For other Group 3 instructions (NOT, NEG, MUL, etc.), there's only one operand - instruction.Operands = destOperand; - } - - return true; - } -}