Ejemplo n.º 1
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 asmList = new AssemblyList("dnspc.exe", false);

            asmList.UseGAC = !noGac;
            asmList.AddSearchPath(Path.GetDirectoryName(fileName));
            foreach (var path in asmPaths)
            {
                asmList.AddSearchPath(path);
            }
            var lasm = new LoadedAssembly(asmList, 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(lasm, new PlainTextOutput(writer), opts);
            }
            finally {
                if (!useStdout && writer != null)
                {
                    writer.Dispose();
                }
            }
        }