• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Cecil.ModuleDefinition类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ModuleDefinition类属于Mono.Cecil命名空间,在下文中一共展示了ModuleDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Phase1

            public void Phase1(ModuleDefinition mod)
            {
                AssemblyDefinition i = AssemblyDefinition.ReadAssembly(typeof(Iid).Assembly.Location);
                i.MainModule.ReadSymbols();
                root = CecilHelper.Inject(mod, i.MainModule.GetType("AntiTamperMem"));
                mod.Types.Add(root);
                MethodDefinition cctor = mod.GetType("<Module>").GetStaticConstructor();
                cctor.Body.GetILProcessor().InsertBefore(0, Instruction.Create(OpCodes.Call, root.Methods.FirstOrDefault(mtd => mtd.Name == "Initalize")));

                Mutator mutator = new Mutator();
                mutator.IntKeys = new int[]
                {
                    key0,
                    (int)sectName.ToCharArray().Sum(_ => (int)_),
                    key2,
                    key3,
                    key4,
                    key5,
                    key6
                };
                mutator.LongKeys = new long[] { key1 };
                mutator.Mutate(Confuser.Random, root);

                root.Name = Confuser.ObfuscationHelper.GetRandomName();
                root.Namespace = "";
                AddHelper(root, HelperAttribute.NoInjection);
                foreach (MethodDefinition mtdDef in root.Methods)
                {
                    mtdDef.Name = Confuser.ObfuscationHelper.GetRandomName();
                    AddHelper(mtdDef, HelperAttribute.NoInjection);
                }
                Confuser.Database.AddEntry("AntiTamper", "Helper", root.FullName);
            }
开发者ID:n017,项目名称:Confuser,代码行数:33,代码来源:AntiTamperConfusion.Mem.cs


示例2: PatchModule

 public static void PatchModule(ModuleDefinition baseModule)
 {
     var type = baseModule.AllNestedTypes().Single(t => t.FullName == "TowerFall.TeamSelectOverlay");
     var method = type.Methods.Single(m => m.FullName == "System.Void TowerFall.TeamSelectOverlay::.ctor(TowerFall.CustomMapButton)");
     var instructions = method.Body.Instructions.ToList();
     instructions.ForEach(i => ChangeFoursToEights(i));
 }
开发者ID:Jonesey13,项目名称:TF-8-Player,代码行数:7,代码来源:TeamSelectOverlay.cs


示例3: EntryPoint

		public void EntryPoint (ModuleDefinition module)
		{
			var entry_point = module.EntryPoint;
			Assert.IsNotNull (entry_point);

			Assert.AreEqual ("System.Void Program::Main()", entry_point.ToString ());
		}
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:7,代码来源:ModuleTests.cs


示例4: ProcessAssemblyReferences

 protected override void ProcessAssemblyReferences(ModuleDefinition moduleDef, IList<AssemblyNameReference> assemblyNameRefs)
 {
     for (int i = assemblyNameRefs.Count - 1; i >= 0; --i) {
         AssemblyNameReference replacement = null;
         var other = assemblyNameRefs[i];
         var otherName = other.Name + "," + other.Version;
         if (_assemblyReplacements.TryGetValue(other.Name, out replacement)) {
             assemblyNameRefs[i].Version = replacement.Version;
             assemblyNameRefs[i].PublicKeyToken = replacement.PublicKeyToken;
             assemblyNameRefs[i].IsRetargetable = replacement.IsRetargetable;
             var replacementName = replacement.Name + "," + replacement.Version;
             Trace.WriteLine(string.Format("Replacing {0} with {1}.", otherName, replacementName), "RetargetReferences");
         } else {
             if (_removeOthers) {
                 try {
                     var otherAss = moduleDef.AssemblyResolver.Resolve(other);
                     var otherProfile = otherAss.GetAssemblyProfileFromAttribute();
                     if (otherProfile != null && otherProfile.IsPortable) {
                         Trace.WriteLine(string.Format("Keeping {0}.", otherName), "RetargetReferences");
                         continue;
                     }
                 } catch(Exception ex) {
                     Trace.WriteLine(string.Format("Failed resolving {0}.", otherName), "RetargetReferences");
                 }
                 Trace.WriteLine(string.Format("Removing {0}.", otherName), "RetargetReferences");
                 assemblyNameRefs.RemoveAt(i);
             } else {
                 Trace.WriteLine(string.Format("Keeping {0}.", otherName), "RetargetReferences");
             }
         }
     }
     base.ProcessAssemblyReferences(moduleDef, assemblyNameRefs);
 }
开发者ID:Ark-kun,项目名称:Piranha,代码行数:33,代码来源:RetargetReferencesProcessor.cs


示例5: Rewrite

        public void Rewrite(ModuleDefinition module, IEnumerable<ImplementedEventSource> loggers)
        {
            var tmp = from l in loggers
                      let old = l.Old.FindMethod("IsEnabled")
                      where old != null
                      select new
                      {
                          Old = old,
                          New = l.New.BaseType.Resolve().FindMethod("IsEnabled").ImportInto(module)
                      };

            var fixMap = tmp.ToDictionary(a => a.Old.FullName, a => a.New);
            var moduleMethods = module.Types.SelectMany(t => t.Methods).Where(m => m.HasBody).ToArray();

            MethodReference impl;

            foreach (var method in moduleMethods)
            {
                var ops = method.GetOpsOf(OpCodes.Callvirt).ToArray();

                foreach (var o in ops)
                {
                    var fullName = (o.Operand as MethodReference)?.FullName;

                    if (fullName != null && fixMap.TryGetValue(fullName, out impl))
                    {
                        o.OpCode = OpCodes.Call;
                        o.Operand = impl;
                    }
                }
            }
        }
开发者ID:enyim,项目名称:EventSourceWeaver,代码行数:32,代码来源:IsEnabledRewriter.cs


示例6: GetFrameworkVersionForModule

 protected FrameworkVersion GetFrameworkVersionForModule(ModuleDefinition module, IFrameworkResolver frameworkResolver)
 {
     //TODO: handle Silverlight/WinPhone projects
     TargetPlatform platform = module.AssemblyResolver.GetTargetPlatform(module.FilePath);
     switch (platform)
     {
         case TargetPlatform.CLR_1:
             return FrameworkVersion.v1_1;
         case TargetPlatform.CLR_2:
             return FrameworkVersion.v2_0;
         case TargetPlatform.CLR_2_3:
         case TargetPlatform.CLR_3_5:
             return FrameworkVersion.v3_5;
         case TargetPlatform.CLR_4:
             return GetFramework4Version(module, frameworkResolver);
         case TargetPlatform.WinRT:
             return FrameworkVersion.WinRT;
         case TargetPlatform.Silverlight:
             return FrameworkVersion.Silverlight;
         case TargetPlatform.WindowsCE:
             return FrameworkVersion.WindowsCE;
         case TargetPlatform.WindowsPhone:
             return FrameworkVersion.WindowsPhone;
         default:
             return FrameworkVersion.Unknown;
     }
 }
开发者ID:juancarlosbaezpozos,项目名称:JustDecompileEngine,代码行数:27,代码来源:NoCacheAssemblyInfoService.cs


示例7: CreateUsage

        private MethodUsage CreateUsage(MemberReference operand, ModuleDefinition assembly, TypeDefinition type, MethodDefinition method, string testAssemblyPath)
        {
            if (operand == null)
                return null;

            Test test = new Test
                {
                    PathToAssembly = Path.GetDirectoryName(testAssemblyPath),
                    AssemblyName = assembly.Assembly.Name.Name,
                    NamespaceName = type.Namespace,
                    ClassName = type.Name,
                    MethodName = method.Name
                };

            var instructionCall = new MethodUsage
                {
                    AssemblyName = operand.DeclaringType.Scope.Name + ".dll",
                    NamespaceName = operand.DeclaringType.Namespace,
                    ClassName = operand.DeclaringType.Name,
                    MethodName = operand.Name,
                    TestCoverage = new List<Test> {test}
                };

            return instructionCall;
        }
开发者ID:BenHall,项目名称:Seacrest,代码行数:25,代码来源:TestFinder.cs


示例8: Read

        public static ModuleReader Read(ModuleDefinition module)
        {
            var reader = new ModuleReader();

            if (module.AssemblyReferences.All(reference => reference.Name != "Stiletto"))
            {
                return reader;
            }

            var allTypes = module.GetTypes();

            foreach (var t in allTypes)
            {
                if (IsModule(t))
                {
                    reader.ModuleTypes.Add(t);
                }

                if (IsInject(t))
                {
                    reader.InjectTypes.Add(t);
                }
            }

            return reader;
        }
开发者ID:benjamin-bader,项目名称:stiletto,代码行数:26,代码来源:ModuleReader.cs


示例9: ImageReader

 public ImageReader(IDeobfuscatorContext deobfuscatorContext, ModuleDefinition module, byte[] data)
 {
     this.deobfuscatorContext = deobfuscatorContext;
     this.module = module;
     this.reader = new BinaryReader(new MemoryStream(data));
     this.memberReferenceConverter = new MemberReferenceConverter(module);
 }
开发者ID:Joelone,项目名称:de4dot,代码行数:7,代码来源:ImageReader.cs


示例10: ImportReferences

        public override void ImportReferences(ModuleDefinition module)
        {
            // Import the references from the base class
            base.ImportReferences(module);

            _modifiableInterfaceType = module.ImportType<IModifiableType>();
        }
开发者ID:zxl359592450,项目名称:linfu,代码行数:7,代码来源:ImplementModifiableType.cs


示例11: Convert

        public Either<MemberReference, PropertyReferenceContainer> Convert(IAstReference astReference, ModuleDefinition module)
        {
            var reflectedType = astReference as AstReflectedType;
            if (reflectedType != null)
                return module.Import(reflectedType.ActualType);

            var reflectedMethod = astReference as AstReflectedMethod;
            if (reflectedMethod != null)
                return module.Import(reflectedMethod.Method);

            var reflectedConstructor = astReference as AstReflectedConstructor;
            if (reflectedConstructor != null)
                return module.Import(reflectedConstructor.Constructor);

            var reflectedProperty = astReference as AstReflectedProperty;
            if (reflectedProperty != null) {
                var getMethod = reflectedProperty.Property.GetGetMethod();
                var setMethod = reflectedProperty.Property.GetSetMethod();
                return new PropertyReferenceContainer(
                    getMethod != null ? module.Import(getMethod) : null,
                    setMethod != null ? module.Import(setMethod) : null
                );
            }

            return null;
        }
开发者ID:izobr,项目名称:light,代码行数:26,代码来源:ReflectedProvider.cs


示例12: AssemblyResolver

 public AssemblyResolver(ModuleDefinition module, DecrypterType decrypterType)
 {
     this.module = module;
     this.frameworkType = DotNetUtils.getFrameworkType(module);
     this.decrypterType = decrypterType;
     this.codeCompilerMethodCallRestorer = new CodeCompilerMethodCallRestorer(module);
 }
开发者ID:huliang,项目名称:de4dot,代码行数:7,代码来源:AssemblyResolver.cs


示例13: ReturnGenericInstance

		public void ReturnGenericInstance (ModuleDefinition module)
		{
			var bar = module.GetType ("Bar`1");

			var self = bar.GetMethod ("Self");
			Assert.IsNotNull (self);

			var bar_t = self.ReturnType;

			Assert.IsTrue (bar_t.IsGenericInstance);

			var bar_t_instance = (GenericInstanceType) bar_t;

			Assert.AreEqual (bar.GenericParameters [0], bar_t_instance.GenericArguments [0]);

			var self_str = bar.GetMethod ("SelfString");
			Assert.IsNotNull (self_str);

			var bar_str = self_str.ReturnType;
			Assert.IsTrue (bar_str.IsGenericInstance);

			var bar_str_instance = (GenericInstanceType) bar_str;

			Assert.AreEqual ("System.String", bar_str_instance.GenericArguments [0].FullName);
		}
开发者ID:0xb1dd1e,项目名称:cecil,代码行数:25,代码来源:MethodTests.cs


示例14: Replace

        public void Replace(IMethodContext context, ModuleDefinition targetModule)
        {
            var currentMethod = context.CurrentMethod;
            var currentArguments = context.CurrentArguments;
            var currentArgument = context.CurrentArgument;
            var pushMethod = targetModule.ImportMethod<Stack<object>>("Push");
            var worker = context.CilWorker;

            var methodMap = _context.MethodMap;
            var targetDependency = _context.TargetDependency;
            var interfaceType = _context.InterfaceType;

            var adapterConstructor = _adapterBuilder.CreateAdapterConstructor(methodMap);
            foreach (ParameterReference param in currentMethod.Parameters)
            {
                var arguments = new ParameterContext(worker,
                interfaceType,
                pushMethod,
                currentArguments,
                currentArgument,
                targetDependency, adapterConstructor, param);

                // Save the current argument
                _pushParameter.Adapt(arguments);
            }
        }
开发者ID:philiplaureano,项目名称:Taiji,代码行数:26,代码来源:PushMethodArguments.cs


示例15: GetInjecteeCecilType

        internal virtual TypeDefinition GetInjecteeCecilType(ModuleDefinition module)
        {
            if (_injecteeCecilDef == null)
                _injecteeCecilDef = module.FindMatchingType(InjecteeType, true);

            return _injecteeCecilDef;
        }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:7,代码来源:TypeInjecteeBase.cs


示例16: Convert

        public Either<MemberReference, PropertyReferenceContainer> Convert(IAstReference astReference, ModuleDefinition module, IReferenceProvider recursive)
        {
            if (astReference != AstVoidType.Instance)
                return null;

            return module.Import(typeof(void));
        }
开发者ID:ashmind,项目名称:light,代码行数:7,代码来源:VoidTypeProvider.cs


示例17: Sample

		public Sample(string targetFileName)
		{
			_targetFileName = targetFileName;

			// Read the module with default parameters
			_module = ModuleDefinition.ReadModule(_targetFileName);
		}
开发者ID:transformersprimeabcxyz,项目名称:cecil.samples,代码行数:7,代码来源:Sample.cs


示例18: ProcessModule

 public ModuleResult ProcessModule(ModuleDefinition module, TypeResult[] typeResults)
 {
     ModuleResult result = new ModuleResult(module.Name);
     result.TypeResults = typeResults;
     result.Result = typeResults.Sum(r => r.Result);
     return result;
 }
开发者ID:sprosin,项目名称:DrivenMetrics,代码行数:7,代码来源:ILCyclomicComplextityMetirc.cs


示例19: InvalidOperationException

        Either<MemberReference, PropertyReferenceContainer> IReferenceProvider.Convert(IAstReference astReference, ModuleDefinition module, IReferenceProvider recursive)
        {
            if (module != this.module)
                throw new InvalidOperationException("Expected module to be " + this.module + ", received " + module);

            return this.ConvertReference(astReference);
        }
开发者ID:ashmind,项目名称:light,代码行数:7,代码来源:ReferenceContext.cs


示例20: GetServiceHash

        /// <summary>
        /// Emits a call that obtains the hash code for the current service instance.
        /// </summary>
        /// <param name="il">The <see cref="ILProcessor"/> that points to the method body.</param>
        /// <param name="module">The target module.</param>
        /// <param name="serviceInstance">The local variable that contains the service instance.</param>
        private void GetServiceHash(ILProcessor il, ModuleDefinition module, VariableDefinition serviceInstance)
        {
            il.Emit(OpCodes.Ldloc, serviceInstance);

            var getHashCodeMethod = module.ImportMethod<object>("GetHashCode");
            il.Emit(OpCodes.Callvirt, getHashCodeMethod);
        }
开发者ID:philiplaureano,项目名称:Hiro,代码行数:13,代码来源:ServiceInitializer.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cecil.ParameterDefinition类代码示例发布时间:2022-05-26
下一篇:
C# Cecil.MethodReference类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap