Exemple #1
0
 public static AssemblyDef AddToNewAssemblyDef(ModuleDef module, ModuleKind moduleKind, out Characteristics characteristics)
 {
     var asmDef = module.UpdateRowId(new AssemblyDefUser(GetAssemblyName(module)));
     asmDef.Modules.Add(module);
     WriteNewModuleKind(module, moduleKind, out characteristics);
     return asmDef;
 }
		public static Characteristics GetCharacteristics(Characteristics characteristics, ModuleKind moduleKind) {
			if (moduleKind == ModuleKind.Dll || moduleKind == ModuleKind.NetModule)
				characteristics |= Characteristics.Dll;
			else
				characteristics &= ~Characteristics.Dll;
			return characteristics;
		}
Exemple #3
0
		public EmbeddedAssemblyInfo(EmbeddedResource resource, byte[] data, string asmFullName, ModuleKind kind) {
			this.resource = resource;
			this.data = data;
			this.asmFullName = asmFullName;
			this.asmSimpleName = Utils.GetAssemblySimpleName(asmFullName);
			this.kind = kind;
			this.extension = DeobUtils.GetExtension(kind);
		}
 private void CreateAssemblyDefinition(String sAssemblyName, ModuleKind akAssemblyKind)
 {
     assemblyName = sAssemblyName;
     assemblyKind = akAssemblyKind;
     //assemblyDefinition = AssemblyDefinition.CreateAssembly(sAssemblyName, TargetRuntime.NET_2_0, akAssemblyKind);
     var assemblyNameDefinition = new AssemblyNameDefinition(sAssemblyName, new Version(0, 0, 0, 0));
     assemblyDefinition = AssemblyDefinition.CreateAssembly(assemblyNameDefinition, sAssemblyName, akAssemblyKind);
     mainModule = assemblyDefinition.MainModule;
 }
Exemple #5
0
		public static ModuleDef CreateModule(string name, Guid mvid, ClrVersion clrVersion, ModuleKind kind, ModuleDef existingModule = null) {
			var module = CreateModuleDef(name, mvid, clrVersion, existingModule);
			module.Kind = kind;
			module.Characteristics = Characteristics._32BitMachine | Characteristics.ExecutableImage;
			if (kind == ModuleKind.Dll || kind == ModuleKind.NetModule)
				module.Characteristics |= Characteristics.Dll;
			module.DllCharacteristics = DllCharacteristics.TerminalServerAware | DllCharacteristics.NoSeh | DllCharacteristics.NxCompat | DllCharacteristics.DynamicBase;
			return module;
		}
Exemple #6
0
		public ModuleOptions(ModuleDef module) {
			Mvid = module.Mvid;
			EncId = module.EncId;
			EncBaseId = module.EncBaseId;
			Name = module.Name;
			Kind = module.Kind;
			Characteristics = module.Characteristics;
			DllCharacteristics = module.DllCharacteristics;
			RuntimeVersion = module.RuntimeVersion;
			Machine = module.Machine;
			Cor20HeaderFlags = module.Cor20HeaderFlags;
			Cor20HeaderRuntimeVersion = module.Cor20HeaderRuntimeVersion;
			TablesHeaderVersion = module.TablesHeaderVersion;
			ManagedEntryPoint = module.ManagedEntryPoint;
			NativeEntryPoint = module.NativeEntryPoint;
			CustomAttributes.AddRange(module.CustomAttributes);
		}
 public AngularModuleKindHandlerAttribute(ModuleKind moduleKind, string kind, UIFeatureKind featureKind = UIFeatureKind.None) : base(moduleKind, kind, featureKind)
 {
 }
Exemple #8
0
 public Boolean UpgradeModuleOfShip(ModuleKind k)
 {
     return _ship.UpgradeModule(k);
 }
Exemple #9
0
        private void ReadHeader()
        { //TODO: break up this method
            MemoryCursor c = this.cursor;
            c.Position = 0;

            ReadDOSHeader(c);
            NTHeader ntHeader = ReadNTHeader(c);
            this.linkerMajorVersion = ntHeader.majorLinkerVersion;
            this.linkerMinorVersion = ntHeader.minorLinkerVersion;
            this.fileAlignment = ntHeader.fileAlignment;
            if ((ntHeader.characteristics & 0x2000) != 0)
                this.moduleKind = ModuleKind.DynamicallyLinkedLibrary;
            else
                this.moduleKind = ntHeader.subsystem == 0x3 ? ModuleKind.ConsoleApplication : ModuleKind.WindowsApplication;

            int sectionCount = ntHeader.numberOfSections;
            SectionHeader[] sectionHeaders = this.sectionHeaders = new SectionHeader[sectionCount];
            int resourceSectionIndex = -1;
            for (int i = 0; i < sectionCount; i++)
            {
                sectionHeaders[i] = ReadSectionHeader(c);
                if (sectionHeaders[i].name == ".rsrc") resourceSectionIndex = i;
            }
            if (resourceSectionIndex >= 0)
                this.win32ResourcesOffset = sectionHeaders[resourceSectionIndex].pointerToRawData;
            else
                this.win32ResourcesOffset = -1;

            DirectoryEntry de = ntHeader.cliHeaderTable;
            int cliHeaderOffset = this.RvaToOffset(de.virtualAddress);
            c.Position = cliHeaderOffset;

            CLIHeader cliHeader = ReadCLIHeader(c);
            this.entryPointToken = cliHeader.entryPointToken;
            if ((cliHeader.flags & 1) != 0)
                this.peKind = PEKindFlags.ILonly;
            if ((cliHeader.flags & 0x10) != 0)
                this.entryPointToken = 0; //Native entry point. Ignore.
            switch (ntHeader.machine)
            {
                case 0x0200:
                    this.peKind |= PEKindFlags.Requires64bits;
                    break;
                case 0x8664:
                    this.peKind |= PEKindFlags.Requires64bits | PEKindFlags.AMD;
                    break;
                default:
                    if (ntHeader.magic == 0x20B) //Optional header magic for PE32+
                        this.peKind |= PEKindFlags.Requires64bits;
                    else if ((cliHeader.flags & 2) != 0)
                        this.peKind |= PEKindFlags.Requires32bits;
                    break;
            }
            this.TrackDebugData = (cliHeader.flags & 0x10000) != 0;
            if (cliHeader.resources.size > 0)
                this.resourcesOffset = this.RvaToOffset(cliHeader.resources.virtualAddress);

            int snSize = cliHeader.strongNameSignature.size;
            if (snSize > 0)
            {
                long hashOffset = this.RvaToOffset(cliHeader.strongNameSignature.virtualAddress);
                c.Position = (int)hashOffset;
                this.HashValue = c.ReadBytes(snSize);
                bool zeroHash = true;
                for (int i = 0; i < snSize; i++) if (this.HashValue[i] != 0) zeroHash = false;
                if (zeroHash) this.HashValue = null; //partially signed assembly
            }

            long mdOffset = this.mdOffset = this.RvaToOffset(cliHeader.metaData.virtualAddress);
            c.Position = (int)mdOffset;
            MetadataHeader mdHeader = ReadMetadataHeader(c);
            this.targetRuntimeVersion = mdHeader.versionString;

            foreach (StreamHeader sheader in mdHeader.streamHeaders)
            {
                //^ assume sheader != null;
                switch (sheader.name)
                {
                    case "#Strings": this.identifierStringHeap = sheader; continue;
                    case "#US": this.generalStringHeap = sheader; continue;
                    case "#Blob": this.blobHeap = sheader; continue;
                    case "#GUID": this.guidHeap = sheader; continue;
                    case "#~": this.tables = sheader; continue;
                    case "#-": this.tables = sheader; continue;
                    default: continue;
                }
            }
            if (this.tables == null) throw new InvalidMetadataException(ExceptionStrings.NoMetadataStream);
            c.Position = (int)(mdOffset + this.tables.offset);
            TablesHeader tablesHeader = this.tablesHeader = ReadTablesHeader(c);
            this.metadataFormatMajorVersion = tablesHeader.majorVersion;
            this.metadataFormatMinorVersion = tablesHeader.minorVersion;

            int[] tableSize = this.tableSize = new int[(int)TableIndices.Count];
            int[] tableRefSize = this.tableRefSize = new int[(int)TableIndices.Count];
            long valid = tablesHeader.maskValid;
            int[] countArray = tablesHeader.countArray;
            //^ assume countArray != null;
            for (int i = 0, j = 0; i < (int)TableIndices.Count; i++)
            {
                if (valid % 2 == 1)
                {
                    int m = tableSize[i] = countArray[j++];
                    tableRefSize[i] = m < 0x10000 ? 2 : 4;
                }
                else
                    tableRefSize[i] = 2;
                valid /= 2;
            }
            int blobRefSize = this.blobRefSize = ((tablesHeader.heapSizes & 0x04) == 0 ? 2 : 4);
            int constantParentRefSize = this.constantParentRefSize =
              tableSize[(int)TableIndices.Param] < 0x4000 &&
              tableSize[(int)TableIndices.Field] < 0x4000 &&
              tableSize[(int)TableIndices.Property] < 0x4000 ? 2 : 4;
            int customAttributeParentRefSize = 0;
            if (this.metadataFormatMajorVersion > 1 || this.metadataFormatMinorVersion > 0)
            {
                customAttributeParentRefSize = this.customAttributeParentRefSize =
                  tableSize[(int)TableIndices.Method] < 0x0800 &&
                  tableSize[(int)TableIndices.Field] < 0x0800 &&
                  tableSize[(int)TableIndices.TypeRef] < 0x0800 &&
                  tableSize[(int)TableIndices.TypeDef] < 0x0800 &&
                  tableSize[(int)TableIndices.Param] < 0x0800 &&
                  tableSize[(int)TableIndices.InterfaceImpl] < 0x0800 &&
                  tableSize[(int)TableIndices.MemberRef] < 0x0800 &&
                  tableSize[(int)TableIndices.Module] < 0x0800 &&
                  tableSize[(int)TableIndices.DeclSecurity] < 0x0800 &&
                  tableSize[(int)TableIndices.Property] < 0x0800 &&
                  tableSize[(int)TableIndices.Event] < 0x0800 &&
                  tableSize[(int)TableIndices.StandAloneSig] < 0x0800 &&
                  tableSize[(int)TableIndices.ModuleRef] < 0x0800 &&
                  tableSize[(int)TableIndices.TypeSpec] < 0x0800 &&
                  tableSize[(int)TableIndices.Assembly] < 0x0800 &&
                  tableSize[(int)TableIndices.File] < 0x0800 &&
                  tableSize[(int)TableIndices.ExportedType] < 0x0800 &&
                  tableSize[(int)TableIndices.ManifestResource] < 0x0800 &&
                  tableSize[(int)TableIndices.GenericParam] < 0x0800 &&
                  tableSize[(int)TableIndices.MethodSpec] < 0x0800 &&
                  tableSize[(int)TableIndices.GenericParamConstraint] < 0x0800 ? 2 : 4;
            }
            else
            {
                customAttributeParentRefSize = this.customAttributeParentRefSize =
                  tableSize[(int)TableIndices.Method] < 0x0800 &&
                  tableSize[(int)TableIndices.Field] < 0x0800 &&
                  tableSize[(int)TableIndices.TypeRef] < 0x0800 &&
                  tableSize[(int)TableIndices.TypeDef] < 0x0800 &&
                  tableSize[(int)TableIndices.Param] < 0x0800 &&
                  tableSize[(int)TableIndices.InterfaceImpl] < 0x0800 &&
                  tableSize[(int)TableIndices.MemberRef] < 0x0800 &&
                  tableSize[(int)TableIndices.Module] < 0x0800 &&
                  tableSize[(int)TableIndices.DeclSecurity] < 0x0800 &&
                  tableSize[(int)TableIndices.Property] < 0x0800 &&
                  tableSize[(int)TableIndices.Event] < 0x0800 &&
                  tableSize[(int)TableIndices.StandAloneSig] < 0x0800 &&
                  tableSize[(int)TableIndices.ModuleRef] < 0x0800 &&
                  tableSize[(int)TableIndices.TypeSpec] < 0x0800 &&
                  tableSize[(int)TableIndices.Assembly] < 0x0800 &&
                  tableSize[(int)TableIndices.File] < 0x0800 &&
                  tableSize[(int)TableIndices.ExportedType] < 0x0800 &&
                  tableSize[(int)TableIndices.ManifestResource] < 0x0800 ? 2 : 4;
            }
            int customAttributeConstructorRefSize = this.customAttributeConstructorRefSize =
              tableSize[(int)TableIndices.Method] < 0x2000 &&
              tableSize[(int)TableIndices.MemberRef] < 0x2000 ? 2 : 4;
            int declSecurityParentRefSize = this.declSecurityParentRefSize =
              tableSize[(int)TableIndices.TypeDef] < 0x4000 &&
              tableSize[(int)TableIndices.Method] < 0x4000 &&
              tableSize[(int)TableIndices.Assembly] < 0x4000 ? 2 : 4;
            int fieldMarshalParentRefSize = this.fieldMarshalParentRefSize =
              tableSize[(int)TableIndices.Field] < 0x8000 &&
              tableSize[(int)TableIndices.Param] < 0x8000 ? 2 : 4;
            int guidRefSize = this.guidRefSize = ((tablesHeader.heapSizes & 0x02) == 0 ? 2 : 4);
            int hasSemanticRefSize = this.hasSemanticRefSize =
              tableSize[(int)TableIndices.Event] < 0x8000 &&
              tableSize[(int)TableIndices.Property] < 0x8000 ? 2 : 4;
            int implementationRefSize = this.implementationRefSize =
              tableSize[(int)TableIndices.File] < 0x4000 &&
              tableSize[(int)TableIndices.AssemblyRef] < 0x4000 &&
              tableSize[(int)TableIndices.ExportedType] < 0x4000 ? 2 : 4;
            int methodDefOrRefSize = this.methodDefOrRefSize =
              tableSize[(int)TableIndices.Method] < 0x8000 &&
              tableSize[(int)TableIndices.MemberRef] < 0x8000 ? 2 : 4;
            int memberRefParentSize = this.memberRefParentSize =
              tableSize[(int)TableIndices.TypeDef] < 0x2000 &&
              tableSize[(int)TableIndices.TypeRef] < 0x2000 &&
              tableSize[(int)TableIndices.ModuleRef] < 0x2000 &&
              tableSize[(int)TableIndices.Method] < 0x2000 &&
              tableSize[(int)TableIndices.TypeSpec] < 0x2000 ? 2 : 4;
            int memberForwardedRefSize = this.memberForwardedRefSize =
              tableSize[(int)TableIndices.Field] < 0x8000 &&
              tableSize[(int)TableIndices.Method] < 0x8000 ? 2 : 4;
            int typeDefOrMethodDefSize = this.typeDefOrMethodDefSize =
              tableSize[(int)TableIndices.TypeDef] < 0x8000 &&
              tableSize[(int)TableIndices.Method] < 0x8000 ? 2 : 4;
            int typeDefOrRefOrSpecSize = this.typeDefOrRefOrSpecSize =
              tableSize[(int)TableIndices.TypeDef] < 0x4000 &&
              tableSize[(int)TableIndices.TypeRef] < 0x4000 &&
              tableSize[(int)TableIndices.TypeSpec] < 0x4000 ? 2 : 4;
            int resolutionScopeRefSize = this.resolutionScopeRefSize =
              tableSize[(int)TableIndices.Module] < 0x4000 &&
              tableSize[(int)TableIndices.ModuleRef] < 0x4000 &&
              tableSize[(int)TableIndices.AssemblyRef] < 0x4000 &&
              tableSize[(int)TableIndices.TypeRef] < 0x4000 ? 2 : 4;
            int stringRefSize = this.stringRefSize = ((tablesHeader.heapSizes & 0x01) == 0 ? 2 : 4);

            int[] tableOffset = this.tableOffset = new int[(int)TableIndices.Count];
            int offset = this.mdOffset + this.tables.offset + 24 + countArray.Length * 4;
            for (int i = 0; i < (int)TableIndices.Count; i++)
            {
                int m = tableSize[i];
                if (m == 0) continue;
                tableOffset[i] = offset;
                switch ((TableIndices)i)
                {
                    case TableIndices.Module: offset += m * (2 + stringRefSize + 3 * guidRefSize); break;
                    case TableIndices.TypeRef: offset += m * (resolutionScopeRefSize + 2 * stringRefSize); break;
                    case TableIndices.TypeDef: offset += m * (4 + 2 * stringRefSize + typeDefOrRefOrSpecSize + tableRefSize[(int)TableIndices.Field] + tableRefSize[(int)TableIndices.Method]); break;
                    case TableIndices.FieldPtr: offset += m * (tableRefSize[(int)TableIndices.Field]); break;
                    case TableIndices.Field: offset += m * (2 + stringRefSize + blobRefSize); break;
                    case TableIndices.MethodPtr: offset += m * (tableRefSize[(int)TableIndices.Method]); break;
                    case TableIndices.Method: offset += m * (8 + stringRefSize + blobRefSize + tableRefSize[(int)TableIndices.Param]); break;
                    case TableIndices.ParamPtr: offset += m * (tableRefSize[(int)TableIndices.Param]); break;
                    case TableIndices.Param: offset += m * (4 + stringRefSize); break;
                    case TableIndices.InterfaceImpl: offset += m * (tableRefSize[(int)TableIndices.TypeDef] + typeDefOrRefOrSpecSize); break;
                    case TableIndices.MemberRef: offset += m * (memberRefParentSize + stringRefSize + blobRefSize); break;
                    case TableIndices.Constant: offset += m * (2 + constantParentRefSize + blobRefSize); break;
                    case TableIndices.CustomAttribute: offset += m * (customAttributeParentRefSize + customAttributeConstructorRefSize + blobRefSize); break;
                    case TableIndices.FieldMarshal: offset += m * (fieldMarshalParentRefSize + blobRefSize); break;
                    case TableIndices.DeclSecurity: offset += m * (2 + declSecurityParentRefSize + blobRefSize); break;
                    case TableIndices.ClassLayout: offset += m * (6 + tableRefSize[(int)TableIndices.TypeDef]); break;
                    case TableIndices.FieldLayout: offset += m * (4 + tableRefSize[(int)TableIndices.Field]); break;
                    case TableIndices.StandAloneSig: offset += m * (blobRefSize); break;
                    case TableIndices.EventMap: offset += m * (tableRefSize[(int)TableIndices.TypeDef] + tableRefSize[(int)TableIndices.Event]); break;
                    case TableIndices.EventPtr: offset += m * (tableRefSize[(int)TableIndices.Event]); break;
                    case TableIndices.Event: offset += m * (2 + stringRefSize + typeDefOrRefOrSpecSize); break;
                    case TableIndices.PropertyMap: offset += m * (tableRefSize[(int)TableIndices.TypeDef] + tableRefSize[(int)TableIndices.Property]); break;
                    case TableIndices.PropertyPtr: offset += m * (tableRefSize[(int)TableIndices.Property]); break;
                    case TableIndices.Property: offset += m * (2 + stringRefSize + blobRefSize); break;
                    case TableIndices.MethodSemantics: offset += m * (2 + tableRefSize[(int)TableIndices.Method] + hasSemanticRefSize); break;
                    case TableIndices.MethodImpl: offset += m * (tableRefSize[(int)TableIndices.TypeDef] + 2 * methodDefOrRefSize); break;
                    case TableIndices.ModuleRef: offset += m * (stringRefSize); break;
                    case TableIndices.TypeSpec: offset += m * (blobRefSize); break;
                    case TableIndices.ImplMap: offset += m * (2 + memberForwardedRefSize + stringRefSize + tableRefSize[(int)TableIndices.ModuleRef]); break;
                    case TableIndices.FieldRva: offset += m * (4 + tableRefSize[(int)TableIndices.Field]); break;
                    case TableIndices.EncLog: throw new InvalidMetadataException(ExceptionStrings.ENCLogTableEncountered);
                    case TableIndices.EncMap: throw new InvalidMetadataException(ExceptionStrings.ENCMapTableEncountered);
                    case TableIndices.Assembly: offset += m * (16 + blobRefSize + 2 * stringRefSize); break;
                    case TableIndices.AssemblyProcessor: offset += m * (4); break;
                    case TableIndices.AssemblyOS: offset += m * (12); break;
                    case TableIndices.AssemblyRef: offset += m * (12 + 2 * blobRefSize + 2 * stringRefSize); break;
                    case TableIndices.AssemblyRefProcessor: offset += m * (4 + tableRefSize[(int)TableIndices.AssemblyRef]); break;
                    case TableIndices.AssemblyRefOS: offset += m * (12 + tableRefSize[(int)TableIndices.AssemblyRef]); break;
                    case TableIndices.File: offset += m * (4 + stringRefSize + blobRefSize); break;
                    case TableIndices.ExportedType: offset += m * (8 + 2 * stringRefSize + implementationRefSize); break;
                    case TableIndices.ManifestResource: offset += m * (8 + stringRefSize + implementationRefSize); break;
                    case TableIndices.NestedClass: offset += m * (2 * tableRefSize[(int)TableIndices.TypeDef]); break;
                    case TableIndices.GenericParam:
                        if (this.metadataFormatMajorVersion == 1 && this.metadataFormatMinorVersion == 0)
                            offset += m * (6 + typeDefOrMethodDefSize + stringRefSize + typeDefOrRefOrSpecSize);
                        else if (this.metadataFormatMajorVersion == 1 && this.metadataFormatMinorVersion == 1)
                            offset += m * (4 + typeDefOrMethodDefSize + stringRefSize + typeDefOrRefOrSpecSize);
                        else
                            offset += m * (4 + typeDefOrMethodDefSize + stringRefSize);
                        break;
                    case TableIndices.MethodSpec: offset += m * (methodDefOrRefSize + blobRefSize); break;
                    case TableIndices.GenericParamConstraint: offset += m * (tableRefSize[(int)TableIndices.GenericParam] + typeDefOrRefOrSpecSize); break;
                    default: throw new InvalidMetadataException(ExceptionStrings.UnsupportedTableEncountered);
                }
            }
        }
Exemple #10
0
 public ModuleParameters()
 {
     this.kind         = ModuleKind.Dll;
     this.Runtime      = GetCurrentRuntime();
     this.architecture = TargetArchitecture.I386;
 }
 public static AssemblyDefinition CreateAssembly(AssemblyNameDefinition assemblyName, string moduleName, ModuleKind kind)
 {
     return(CreateAssembly(assemblyName, moduleName, new ModuleParameters {
         Kind = kind
     }));
 }
Exemple #12
0
        public static ModuleDef CreateModule(string name, Guid mvid, ClrVersion clrVersion, ModuleKind kind, ModuleDef existingModule = null)
        {
            var module = CreateModuleDef(name, mvid, clrVersion, existingModule);

            module.Kind            = kind;
            module.Characteristics = Characteristics.Bit32Machine | Characteristics.ExecutableImage;
            if (kind == ModuleKind.Dll || kind == ModuleKind.NetModule)
            {
                module.Characteristics |= Characteristics.Dll;
            }
            module.DllCharacteristics = DllCharacteristics.TerminalServerAware | DllCharacteristics.NoSeh | DllCharacteristics.NxCompat | DllCharacteristics.DynamicBase;
            return(module);
        }
        private static string ParseOutputPaths(IEnumerable <string> outputPaths, IReadOnlyList <string> sourceFiles, ModuleKind moduleKind)
        {
            string outputPath      = null;
            var    targetExtension = ModuleKindToExtension(moduleKind);
            var    outputPathCount = outputPaths.Count();

            if (outputPathCount > 1)
            {
                Errors.Report(ErrorCode.MoreThanOneOutputPath, "More than one output path specified.");
                return(null);
            }
            else if (outputPathCount == 0)
            {
                if (sourceFiles.Count > 1)
                {
                    Errors.Report(ErrorCode.NoOutputPaths, "No output path and more than one source file specified.");
                    return(null);
                }
                else if (sourceFiles.Count == 1)
                {
                    outputPath = Path.ChangeExtension(sourceFiles.First(), targetExtension);
                }
                else
                {
                    return(null);    // "No source files" error is already reported at this point
                }
            }
            else
            {
                outputPath = outputPaths.First().Substring(5);

                if (Path.GetFileNameWithoutExtension(outputPath) == Path.GetFileName(outputPath))
                {
                    outputPath = outputPath + targetExtension;
                }
                else if (Path.GetExtension(outputPath) != targetExtension)
                {
                    Errors.Report(ErrorCode.OutputPathAndModuleKindMismatch, string.Join(Environment.NewLine, new string[]
                    {
                        "Output path doesn't match specified module kind!",
                        string.Format("\tSpecified output path: \"{0}\"", outputPath),
                        string.Format("\tSpecified module kind: \"{0}\"", moduleKind)
                    }));

                    return(null);
                }
            }

            if (HasIllegalCharactersInPath(outputPath))
            {
                Errors.Report(ErrorCode.IllegalCharactersInPath, string.Format("Illegal characters in path \"{0}\"", outputPath));
            }

            return(outputPath);
        }
Exemple #14
0
 //public:
 public Module(ModuleKind kind)
 {
     _kind = kind;
     _size = 0;
     SetTypeBySize();
 }
Exemple #15
0
        public AssemblyDefinition CreateAndRegisterAssembly(string name, Version version, ModuleKind kind)
        {
            var def = AssemblyDefinition.CreateAssembly(new AssemblyNameDefinition(name, version), name,
                                                        new ModuleParameters()
            {
                AssemblyResolver = this,
                MetadataResolver = this._resolver,
                Kind             = kind
            });

            RegisterAssembly(def);
            return(def);
        }
Exemple #16
0
        /// <summary>
        /// The actual repacking process, called by main after parsing arguments.
        /// When referencing this assembly, call this after setting the merge properties.
        /// </summary>
        public void Repack()
        {
            var timer = new Stopwatch();

            timer.Start();
            Options.Validate();
            PrintRepackHeader();

            var actualOutFile = Path.GetFullPath(Options.OutputFile);

            Options.OutputFile = actualOutFile;

            _reflectionHelper = new ReflectionHelper(this);
            ResolveSearchDirectories();

            // Read input assemblies only after all properties are set.
            ReadInputAssemblies();

            if (MergedAssemblyFiles.Any(m => string.Compare(m, actualOutFile, StringComparison.OrdinalIgnoreCase) == 0))
            {
                Options.OutputFile = GetTempFile(Options.OutputFile);
            }

            _platformFixer  = new PlatformFixer(this, PrimaryAssemblyMainModule.Runtime);
            _mappingHandler = new MappingHandler();
            bool hadStrongName = PrimaryAssemblyDefinition.Name.HasPublicKey;

            ModuleKind kind = PrimaryAssemblyMainModule.Kind;

            if (Options.TargetKind.HasValue)
            {
                switch (Options.TargetKind.Value)
                {
                case Kind.Dll: kind = ModuleKind.Dll; break;

                case Kind.Exe: kind = ModuleKind.Console; break;

                case Kind.WinExe: kind = ModuleKind.Windows; break;
                }
            }
            TargetRuntime runtime = ParseTargetPlatform();

            // change assembly's name to correspond to the file we create
            string mainModuleName = Options.UsePrimaryAssemblyName
                ? PrimaryAssemblyDefinition.Name.Name
                : Path.GetFileNameWithoutExtension(Options.OutputFile);

            if (TargetAssemblyDefinition == null)
            {
                AssemblyNameDefinition asmName = Clone(PrimaryAssemblyDefinition.Name);
                asmName.Name             = mainModuleName;
                TargetAssemblyDefinition = AssemblyDefinition.CreateAssembly(asmName, mainModuleName,
                                                                             new ModuleParameters()
                {
                    Kind             = kind,
                    Architecture     = PrimaryAssemblyMainModule.Architecture,
                    AssemblyResolver = GlobalAssemblyResolver,
                    Runtime          = runtime
                });
            }
            else
            {
                // TODO: does this work or is there more to do?
                TargetAssemblyMainModule.Kind    = kind;
                TargetAssemblyMainModule.Runtime = runtime;

                TargetAssemblyDefinition.Name.Name = mainModuleName;
                TargetAssemblyMainModule.Name      = mainModuleName;
            }
            // set the main module attributes
            TargetAssemblyMainModule.Attributes             = PrimaryAssemblyMainModule.Attributes;
            TargetAssemblyMainModule.Win32ResourceDirectory = MergeWin32Resources(PrimaryAssemblyMainModule.Win32ResourceDirectory);

            if (Options.Version != null)
            {
                TargetAssemblyDefinition.Name.Version = Options.Version;
            }

            _lineIndexer = new IKVMLineIndexer(this, Options.LineIndexation);
            var signingStep       = new SigningStep(this, Options);
            var isUnixEnvironment = Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix;
            var isMonoRuntime     = Type.GetType("Mono.Runtime") != null;

            using (var sourceServerDataStep = GetSourceServerDataStep(isUnixEnvironment))
            {
                List <IRepackStep> repackSteps = new List <IRepackStep>
                {
                    signingStep,
                    new ReferencesRepackStep(Logger, this),
                    new TypesRepackStep(Logger, this, _repackImporter, Options),
                    new ResourcesRepackStep(Logger, this, Options),
                    new AttributesRepackStep(Logger, this, _repackImporter, Options),
                    new ReferencesFixStep(Logger, this, _repackImporter, Options),
                    new XamlResourcePathPatcherStep(Logger, this),
                    sourceServerDataStep
                };

                foreach (var step in repackSteps)
                {
                    step.Perform();
                }

                var parameters = new WriterParameters
                {
                    StrongNameKeyPair    = signingStep.KeyInfo?.KeyPair,
                    StrongNameKeyBlob    = signingStep.KeyInfo?.KeyBlob,
                    WriteSymbols         = Options.DebugInfo && PrimaryAssemblyMainModule.SymbolReader != null,
                    SymbolWriterProvider = PrimaryAssemblyMainModule.SymbolReader?.GetWriterProvider(),
                };
                // create output directory if it does not exist
                var outputDir = Path.GetDirectoryName(Options.OutputFile);
                if (!string.IsNullOrEmpty(outputDir) && !Directory.Exists(outputDir))
                {
                    Logger.Info("Output directory does not exist. Creating output directory: " + outputDir);
                    Directory.CreateDirectory(outputDir);
                }

                Logger.Info("Writing output assembly to disk");
                TargetAssemblyDefinition.Write(Options.OutputFile, parameters);
                sourceServerDataStep.Write();

                for (int i = 1; i < MergedAssemblies.Count; ++i)
                {
                    MergedAssemblies[i].Dispose();
                }

                TargetAssemblyDefinition.Dispose();
                GlobalAssemblyResolver.Dispose();

                if (Options.OutputFile != actualOutFile)
                {
                    MoveTempFile(Options.OutputFile, actualOutFile);
                    Options.OutputFile = actualOutFile;
                }

                // If this is an executable and we are on linux/osx we should copy file permissions from
                // the primary assembly
                if (isUnixEnvironment && isMonoRuntime)
                {
                    Stat stat;
                    Logger.Info("Copying permissions from " + PrimaryAssemblyFile);
                    Syscall.stat(PrimaryAssemblyFile, out stat);
                    Syscall.chmod(Options.OutputFile, stat.st_mode);
                }
                if (hadStrongName && !TargetAssemblyDefinition.Name.HasPublicKey)
                {
                    Options.StrongNameLost = true;
                }

                // nice to have, merge .config (assembly configuration file) & .xml (assembly documentation)
                ConfigMerger.Process(this);
                if (Options.XmlDocumentation)
                {
                    DocumentationMerger.Process(this);
                }
            }

            Logger.Info($"Finished in {timer.Elapsed}");
        }
Exemple #17
0
 public RealAssemblyInfo(AssemblyDef realAssembly, uint entryPointToken, ModuleKind kind)
 {
     this.realAssembly = realAssembly;
     this.entryPointToken = entryPointToken;
     this.kind = kind;
     this.moduleName = realAssembly.Name.String + DeobUtils.GetExtension(kind);
 }
Exemple #18
0
 public Contract(string name, ModuleKind kind, Module parent = null) : base(name, kind, parent)
 {
 }
Exemple #19
0
 public EmbeddedAssemblyInfo(EmbeddedResource resource, byte[] data, string asmFullName, ModuleKind kind)
 {
     this.resource      = resource;
     this.data          = data;
     this.asmFullName   = asmFullName;
     this.asmSimpleName = Utils.GetAssemblySimpleName(asmFullName);
     this.kind          = kind;
     this.extension     = DeobUtils.GetExtension(kind);
 }
 private void LoadManifestModuleKind()
 {
     ManifestModuleKind = ManifestModule.Kind;
     cmbManifestModuleKind.SelectedItem = ManifestModuleKind;
 }
Exemple #21
0
        public static AssemblyDefinition CreateAssembly(AssemblyNameDefinition assemblyName, string moduleName, ModuleKind kind)
        {
            if (assemblyName == null)
            {
                throw new ArgumentNullException("assemblyName");
            }
            if (moduleName == null)
            {
                throw new ArgumentNullException("moduleName");
            }
            if (kind == ModuleKind.NetModule)
            {
                throw new ArgumentException("kind");
            }

            var assembly = ModuleDefinition.CreateModule(moduleName, kind).Assembly;

            assembly.Name = assemblyName;

            return(assembly);
        }
Exemple #22
0
 public static void WriteNewModuleKind(ModuleDef module, ModuleKind moduleKind, out Characteristics characteristics)
 {
     module.Kind            = moduleKind;
     characteristics        = module.Characteristics;
     module.Characteristics = SaveModule.CharacteristicsHelper.GetCharacteristics(module.Characteristics, moduleKind);
 }
Exemple #23
0
 /// <nodoc/>
 public DscModule(ModuleKind moduleKind, string moduleName)
 {
     ModuleKind = moduleKind;
     ModuleName = moduleName;
 }
 /// <summary>
 /// Creates an assembly.
 /// </summary>
 /// <param name="assemblyName">The name of the assembly.</param>
 /// <param name="moduleKind">The assembly type.</param>
 /// <returns>An assembly.</returns>
 public AssemblyDefinition CreateAssembly(string assemblyName, ModuleKind moduleKind)
 {
     return(AssemblyDefinition.CreateAssembly(new AssemblyNameDefinition(assemblyName, new Version(0, 0, 0, 0)), assemblyName, moduleKind));
 }
Exemple #25
0
 public Boolean UpgradeModule(ModuleKind k)
 {
     if(_modules[k].UpgradeModul())
     {
         RecalculateModuleEffect(k);
         return true;
     }
     return false;
 }
Exemple #26
0
 static AssemblyDefinition CreateAssembly(string name, ModuleKind kind)
 {
     return(AssemblyDefinition.CreateAssembly(
                new AssemblyNameDefinition(name, new Version(0, 0)),
                name, kind));
 }
Exemple #27
0
 private void RemoveModuleEffect(ModuleKind k)
 {
     Module m = _modules[k];
     switch (k)
     {
         case ModuleKind.Shield:
             _shield -= (Int32)(_shieldDEFAULT * ((Double)m.bonus / 100));
             break;
         case ModuleKind.Gun:
             Damage -= (Int32)(_type.basedamage * ((Double)m.bonus / 100));
             break;
         case ModuleKind.Core:
             Health -= (Int32)(_healthDEFAULT * ((Double)m.bonus / 100));
             break;
     }
 }
 public static ModuleDefinition CreateModule(string name, ModuleKind kind)
 {
     return(CreateModule(name, new ModuleParameters {
         Kind = kind
     }));
 }
 public CecilAssemblyBuilder(String sAssemblyName, ModuleKind akAssemblyKind)
 {
     CreateAssemblyDefinition(sAssemblyName, akAssemblyKind);
 }
Exemple #30
0
		static Subsystem GetSubsystem(ModuleKind moduleKind) {
			if (moduleKind == dnlib.DotNet.ModuleKind.Windows)
				return Subsystem.WindowsGui;
			return Subsystem.WindowsCui;
		}
		static string GetTypeString (ModuleKind kind)
		{
			switch (kind) {
			case ModuleKind.Console:
				return GettextCatalog.GetString ("Console application");
			case ModuleKind.Dll:
				return GettextCatalog.GetString ("Library");
			case ModuleKind.Windows:
				return GettextCatalog.GetString ("Application");
			}
			return GettextCatalog.GetString ("Unknown");
		}
Exemple #32
0
        public ModuleInfo GetModuleInfo(int id, ModuleKind kind)
        {
            var module = mModules.Find(info => info.ID == id && info.K == kind);

            return(module);
        }
 public AngularModuleKindHandlerAttribute(ModuleKind moduleKind, DefinitionKind definitionKind, UIFeatureKind featureKind = UIFeatureKind.None) : base(moduleKind, definitionKind, featureKind)
 {
 }
Exemple #34
0
		public static void WriteNewModuleKind(ModuleDef module, ModuleKind moduleKind, out Characteristics characteristics) {
			module.Kind = moduleKind;
			characteristics = module.Characteristics;
			module.Characteristics = SaveModule.CharacteristicsHelper.GetCharacteristics(module.Characteristics, moduleKind);
		}
Exemple #35
0
        public List <ModuleInfo> GetModulesOfKind(ModuleKind kind)
        {
            var modules = mModules.FindAll(info => info.K == kind);

            return(modules);
        }
Exemple #36
0
        public bool IsModuleEnable(ModuleKind kind, int id)
        {
            var module = mModules.Find(info => info.ID == id && info.K == kind);

            return(module == null ? false : module.S != 0);
        }
Exemple #37
0
        public bool IsModuleExist(ModuleKind kind, int id)
        {
            var module = mModules.Find(info => info.ID == id && info.K == kind);

            return(module != null);
        }
 /// <summary>
 /// Creates an assembly.
 /// </summary>
 /// <param name="assemblyName">The name of the assembly.</param>
 /// <param name="moduleKind">The assembly type.</param>
 /// <returns>An assembly.</returns>
 public AssemblyDefinition CreateAssembly(string assemblyName, ModuleKind moduleKind)
 {
     return AssemblyDefinition.CreateAssembly (new AssemblyNameDefinition (assemblyName, new Version (0, 0, 0, 0)), assemblyName, moduleKind);
 }
Exemple #39
0
 public static Characteristics GetCharacteristics(Characteristics characteristics, ModuleKind moduleKind)
 {
     if (moduleKind == ModuleKind.Dll || moduleKind == ModuleKind.NetModule)
     {
         characteristics |= Characteristics.Dll;
     }
     else
     {
         characteristics &= ~Characteristics.Dll;
     }
     return(characteristics);
 }
 public static AssemblyDefinition CreateAssembly(AssemblyNameDefinition assemblyName, string moduleName, ModuleKind kind)
 {
     return CreateAssembly(assemblyName, moduleName, new ModuleParameters { Kind = kind });
 }
Exemple #41
0
 public Script(string name, ModuleKind kind) : base(name, kind)
 {
 }