示例#1
0
文件: Program.cs 项目: xornand/dnSpy
        static void DumpNetModule(ProjectInfo info, List <ProjectInfo> projectFiles)
        {
            var fileName = info.AssemblyFileName;

            if (string.IsNullOrEmpty(fileName))
            {
                throw new Exception(".NET module filename is empty or null");
            }

            var listOpts = new DnSpyFileListOptionsImpl();

            listOpts.UseGAC            = !noGac;
            listOpts.UseDebugSymbols   = true;
            listOpts.UseMemoryMappedIO = true;
            var fileList = new DnSpyFileList(listOpts, string.Empty);

            fileList.AssemblyResolver.AddSearchPath(Path.GetDirectoryName(fileName));
            foreach (var path in asmPaths)
            {
                fileList.AssemblyResolver.AddSearchPath(path);
            }
            var file = fileList.OpenFile(fileName);
            var opts = new DecompilationOptions {
                FullDecompilation = true,
                CancellationToken = new CancellationToken(),
            };

            TextWriter writer = null;

            try {
                var lang = GetLanguage();

                if (useStdout)
                {
                    writer = System.Console.Out;
                }
                else
                {
                    var baseDir = GetProjectDir(lang, fileName);
                    Directory.CreateDirectory(baseDir);
                    writer = new StreamWriter(info.ProjectFileName, false, Encoding.UTF8);
                    opts.SaveAsProjectDirectory             = baseDir;
                    opts.DontReferenceStdLib                = noCorlibRef;
                    opts.ProjectFiles                       = projectFiles;
                    opts.ProjectGuid                        = info.ProjectGuid;
                    opts.DontShowCreateMethodBodyExceptions = dontMaskErr;
                    Console.WriteLine("Saving {0} to {1}", fileName, baseDir);
                }

                lang.DecompileAssembly(fileList, file, new PlainTextOutput(writer), opts);
            }
            finally {
                if (!useStdout && writer != null)
                {
                    writer.Dispose();
                }
            }
        }
示例#2
0
		static void DumpNetModule(ProjectInfo info, List<ProjectInfo> projectFiles) {
			var fileName = info.AssemblyFileName;
			if (string.IsNullOrEmpty(fileName))
				throw new Exception(".NET module filename is empty or null");

			var listOpts = new DnSpyFileListOptionsImpl();
			listOpts.UseGAC = !noGac;
			listOpts.UseDebugSymbols = true;
			listOpts.UseMemoryMappedIO = true;
			var fileList = new DnSpyFileList(listOpts, string.Empty);
			fileList.AssemblyResolver.AddSearchPath(Path.GetDirectoryName(fileName));
			foreach (var path in asmPaths)
				fileList.AssemblyResolver.AddSearchPath(path);
			var file = fileList.OpenFile(fileName);
			var opts = new DecompilationOptions {
				FullDecompilation = true,
				CancellationToken = new CancellationToken(),
			};

			TextWriter writer = null;
			try {
				var lang = GetLanguage();

				if (useStdout)
					writer = System.Console.Out;
				else {
					var baseDir = GetProjectDir(lang, fileName);
					Directory.CreateDirectory(baseDir);
					writer = new StreamWriter(info.ProjectFileName, false, Encoding.UTF8);
					opts.SaveAsProjectDirectory = baseDir;
					opts.DontReferenceStdLib = noCorlibRef;
					opts.ProjectFiles = projectFiles;
					opts.ProjectGuid = info.ProjectGuid;
					opts.DontShowCreateMethodBodyExceptions = dontMaskErr;
					Console.WriteLine("Saving {0} to {1}", fileName, baseDir);
				}

				lang.DecompileAssembly(fileList, file, new PlainTextOutput(writer), opts);
			}
			finally {
				if (!useStdout && writer != null)
					writer.Dispose();
			}
		}