コード例 #1
0
 public override void Create(DecompileContext ctx)
 {
     using (var stream = File.Create(Filename)) {
         var data = embeddedResource.GetResourceData();
         stream.Write(data, 0, data.Length);
     }
 }
コード例 #2
0
 public override void Create(DecompileContext ctx)
 {
     using (var writer = new StreamWriter(Filename, false, Encoding.UTF8)) {
         var output = createDecompilerOutput(writer);
         decompiler.Decompile(DecompilationType.AssemblyInfo, new DecompileAssemblyInfo(output, decompilationContext, module));
     }
 }
コード例 #3
0
 public override void Create(DecompileContext ctx)
 {
     using (var writer = new StreamWriter(Filename, false, Encoding.UTF8)) {
         var output = createDecompilerOutput(writer);
         Decompile(ctx, output);
     }
 }
コード例 #4
0
        public override void Create(DecompileContext ctx)
        {
            var settings = new XmlWriterSettings {
                Encoding = Encoding.UTF8,
                Indent   = true,
            };

            using (var writer = XmlWriter.Create(filename, settings)) {
                writer.WriteProcessingInstruction("xml", "version='1.0' encoding='utf-8'");
                writer.WriteStartElement("SettingsFile", "http://schemas.microsoft.com/VisualStudio/2004/01/settings");
                writer.WriteAttributeString("CurrentProfile", DEFAULT_PROFILE);
                writer.WriteAttributeString("GeneratedClassNamespace", type.ReflectionNamespace);
                writer.WriteAttributeString("GeneratedClassName", type.ReflectionName);

                writer.WriteStartElement("Profiles");
                writer.WriteEndElement();

                writer.WriteStartElement("Settings");
                foreach (var setting in FindSettings())
                {
                    writer.WriteStartElement("Setting");
                    writer.WriteAttributeString("Name", setting.Name);
                    if (!string.IsNullOrEmpty(setting.Description))
                    {
                        writer.WriteAttributeString("Description", setting.Description);
                    }
                    if (!string.IsNullOrEmpty(setting.Provider))
                    {
                        writer.WriteAttributeString("Provider", setting.Provider);
                    }
                    if (setting.Roaming)
                    {
                        writer.WriteAttributeString("Roaming", "true");
                    }
                    if (!setting.GenerateDefaultValueInCode)
                    {
                        writer.WriteAttributeString("GenerateDefaultValueInCode", "false");
                    }
                    writer.WriteAttributeString("Type", setting.Type);
                    writer.WriteAttributeString("Scope", setting.Scope);
                    if (!(setting.DesignTimeValue is null))
                    {
                        writer.WriteStartElement("DesignTimeValue");
                        writer.WriteAttributeString("Profile", setting.DesignTimeValue.Profile);
                        writer.WriteString(setting.DesignTimeValue.Text);
                        writer.WriteEndElement();
                    }
                    writer.WriteStartElement("Value");
                    writer.WriteAttributeString("Profile", setting.Value?.Profile ?? "???");
                    writer.WriteString(setting.Value?.Text ?? "???");
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
コード例 #5
0
 public override void Create(DecompileContext ctx)
 {
     InitializeIsEmpty();
     if (!isEmpty)
     {
         base.Create(ctx);
     }
 }
コード例 #6
0
		protected override void Decompile(DecompileContext ctx, IDecompilerOutput output) {
			var opts = new DecompilePartialType(output, decompilationContext, Type);
			foreach (var d in GetDefsToRemove())
				opts.Definitions.Add(d);
			opts.InterfacesToRemove.Add(new TypeRefUser(Type.Module, "System.Windows.Markup", "IComponentConnector", new AssemblyNameInfo("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35").ToAssemblyRef()));
			opts.InterfacesToRemove.Add(new TypeRefUser(Type.Module, "System.Windows.Markup", "IComponentConnector", new AssemblyNameInfo("System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089").ToAssemblyRef()));
			decompiler.Decompile(DecompilationType.PartialType, opts);
		}
コード例 #7
0
        protected override void Decompile(DecompileContext ctx, IDecompilerOutput output)
        {
            var opts = new DecompilePartialType(output, decompilationContext, Type);

            foreach (var d in GetDefsToRemove())
            {
                opts.Definitions.Add(d);
            }
            decompiler.Decompile(DecompilationType.PartialType, opts);
        }
コード例 #8
0
ファイル: ResXProjectFile.cs プロジェクト: manojdjoshi/dnSpy
		public override void Create(DecompileContext ctx) {
			var list = ReadResourceEntries(ctx);

			using (var writer = delegateResXResourceWriterConstructor?.Invoke(Filename, TypeNameConverter) ?? new ResXResourceWriter(Filename)) {
				foreach (var t in list) {
					ctx.CancellationToken.ThrowIfCancellationRequested();
					writer.AddResource(t);
				}
			}
		}
コード例 #9
0
		protected override void Decompile(DecompileContext ctx, IDecompilerOutput output) {
			if (!decompiler.CanDecompile(DecompilationType.PartialType))
				base.Decompile(ctx, output);
			else {
				var opts = new DecompilePartialType(output, decompilationContext, Type);
				foreach (var d in GetDefsToRemove())
					opts.Definitions.Add(d);
				decompiler.Decompile(DecompilationType.PartialType, opts);
			}
		}
コード例 #10
0
		public override void Create(DecompileContext ctx) {
			IList<string> refs;
			using (var stream = File.Create(Filename))
				refs = decompileBaml(bamlData, stream);
			foreach (var asmRef in refs) {
				var a = new AssemblyNameInfo(asmRef);
				if (!UTF8String.IsNullOrEmpty(a.Name))
					asmRefs.Add(a);
			}
		}
コード例 #11
0
ファイル: ResXProjectFile.cs プロジェクト: zixing131/dnSpy
        public override void Create(DecompileContext ctx)
        {
            var list = ReadResourceEntries(ctx);

            using (var writer = delegateResXResourceWriterConstructor?.Invoke(Filename, TypeNameConverter) ?? new ResXResourceWriter(Filename)) {
                foreach (var t in list)
                {
                    ctx.CancellationToken.ThrowIfCancellationRequested();
                    writer.AddResource(t);
                }
            }
        }
コード例 #12
0
        protected override void Decompile(DecompileContext ctx, IDecompilerOutput output)
        {
            var opts = new DecompilePartialType(output, decompilationContext, Type);

            foreach (var d in GetDefsToRemove())
            {
                opts.Definitions.Add(d);
            }
            opts.InterfacesToRemove.Add(new TypeRefUser(Type.Module, "System.Windows.Markup", "IComponentConnector", new AssemblyNameInfo("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35").ToAssemblyRef()));
            opts.InterfacesToRemove.Add(new TypeRefUser(Type.Module, "System.Windows.Markup", "IComponentConnector", new AssemblyNameInfo("System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089").ToAssemblyRef()));
            decompiler.Decompile(DecompilationType.PartialType, opts);
        }
コード例 #13
0
ファイル: ResXProjectFile.cs プロジェクト: xisuo67/dnSpy
        List <ResXDataNode> ReadResourceEntries(DecompileContext ctx)
        {
            var list   = new List <ResXDataNode>();
            int errors = 0;

            try {
                using (var reader = new ResourceReader(embeddedResource.CreateReader().AsStream())) {
                    var iter = reader.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        ctx.CancellationToken.ThrowIfCancellationRequested();
                        string?key = null;
                        try {
                            key = iter.Key as string;
                            if (key is null)
                            {
                                continue;
                            }
                            var value = iter.Value;
                            // ResXDataNode ctor checks if the input is serializable, which this stream isn't.
                            // We have no choice but to create a new stream.
                            if (value is Stream && !value.GetType().IsSerializable)
                            {
                                var stream = (Stream)value;
                                var data   = new byte[stream.Length];
                                if (stream.Read(data, 0, data.Length) != data.Length)
                                {
                                    throw new IOException("Could not read all bytes");
                                }
                                value = new MemoryStream(data);
                            }
                            //TODO: Some resources, like images, should be saved as separate files. Use ResXFileRef.
                            //		Don't do it if it's a satellite assembly.
                            list.Add(delegateResXDataNodeConstructor?.Invoke(key, value, TypeNameConverter) ?? new ResXDataNode(key, value));
                        }
                        catch (Exception ex) {
                            if (errors++ < 30)
                            {
                                ctx.Logger.Error($"Could not add resource '{key}', Message: {ex.Message}");
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {
                ctx.Logger.Error($"Could not read resources from {embeddedResource.Name}, Message: {ex.Message}");
            }
            return(list);
        }
コード例 #14
0
        public override void Create(DecompileContext ctx)
        {
            IList <string> refs;

            using (var stream = File.Create(Filename))
                refs = decompileBaml(bamlData, stream);
            foreach (var asmRef in refs)
            {
                var a = new AssemblyNameInfo(asmRef);
                if (!UTF8String.IsNullOrEmpty(a.Name))
                {
                    asmRefs.Add(a);
                }
            }
        }
コード例 #15
0
 public override void Create(DecompileContext ctx)
 {
     using (var writer = new StreamWriter(Filename, false, Encoding.UTF8)) {
         if (typeFile.Decompiler.CanDecompile(DecompilationType.PartialType))
         {
             var output = createDecompilerOutput(writer);
             var opts   = new DecompilePartialType(output, typeFile.DecompilationContext, typeFile.Type);
             foreach (var d in typeFile.GetDefsToRemove())
             {
                 opts.Definitions.Add(d);
             }
             opts.ShowDefinitions = true;
             typeFile.Decompiler.Decompile(DecompilationType.PartialType, opts);
         }
     }
 }
コード例 #16
0
		public override void Create(DecompileContext ctx) {
			var settings = new XmlWriterSettings {
				Encoding = Encoding.UTF8,
				Indent = true,
			};
			using (var writer = XmlWriter.Create(filename, settings)) {
				writer.WriteProcessingInstruction("xml", "version='1.0' encoding='utf-8'");
				writer.WriteStartElement("SettingsFile", "http://schemas.microsoft.com/VisualStudio/2004/01/settings");
				writer.WriteAttributeString("CurrentProfile", DEFAULT_PROFILE);
				writer.WriteAttributeString("GeneratedClassNamespace", type.ReflectionNamespace);
				writer.WriteAttributeString("GeneratedClassName", type.ReflectionName);

				writer.WriteStartElement("Profiles");
				writer.WriteEndElement();

				writer.WriteStartElement("Settings");
				foreach (var setting in FindSettings()) {
					writer.WriteStartElement("Setting");
					writer.WriteAttributeString("Name", setting.Name);
					if (!string.IsNullOrEmpty(setting.Description))
						writer.WriteAttributeString("Description", setting.Description);
					if (!string.IsNullOrEmpty(setting.Provider))
						writer.WriteAttributeString("Provider", setting.Provider);
					if (setting.Roaming)
						writer.WriteAttributeString("Roaming", "true");
					if (!setting.GenerateDefaultValueInCode)
						writer.WriteAttributeString("GenerateDefaultValueInCode", "false");
					writer.WriteAttributeString("Type", setting.Type);
					writer.WriteAttributeString("Scope", setting.Scope);
					if (setting.DesignTimeValue != null) {
						writer.WriteStartElement("DesignTimeValue");
						writer.WriteAttributeString("Profile", setting.DesignTimeValue.Profile);
						writer.WriteString(setting.DesignTimeValue.Text);
						writer.WriteEndElement();
					}
					writer.WriteStartElement("Value");
					writer.WriteAttributeString("Profile", setting.Value.Profile);
					writer.WriteString(setting.Value.Text);
					writer.WriteEndElement();
					writer.WriteEndElement();
				}
				writer.WriteEndElement();

				writer.WriteEndElement();
				writer.WriteEndDocument();
			}
		}
コード例 #17
0
        public override void Create(DecompileContext ctx)
        {
            var settings = new XmlWriterSettings {
                Encoding           = Encoding.UTF8,
                Indent             = true,
                OmitXmlDeclaration = true,
            };

            using (var writer = XmlWriter.Create(Filename, settings)) {
                writer.WriteStartDocument();
                writer.WriteStartElement("Application", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");

                writer.WriteAttributeString("x", "Class", "http://schemas.microsoft.com/winfx/2006/xaml", type.ReflectionFullName);

                if (type.IsNotPublic)
                {
                    var opts = BamlDecompilerOptions.Create(decompiler);
                    writer.WriteAttributeString("x", "ClassModifier", "http://schemas.microsoft.com/winfx/2006/xaml", opts.InternalClassModifier);
                }

                var body = GetInitializeComponentBody();
                Debug.Assert(body != null);
                if (body != null)
                {
                    var startupUri = GetStartupUri(body);
                    if (startupUri != null)
                    {
                        writer.WriteAttributeString("StartupUri", startupUri);
                    }

                    foreach (var info in GetEvents(body))
                    {
                        writer.WriteAttributeString(info.Item1, info.Item2);
                    }
                }

                writer.WriteElementString("Application.Resources", "\r\n");

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
コード例 #18
0
ファイル: ResXProjectFile.cs プロジェクト: zixing131/dnSpy
        List <ResXDataNode> ReadResourceEntries(DecompileContext ctx)
        {
            var list   = new List <ResXDataNode>();
            int errors = 0;

            try {
                using (var reader = new ResourceReader(embeddedResource.GetResourceStream())) {
                    var iter = reader.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        ctx.CancellationToken.ThrowIfCancellationRequested();
                        string key = null;
                        try {
                            key = iter.Key as string;
                            if (key == null)
                            {
                                continue;
                            }
                            //TODO: Some resources, like images, should be saved as separate files. Use ResXFileRef.
                            //		Don't do it if it's a satellite assembly.
                            list.Add(delegateResXDataNodeConstructor?.Invoke(key, iter.Value, TypeNameConverter) ?? new ResXDataNode(key, iter.Value));
                        }
                        catch (Exception ex) {
                            if (errors++ < 30)
                            {
                                ctx.Logger.Error($"Could not add resource '{key}', Message: {ex.Message}");
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {
                ctx.Logger.Error($"Could not read resources from {embeddedResource.Name}, Message: {ex.Message}");
            }
            return(list);
        }
コード例 #19
0
 public void Create(DecompileContext ctx)
 {
     using (var stream = File.Create(Filename))
         stream.Write(data, 0, data.Length);
 }
コード例 #20
0
 public override void Create(DecompileContext ctx)
 {
     using (var stream = File.Create(Filename))
         embeddedResource.GetReader().CopyTo(stream);
 }
コード例 #21
0
		public override void Create(DecompileContext ctx) => File.Copy(existingName, Filename, true);
コード例 #22
0
		public override void Create(DecompileContext ctx) {
			// ApplicationManifest writes the file
		}
コード例 #23
0
 public override void Create(DecompileContext ctx) => File.Copy(existingName, Filename, true);
コード例 #24
0
ファイル: ResXProjectFile.cs プロジェクト: manojdjoshi/dnSpy
		List<ResXDataNode> ReadResourceEntries(DecompileContext ctx) {
			var list = new List<ResXDataNode>();
			int errors = 0;
			try {
				using (var reader = new ResourceReader(embeddedResource.GetResourceStream())) {
					var iter = reader.GetEnumerator();
					while (iter.MoveNext()) {
						ctx.CancellationToken.ThrowIfCancellationRequested();
						string key = null;
						try {
							key = iter.Key as string;
							if (key == null)
								continue;
							//TODO: Some resources, like images, should be saved as separate files. Use ResXFileRef.
							//		Don't do it if it's a satellite assembly.
							list.Add(delegateResXDataNodeConstructor?.Invoke(key, iter.Value, TypeNameConverter) ?? new ResXDataNode(key, iter.Value));
						}
						catch (Exception ex) {
							if (errors++ < 30)
								ctx.Logger.Error($"Could not add resource '{key}', Message: {ex.Message}");
						}
					}
				}
			}
			catch (Exception ex) {
				ctx.Logger.Error($"Could not read resources from {embeddedResource.Name}, Message: {ex.Message}");
			}
			return list;
		}
コード例 #25
0
ファイル: Project.cs プロジェクト: manojdjoshi/dnSpy
		public void CreateProjectFiles(DecompileContext ctx) {
			var filenameCreator = new FilenameCreator(Directory, DefaultNamespace);
			var resourceNameCreator = new ResourceNameCreator(Options.Module, filenameCreator);

			AllowUnsafeBlocks = DotNetUtils.IsUnsafe(Options.Module);
			InitializeSplashScreen();
			if (Options.Decompiler.CanDecompile(DecompilationType.AssemblyInfo)) {
				var filename = filenameCreator.CreateFromRelativePath(Path.Combine(PropertiesFolder, "AssemblyInfo"), Options.Decompiler.FileExtension);
				Files.Add(new AssemblyInfoProjectFile(Options.Module, filename, Options.DecompilationContext, Options.Decompiler, createDecompilerOutput));
			}

			var ep = Options.Module.EntryPoint;
			if (ep != null && ep.DeclaringType != null)
				StartupObject = ep.DeclaringType.ReflectionFullName;

			applicationManifest = ApplicationManifest.TryCreate(Options.Module.Win32Resources, filenameCreator);
			if (ApplicationManifest != null)
				Files.Add(new ApplicationManifestProjectFile(ApplicationManifest.Filename));

			foreach (var rsrc in Options.Module.Resources) {
				ctx.CancellationToken.ThrowIfCancellationRequested();
				switch (rsrc.ResourceType) {
				case ResourceType.Embedded:
					foreach (var file in CreateEmbeddedResourceFiles(Options.Module, resourceNameCreator, (EmbeddedResource)rsrc)) {
						Files.Add(file);
						Files.AddRange(CreateSatelliteFiles(rsrc.Name, filenameCreator, file));
					}
					break;

				case ResourceType.AssemblyLinked:
					//TODO: What should be created here?
					break;

				case ResourceType.Linked:
					//TODO: What should be created here?
					break;

				default:
					break;
				}
			}
			InitializeXaml();
			InitializeResX();
			foreach (var type in Options.Module.Types) {
				ctx.CancellationToken.ThrowIfCancellationRequested();
				if (!DecompileType(type))
					continue;
				Files.Add(CreateTypeProjectFile(type, filenameCreator));
			}
			CreateEmptyAppXamlFile();

			var existingAppConfig = Options.Module.Location + ".config";
			if (File.Exists(existingAppConfig))
				Files.Add(new AppConfigProjectFile(filenameCreator.CreateName("App.config"), existingAppConfig));

			applicationIcon = ApplicationIcon.TryCreate(Options.Module.Win32Resources, Path.GetFileName(Directory), filenameCreator);

			var dirs = new HashSet<string>(Files.Select(a => GetDirectoryName(a.Filename)).Where(a => a != null), StringComparer.OrdinalIgnoreCase);
			int errors = 0;
			foreach (var dir in dirs) {
				ctx.CancellationToken.ThrowIfCancellationRequested();
				try {
					System.IO.Directory.CreateDirectory(dir);
				}
				catch (Exception ex) {
					if (errors++ < 20)
						ctx.Logger.Error(string.Format(dnSpy_Decompiler_Resources.MSBuild_CouldNotCreateDirectory2, dir, ex.Message));
				}
			}
		}
コード例 #26
0
		public override void Create(DecompileContext ctx) {
			InitializeIsEmpty();
			if (!isEmpty)
				base.Create(ctx);
		}
コード例 #27
0
		public override void Create(DecompileContext ctx) {
			using (var stream = File.Create(Filename)) {
				var data = embeddedResource.GetResourceData();
				stream.Write(data, 0, data.Length);
			}
		}
コード例 #28
0
		public override void Create(DecompileContext ctx) {
			using (var writer = new StreamWriter(Filename, false, Encoding.UTF8)) {
				if (winFormsFile.Decompiler.CanDecompile(DecompilationType.PartialType)) {
					var output = createDecompilerOutput(writer);
					var opts = new DecompilePartialType(output, winFormsFile.DecompilationContext, winFormsFile.Type);
					foreach (var d in winFormsFile.GetDefsToRemove())
						opts.Definitions.Add(d);
					opts.ShowDefinitions = true;
					opts.UseUsingDeclarations = false;
					winFormsFile.Decompiler.Decompile(DecompilationType.PartialType, opts);
				}
			}
		}
コード例 #29
0
ファイル: ApplicationManifest.cs プロジェクト: zz110/dnSpy
 public void Create(DecompileContext ctx)
 {
     using (var stream = File.Create(Filename))
         reader.CopyTo(stream);
 }
コード例 #30
0
 protected virtual void Decompile(DecompileContext ctx, IDecompilerOutput output) =>
 decompiler.Decompile(Type, output, decompilationContext);
コード例 #31
0
		public override void Create(DecompileContext ctx) {
			var settings = new XmlWriterSettings {
				Encoding = Encoding.UTF8,
				Indent = true,
				OmitXmlDeclaration = true,
			};
			using (var writer = XmlWriter.Create(Filename, settings)) {
				writer.WriteStartDocument();
				writer.WriteStartElement("Application", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");

				writer.WriteAttributeString("x", "Class", "http://schemas.microsoft.com/winfx/2006/xaml", type.ReflectionFullName);

				if (type.IsNotPublic) {
					var opts = BamlDecompilerOptions.Create(decompiler);
					writer.WriteAttributeString("x", "ClassModifier", "http://schemas.microsoft.com/winfx/2006/xaml", opts.InternalClassModifier);
				}

				var body = GetInitializeComponentBody();
				Debug.Assert(body != null);
				if (body != null) {
					var startupUri = GetStartupUri(body);
					if (startupUri != null)
						writer.WriteAttributeString("StartupUri", startupUri);

					foreach (var info in GetEvents(body))
						writer.WriteAttributeString(info.Item1, info.Item2);
				}

				writer.WriteElementString("Application.Resources", "\r\n");

				writer.WriteEndElement();
				writer.WriteEndDocument();
			}
		}
コード例 #32
0
 public override void Create(DecompileContext ctx)
 {
     // ApplicationManifest writes the file
 }
コード例 #33
0
        public void Create()
        {
            SatelliteAssemblyFinder?satelliteAssemblyFinder = null;

            try {
                var opts = new ParallelOptions {
                    CancellationToken      = options.CancellationToken,
                    MaxDegreeOfParallelism = options.NumberOfThreads <= 0 ? Environment.ProcessorCount : options.NumberOfThreads,
                };
                var filenameCreator = new FilenameCreator(options.Directory);
                var ctx             = new DecompileContext(options.CancellationToken, logger);
                satelliteAssemblyFinder = new SatelliteAssemblyFinder();
                Parallel.ForEach(options.ProjectModules, opts, modOpts => {
                    options.CancellationToken.ThrowIfCancellationRequested();
                    string name;
                    lock (filenameCreator)
                        name = filenameCreator.Create(modOpts.Module);
                    var p = new Project(modOpts, name, satelliteAssemblyFinder, options.CreateDecompilerOutput);
                    lock (projects)
                        projects.Add(p);
                    p.CreateProjectFiles(ctx);
                });

                var  jobs = GetJobs().ToArray();
                bool writeSolutionFile = !string.IsNullOrEmpty(options.SolutionFilename);
                int  maxProgress       = jobs.Length + projects.Count;
                if (writeSolutionFile)
                {
                    maxProgress++;
                }
                progressListener.SetMaxProgress(maxProgress);

                Parallel.ForEach(GetJobs(), opts, job => {
                    options.CancellationToken.ThrowIfCancellationRequested();
                    try {
                        job.Create(ctx);
                    }
                    catch (OperationCanceledException) {
                        throw;
                    }
                    catch (Exception ex) {
                        if (job is IFileJob fjob)
                        {
                            logger.Error(string.Format(dnSpy_Decompiler_Resources.MSBuild_FileCreationFailed3, fjob.Filename, job.Description, ex.Message));
                        }
                        else
                        {
                            logger.Error(string.Format(dnSpy_Decompiler_Resources.MSBuild_FileCreationFailed2, job.Description, ex.Message));
                        }
                    }
                    progressListener.SetProgress(Interlocked.Increment(ref totalProgress));
                });
                Parallel.ForEach(projects, opts, p => {
                    options.CancellationToken.ThrowIfCancellationRequested();
                    try {
                        var writer = new ProjectWriter(p, p.Options.ProjectVersion ?? options.ProjectVersion, projects, options.UserGACPaths);
                        writer.Write();
                    }
                    catch (OperationCanceledException) {
                        throw;
                    }
                    catch (Exception ex) {
                        logger.Error(string.Format(dnSpy_Decompiler_Resources.MSBuild_FailedToCreateProjectFile, p.Filename, ex.Message));
                    }
                    progressListener.SetProgress(Interlocked.Increment(ref totalProgress));
                });
                if (writeSolutionFile)
                {
                    options.CancellationToken.ThrowIfCancellationRequested();
                    try {
                        var writer = new SolutionWriter(options.ProjectVersion, projects, SolutionFilename);
                        writer.Write();
                    }
                    catch (OperationCanceledException) {
                        throw;
                    }
                    catch (Exception ex) {
                        logger.Error(string.Format(dnSpy_Decompiler_Resources.MSBuild_FailedToCreateSolutionFile, SolutionFilename, ex.Message));
                    }
                    progressListener.SetProgress(Interlocked.Increment(ref totalProgress));
                }
                Debug.Assert(totalProgress == maxProgress);
                progressListener.SetProgress(maxProgress);
            }
            finally {
                if (satelliteAssemblyFinder is not null)
                {
                    satelliteAssemblyFinder.Dispose();
                }
            }
        }
コード例 #34
0
ファイル: ApplicationIcon.cs プロジェクト: manojdjoshi/dnSpy
		public void Create(DecompileContext ctx) {
			using (var stream = File.Create(Filename))
				stream.Write(data, 0, data.Length);
		}
コード例 #35
0
ファイル: Project.cs プロジェクト: youxiaotian/dnSpy
        public void CreateProjectFiles(DecompileContext ctx)
        {
            var filenameCreator     = new FilenameCreator(Directory, DefaultNamespace);
            var resourceNameCreator = new ResourceNameCreator(Options.Module, filenameCreator);

            AllowUnsafeBlocks = DotNetUtils.IsUnsafe(Options.Module);
            InitializeSplashScreen();
            if (Options.Decompiler.CanDecompile(DecompilationType.AssemblyInfo))
            {
                var filename = filenameCreator.CreateFromRelativePath(Path.Combine(PropertiesFolder, "AssemblyInfo"), Options.Decompiler.FileExtension);
                Files.Add(new AssemblyInfoProjectFile(Options.Module, filename, Options.DecompilationContext, Options.Decompiler, createDecompilerOutput));
            }

            var ep = Options.Module.EntryPoint;

            if (!(ep is null) && !(ep.DeclaringType is null))
            {
                StartupObject = ep.DeclaringType.ReflectionFullName;
            }

            applicationManifest = ApplicationManifest.TryCreate(Options.Module.Win32Resources, filenameCreator);
            if (!(ApplicationManifest is null))
            {
                Files.Add(new ApplicationManifestProjectFile(ApplicationManifest.Filename));
            }

            foreach (var rsrc in Options.Module.Resources)
            {
                ctx.CancellationToken.ThrowIfCancellationRequested();
                switch (rsrc.ResourceType)
                {
                case ResourceType.Embedded:
                    foreach (var file in CreateEmbeddedResourceFiles(Options.Module, resourceNameCreator, (EmbeddedResource)rsrc))
                    {
                        Files.Add(file);
                        Files.AddRange(CreateSatelliteFiles(rsrc.Name, filenameCreator, file));
                    }
                    break;

                case ResourceType.AssemblyLinked:
                    //TODO: What should be created here?
                    break;

                case ResourceType.Linked:
                    //TODO: What should be created here?
                    break;

                default:
                    break;
                }
            }
            InitializeXaml();
            InitializeResX();
            foreach (var type in Options.Module.Types)
            {
                ctx.CancellationToken.ThrowIfCancellationRequested();
                if (!DecompileType(type))
                {
                    continue;
                }
                Files.Add(CreateTypeProjectFile(type, filenameCreator));
            }
            CreateEmptyAppXamlFile();

            var existingAppConfig = Options.Module.Location + ".config";

            if (File.Exists(existingAppConfig))
            {
                Files.Add(new AppConfigProjectFile(filenameCreator.CreateName("app.config"), existingAppConfig));
            }

            applicationIcon = ApplicationIcon.TryCreate(Options.Module.Win32Resources, Path.GetFileName(Directory), filenameCreator);

            var dirs   = new HashSet <string>(Files.Select(a => GetDirectoryName(a.Filename)).OfType <string>(), StringComparer.OrdinalIgnoreCase);
            int errors = 0;

            foreach (var dir in dirs)
            {
                ctx.CancellationToken.ThrowIfCancellationRequested();
                try {
                    System.IO.Directory.CreateDirectory(dir);
                }
                catch (Exception ex) {
                    if (errors++ < 20)
                    {
                        ctx.Logger.Error(string.Format(dnSpy_Decompiler_Resources.MSBuild_CouldNotCreateDirectory2, dir, ex.Message));
                    }
                }
            }
        }
コード例 #36
0
		public void Create() {
			SatelliteAssemblyFinder satelliteAssemblyFinder = null;
			try {
				var opts = new ParallelOptions {
					CancellationToken = options.CancellationToken,
					MaxDegreeOfParallelism = options.NumberOfThreads <= 0 ? Environment.ProcessorCount : options.NumberOfThreads,
				};
				var filenameCreator = new FilenameCreator(options.Directory);
				var ctx = new DecompileContext(options.CancellationToken, logger);
				satelliteAssemblyFinder = new SatelliteAssemblyFinder();
				Parallel.ForEach(options.ProjectModules, opts, modOpts => {
					options.CancellationToken.ThrowIfCancellationRequested();
					string name;
					lock (filenameCreator)
						name = filenameCreator.Create(modOpts.Module);
					var p = new Project(modOpts, name, satelliteAssemblyFinder, options.CreateDecompilerOutput);
					lock (projects)
						projects.Add(p);
					p.CreateProjectFiles(ctx);
				});

				var jobs = GetJobs().ToArray();
				bool writeSolutionFile = !string.IsNullOrEmpty(options.SolutionFilename);
				int maxProgress = jobs.Length + projects.Count;
				if (writeSolutionFile)
					maxProgress++;
				progressListener.SetMaxProgress(maxProgress);

				Parallel.ForEach(GetJobs(), opts, job => {
					options.CancellationToken.ThrowIfCancellationRequested();
					try {
						job.Create(ctx);
					}
					catch (OperationCanceledException) {
						throw;
					}
					catch (Exception ex) {
						var fjob = job as IFileJob;
						if (fjob != null)
							logger.Error(string.Format(dnSpy_Decompiler_Resources.MSBuild_FileCreationFailed3, fjob.Filename, job.Description, ex.Message));
						else
							logger.Error(string.Format(dnSpy_Decompiler_Resources.MSBuild_FileCreationFailed2, job.Description, ex.Message));
					}
					progressListener.SetProgress(Interlocked.Increment(ref totalProgress));
				});
				Parallel.ForEach(projects, opts, p => {
					options.CancellationToken.ThrowIfCancellationRequested();
					try {
						var writer = new ProjectWriter(p, p.Options.ProjectVersion ?? options.ProjectVersion, projects, options.UserGACPaths);
						writer.Write();
					}
					catch (OperationCanceledException) {
						throw;
					}
					catch (Exception ex) {
						logger.Error(string.Format(dnSpy_Decompiler_Resources.MSBuild_FailedToCreateProjectFile, p.Filename, ex.Message));
					}
					progressListener.SetProgress(Interlocked.Increment(ref totalProgress));
				});
				if (writeSolutionFile) {
					options.CancellationToken.ThrowIfCancellationRequested();
					try {
						var writer = new SolutionWriter(options.ProjectVersion, projects, SolutionFilename);
						writer.Write();
					}
					catch (OperationCanceledException) {
						throw;
					}
					catch (Exception ex) {
						logger.Error(string.Format(dnSpy_Decompiler_Resources.MSBuild_FailedToCreateSolutionFile, SolutionFilename, ex.Message));
					}
					progressListener.SetProgress(Interlocked.Increment(ref totalProgress));
				}
				Debug.Assert(totalProgress == maxProgress);
				progressListener.SetProgress(maxProgress);
			}
			finally {
				if (satelliteAssemblyFinder != null)
					satelliteAssemblyFinder.Dispose();
			}
		}