/* Copyright (C) 2011-2015 de4dot@gmail.com This file is part of de4dot. de4dot is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. de4dot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with de4dot. If not, see . */ using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using dnlib.DotNet.Emit; using dnlib.DotNet; using de4dot.blocks; using OpCode = dnlib.DotNet.Emit.OpCode; using OpCodes = dnlib.DotNet.Emit.OpCodes; using OperandType = dnlib.DotNet.Emit.OperandType; using ROpCode = System.Reflection.Emit.OpCode; using ROpCodes = System.Reflection.Emit.OpCodes; namespace AssemblyData.methodsrewriter { class CodeGenerator { static Dictionary dnlibToReflection = new Dictionary(); static CodeGenerator() { var refDict = new Dictionary(0x100); foreach (var f in typeof(ROpCodes).GetFields(BindingFlags.Static | BindingFlags.Public)) { if (f.FieldType != typeof(ROpCode)) continue; var ropcode = (ROpCode)f.GetValue(null); refDict[ropcode.Value] = ropcode; } foreach (var f in typeof(OpCodes).GetFields(BindingFlags.Static | BindingFlags.Public)) { if (f.FieldType != typeof(OpCode)) continue; var opcode = (OpCode)f.GetValue(null); ROpCode ropcode; if (!refDict.TryGetValue(opcode.Value, out ropcode)) continue; dnlibToReflection[opcode] = ropcode; } } IMethodsRewriter methodsRewriter; string methodName; IList allInstructions; IList allExceptionHandlers; ILGenerator ilg; Type methodReturnType; Type[] methodParameters; Type delegateType; MMethod methodInfo; LocalBuilder tempObjLocal; LocalBuilder tempObjArrayLocal; int thisArgIndex; List locals; List