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


C# Mono.GetILProcessor方法代码示例

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


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

示例1: NopRet

    private static void NopRet(Mono.Cecil.Cil.MethodBody methodBody)
    {
      if (methodBody == null)
      {
        return;
      }

      var ilProcessor = methodBody.GetILProcessor();
      if (ilProcessor == null)
      {
        return;
      }

      foreach (var instruction in methodBody.Instructions.ToArray())
      {
        ilProcessor.Remove(instruction);
      }

      ilProcessor.Append(ilProcessor.Create(OpCodes.Nop));
      ilProcessor.Append(ilProcessor.Create(OpCodes.Ret));
    }
开发者ID:alienlab,项目名称:Alienlab.AssemblyShredder,代码行数:21,代码来源:Shredder.cs

示例2: CopyBlock

        public static void CopyBlock(Mono.Cecil.Cil.MethodBody body, int fromIndex, int startIndex, int endIndex)
        {
            //copy instructions startIndex to endIndex after fromIndex

            if (fromIndex >= startIndex - 1 && fromIndex <= endIndex) return;

            Collection<Instruction> instructions = body.Instructions;            
            Type icType = typeof(Collection<Instruction>);
            Instruction[] alIns = (Instruction[])icType.InvokeMember("items",
                 BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance,
                 null, instructions, null);

            int copyCount = endIndex - startIndex + 1;
            Instruction[] al = new Instruction[instructions.Count + copyCount];
            
            int curIndex = 0;
            //0 to fromIndex
            int count = fromIndex + 1;
            Array.Copy(alIns, 0, al, curIndex, count);
            curIndex += count;
            
            //startIndex to endIndex
            count = copyCount;
            ILProcessor ilp = body.GetILProcessor();
            for (int i = 0, j = curIndex; i < count; i++, j++)
            {
                Instruction ins = instructions[i + startIndex];
                al[j] = InsUtils.CreateInstruction(ins.OpCode, ins.Operand);
            }
            curIndex += count;

            //fromIndex+1 to end
            count = instructions.Count - fromIndex - 1;
            Array.Copy(alIns, fromIndex + 1, al, curIndex, count);
            curIndex += count;

            if (instructions.Count + copyCount != curIndex)
            {
                throw new ApplicationException("Internal CopyBlock error!");
            }

            al[fromIndex].Next = al[fromIndex + 1];
            int index;
            for (int i = 0; i < copyCount; i++)
            {
                index = i + fromIndex + 1;
                al[index].Previous = al[index - 1];
                al[index].Next = (index < al.Length - 1 ? al[index + 1] : null);
            }
            index = fromIndex + copyCount + 1;
            if (index < al.Length)
            {
                al[index].Previous = al[index - 1];
            }

            alIns = null;
            while (instructions.Count < al.Length)
            {
                instructions.Add(InsUtils.CreateInstruction(OpCodes.Nop, null));
            }
            alIns = (Instruction[])icType.InvokeMember("items",
                 BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance,
                 null, instructions, null);           
            Array.Copy(al, alIns, al.Length);
            instructions[instructions.Count - 1].Next = null;

            icType.InvokeMember("size",
                 BindingFlags.SetField | BindingFlags.NonPublic | BindingFlags.Instance,
                 null, instructions, new object[] { al.Length });

            InsUtils.ComputeOffsets(instructions);
        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:72,代码来源:DeobfUtils.cs


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