public static IList<MethodSourceStatement> GetStatements(IDocumentViewer documentViewer, int textPosition) { if (documentViewer == null) return null; var methodDebugService = documentViewer.GetMethodDebugService(); var methodStatements = methodDebugService.FindByTextPosition(textPosition, sameMethod: true); return methodStatements.Count == 0 ? null : methodStatements; }
public HighlightRelatedKeywordsDocumentViewerReferenceEnabler(IDocumentViewer documentViewer) { if (documentViewer == null) throw new ArgumentNullException(nameof(documentViewer)); this.documentViewer = documentViewer; IsEnabled = documentViewer.TextView.Options.IsHighlightRelatedKeywordsEnabled(); documentViewer.TextView.Options.OptionChanged += Options_OptionChanged; }
public void RaiseRemovedEvent(IDocumentViewer documentViewer) { if (documentViewer == null) throw new ArgumentNullException(nameof(documentViewer)); var e = new DocumentViewerRemovedEventArgs(documentViewer); NotifyListeners(e); Removed?.Invoke(this, e); }
NodeTabSaver(IMessageBoxService messageBoxService, IDocumentTab tab, IDocumentTreeNodeDecompiler documentTreeNodeDecompiler, IDecompiler decompiler, IDocumentViewer documentViewer, DocumentTreeNodeData[] nodes) { this.messageBoxService = messageBoxService; this.tab = tab; this.documentTreeNodeDecompiler = documentTreeNodeDecompiler; this.decompiler = decompiler; this.documentViewer = documentViewer; this.nodes = nodes; }
public void RaiseNewContentEvent(IDocumentViewer documentViewer, DocumentViewerContent content, IContentType contentType) { if (documentViewer == null) throw new ArgumentNullException(nameof(documentViewer)); if (content == null) throw new ArgumentNullException(nameof(content)); if (contentType == null) throw new ArgumentNullException(nameof(contentType)); var e = new DocumentViewerGotNewContentEventArgs(documentViewer, content, contentType); NotifyListeners(e); GotNewContent?.Invoke(this, e); }
public static IList <MethodSourceStatement> GetStatements(IDocumentViewer documentViewer, int textPosition, FindByTextPositionOptions options) { if (documentViewer == null) { return(null); } var methodDebugService = documentViewer.GetMethodDebugService(); var methodStatements = methodDebugService.FindByTextPosition(textPosition, options | FindByTextPositionOptions.SameMethod); return(methodStatements.Count == 0 ? null : methodStatements); }
public void RaiseRemovedEvent(IDocumentViewer documentViewer) { if (documentViewer == null) { throw new ArgumentNullException(nameof(documentViewer)); } var e = new DocumentViewerRemovedEventArgs(documentViewer); NotifyListeners(e); Removed?.Invoke(this, e); }
void SetDocumentViewer(IDocumentViewer documentViewer, Dictionary <string, Lazy <IDocumentViewerReferenceEnablerProvider, IDocumentViewerReferenceEnablerProviderMetadata> > documentViewerReferenceEnablerProviders) { if (!(this.documentViewer is null)) { throw new InvalidOperationException(); } this.documentViewer = documentViewer ?? throw new ArgumentNullException(nameof(documentViewer)); this.documentViewerReferenceEnablerProviders = documentViewerReferenceEnablerProviders ?? throw new ArgumentNullException(nameof(documentViewerReferenceEnablerProviders)); documentViewerReferenceEnablers = new Dictionary <string, IDocumentViewerReferenceEnabler?>(documentViewerReferenceEnablerProviders.Count, StringComparer.Ordinal); documentViewer.GotNewContent += DocumentViewer_GotNewContent; }
/// <summary> /// Constructor /// </summary> /// <param name="documentViewer">Document viewer</param> /// <param name="content">New content</param> /// <param name="contentType">Content type</param> public DocumentViewerGotNewContentEventArgs(IDocumentViewer documentViewer, DocumentViewerContent content, IContentType contentType) : base(documentViewer) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (contentType == null) { throw new ArgumentNullException(nameof(contentType)); } Content = content; ContentType = contentType; }
static object GetReference(IMenuItemContext context, out IDocumentViewer documentViewer) { documentViewer = null; if (context.CreatorObject.Guid != new Guid(MenuConstants.GUIDOBJ_DOCUMENTVIEWERCONTROL_GUID)) { return(null); } documentViewer = context.Find <IDocumentViewer>(); if (documentViewer == null) { return(null); } return(context.Find <TextReference>()); }
static Tuple <int?, BracePairResult> GetMatchingBracePosition(IDocumentViewer documentViewer) { var caretPos = documentViewer.TextView.Caret.Position; if (caretPos.VirtualSpaces > 0) { return(null); } var coll = documentViewer.Content.GetCustomData <BracePairCollection>(DocumentViewerContentDataIds.BracePair); if (coll == null) { return(null); } int pos = caretPos.BufferPosition.Position; var pairColl = coll.GetBracePairs(pos); if (pairColl == null) { return(null); } var pair = pairColl.Value.First; if (pair.Left.Start == pos) { return(Tuple.Create <int?, BracePairResult>(pair.Right.End, pair)); } if (pair.Right.End == pos) { return(Tuple.Create <int?, BracePairResult>(pair.Left.Start, pair)); } if (pair.Right.Start == pos) { var pair2 = coll.GetBracePairs(pos - 1); if (pair2 != null && pair2.Value.First.Right.End == pos) { return(Tuple.Create <int?, BracePairResult>(pair2.Value.First.Left.Start, pair2.Value.First)); } } if (pair.Left.Start <= pos && pos <= pair.Left.End) { return(Tuple.Create <int?, BracePairResult>(pair.Right.End, pair)); } if (pair.Right.Start <= pos && pos <= pair.Right.End) { return(Tuple.Create <int?, BracePairResult>(pair.Left.Start, pair)); } return(null); }
public static bool MoveCaretTo(IDocumentViewer documentViewer, ModuleTokenId key, uint ilOffset) { if (documentViewer == null) return false; IMethodDebugService methodDebugService; if (!VerifyAndGetCurrentDebuggedMethod(documentViewer, key, out methodDebugService)) return false; var sourceStatement = methodDebugService.TryGetMethodDebugInfo(key).GetSourceStatementByCodeOffset(ilOffset); if (sourceStatement == null) return false; documentViewer.MoveCaretToPosition(sourceStatement.Value.TextSpan.Start); return true; }
static bool MoveCaretTo(IDocumentViewer documentViewer, IMemberDef def) { if (documentViewer == null) { return(false); } var data = documentViewer.ReferenceCollection.FirstOrNull(a => a.Data.IsDefinition && a.Data.Reference == def); if (data == null) { return(false); } documentViewer.MoveCaretToPosition(data.Value.Span.Start); return(true); }
public MasterDetailViewModel(INavigationService navigationService, IMenuService menuService, IEventAggregator eventAggregator, IDocumentViewer documentViewer) : base(navigationService) { _menuService = menuService; _eventAggregator = eventAggregator; _documentViewer = documentViewer; DetailsItems = new ObservableCollection <DetailsItem>(_menuService.GetAllowedAccessItems()); _eventAggregator.GetEvent <LogInMessage>().Subscribe(LoginEvent); _eventAggregator.GetEvent <LogOutMessage>().Subscribe(LogOutEvent); _pdfPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); }
public static void Execute(IDocumentViewer documentViewer, Lazy<IMethodAnnotations> methodAnnotations) { if (!CanExecute(documentViewer)) return; var copier = new InstructionILBytesCopier(); var text = copier.Copy(FindInstructions(documentViewer), methodAnnotations); if (text.Length > 0) { try { Clipboard.SetText(text); } catch (ExternalException) { } if (copier.FoundUnknownBytes) { MsgBox.Instance.ShowIgnorableMessage(new Guid("141A1744-13CD-4835-A804-08D93D8E0D2B"), dnSpy_AsmEditor_Resources.UnknownBytesMsg, MsgBoxButton.OK); } } }
static void MoveToMatchingBrace(IDocumentViewer documentViewer, bool select) { var t = GetMatchingBracePosition(documentViewer); if (t == null) { return; } var pos = t.Item1; if (pos == null) { return; } var snapshot = documentViewer.TextView.TextSnapshot; if (pos.Value > snapshot.Length) { return; } var bpResult = t.Item2; if (bpResult.Left.End > snapshot.Length || bpResult.Right.End > snapshot.Length) { return; } if (bpResult.Left.Start > bpResult.Right.Start) { return; } if (select) { bool reverse = pos.Value == bpResult.Left.Start; documentViewer.Selection.Mode = TextSelectionMode.Stream; documentViewer.Selection.Select(new SnapshotSpan(snapshot, Span.FromBounds(bpResult.Left.Start, bpResult.Right.End)), reverse); } else { documentViewer.Selection.Clear(); } documentViewer.Caret.MoveTo(new SnapshotPoint(snapshot, pos.Value)); documentViewer.Caret.EnsureVisible(); }
public void RaiseNewContentEvent(IDocumentViewer documentViewer, DocumentViewerContent content, IContentType contentType) { if (documentViewer == null) { throw new ArgumentNullException(nameof(documentViewer)); } if (content == null) { throw new ArgumentNullException(nameof(content)); } if (contentType == null) { throw new ArgumentNullException(nameof(contentType)); } var e = new DocumentViewerGotNewContentEventArgs(documentViewer, content, contentType); NotifyListeners(e); GotNewContent?.Invoke(this, e); }
public DocumentViewerToolTipService(IImageManager imageManager, IDotNetImageManager dotNetImageManager, ICodeToolTipSettings codeToolTipSettings, Lazy <IDocumentViewerToolTipProvider, IDocumentViewerToolTipProviderMetadata>[] documentViewerToolTipProviders, IDocumentViewer documentViewer, IQuickInfoBroker quickInfoBroker, IClassificationFormatMap classificationFormatMap, IThemeClassificationTypeService themeClassificationTypeService) { if (imageManager == null) { throw new ArgumentNullException(nameof(imageManager)); } if (dotNetImageManager == null) { throw new ArgumentNullException(nameof(dotNetImageManager)); } if (codeToolTipSettings == null) { throw new ArgumentNullException(nameof(codeToolTipSettings)); } if (documentViewerToolTipProviders == null) { throw new ArgumentNullException(nameof(documentViewerToolTipProviders)); } if (documentViewer == null) { throw new ArgumentNullException(nameof(documentViewer)); } if (quickInfoBroker == null) { throw new ArgumentNullException(nameof(quickInfoBroker)); } if (classificationFormatMap == null) { throw new ArgumentNullException(nameof(classificationFormatMap)); } if (themeClassificationTypeService == null) { throw new ArgumentNullException(nameof(themeClassificationTypeService)); } this.imageManager = imageManager; this.dotNetImageManager = dotNetImageManager; this.codeToolTipSettings = codeToolTipSettings; this.documentViewerToolTipProviders = documentViewerToolTipProviders; this.documentViewer = documentViewer; this.quickInfoBroker = quickInfoBroker; this.classificationFormatMap = classificationFormatMap; this.themeClassificationTypeService = themeClassificationTypeService; }
public ToolTipProviderContext(IDotNetImageService dotNetImageService, IDecompiler decompiler, ICodeToolTipSettings codeToolTipSettings, IDocumentViewer documentViewer, IClassificationFormatMap classificationFormatMap, IThemeClassificationTypeService themeClassificationTypeService) { if (dotNetImageService == null) throw new ArgumentNullException(nameof(dotNetImageService)); if (decompiler == null) throw new ArgumentNullException(nameof(decompiler)); if (codeToolTipSettings == null) throw new ArgumentNullException(nameof(codeToolTipSettings)); if (documentViewer == null) throw new ArgumentNullException(nameof(documentViewer)); if (classificationFormatMap == null) throw new ArgumentNullException(nameof(classificationFormatMap)); if (themeClassificationTypeService == null) throw new ArgumentNullException(nameof(themeClassificationTypeService)); DocumentViewer = documentViewer; this.dotNetImageService = dotNetImageService; Decompiler = decompiler; this.codeToolTipSettings = codeToolTipSettings; this.classificationFormatMap = classificationFormatMap; this.themeClassificationTypeService = themeClassificationTypeService; }
public DocumentViewerContent CreateContent(IDocumentViewer documentViewer) { if (documentViewerOutput == null) { throw new InvalidOperationException(); } if (documentViewer == null) { throw new ArgumentNullException(nameof(documentViewer)); } using (var context = new DocumentViewerCustomDataContext(documentViewer, documentViewerOutput.GetCachedText(), documentViewerOutput.GetCustomDataDictionary())) { foreach (var lazy in documentViewerCustomDataProviders) { lazy.Value.OnCustomData(context); } var output = documentViewerOutput; documentViewerOutput = null; return(output.CreateContent(context.GetResultDictionary())); } }
//TODO: This method (and all callers) should take an ITextView instead of an IDocumentViewer as a parameter List <ILCodeBreakpoint> GetILCodeBreakpoints(IDocumentViewer documentViewer, IList <MethodSourceStatement> methodStatements) { var list = new List <ILCodeBreakpoint>(); if (methodStatements.Count == 0) { return(list); } var service = documentViewer.TryGetMethodDebugService(); if (service == null) { return(list); } var methodStatement = methodStatements[0]; foreach (var ilbp in GetILCodeBreakpoints()) { var info = service.TryGetMethodDebugInfo(ilbp.MethodToken); if (info == null) { continue; } var statement = info.GetSourceStatementByCodeOffset(ilbp.ILOffset); if (statement == null) { continue; } if (statement.Value.TextSpan != methodStatement.Statement.TextSpan) { continue; } list.Add(ilbp); } return(list); }
public static IList <MethodSourceStatement> GetStatements(IDocumentViewer documentViewer, int textPosition) { if (documentViewer == null) { return(null); } var methodDebugService = documentViewer.GetMethodDebugService(); var methodStatements = methodDebugService.FindByTextPosition(textPosition); if (methodStatements.Count == 0) { return(null); } var span = methodStatements[0].Statement.TextSpan; var snapshot = documentViewer.TextView.TextSnapshot; Debug.Assert(span.End <= snapshot.Length); Debug.Assert(textPosition <= snapshot.Length); if (span.End > snapshot.Length) { return(null); } if (textPosition > snapshot.Length) { return(null); } var line1 = snapshot.GetLineFromPosition(span.Start); var line2 = snapshot.GetLineFromPosition(span.End); var textLine = snapshot.GetLineFromPosition(textPosition); if (!(line1.LineNumber <= textLine.LineNumber && textLine.LineNumber <= line2.LineNumber)) { return(null); } return(methodStatements); }
public static bool MoveCaretTo(IDocumentViewer documentViewer, ModuleTokenId key, uint ilOffset) { if (documentViewer == null) { return(false); } IMethodDebugService methodDebugService; if (!VerifyAndGetCurrentDebuggedMethod(documentViewer, key, out methodDebugService)) { return(false); } var sourceStatement = methodDebugService.TryGetMethodDebugInfo(key).GetSourceStatementByCodeOffset(ilOffset); if (sourceStatement == null) { return(false); } documentViewer.MoveCaretToPosition(sourceStatement.Value.TextSpan.Start); return(true); }
public static void Execute(IDocumentViewer documentViewer, Lazy <IMethodAnnotations> methodAnnotations) { if (!CanExecute(documentViewer)) { return; } var copier = new InstructionILBytesCopier(); var text = copier.Copy(FindInstructions(documentViewer), methodAnnotations); if (text.Length > 0) { try { Clipboard.SetText(text); } catch (ExternalException) { } if (copier.FoundUnknownBytes) { MsgBox.Instance.ShowIgnorableMessage(new Guid("141A1744-13CD-4835-A804-08D93D8E0D2B"), dnSpy_AsmEditor_Resources.UnknownBytesMsg, MsgBoxButton.OK); } } }
static IEnumerable<SpanData<ReferenceInfo>> FindInstructions(IDocumentViewer documentViewer) { foreach (var refInfo in documentViewer.GetSelectedReferences()) { if (refInfo.Data.IsDefinition && refInfo.Data.Reference is InstructionReference) yield return refInfo; } }
/// <summary> /// Constructor /// </summary> /// <param name="documentViewer"><see cref="IDocumentViewer"/> instance</param> public DocumentViewerAddedEventArgs(IDocumentViewer documentViewer) : base(documentViewer) { }
public DocumentViewerToolTipService GetService(IDocumentViewer documentViewer) => documentViewer.TextView.Properties.GetOrCreateSingletonProperty(typeof(DocumentViewerToolTipService), () => new DocumentViewerToolTipService(imageManager, dotNetImageManager, codeToolTipSettings, documentViewerToolTipProviders, documentViewer, quickInfoBroker, classificationFormatMapService.GetClassificationFormatMap(AppearanceCategoryConstants.QuickInfoToolTip), themeClassificationTypeService));
public DocumentViewerToolTipService(IDotNetImageService dotNetImageService, ICodeToolTipSettings codeToolTipSettings, Lazy<IDocumentViewerToolTipProvider, IDocumentViewerToolTipProviderMetadata>[] documentViewerToolTipProviders, IDocumentViewer documentViewer, IQuickInfoBroker quickInfoBroker, IClassificationFormatMap classificationFormatMap, IThemeClassificationTypeService themeClassificationTypeService, IDecompilerService decompilerService) { if (dotNetImageService == null) throw new ArgumentNullException(nameof(dotNetImageService)); if (codeToolTipSettings == null) throw new ArgumentNullException(nameof(codeToolTipSettings)); if (documentViewerToolTipProviders == null) throw new ArgumentNullException(nameof(documentViewerToolTipProviders)); if (documentViewer == null) throw new ArgumentNullException(nameof(documentViewer)); if (quickInfoBroker == null) throw new ArgumentNullException(nameof(quickInfoBroker)); if (classificationFormatMap == null) throw new ArgumentNullException(nameof(classificationFormatMap)); if (themeClassificationTypeService == null) throw new ArgumentNullException(nameof(themeClassificationTypeService)); if (decompilerService == null) throw new ArgumentNullException(nameof(decompilerService)); this.dotNetImageService = dotNetImageService; this.codeToolTipSettings = codeToolTipSettings; this.documentViewerToolTipProviders = documentViewerToolTipProviders; this.documentViewer = documentViewer; this.quickInfoBroker = quickInfoBroker; this.classificationFormatMap = classificationFormatMap; this.themeClassificationTypeService = themeClassificationTypeService; this.decompilerService = decompilerService; }
public ToolTipProviderContext(IDotNetImageService dotNetImageService, IDecompiler decompiler, ICodeToolTipSettings codeToolTipSettings, IDocumentViewer documentViewer, IClassificationFormatMap classificationFormatMap, IThemeClassificationTypeService themeClassificationTypeService) { if (dotNetImageService == null) { throw new ArgumentNullException(nameof(dotNetImageService)); } if (decompiler == null) { throw new ArgumentNullException(nameof(decompiler)); } if (codeToolTipSettings == null) { throw new ArgumentNullException(nameof(codeToolTipSettings)); } if (documentViewer == null) { throw new ArgumentNullException(nameof(documentViewer)); } if (classificationFormatMap == null) { throw new ArgumentNullException(nameof(classificationFormatMap)); } if (themeClassificationTypeService == null) { throw new ArgumentNullException(nameof(themeClassificationTypeService)); } DocumentViewer = documentViewer; this.dotNetImageService = dotNetImageService; Decompiler = decompiler; this.codeToolTipSettings = codeToolTipSettings; this.classificationFormatMap = classificationFormatMap; this.themeClassificationTypeService = themeClassificationTypeService; }
/// <summary> /// Constructor /// </summary> /// <param name="documentViewer">Document viewer</param> /// <param name="content">New content</param> /// <param name="contentType">Content type</param> public DocumentViewerGotNewContentEventArgs(IDocumentViewer documentViewer, DocumentViewerContent content, IContentType contentType) : base(documentViewer) { if (content == null) throw new ArgumentNullException(nameof(content)); if (contentType == null) throw new ArgumentNullException(nameof(contentType)); Content = content; ContentType = contentType; }
public static IBlockStructureServiceDataProvider TryCreate(IDocumentViewer documentViewer) { var lazyColl = documentViewer.Content.GetCustomData <LazyBlockStructureCollection>(DocumentViewerContentDataIds.BlockStructure); return(lazyColl == null ? null : new BlockStructureServiceDataProvider(lazyColl)); }
public void Toggle(IDocumentViewer documentViewer, int textPosition) { var statements = documentViewer.GetMethodDebugService().FindByTextPosition(textPosition, sameMethod: false); var ilbps = GetILCodeBreakpoints(documentViewer, statements); if (ilbps.Count > 0) { if (IsEnabled(ilbps)) { foreach (var ilbp in ilbps) Remove(ilbp); } else { foreach (var bpm in ilbps) bpm.IsEnabled = true; } } else if (statements.Count > 0) { foreach (var methodStatement in statements) { var md = methodStatement.Method; var modId = moduleIdProvider.Create(md.Module); var key = new ModuleTokenId(modId, md.MDToken); Add(new ILCodeBreakpoint(key, methodStatement.Statement.BinSpan.Start)); } documentViewer.MoveCaretToPosition(statements[0].Statement.TextSpan.Start); } }
List <ILCodeBreakpoint> GetILCodeBreakpoints(IDocumentViewer documentViewer, int textPosition) => GetILCodeBreakpoints(documentViewer, documentViewer.GetMethodDebugService().FindByTextPosition(textPosition, sameMethod: false));
public DocumentViewerToolTipService GetService(IDocumentViewer documentViewer) => documentViewer.TextView.Properties.GetOrCreateSingletonProperty(typeof(DocumentViewerToolTipService), () => new DocumentViewerToolTipService(dotNetImageService, codeToolTipSettings, documentViewerToolTipProviders, documentViewer, quickInfoBroker, classificationFormatMapService.GetClassificationFormatMap(AppearanceCategoryConstants.UIMisc), themeClassificationTypeService, decompilerService));
public static bool CanExecute(IDocumentViewer documentViewer) => documentViewer != null && FindInstructions(documentViewer).Any();
public static IStructureVisualizerServiceDataProvider TryCreate(IDocumentViewer documentViewer) { var lazyColl = documentViewer.Content.GetCustomData <LazyStructureVisualizerCollection>(DocumentViewerContentDataIds.StructureVisualizer); return(lazyColl == null ? null : new StructureVisualizerServiceDataProvider(lazyColl)); }
public IDocumentViewerReferenceEnabler Create(IDocumentViewer documentViewer) => new HighlightRelatedKeywordsDocumentViewerReferenceEnabler(documentViewer);
/// <summary> /// Constructor /// </summary> /// <param name="documentViewer"><see cref="IDocumentViewer"/> instance</param> public DocumentViewerRemovedEventArgs(IDocumentViewer documentViewer) : base(documentViewer) { }
/// <summary> /// Constructor /// </summary> /// <param name="documentViewer"><see cref="IDocumentViewer"/> instance</param> protected DocumentViewerEventArgs(IDocumentViewer documentViewer) { if (documentViewer == null) throw new ArgumentNullException(nameof(documentViewer)); DocumentViewer = documentViewer; }
public DocumentViewerToolTipService(IImageManager imageManager, IDotNetImageManager dotNetImageManager, ICodeToolTipSettings codeToolTipSettings, Lazy <IToolTipProvider, IToolTipProviderMetadata>[] toolTipProviders, IDocumentViewer documentViewer) { if (imageManager == null) { throw new ArgumentNullException(nameof(imageManager)); } if (dotNetImageManager == null) { throw new ArgumentNullException(nameof(dotNetImageManager)); } if (codeToolTipSettings == null) { throw new ArgumentNullException(nameof(codeToolTipSettings)); } if (toolTipProviders == null) { throw new ArgumentNullException(nameof(toolTipProviders)); } if (documentViewer == null) { throw new ArgumentNullException(nameof(documentViewer)); } this.imageManager = imageManager; this.dotNetImageManager = dotNetImageManager; this.codeToolTipSettings = codeToolTipSettings; this.toolTipProviders = toolTipProviders; this.documentViewer = documentViewer; documentViewer.TextView.Closed += TextView_Closed; documentViewer.TextView.MouseHover += TextView_MouseHover; }
NodeTabSaver(IMessageBoxManager messageBoxManager, IFileTab tab, IFileTreeNodeDecompiler fileTreeNodeDecompiler, IDecompiler decompiler, IDocumentViewer documentViewer, IFileTreeNodeData[] nodes) { this.messageBoxManager = messageBoxManager; this.tab = tab; this.fileTreeNodeDecompiler = fileTreeNodeDecompiler; this.decompiler = decompiler; this.documentViewer = documentViewer; this.nodes = nodes; }
public ToolTipProviderContext(IImageManager imageManager, IDotNetImageManager dotNetImageManager, IDecompiler decompiler, ICodeToolTipSettings codeToolTipSettings, IDocumentViewer documentViewer) { this.DocumentViewer = documentViewer; this.imageManager = imageManager; this.dotNetImageManager = dotNetImageManager; this.Decompiler = decompiler; this.codeToolTipSettings = codeToolTipSettings; }
public DocumentViewerPostProcessorContext(IDocumentViewerOutput documentViewerOutput, IDocumentViewer documentViewer, string text, IContentType contentType) { this.documentViewerOutput = documentViewerOutput; this.documentViewer = documentViewer; this.text = text; ContentType = contentType; }
public static bool VerifyAndGetCurrentDebuggedMethod(IDocumentViewer documentViewer, ModuleTokenId serToken, out IMethodDebugService methodDebugService) { methodDebugService = documentViewer.GetMethodDebugService(); return(methodDebugService.TryGetMethodDebugInfo(serToken) != null); }
bool DebugGetMethodSourceStatementForSetNextStatement(IDocumentViewer documentViewer, out string errMsg, out MethodSourceStatement methodStatement) { errMsg = string.Empty; methodStatement = default(MethodSourceStatement); if (ProcessState == DebuggerProcessState.Terminated) { errMsg = dnSpy_Debugger_Resources.Error_NotDebugging; return false; } if (ProcessState == DebuggerProcessState.Starting || ProcessState == DebuggerProcessState.Continuing || ProcessState == DebuggerProcessState.Running) { errMsg = dnSpy_Debugger_Resources.Error_CantSetNextStatementWhenNotStopped; return false; } if (documentViewer == null) { documentViewer = documentTabService.ActiveTab.TryGetDocumentViewer(); if (documentViewer == null) { errMsg = dnSpy_Debugger_Resources.Error_NoTabAvailableDecompileCurrentMethod; return false; } } IMethodDebugService methodDebugService; if (currentLocation == null || !DebugUtils.VerifyAndGetCurrentDebuggedMethod(documentViewer, currentLocation.Value.SerializedDnToken, out methodDebugService)) { errMsg = dnSpy_Debugger_Resources.Error_NoDebugInfoAvailable; return false; } Debug.Assert(currentLocation != null); var methodStatements = methodDebugService.FindByTextPosition(documentViewer.Caret.Position.BufferPosition.Position, sameMethod: false); if (methodStatements.Count == 0) { errMsg = dnSpy_Debugger_Resources.Error_CantSetNextStatementHere; return false; } if (GetCurrentMethodILFrame() == null) { errMsg = dnSpy_Debugger_Resources.Error_CantSetNextStatementNoILFrame; return false; } foreach (var info in methodStatements) { var md = info.Method; if (currentLocation.Value.Function.Token != md.MDToken.Raw) continue; var moduleId = moduleIdProvider.Create(md.Module); if (!moduleId.Equals(currentLocation.Value.SerializedDnToken.Module)) continue; methodStatement = info; break; } if (methodStatement.Method == null) { errMsg = dnSpy_Debugger_Resources.Error_CantSetNextStatementToAnotherMethod; return false; } return true; }
public static IBlockStructureServiceDataProvider TryCreate(IDocumentViewer documentViewer) { var lazyColl = documentViewer.Content.GetCustomData<LazyBlockStructureCollection>(DocumentViewerContentDataIds.BlockStructure); return lazyColl == null ? null : new BlockStructureServiceDataProvider(lazyColl); }
bool MoveCaretToCurrentStatement(IDocumentViewer documentViewer, bool canRefreshMethods) { if (documentViewer == null) return false; if (currentLocation == null) return false; if (DebugUtils.MoveCaretTo(documentViewer, currentLocation.Value.SerializedDnToken, currentLocation.Value.Offset)) return true; if (!canRefreshMethods) return false; RefreshMethodBodies(documentViewer); return false; }
bool TryShowNextStatement(IDocumentViewer documentViewer) { // Always reset the selected frame StackFrameService.SelectedFrameNumber = 0; if (currentLocation == null) return false; return DebugUtils.MoveCaretTo(documentViewer, currentLocation.Value.SerializedDnToken, currentLocation.Value.Offset); }
void RefreshMethodBodies(IDocumentViewer documentViewer) { if (currentLocation == null) return; if (currentMethod == null) return; if (documentViewer == null) return; // If this fails, we're probably in the prolog or epilog. Shouldn't normally happen. if (!currentLocation.Value.IsExact && !currentLocation.Value.IsApproximate) return; var body = currentMethod.Body; if (body == null) return; // If the offset is a valid instruction in the body, the method is probably not encrypted if (body.Instructions.Any(i => i.Offset == currentLocation.Value.Offset)) return; // No instruction with the current offset: it must be encrypted, and since we're executing // the method, we must be using an invalid method body. Use a copy of the module in // memory, and refresh the method bodies in case it's already loaded, and re-decompile // the method. var mod = currentMethod.Module; if (mod == null) return; var modNode = documentTabService.DocumentTreeView.FindNode(mod); if (modNode == null) return; var memFile = modNode.Document as MemoryModuleDefFile; IDsDocument document = memFile; if (memFile == null) { if (modNode.Document is CorModuleDefFile) return; var corMod = currentLocation.Value.Function.Module; if (corMod == null || corMod.IsDynamic) return; var dnMod = moduleLoader.Value.GetDnModule(corMod); document = inMemoryModuleService.Value.LoadDocument(dnMod, true); Debug.Assert(document != null); memFile = document as MemoryModuleDefFile; } if (document == null) return; // It's null if we couldn't load the file from memory because the PE / COR20 headers // are corrupt (eg. an obfuscator overwrote various fields with garbage). In that case, // file is a CorModuleDefFile and it's using the MD API to read the MD. if (memFile != null) inMemoryModuleService.Value.UpdateModuleMemory(memFile); UpdateCurrentMethod(document); JumpToCurrentStatement(documentViewer.DocumentTab, false); }
public DocumentViewerToolTipService GetService(IDocumentViewer documentViewer) => documentViewer.TextView.Properties.GetOrCreateSingletonProperty(typeof(DocumentViewerToolTipService), () => new DocumentViewerToolTipService(imageManager, dotNetImageManager, codeToolTipSettings, toolTipProviders, documentViewer));
public static bool VerifyAndGetCurrentDebuggedMethod(IDocumentViewer documentViewer, ModuleTokenId serToken, out IMethodDebugService methodDebugService) { methodDebugService = documentViewer.GetMethodDebugService(); return methodDebugService.TryGetMethodDebugInfo(serToken) != null; }
public ViewPdfViewViewModel(INavigationService navigationService, IDocumentViewer documentViewer) : base(navigationService) { _pdfPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); _documentViewer = documentViewer; }
List<ILCodeBreakpoint> GetILCodeBreakpoints(IDocumentViewer documentViewer, int textPosition) => GetILCodeBreakpoints(documentViewer, documentViewer.GetMethodDebugService().FindByTextPosition(textPosition, sameMethod: false));
//TODO: This method (and all callers) should take an ITextView instead of an IDocumentViewer as a parameter List<ILCodeBreakpoint> GetILCodeBreakpoints(IDocumentViewer documentViewer, IList<MethodSourceStatement> methodStatements) { var list = new List<ILCodeBreakpoint>(); if (methodStatements.Count == 0) return list; var service = documentViewer.TryGetMethodDebugService(); if (service == null) return list; var methodStatement = methodStatements[0]; foreach (var ilbp in GetILCodeBreakpoints()) { var info = service.TryGetMethodDebugInfo(ilbp.MethodToken); if (info == null) continue; var statement = info.GetSourceStatementByCodeOffset(ilbp.ILOffset); if (statement == null) continue; if (statement.Value.TextSpan != methodStatement.Statement.TextSpan) continue; list.Add(ilbp); } return list; }
BamlTabSaver(IDocumentTab tab, BamlResourceElementNode bamlNode, IDocumentViewer documentViewer, IMessageBoxService messageBoxService) { this.tab = tab; this.bamlNode = bamlNode; this.documentViewer = documentViewer; this.messageBoxService = messageBoxService; }