当前位置: 首页>>代码示例>>C#>>正文


C# Block.replace方法代码示例

本文整理汇总了C#中de4dot.blocks.Block.replace方法的典型用法代码示例。如果您正苦于以下问题:C# Block.replace方法的具体用法?C# Block.replace怎么用?C# Block.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在de4dot.blocks.Block的用法示例。


在下文中一共展示了Block.replace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: addInitializeArrayCode

 public void addInitializeArrayCode(Block block, int start, int numToRemove, ITypeDefOrRef elementType, byte[] data)
 {
     int index = start;
     block.replace(index++, numToRemove, Instruction.CreateLdcI4(data.Length / elementType.ToTypeSig().ElementType.GetPrimitiveSize()));
     block.insert(index++, OpCodes.Newarr.ToInstruction(elementType));
     block.insert(index++, OpCodes.Dup.ToInstruction());
     block.insert(index++, OpCodes.Ldtoken.ToInstruction((IField)create(data)));
     block.insert(index++, OpCodes.Call.ToInstruction((IMethod)InitializeArrayMethod));
 }
开发者ID:GodLesZ,项目名称:ConfuserDeobfuscator,代码行数:9,代码来源:InitializedDataCreator.cs

示例2: addInitializeArrayCode

 public void addInitializeArrayCode(Block block, int start, int numToRemove, TypeReference elementType, byte[] data)
 {
     int index = start;
     block.replace(index++, numToRemove, DotNetUtils.createLdci4(data.Length / elementType.PrimitiveSize));
     block.insert(index++, Instruction.Create(OpCodes.Newarr, elementType));
     block.insert(index++, Instruction.Create(OpCodes.Dup));
     block.insert(index++, Instruction.Create(OpCodes.Ldtoken, create(data)));
     block.insert(index++, Instruction.Create(OpCodes.Call, InitializeArrayMethod));
 }
开发者ID:Joelone,项目名称:de4dot,代码行数:9,代码来源:InitializedDataCreator.cs

示例3: update

        void update(Block block, NewMethodInfo currentMethodInfo)
        {
            var instrs = block.Instructions;
            for (int i = 0; i < instrs.Count; i++) {
                var instr = instrs[i];
                if (instr.OpCode == OpCodes.Newobj) {
                    var ctor = (IMethod)instr.Operand;
                    var ctorTypeFullName = ctor.DeclaringType.FullName;
                    if (ctorTypeFullName == "System.Diagnostics.StackTrace") {
                        insertLoadThis(block, i + 1);
                        insertCallOurMethod(block, i + 2, "static_rtFixStackTrace");
                        i += 2;
                        continue;
                    }
                    else if (ctorTypeFullName == "System.Diagnostics.StackFrame") {
                        insertLoadThis(block, i + 1);
                        insertCallOurMethod(block, i + 2, "static_rtFixStackFrame");
                        i += 2;
                        continue;
                    }
                }

                if (instr.OpCode == OpCodes.Call || instr.OpCode == OpCodes.Callvirt) {
                    var calledMethod = (IMethod)instr.Operand;
                    if (calledMethod.DeclaringType.DefinitionAssembly.IsCorLib()) {
                        var calledMethodFullName = calledMethod.FullName;
                        if (calledMethodFullName == "System.Reflection.Assembly System.Reflection.Assembly::GetAssembly(System.Type)") {
                            block.replace(i, 1, OpCodes.Nop.ToInstruction());
                            insertLoadThis(block, i + 1);
                            insertCallOurMethod(block, i + 2, "static_rtGetAssembly_TypeArg");
                            i += 2;
                            continue;
                        }
                        else if (calledMethodFullName == "System.Reflection.Assembly System.Reflection.Assembly::GetCallingAssembly()" ||
                                calledMethodFullName == "System.Reflection.Assembly System.Reflection.Assembly::GetEntryAssembly()" ||
                                calledMethodFullName == "System.Reflection.Assembly System.Reflection.Assembly::GetExecutingAssembly()") {
                            block.replace(i, 1, OpCodes.Nop.ToInstruction());
                            insertLoadThis(block, i + 1);
                            block.insert(i + 2, OpCodes.Ldc_I4.ToInstruction(currentMethodInfo.delegateIndex));
                            insertCallOurMethod(block, i + 3, "rtGetAssembly");
                            i += 3;
                            continue;
                        }
                    }

                    var method = Resolver.getMethod((IMethod)instr.Operand);
                    if (method != null) {
                        createMethod(method.methodBase);
                        var newMethodInfo = realMethodToNewMethod[method.methodBase];

                        block.replace(i, 1, OpCodes.Nop.ToInstruction());
                        int n = i + 1;

                        // Pop all pushed args to a temp array
                        var mparams = getParameters(method.methodDef);
                        if (mparams.Count > 0) {
                            block.insert(n++, OpCodes.Ldc_I4.ToInstruction(mparams.Count));
                            var objectType = method.methodDef.DeclaringType.Module.CorLibTypes.Object;
                            block.insert(n++, OpCodes.Newarr.ToInstruction(objectType));
                            block.insert(n++, create(OpCodes.Stloc, new Operand(Operand.Type.TempObjArray)));

                            for (int j = mparams.Count - 1; j >= 0; j--) {
                                var argType = mparams[j];
                                if (argType.RemovePinnedAndModifiers().IsValueType)
                                    block.insert(n++, OpCodes.Box.ToInstruction(((TypeDefOrRefSig)argType).TypeDefOrRef));
                                block.insert(n++, create(OpCodes.Stloc, new Operand(Operand.Type.TempObj)));
                                block.insert(n++, create(OpCodes.Ldloc, new Operand(Operand.Type.TempObjArray)));
                                block.insert(n++, OpCodes.Ldc_I4.ToInstruction(j));
                                block.insert(n++, create(OpCodes.Ldloc, new Operand(Operand.Type.TempObj)));
                                block.insert(n++, OpCodes.Stelem_Ref.ToInstruction());
                            }
                        }

                        // Push delegate instance
                        insertLoadThis(block, n++);
                        block.insert(n++, OpCodes.Ldc_I4.ToInstruction(newMethodInfo.delegateIndex));
                        insertCallOurMethod(block, n++, "rtGetDelegateInstance");
                        block.insert(n++, create(OpCodes.Castclass, new Operand(Operand.Type.ReflectionType, newMethodInfo.delegateType)));

                        // Push all popped args
                        if (mparams.Count > 0) {
                            for (int j = 0; j < mparams.Count; j++) {
                                block.insert(n++, create(OpCodes.Ldloc, new Operand(Operand.Type.TempObjArray)));
                                block.insert(n++, OpCodes.Ldc_I4.ToInstruction(j));
                                block.insert(n++, OpCodes.Ldelem_Ref.ToInstruction());
                                var argType = mparams[j];
                                if (argType.RemovePinnedAndModifiers().IsValueType)
                                    block.insert(n++, OpCodes.Unbox_Any.ToInstruction(((TypeDefOrRefSig)argType).TypeDefOrRef));
                                else {
                                    // Don't cast it to its correct type. This will sometimes cause
                                    // an exception in some EF obfuscated assembly since we'll be
                                    // trying to cast a System.Reflection.AssemblyName type to some
                                    // other type.
                                    // block.insert(n++, Instruction.Create(OpCodes.Castclass, argType.ToTypeDefOrRef()));
                                }
                            }
                        }

                        insertLoadThis(block, n++);
                        block.insert(n++, create(OpCodes.Call, new Operand(Operand.Type.NewMethod, method.methodBase)));
//.........这里部分代码省略.........
开发者ID:n017,项目名称:ConfuserDeobfuscator,代码行数:101,代码来源:MethodsRewriter.cs

示例4: update

        void update(Block block, NewMethodInfo currentMethodInfo)
        {
            var instrs = block.Instructions;
            for (int i = 0; i < instrs.Count; i++) {
                var instr = instrs[i];
                if (instr.OpCode == OpCodes.Newobj) {
                    var ctor = (MethodReference)instr.Operand;
                    if (MemberReferenceHelper.verifyType(ctor.DeclaringType, "mscorlib", "System.Diagnostics.StackTrace")) {
                        insertLoadThis(block, i + 1);
                        insertCallOurMethod(block, i + 2, "static_rtFixStackTrace");
                        i += 2;
                        continue;
                    }
                    else if (MemberReferenceHelper.verifyType(ctor.DeclaringType, "mscorlib", "System.Diagnostics.StackFrame")) {
                        insertLoadThis(block, i + 1);
                        insertCallOurMethod(block, i + 2, "static_rtFixStackFrame");
                        i += 2;
                        continue;
                    }
                }

                if (instr.OpCode == OpCodes.Call || instr.OpCode == OpCodes.Callvirt) {
                    var calledMethod = (MethodReference)instr.Operand;
                    if (DotNetUtils.isSameAssembly(calledMethod.DeclaringType, "mscorlib")) {
                        if (calledMethod.ToString() == "System.Reflection.Assembly System.Reflection.Assembly::GetAssembly(System.Type)") {
                            block.replace(i, 1, Instruction.Create(OpCodes.Nop));
                            insertLoadThis(block, i + 1);
                            insertCallOurMethod(block, i + 2, "static_rtGetAssembly_TypeArg");
                            i += 2;
                            continue;
                        }
                        else if (calledMethod.ToString() == "System.Reflection.Assembly System.Reflection.Assembly::GetCallingAssembly()" ||
                                calledMethod.ToString() == "System.Reflection.Assembly System.Reflection.Assembly::GetEntryAssembly()" ||
                                calledMethod.ToString() == "System.Reflection.Assembly System.Reflection.Assembly::GetExecutingAssembly()") {
                            block.replace(i, 1, Instruction.Create(OpCodes.Nop));
                            insertLoadThis(block, i + 1);
                            block.insert(i + 2, Instruction.Create(OpCodes.Ldc_I4, currentMethodInfo.delegateIndex));
                            insertCallOurMethod(block, i + 3, "rtGetAssembly");
                            i += 3;
                            continue;
                        }
                    }

                    var method = Resolver.getMethod((MethodReference)instr.Operand);
                    if (method != null) {
                        createMethod(method.methodBase);
                        var newMethodInfo = realMethodToNewMethod[method.methodBase];

                        block.replace(i, 1, Instruction.Create(OpCodes.Nop));
                        int n = i + 1;

                        // Pop all pushed args to a temp array
                        var mparams = getParameters(method.methodDefinition);
                        if (mparams.Count > 0) {
                            block.insert(n++, Instruction.Create(OpCodes.Ldc_I4, mparams.Count));
                            var objectType = method.methodDefinition.Module.TypeSystem.Object;
                            block.insert(n++, Instruction.Create(OpCodes.Newarr, objectType));
                            block.insert(n++, create(OpCodes.Stloc, new Operand(Operand.Type.TempObjArray)));

                            for (int j = mparams.Count - 1; j >= 0; j--) {
                                var argType = mparams[j];
                                if (argType.IsValueType)
                                    block.insert(n++, Instruction.Create(OpCodes.Box, argType));
                                block.insert(n++, create(OpCodes.Stloc, new Operand(Operand.Type.TempObj)));
                                block.insert(n++, create(OpCodes.Ldloc, new Operand(Operand.Type.TempObjArray)));
                                block.insert(n++, Instruction.Create(OpCodes.Ldc_I4, j));
                                block.insert(n++, create(OpCodes.Ldloc, new Operand(Operand.Type.TempObj)));
                                block.insert(n++, Instruction.Create(OpCodes.Stelem_Ref));
                            }
                        }

                        // Push delegate instance
                        insertLoadThis(block, n++);
                        block.insert(n++, Instruction.Create(OpCodes.Ldc_I4, newMethodInfo.delegateIndex));
                        insertCallOurMethod(block, n++, "rtGetDelegateInstance");
                        block.insert(n++, create(OpCodes.Castclass, new Operand(Operand.Type.ReflectionType, newMethodInfo.delegateType)));

                        // Push all popped args
                        if (mparams.Count > 0) {
                            for (int j = 0; j < mparams.Count; j++) {
                                block.insert(n++, create(OpCodes.Ldloc, new Operand(Operand.Type.TempObjArray)));
                                block.insert(n++, Instruction.Create(OpCodes.Ldc_I4, j));
                                block.insert(n++, Instruction.Create(OpCodes.Ldelem_Ref));
                                var argType = mparams[j];
                                if (argType.IsValueType)
                                    block.insert(n++, Instruction.Create(OpCodes.Unbox_Any, argType));
                                else {
                                    // Don't cast it to its correct type. This will sometimes cause
                                    // an exception in some EF obfuscated assembly since we'll be
                                    // trying to cast a System.Reflection.AssemblyName type to some
                                    // other type.
                                    // block.insert(n++, Instruction.Create(OpCodes.Castclass, argType));
                                }
                            }
                        }

                        insertLoadThis(block, n++);
                        block.insert(n++, create(OpCodes.Call, new Operand(Operand.Type.NewMethod, method.methodBase)));
                        i = n - 1;
                        continue;
//.........这里部分代码省略.........
开发者ID:Perplexity,项目名称:de4dot,代码行数:101,代码来源:MethodsRewriter.cs


注:本文中的de4dot.blocks.Block.replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。