示例#1
0
            private static TypeDef PopulateContext(
                TypeDef typeDef,
                InjectHelper1.InjectHelper.InjectContext ctx)
            {
                IDnlibDef dnlibDef;
                TypeDef   typeDef1;

                if (!ctx.Map.TryGetValue((IDnlibDef)typeDef, out dnlibDef))
                {
                    typeDef1 = (TypeDef)InjectHelper1.InjectHelper.Clone(typeDef);
                    ctx.Map[(IDnlibDef)typeDef] = (IDnlibDef)typeDef1;
                }
                else
                {
                    typeDef1 = (TypeDef)dnlibDef;
                }
                foreach (TypeDef nestedType in (IEnumerable <TypeDef>)typeDef.NestedTypes)
                {
                    typeDef1.NestedTypes.Add(InjectHelper1.InjectHelper.PopulateContext(nestedType, ctx));
                }
                foreach (MethodDef method in (IEnumerable <MethodDef>)typeDef.Methods)
                {
                    typeDef1.Methods.Add((MethodDef)(ctx.Map[(IDnlibDef)method] = (IDnlibDef)InjectHelper1.InjectHelper.Clone(method)));
                }
                foreach (FieldDef field in (IEnumerable <FieldDef>)typeDef.Fields)
                {
                    typeDef1.Fields.Add((FieldDef)(ctx.Map[(IDnlibDef)field] = (IDnlibDef)InjectHelper1.InjectHelper.Clone(field)));
                }
                return(typeDef1);
            }
示例#2
0
 public static MethodDef Inject(MethodDef methodDef, ModuleDef target)
 {
     InjectHelper1.InjectHelper.InjectContext ctx = new InjectHelper1.InjectHelper.InjectContext(methodDef.Module, target);
     ctx.Map[(IDnlibDef)methodDef] = (IDnlibDef)InjectHelper1.InjectHelper.Clone(methodDef);
     InjectHelper1.InjectHelper.CopyMethodDef(methodDef, ctx);
     return((MethodDef)ctx.Map[(IDnlibDef)methodDef]);
 }
            // Token: 0x060000DB RID: 219 RVA: 0x000095EC File Offset: 0x000077EC
            private static TypeDef PopulateContext(TypeDef typeDef, InjectHelper1.InjectHelper.InjectContext ctx)
            {
                IDnlibDef dnlibDef;
                bool      flag = !ctx.Map.TryGetValue(typeDef, out dnlibDef);
                TypeDef   typeDef2;

                if (flag)
                {
                    typeDef2         = InjectHelper1.InjectHelper.Clone(typeDef);
                    ctx.Map[typeDef] = typeDef2;
                }
                else
                {
                    typeDef2 = (TypeDef)dnlibDef;
                }
                foreach (TypeDef typeDef3 in typeDef.NestedTypes)
                {
                    typeDef2.NestedTypes.Add(InjectHelper1.InjectHelper.PopulateContext(typeDef3, ctx));
                }
                foreach (MethodDef methodDef in typeDef.Methods)
                {
                    typeDef2.Methods.Add((MethodDef)(ctx.Map[methodDef] = InjectHelper1.InjectHelper.Clone(methodDef)));
                }
                foreach (FieldDef fieldDef in typeDef.Fields)
                {
                    typeDef2.Fields.Add((FieldDef)(ctx.Map[fieldDef] = InjectHelper1.InjectHelper.Clone(fieldDef)));
                }
                return(typeDef2);
            }
示例#4
0
 public static TypeDef Inject(TypeDef typeDef, ModuleDef target)
 {
     InjectHelper1.InjectHelper.InjectContext ctx = new InjectHelper1.InjectHelper.InjectContext(typeDef.Module, target);
     InjectHelper1.InjectHelper.PopulateContext(typeDef, ctx);
     InjectHelper1.InjectHelper.Copy(typeDef, ctx, true);
     return((TypeDef)ctx.Map[(IDnlibDef)typeDef]);
 }
 // Token: 0x060000E1 RID: 225 RVA: 0x00009EFC File Offset: 0x000080FC
 public static MethodDef Inject(MethodDef methodDef, ModuleDef target)
 {
     InjectHelper1.InjectHelper.InjectContext injectContext = new InjectHelper1.InjectHelper.InjectContext(methodDef.Module, target);
     injectContext.Map[methodDef] = InjectHelper1.InjectHelper.Clone(methodDef);
     InjectHelper1.InjectHelper.CopyMethodDef(methodDef, injectContext);
     return((MethodDef)injectContext.Map[methodDef]);
 }
 // Token: 0x060000E0 RID: 224 RVA: 0x00009EB8 File Offset: 0x000080B8
 public static TypeDef Inject(TypeDef typeDef, ModuleDef target)
 {
     InjectHelper1.InjectHelper.InjectContext injectContext = new InjectHelper1.InjectHelper.InjectContext(typeDef.Module, target);
     InjectHelper1.InjectHelper.PopulateContext(typeDef, injectContext);
     InjectHelper1.InjectHelper.Copy(typeDef, injectContext, true);
     return((TypeDef)injectContext.Map[typeDef]);
 }
示例#7
0
            private static void CopyTypeDef(TypeDef typeDef, InjectHelper1.InjectHelper.InjectContext ctx)
            {
                TypeDef typeDef1 = (TypeDef)ctx.Map[(IDnlibDef)typeDef];

                typeDef1.BaseType = (ITypeDefOrRef)ctx.Importer.Import((IType)typeDef.BaseType);
                foreach (InterfaceImpl interfaceImpl in (IEnumerable <InterfaceImpl>)typeDef.Interfaces)
                {
                    typeDef1.Interfaces.Add((InterfaceImpl) new InterfaceImplUser((ITypeDefOrRef)ctx.Importer.Import((IType)interfaceImpl.Interface)));
                }
            }
            // Token: 0x060000DC RID: 220 RVA: 0x00009758 File Offset: 0x00007958
            private static void CopyTypeDef(TypeDef typeDef, InjectHelper1.InjectHelper.InjectContext ctx)
            {
                TypeDef typeDef2 = (TypeDef)ctx.Map[typeDef];

                typeDef2.BaseType = (ITypeDefOrRef)ctx.Importer.Import(typeDef.BaseType);
                foreach (InterfaceImpl interfaceImpl in typeDef.Interfaces)
                {
                    typeDef2.Interfaces.Add(new InterfaceImplUser((ITypeDefOrRef)ctx.Importer.Import(interfaceImpl.Interface)));
                }
            }
 // Token: 0x060000E2 RID: 226 RVA: 0x00009F48 File Offset: 0x00008148
 public static IEnumerable <IDnlibDef> Inject(TypeDef typeDef, TypeDef newType, ModuleDef target)
 {
     InjectHelper1.InjectHelper.InjectContext injectContext = new InjectHelper1.InjectHelper.InjectContext(typeDef.Module, target);
     injectContext.Map[typeDef] = newType;
     InjectHelper1.InjectHelper.PopulateContext(typeDef, injectContext);
     InjectHelper1.InjectHelper.Copy(typeDef, injectContext, false);
     return(injectContext.Map.Values.Except(new TypeDef[]
     {
         newType
     }));
 }
示例#10
0
 public static IEnumerable <IDnlibDef> Inject(
     TypeDef typeDef,
     TypeDef newType,
     ModuleDef target)
 {
     InjectHelper1.InjectHelper.InjectContext ctx = new InjectHelper1.InjectHelper.InjectContext(typeDef.Module, target);
     ctx.Map[(IDnlibDef)typeDef] = (IDnlibDef)newType;
     InjectHelper1.InjectHelper.PopulateContext(typeDef, ctx);
     InjectHelper1.InjectHelper.Copy(typeDef, ctx, false);
     return(ctx.Map.Values.Except <IDnlibDef>((IEnumerable <IDnlibDef>) new TypeDef[1]
     {
         newType
     }));
 }
 // Token: 0x060000DF RID: 223 RVA: 0x00009DD0 File Offset: 0x00007FD0
 private static void Copy(TypeDef typeDef, InjectHelper1.InjectHelper.InjectContext ctx, bool copySelf)
 {
     if (copySelf)
     {
         InjectHelper1.InjectHelper.CopyTypeDef(typeDef, ctx);
     }
     foreach (TypeDef typeDef2 in typeDef.NestedTypes)
     {
         InjectHelper1.InjectHelper.Copy(typeDef2, ctx, true);
     }
     foreach (MethodDef methodDef in typeDef.Methods)
     {
         InjectHelper1.InjectHelper.CopyMethodDef(methodDef, ctx);
     }
     foreach (FieldDef fieldDef in typeDef.Fields)
     {
         InjectHelper1.InjectHelper.CopyFieldDef(fieldDef, ctx);
     }
 }
示例#12
0
 private static void Copy(
     TypeDef typeDef,
     InjectHelper1.InjectHelper.InjectContext ctx,
     bool copySelf)
 {
     if (copySelf)
     {
         InjectHelper1.InjectHelper.CopyTypeDef(typeDef, ctx);
     }
     foreach (TypeDef nestedType in (IEnumerable <TypeDef>)typeDef.NestedTypes)
     {
         InjectHelper1.InjectHelper.Copy(nestedType, ctx, true);
     }
     foreach (MethodDef method in (IEnumerable <MethodDef>)typeDef.Methods)
     {
         InjectHelper1.InjectHelper.CopyMethodDef(method, ctx);
     }
     foreach (FieldDef field in (IEnumerable <FieldDef>)typeDef.Fields)
     {
         InjectHelper1.InjectHelper.CopyFieldDef(field, ctx);
     }
 }
示例#13
0
            private static void CopyMethodDef(
                MethodDef methodDef,
                InjectHelper1.InjectHelper.InjectContext ctx)
            {
                MethodDef methodDef1 = (MethodDef)ctx.Map[(IDnlibDef)methodDef];

                methodDef1.Signature = ctx.Importer.Import(methodDef.Signature);
                methodDef1.Parameters.UpdateParameterTypes();
                if (methodDef.ImplMap != null)
                {
                    methodDef1.ImplMap = (ImplMap) new ImplMapUser((ModuleRef) new ModuleRefUser(ctx.TargetModule, methodDef.ImplMap.Module.Name), methodDef.ImplMap.Name, methodDef.ImplMap.Attributes);
                }
                foreach (CustomAttribute customAttribute in (LazyList <CustomAttribute>)methodDef.CustomAttributes)
                {
                    methodDef1.CustomAttributes.Add(new CustomAttribute((ICustomAttributeType)ctx.Importer.Import((IMethod)customAttribute.Constructor)));
                }
                if (!methodDef.HasBody)
                {
                    return;
                }
                methodDef1.Body          = new CilBody(methodDef.Body.InitLocals, (IList <Instruction>) new List <Instruction>(), (IList <ExceptionHandler>) new List <ExceptionHandler>(), (IList <Local>) new List <Local>());
                methodDef1.Body.MaxStack = methodDef.Body.MaxStack;
                Dictionary <object, object> bodyMap = new Dictionary <object, object>();

                foreach (Local variable in methodDef.Body.Variables)
                {
                    Local local = new Local(ctx.Importer.Import(variable.Type));
                    methodDef1.Body.Variables.Add(local);
                    local.Name                = variable.Name;
                    local.PdbAttributes       = variable.PdbAttributes;
                    bodyMap[(object)variable] = (object)local;
                }
                foreach (Instruction instruction1 in (IEnumerable <Instruction>)methodDef.Body.Instructions)
                {
                    Instruction instruction2 = new Instruction(instruction1.OpCode, instruction1.Operand);
                    instruction2.SequencePoint = instruction1.SequencePoint;
                    if (instruction2.Operand is IType)
                    {
                        instruction2.Operand = (object)ctx.Importer.Import((IType)instruction2.Operand);
                    }
                    else if (instruction2.Operand is IMethod)
                    {
                        instruction2.Operand = (object)ctx.Importer.Import((IMethod)instruction2.Operand);
                    }
                    else if (instruction2.Operand is IField)
                    {
                        instruction2.Operand = (object)ctx.Importer.Import((IField)instruction2.Operand);
                    }
                    methodDef1.Body.Instructions.Add(instruction2);
                    bodyMap[(object)instruction1] = (object)instruction2;
                }
                foreach (Instruction instruction in (IEnumerable <Instruction>)methodDef1.Body.Instructions)
                {
                    if (instruction.Operand != null && bodyMap.ContainsKey(instruction.Operand))
                    {
                        instruction.Operand = bodyMap[instruction.Operand];
                    }
                    else if (instruction.Operand is Instruction[])
                    {
                        instruction.Operand = (object)((IEnumerable <Instruction>)(Instruction[]) instruction.Operand).Select <Instruction, Instruction>((Func <Instruction, Instruction>)(target => (Instruction)bodyMap[(object)target])).ToArray <Instruction>();
                    }
                }
                foreach (ExceptionHandler exceptionHandler in (IEnumerable <ExceptionHandler>)methodDef.Body.ExceptionHandlers)
                {
                    methodDef1.Body.ExceptionHandlers.Add(new ExceptionHandler(exceptionHandler.HandlerType)
                    {
                        CatchType    = exceptionHandler.CatchType == null ? (ITypeDefOrRef)null : (ITypeDefOrRef)ctx.Importer.Import((IType)exceptionHandler.CatchType),
                        TryStart     = (Instruction)bodyMap[(object)exceptionHandler.TryStart],
                        TryEnd       = (Instruction)bodyMap[(object)exceptionHandler.TryEnd],
                        HandlerStart = (Instruction)bodyMap[(object)exceptionHandler.HandlerStart],
                        HandlerEnd   = (Instruction)bodyMap[(object)exceptionHandler.HandlerEnd],
                        FilterStart  = exceptionHandler.FilterStart == null ? (Instruction)null : (Instruction)bodyMap[(object)exceptionHandler.FilterStart]
                    });
                }
                methodDef1.Body.SimplifyMacros((IList <Parameter>)methodDef1.Parameters);
            }
示例#14
0
 private static void CopyFieldDef(
     FieldDef fieldDef,
     InjectHelper1.InjectHelper.InjectContext ctx)
 {
     ((FieldDef)ctx.Map[(IDnlibDef)fieldDef]).Signature = ctx.Importer.Import(fieldDef.Signature);
 }
            // Token: 0x060000DD RID: 221 RVA: 0x00009800 File Offset: 0x00007A00
            private static void CopyMethodDef(MethodDef methodDef, InjectHelper1.InjectHelper.InjectContext ctx)
            {
                MethodDef methodDef2 = (MethodDef)ctx.Map[methodDef];

                methodDef2.Signature = ctx.Importer.Import(methodDef.Signature);
                methodDef2.Parameters.UpdateParameterTypes();
                bool flag = methodDef.ImplMap != null;

                if (flag)
                {
                    methodDef2.ImplMap = new ImplMapUser(new ModuleRefUser(ctx.TargetModule, methodDef.ImplMap.Module.Name), methodDef.ImplMap.Name, methodDef.ImplMap.Attributes);
                }
                foreach (CustomAttribute customAttribute in methodDef.CustomAttributes)
                {
                    methodDef2.CustomAttributes.Add(new CustomAttribute((ICustomAttributeType)ctx.Importer.Import(customAttribute.Constructor)));
                }
                bool hasBody = methodDef.HasBody;

                if (hasBody)
                {
                    methodDef2.Body          = new CilBody(methodDef.Body.InitLocals, new List <Instruction>(), new List <ExceptionHandler>(), new List <Local>());
                    methodDef2.Body.MaxStack = methodDef.Body.MaxStack;
                    Dictionary <object, object> bodyMap = new Dictionary <object, object>();
                    foreach (Local local in methodDef.Body.Variables)
                    {
                        Local local2 = new Local(ctx.Importer.Import(local.Type));
                        methodDef2.Body.Variables.Add(local2);
                        local2.Name          = local.Name;
                        local2.PdbAttributes = local.PdbAttributes;
                        bodyMap[local]       = local2;
                    }
                    foreach (Instruction instruction in methodDef.Body.Instructions)
                    {
                        Instruction instruction2 = new Instruction(instruction.OpCode, instruction.Operand);
                        instruction2.SequencePoint = instruction.SequencePoint;
                        bool flag2 = instruction2.Operand is IType;
                        if (flag2)
                        {
                            instruction2.Operand = ctx.Importer.Import((IType)instruction2.Operand);
                        }
                        else
                        {
                            bool flag3 = instruction2.Operand is IMethod;
                            if (flag3)
                            {
                                instruction2.Operand = ctx.Importer.Import((IMethod)instruction2.Operand);
                            }
                            else
                            {
                                bool flag4 = instruction2.Operand is IField;
                                if (flag4)
                                {
                                    instruction2.Operand = ctx.Importer.Import((IField)instruction2.Operand);
                                }
                            }
                        }
                        methodDef2.Body.Instructions.Add(instruction2);
                        bodyMap[instruction] = instruction2;
                    }
                    Func <Instruction, Instruction> < > 9__0;
                    foreach (Instruction instruction3 in methodDef2.Body.Instructions)
                    {
                        bool flag5 = instruction3.Operand != null && bodyMap.ContainsKey(instruction3.Operand);
                        if (flag5)
                        {
                            instruction3.Operand = bodyMap[instruction3.Operand];
                        }
                        else
                        {
                            bool flag6 = instruction3.Operand is Instruction[];
                            if (flag6)
                            {
                                Instruction instruction4 = instruction3;
                                IEnumerable <Instruction>       source = (Instruction[])instruction3.Operand;
                                Func <Instruction, Instruction> selector;
                                if ((selector = < > 9__0) == null)
                                {
                                    selector = (< > 9__0 = ((Instruction target) => (Instruction)bodyMap[target]));
                                }
                                instruction4.Operand = source.Select(selector).ToArray <Instruction>();
                            }
                        }
                    }
                    foreach (ExceptionHandler exceptionHandler in methodDef.Body.ExceptionHandlers)
                    {
                        methodDef2.Body.ExceptionHandlers.Add(new ExceptionHandler(exceptionHandler.HandlerType)
                        {
                            CatchType    = ((exceptionHandler.CatchType == null) ? null : ((ITypeDefOrRef)ctx.Importer.Import(exceptionHandler.CatchType))),
                            TryStart     = (Instruction)bodyMap[exceptionHandler.TryStart],
                            TryEnd       = (Instruction)bodyMap[exceptionHandler.TryEnd],
                            HandlerStart = (Instruction)bodyMap[exceptionHandler.HandlerStart],
                            HandlerEnd   = (Instruction)bodyMap[exceptionHandler.HandlerEnd],
                            FilterStart  = ((exceptionHandler.FilterStart == null) ? null : ((Instruction)bodyMap[exceptionHandler.FilterStart]))
                        });
                    }
                    methodDef2.Body.SimplifyMacros(methodDef2.Parameters);
                }
            }
            // Token: 0x060000DE RID: 222 RVA: 0x00009D94 File Offset: 0x00007F94
            private static void CopyFieldDef(FieldDef fieldDef, InjectHelper1.InjectHelper.InjectContext ctx)
            {
                FieldDef fieldDef2 = (FieldDef)ctx.Map[fieldDef];

                fieldDef2.Signature = ctx.Importer.Import(fieldDef.Signature);
            }