DecompileType() public method

public DecompileType ( Mono.Cecil.TypeDefinition type, ITextOutput output, DecompilationOptions options ) : void
type Mono.Cecil.TypeDefinition
output ITextOutput
options DecompilationOptions
return void
示例#1
0
        public override void Decompile(ICSharpCode.ILSpy.Language language, ITextOutput output, ICSharpCode.ILSpy.DecompilationOptions options)
        {
            //Switches on the token
            switch (_tokenProvider.MetadataToken.TokenType)
            {
            case TokenType.Module:
                language.DecompileModule((ModuleDefinition)_tokenProvider, output, options);
                break;

            case TokenType.Assembly:
                language.WriteCommentLine(output, ((AssemblyNameReference)_tokenProvider).FullName);
                break;

            case TokenType.TypeDef:
                language.DecompileType((TypeDefinition)_tokenProvider, output, options);
                break;

            case TokenType.Field:
                language.DecompileField((FieldDefinition)_tokenProvider, output, options);
                break;

            case TokenType.Method:
                language.DecompileMethod((MethodDefinition)_tokenProvider, output, options);
                break;

            case TokenType.Event:
                language.DecompileEvent((EventDefinition)_tokenProvider, output, options);
                break;

            case TokenType.Property:
                language.DecompileProperty((PropertyDefinition)_tokenProvider, output, options);
                break;

            case TokenType.MemberRef:
                var memberRef = (MemberReference)_tokenProvider;
                if (memberRef.DeclaringType != null && memberRef.DeclaringType is GenericInstanceType)
                {
                    var giType    = (GenericInstanceType)memberRef.DeclaringType;
                    var type      = giType.ElementType.Resolve();
                    var memberDef = type.Fields.Cast <IMemberDefinition>()
                                    .Concat(type.Methods)
                                    .Concat(type.Properties)
                                    .Concat(type.Events)
                                    .FirstOrDefault(m => m.Name == memberRef.Name);
                    if (memberDef != null)
                    {
                        new ILEditTreeNode(memberDef, true).Decompile(language, output, options);
                    }
                }
                break;

            default:
                language.WriteCommentLine(output, (string)this.Text);
                break;
            }
        }
示例#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);
                }
            }
        }
示例#3
0
 private void DecomplieType(Language language, TypeDefinition type, ITextOutput output, DecompilationOptions options)
 {
     language.DecompileType(type, output, options);
 }
        public string Decompile(string language, object o)
        {
            if (o == null)
            {
                return(String.Empty);
            }
            Language l = CreateLanguage(language);

            if (l == null)
            {
                return(String.Format("Can't create language: {0}", language));
            }

            ITextOutput          output  = new RtfTextOutput();
            DecompilationOptions options = new DecompilationOptions();

            if (o is AssemblyDefinition)
            {
                l.DecompileAssembly((AssemblyDefinition)o, output, options);
            }
            else if (o is TypeDefinition)
            {
                l.DecompileType((TypeDefinition)o, output, options);
            }
            else if (o is MethodDefinition)
            {
                l.DecompileMethod((MethodDefinition)o, output, options);
            }
            else if (o is FieldDefinition)
            {
                l.DecompileField((FieldDefinition)o, output, options);
            }
            else if (o is PropertyDefinition)
            {
                l.DecompileProperty((PropertyDefinition)o, output, options);
            }
            else if (o is EventDefinition)
            {
                l.DecompileEvent((EventDefinition)o, output, options);
            }
            else if (o is AssemblyNameReference)
            {
                output.Write("// Assembly Reference ");
                output.WriteDefinition(o.ToString(), null);
                output.WriteLine();
            }
            else if (o is ModuleReference)
            {
                output.Write("// Module Reference ");
                output.WriteDefinition(o.ToString(), null);
                output.WriteLine();
            }
            else
            {
                output.Write(String.Format("// {0} ", o.GetType().Name));
                output.WriteDefinition(o.ToString(), null);
                output.WriteLine();
            }

            return(output.ToString());
        }