Пример #1
0
        public static ModuleDefinition CreateModule(string name, ModuleParameters parameters)
        {
            Mixin.CheckName(name);
            Mixin.CheckParameters(parameters);
            ModuleDefinition moduleDefinition = new ModuleDefinition()
            {
                Name            = name,
                kind            = parameters.Kind,
                Runtime         = parameters.Runtime,
                architecture    = parameters.Architecture,
                mvid            = Guid.NewGuid(),
                Attributes      = ModuleAttributes.ILOnly,
                Characteristics = ModuleCharacteristics.DynamicBase | ModuleCharacteristics.NoSEH | ModuleCharacteristics.NXCompat | ModuleCharacteristics.TerminalServerAware
            };

            if (parameters.AssemblyResolver != null)
            {
                moduleDefinition.assembly_resolver = parameters.AssemblyResolver;
            }
            if (parameters.MetadataResolver != null)
            {
                moduleDefinition.metadata_resolver = parameters.MetadataResolver;
            }
            if (parameters.Kind != ModuleKind.NetModule)
            {
                AssemblyDefinition assemblyDefinition = new AssemblyDefinition();
                moduleDefinition.assembly      = assemblyDefinition;
                moduleDefinition.assembly.Name = ModuleDefinition.CreateAssemblyName(name);
                assemblyDefinition.main_module = moduleDefinition;
            }
            moduleDefinition.Types.Add(new TypeDefinition(string.Empty, "<Module>", Mono.Cecil.TypeAttributes.NotPublic));
            return(moduleDefinition);
        }