public static void Display(DecompilerTextView textView) { AvalonEditTextOutput output = new AvalonEditTextOutput(); output.WriteLine("ILSpy version " + RevisionClass.FullVersion); output.AddUIElement( delegate { StackPanel stackPanel = new StackPanel(); stackPanel.HorizontalAlignment = HorizontalAlignment.Center; stackPanel.Orientation = Orientation.Horizontal; if (latestAvailableVersion == null) { AddUpdateCheckButton(stackPanel, textView); } else { // we already retrieved the latest version sometime earlier ShowAvailableVersion(latestAvailableVersion, stackPanel); } CheckBox checkBox = new CheckBox(); checkBox.Margin = new Thickness(4); checkBox.Content = "Automatically check for updates every week"; UpdateSettings settings = new UpdateSettings(ILSpySettings.Load()); checkBox.SetBinding(CheckBox.IsCheckedProperty, new Binding("AutomaticUpdateCheckEnabled") { Source = settings }); return(new StackPanel { Margin = new Thickness(0, 4, 0, 0), Cursor = Cursors.Arrow, Children = { stackPanel, checkBox } }); }); output.WriteLine(); foreach (var plugin in App.CompositionContainer.GetExportedValues <IAboutPageAddition>()) { plugin.Write(output); } output.WriteLine(); using (Stream s = typeof(AboutPage).Assembly.GetManifestResourceStream(typeof(AboutPage), "README.txt")) { using (StreamReader r = new StreamReader(s)) { string line; while ((line = r.ReadLine()) != null) { output.WriteLine(line); } } } output.AddVisualLineElementGenerator(new MyLinkElementGenerator("SharpDevelop", "http://www.icsharpcode.net/opensource/sd/")); output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt")); output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt")); textView.ShowText(output); //reset icon bar textView.manager.Bookmarks.Clear(); }
public override bool View(DecompilerTextView textView) { EmbeddedResource er = r as EmbeddedResource; if (er != null) { return(View(this, textView, new MemoryStream(er.GetResourceData()), er.Name)); } return(false); }
public TextLocation GetLocation(DecompilerTextView textView) { TextLocation location, endLocation; if (GetLocation(textView, out location, out endLocation)) { return(location); } return(new TextLocation()); }
public static int GetLineNumber(IBookmark b, DecompilerTextView textView) { var bm = b as BookmarkBase; if (bm != null) { return(bm.GetLineNumber(textView)); } return(b.LineNumber); }
/// <summary> /// Gets line number. Returns -1 if it's unknown /// </summary> /// <param name="textView"></param> /// <returns></returns> public int GetLineNumber(DecompilerTextView textView) { TextLocation location, endLocation; if (GetLocation(textView, out location, out endLocation)) { return(location.Line); } return(-1); }
/// <summary> /// Enables extensible context menu support for the specified text view. /// </summary> public static ContextMenuProvider Add(DecompilerTextView textView) { var provider = new ContextMenuProvider(textView); textView.ContextMenuOpening += provider.textView_ContextMenuOpening; // Context menu is shown only when the ContextMenu property is not null before the // ContextMenuOpening event handler is called. textView.ContextMenu = new ContextMenu(); return(provider); }
public static bool JumpTo(DecompilerTextView textView, IMemberRef mr, MethodKey key, int ilOffset) { return(MainWindow.Instance.JumpToReference(textView, mr, (success, hasMovedCaret) => { if (success) { return MoveCaretTo(textView, key, ilOffset); } return false; })); }
static bool MoveCaretToCurrentStatement(DecompilerTextView textView) { var info = DebugInformation.DebugStepInformation; if (info == null) { return(false); } return(MoveCaretTo(textView, info.Item1, info.Item2)); }
public static bool VerifyAndGetCurrentDebuggedMethod(DecompilerTextView textView, SerializedDnSpyToken serToken, out Dictionary <SerializedDnSpyToken, MemberMapping> codeMappings) { codeMappings = textView == null ? null : textView.CodeMappings; if (codeMappings == null || !codeMappings.ContainsKey(serToken)) { return(false); } return(true); }
public ITextMarker CreateMarker(DecompilerTextView textView, ITextMarkerService markerService) { var marker = CreateMarkerInternal(markerService, textView); var cm = textView == null ? null : textView.CodeMappings; marker.ZOrder = ZOrder; marker.IsVisible = b => cm != null && cm.ContainsKey(SerializedDnSpyToken); marker.TextMarkerObject = this; Initialize(textView, markerService, marker); return(marker); }
static void Remove(DecompilerTextView decompilerTextView) { for (int i = returnStatementBookmarks.Count - 1; i >= 0; i--) { if (returnStatementBookmarks[i].decompilerTextView == decompilerTextView) { BookmarkManager.RemoveMark(returnStatementBookmarks[i]); returnStatementBookmarks.RemoveAt(i); } } }
static IMemberRef GetMemberRef(DecompilerTextView textView) { if (textView == null) { return(null); } var refSeg = textView.GetCurrentReferenceSegment(); return(refSeg == null ? null : refSeg.Reference as IMemberRef); }
void Remove(DecompilerTextView decompilerTextView) { for (int i = stackFrameLines.Count - 1; i >= 0; i--) { if (stackFrameLines[i].TextView == decompilerTextView) { TextLineObjectManager.Instance.Remove(stackFrameLines[i]); stackFrameLines.RemoveAt(i); } } }
public override ITextMarker CreateMarker(ITextMarkerService markerService, DecompilerTextView textView) { ITextMarker marker = CreateMarkerInternal(markerService, textView); var cm = textView == null ? null : textView.CodeMappings; marker.ZOrder = ZOrder; marker.HighlightingColor = () => IsEnabled ? HighlightingColor : DisabledHighlightingColor; marker.IsVisible = b => cm != null && b is BreakpointBookmark && cm.ContainsKey(((BreakpointBookmark)b).MethodKey); marker.Bookmark = this; return(marker); }
public static bool JumpToReference(DecompilerTextView textView, IMemberRef mr, Func <TextLocation> getLocation) { bool retVal = MainWindow.Instance.JumpToReference(textView, mr, getLocation); if (!retVal) { MainWindow.Instance.ShowMessageBox( string.Format("Could not find {0}\n" + "Make sure that it's visible in the treeview and not a hidden method or part of a hidden class. You could also try to debug the method in IL mode.", mr)); } return(retVal); }
public IconBarMargin(IconBarManager manager, DecompilerTextView decompilerTextView) { this.decompilerTextView = decompilerTextView; BookmarkManager.Added += OnBookmarkAdded; BookmarkManager.Removed += OnBookmarkRemoved; decompilerTextView.OnShowOutput += decompilerTextView_OnShowOutput; MainWindow.Instance.ExecuteWhenLoaded(() => { MainWindow.Instance.OnDecompilerTextViewRemoved += OnDecompilerTextViewRemoved; }); this.manager = manager; SyncBookmarks(); }
public override bool Save(ViewModels.TabPageModel tabPage) { SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = Path.GetFileName(DecompilerTextView.CleanUpName(key)); if (dlg.ShowDialog() == true) { using var data = OpenStream(); using var fs = dlg.OpenFile(); data.CopyTo(fs); } return(true); }
public static TextViewContext Create(SharpTreeView treeView = null, DecompilerTextView textView = null) { var reference = textView != null?textView.GetReferenceSegmentAtMousePosition() : null; var selectedTreeNodes = treeView != null?treeView.GetTopLevelSelection().ToArray() : null; return(new TextViewContext { TreeView = treeView, SelectedTreeNodes = selectedTreeNodes, TextView = textView, Reference = reference }); }
internal static async void GeneratePdbForAssembly(LoadedAssembly assembly) { var file = assembly.GetPEFileOrNull(); if (!PortablePdbWriter.HasCodeViewDebugDirectoryEntry(file)) { await MessageBox.Show($"Cannot create PDB file for {Path.GetFileName(assembly.FileName)}, because it does not contain a PE Debug Directory Entry of type 'CodeView'."); return; } SaveFileDialog dlg = new SaveFileDialog(); dlg.Title = "Save file"; dlg.InitialFileName = DecompilerTextView.CleanUpName(assembly.ShortName) + ".pdb"; dlg.Filters = new List <FileDialogFilter> { new FileDialogFilter { Name = "Portable PDB", Extensions = { "pdb" } }, new FileDialogFilter { Name = "All files", Extensions = { "*" } } }; dlg.Directory = Path.GetDirectoryName(assembly.FileName); string fileName = await dlg.ShowAsync(App.Current.GetMainWindow()); if (string.IsNullOrEmpty(fileName)) { return; } DecompilationOptions options = new DecompilationOptions(); MainWindow.Instance.TextView.RunWithCancellation(ct => Task <AvaloniaEditTextOutput> .Factory.StartNew(() => { AvaloniaEditTextOutput output = new AvaloniaEditTextOutput(); Stopwatch stopwatch = Stopwatch.StartNew(); using (FileStream stream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)) { try { var decompiler = new CSharpDecompiler(file, assembly.GetAssemblyResolver(), options.DecompilerSettings); PortablePdbWriter.WritePdb(file, decompiler, options.DecompilerSettings, stream); } catch (OperationCanceledException) { output.WriteLine(); output.WriteLine("Generation was cancelled."); throw; } } stopwatch.Stop(); output.WriteLine("Generation complete in " + stopwatch.Elapsed.TotalSeconds.ToString("F1") + " seconds."); output.WriteLine(); output.AddButton(null, "Open Explorer", delegate { Process.Start("explorer", "/select,\"" + fileName + "\""); }); output.WriteLine(); return(output); }, ct)).Then(output => MainWindow.Instance.TextView.ShowText(output)).HandleExceptions(); }
/// <summary> /// Should be called each time the IL offset has been updated /// </summary> static bool UpdateReturnStatementBookmarks(DecompilerTextView decompilerTextView, bool moveCaret = false) { Remove(decompilerTextView); bool movedCaret = false; var cm = decompilerTextView == null ? null : decompilerTextView.CodeMappings; bool updateReturnStatements = cm != null && DebuggerService.CurrentDebugger != null && DebuggerService.CurrentDebugger.IsDebugging && !DebuggerService.CurrentDebugger.IsProcessRunning; if (updateReturnStatements) { int frameNo = -1; foreach (var frame in DebuggerService.CurrentDebugger.GetStackFrames(100)) { frameNo++; StackFrameStatementType type; if (frameNo == 0) { type = StackFrameStatementType.CurrentStatement; } else { type = selectedFrame == frameNo ? StackFrameStatementType.SelectedReturnStatement : StackFrameStatementType.ReturnStatement; } if (frame.ILOffset == null) { continue; } var key = frame.MethodKey; int offset = frame.ILOffset.Value; MethodDef methodDef; ICSharpCode.NRefactory.TextLocation location, endLocation; if (cm != null && cm.ContainsKey(key) && cm[key].GetInstructionByTokenAndOffset((uint)offset, out methodDef, out location, out endLocation)) { var rs = new StackFrameStatementBookmark(decompilerTextView, methodDef, location, endLocation, type, (uint)offset); returnStatementBookmarks.Add(rs); BookmarkManager.AddMark(rs); if (moveCaret && frameNo == selectedFrame) { decompilerTextView.ScrollAndMoveCaretTo(location.Line, location.Column); movedCaret = true; } } } } return(movedCaret); }
public override bool Save(TabPageModel tabPage) { Stream s = Resource.TryOpenStream(); if (s == null) { return(false); } SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = DecompilerTextView.CleanUpName(Resource.Name); dlg.Filter = Resources.ResourcesFileFilter; if (dlg.ShowDialog() == true) { s.Position = 0; switch (dlg.FilterIndex) { case 1: using (var fs = dlg.OpenFile()) { s.CopyTo(fs); } break; case 2: try { using (var fs = dlg.OpenFile()) using (var writer = new ResXResourceWriter(fs)) { foreach (var entry in new ResourcesFile(s)) { writer.AddResource(entry.Key, entry.Value); } } } catch (BadImageFormatException) { // ignore errors } catch (EndOfStreamException) { // ignore errors } break; } } return(true); }
public override bool Save(DecompilerTextView textView) { SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = Path.GetFileName(DecompilerTextView.CleanUpName(key)); if (dlg.ShowDialog() == true) { data.Position = 0; using (var fs = dlg.OpenFile()) { data.CopyTo(fs); } } return(true); }
DecompilerTextView GetDecompilerTextView() { var typesToDecompile = GetDefaultModuleTypes(); var decomTextView = new DecompilerTextView(); CompositionContainerBuilder.Container.ComposeParts(decomTextView); decomTextView.Decompile(this.decompiledLanguage, typesToDecompile, new DecompilationOptions() { TextViewState = new DecompilerTextViewState() }); return(decomTextView); }
public LinqPadSpyContainer(Application currentApplication, Language decompiledLanguage) { if (currentApplication == null) { throw new ArgumentNullException("currentApplication"); } if (decompiledLanguage == null) { throw new ArgumentNullException("decompiledLanguage"); } this.decompiledLanguage = decompiledLanguage; this.currentApplication = currentApplication; // Initialize supported ILSpy languages. Values used for the combobox. Languages.Initialize(CompositionContainerBuilder.Container); this.CurrentAssemblyList = new AssemblyList("LINQPadAssemblyList", this.currentApplication); ICSharpCode.ILSpy.App.CompositionContainer = CompositionContainerBuilder.Container; CompositionContainerBuilder.Container.ComposeParts(this); // A hack to get around the global shared state of the Window object throughout ILSpy. ICSharpCode.ILSpy.MainWindow.SpyWindow = this; this.spySettings = ILSpySettings.Load(); this.sessionSettings = new SessionSettings(this.spySettings) { ActiveAssemblyList = this.CurrentAssemblyList.ListName }; SetUpDataContext(); this.assemblyPath = LinqPadUtil.GetLastLinqPadQueryAssembly(); this.decompilerTextView = GetDecompilerTextView(); InitializeComponent(); this.mainPane.Content = this.decompilerTextView; this.InitToolbar(); this.Loaded += new RoutedEventHandler(this.MainWindowLoaded); }
static void OnDecompilerTextViewChanged(DecompilerTextView oldView, DecompilerTextView newView) { if (oldView != null) { oldView.OnBeforeShowOutput -= DecompilerTextView_OnBeforeShowOutput; oldView.OnShowOutput -= DecompilerTextView_OnShowOutput; } if (newView != null) { newView.OnBeforeShowOutput += DecompilerTextView_OnBeforeShowOutput; newView.OnShowOutput += DecompilerTextView_OnShowOutput; } Remove(oldView); UpdateReturnStatementBookmarks(newView); }
public TextMarkerService(DecompilerTextView textView) { if (textView == null) { throw new ArgumentNullException("textView"); } this.textView = textView; TextView.DocumentChanged += OnDocumentChanged; TextLineObjectManager.Instance.OnListModified += TextLineObjectManager_OnListModified; MainWindow.Instance.ExecuteWhenLoaded(() => { MainWindow.Instance.OnTabStateRemoved += OnTabStateRemoved; this.textView.OnShowOutput += textView_OnShowOutput; RecreateMarkers(); }); OnDocumentChanged(null, null); }
protected ITextMarker CreateMarkerInternal(ITextMarkerService markerService, DecompilerTextView textView) { TextLocation location, endLocation; if (!GetLocation(textView, out location, out endLocation)) { throw new InvalidOperationException(); } var line = markerService.TextView.Document.GetLineByNumber(location.Line); var endLine = markerService.TextView.Document.GetLineByNumber(endLocation.Line); int startOffset = line.Offset + location.Column - 1; int endOffset = endLine.Offset + endLocation.Column - 1; return(markerService.Create(startOffset, endOffset - startOffset)); }
public override async Task <bool> Save(DecompilerTextView textView) { SaveFileDialog dlg = new SaveFileDialog(); dlg.InitialFileName = Path.GetFileName(DecompilerTextView.CleanUpName(key)); var filename = await dlg.ShowAsync(App.Current.GetMainWindow()); if (!string.IsNullOrEmpty(filename)) { data.Position = 0; using (var fs = File.OpenWrite(filename)) { data.CopyTo(fs); } } return(true); }
/// <summary> /// Enables extensible context menu support for the specified tree view. /// </summary> public static void Add(SharpTreeView treeView, DecompilerTextView textView = null) { var provider = new ContextMenuProvider(treeView, textView); treeView.ContextMenuOpening += provider.treeView_ContextMenuOpening; // Context menu is shown only when the ContextMenu property is not null before the // ContextMenuOpening event handler is called. treeView.ContextMenu = new ContextMenu(); if (textView != null) { textView.ContextMenuOpening += provider.textView_ContextMenuOpening; // Context menu is shown only when the ContextMenu property is not null before the // ContextMenuOpening event handler is called. textView.ContextMenu = new ContextMenu(); } }
public override bool IsVisible(DecompilerTextView textView) { TextLocation location, endLocation; var cm = textView == null ? null : textView.CodeMappings; if (cm == null || !cm.ContainsKey(SerializedDnSpyToken)) { return(false); } if (!cm[SerializedDnSpyToken].GetInstructionByTokenAndOffset(ILOffset, out location, out endLocation)) { return(false); } return(true); }