Skip to content

Commit

Permalink
Implement enhancements #3 and #4
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
valarnin committed Feb 10, 2016
1 parent 529fac0 commit 0a02ce2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NTRDebuggerTool/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
21 changes: 21 additions & 0 deletions NTRDebuggerTool/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using NTRDebuggerTool.Forms;
using NTRDebuggerTool.Remote;
using System;
using System.IO;
using System.Net;
using System.Windows.Forms;

namespace NTRDebuggerTool
Expand All @@ -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()));
Expand Down
24 changes: 23 additions & 1 deletion NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml;

namespace NTRDebuggerTool.Remote
{
Expand Down Expand Up @@ -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<string> 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;
}
}
Expand Down
17 changes: 15 additions & 2 deletions NTRDebuggerTool/Remote/NTRRemoteConnection.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -53,13 +55,24 @@ public class NTRRemoteConnection
public string SetCurrentOperationText = "";
private NTRPacketReceiverThread PacketReceiverThread;

internal XmlDocument ReleasesDocument;

#endregion

#region Constructor

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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 0a02ce2

Please sign in to comment.