/// <summary> /// Creates an instance of a x86 instruction with two operands. /// </summary> /// <param name="assembly">The parent assembly.</param> /// <param name="opcode">The opcode to use.</param> /// <param name="operand1">The first operand to use.</param> /// <param name="operand2">The second operand to use.</param> /// <returns></returns> public static x86Instruction Create(Win32Assembly assembly, x86OpCode opcode, Operand operand1, Operand operand2) { x86Instruction newInstruction = new x86Instruction(assembly); newInstruction.OpCode = opcode; newInstruction.operand1 = operand1; newInstruction.operand2 = operand2; newInstruction.GenerateBytes(); return newInstruction; }
internal void ProcessOperandBytes(x86Instruction instruction) { uint nextOffset = (uint)(instruction.Offset.FileOffset + instruction.Size); Operand operandValue = null; switch (instruction.OpCode.GetNormalOperandType()) { case x86OperandType.Byte: operandValue = new Operand(instruction.operandbytes[0]); break; case x86OperandType.Word: operandValue = new Operand(BitConverter.ToInt16(instruction.operandbytes, 0)); break; case x86OperandType.WordAndByte: break; // TODO case x86OperandType.Dword: operandValue = new Operand(BitConverter.ToUInt32(instruction.operandbytes, 0)); break; case x86OperandType.Fword: break; // TODO case x86OperandType.Qword: operandValue = new Operand(BitConverter.ToUInt64(instruction.operandbytes, 0)); break; case x86OperandType.InstructionAddress: operandValue = CreateTargetOffset((uint)(nextOffset + BitConverter.ToInt32(instruction.operandbytes, 0))); break; case x86OperandType.ShortInstructionAddress: operandValue = CreateTargetOffset((uint)(nextOffset + ASMGlobals.ByteToSByte(instruction.operandbytes[0]))); break; case x86OperandType.Register32: DecodeSingleRegister(ref instruction, instruction.code._opcodeBytes[instruction.code._opcodeBytes.Length - 1]); break; case x86OperandType.Instruction: // opcode is prefix. x86Instruction nextInstruction = DisassembleNextInstruction(); operandValue = new Operand(nextInstruction); instruction.operandbytes = ASMGlobals.MergeBytes(nextInstruction.code.OpCodeBytes, nextInstruction.operandbytes); instruction.code._operandLength = nextInstruction.Size; break; case x86OperandType.None: if (instruction.code.IsBasedOn(x86OpCodes.Unknown)) operandValue = new Operand(instruction.code._opcodeBytes[0]); break; } if (operandValue != null) { if (instruction.operand1 != null) instruction.operand2 = operandValue; else instruction.operand1 = operandValue; } }
/// <summary> /// Creates an instance of a x86 instruction with a single operand. /// </summary> /// <param name="assembly">The parent assembly.</param> /// <param name="opcode">The opcode to use.</param> /// <param name="operand">The operand to use.</param> /// <returns></returns> public static x86Instruction Create(Win32Assembly assembly, x86OpCode opcode, Operand operand) { return Create(assembly, opcode, operand, null); }
/// <summary> /// Creates an instance of a x86 instruction with a single operand. /// </summary> /// <param name="assembly">The parent assembly.</param> /// <param name="opcode">The opcode to use.</param> /// <param name="operand">The operand to use.</param> /// <returns></returns> public static x86Instruction Create(x86OpCode opcode, Operand operand) { return Create(opcode, operand, null); }