public GetDocument ( ) : |
||
리턴 |
/// <summary> /// Shows the given output in the text view. /// </summary> void ShowOutput(AvalonEditTextOutput textOutput, IHighlightingDefinition highlighting = null, DecompilerTextViewState state = null) { Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength); Stopwatch w = Stopwatch.StartNew(); textEditor.ScrollToHome(); if (foldingManager != null) { FoldingManager.Uninstall(foldingManager); foldingManager = null; } textEditor.Document = null; // clear old document while we're changing the highlighting uiElementGenerator.UIElements = textOutput.UIElements; referenceElementGenerator.References = textOutput.References; definitionLookup = textOutput.DefinitionLookup; textEditor.SyntaxHighlighting = highlighting; Debug.WriteLine(" Set-up: {0}", w.Elapsed); w.Restart(); textEditor.Document = textOutput.GetDocument(); Debug.WriteLine(" Assigning document: {0}", w.Elapsed); w.Restart(); if (textOutput.Foldings.Count > 0) { if (state != null) { state.RestoreFoldings(textOutput.Foldings); textEditor.ScrollToVerticalOffset(state.VerticalOffset); textEditor.ScrollToHorizontalOffset(state.HorizontalOffset); } foldingManager = FoldingManager.Install(textEditor.TextArea); foldingManager.UpdateFoldings(textOutput.Foldings.OrderBy(f => f.StartOffset), -1); Debug.WriteLine(" Updating folding: {0}", w.Elapsed); w.Restart(); } }
/// <summary> /// Shows the given output in the text view. /// </summary> void ShowOutput(AvalonEditTextOutput textOutput, IHighlightingDefinition highlighting = null, DecompilerTextViewState state = null) { Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength); Stopwatch w = Stopwatch.StartNew(); ClearLocalReferenceMarks(); textEditor.ScrollToHome(); if (foldingManager != null) { FoldingManager.Uninstall(foldingManager); foldingManager = null; } textEditor.Document = null; // clear old document while we're changing the highlighting uiElementGenerator.UIElements = textOutput.UIElements; referenceElementGenerator.References = textOutput.References; references = textOutput.References; definitionLookup = textOutput.DefinitionLookup; textEditor.SyntaxHighlighting = highlighting; textEditor.Options.EnableEmailHyperlinks = textOutput.EnableHyperlinks; textEditor.Options.EnableHyperlinks = textOutput.EnableHyperlinks; if (activeRichTextColorizer != null) { textEditor.TextArea.TextView.LineTransformers.Remove(activeRichTextColorizer); } if (textOutput.HighlightingModel != null) { activeRichTextColorizer = new RichTextColorizer(textOutput.HighlightingModel); textEditor.TextArea.TextView.LineTransformers.Insert(highlighting == null ? 0 : 1, activeRichTextColorizer); } // Change the set of active element generators: foreach (var elementGenerator in activeCustomElementGenerators) { textEditor.TextArea.TextView.ElementGenerators.Remove(elementGenerator); } activeCustomElementGenerators.Clear(); foreach (var elementGenerator in textOutput.elementGenerators) { textEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator); activeCustomElementGenerators.Add(elementGenerator); } Debug.WriteLine(" Set-up: {0}", w.Elapsed); w.Restart(); textEditor.Document = textOutput.GetDocument(); Debug.WriteLine(" Assigning document: {0}", w.Elapsed); w.Restart(); if (textOutput.Foldings.Count > 0) { if (state != null) { state.RestoreFoldings(textOutput.Foldings); textEditor.ScrollToVerticalOffset(state.VerticalOffset); textEditor.ScrollToHorizontalOffset(state.HorizontalOffset); } foldingManager = FoldingManager.Install(textEditor.TextArea); foldingManager.UpdateFoldings(textOutput.Foldings.OrderBy(f => f.StartOffset), -1); Debug.WriteLine(" Updating folding: {0}", w.Elapsed); w.Restart(); } }
/// <summary> /// Shows the given output in the text view. /// </summary> void ShowOutput(AvalonEditTextOutput textOutput, IHighlightingDefinition highlighting = null, DecompilerTextViewState state = null) { Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength); Stopwatch w = Stopwatch.StartNew(); ClearLocalReferenceMarks(); textEditor.ScrollToHome(); if (foldingManager != null) { FoldingManager.Uninstall(foldingManager); foldingManager = null; } textEditor.Document = null; // clear old document while we're changing the highlighting uiElementGenerator.UIElements = textOutput.UIElements; referenceElementGenerator.References = textOutput.References; references = textOutput.References; definitionLookup = textOutput.DefinitionLookup; textEditor.SyntaxHighlighting = highlighting; // Change the set of active element generators: foreach (var elementGenerator in activeCustomElementGenerators) { textEditor.TextArea.TextView.ElementGenerators.Remove(elementGenerator); } activeCustomElementGenerators.Clear(); foreach (var elementGenerator in textOutput.elementGenerators) { textEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator); activeCustomElementGenerators.Add(elementGenerator); } Debug.WriteLine(" Set-up: {0}", w.Elapsed); w.Restart(); textEditor.Document = textOutput.GetDocument(); Debug.WriteLine(" Assigning document: {0}", w.Elapsed); w.Restart(); if (textOutput.Foldings.Count > 0) { if (state != null) { state.RestoreFoldings(textOutput.Foldings); textEditor.ScrollToVerticalOffset(state.VerticalOffset); textEditor.ScrollToHorizontalOffset(state.HorizontalOffset); } foldingManager = FoldingManager.Install(textEditor.TextArea); foldingManager.UpdateFoldings(textOutput.Foldings.OrderBy(f => f.StartOffset), -1); Debug.WriteLine(" Updating folding: {0}", w.Elapsed); w.Restart(); } // update class bookmarks var document = textEditor.Document; manager.UpdateClassMemberBookmarks(textOutput.DefinitionLookup.ToDictionary(line => document.GetLineByOffset(line).LineNumber), typeof(TypeBookmark), typeof(MemberBookmark)); }
/// <summary> /// Starts the decompilation of the given nodes. /// The result will be saved to the given file name. /// </summary> void SaveToDisk(DecompilationContext context, string fileName) { textEditor.Clear(); TaskCompletionSource <AvalonEditTextOutput> tcs = new TaskCompletionSource <AvalonEditTextOutput>(); RunWithCancellation( delegate(CancellationToken ct) { context.Options.CancellationToken = ct; try { var language = context.Language; var options = context.Options; AvalonEditTextOutput output = new AvalonEditTextOutput(); string path = Path.GetDirectoryName(fileName); char[] invalidPathCharacters = Path.GetInvalidPathChars().Concat(Path.GetInvalidFileNameChars()).Distinct().ToArray(); foreach (ILSpyTreeNode node in context.TreeNodes) { string sanitized = new string(node.Text.ToString().Replace("<", "-").Replace(">", "-").Where(c => !invalidPathCharacters.Contains(c)).ToArray()); string fn = Path.Combine(path, $"{sanitized}.cs"); AvalonEditTextOutput saveOutput = SaveToDiskAsync(new DecompilationContext(language, new ILSpyTreeNode[] { node }, options), fn).Result; output.WriteLine(saveOutput.GetDocument().Text); } tcs.SetResult(output); } catch (OperationCanceledException) { tcs.SetCanceled(); } return(tcs.Task); }) .Then(output => ShowOutput(output)) .Catch((Exception ex) => { textEditor.SyntaxHighlighting = null; Debug.WriteLine("Decompiler crashed: " + ex.ToString()); // Unpack aggregate exceptions as long as there's only a single exception: // (assembly load errors might produce nested aggregate exceptions) AvalonEditTextOutput output = new AvalonEditTextOutput(); output.WriteLine(ex.ToString()); ShowOutput(output); }).HandleExceptions(); }
void TreeView_SelectionChanged(object sender, SelectionChangedEventArgs e) { this.textEditor.Clear(); AvalonEditTextOutput textOutput = new AvalonEditTextOutput(); //_humDisassembler = new HumanizerDisassembler(textOutput, token); foreach (var item in MainWindow.Instance.SelectedNodes) { var typeTreeNode = item as TypeTreeNode; if (typeTreeNode != null) { ToolSetSettings.Instance.Language.DecompileType(typeTreeNode.TypeDefinition, textOutput, new DecompilationOptions()); //_humDisassembler.DisassembleType(typeTreeNode.TypeDefinition); } } this.textEditor.SyntaxHighlighting = ToolSetSettings.Instance.Language.SyntaxHighlighting; this.textEditor.AppendText(textOutput.GetDocument().Text); textEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new ICSharpCode.AvalonEdit.Search.SearchInputHandler(textEditor.TextArea)); }
/// <summary> /// Shows the given output in the text view. /// </summary> void ShowOutput(AvalonEditTextOutput textOutput, IHighlightingDefinition highlighting = null, DecompilerTextViewState state = null) { Debug.WriteLine("Showing {0} characters of output", textOutput.TextLength); Stopwatch w = Stopwatch.StartNew(); ClearLocalReferenceMarks(); textEditor.ScrollToHome(); if (foldingManager != null) { FoldingManager.Uninstall(foldingManager); foldingManager = null; } textEditor.Document = null; // clear old document while we're changing the highlighting uiElementGenerator.UIElements = textOutput.UIElements; referenceElementGenerator.References = textOutput.References; references = textOutput.References; definitionLookup = textOutput.DefinitionLookup; textEditor.SyntaxHighlighting = highlighting; // Change the set of active element generators: foreach (var elementGenerator in activeCustomElementGenerators) { textEditor.TextArea.TextView.ElementGenerators.Remove(elementGenerator); } activeCustomElementGenerators.Clear(); foreach (var elementGenerator in textOutput.elementGenerators) { textEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator); activeCustomElementGenerators.Add(elementGenerator); } Debug.WriteLine(" Set-up: {0}", w.Elapsed); w.Restart(); textEditor.Document = textOutput.GetDocument(); Debug.WriteLine(" Assigning document: {0}", w.Elapsed); w.Restart(); if (textOutput.Foldings.Count > 0) { if (state != null) { state.RestoreFoldings(textOutput.Foldings); textEditor.ScrollToVerticalOffset(state.VerticalOffset); textEditor.ScrollToHorizontalOffset(state.HorizontalOffset); } foldingManager = FoldingManager.Install(textEditor.TextArea); foldingManager.UpdateFoldings(textOutput.Foldings.OrderBy(f => f.StartOffset), -1); Debug.WriteLine(" Updating folding: {0}", w.Elapsed); w.Restart(); } // update debugger info DebugInformation.CodeMappings = textOutput.DebuggerMemberMappings.ToDictionary(m => m.MetadataToken); // update class bookmarks var document = textEditor.Document; manager.Bookmarks.Clear(); foreach (var pair in textOutput.DefinitionLookup.definitions) { IMemberRef member = pair.Key as IMemberRef; int offset = pair.Value; if (member != null) { int line = document.GetLocation(offset).Line; manager.Bookmarks.Add(new MemberBookmark(member, line)); } } }
public ICSharpCode.AvalonEdit.Document.TextDocument Decompile(object obj) { AvalonEditTextOutput aeto = new AvalonEditTextOutput(); AstBuilder ast = new AstBuilder(new DecompilerContext(ModuleDefinition.CreateModule("ash", ModuleKind.NetModule))); switch (obj.GetType().Name) { case "AssemblyDefinition": ast = new AstBuilder(new DecompilerContext((obj as AssemblyDefinition).MainModule) { Settings = new DecompilerSettings() }); try { ast.AddAssembly(obj as AssemblyDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.FullName); } break; case "TypeDefinition": ast = CreateAstBuilder((obj as TypeDefinition), true); try { ast.AddType(obj as TypeDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.FullName); } break; case "MethodDefinition": MethodDefinition method = (obj as MethodDefinition); ast = CreateAstBuilder(method.DeclaringType, true); if (method.IsConstructor && !method.IsStatic && !method.DeclaringType.IsValueType) { foreach (var field in method.DeclaringType.Fields) if (field.IsStatic == method.IsStatic) { try { ast.AddField(field); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } } foreach (var ctor in method.DeclaringType.Methods) if (ctor.IsConstructor && ctor.IsStatic == method.IsStatic) { try { ast.AddMethod(ctor); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } } } else { try { ast.AddMethod(obj as MethodDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } } break; case "PropertyDefinition": ast = CreateAstBuilder((obj as PropertyDefinition).DeclaringType, true); try { ast.AddProperty(obj as PropertyDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } break; case "FieldDefinition": ast = CreateAstBuilder((obj as FieldDefinition).DeclaringType, true); try { ast.AddField(obj as FieldDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } break; case "EventDefinition": ast = CreateAstBuilder((obj as EventDefinition).DeclaringType, true); try { ast.AddEvent(obj as EventDefinition); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly " + e.AssemblyReference.Name); } break; default: return new ICSharpCode.AvalonEdit.Document.TextDocument(); } try { ast.GenerateCode(aeto); } catch (AssemblyResolutionException e) { MessageBox.Show("Could not load assembly upon code generation:\r" + e.AssemblyReference.FullName); } return aeto.GetDocument(); }