From 0a02ce2dc81564d7594bf572c3b34bcd5777ed14 Mon Sep 17 00:00:00 2001 From: valarnin Date: Tue, 9 Feb 2016 19:27:50 -0500 Subject: [PATCH] Implement enhancements #3 and #4 Implement enhancement #3. Will now download 3dsreleases.xml from 3dsdb.com to temp directory if it doesn't already exist. Will then use this file to identify title IDs of running processes. Implement ehnancement #4. If title IDs are identified from 3dsreleases.xml, they are bubbled to the top of the Processes list and the first item in the list is auto-selected. --- NTRDebuggerTool/Forms/MainForm.cs | 4 ++++ NTRDebuggerTool/Program.cs | 21 ++++++++++++++++ .../Remote/NTRPacketReceiverThread.cs | 24 ++++++++++++++++++- NTRDebuggerTool/Remote/NTRRemoteConnection.cs | 17 +++++++++++-- 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/NTRDebuggerTool/Forms/MainForm.cs b/NTRDebuggerTool/Forms/MainForm.cs index 3c1b1af..b03d4a3 100644 --- a/NTRDebuggerTool/Forms/MainForm.cs +++ b/NTRDebuggerTool/Forms/MainForm.cs @@ -132,6 +132,10 @@ private void GUIUpdateTimer_Tick(object sender, EventArgs e) Processes.SelectedValue = CurrentProcess; Processes.SelectedIndex = Processes.Items.IndexOf(CurrentProcess); } + else if (!Processes.Items[0].ToString().Contains(',')) + { + Processes.SelectedIndex = 0; + } SetConnectedControls(true); ControlEnabledButtonConnectDisconnect = true; NTRConnection.SetCurrentOperationText = ""; diff --git a/NTRDebuggerTool/Program.cs b/NTRDebuggerTool/Program.cs index 044c61e..03650ff 100644 --- a/NTRDebuggerTool/Program.cs +++ b/NTRDebuggerTool/Program.cs @@ -1,6 +1,8 @@ using NTRDebuggerTool.Forms; using NTRDebuggerTool.Remote; using System; +using System.IO; +using System.Net; using System.Windows.Forms; namespace NTRDebuggerTool @@ -13,6 +15,25 @@ static class Program [STAThread] static void Main() { + try + { + File.Open(Path.GetTempPath() + "3dsreleases.xml", FileMode.Open).Close(); + } + catch (FileNotFoundException ex) + { + try + { + using (WebClient client = new WebClient()) + { + client.DownloadFile("http://3dsdb.com/xml.php", Path.GetTempPath() + "3dsreleases.xml"); + } + } + catch (Exception e) + { + System.Console.Write(e); + } + } + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(new NTRRemoteConnection())); diff --git a/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs b/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs index 37e5707..c084eba 100644 --- a/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs +++ b/NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Xml; namespace NTRDebuggerTool.Remote { @@ -162,12 +163,33 @@ private void ReadProcessesPacket(uint DataLength) 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(); + XmlNode Node = null; - this.NTRConnection.Processes.Add(ProcessID + "|" + ProcessName + "," + TitleID); + if (NTRConnection.ReleasesDocument != null) + { + Node = NTRConnection.ReleasesDocument.DocumentElement.SelectSingleNode("/releases/release[translate(./titleid, 'ABCDEF', 'abcdef') = '" + TitleID.ToLower() + "']/name"); + } + + if (Node != null) + { + this.NTRConnection.Processes.Add(ProcessID + "|" + Node.InnerText); + } + else + { + this.NTRConnection.Processes.Add(ProcessID + "|" + ProcessName + "," + TitleID); + } } if (this.NTRConnection.Processes.Count > 0) { + //Bubble processes we ID'd to the top + List TempProcesses = this.NTRConnection.Processes.FindAll(x => x.Contains(',')); + this.NTRConnection.Processes.RemoveAll(x => TempProcesses.Contains(x)); + foreach (string Process in TempProcesses) + { + this.NTRConnection.Processes.Add(Process); + } + this.NTRConnection.IsProcessListUpdated = true; } } diff --git a/NTRDebuggerTool/Remote/NTRRemoteConnection.cs b/NTRDebuggerTool/Remote/NTRRemoteConnection.cs index 19f69a9..cddfb1f 100644 --- a/NTRDebuggerTool/Remote/NTRRemoteConnection.cs +++ b/NTRDebuggerTool/Remote/NTRRemoteConnection.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Net.Sockets; using System.Threading; +using System.Xml; namespace NTRDebuggerTool.Remote { @@ -53,6 +55,8 @@ public class NTRRemoteConnection public string SetCurrentOperationText = ""; private NTRPacketReceiverThread PacketReceiverThread; + internal XmlDocument ReleasesDocument; + #endregion #region Constructor @@ -60,6 +64,15 @@ public class NTRRemoteConnection public NTRRemoteConnection() { this.PacketReceiverThread = new NTRPacketReceiverThread(this); + try + { + this.ReleasesDocument = new XmlDocument(); + ReleasesDocument.Load(File.OpenRead(Path.GetTempPath() + "3dsreleases.xml")); + } + catch (Exception e) + { + this.ReleasesDocument = null; + } } #endregion @@ -241,7 +254,7 @@ public void SendReadMemoryPacket(uint ProcessID, uint AddressSpace, uint Size, b private void SendReadMemoryPacket(uint ProcessID, uint Address, uint Size) { - SetCurrentOperationText = "Searching Memory " + Utilities.GetStringFromByteArray(BitConverter.GetBytes(Address)); + SetCurrentOperationText = "Searching Memory " + Utilities.GetStringFromByteArray(BitConverter.GetBytes(Address).Reverse().ToArray()); 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) @@ -280,7 +293,7 @@ public bool SendHeartbeatPacket(bool IsConnecting) { if (IsConnecting || this.Client != null) { - if (IsConnecting || this.Client.Connected) + if (IsConnecting || (this.Client != null && this.Client.Connected)) { if (CanSendHeartbeat && LastHeartbeat < (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - 30000) {