From 8e675e375eec58b1e2e1effff4ddb26f361f2de6 Mon Sep 17 00:00:00 2001 From: valarnin Date: Sun, 7 Feb 2016 20:01:01 -0500 Subject: [PATCH] Added project files --- NTRDebuggerTool.sln | 20 + NTRDebuggerTool/App.config | 6 + NTRDebuggerTool/Forms/MainForm.Designer.cs | 556 ++++++++++++++++++ NTRDebuggerTool/Forms/MainForm.cs | 461 +++++++++++++++ NTRDebuggerTool/Forms/MainForm.resx | 314 ++++++++++ .../Forms/MainFormThreadEventDispatcher.cs | 134 +++++ NTRDebuggerTool/NTRDebuggerTool.csproj | 94 +++ NTRDebuggerTool/Program.cs | 21 + NTRDebuggerTool/Properties/AssemblyInfo.cs | 35 ++ .../Properties/Resources.Designer.cs | 71 +++ NTRDebuggerTool/Properties/Resources.resx | 117 ++++ .../Properties/Settings.Designer.cs | 30 + NTRDebuggerTool/Properties/Settings.settings | 7 + .../Remote/NTRPacketReceiverThread.cs | 247 ++++++++ NTRDebuggerTool/Remote/NTRRemoteConnection.cs | 353 +++++++++++ NTRDebuggerTool/Remote/PacketCommand.cs | 17 + NTRDebuggerTool/Remote/PacketType.cs | 9 + NTRDebuggerTool/Utilities.cs | 22 + 18 files changed, 2514 insertions(+) create mode 100644 NTRDebuggerTool.sln create mode 100644 NTRDebuggerTool/App.config create mode 100644 NTRDebuggerTool/Forms/MainForm.Designer.cs create mode 100644 NTRDebuggerTool/Forms/MainForm.cs create mode 100644 NTRDebuggerTool/Forms/MainForm.resx create mode 100644 NTRDebuggerTool/Forms/MainFormThreadEventDispatcher.cs create mode 100644 NTRDebuggerTool/NTRDebuggerTool.csproj create mode 100644 NTRDebuggerTool/Program.cs create mode 100644 NTRDebuggerTool/Properties/AssemblyInfo.cs create mode 100644 NTRDebuggerTool/Properties/Resources.Designer.cs create mode 100644 NTRDebuggerTool/Properties/Resources.resx create mode 100644 NTRDebuggerTool/Properties/Settings.Designer.cs create mode 100644 NTRDebuggerTool/Properties/Settings.settings create mode 100644 NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs create mode 100644 NTRDebuggerTool/Remote/NTRRemoteConnection.cs create mode 100644 NTRDebuggerTool/Remote/PacketCommand.cs create mode 100644 NTRDebuggerTool/Remote/PacketType.cs create mode 100644 NTRDebuggerTool/Utilities.cs diff --git a/NTRDebuggerTool.sln b/NTRDebuggerTool.sln new file mode 100644 index 0000000..4e1aa9e --- /dev/null +++ b/NTRDebuggerTool.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NTRDebuggerTool", "NTRDebuggerTool\NTRDebuggerTool.csproj", "{86AF1318-9584-4CDE-93BC-C2F0DCF958C5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {86AF1318-9584-4CDE-93BC-C2F0DCF958C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86AF1318-9584-4CDE-93BC-C2F0DCF958C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {86AF1318-9584-4CDE-93BC-C2F0DCF958C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {86AF1318-9584-4CDE-93BC-C2F0DCF958C5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/NTRDebuggerTool/App.config b/NTRDebuggerTool/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/NTRDebuggerTool/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/NTRDebuggerTool/Forms/MainForm.Designer.cs b/NTRDebuggerTool/Forms/MainForm.Designer.cs new file mode 100644 index 0000000..1e55b9b --- /dev/null +++ b/NTRDebuggerTool/Forms/MainForm.Designer.cs @@ -0,0 +1,556 @@ +namespace NTRDebuggerTool.Forms +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); + this.SearchType = new System.Windows.Forms.ComboBox(); + this.LabelSearchType = new System.Windows.Forms.Label(); + this.LabelSearchValue = new System.Windows.Forms.Label(); + this.SearchValue = new System.Windows.Forms.TextBox(); + this.LabelSearchResults = new System.Windows.Forms.Label(); + this.ResultsGrid = new System.Windows.Forms.DataGridView(); + this.SearchResultsAddressColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SearchResultsValueColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ButtonAddResults = new System.Windows.Forms.Button(); + this.SearchButton = new System.Windows.Forms.Button(); + this.ResetButton = new System.Windows.Forms.Button(); + this.LabelResults = new System.Windows.Forms.Label(); + this.ValuesGrid = new System.Windows.Forms.DataGridView(); + this.ValuesGridLockColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.ValuesGridAddressColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ValuesGridValueColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ValuesGridTypeColumn = new System.Windows.Forms.DataGridViewComboBoxColumn(); + this.ValuesGridContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.ValuesGridAddItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ValuesGridDeleteItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ValuesGridConvertCode = new System.Windows.Forms.ToolStripMenuItem(); + this.LabelIPPort = new System.Windows.Forms.Label(); + this.LabelProcess = new System.Windows.Forms.Label(); + this.LabelMemoryRange = new System.Windows.Forms.Label(); + this.ButtonConnectDisconnect = new System.Windows.Forms.Button(); + this.ButtonOpenProcess = new System.Windows.Forms.Button(); + this.ButtonRefreshMemoryRange = new System.Windows.Forms.Button(); + this.IP = new System.Windows.Forms.TextBox(); + this.Port = new System.Windows.Forms.TextBox(); + this.Processes = new System.Windows.Forms.ComboBox(); + this.MemoryRange = new System.Windows.Forms.ComboBox(); + this.ProgressBarStatusStrip = new System.Windows.Forms.StatusStrip(); + this.ProgressBar = new System.Windows.Forms.ProgressBar(); + this.GUIUpdateTimer = new System.Windows.Forms.Timer(this.components); + this.LabelCustomRange = new System.Windows.Forms.Label(); + this.MemoryStart = new System.Windows.Forms.TextBox(); + this.MemorySize = new System.Windows.Forms.TextBox(); + this.LabelCurrentOperation = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.ResultsGrid)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.ValuesGrid)).BeginInit(); + this.ValuesGridContextMenuStrip.SuspendLayout(); + this.SuspendLayout(); + // + // SearchType + // + this.SearchType.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.SearchType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.SearchType.FormattingEnabled = true; + this.SearchType.Items.AddRange(new object[] { + "1 Byte", + "2 Bytes", + "4 Bytes", + "8 Bytes", + "Float", + "Double", + "Raw Bytes"}); + this.SearchType.Location = new System.Drawing.Point(313, 110); + this.SearchType.Name = "SearchType"; + this.SearchType.Size = new System.Drawing.Size(173, 21); + this.SearchType.TabIndex = 1; + // + // LabelSearchType + // + this.LabelSearchType.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.LabelSearchType.AutoSize = true; + this.LabelSearchType.Location = new System.Drawing.Point(250, 115); + this.LabelSearchType.Name = "LabelSearchType"; + this.LabelSearchType.Size = new System.Drawing.Size(57, 13); + this.LabelSearchType.TabIndex = 2; + this.LabelSearchType.Text = "Data Type"; + this.LabelSearchType.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // LabelSearchValue + // + this.LabelSearchValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.LabelSearchValue.AutoSize = true; + this.LabelSearchValue.Location = new System.Drawing.Point(236, 140); + this.LabelSearchValue.Name = "LabelSearchValue"; + this.LabelSearchValue.Size = new System.Drawing.Size(71, 13); + this.LabelSearchValue.TabIndex = 3; + this.LabelSearchValue.Text = "Search Value"; + this.LabelSearchValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // SearchValue + // + this.SearchValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.SearchValue.Location = new System.Drawing.Point(313, 137); + this.SearchValue.Name = "SearchValue"; + this.SearchValue.Size = new System.Drawing.Size(173, 20); + this.SearchValue.TabIndex = 4; + // + // LabelSearchResults + // + this.LabelSearchResults.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.LabelSearchResults.Location = new System.Drawing.Point(12, 9); + this.LabelSearchResults.Name = "LabelSearchResults"; + this.LabelSearchResults.Size = new System.Drawing.Size(95, 27); + this.LabelSearchResults.TabIndex = 5; + this.LabelSearchResults.Text = "Search Results"; + this.LabelSearchResults.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // ResultsGrid + // + this.ResultsGrid.AllowUserToAddRows = false; + this.ResultsGrid.AllowUserToDeleteRows = false; + this.ResultsGrid.AllowUserToResizeRows = false; + this.ResultsGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.ResultsGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.ResultsGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.SearchResultsAddressColumn, + this.SearchResultsValueColumn}); + this.ResultsGrid.Location = new System.Drawing.Point(12, 39); + this.ResultsGrid.Name = "ResultsGrid"; + this.ResultsGrid.ReadOnly = true; + this.ResultsGrid.RowHeadersVisible = false; + this.ResultsGrid.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.ResultsGrid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.ResultsGrid.ShowCellErrors = false; + this.ResultsGrid.ShowCellToolTips = false; + this.ResultsGrid.ShowEditingIcon = false; + this.ResultsGrid.ShowRowErrors = false; + this.ResultsGrid.Size = new System.Drawing.Size(218, 270); + this.ResultsGrid.TabIndex = 7; + // + // SearchResultsAddressColumn + // + this.SearchResultsAddressColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.SearchResultsAddressColumn.FillWeight = 600F; + this.SearchResultsAddressColumn.HeaderText = "Address"; + this.SearchResultsAddressColumn.Name = "SearchResultsAddressColumn"; + this.SearchResultsAddressColumn.ReadOnly = true; + // + // SearchResultsValueColumn + // + this.SearchResultsValueColumn.HeaderText = "Value"; + this.SearchResultsValueColumn.Name = "SearchResultsValueColumn"; + this.SearchResultsValueColumn.ReadOnly = true; + this.SearchResultsValueColumn.Width = 50; + // + // ButtonAddResults + // + this.ButtonAddResults.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonAddResults.Location = new System.Drawing.Point(113, 12); + this.ButtonAddResults.Name = "ButtonAddResults"; + this.ButtonAddResults.Size = new System.Drawing.Size(117, 23); + this.ButtonAddResults.TabIndex = 8; + this.ButtonAddResults.Text = "Add Selected Results"; + this.ButtonAddResults.UseVisualStyleBackColor = true; + this.ButtonAddResults.Click += new System.EventHandler(this.ButtonAddResults_Click); + // + // SearchButton + // + this.SearchButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.SearchButton.Location = new System.Drawing.Point(239, 163); + this.SearchButton.Name = "SearchButton"; + this.SearchButton.Size = new System.Drawing.Size(75, 23); + this.SearchButton.TabIndex = 9; + this.SearchButton.Text = "Search"; + this.SearchButton.UseVisualStyleBackColor = true; + this.SearchButton.Click += new System.EventHandler(this.SearchButton_Click); + // + // ResetButton + // + this.ResetButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ResetButton.Location = new System.Drawing.Point(411, 163); + this.ResetButton.Name = "ResetButton"; + this.ResetButton.Size = new System.Drawing.Size(75, 23); + this.ResetButton.TabIndex = 10; + this.ResetButton.Text = "Reset"; + this.ResetButton.UseVisualStyleBackColor = true; + this.ResetButton.Click += new System.EventHandler(this.ResetButton_Click); + // + // LabelResults + // + this.LabelResults.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.LabelResults.Location = new System.Drawing.Point(320, 163); + this.LabelResults.Name = "LabelResults"; + this.LabelResults.Size = new System.Drawing.Size(85, 23); + this.LabelResults.TabIndex = 11; + this.LabelResults.Text = "Results:"; + this.LabelResults.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // ValuesGrid + // + this.ValuesGrid.AllowUserToAddRows = false; + this.ValuesGrid.AllowUserToResizeRows = false; + this.ValuesGrid.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.ValuesGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.ValuesGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ValuesGridLockColumn, + this.ValuesGridAddressColumn, + this.ValuesGridValueColumn, + this.ValuesGridTypeColumn}); + this.ValuesGrid.ContextMenuStrip = this.ValuesGridContextMenuStrip; + this.ValuesGrid.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; + this.ValuesGrid.Location = new System.Drawing.Point(239, 192); + this.ValuesGrid.MultiSelect = false; + this.ValuesGrid.Name = "ValuesGrid"; + this.ValuesGrid.RowHeadersVisible = false; + this.ValuesGrid.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.ValuesGrid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; + this.ValuesGrid.ShowCellErrors = false; + this.ValuesGrid.ShowCellToolTips = false; + this.ValuesGrid.ShowEditingIcon = false; + this.ValuesGrid.ShowRowErrors = false; + this.ValuesGrid.Size = new System.Drawing.Size(247, 117); + this.ValuesGrid.TabIndex = 12; + this.ValuesGrid.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.ValuesGrid_CellDoubleClick); + this.ValuesGrid.CellLeave += new System.Windows.Forms.DataGridViewCellEventHandler(this.ValuesGrid_CellLeave); + this.ValuesGrid.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.ValuesGrid_CellValueChanged); + // + // ValuesGridLockColumn + // + this.ValuesGridLockColumn.HeaderText = "Lock"; + this.ValuesGridLockColumn.Name = "ValuesGridLockColumn"; + this.ValuesGridLockColumn.Resizable = System.Windows.Forms.DataGridViewTriState.False; + this.ValuesGridLockColumn.TrueValue = "T"; + this.ValuesGridLockColumn.Width = 35; + // + // ValuesGridAddressColumn + // + this.ValuesGridAddressColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ValuesGridAddressColumn.FillWeight = 600F; + this.ValuesGridAddressColumn.HeaderText = "Address"; + this.ValuesGridAddressColumn.Name = "ValuesGridAddressColumn"; + // + // ValuesGridValueColumn + // + this.ValuesGridValueColumn.HeaderText = "Value"; + this.ValuesGridValueColumn.Name = "ValuesGridValueColumn"; + this.ValuesGridValueColumn.Width = 50; + // + // ValuesGridTypeColumn + // + this.ValuesGridTypeColumn.HeaderText = "Type"; + this.ValuesGridTypeColumn.Items.AddRange(new object[] { + "1 Byte", + "2 Bytes", + "4 Bytes", + "8 Bytes", + "Float", + "Double", + "Raw Bytes"}); + this.ValuesGridTypeColumn.Name = "ValuesGridTypeColumn"; + this.ValuesGridTypeColumn.Width = 40; + // + // ValuesGridContextMenuStrip + // + this.ValuesGridContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ValuesGridAddItem, + this.ValuesGridDeleteItem, + this.ValuesGridConvertCode}); + this.ValuesGridContextMenuStrip.Name = "ValuesGridContextMenuStrip"; + this.ValuesGridContextMenuStrip.Size = new System.Drawing.Size(186, 70); + this.ValuesGridContextMenuStrip.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.ValuesGridContextMenuStrip_ItemClicked); + // + // ValuesGridAddItem + // + this.ValuesGridAddItem.Name = "ValuesGridAddItem"; + this.ValuesGridAddItem.Size = new System.Drawing.Size(185, 22); + this.ValuesGridAddItem.Text = "New"; + // + // ValuesGridDeleteItem + // + this.ValuesGridDeleteItem.Name = "ValuesGridDeleteItem"; + this.ValuesGridDeleteItem.Size = new System.Drawing.Size(185, 22); + this.ValuesGridDeleteItem.Text = "Delete"; + // + // ValuesGridConvertCode + // + this.ValuesGridConvertCode.Name = "ValuesGridConvertCode"; + this.ValuesGridConvertCode.Size = new System.Drawing.Size(185, 22); + this.ValuesGridConvertCode.Text = "Convert AR3DS Code"; + // + // LabelIPPort + // + this.LabelIPPort.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.LabelIPPort.Location = new System.Drawing.Point(236, 9); + this.LabelIPPort.Name = "LabelIPPort"; + this.LabelIPPort.Size = new System.Drawing.Size(48, 23); + this.LabelIPPort.TabIndex = 13; + this.LabelIPPort.Text = "IP, Port"; + this.LabelIPPort.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // LabelProcess + // + this.LabelProcess.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.LabelProcess.Location = new System.Drawing.Point(236, 32); + this.LabelProcess.Name = "LabelProcess"; + this.LabelProcess.Size = new System.Drawing.Size(48, 23); + this.LabelProcess.TabIndex = 15; + this.LabelProcess.Text = "Process"; + this.LabelProcess.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // LabelMemoryRange + // + this.LabelMemoryRange.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.LabelMemoryRange.Location = new System.Drawing.Point(236, 55); + this.LabelMemoryRange.Name = "LabelMemoryRange"; + this.LabelMemoryRange.Size = new System.Drawing.Size(48, 23); + this.LabelMemoryRange.TabIndex = 16; + this.LabelMemoryRange.Text = "Range"; + this.LabelMemoryRange.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // ButtonConnectDisconnect + // + this.ButtonConnectDisconnect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonConnectDisconnect.Location = new System.Drawing.Point(413, 9); + this.ButtonConnectDisconnect.Name = "ButtonConnectDisconnect"; + this.ButtonConnectDisconnect.Size = new System.Drawing.Size(73, 23); + this.ButtonConnectDisconnect.TabIndex = 17; + this.ButtonConnectDisconnect.Text = "Connect"; + this.ButtonConnectDisconnect.UseVisualStyleBackColor = true; + this.ButtonConnectDisconnect.Click += new System.EventHandler(this.ButtonConnectDisconnect_Click); + // + // ButtonOpenProcess + // + this.ButtonOpenProcess.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonOpenProcess.Location = new System.Drawing.Point(418, 32); + this.ButtonOpenProcess.Name = "ButtonOpenProcess"; + this.ButtonOpenProcess.Size = new System.Drawing.Size(68, 23); + this.ButtonOpenProcess.TabIndex = 18; + this.ButtonOpenProcess.Text = "Open"; + this.ButtonOpenProcess.UseVisualStyleBackColor = true; + this.ButtonOpenProcess.Click += new System.EventHandler(this.ButtonOpenProcess_Click); + // + // ButtonRefreshMemoryRange + // + this.ButtonRefreshMemoryRange.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRefreshMemoryRange.Location = new System.Drawing.Point(418, 55); + this.ButtonRefreshMemoryRange.Name = "ButtonRefreshMemoryRange"; + this.ButtonRefreshMemoryRange.Size = new System.Drawing.Size(68, 23); + this.ButtonRefreshMemoryRange.TabIndex = 19; + this.ButtonRefreshMemoryRange.Text = "Refresh"; + this.ButtonRefreshMemoryRange.UseVisualStyleBackColor = true; + this.ButtonRefreshMemoryRange.Click += new System.EventHandler(this.ButtonRefreshMemoryRange_Click); + // + // IP + // + this.IP.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.IP.Location = new System.Drawing.Point(290, 11); + this.IP.Name = "IP"; + this.IP.Size = new System.Drawing.Size(75, 20); + this.IP.TabIndex = 20; + // + // Port + // + this.Port.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.Port.Location = new System.Drawing.Point(366, 11); + this.Port.Name = "Port"; + this.Port.Size = new System.Drawing.Size(41, 20); + this.Port.TabIndex = 21; + this.Port.Text = "8000"; + // + // Processes + // + this.Processes.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.Processes.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.Processes.DropDownWidth = 200; + this.Processes.FormattingEnabled = true; + this.Processes.Location = new System.Drawing.Point(290, 34); + this.Processes.Name = "Processes"; + this.Processes.Size = new System.Drawing.Size(122, 21); + this.Processes.TabIndex = 22; + // + // MemoryRange + // + this.MemoryRange.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.MemoryRange.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.MemoryRange.FormattingEnabled = true; + this.MemoryRange.Location = new System.Drawing.Point(290, 57); + this.MemoryRange.Name = "MemoryRange"; + this.MemoryRange.Size = new System.Drawing.Size(122, 21); + this.MemoryRange.TabIndex = 23; + this.MemoryRange.SelectedIndexChanged += new System.EventHandler(this.MemoryRange_SelectedIndexChanged); + // + // ProgressBarStatusStrip + // + this.ProgressBarStatusStrip.Location = new System.Drawing.Point(0, 312); + this.ProgressBarStatusStrip.Name = "ProgressBarStatusStrip"; + this.ProgressBarStatusStrip.Size = new System.Drawing.Size(498, 22); + this.ProgressBarStatusStrip.SizingGrip = false; + this.ProgressBarStatusStrip.TabIndex = 24; + // + // ProgressBar + // + this.ProgressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.ProgressBar.Location = new System.Drawing.Point(12, 315); + this.ProgressBar.Name = "ProgressBar"; + this.ProgressBar.Size = new System.Drawing.Size(305, 15); + this.ProgressBar.TabIndex = 25; + // + // GUIUpdateTimer + // + this.GUIUpdateTimer.Enabled = true; + this.GUIUpdateTimer.Tick += new System.EventHandler(this.GUIUpdateTimer_Tick); + // + // LabelCustomRange + // + this.LabelCustomRange.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.LabelCustomRange.Location = new System.Drawing.Point(236, 82); + this.LabelCustomRange.Name = "LabelCustomRange"; + this.LabelCustomRange.Size = new System.Drawing.Size(56, 23); + this.LabelCustomRange.TabIndex = 26; + this.LabelCustomRange.Text = "Start, Size"; + this.LabelCustomRange.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // MemoryStart + // + this.MemoryStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.MemoryStart.Location = new System.Drawing.Point(298, 84); + this.MemoryStart.Name = "MemoryStart"; + this.MemoryStart.Size = new System.Drawing.Size(90, 20); + this.MemoryStart.TabIndex = 27; + // + // MemorySize + // + this.MemorySize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.MemorySize.Location = new System.Drawing.Point(394, 84); + this.MemorySize.Name = "MemorySize"; + this.MemorySize.Size = new System.Drawing.Size(90, 20); + this.MemorySize.TabIndex = 28; + // + // LabelCurrentOperation + // + this.LabelCurrentOperation.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.LabelCurrentOperation.Location = new System.Drawing.Point(323, 315); + this.LabelCurrentOperation.Name = "LabelCurrentOperation"; + this.LabelCurrentOperation.Size = new System.Drawing.Size(163, 15); + this.LabelCurrentOperation.TabIndex = 29; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(498, 334); + this.Controls.Add(this.LabelCurrentOperation); + this.Controls.Add(this.MemorySize); + this.Controls.Add(this.MemoryStart); + this.Controls.Add(this.LabelCustomRange); + this.Controls.Add(this.ProgressBar); + this.Controls.Add(this.ProgressBarStatusStrip); + this.Controls.Add(this.MemoryRange); + this.Controls.Add(this.Processes); + this.Controls.Add(this.Port); + this.Controls.Add(this.IP); + this.Controls.Add(this.ButtonRefreshMemoryRange); + this.Controls.Add(this.ButtonOpenProcess); + this.Controls.Add(this.ButtonConnectDisconnect); + this.Controls.Add(this.LabelMemoryRange); + this.Controls.Add(this.LabelProcess); + this.Controls.Add(this.LabelIPPort); + this.Controls.Add(this.ValuesGrid); + this.Controls.Add(this.LabelResults); + this.Controls.Add(this.ResetButton); + this.Controls.Add(this.SearchButton); + this.Controls.Add(this.ButtonAddResults); + this.Controls.Add(this.ResultsGrid); + this.Controls.Add(this.LabelSearchResults); + this.Controls.Add(this.SearchValue); + this.Controls.Add(this.LabelSearchValue); + this.Controls.Add(this.LabelSearchType); + this.Controls.Add(this.SearchType); + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.MinimumSize = new System.Drawing.Size(514, 372); + this.Name = "MainForm"; + this.Text = "NTR Cheat Tool"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); + this.Load += new System.EventHandler(this.MainForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.ResultsGrid)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.ValuesGrid)).EndInit(); + this.ValuesGridContextMenuStrip.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ComboBox SearchType; + private System.Windows.Forms.Label LabelSearchType; + private System.Windows.Forms.Label LabelSearchValue; + internal System.Windows.Forms.TextBox SearchValue; + private System.Windows.Forms.Label LabelSearchResults; + internal System.Windows.Forms.DataGridView ResultsGrid; + private System.Windows.Forms.Button ButtonAddResults; + private System.Windows.Forms.Button SearchButton; + private System.Windows.Forms.Button ResetButton; + private System.Windows.Forms.Label LabelResults; + private System.Windows.Forms.DataGridView ValuesGrid; + private System.Windows.Forms.DataGridViewTextBoxColumn SearchResultsAddressColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn SearchResultsValueColumn; + private System.Windows.Forms.Label LabelIPPort; + private System.Windows.Forms.Label LabelProcess; + private System.Windows.Forms.Label LabelMemoryRange; + internal System.Windows.Forms.Button ButtonConnectDisconnect; + private System.Windows.Forms.Button ButtonOpenProcess; + private System.Windows.Forms.Button ButtonRefreshMemoryRange; + internal System.Windows.Forms.TextBox IP; + internal System.Windows.Forms.TextBox Port; + private System.Windows.Forms.ComboBox Processes; + private System.Windows.Forms.ComboBox MemoryRange; + private System.Windows.Forms.StatusStrip ProgressBarStatusStrip; + private System.Windows.Forms.ProgressBar ProgressBar; + private System.Windows.Forms.Timer GUIUpdateTimer; + private System.Windows.Forms.DataGridViewCheckBoxColumn ValuesGridLockColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn ValuesGridAddressColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn ValuesGridValueColumn; + private System.Windows.Forms.DataGridViewComboBoxColumn ValuesGridTypeColumn; + private System.Windows.Forms.Label LabelCustomRange; + internal System.Windows.Forms.TextBox MemoryStart; + internal System.Windows.Forms.TextBox MemorySize; + private System.Windows.Forms.Label LabelCurrentOperation; + private System.Windows.Forms.ContextMenuStrip ValuesGridContextMenuStrip; + private System.Windows.Forms.ToolStripMenuItem ValuesGridAddItem; + private System.Windows.Forms.ToolStripMenuItem ValuesGridDeleteItem; + private System.Windows.Forms.ToolStripMenuItem ValuesGridConvertCode; + } +} diff --git a/NTRDebuggerTool/Forms/MainForm.cs b/NTRDebuggerTool/Forms/MainForm.cs new file mode 100644 index 0000000..bc08f4f --- /dev/null +++ b/NTRDebuggerTool/Forms/MainForm.cs @@ -0,0 +1,461 @@ +using NTRDebuggerTool.Remote; +using System; +using System.Linq; +using System.Threading; +using System.Windows.Forms; + +namespace NTRDebuggerTool.Forms +{ + public partial class MainForm : Form + { + internal bool ControlEnabledButtonConnectDisconnect = true; + private bool ControlEnabledIP = true; + private bool ControlEnabledPort = true; + + private bool ControlEnabledProcesses = false; + private bool ControlEnabledButtonOpenProcess = false; + + private bool ControlEnabledMemoryRange = false; + private bool ControlEnabledButtonRefreshMemoryRange = false; + private bool ControlEnabledButtonAddResults = false; + private bool ControlEnabledResetButton = false; + private bool ControlEnabledResultsGrid = false; + internal bool ControlEnabledSearchButton = false; + private bool ControlEnabledSearchType = false; + private bool ControlEnabledSearchValue = false; + private bool ControlEnabledValuesGrid = false; + + private bool ControlEnabledStart = false; + private bool ControlEnabledSize = false; + + private Thread EventDispatcherThread; + + internal string SetConnectText = null; + + internal NTRRemoteConnection NTRConnection; + + private MainFormThreadEventDispatcher ThreadEventDispatcher; + + public MainForm(NTRRemoteConnection NTRConnection) + { + InitializeComponent(); + this.NTRConnection = NTRConnection; + this.ThreadEventDispatcher = new MainFormThreadEventDispatcher(this); + this.EventDispatcherThread = new Thread(new ThreadStart(this.ThreadEventDispatcher.ThreadEventDispatcher)); + this.EventDispatcherThread.Name = "EventDispatcherThread"; + this.EventDispatcherThread.Start(); + } + + private void MainForm_Load(object sender, EventArgs e) + { + this.SearchType.SelectedIndex = 2; + } + + private void UpdateLockedControls() + { + this.ButtonAddResults.Enabled = !NTRConnection.LockControls && this.ControlEnabledButtonAddResults; + this.ButtonConnectDisconnect.Enabled = !NTRConnection.LockControls && this.ControlEnabledButtonConnectDisconnect; + this.ButtonOpenProcess.Enabled = !NTRConnection.LockControls && this.ControlEnabledButtonOpenProcess; + this.ButtonRefreshMemoryRange.Enabled = !NTRConnection.LockControls && this.ControlEnabledButtonRefreshMemoryRange; + this.IP.Enabled = !NTRConnection.LockControls && this.ControlEnabledIP; + this.MemoryRange.Enabled = !NTRConnection.LockControls && this.ControlEnabledMemoryRange; + this.Port.Enabled = !NTRConnection.LockControls && this.ControlEnabledPort; + this.Processes.Enabled = !NTRConnection.LockControls && this.ControlEnabledProcesses; + this.ResetButton.Enabled = !NTRConnection.LockControls && this.ControlEnabledResetButton; + this.ResultsGrid.Enabled = !NTRConnection.LockControls && this.ControlEnabledResultsGrid; + this.SearchButton.Enabled = !NTRConnection.LockControls && this.ControlEnabledSearchButton; + this.SearchType.Enabled = !NTRConnection.LockControls && this.ControlEnabledSearchType; + this.SearchValue.Enabled = !NTRConnection.LockControls && this.ControlEnabledSearchValue; + this.ValuesGrid.Enabled = !NTRConnection.LockControls && this.ControlEnabledValuesGrid; + this.MemoryStart.Enabled = !NTRConnection.LockControls && this.ControlEnabledStart; + this.MemorySize.Enabled = !NTRConnection.LockControls && this.ControlEnabledSize; + } + + internal void SetConnectedControls(bool Enabled) + { + ControlEnabledProcesses = Enabled; + ControlEnabledButtonOpenProcess = Enabled; + } + + internal void SetProcessSelectedControls(bool Enabled) + { + ControlEnabledMemoryRange = Enabled; + ControlEnabledButtonRefreshMemoryRange = Enabled; + ControlEnabledButtonAddResults = Enabled; + ControlEnabledResetButton = Enabled; + ControlEnabledResultsGrid = Enabled; + ControlEnabledSearchButton = Enabled; + ControlEnabledSearchType = Enabled; + ControlEnabledSearchValue = Enabled; + ControlEnabledValuesGrid = Enabled; + } + + internal void SetConnectionControls(bool Enabled) + { + ControlEnabledButtonConnectDisconnect = Enabled; + ControlEnabledIP = Enabled; + ControlEnabledPort = Enabled; + } + + private void GUIUpdateTimer_Tick(object sender, EventArgs e) + { + NTRConnection.SendHeartbeatPacket(); + + if (NTRConnection.ProgressMax > 0) + { + ProgressBar.Maximum = (int)NTRConnection.ProgressMax; + ProgressBar.Value = (int)NTRConnection.Progress; + } + else + { + ProgressBar.Maximum = ProgressBar.Value = 0; + } + + if (NTRConnection.IsProcessListUpdated) + { + NTRConnection.IsProcessListUpdated = false; + string CurrentProcess = Processes.SelectedValue == null ? null : Processes.SelectedValue.ToString(); + Processes.Items.Clear(); + Processes.Items.AddRange(NTRConnection.Processes.ToArray()); + if (CurrentProcess != null && Processes.Items.Contains(CurrentProcess)) + { + Processes.SelectedValue = CurrentProcess; + Processes.SelectedIndex = Processes.Items.IndexOf(CurrentProcess); + } + SetConnectedControls(true); + ControlEnabledButtonConnectDisconnect = true; + NTRConnection.SetCurrentOperationText = ""; + } + + if (NTRConnection.IsMemoryListUpdated) + { + NTRConnection.IsMemoryListUpdated = false; + string CurrentRange = MemoryRange.SelectedValue == null ? "All" : MemoryRange.SelectedValue.ToString(); + MemoryRange.Items.Clear(); + MemoryRange.Items.Add("All"); + foreach (uint Start in NTRConnection.AddressSpaces.Keys) + { + MemoryRange.Items.Add(Utilities.GetStringFromByteArray(BitConverter.GetBytes(Start).Reverse().ToArray()) + "|" + Utilities.GetStringFromByteArray(BitConverter.GetBytes(NTRConnection.AddressSpaces[Start]).Reverse().ToArray())); + } + MemoryRange.Items.Add("Custom"); + if (CurrentRange != null && MemoryRange.Items.Contains(CurrentRange)) + { + MemoryRange.SelectedValue = CurrentRange; + MemoryRange.SelectedIndex = MemoryRange.Items.IndexOf(CurrentRange); + } + SetProcessSelectedControls(true); + SetConnectedControls(true); + NTRConnection.SetCurrentOperationText = ""; + } + + if (NTRConnection.IsMemorySearchFinished) + { + NTRConnection.IsMemorySearchFinished = false; + LabelResults.Text = "Results: " + NTRConnection.AddressesFound.Count; + + if (NTRConnection.AddressesFound.Count < 50) + { + ResultsGrid.Rows.Clear(); + foreach (uint Address in NTRConnection.AddressesFound) + { + int Row = ResultsGrid.Rows.Add(); + ResultsGrid[0, Row].Value = Utilities.GetStringFromByteArray(BitConverter.GetBytes(Address).Reverse().ToArray()); + ResultsGrid[1, Row].Value = SearchValue.Text; + } + } + NTRConnection.SetCurrentOperationText = ""; + } + + if (SetConnectText != null) + { + ButtonConnectDisconnect.Text = SetConnectText; + SetConnectText = null; + } + + LabelCurrentOperation.Text = NTRConnection.SetCurrentOperationText; + + UpdateLockedControls(); + + if (NTRConnection.IsConnected) + { + for (int i = 0; i < ValuesGrid.Rows.Count; ++i) + { + if (ValuesGrid[0, i].Value is string) + { + SetMemory(i); + } + } + } + } + + internal uint GetSearchMemorySize() + { + switch (ThreadEventDispatcher.CurrentSelectedDataType) + { + case 0: //1 Byte + return 1; + case 1: //2 Bytes + return 2; + case 3: //8 Bytes + return 8; + case 4: //Float + return (uint)BitConverter.GetBytes(float.MinValue).Length; + case 5: //Double + return (uint)BitConverter.GetBytes(double.MinValue).Length; + case 6: //Raw Bytes + return (uint)Utilities.GetByteArrayFromByteString(SearchValue.Text).Length; + case 2: //4 Bytes + default: + return 4; + } + } + + private void ResetButton_Click(object sender, EventArgs e) + { + ResultsGrid.Rows.Clear(); + ControlEnabledSearchType = ControlEnabledMemoryRange = true; + if (MemoryRange.SelectedIndex > 0) + { + ControlEnabledStart = ControlEnabledSize = true; + } + + LabelResults.Text = "Results: "; + } + + private void MainForm_FormClosing(object sender, FormClosingEventArgs e) + { + NTRConnection.Disconnect(); + this.EventDispatcherThread.Abort(); + } + + private void ButtonAddResults_Click(object sender, EventArgs e) + { + foreach (DataGridViewRow Row in ResultsGrid.SelectedRows) + { + if (!IsInValues((string)Row.Cells[0].Value)) + { + int RowIndex = ValuesGrid.Rows.Add(); + ValuesGrid[0, RowIndex].Value = null; + ValuesGrid[1, RowIndex].Value = Row.Cells[0].Value; + ValuesGrid[2, RowIndex].Value = SearchValue.Text; + ValuesGrid[3, RowIndex].Value = SearchType.Text; + } + } + } + + private bool IsInValues(String Address) + { + for (int i = 0; i < ValuesGrid.RowCount; ++i) + { + if (((string)ValuesGrid[1, i].Value) == Address) + { + return true; + } + } + return false; + } + + private void ValuesGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0 && e.ColumnIndex == 2) + { + SetMemory(e.RowIndex); + } + } + + private void SetMemory(int RowIndex) + { + if (IsValidMemoryAddress(BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString((string)ValuesGrid[1, RowIndex].Value).Reverse().ToArray(), 0))) + { + switch ((string)ValuesGrid[3, RowIndex].Value) + { + case "1 Byte": //1 Byte + NTRConnection.SendWriteMemoryPacket( + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Processes.Text.Split('|')[0]), 0), + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString((string)ValuesGrid[1, RowIndex].Value).Reverse().ToArray(), 0), + (byte)uint.Parse((string)ValuesGrid[2, RowIndex].Value)); + break; + case "2 Bytes": //2 Bytes + NTRConnection.SendWriteMemoryPacket( + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Processes.Text.Split('|')[0]), 0), + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString((string)ValuesGrid[1, RowIndex].Value).Reverse().ToArray(), 0), + ushort.Parse((string)ValuesGrid[2, RowIndex].Value)); + break; + case "4 Bytes": //4 Bytes + NTRConnection.SendWriteMemoryPacket( + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Processes.Text.Split('|')[0]), 0), + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString((string)ValuesGrid[1, RowIndex].Value).Reverse().ToArray(), 0), + uint.Parse((string)ValuesGrid[2, RowIndex].Value)); + break; + case "8 Bytes": //8 Bytes + NTRConnection.SendWriteMemoryPacket( + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Processes.Text.Split('|')[0]), 0), + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString((string)ValuesGrid[1, RowIndex].Value).Reverse().ToArray(), 0), + ulong.Parse((string)ValuesGrid[2, RowIndex].Value)); + break; + case "Float": //Float + NTRConnection.SendWriteMemoryPacket( + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Processes.Text.Split('|')[0]), 0), + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString((string)ValuesGrid[1, RowIndex].Value).Reverse().ToArray(), 0), + float.Parse((string)ValuesGrid[2, RowIndex].Value)); + break; + case "Double": //Double + NTRConnection.SendWriteMemoryPacket( + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Processes.Text.Split('|')[0]), 0), + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString((string)ValuesGrid[1, RowIndex].Value).Reverse().ToArray(), 0), + double.Parse((string)ValuesGrid[2, RowIndex].Value)); + break; + case "Raw Bytes": //Raw Bytes + NTRConnection.SendWriteMemoryPacket( + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Processes.Text.Split('|')[0]), 0), + BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString((string)ValuesGrid[1, RowIndex].Value).Reverse().ToArray(), 0), + Utilities.GetByteArrayFromByteString((string)ValuesGrid[2, RowIndex].Value)); + break; + } + } + } + + private void ValuesGrid_CellDoubleClick(object sender, DataGridViewCellEventArgs e) + { + ValuesGrid.BeginEdit(true); + } + + private void ValuesGrid_CellLeave(object sender, DataGridViewCellEventArgs e) + { + ValuesGrid.EndEdit(); + } + + private void MemoryRange_SelectedIndexChanged(object sender, EventArgs e) + { + if (MemoryRange.SelectedIndex == 0) + { + this.MemoryStart.Text = this.MemorySize.Text = ""; + ControlEnabledStart = ControlEnabledSize = false; + } + else if (MemoryRange.SelectedIndex == MemoryRange.Items.Count - 1) + { + ControlEnabledStart = ControlEnabledSize = true; + } + else + { + string[] Parts = MemoryRange.Text.Split('|'); + this.MemoryStart.Text = Parts[0]; + this.MemorySize.Text = Parts[1]; + ControlEnabledStart = ControlEnabledSize = false; + } + } + + private void ButtonConnectDisconnect_Click(object sender, EventArgs e) + { + ButtonConnectDisconnect.Enabled = ControlEnabledButtonConnectDisconnect = false; + ThreadEventDispatcher.DispatchConnect = true; + } + + private void ButtonOpenProcess_Click(object sender, EventArgs e) + { + ButtonOpenProcess.Enabled = ControlEnabledButtonOpenProcess = false; + ThreadEventDispatcher.CurrentSelectedProcess = Processes.Text; + ThreadEventDispatcher.DispatchOpenProcess = true; + } + + private void ButtonRefreshMemoryRange_Click(object sender, EventArgs e) + { + ButtonRefreshMemoryRange.Enabled = ControlEnabledButtonRefreshMemoryRange = false; + ThreadEventDispatcher.CurrentSelectedProcess = Processes.Text; + ThreadEventDispatcher.DispatchOpenProcess = true; + } + + private void SearchButton_Click(object sender, EventArgs e) + { + SearchButton.Enabled = ControlEnabledSearchButton = false; + ThreadEventDispatcher.CurrentSelectedDataType = SearchType.SelectedIndex; + ThreadEventDispatcher.CurrentMemoryRange = this.MemoryRange.Text; + ThreadEventDispatcher.DispatchSearch = true; + } + + private void ValuesGridContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) + { + switch (e.ClickedItem.Name) + { + case "ValuesGridDeleteItem": + foreach (DataGridViewRow Row in ValuesGrid.SelectedRows) + { + ValuesGrid.Rows.Remove(Row); + } + foreach (DataGridViewCell Cell in ValuesGrid.SelectedCells) + { + ValuesGrid.Rows.Remove(Cell.OwningRow); + } + break; + case "ValuesGridAddItem": + ValuesGrid.Rows.Add(); + break; + case "ValuesGridConvertCode": + foreach (DataGridViewRow Row in ValuesGrid.SelectedRows) + { + Row.Cells[1].Value = ConvertCode((string)Row.Cells[1].Value); + } + foreach (DataGridViewCell Cell in ValuesGrid.SelectedCells) + { + Cell.OwningRow.Cells[1].Value = ConvertCode((string)Cell.OwningRow.Cells[1].Value); + } + break; + } + } + + private string ConvertCode(string Address) + { + uint OriginalCodeAddress = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Address).Reverse().ToArray(), 0); + uint ConvertedMemoryAddress = OriginalCodeAddress + 0x14000000u; //High memory region + if (IsValidMemoryAddress(ConvertedMemoryAddress)) + { + return Utilities.GetStringFromByteArray(BitConverter.GetBytes(ConvertedMemoryAddress).Reverse().ToArray()); + } + uint ConversionModifier = GetConversionModifier(ConvertedMemoryAddress); + if (ConversionModifier == 0) + { + return Address; + } + uint Offset = ConvertedMemoryAddress - ConversionModifier; + ConvertedMemoryAddress = 0x08000000 + Offset; + if (IsValidMemoryAddress(ConvertedMemoryAddress)) + { + return Utilities.GetStringFromByteArray(BitConverter.GetBytes(ConvertedMemoryAddress).Reverse().ToArray()); + } + ConvertedMemoryAddress = 0x00100000 + Offset; + if (IsValidMemoryAddress(ConvertedMemoryAddress)) + { + return Utilities.GetStringFromByteArray(BitConverter.GetBytes(ConvertedMemoryAddress).Reverse().ToArray()); + } + return Address; + } + + private bool IsValidMemoryAddress(uint Address) + { + foreach (uint RangeStart in NTRConnection.AddressSpaces.Keys) + { + if (Address >= RangeStart && Address <= (RangeStart + NTRConnection.AddressSpaces[RangeStart])) + { + return true; + } + } + return false; + } + + private uint GetConversionModifier(uint Address) + { + uint[] Keys = NTRConnection.AddressSpaces.Keys.ToArray(); + Array.Sort(Keys); + foreach (uint RangeStart in Keys.Reverse()) + { + if (RangeStart <= Address) + { + //This is ugly. + return BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Utilities.GetStringFromByteArray(BitConverter.GetBytes(RangeStart + NTRConnection.AddressSpaces[RangeStart]).Reverse().ToArray()).Substring(0, 3).PadRight(8, '0')).Reverse().ToArray(), 0) + 0x00100000u; + } + } + return 0; + } + + } +} diff --git a/NTRDebuggerTool/Forms/MainForm.resx b/NTRDebuggerTool/Forms/MainForm.resx new file mode 100644 index 0000000..caaea75 --- /dev/null +++ b/NTRDebuggerTool/Forms/MainForm.resx @@ -0,0 +1,314 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + + 335, 17 + + + 17, 17 + + + 192, 17 + + + + + AAABAAEAMDAAAAEAIACoJQAAFgAAACgAAAAwAAAAYAAAAAEAIAAAAAAAAEgAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFFRUULPz8/DEVFRQsAAAABAAAAAAAA + AAAAAAABcllMFHJbT0NxW05+b1pNtG9bTtduWk3vclxO/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ZG/8HBwP/r5+X/taqi/3lkVv99aFv/dmFT/66jnP/x8fD/8vLx/8zEv/+EcGT/gW1g/97Z + 1f////////////39/f/l4+H/opSM/29bT/9MSUf/RkZG/01JR/9yXE//c11P/3NdT/9zXU//cFtN/3Bb + Tv9wW03/c11P/3NdT/9zXU//c11P/3FdT+5zXU/+c11P/3NdT/9zXU//c11P/3NdT/9zXU//c11P/3Nd + T/9yXE7/fmpd/2NiYf9GRkb/cnJy//39/f//////7Onn/4NwZP+gkYj/oJGI/3lkVv/DvLf/9PT0//T0 + 9P/X0c3/e2ZZ/66hmf/////////////////9/f3/7ezr/6eblP9jVUv/RkZG/0ZGRv9kVUz/c11P/3Nd + T/9zXU//c11P/3BbTf9wW07/cFtN/3NdT/9zXU//c11P/3NdT/5zXU//c11P/3NdT/9zXU//c11P/3Nd + T/9zXU//c11P/3NdT/9zXU//aVdL/0ZGRv9GRkb/xsbG//T09P/9/f3/9PLx/4x6b/+aioD/5uLg/458 + cP+Bb2L/1dDO//T09P/u7ez/koF3/5OCeP/39vX//////////////////f39/+vp6P+cjoX/S0dF/0ZG + Rv9SS0f/c11P/3NdT/9zXU//c11P/3NdT/9wW03/cFtO/3BbTf9zXU//c11P/3NdT/9zXU//c11P/3Nd + T/9zXU//c11P/3NdT/9zXU//c11P/3NdT/9zXU//XVFK/0ZGRv9TUlL/8/Pz//T09P/09PT/+/v7/56P + hf+HdGj/8O7t/9nTz/9/al3/inlt/762sP/RzMj/kYF2/4t6bv/08vH///////////////////////39 + /f/g3Nr/aF9Z/0ZGRv9HRkb/cVxO/3NdT/9zXU//c11P/3NdT/9zXU//cFtN/3BbTv9wW03/c11P/3Nd + T/9zXU/+c11P/3NdT/9zXU//c11P/3NdT/9yXE//clxO/3NdT/9zXU//VE1I/0ZGRv9jXVn/9vX0//T0 + 9P/09PT/9PT0/7mup/94Y1b/29XS///////Kwbz/h3Ro/3ZhU/91YVT/cl1R/6KVjf/7+vr//f38//Ty + 8f/5+Pf////////////9/f3/qqSg/0ZGRv9GRkb/aFdM/3NdT/9zXU//c11P/3NdT/9zXU//c11P/3Bb + Tf9wW07/cFtN/3NdT/5xXU/uc11P/3NdT/9zXU//c11P/3NdT/9yXE//cVxO/3JcTv9zXU//TEhF/0ZG + Rv9eU03/y8O+//39/f/09PT/9PT0/9DLyP95Y1b/t6uk///////+/v7/7ero/9PMyP/Bt7H/wLiz/+Xk + 4v/e2tj/p5mR/458cf+YiH7/zcXA//z7+///////7ezs/0ZGRv9GRkb/YVNL/3NdT/9zXU//c11P/3Nd + T/9zXU//c11P/3NdT/9wW03/cFtO/21aTO9xXU/Vc11P/3NdT/9zXU//c11P/3NdT/9yXE//clxP/3Fc + Tv9yXE7/SkdF/0ZGRv9eUkr/kYB1//Hv7v/9/f3/9PT0/+ro5/+MfHH/i3lu//Hv7f////////////// + /////////f39/+jm5f+Rgnf/bVhL/3FbTf9xWkz/e2ZZ/9LLx////////////0RERP9GRkb/XVFJ/3Bb + Tf9zXU//c11P/3NdT/9zXU//c11P/3NdT/9zXU//cFtN/25bTtdzXU+xc11P/3NdT/9zXU//c11P/3Nd + T/9zXU//cVxO/3BbTv9xW07/SkZE/0ZGRv9fUkv/dF5Q/7uxqv/+/v7//f39//T09P+5sKr/cV5Q/8S7 + tf///////////////////////////9PNyP9zX1H/cFtO/3BbTf9zXU//cFpM/6aYj//+/f3//f39/0ZG + Rv9GRkb/XlFJ/3BbTv9wW03/c11P/3NdT/9zXU//c11P/3NdT/9zXU//c11P/21aTbVyXU99cVtN/XNd + T/9zXU//c11P/3NdT/9zXU//clxO/3FcTv9wW07/TklG/0ZGRv9aUEn/clxO/39rX//Sy8f//v7+//39 + /f/m4+L/iHht/4Z0av/q5+X//////////////////////87Hwv90XlD/cFtN/3BbTv9wW03/cFpM/6GS + if/8/Pz/6enp/0ZGRv9GRkb/ZVZM/3BbTf9wW07/cFtN/3NdT/9zXU//c11P/3NdT/9zXU//cVtN/XFd + Tn5yW09DcV1P7nNdT/9zXU//c11P/3NdT/9zXU//c11P/3JcTv9xW07/Vk1I/0ZGRv9QS0f/c11P/3Jc + Tv+AbF//saSc/9HKxf/c19T/qJuU/3BbTv+ilY3/9/b1/////////////////+rn5f+IdWn/cVpM/29a + TP9vWk3/cVxO/8K4sv//////xcXF/0ZGRv9GRkb/eGdc/3JcTv9wW03/cFtO/3BbTf9zXU//c11P/3Nd + T/9zXU//cV1P7nJbT0NtYVQVc11NxXNdT/9zXU//c11P/3NdT/9zXU//c11P/3NdT/9yXE7/YFNL/0ZG + Rv9EQ0P/b1pN/3NdT/9yXE7/clxN/3RfUf95ZFf/eWRW/3BbTf9zXlH/raOb//j39/////////////// + ///RycX/jXtv/3tnWf9+a1//rKGZ/+ro5//p5uP/h4aF/0ZGRv9XV1f/l4d8/3FbTf9zXU//cFtN/3Bb + Tv9wW03/c11P/3NdT/9zXU//c11NxW1hVBUAAAAAc11PgHNdT/9zXU//c11P/3NdT/9zXU//c11P/3Nd + T/9zXU//cFtO/0RDQ/9GRkb/XVFK/3NdT/9zXU//c11P/3NdT/9zXU//c11P/3NdT/9vWkz/c19S/6qf + l//z8vH////////////+/v7/8O7s/+Db2P/n4+H/8/Ly/8fBvP96aF3/RkVE/0ZGRv+UlJT/sKSc/3Fb + TP9zXU//c11P/3BbTf9wW07/cFtN/3NdT/9zXU//c11PgAAAAAAAAAAAc19QM3FbT+dzXU//c11P/3Nd + T/9zXU//c11P/3NdT/9zXU//c11P/1VNSP9GRkb/SEZF/21aTf9zXU//c11P/3NdT/9zXU//c11P/3Nd + T/9zXU//cFpM/3FcT/+YioH/49/c//7+/v///////////////////////f39/62imv9XTEb/RkZG/0ZG + Rv/e3t7/w7q0/3NdT/9zXU//c11P/3NdT/9wW03/cFtO/3BbTf9xW0/nc19QMwAAAAAAAAAAZmZmBXNd + Tp9zXU//c11P/3NdT/9zXU//c11P/3NdT/9zXU//c11P/2xZTf9EQ0P/RkZG/1RNR/9wW03/c11P/3Nd + T/9zXU//c11P/3NdT/9zXU//c11P/3BbT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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABcllMFHJbT0NyXU99c11PsXFdT9VxXU/uc11P/nNd + T/9zXU//c11P/nFdT+5xXU/Vc11PsXJdT31yW09DcllMFAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//+AD//8AAP/+AAB/8QAA//gAAB/g + AAD/4AAAB8EAAP/AAAADgQAA/4AAAAEDAAD+AAAAAAcAAPwAAAAADwAA/AAAAAAfAAD4AAAAAB8AAPAA + AAAADwAA4AAAAAAHAADgAAAAAAcAAMAAAAAAAwAAwAAAAAADAACAAAAAAAEAAIAAAAAAAQAAgAAAAAAB + AACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAABAACAAAAAAAEAAIAAAAAAAQAAgAAAAAAB + AADAAAAAAAMAAMAAAAAAAwAA4AAAAAAHAADgAAAAAAcAAPAAAAAADwAA+AAAAAAfAAD8AAAAAD8AAPwA + AAAAPwAA/gAAAAB/AAD/gAAAAf8AAP/AAAAD/wAA/+AAAAf/AAD/+AAAH/8AAP/+AAB//wAA///gB/// + AAA= + + + \ No newline at end of file diff --git a/NTRDebuggerTool/Forms/MainFormThreadEventDispatcher.cs b/NTRDebuggerTool/Forms/MainFormThreadEventDispatcher.cs new file mode 100644 index 0000000..8b7ff0d --- /dev/null +++ b/NTRDebuggerTool/Forms/MainFormThreadEventDispatcher.cs @@ -0,0 +1,134 @@ +using System; +using System.Linq; +using System.Threading; + +namespace NTRDebuggerTool.Forms +{ + class MainFormThreadEventDispatcher + { + internal bool DispatchConnect = false; + internal bool DispatchOpenProcess = false; + internal bool DispatchSearch = false; + + internal string CurrentSelectedProcess = ""; + internal string CurrentMemoryRange = ""; + internal int CurrentSelectedDataType = 2; + private MainForm Form; + + internal MainFormThreadEventDispatcher(MainForm Form) + { + // TODO: Complete member initialization + this.Form = Form; + } + + internal void ThreadEventDispatcher() + { + while (true) + { + if (DispatchConnect) + { + DispatchConnect = false; + DoConnect(); + } + if (DispatchOpenProcess) + { + DispatchOpenProcess = false; + DoOpenProcess(); + } + if (DispatchSearch) + { + DispatchSearch = false; + DoSearch(); + } + + Thread.Sleep(100); + } + } + + private void DoConnect() + { + if (Form.NTRConnection.IsConnected || Form.ButtonConnectDisconnect.Text == "Disconnect") + { + Form.NTRConnection.SetCurrentOperationText = "Disconnecting"; + Form.NTRConnection.Disconnect(); + Form.SetConnectedControls(false); + Form.SetProcessSelectedControls(false); + Form.SetConnectText = "Connect"; + Form.ControlEnabledButtonConnectDisconnect = true; + Form.NTRConnection.SetCurrentOperationText = ""; + } + else + { + Form.SetConnectionControls(false); + Form.NTRConnection.SetCurrentOperationText = "Connecting"; + Form.NTRConnection.IP = Form.IP.Text; + Form.NTRConnection.Port = short.Parse(Form.Port.Text); + if (Form.NTRConnection.Connect()) + { + Form.SetConnectText = "Disconnect"; + Form.NTRConnection.SetCurrentOperationText = "Fetching Processes"; + Form.NTRConnection.SendListProcessesPacket(); + } + else + { + Form.SetConnectionControls(true); + Form.NTRConnection.SetCurrentOperationText = ""; + } + } + } + + private void DoOpenProcess() + { + Form.SetConnectedControls(false); + Form.NTRConnection.SetCurrentOperationText = "Fetching Memory Ranges"; + Form.NTRConnection.SendReadMemoryAddressesPacket(CurrentSelectedProcess.Split('|')[0]); + } + + private void DoSearch() + { + Form.NTRConnection.SetCurrentOperationText = "Searching Memory"; + uint ProcessID = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(CurrentSelectedProcess.Split('|')[0]), 0); + uint StartAddress, MemorySize; + if (CurrentMemoryRange.Equals("All")) + { + StartAddress = MemorySize = uint.MaxValue; + } + else + { + StartAddress = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Form.MemoryStart.Text).Reverse().ToArray(), 0); + MemorySize = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Form.MemorySize.Text).Reverse().ToArray(), 0); + } + + if (Form.ResultsGrid.Rows.Count > 0 || Form.NTRConnection.AddressesFound.Count > 0) + { + MemorySize = Form.GetSearchMemorySize(); + } + + switch (CurrentSelectedDataType) + { + case 0: //1 Byte + Form.NTRConnection.SendReadMemoryPacket(ProcessID, StartAddress, MemorySize, (byte)uint.Parse(Form.SearchValue.Text)); + break; + case 1: //2 Bytes + Form.NTRConnection.SendReadMemoryPacket(ProcessID, StartAddress, MemorySize, ushort.Parse(Form.SearchValue.Text)); + break; + case 2: //4 Bytes + Form.NTRConnection.SendReadMemoryPacket(ProcessID, StartAddress, MemorySize, uint.Parse(Form.SearchValue.Text)); + break; + case 3: //8 Bytes + Form.NTRConnection.SendReadMemoryPacket(ProcessID, StartAddress, MemorySize, ulong.Parse(Form.SearchValue.Text)); + break; + case 4: //Float + Form.NTRConnection.SendReadMemoryPacket(ProcessID, StartAddress, MemorySize, float.Parse(Form.SearchValue.Text)); + break; + case 5: //Double + Form.NTRConnection.SendReadMemoryPacket(ProcessID, StartAddress, MemorySize, double.Parse(Form.SearchValue.Text)); + break; + case 6: //Raw Bytes + Form.NTRConnection.SendReadMemoryPacket(ProcessID, StartAddress, MemorySize, Utilities.GetByteArrayFromByteString(Form.SearchValue.Text)); + break; + } + Form.ControlEnabledSearchButton = true; + } + } +} diff --git a/NTRDebuggerTool/NTRDebuggerTool.csproj b/NTRDebuggerTool/NTRDebuggerTool.csproj new file mode 100644 index 0000000..a0e2733 --- /dev/null +++ b/NTRDebuggerTool/NTRDebuggerTool.csproj @@ -0,0 +1,94 @@ + + + + + Debug + AnyCPU + {86AF1318-9584-4CDE-93BC-C2F0DCF958C5} + WinExe + Properties + NTRDebuggerTool + NTRDebuggerTool + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + + + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + \ No newline at end of file diff --git a/NTRDebuggerTool/Program.cs b/NTRDebuggerTool/Program.cs new file mode 100644 index 0000000..044c61e --- /dev/null +++ b/NTRDebuggerTool/Program.cs @@ -0,0 +1,21 @@ +using NTRDebuggerTool.Forms; +using NTRDebuggerTool.Remote; +using System; +using System.Windows.Forms; + +namespace NTRDebuggerTool +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm(new NTRRemoteConnection())); + } + } +} diff --git a/NTRDebuggerTool/Properties/AssemblyInfo.cs b/NTRDebuggerTool/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e99ad0d --- /dev/null +++ b/NTRDebuggerTool/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("NTRDebuggerTool")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("NTRDebuggerTool")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("290cd39f-c191-4212-9985-0584c9200acc")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.7.0.0")] +[assembly: AssemblyFileVersion("0.7.0.0")] diff --git a/NTRDebuggerTool/Properties/Resources.Designer.cs b/NTRDebuggerTool/Properties/Resources.Designer.cs new file mode 100644 index 0000000..032f2d9 --- /dev/null +++ b/NTRDebuggerTool/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace NTRDebuggerTool.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NTRDebuggerTool.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/NTRDebuggerTool/Properties/Resources.resx b/NTRDebuggerTool/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/NTRDebuggerTool/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/NTRDebuggerTool/Properties/Settings.Designer.cs b/NTRDebuggerTool/Properties/Settings.Designer.cs new file mode 100644 index 0000000..59f1014 --- /dev/null +++ b/NTRDebuggerTool/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace NTRDebuggerTool.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/NTRDebuggerTool/Properties/Settings.settings b/NTRDebuggerTool/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/NTRDebuggerTool/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs b/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs new file mode 100644 index 0000000..36cb98e --- /dev/null +++ b/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs @@ -0,0 +1,247 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; + +namespace NTRDebuggerTool.Remote +{ + class NTRPacketReceiverThread + { + private NTRRemoteConnection NTRConnection; + + internal NTRPacketReceiverThread(NTRRemoteConnection NTRConnection) + { + this.NTRConnection = NTRConnection; + } + + #region Receiving Packets + + internal void ThreadReceivePackets() + { + byte[] Buffer = new byte[84]; + uint[] Arguments = new uint[16]; + uint Magic, Sequence, Type, Command; + + while (true) + { + try + { + Array.Clear(Buffer, 0, Buffer.Length); + int PacketSize = ReadBasePacket(Buffer, true); + if (PacketSize == 0) + { + break; + } + if (PacketSize < Buffer.Length && ShouldSkipPacket(Buffer)) + { + continue; + } + int t = 0; + Magic = BitConverter.ToUInt32(Buffer, t); + Sequence = BitConverter.ToUInt32(Buffer, t += 4); + Type = BitConverter.ToUInt32(Buffer, t += 4); + Command = BitConverter.ToUInt32(Buffer, t += 4); + for (int i = 0; i < Arguments.Length; i++) + { + Arguments[i] = BitConverter.ToUInt32(Buffer, t += 4); + } + uint ExtraDataLength = BitConverter.ToUInt32(Buffer, t += 4); + + if (Magic != 0x12345678) + { + break; + } + + if (ExtraDataLength > 0) + { + ReadExtraData(Command, Sequence, ExtraDataLength); + } + + if (Type == PacketType.General && Command == PacketCommand.Heartbeat) + { + this.NTRConnection.CanSendHeartbeat = true; + } + } + catch (Exception e) + { + System.Console.WriteLine(e); + break; + } + } + + this.NTRConnection.Disconnect(); + } + + private bool ShouldSkipPacket(byte[] Buffer) + { + if (System.Text.Encoding.Default.GetString(Buffer).Equals("finished")) //Finshed writing memory + { + return true; + } + return false; + } + + int ReadBasePacket(byte[] Buffer) + { + return ReadBasePacket(Buffer, false); + } + + int ReadBasePacket(byte[] Buffer, bool MainLoop) + { + int Read = 0; + int Position = this.NTRConnection.Client.GetStream().Read(Buffer, 0, Buffer.Length); + if (Position == 0) + { + return 0; + } + if (MainLoop) + { + if (ShouldSkipPacket(Buffer)) + { + return Read; + } + } + while (Position < Buffer.Length) + { + if (this.NTRConnection.ProgressMax > 0) + { + this.NTRConnection.Progress = (uint)Position; + } + Read = this.NTRConnection.Client.GetStream().Read(Buffer, Position, Buffer.Length - Position); + if (Read == 0) + { + return 0; + } + Position += Read; + } + return Position; + } + + private void ReadExtraData(uint Command, uint Sequence, uint DataLength) + { + if (Sequence == this.NTRConnection.LastListProcessesSequence + 1000) + { + ReadProcessesPacket(DataLength); + } + else if (Sequence == this.NTRConnection.LastListMemoryRegionsSequence + 1000) + { + ReadAddressesPacket(DataLength); + } + else if (Sequence == this.NTRConnection.LastReadMemorySequence) //For some reason, not +1000? + { + ReadMemoryPacket(DataLength); + } + else + { + switch (Command) + { + default: + ReadBasePacket(new byte[DataLength]); + break; + } + } + } + + private void ReadProcessesPacket(uint DataLength) + { + this.NTRConnection.Processes.Clear(); + byte[] Buffer = new byte[DataLength]; + ReadBasePacket(Buffer); + string BufferText = System.Text.Encoding.Default.GetString(Buffer); + BufferText = BufferText.Replace("rtRecvSocket failed: 00000000", ""); + //Line format: + //pid: 0x00000029, pname: ro, tid: 0004013000003702, kpobj: fff7b5f8 + //Split on comma, then split KV on `: `, trim both key and value + foreach (string Line in BufferText.Split('\n')) + { + if (!Line.StartsWith("pid")) + { + continue; + } + string[] KVStrings = Line.Split(','); + string ProcessID = KVStrings[0].Split(new String[] { ": " }, StringSplitOptions.None)[1].Trim().Substring(2); + string ProcessName = KVStrings[1].Split(new String[] { ": " }, StringSplitOptions.None)[1].Trim(); + string TitleID = KVStrings[2].Split(new String[] { ": " }, StringSplitOptions.None)[1].Trim(); + + this.NTRConnection.Processes.Add(ProcessID + "|" + ProcessName + "," + TitleID); + } + + if (this.NTRConnection.Processes.Count > 0) + { + this.NTRConnection.IsProcessListUpdated = true; + } + } + + private void ReadAddressesPacket(uint DataLength) + { + Dictionary AddressSpaces = new Dictionary(); + byte[] Buffer = new byte[DataLength]; + ReadBasePacket(Buffer); + string BufferText = System.Text.Encoding.Default.GetString(Buffer); + BufferText = BufferText.Replace("rtRecvSocket failed: 00000000", ""); + //Line format: + //00100000 - 0093cfff , size: 0083d000 + //Split on comma, then split on ` - ` for address start and `: ` for size + foreach (string Line in BufferText.Split('\n')) + { + if (!Line.Contains("size")) + { + continue; + } + string[] Parts = Line.Split(new String[] { " , " }, StringSplitOptions.None); + uint Start = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Parts[0].Split(new String[] { " - " }, StringSplitOptions.None)[0].Trim()).Reverse().ToArray(), 0); + uint Size = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Parts[1].Split(new String[] { ": " }, StringSplitOptions.None)[1].Trim()).Reverse().ToArray(), 0); + + AddressSpaces.Add(Start, Size); + } + + if (AddressSpaces.Count > 0) + { + this.NTRConnection.AddressSpaces = new ReadOnlyDictionary(AddressSpaces); + + this.NTRConnection.IsMemoryListUpdated = true; + } + } + + private void ReadMemoryPacket(uint DataLength) + { + this.NTRConnection.ProgressMax = DataLength * 2; + if (DataLength < this.NTRConnection.SearchBytes.Length) + { + this.NTRConnection.MemoryReadAddress = uint.MaxValue; + return; + } + + byte[] Buffer = new byte[DataLength]; + byte[] TemporaryBuffer = new byte[this.NTRConnection.SearchBytes.Length]; + ReadBasePacket(Buffer); + + this.NTRConnection.SetCurrentOperationText = "Scanning Read Memory"; + + uint RealAddress; + + for (uint i = 0; i <= DataLength - this.NTRConnection.SearchBytes.Length; ++i) + { + this.NTRConnection.Progress = DataLength + i; + RealAddress = (uint)(this.NTRConnection.MemoryReadAddress + i); + if (this.NTRConnection.NewSearch || this.NTRConnection.AddressesFound.Contains(RealAddress)) + { + Array.Copy(Buffer, i, TemporaryBuffer, 0, TemporaryBuffer.Length); + if (!System.Linq.Enumerable.SequenceEqual(this.NTRConnection.SearchBytes, TemporaryBuffer)) + { + this.NTRConnection.AddressesFound.Remove(RealAddress); + } + else if (!this.NTRConnection.AddressesFound.Contains(RealAddress)) + { + this.NTRConnection.AddressesFound.Add(RealAddress); + } + } + } + + this.NTRConnection.MemoryReadAddress = uint.MaxValue; + this.NTRConnection.ProgressMax = this.NTRConnection.Progress = 0; + } + + #endregion + } +} diff --git a/NTRDebuggerTool/Remote/NTRRemoteConnection.cs b/NTRDebuggerTool/Remote/NTRRemoteConnection.cs new file mode 100644 index 0000000..0639289 --- /dev/null +++ b/NTRDebuggerTool/Remote/NTRRemoteConnection.cs @@ -0,0 +1,353 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Net.Sockets; +using System.Threading; + +namespace NTRDebuggerTool.Remote +{ + public class NTRRemoteConnection + { + #region Members + + public String IP { get; set; } + public Int16 Port { get; set; } + public List AddressesFound = new List(); + + public ReadOnlyDictionary AddressSpaces; + + public uint Progress = 0; + public uint ProgressMax = 0; + + internal uint MemoryReadAddress = 0; + internal byte[] SearchBytes; + + internal bool NewSearch = true; + + internal TcpClient Client; + + private uint Sequence = 0u; + + private object SendLock = new object(); + private object ReceiveLock = new object(); + public bool LockControls = false; + public bool IsConnected = false; + public bool IsProcessListUpdated = false; + public bool IsMemoryListUpdated = false; + + private long LastHeartbeat = 0; + + internal uint LastListProcessesSequence = 0u; + internal uint LastListMemoryRegionsSequence = 0u; + internal uint LastReadMemorySequence = 0u; + + private Thread PacketThread = null; + internal bool CanSendHeartbeat = true; + public List Processes = new List(); + public bool IsMemorySearchFinished = false; + + public string SetCurrentOperationText = ""; + private NTRPacketReceiverThread PacketReceiverThread; + + #endregion + + #region Constructor + + public NTRRemoteConnection() + { + this.PacketReceiverThread = new NTRPacketReceiverThread(this); + } + + #endregion + + #region Other Methods + + public void ResetSearch() + { + NewSearch = true; + AddressesFound.Clear(); + } + + #endregion + + #region Connection Management + + public bool Connect() + { + if (Client != null) + { + bool Disconnected = false; + try + { + if (Client.Connected) + { + if (!SendHeartbeatPacket(true)) + { + Disconnected = true; + } + } + else + { + Disconnected = true; + } + } + catch (Exception e) + { + System.Console.WriteLine(e); + Disconnected = true; + } + if (Disconnected) + { + Disconnect(); + } + } + if (Client == null) + { + try + { + Client = new TcpClient(); + Client.NoDelay = true; + Client.Connect(IP, Port); + PacketThread = new Thread(new ThreadStart(this.PacketReceiverThread.ThreadReceivePackets)); + PacketThread.Name = "ReadPacketsThread"; + PacketThread.Start(); + IsConnected = true; + CanSendHeartbeat = true; + SendHeartbeatPacket(true); + } + catch (Exception e) + { + System.Console.WriteLine(e); + return false; + } + } + return true; + } + + public void Disconnect() + { + try + { + Client.Close(); + PacketThread.Abort(); + } + catch (Exception e) + { + System.Console.WriteLine(e); + } + Client = null; + IsConnected = false; + } + + #endregion + + #region Sending Packets + + public void SendWriteMemoryPacket(uint ProcessID, uint Address, byte Value) + { + SendWriteMemoryPacket(ProcessID, Address, new byte[] { Value }); + } + + public void SendWriteMemoryPacket(uint ProcessID, uint Address, ushort Value) + { + SendWriteMemoryPacket(ProcessID, Address, BitConverter.GetBytes(Value)); + } + + public void SendWriteMemoryPacket(uint ProcessID, uint Address, uint Value) + { + SendWriteMemoryPacket(ProcessID, Address, BitConverter.GetBytes(Value)); + } + + public void SendWriteMemoryPacket(uint ProcessID, uint Address, ulong Value) + { + SendWriteMemoryPacket(ProcessID, Address, BitConverter.GetBytes(Value)); + } + + public void SendWriteMemoryPacket(uint ProcessID, uint Address, float Value) + { + SendWriteMemoryPacket(ProcessID, Address, BitConverter.GetBytes(Value)); + } + + public void SendWriteMemoryPacket(uint ProcessID, uint Address, double Value) + { + SendWriteMemoryPacket(ProcessID, Address, BitConverter.GetBytes(Value)); + } + + public void SendWriteMemoryPacket(uint ProcessID, uint Address, byte[] Values) + { + this.SendPacket(PacketType.GeneralMemory, PacketCommand.Write, new uint[] { BitConverter.ToUInt32(BitConverter.GetBytes(ProcessID).Reverse().ToArray(), 0), Address, (uint)Values.Length }, Values); + } + + public void SendReadMemoryPacket(uint ProcessID, uint Address, uint Size, byte Value) + { + SendReadMemoryPacket(ProcessID, Address, Size, new byte[] { Value }); + } + + public void SendReadMemoryPacket(uint ProcessID, uint Address, uint Size, ushort Value) + { + SendReadMemoryPacket(ProcessID, Address, Size, BitConverter.GetBytes(Value)); + } + + public void SendReadMemoryPacket(uint ProcessID, uint Address, uint Size, uint Value) + { + SendReadMemoryPacket(ProcessID, Address, Size, BitConverter.GetBytes(Value)); + } + + public void SendReadMemoryPacket(uint ProcessID, uint Address, uint Size, ulong Value) + { + SendReadMemoryPacket(ProcessID, Address, Size, BitConverter.GetBytes(Value)); + } + + public void SendReadMemoryPacket(uint ProcessID, uint Address, uint Size, float Value) + { + SendReadMemoryPacket(ProcessID, Address, Size, BitConverter.GetBytes(Value)); + } + + public void SendReadMemoryPacket(uint ProcessID, uint Address, uint Size, double Value) + { + SendReadMemoryPacket(ProcessID, Address, Size, BitConverter.GetBytes(Value)); + } + + public void SendReadMemoryPacket(uint ProcessID, uint AddressSpace, uint Size, byte[] SearchValue) + { + this.SearchBytes = SearchValue; + this.LockControls = true; + if (AddressesFound.Count > 0) + { + //Clone the list to an array to prevent concurrent modification + foreach (uint Address in AddressesFound.ToArray()) + { + SendReadMemoryPacket(ProcessID, Address, Size); + } + } + else if (AddressSpace == uint.MaxValue) + { + foreach (uint ActualAddressSpace in AddressSpaces.Keys) + { + SendReadMemoryPacket(ProcessID, ActualAddressSpace, AddressSpaces[ActualAddressSpace]); + } + } + else + { + SendReadMemoryPacket(ProcessID, AddressSpace, Size); + } + IsMemorySearchFinished = true; + this.LockControls = false; + } + + private void SendReadMemoryPacket(uint ProcessID, uint Address, uint Size) + { + SetCurrentOperationText = "Searching Memory " + Utilities.GetStringFromByteArray(BitConverter.GetBytes(Address)); + this.MemoryReadAddress = Address; + this.SendPacket(PacketType.General, PacketCommand.Read, new uint[] { BitConverter.ToUInt32(BitConverter.GetBytes(ProcessID).Reverse().ToArray(), 0), Address, Size }); + while (MemoryReadAddress != uint.MaxValue) + { + Thread.Sleep(100); + } + SetCurrentOperationText = ""; + } + public void SendListProcessesPacket() + { + this.SendPacket(PacketType.General, PacketCommand.ListProcesses, null); + } + + public void SendReadMemoryAddressesPacket(string ProcessID) + { + uint ActualProcessID = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(ProcessID).Reverse().ToArray(), 0); + this.SendPacket(PacketType.General, PacketCommand.ListAddresses, new uint[1] { ActualProcessID }); + } + + public void sendReloadPacket() + { + this.SendPacket(PacketType.General, PacketCommand.Reload, null); + } + + public void SendHelloPacket() + { + this.SendPacket(PacketType.General, PacketCommand.Hello, null); + } + + public bool SendHeartbeatPacket() + { + return SendHeartbeatPacket(false); + } + + public bool SendHeartbeatPacket(bool IsConnecting) + { + if (IsConnecting || this.Client != null) + { + if (IsConnecting || this.Client.Connected) + { + if (CanSendHeartbeat && LastHeartbeat < (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - 30000) + { + CanSendHeartbeat = false; + LastHeartbeat = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; + try + { + SendPacket(PacketType.General, PacketCommand.Heartbeat, null); + return true; + } + catch (Exception e) + { + System.Console.WriteLine(e); + } + } + } + } + return false; + } + + private void SendPacket(uint Type, uint Command, uint[] Arguments) + { + SendPacket(Type, Command, Arguments, new byte[0]); + } + + private void SendPacket(uint Type, uint Command, uint[] Arguments, byte[] AdditionalData) + { + lock (this.SendLock) + { + int num = 0; + byte[] array = new byte[84]; + Array.Clear(array, 0, 84); //Force to zero + BitConverter.GetBytes(0x12345678).CopyTo(array, num); + BitConverter.GetBytes(this.Sequence += 1000u).CopyTo(array, num += 4); + SetPacketSequence(Type, Command); + BitConverter.GetBytes(Type).CopyTo(array, num += 4); + BitConverter.GetBytes(Command).CopyTo(array, num += 4); + if (Arguments != null) + { + for (int i = 0; i < 16 && i < Arguments.Length; i++) + { + BitConverter.GetBytes(Arguments[i]).CopyTo(array, num += 4); + } + } + + BitConverter.GetBytes(AdditionalData.Length).CopyTo(array, array.Length - 4); + this.Client.GetStream().Write(array, 0, array.Length); + if (AdditionalData.Length > 0u) + { + this.Client.GetStream().Write(AdditionalData, 0, AdditionalData.Length); + } + } + } + + private void SetPacketSequence(uint Type, uint Command) + { + if (Type == PacketType.General && Command == PacketCommand.ListProcesses) + { + LastListProcessesSequence = Sequence; + } + else if (Type == PacketType.General && Command == PacketCommand.ListAddresses) + { + LastListMemoryRegionsSequence = Sequence; + } + else if (Type == PacketType.General && Command == PacketCommand.Read) + { + LastReadMemorySequence = Sequence; + } + } + + #endregion + } +} diff --git a/NTRDebuggerTool/Remote/PacketCommand.cs b/NTRDebuggerTool/Remote/PacketCommand.cs new file mode 100644 index 0000000..f0127fb --- /dev/null +++ b/NTRDebuggerTool/Remote/PacketCommand.cs @@ -0,0 +1,17 @@ + +namespace NTRDebuggerTool.Remote +{ + static class PacketCommand + { + //General + public const uint Heartbeat = 0u; + public const uint Hello = 3u; + public const uint Reload = 4u; + public const uint ListProcesses = 5u; + + //Memory + public const uint ListAddresses = 8u; + public const uint Read = 9u; + public const uint Write = 10u; + } +} diff --git a/NTRDebuggerTool/Remote/PacketType.cs b/NTRDebuggerTool/Remote/PacketType.cs new file mode 100644 index 0000000..958d122 --- /dev/null +++ b/NTRDebuggerTool/Remote/PacketType.cs @@ -0,0 +1,9 @@ + +namespace NTRDebuggerTool.Remote +{ + static class PacketType + { + public const uint General = 0u; + public const uint GeneralMemory = 1u; + } +} diff --git a/NTRDebuggerTool/Utilities.cs b/NTRDebuggerTool/Utilities.cs new file mode 100644 index 0000000..909e57b --- /dev/null +++ b/NTRDebuggerTool/Utilities.cs @@ -0,0 +1,22 @@ +using System; +using System.Linq; + +namespace NTRDebuggerTool +{ + static class Utilities + { + public static byte[] GetByteArrayFromByteString(string Text) + { + return Enumerable.Range(0, Text.Length) + .Where(x => x % 2 == 0) + .Select(x => Convert.ToByte(Text.Substring(x, 2), 16)) + .ToArray(); + } + + public static string GetStringFromByteArray(byte[] Buffer) + { + return BitConverter.ToString(Buffer).Replace("-", ""); + } + + } +}