Exemple #1
0
        public override void DecompileAssembly(DnSpyFileList dnSpyFileList, DnSpyFile file, ITextOutput output, DecompilationOptions options, DecompileAssemblyFlags flags = DecompileAssemblyFlags.AssemblyAndModule)
        {
            if (options.FullDecompilation && options.SaveAsProjectDirectory != null)
            {
                HashSet <string> directories = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                var files = WriteCodeFilesInProject(dnSpyFileList, file.ModuleDef, options, directories).ToList();
                files.AddRange(WriteResourceFilesInProject(file, options, directories));
                WriteProjectFile(dnSpyFileList, new TextOutputWriter(output), files, file, options);
            }
            else
            {
                bool decompileAsm = (flags & DecompileAssemblyFlags.Assembly) != 0;
                bool decompileMod = (flags & DecompileAssemblyFlags.Module) != 0;
                base.DecompileAssembly(dnSpyFileList, file, output, options, flags);
                output.WriteLine();
                ModuleDef mainModule = file.ModuleDef;
                if (decompileMod && mainModule.Types.Count > 0)
                {
                    output.Write("' Global type: ", TextTokenType.Comment);
                    output.WriteReference(IdentifierEscaper.Escape(mainModule.GlobalType.FullName), mainModule.GlobalType, TextTokenType.Comment);
                    output.WriteLine();
                }
                if (decompileMod || decompileAsm)
                {
                    PrintEntryPoint(file, output);
                }
                if (decompileMod)
                {
                    WriteCommentLine(output, "Architecture: " + CSharpLanguage.GetPlatformDisplayName(mainModule));
                    if (!mainModule.IsILOnly)
                    {
                        WriteCommentLine(output, "This assembly contains unmanaged code.");
                    }
                    string runtimeName = ICSharpCode.ILSpy.CSharpLanguage.GetRuntimeDisplayName(mainModule);
                    if (runtimeName != null)
                    {
                        WriteCommentLine(output, "Runtime: " + runtimeName);
                    }
                }
                if (decompileMod || decompileAsm)
                {
                    output.WriteLine();
                }

                // don't automatically load additional assemblies when an assembly node is selected in the tree view
                using (options.FullDecompilation ? null : dnSpyFileList.DisableAssemblyLoad()) {
                    AstBuilder codeDomBuilder = CreateAstBuilder(options, currentModule: file.ModuleDef);
                    codeDomBuilder.AddAssembly(file.ModuleDef, !options.FullDecompilation, decompileAsm, decompileMod);
                    RunTransformsAndGenerateCode(codeDomBuilder, output, options, file.ModuleDef);
                }
            }
        }
Exemple #2
0
        IEnumerable <Tuple <string, string> > WriteAssemblyInfo(DnSpyFileList dnSpyFileList, ModuleDef module, DecompilationOptions options, HashSet <string> directories)
        {
            // don't automatically load additional assemblies when an assembly node is selected in the tree view
            using (dnSpyFileList.DisableAssemblyLoad()) {
                AstBuilder codeDomBuilder = CreateAstBuilder(options, currentModule: module);
                codeDomBuilder.AddAssembly(module, true, true, true);
                codeDomBuilder.RunTransformations(transformAbortCondition);

                string prop = "Properties";
                if (directories.Add("Properties"))
                {
                    Directory.CreateDirectory(Path.Combine(options.SaveAsProjectDirectory, prop));
                }
                string assemblyInfo = Path.Combine(prop, "AssemblyInfo" + this.FileExtension);
                using (StreamWriter w = new StreamWriter(Path.Combine(options.SaveAsProjectDirectory, assemblyInfo)))
                    codeDomBuilder.GenerateCode(new PlainTextOutput(w));
                return(new Tuple <string, string>[] { Tuple.Create("Compile", assemblyInfo) });
            }
        }