示例#1
0
 public List <ReferenceSegment> Decompile(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
 {
     return(Disassemble(data, navigator));
 }
        public static List <ReferenceSegment> Decompile(TextEditor data, AssemblyLoader assemblyLoader, Func <CSharpDecompiler, SyntaxTree> decompile, DecompilerSettings settings = null, DecompileFlags flags = null)
        {
            settings = settings ?? GetDecompilerSettings(data, publicOnly: flags.PublicOnly);
            var csharpDecompiler = assemblyLoader.CSharpDecompiler;

            try
            {
                var syntaxTree = decompile(csharpDecompiler);
                if (!flags.MethodBodies)
                {
                    MethodBodyRemoveVisitor.RemoveMethodBodies(syntaxTree);
                }

                var         output      = new ColoredCSharpFormatter(data);
                TokenWriter tokenWriter = new TextTokenWriter(output, settings, csharpDecompiler.TypeSystem)
                {
                    FoldBraces = settings.FoldBraces
                };
                var formattingPolicy = settings.CSharpFormattingOptions;
                syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, formattingPolicy));
                output.SetDocumentData();
                return(output.ReferencedSegments);
            }
            catch (Exception e)
            {
                data.InsertText(data.Length, "/* decompilation failed: \n" + e + " */");
            }
            return(null);
        }
        public List <ReferenceSegment> Decompile(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
        {
            var method = (IUnresolvedMethod)navigator.DataItem;

            if (HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var cecilMethod = GetCecilLoader(navigator).GetCecilObject <MethodDefinition> (method);

            if (cecilMethod == null)
            {
                return(null);
            }
            return(DomMethodNodeBuilder.Decompile(data, DomMethodNodeBuilder.GetAssemblyLoader(navigator), b => b.Decompile(cecilMethod), flags: flags));
        }
示例#4
0
        List <ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
        {
            if (DomMethodNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var evt = GetCecilLoader(navigator).GetCecilObject <EventDefinition>((IUnresolvedEvent)navigator.DataItem);

            if (evt == null)
            {
                return(null);
            }
            return(DomMethodNodeBuilder.Decompile(data, DomMethodNodeBuilder.GetAssemblyLoader(navigator), b => b.Decompile(evt), flags: flags));
        }
        public List <ReferenceSegment> Decompile(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
        {
            if (HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var cecilMethod = (MethodDefinition)navigator.DataItem;

            if (cecilMethod == null)
            {
                return(null);
            }
            return(MethodDefinitionNodeBuilder.Decompile(data, MethodDefinitionNodeBuilder.GetAssemblyLoader(navigator), b => b.Decompile(cecilMethod), flags: flags));
        }
示例#6
0
        List <ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
        {
            if (MethodDefinitionNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var property = navigator.DataItem as PropertyDefinition;

            if (property == null)
            {
                return(null);
            }
            return(MethodDefinitionNodeBuilder.Decompile(data, MethodDefinitionNodeBuilder.GetAssemblyLoader(navigator), b => b.Decompile(property), flags: flags));
        }
        public Task <List <ReferenceSegment> > DecompileAsync(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
        {
            var assemblyLoader = (AssemblyLoader)navigator.DataItem;

            return(MethodDefinitionNodeBuilder.DecompileAsync(data, MethodDefinitionNodeBuilder.GetAssemblyLoader(navigator), b =>
                                                              b.DecompileModuleAndAssemblyAttributes(), flags: flags));
        }
示例#8
0
        public List <ReferenceSegment> Decompile(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
        {
            if (DomMethodNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var type = (IUnresolvedTypeDefinition)navigator.DataItem;

            if (type == null)
            {
                return(null);
            }
            var settings = DomMethodNodeBuilder.GetDecompilerSettings(data, flags.PublicOnly);

            return(DomMethodNodeBuilder.Decompile(data, DomMethodNodeBuilder.GetAssemblyLoader(navigator), builder => builder.DecompileType(type.FullTypeName), flags: flags));
        }
示例#9
0
 Task <List <ReferenceSegment> > IAssemblyBrowserNodeBuilder.DecompileAsync(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
 {
     if (MethodDefinitionNodeBuilder.HandleSourceCodeEntity(navigator, data))
     {
         return(EmptyReferenceSegmentTask);
     }
     if (!(navigator.DataItem is IProperty property))
     {
         return(EmptyReferenceSegmentTask);
     }
     return(MethodDefinitionNodeBuilder.DecompileAsync(data, MethodDefinitionNodeBuilder.GetAssemblyLoader(navigator), b => b.Decompile(property.MetadataToken), flags: flags));
 }
示例#10
0
		Task<List<ReferenceSegment>> IAssemblyBrowserNodeBuilder.DecompileAsync (TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
		{
			if (MethodDefinitionNodeBuilder.HandleSourceCodeEntity (navigator, data)) 
				return EmptyReferenceSegmentTask;
			var evt = navigator.DataItem as IEvent;
			if (evt == null)
				return EmptyReferenceSegmentTask;
			return MethodDefinitionNodeBuilder.DecompileAsync (data, MethodDefinitionNodeBuilder.GetAssemblyLoader (navigator), b => b.Decompile (evt.MetadataToken), flags: flags);
		}
        public static Task <List <ReferenceSegment> > DecompileAsync(TextEditor data, AssemblyLoader assemblyLoader, Func <CSharpDecompiler, SyntaxTree> decompile, DecompilerSettings settings = null, DecompileFlags flags = null)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (assemblyLoader == null)
            {
                throw new ArgumentNullException(nameof(assemblyLoader));
            }

            return(Task.Run(async delegate {
                settings = settings ?? GetDecompilerSettings(data, publicOnly: flags.PublicOnly);
                var csharpDecompiler = assemblyLoader.CSharpDecompiler;
                try {
                    var syntaxTree = decompile(csharpDecompiler);
                    if (!flags.MethodBodies)
                    {
                        MethodBodyRemoveVisitor.RemoveMethodBodies(syntaxTree);
                    }
                    return await Runtime.RunInMainThread(delegate {
                        if (data.IsDisposed)
                        {
                            return new List <ReferenceSegment> ();
                        }
                        var output = new ColoredCSharpFormatter(data);
                        TokenWriter tokenWriter = new TextTokenWriter(output, settings, csharpDecompiler.TypeSystem)
                        {
                            FoldBraces = settings.FoldBraces
                        };
                        var formattingPolicy = settings.CSharpFormattingOptions;
                        syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, formattingPolicy));
                        output.SetDocumentData();
                        return output.ReferencedSegments;
                    });
                } catch (Exception e) {
                    await Runtime.RunInMainThread(delegate {
                        data.InsertText(data.Length, "/* decompilation failed: \n" + e + " */");
                    });
                }
                return new List <ReferenceSegment> ();
            }));
        }
        public Task <List <ReferenceSegment> > DecompileAsync(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
        {
            if (MethodDefinitionNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(EmptyReferenceSegmentTask);
            }
            var type = (ITypeDefinition)navigator.DataItem;

            if (type == null)
            {
                return(EmptyReferenceSegmentTask);
            }
            var settings = MethodDefinitionNodeBuilder.GetDecompilerSettings(data, flags.PublicOnly);

            // CSharpLanguage.Instance.DecompileType (type, output, settings);
            return(MethodDefinitionNodeBuilder.DecompileAsync(
                       data,
                       MethodDefinitionNodeBuilder.GetAssemblyLoader(navigator),
                       builder => builder.Decompile(type.MetadataToken), flags: flags));
        }
示例#13
0
        public List <ReferenceSegment> Decompile(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
        {
            var assemblyLoader = (AssemblyLoader)navigator.DataItem;

            return(DomMethodNodeBuilder.Decompile(data, DomMethodNodeBuilder.GetAssemblyLoader(navigator), b =>
                                                  b.DecompileModuleAndAssemblyAttributes(), flags: flags));
        }
示例#14
0
        List <ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile(TextEditor data, ITreeNavigator navigator, DecompileFlags flags)
        {
            if (MethodDefinitionNodeBuilder.HandleSourceCodeEntity(navigator, data))
            {
                return(null);
            }
            var field = (IField)navigator.DataItem;

            if (field == null)
            {
                return(null);
            }
            return(MethodDefinitionNodeBuilder.Decompile(data, MethodDefinitionNodeBuilder.GetAssemblyLoader(navigator), b => b.Decompile(field.MetadataToken), flags: flags));
        }