static string GetMethodAsString(SerializedDnSpyToken key) { var file = ModuleLoader.Instance.LoadModule(key.Module, true, true); var method = file == null ? null : file.ModuleDef.ResolveToken(key.Token) as MethodDef; return(method == null ? null : method.ToString()); }
public void GetMethodInfo(SerializedDnSpyToken key, out Parameter[] parameters, out Local[] locals, out ILVariable[] decLocals) { parameters = null; locals = null; decLocals = null; foreach (var textView in MainWindow.Instance.AllTextViews) { if (parameters != null && decLocals != null) break; var cm = textView.CodeMappings; if (cm == null) continue; MemberMapping mapping; if (!cm.TryGetValue(key, out mapping)) continue; var method = mapping.MethodDef; if (mapping.LocalVariables != null && method.Body != null) { locals = method.Body.Variables.ToArray(); decLocals = new ILVariable[method.Body.Variables.Count]; foreach (var v in mapping.LocalVariables) { if (v.IsGenerated) continue; if (v.OriginalVariable == null) continue; if ((uint)v.OriginalVariable.Index >= decLocals.Length) continue; decLocals[v.OriginalVariable.Index] = v; } } parameters = method.Parameters.ToArray(); } }
static bool JumpToStatement(MethodDef method, uint ilOffset, DecompilerTextView textView) { if (method == null) return false; var serMod = method.Module.ToSerializedDnSpyModule(); var key = new SerializedDnSpyToken(serMod, method.MDToken); if (textView == null) textView = MainWindow.Instance.SafeActiveTextView; bool found = MainWindow.Instance.DnSpyFileListTreeNode.FindModuleNode(method.Module) != null; if (found) { return MainWindow.Instance.JumpToReference(textView, method, (success, hasMovedCaret) => { if (success) return MoveCaretTo(textView, key, ilOffset); return false; }); } MainWindow.Instance.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { MainWindow.Instance.JumpToReference(textView, method, (success, hasMovedCaret) => { if (success) return MoveCaretTo(textView, key, ilOffset); return false; }); })); return true; }
public static void Toggle(DecompilerTextView textView, int line, int column) { var bps = SourceCodeMappingUtils.Find(textView, line, column); var ilbps = GetILCodeBreakpoints(textView, bps); if (ilbps.Count > 0) { if (IsEnabled(ilbps)) { foreach (var ilbp in ilbps) { BreakpointManager.Instance.Remove(ilbp); } } else { foreach (var bpm in ilbps) { bpm.IsEnabled = true; } } } else if (bps.Count > 0) { foreach (var bp in bps) { var md = bp.MemberMapping.MethodDef; var serMod = md.Module.ToSerializedDnSpyModule(); var key = new SerializedDnSpyToken(serMod, md.MDToken); BreakpointManager.Instance.Add(new ILCodeBreakpoint(key, bp.ILInstructionOffset.From)); } textView.ScrollAndMoveCaretTo(bps[0].StartLocation.Line, bps[0].StartLocation.Column); } }
void LoadInternal() { DNSpySettings settings = DNSpySettings.Load(); var bpsx = settings[SETTINGS_NAME]; BreakpointManager.Instance.Clear(); foreach (var bpx in bpsx.Elements("Breakpoint")) { uint? token = (uint?)bpx.Attribute("Token"); string asmFullName = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullName")); string moduleName = SessionSettings.Unescape((string)bpx.Attribute("ModuleName")); bool? isDynamic = (bool?)bpx.Attribute("IsDynamic"); bool? isInMemory = (bool?)bpx.Attribute("IsInMemory"); uint? ilOffset = (uint?)bpx.Attribute("ILOffset"); bool? isEnabled = (bool?)bpx.Attribute("IsEnabled"); if (token == null) { continue; } if (isDynamic == null || isInMemory == null) { continue; } if (string.IsNullOrEmpty(asmFullName)) { continue; } if (string.IsNullOrEmpty(moduleName)) { continue; } if (ilOffset == null) { continue; } if (isEnabled == null) { continue; } var snModule = SerializedDnSpyModule.Create(asmFullName, moduleName, isDynamic.Value, isInMemory.Value); var key = new SerializedDnSpyToken(snModule, token.Value); if (!isInMemory.Value && !isDynamic.Value) { var s = SessionSettings.Unescape((string)bpx.Attribute("Method")); if (s == null || s != GetMethodAsString(key)) { continue; } } var bp = new ILCodeBreakpoint(key, ilOffset.Value, isEnabled.Value); BreakpointManager.Instance.Add(bp); } }
public void GetMethodInfo(SerializedDnSpyToken key, out Parameter[] parameters, out Local[] locals, out ILVariable[] decLocals) { parameters = null; locals = null; decLocals = null; foreach (var textView in MainWindow.Instance.AllTextViews) { if (parameters != null && decLocals != null) { break; } var cm = textView.CodeMappings; if (cm == null) { continue; } MemberMapping mapping; if (!cm.TryGetValue(key, out mapping)) { continue; } var method = mapping.MethodDef; if (mapping.LocalVariables != null && method.Body != null) { locals = method.Body.Variables.ToArray(); decLocals = new ILVariable[method.Body.Variables.Count]; foreach (var v in mapping.LocalVariables) { if (v.IsGenerated) { continue; } if (v.OriginalVariable == null) { continue; } if ((uint)v.OriginalVariable.Index >= decLocals.Length) { continue; } decLocals[v.OriginalVariable.Index] = v; } } parameters = method.Parameters.ToArray(); } }
public static bool MoveCaretTo(DecompilerTextView textView, SerializedDnSpyToken key, uint ilOffset) { if (textView == null) return false; Dictionary<SerializedDnSpyToken, MemberMapping> cm; if (!VerifyAndGetCurrentDebuggedMethod(textView, key, out cm)) return false; TextLocation location, endLocation; if (!cm[key].GetInstructionByTokenAndOffset(ilOffset, out location, out endLocation)) return false; textView.ScrollAndMoveCaretTo(location.Line, location.Column); return true; }
static bool JumpToStatement(MethodDef method, uint ilOffset, DecompilerTextView textView) { if (method == null) { return(false); } var serMod = method.Module.ToSerializedDnSpyModule(); var key = new SerializedDnSpyToken(serMod, method.MDToken); if (textView == null) { textView = MainWindow.Instance.SafeActiveTextView; } bool found = MainWindow.Instance.DnSpyFileListTreeNode.FindModuleNode(method.Module) != null; if (found) { return(MainWindow.Instance.JumpToReference(textView, method, (success, hasMovedCaret) => { if (success) { return MoveCaretTo(textView, key, ilOffset); } return false; })); } MainWindow.Instance.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { MainWindow.Instance.JumpToReference(textView, method, (success, hasMovedCaret) => { if (success) { return(MoveCaretTo(textView, key, ilOffset)); } return(false); }); })); return(true); }
public static bool MoveCaretTo(DecompilerTextView textView, SerializedDnSpyToken key, uint ilOffset) { if (textView == null) { return(false); } Dictionary <SerializedDnSpyToken, MemberMapping> cm; if (!VerifyAndGetCurrentDebuggedMethod(textView, key, out cm)) { return(false); } TextLocation location, endLocation; if (!cm[key].GetInstructionByTokenAndOffset(ilOffset, out location, out endLocation)) { return(false); } textView.ScrollAndMoveCaretTo(location.Line, location.Column); return(true); }
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; }
static string GetMethodAsString(SerializedDnSpyToken key) { var file = ModuleLoader.Instance.LoadModule(key.Module, true, true); var method = file == null ? null : file.ModuleDef.ResolveToken(key.Token) as MethodDef; return method == null ? null : method.ToString(); }
public static void Toggle(DecompilerTextView textView, int line, int column) { var bps = SourceCodeMappingUtils.Find(textView, line, column); var ilbps = GetILCodeBreakpoints(textView, bps); if (ilbps.Count > 0) { if (IsEnabled(ilbps)) { foreach (var ilbp in ilbps) BreakpointManager.Instance.Remove(ilbp); } else { foreach (var bpm in ilbps) bpm.IsEnabled = true; } } else if (bps.Count > 0) { foreach (var bp in bps) { var md = bp.MemberMapping.MethodDef; var serMod = md.Module.ToSerializedDnSpyModule(); var key = new SerializedDnSpyToken(serMod, md.MDToken); BreakpointManager.Instance.Add(new ILCodeBreakpoint(key, bp.ILInstructionOffset.From)); } textView.ScrollAndMoveCaretTo(bps[0].StartLocation.Line, bps[0].StartLocation.Column); } }
public StackFrameLine(StackFrameLineType type, DecompilerTextView decompilerTextView, SerializedDnSpyToken methodKey, uint ilOffset) : base(methodKey, ilOffset) { this.type = type; this.decompilerTextView = decompilerTextView; }
protected MarkedTextLine(SerializedDnSpyToken methodKey, uint ilOffset, IMarkedTextLine senderObj = null) { this.methodKey = methodKey; this.ilOffset = ilOffset; this.senderObj = senderObj ?? this; }
/// <summary> /// Should be called each time the IL offset has been updated /// </summary> bool UpdateStackFrameLines(DecompilerTextView decompilerTextView, bool moveCaret = false) { Remove(decompilerTextView); bool movedCaret = false; var cm = decompilerTextView == null ? null : decompilerTextView.CodeMappings; bool updateReturnStatements = cm != null && DebugManager.Instance.ProcessState == DebuggerProcessState.Stopped; if (updateReturnStatements) { int frameNo = -1; bool tooManyFrames; foreach (var frame in GetFrames(MAX_STACKFRAME_LINES, out tooManyFrames)) { frameNo++; if (!frame.IsILFrame) { continue; } var ip = frame.ILFrameIP; if (!ip.IsExact && !ip.IsApproximate && !ip.IsProlog && !ip.IsEpilog) { continue; } uint token = frame.Token; if (token == 0) { continue; } var serAsm = frame.SerializedDnModule; if (serAsm == null) { continue; } StackFrameLineType type; if (frameNo == 0) { type = StackFrameLineType.CurrentStatement; } else { type = currentState.FrameNumber == frameNo ? StackFrameLineType.SelectedReturnStatement : StackFrameLineType.ReturnStatement; } var key = new SerializedDnSpyToken(serAsm.Value.ToSerializedDnSpyModule(), token); uint offset = frame.GetILOffset(); MethodDef methodDef; TextLocation location, endLocation; if (cm != null && cm.ContainsKey(key) && cm[key].GetInstructionByTokenAndOffset(offset, out methodDef, out location, out endLocation)) { var rs = new StackFrameLine(type, decompilerTextView, key, offset); stackFrameLines.Add(rs); TextLineObjectManager.Instance.Add(rs); if (moveCaret && frameNo == currentState.FrameNumber) { decompilerTextView.ScrollAndMoveCaretTo(location.Line, location.Column); movedCaret = true; } } } } return(movedCaret); }
public MyMarkedTextLine(ILCodeBreakpoint ilbp, SerializedDnSpyToken methodKey, uint ilOffset) : base(methodKey, ilOffset, ilbp) { this.ilbp = ilbp; }
void LoadInternal() { DNSpySettings settings = DNSpySettings.Load(); var bpsx = settings[SETTINGS_NAME]; BreakpointManager.Instance.Clear(); foreach (var bpx in bpsx.Elements("Breakpoint")) { uint? token = (uint?)bpx.Attribute("Token"); string asmFullName = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullName")); string moduleName = SessionSettings.Unescape((string)bpx.Attribute("ModuleName")); bool? isDynamic = (bool?)bpx.Attribute("IsDynamic"); bool? isInMemory = (bool?)bpx.Attribute("IsInMemory"); uint? ilOffset = (uint?)bpx.Attribute("ILOffset"); bool? isEnabled = (bool?)bpx.Attribute("IsEnabled"); if (token == null) continue; if (isDynamic == null || isInMemory == null) continue; if (string.IsNullOrEmpty(asmFullName)) continue; if (string.IsNullOrEmpty(moduleName)) continue; if (ilOffset == null) continue; if (isEnabled == null) continue; var snModule = SerializedDnSpyModule.Create(asmFullName, moduleName, isDynamic.Value, isInMemory.Value); var key = new SerializedDnSpyToken(snModule, token.Value); if (!isInMemory.Value && !isDynamic.Value) { var s = SessionSettings.Unescape((string)bpx.Attribute("Method")); if (s == null || s != GetMethodAsString(key)) continue; } var bp = new ILCodeBreakpoint(key, ilOffset.Value, isEnabled.Value); BreakpointManager.Instance.Add(bp); } }
/// <summary> /// Should be called each time the IL offset has been updated /// </summary> bool UpdateStackFrameLines(DecompilerTextView decompilerTextView, bool moveCaret = false) { Remove(decompilerTextView); bool movedCaret = false; var cm = decompilerTextView == null ? null : decompilerTextView.CodeMappings; bool updateReturnStatements = cm != null && DebugManager.Instance.ProcessState == DebuggerProcessState.Stopped; if (updateReturnStatements) { int frameNo = -1; bool tooManyFrames; foreach (var frame in GetFrames(MAX_STACKFRAME_LINES, out tooManyFrames)) { frameNo++; if (!frame.IsILFrame) continue; var ip = frame.ILFrameIP; if (!ip.IsExact && !ip.IsApproximate && !ip.IsProlog && !ip.IsEpilog) continue; uint token = frame.Token; if (token == 0) continue; var serAsm = frame.SerializedDnModule; if (serAsm == null) continue; StackFrameLineType type; if (frameNo == 0) type = StackFrameLineType.CurrentStatement; else type = currentState.FrameNumber == frameNo ? StackFrameLineType.SelectedReturnStatement : StackFrameLineType.ReturnStatement; var key = new SerializedDnSpyToken(serAsm.Value.ToSerializedDnSpyModule(), token); uint offset = frame.GetILOffset(); MethodDef methodDef; TextLocation location, endLocation; if (cm != null && cm.ContainsKey(key) && cm[key].GetInstructionByTokenAndOffset(offset, out methodDef, out location, out endLocation)) { var rs = new StackFrameLine(type, decompilerTextView, key, offset); stackFrameLines.Add(rs); TextLineObjectManager.Instance.Add(rs); if (moveCaret && frameNo == currentState.FrameNumber) { decompilerTextView.ScrollAndMoveCaretTo(location.Line, location.Column); movedCaret = true; } } } } return movedCaret; }
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 ILCodeBreakpoint(SerializedDnSpyToken methodKey, uint ilOffset, bool isEnabled = true) : base(isEnabled) { this.myMarkedTextLine = new MyMarkedTextLine(this, methodKey, ilOffset); }