コード例 #1
0
        public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
        {
            output.WriteLine("// " + assembly.FileName);
            output.WriteLine();

            var dis    = CreateDisassembler(output, options);
            var module = assembly.GetModuleDefinitionAsync().Result;

            if (options.FullDecompilation)
            {
                dis.WriteAssemblyReferences(module);
            }
            if (module.Assembly != null)
            {
                dis.WriteAssemblyHeader(module.Assembly);
            }
            output.WriteLine();
            dis.WriteModuleHeader(module);
            if (options.FullDecompilation)
            {
                output.WriteLine();
                output.WriteLine();
                dis.WriteModuleContents(module);
            }
        }
コード例 #2
0
        public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
        {
            var module = assembly.GetModuleDefinitionAsync().Result;

            if (options.FullDecompilation && options.SaveAsProjectDirectory != null)
            {
                var decompiler = new ILSpyWholeProjectDecompiler(assembly, options);
                decompiler.DecompileProject(module, options.SaveAsProjectDirectory, new TextOutputWriter(output), options.CancellationToken);
            }
            else
            {
                AddReferenceWarningMessage(module.Assembly, output);
                output.WriteLine();
                base.DecompileAssembly(assembly, output, options);
                ModuleDefinition mainModule = module;
                if (mainModule.Types.Count > 0)
                {
                    output.Write("// Global type: ");
                    output.WriteReference(mainModule.Types[0].FullName, mainModule.Types[0]);
                    output.WriteLine();
                }
                if (mainModule.EntryPoint != null)
                {
                    output.Write("// Entry point: ");
                    output.WriteReference(mainModule.EntryPoint.DeclaringType.FullName + "." + mainModule.EntryPoint.Name, mainModule.EntryPoint);
                    output.WriteLine();
                }
                output.WriteLine("// Architecture: " + GetPlatformDisplayName(mainModule));
                if ((mainModule.Attributes & ModuleAttributes.ILOnly) == 0)
                {
                    output.WriteLine("// This assembly contains unmanaged code.");
                }
                string runtimeName = GetRuntimeDisplayName(mainModule);
                if (runtimeName != null)
                {
                    output.WriteLine("// Runtime: " + runtimeName);
                }
                output.WriteLine();

                // don't automatically load additional assemblies when an assembly node is selected in the tree view
                using (options.FullDecompilation ? null : LoadedAssembly.DisableAssemblyLoad()) {
                    CSharpDecompiler decompiler = new CSharpDecompiler(module, options.DecompilerSettings);
                    decompiler.CancellationToken = options.CancellationToken;
                    SyntaxTree st;
                    if (options.FullDecompilation)
                    {
                        st = decompiler.DecompileWholeModuleAsSingleFile();
                    }
                    else
                    {
                        st = decompiler.DecompileModuleAndAssemblyAttributes();
                    }
                    WriteCode(output, options.DecompilerSettings, st, decompiler.TypeSystem);
                }
            }
        }
コード例 #3
0
        public virtual void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
        {
            WriteCommentLine(output, assembly.FileName);
            var asm = assembly.GetAssemblyDefinitionOrNull();

            if (asm != null)
            {
                var name = asm.Name;
                if (name.IsWindowsRuntime)
                {
                    WriteCommentLine(output, name.Name + " [WinRT]");
                }
                else
                {
                    WriteCommentLine(output, name.FullName);
                }
            }
            else
            {
                WriteCommentLine(output, assembly.GetModuleDefinitionAsync().Result.Name);
            }
        }