Exemple #1
0
        private void DecompileAssembly(AssemblyDefinition adef, string outputDir, string location)
        {
            Utils.WriteToConsole("Decompiling assembly: " + adef.FullName);
            //Each visitor is responsible of changing the file if necessary (from here it is ipmossible to know the file names)
            ICSharpCode.Decompiler.ITextOutput textOutput = new ICSharpCode.Decompiler.FileTextOutput(outputDir);
            FileWritterManager.WorkingPath = outputDir;

            ICSharpCode.ILSpy.Language lang = null;
            //CONFIGURE OUTPUT LANGUAGE
            if (Config.ToCSharp)
            {
                lang = OutputLanguage("C#");
            }
            else
            {
                lang = OutputLanguage("CXX");
            }

            if (Config.RecursiveDependencies)
            {
                var resolver = new DefaultAssemblyResolver();
                Utils.WriteToConsole("Adding " + location + " to resolver search directories");
                resolver.AddSearchDirectory(location);
                foreach (AssemblyNameReference anref in adef.MainModule.AssemblyReferences)
                {
                    if (!Config.IgnoreReferences.Contains(anref.Name))
                    {
                        AssemblyDefinition assembly = resolver.Resolve(anref);

                        //TODO: Change directory ?
                        DecompileAssembly(assembly, outputDir, location);
                        if (assembly == null)
                        {
                            Utils.WriteToConsole("alternative: ");
                            Utils.WriteToConsole("ERROR - could not resolve assembly " + anref.FullName + " .");
                        }
                    }
                }
            }

            //DECOMPILE FIRST TIME AND FILL THE TABLES
            foreach (TypeDefinition tdef in adef.MainModule.Types)
            {
                if (!tdef.Name.Contains("<"))
                {
                    lang.DecompileType(tdef, textOutput, new ICSharpCode.ILSpy.DecompilationOptions()
                    {
                        FullDecompilation = false
                    });
                }
            }

            //DECOMPILE
            foreach (TypeDefinition tdef in adef.MainModule.Types)
            {
                if (!tdef.Name.Contains("<"))
                {
                    lang.DecompileType(tdef, textOutput, new ICSharpCode.ILSpy.DecompilationOptions()
                    {
                        FullDecompilation = false
                    });
                    Utils.WriteToConsole("Decompiled: " + tdef.FullName);
                }
            }
        }
Exemple #2
0
        private void DecompileAssembly(AssemblyDefinition adef, string outputDir, string location)
        {
            Utils.WriteToConsole("Decompiling assembly: " + adef.FullName);
            //Each visitor is responsible of changing the file if necessary (from here it is ipmossible to know the file names)
            ICSharpCode.Decompiler.ITextOutput textOutput = new ICSharpCode.Decompiler.FileTextOutput(outputDir);
            FileWritterManager.WorkingPath = outputDir;
            
            ICSharpCode.ILSpy.Language lang = null;
            //CONFIGURE OUTPUT LANGUAGE
            if (Config.ToCSharp)
            {
                 lang = OutputLanguage("C#");
            }
            else
            {
                lang = OutputLanguage("CXX");
            }

            if (Config.RecursiveDependencies)
            {
                var resolver = new DefaultAssemblyResolver();
                Utils.WriteToConsole("Adding " + location + " to resolver search directories");
                resolver.AddSearchDirectory(location);
                foreach (AssemblyNameReference anref in adef.MainModule.AssemblyReferences)
                {
                    if (!Config.IgnoreReferences.Contains(anref.Name))
                    {
                        AssemblyDefinition assembly = resolver.Resolve(anref);

                        //TODO: Change directory ?
                        DecompileAssembly(assembly, outputDir, location);
                        if (assembly == null)
                        {
                            Utils.WriteToConsole("alternative: ");
                            Utils.WriteToConsole("ERROR - could not resolve assembly " + anref.FullName + " .");
                        }
                    }
                }
            }

            //DECOMPILE FIRST TIME AND FILL THE TABLES
            foreach (TypeDefinition tdef in adef.MainModule.Types)
            {
                if (!tdef.Name.Contains("<"))
                {
                    lang.DecompileType(tdef, textOutput, new ICSharpCode.ILSpy.DecompilationOptions() { FullDecompilation = false });
                }
            }

            //DECOMPILE
            foreach (TypeDefinition tdef in adef.MainModule.Types)
            {
                if (!tdef.Name.Contains("<"))
                {
                    lang.DecompileType(tdef, textOutput, new ICSharpCode.ILSpy.DecompilationOptions() { FullDecompilation = false });
                    Utils.WriteToConsole("Decompiled: " + tdef.FullName);
                }
            }
        }