protected Instruction ReadOneInstruction_CIL(VirtualOpCode virtualInstruction) { OpCode opcode = virtualInstruction.OpCode.ToOpCode(); Instruction instruction = new Instruction(opcode); instruction.Offset = this.CurrentILOffset; instruction.OpCode = opcode; instruction.Operand = this.ReadOperand(instruction); if (instruction.OpCode.Code == Code.Switch) { var targets = (IList <UInt32>)instruction.Operand; this.CurrentILOffset += (UInt32)(instruction.OpCode.Size + 4 + (4 * targets.Count)); this.CurrentVirtualOffset += (UInt32)(4 + 4 + (4 * targets.Count)); } else { this.CurrentILOffset += (UInt32)instruction.GetSize(); this.CurrentVirtualOffset += (UInt32)virtualInstruction.GetSize(instruction.Operand); } this.CurrentInstructionOffset++; return(instruction); }
protected Instruction ReadOneInstruction_Special(VirtualOpCode virtualInstruction) { //this.Logger.Verbose(this, "Special Opcode ({0}, delegate MDToken = 0x{1:X8})", // virtualInstruction.SpecialOpCode.ToString(), // virtualInstruction.DelegateMethod.MDToken.Raw //); // Have a method for this? OpCode opcode = null; switch (virtualInstruction.SpecialOpCode) { case SpecialCode.Eaz_Call: opcode = Code.Call.ToOpCode(); // Or Callvirt? break; } if (opcode == null) { throw new Exception(String.Format( "Cannot convert SpecialOpCode to CIL OpCode: {0}", virtualInstruction.SpecialOpCode )); } Object operand = this.ReadSpecialOperand(virtualInstruction); Instruction instruction = new Instruction(opcode); instruction.Offset = this.CurrentILOffset; instruction.OpCode = opcode; instruction.Operand = operand; // this.ReadOperand(instruction); this.CurrentILOffset += (UInt32)instruction.GetSize(); this.CurrentVirtualOffset += (UInt32)virtualInstruction.GetSize(instruction.Operand); this.CurrentInstructionOffset++; return(instruction); }
protected Instruction ReadOneInstruction_Special(VirtualOpCode virtualInstruction) { //this.Logger.Verbose(this, "Special Opcode ({0}, delegate MDToken = 0x{1:X8})", // virtualInstruction.SpecialOpCode.ToString(), // virtualInstruction.DelegateMethod.MDToken.Raw //); // Have a method for this? OpCode opcode = null; switch(virtualInstruction.SpecialOpCode) { case SpecialCode.Eaz_Call: opcode = Code.Call.ToOpCode(); // Or Callvirt? break; } if(opcode == null) { throw new Exception(String.Format( "Cannot convert SpecialOpCode to CIL OpCode: {0}", virtualInstruction.SpecialOpCode )); } Object operand = this.ReadSpecialOperand(virtualInstruction); Instruction instruction = new Instruction(opcode); instruction.Offset = this.CurrentILOffset; instruction.OpCode = opcode; instruction.Operand = operand; // this.ReadOperand(instruction); this.CurrentILOffset += (UInt32)instruction.GetSize(); this.CurrentVirtualOffset += (UInt32)virtualInstruction.GetSize(instruction.Operand); this.CurrentInstructionOffset++; return instruction; }
protected Instruction ReadOneInstruction_CIL(VirtualOpCode virtualInstruction) { OpCode opcode = virtualInstruction.OpCode.ToOpCode(); Instruction instruction = new Instruction(opcode); instruction.Offset = this.CurrentILOffset; instruction.OpCode = opcode; instruction.Operand = this.ReadOperand(instruction); if (instruction.OpCode.Code == Code.Switch) { var targets = (IList<UInt32>)instruction.Operand; this.CurrentILOffset += (UInt32)(instruction.OpCode.Size + 4 + (4 * targets.Count)); this.CurrentVirtualOffset += (UInt32)(4 + 4 + (4 * targets.Count)); } else { this.CurrentILOffset += (UInt32)instruction.GetSize(); this.CurrentVirtualOffset += (UInt32)virtualInstruction.GetSize(instruction.Operand); } this.CurrentInstructionOffset++; return instruction; }