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


C# ModuleDef.Import方法代码示例

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


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

示例1: SetAssemblyAttribute

 private static bool SetAssemblyAttribute(ModuleDef moduleDef, Type attributeType, string value)
 {
     var attributeAssemblyFileName = attributeType.Module.FullyQualifiedName;
     using (var attributeModule = ModuleDefMD.Load(attributeAssemblyFileName))
     {
         var attributeTypeRef = moduleDef.Import(attributeType);
         var attributeTypeDef = attributeModule.GetTypes().Single(t => t.FullName == attributeTypeRef.FullName);
         var existingAttribute = moduleDef.Assembly.CustomAttributes.SingleOrDefault(t => t.TypeFullName == attributeTypeDef.FullName);
         if (existingAttribute != null)
         {
             // if it exists and is already initialized with the same value, then no need to change it
             if (((UTF8String)existingAttribute.ConstructorArguments[0].Value).String == value)
                 return false;
             moduleDef.Assembly.CustomAttributes.Remove(existingAttribute);
         }
         var ctor = moduleDef.Import(attributeTypeDef.FindConstructors().Single());
         var stringTypeSig = moduleDef.Import(typeof(string)).ToTypeSig();
         moduleDef.Assembly.CustomAttributes.Add(new CustomAttribute(ctor, new[] { new CAArgument(stringTypeSig, new UTF8String(value)) }));
     }
     return true;
 }
开发者ID:picrap,项目名称:VersionStitcher,代码行数:21,代码来源:VersionStitcher.Custom.cs

示例2: InjectData

        void InjectData(ModuleDef stubModule, MethodDef method, byte[] data)
        {
            var dataType = new TypeDefUser("", "DataType", stubModule.CorLibTypes.GetTypeRef("System", "ValueType"));
            dataType.Layout = TypeAttributes.ExplicitLayout;
            dataType.Visibility = TypeAttributes.NestedPrivate;
            dataType.IsSealed = true;
            dataType.ClassLayout = new ClassLayoutUser(1, (uint)data.Length);
            stubModule.GlobalType.NestedTypes.Add(dataType);

            var dataField = new FieldDefUser("DataField", new FieldSig(dataType.ToTypeSig())) {
                IsStatic = true,
                HasFieldRVA = true,
                InitialValue = data,
                Access = FieldAttributes.CompilerControlled
            };
            stubModule.GlobalType.Fields.Add(dataField);

            MutationHelper.ReplacePlaceholder(method, arg => {
                var repl = new List<Instruction>();
                repl.AddRange(arg);
                repl.Add(Instruction.Create(OpCodes.Dup));
                repl.Add(Instruction.Create(OpCodes.Ldtoken, dataField));
                repl.Add(Instruction.Create(OpCodes.Call, stubModule.Import(
                    typeof(RuntimeHelpers).GetMethod("InitializeArray"))));
                return repl.ToArray();
            });
        }
开发者ID:cybercircuits,项目名称:ConfuserEx,代码行数:27,代码来源:Compressor.cs

示例3: ImportAssemblyTypeReferences

 void ImportAssemblyTypeReferences(ModuleDef originModule, ModuleDef stubModule)
 {
     var assembly = stubModule.Assembly;
     foreach (var ca in assembly.CustomAttributes) {
         if (ca.AttributeType.Scope == originModule)
             ca.Constructor = (ICustomAttributeType)stubModule.Import(ca.Constructor);
     }
     foreach (var ca in assembly.DeclSecurities.SelectMany(declSec => declSec.CustomAttributes)) {
         if (ca.AttributeType.Scope == originModule)
             ca.Constructor = (ICustomAttributeType)stubModule.Import(ca.Constructor);
     }
 }
开发者ID:cybercircuits,项目名称:ConfuserEx,代码行数:12,代码来源:Compressor.cs


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