Exemple #1
0
        static void ExecuteInternal(DnHexBox dnHexBox, Window ownerWindow)
        {
            Debug.Assert(ownerWindow != null);
            if (dnHexBox == null)
            {
                return;
            }
            ulong start = dnHexBox.CaretPosition.Offset;
            ulong end   = start;

            if (dnHexBox.Selection != null)
            {
                start = dnHexBox.Selection.Value.StartOffset;
                end   = dnHexBox.Selection.Value.EndOffset;
            }
            var data = new SelectVM(dnHexBox.PhysicalToVisibleOffset(start), dnHexBox.PhysicalToVisibleOffset(end), dnHexBox.PhysicalToVisibleOffset(dnHexBox.StartOffset), dnHexBox.PhysicalToVisibleOffset(dnHexBox.EndOffset));
            var win  = new SelectDlg();

            win.DataContext = data;
            win.Owner       = ownerWindow ?? Application.Current.MainWindow;
            if (win.ShowDialog() != true)
            {
                return;
            }

            dnHexBox.Selection     = new HexSelection(dnHexBox.VisibleToPhysicalOffset(data.EndVM.Value), dnHexBox.VisibleToPhysicalOffset(data.StartVM.Value));
            dnHexBox.CaretPosition = new HexBoxPosition(dnHexBox.VisibleToPhysicalOffset(data.StartVM.Value), dnHexBox.CaretPosition.Kind, 0);
        }
Exemple #2
0
        internal static void Execute2(DnHexBox dnHexBox, Window ownerWindow)
        {
            Debug.Assert(ownerWindow != null);
            if (!CanExecute(dnHexBox))
            {
                return;
            }

            var data = new GoToOffsetVM(dnHexBox.PhysicalToVisibleOffset(dnHexBox.CaretPosition.Offset), dnHexBox.PhysicalToVisibleOffset(dnHexBox.StartOffset), dnHexBox.PhysicalToVisibleOffset(dnHexBox.EndOffset));
            var win  = new GoToOffsetDlg();

            win.DataContext = data;
            win.Owner       = ownerWindow ?? Application.Current.MainWindow;
            if (dnHexBox.IsMemory)
            {
                win.Title = dnSpy_Shared_Resources.GoToOffset_Title_Address;
                win.offsetLabel.Content = dnSpy_Shared_Resources.GoToOffset_Address_Label;
            }
            else
            {
                win.Title = dnSpy_Shared_Resources.GoToOffset_Title;
                win.offsetLabel.Content = dnSpy_Shared_Resources.GoToOffset_Offset_Label;
            }
            if (win.ShowDialog() != true)
            {
                return;
            }

            dnHexBox.CaretPosition = new HexBoxPosition(dnHexBox.VisibleToPhysicalOffset(data.OffsetVM.Value), dnHexBox.CaretPosition.Kind, 0);
        }
Exemple #3
0
        public override void Execute(DnHexBox dnHexBox)
        {
            var sel = dnHexBox.Selection;

            if (sel == null)
            {
                return;
            }

            var res = messageBoxManager.Ask <byte?>(dnSpy_Shared_Resources.FillSelection_Label, "0xFF", dnSpy_Shared_Resources.FillSelection_Title, s => {
                string error;
                byte b = NumberVMUtils.ParseByte(s, byte.MinValue, byte.MaxValue, out error);
                return(string.IsNullOrEmpty(error) ? b : (byte?)null);
            }, s => {
                string error;
                byte b = NumberVMUtils.ParseByte(s, byte.MinValue, byte.MaxValue, out error);
                return(error);
            });

            if (res == null)
            {
                return;
            }

            dnHexBox.FillBytes(sel.Value.StartOffset, sel.Value.EndOffset, res.Value);
            dnHexBox.Selection = null;
        }
Exemple #4
0
        internal static void Execute2(DnHexBox dnHexBox)
        {
            var sel = dnHexBox.Selection;

            if (sel == null)
            {
                return;
            }

            dnHexBox.StartOffset = sel.Value.StartOffset;
            dnHexBox.EndOffset   = sel.Value.EndOffset;
        }
Exemple #5
0
        internal static void Execute2(DnHexBox dnHexBox)
        {
            if (!CanExecute(dnHexBox))
            {
                return;
            }

            var data = GetBlobData(ClipboardUtils.GetData());

            if (data != null)
            {
                dnHexBox.Paste(data);
            }
        }
Exemple #6
0
 public void CopyTo(DnHexBox dnHexBox)
 {
     dnHexBox.BytesGroupCount    = this.BytesGroupCount;
     dnHexBox.BytesPerLine       = this.BytesPerLine;
     dnHexBox.UseHexPrefix       = this.UseHexPrefix;
     dnHexBox.ShowAscii          = this.ShowAscii;
     dnHexBox.LowerCaseHex       = this.LowerCaseHex;
     dnHexBox.AsciiEncoding      = this.AsciiEncoding;
     dnHexBox.HexOffsetSize      = this.HexOffsetSize;
     dnHexBox.UseRelativeOffsets = this.UseRelativeOffsets;
     dnHexBox.BaseOffset         = this.BaseOffset;
     dnHexBox.StartOffset        = this.StartOffset ?? dnHexBox.DocumentStartOffset;
     dnHexBox.EndOffset          = this.EndOffset ?? dnHexBox.DocumentEndOffset;
 }
Exemple #7
0
 public LocalHexSettings(DnHexBox dnHexBox)
 {
     this.BytesGroupCount    = dnHexBox.BytesGroupCount;
     this.BytesPerLine       = dnHexBox.BytesPerLine;
     this.UseHexPrefix       = dnHexBox.UseHexPrefix;
     this.ShowAscii          = dnHexBox.ShowAscii;
     this.LowerCaseHex       = dnHexBox.LowerCaseHex;
     this.AsciiEncoding      = dnHexBox.AsciiEncoding;
     this.HexOffsetSize      = dnHexBox.HexOffsetSize;
     this.UseRelativeOffsets = dnHexBox.UseRelativeOffsets;
     this.BaseOffset         = dnHexBox.BaseOffset;
     this.StartOffset        = dnHexBox.StartOffset == dnHexBox.DocumentStartOffset ? (ulong?)null : dnHexBox.StartOffset;
     this.EndOffset          = dnHexBox.EndOffset == dnHexBox.DocumentEndOffset ? (ulong?)null : dnHexBox.EndOffset;
 }
Exemple #8
0
        public override void Execute(DnHexBox dnHexBox)
        {
            var data = new LocalSettingsVM(new LocalHexSettings(dnHexBox));
            var win  = new LocalSettingsDlg();

            win.DataContext = data;
            win.Owner       = appWindow.MainWindow;
            if (win.ShowDialog() != true)
            {
                return;
            }

            data.CreateLocalHexSettings().CopyTo(dnHexBox);
        }
 public void CopyTo(DnHexBox dnHexBox)
 {
     dnHexBox.BytesGroupCount = this.BytesGroupCount;
     dnHexBox.BytesPerLine = this.BytesPerLine;
     dnHexBox.UseHexPrefix = this.UseHexPrefix;
     dnHexBox.ShowAscii = this.ShowAscii;
     dnHexBox.LowerCaseHex = this.LowerCaseHex;
     dnHexBox.AsciiEncoding = this.AsciiEncoding;
     dnHexBox.HexOffsetSize = this.HexOffsetSize;
     dnHexBox.UseRelativeOffsets = this.UseRelativeOffsets;
     dnHexBox.BaseOffset = this.BaseOffset;
     dnHexBox.StartOffset = this.StartOffset ?? dnHexBox.DocumentStartOffset;
     dnHexBox.EndOffset = this.EndOffset ?? dnHexBox.DocumentEndOffset;
 }
Exemple #10
0
 public LocalHexSettings(DnHexBox dnHexBox)
 {
     this.BytesGroupCount = dnHexBox.BytesGroupCount;
     this.BytesPerLine = dnHexBox.BytesPerLine;
     this.UseHexPrefix = dnHexBox.UseHexPrefix;
     this.ShowAscii = dnHexBox.ShowAscii;
     this.LowerCaseHex = dnHexBox.LowerCaseHex;
     this.AsciiEncoding = dnHexBox.AsciiEncoding;
     this.HexOffsetSize = dnHexBox.HexOffsetSize;
     this.UseRelativeOffsets = dnHexBox.UseRelativeOffsets;
     this.BaseOffset = dnHexBox.BaseOffset;
     this.StartOffset = dnHexBox.StartOffset == dnHexBox.DocumentStartOffset ? (ulong?)null : dnHexBox.StartOffset;
     this.EndOffset = dnHexBox.EndOffset == dnHexBox.DocumentEndOffset ? (ulong?)null : dnHexBox.EndOffset;
 }
Exemple #11
0
        internal static void Execute2(DnHexBox dnHexBox, Window ownerWindow)
        {
            Debug.Assert(ownerWindow != null);
            var doc = dnHexBox.Document;

            if (doc == null)
            {
                return;
            }
            var sel = dnHexBox.Selection;

            if (sel == null)
            {
                return;
            }

            var dialog = new WF.SaveFileDialog()
            {
                Filter           = PickFilenameConstants.AnyFilenameFilter,
                RestoreDirectory = true,
                ValidateNames    = true,
            };

            if (dialog.ShowDialog() != WF.DialogResult.OK)
            {
                return;
            }

            var data = new ProgressVM(Dispatcher.CurrentDispatcher, new HexDocumentDataSaver(doc, sel.Value.StartOffset, sel.Value.EndOffset, dialog.FileName));
            var win  = new ProgressDlg();

            win.DataContext = data;
            win.Owner       = ownerWindow ?? Application.Current.MainWindow;
            win.Title       = string.Format(dnSpy_Shared_Resources.HexEditorSaveSelection_Title, sel.Value.StartOffset, sel.Value.EndOffset);
            var res = win.ShowDialog();

            if (res != true)
            {
                return;
            }
            if (!data.WasError)
            {
                return;
            }
            App.MsgBox.Instance.Show(string.Format(dnSpy_Shared_Resources.AnErrorOccurred, data.ErrorMessage));
        }
Exemple #12
0
        internal static void Execute2(DnHexBox dnHexBox)
        {
            dnHexBox.StartOffset = dnHexBox.DocumentStartOffset;
            dnHexBox.EndOffset   = dnHexBox.DocumentEndOffset;
            var sel = dnHexBox.Selection;

            dnHexBox.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(delegate {
                if (sel != null && sel == dnHexBox.Selection)
                {
                    dnHexBox.SetCaretPositionAndMakeVisible(sel.Value.StartOffset, sel.Value.EndOffset);
                }
                else
                {
                    dnHexBox.BringCaretIntoView();
                }
            }));
        }
Exemple #13
0
		public MemoryContent(IWpfCommandManager wpfCommandManager, IThemeManager themeManager, IMenuManager menuManager, IHexEditorSettings hexEditorSettings, IMemoryVM memoryVM, IAppSettings appSettings) {
			this.memoryControl = new MemoryControl();
			this.vmMemory = memoryVM;
			this.vmMemory.SetRefreshLines(() => this.memoryControl.DnHexBox.RedrawModifiedLines());
			this.memoryControl.DataContext = this.vmMemory;
			var dnHexBox = new DnHexBox(menuManager, hexEditorSettings) {
				CacheLineBytes = true,
				IsMemory = true,
			};
			dnHexBox.SetBinding(HexBox.DocumentProperty, "HexDocument");
			this.memoryControl.DnHexBox = dnHexBox;
			dnHexBox.StartOffset = 0;
			dnHexBox.EndOffset = IntPtr.Size == 4 ? uint.MaxValue : ulong.MaxValue;

			appSettings.PropertyChanged += AppSettings_PropertyChanged;
			UpdateHexBoxRenderer(appSettings.UseNewRenderer_HexEditor);

			wpfCommandManager.Add(CommandConstants.GUID_DEBUGGER_MEMORY_CONTROL, memoryControl);
			wpfCommandManager.Add(CommandConstants.GUID_DEBUGGER_MEMORY_HEXBOX, memoryControl.DnHexBox);
		}
Exemple #14
0
 public override bool IsVisible(DnHexBox dnHexBox)
 {
     return(CanExecute(dnHexBox));
 }
		public HexBoxFileTabUIContext(HexDocument hexDocument, IMenuManager menuManager, IHexEditorSettings hexEditorSettings, IAppSettings appSettings, IHexBoxUndoManager hexBoxUndoManager) {
			this.hexDocument = hexDocument;
			this.dnHexBox = new DnHexBox(menuManager, hexEditorSettings);
			this.dnHexBox.Document = this.hexDocument;
			this.dnHexBox.InitializeStartEndOffsetToDocument();
			this.scrollViewer = new ScrollViewer {
				Content = this.dnHexBox,
				CanContentScroll = true,
				HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
				VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
				Focusable = false,
			};
			this.appSettings = appSettings;
			this.hexBoxUndoManager = hexBoxUndoManager;
			appSettings.PropertyChanged += AppSettings_PropertyChanged;
			UpdateHexBoxRenderer(appSettings.UseNewRenderer_HexEditor);
			hexBoxUndoManager.Initialize(this.dnHexBox);
		}
Exemple #16
0
 public override void Execute(DnHexBox dnHexBox)
 {
     Execute2(dnHexBox, appWindow.MainWindow);
 }
Exemple #17
0
 public override bool IsVisible(DnHexBox dnHexBox)
 {
     return(true);
 }
Exemple #18
0
 public override bool IsEnabled(DnHexBox dnHexBox)
 {
     return(dnHexBox.Selection != null);
 }
Exemple #19
0
 public override bool IsEnabled(DnHexBox dnHexBox)
 {
     return(dnHexBox.CanPasteUnicode());
 }
Exemple #20
0
 internal static bool CanExecute(DnHexBox dnHexBox)
 {
     return(dnHexBox != null && dnHexBox.Document != null);
 }
Exemple #21
0
 public override void Execute(DnHexBox dnHexBox)
 {
     dnHexBox.CopyUIContents();
 }
Exemple #22
0
 public override void Execute(DnHexBox dnHexBox)
 {
     dnHexBox.CopyUnicodeString();
 }
Exemple #23
0
 public override bool IsChecked(DnHexBox context)
 {
     return(context.UseHexPrefix ?? hexEditorSettings.UseHexPrefix);
 }
Exemple #24
0
 public override void Execute(DnHexBox dnHexBox)
 {
     dnHexBox.CopyVBArray();
 }
Exemple #25
0
 public override void Execute(DnHexBox dnHexBox)
 {
     dnHexBox.ShowAscii = !(dnHexBox.ShowAscii ?? hexEditorSettings.ShowAscii);
 }
Exemple #26
0
 public override void Execute(DnHexBox dnHexBox)
 {
     dnHexBox.CopyOffset();
 }
Exemple #27
0
 public override bool IsChecked(DnHexBox context)
 {
     return(context.ShowAscii ?? hexEditorSettings.ShowAscii);
 }
Exemple #28
0
 public override void Execute(DnHexBox dnHexBox)
 {
     dnHexBox.PasteUnicode();
 }
Exemple #29
0
 public override void Execute(DnHexBox dnHexBox)
 {
     dnHexBox.LowerCaseHex = !(dnHexBox.LowerCaseHex ?? hexEditorSettings.LowerCaseHex);
 }
Exemple #30
0
 internal static bool CanExecute(DnHexBox dnHexBox)
 {
     return(dnHexBox != null && GetBlobData(ClipboardUtils.GetData()) != null);
 }
Exemple #31
0
 public override bool IsChecked(DnHexBox context)
 {
     return(context.LowerCaseHex ?? hexEditorSettings.LowerCaseHex);
 }
Exemple #32
0
 public override void Execute(DnHexBox dnHexBox)
 {
     Execute2(dnHexBox);
 }
Exemple #33
0
 public override void Execute(DnHexBox context)
 {
 }
Exemple #34
0
 public override bool IsEnabled(DnHexBox dnHexBox)
 {
     return(CanExecute(dnHexBox));
 }
		static bool IsVisible(DnHexBox dnHexBox, ulong start, ulong length) {
			ulong end = length == 0 ? start : start + length - 1;
			if (end < start)
				return false;
			return start >= dnHexBox.StartOffset && end <= dnHexBox.EndOffset;
		}