Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Added a BugReporter | Not yet finished
Browse files Browse the repository at this point in the history
  • Loading branch information
phecdaDia committed May 9, 2016
1 parent d6b1000 commit e9230bc
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 39 deletions.
68 changes: 68 additions & 0 deletions ntrclient/Extra/BugReporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using ntrclient.Prog.CS;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ntrclient.Extra
{
public class BugReporter
{
private Exception e;
private String additionalInformation;
private String NtrVersion;
private bool showMessagebox;


public BugReporter(Exception e, String additionalInformation, bool showMessagebox = true)
{
this.e = e;
this.additionalInformation = additionalInformation;
NtrVersion = @"**todo**";
this.showMessagebox = showMessagebox;

saveLog();
}

private void saveLog()
{
String log = @"--- NTR Debugger Bug report ---" + Environment.NewLine +
@"Please upload this bugreport to pastebin or similar and send it to imthe666st" + Environment.NewLine + Environment.NewLine +
@"------------------------------" + Environment.NewLine + Environment.NewLine;

log += @"Additional Information: " + additionalInformation + Environment.NewLine;
log += @"Version of NTR: " + NtrVersion + Environment.NewLine + Environment.NewLine;
log += @"------------------------------" + Environment.NewLine + Environment.NewLine;
log += @"Exception stacktrace: " + Environment.NewLine + e.ToString();
log += @"------------------------------" + Environment.NewLine + Environment.NewLine;
log += Program.GCmdWindow.GetLog() + Environment.NewLine + Environment.NewLine;
log += @"------------------------------" + Environment.NewLine + Environment.NewLine;
log += @"System information: [PROCESSES]" + Environment.NewLine;
foreach (NtrProcess process in Program.GCmdWindow.Processes)
{
log += string.Format("{0} | {1:X} : {2} [{3:X}]", Program.GCmdWindow.FillString(Program.GCmdWindow.CheckSystem(process.Name), 6), process.Pid, process.Name, process.Tid) + Environment.NewLine;
}
log += Environment.NewLine + @"------------------------------" + Environment.NewLine + Environment.NewLine;
log += @"Current process: " + Program.GCmdWindow.comboBox_processes.Text + Environment.NewLine + Environment.NewLine;
log += @"------------------------------" + Environment.NewLine + Environment.NewLine;

log += @"This is the end of the bugreport. ^_^";

Directory.CreateDirectory("bugreports");
String name = @"bugreports/bugreport-" + GetTimestamp(DateTime.Now) + @".txt";
File.WriteAllText(name, log);

if (showMessagebox)
MessageBox.Show(@"Saved bugreport to " + name);
}


public static String GetTimestamp(DateTime value)
{
return value.ToString("yyyyMMddHHmmssffff");
}
}
}
2 changes: 2 additions & 0 deletions ntrclient/Prog/CS/GitHub/Octo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Octokit;
using System;
using System.Windows.Forms;
using ntrclient.Extra;

namespace ntrclient.Prog.CS.GitHub
{
Expand All @@ -28,6 +29,7 @@ public static async Task<Release> GetLastUpdate()
} catch ( Exception e )
{
MessageBox.Show("An error occured trying to look for updates!");
BugReporter br = new BugReporter(e, "Updater exception", false);
return null;
}
}
Expand Down
7 changes: 5 additions & 2 deletions ntrclient/Prog/CS/NtrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Windows.Forms;
using ntrclient.Prog.Window;
using ntrclient.Extra;

namespace ntrclient.Prog.CS
{
Expand Down Expand Up @@ -52,7 +53,7 @@ private int ReadNetworkStream(Stream stream, byte[] buf, int length)
return length;

}
catch (Exception e)
catch (Exception)
{
Log("Connection timed out");
return 0;
Expand Down Expand Up @@ -148,6 +149,7 @@ private void PacketRecvThreadStart()
{
Log(e.Message);
Log(e.StackTrace);
BugReporter br = new BugReporter(e, "Packet receiver exception", true);
//log("An error occured!");
break;
}
Expand Down Expand Up @@ -347,7 +349,8 @@ public void Log(string msg)
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

BugReporter br = new BugReporter(ex, "Logging exception");
}
}

Expand Down
6 changes: 4 additions & 2 deletions ntrclient/Prog/CS/SettingsManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ntrclient.Extra;
using System;
using System.IO;
using System.Windows.Forms;

Expand Down Expand Up @@ -43,7 +44,7 @@ public static void SaveToXml(string filePath, SettingsManager sourceObj)
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
BugReporter br = new BugReporter(ex, "XML save exception", true);
}
}

Expand All @@ -65,6 +66,7 @@ public static SettingsManager LoadFromXml(string filePath)
@"Downloaded or Updated this tool..." + Environment.NewLine + Environment.NewLine +
ex.Message
);
BugReporter br = new BugReporter(ex, "XML Load exception", false);
}
return new SettingsManager();
}
Expand Down
10 changes: 6 additions & 4 deletions ntrclient/Prog/CS/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ntrclient.Extra;
using System;
using System.Diagnostics;
using System.Linq;

Expand All @@ -8,6 +9,8 @@ public class Utility
{
public static int RunCommandAndGetOutput(string exeFile, string args, ref string output)
{
try
{
if (output == null) throw new ArgumentNullException(nameof(output));
Process proc = new Process
{
Expand All @@ -22,9 +25,7 @@ public static int RunCommandAndGetOutput(string exeFile, string args, ref string
}
};


try
{

proc.Start();
proc.WaitForExit();
var processOutput = proc.StandardError.ReadToEnd();
Expand All @@ -37,6 +38,7 @@ public static int RunCommandAndGetOutput(string exeFile, string args, ref string
catch (Exception e)
{
output = e.Message;
//BugReporter br = new BugReporter(e, "Run CMD exception", false);
return -1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion ntrclient/Prog/Window/CmdWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 88 additions & 30 deletions ntrclient/Prog/Window/CmdWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ namespace ntrclient.Prog.Window
{
public partial class CmdWindow : Form
{

private String version = @"V1.5-1";
private String release = @"Public Version";

//________________________________________________________________
// System

Expand Down Expand Up @@ -54,9 +58,10 @@ private void timer1_Tick(object sender, EventArgs e)
LookForUpdate();
}
}
catch (Exception)
catch (Exception e_)
{
// ignored
BugReporter br = new BugReporter(e_, "Timer exception");

}
}

Expand All @@ -72,7 +77,7 @@ private async void LookForUpdate()
{
_lookedForUpdate = true;
Release upd = await Octo.GetLastUpdate();
if (upd.TagName != "V1.5-1" && upd.TagName != "ERROR" && !upd.Prerelease && !upd.Draft)
if (upd.TagName != version && upd.TagName != "ERROR" && !upd.Prerelease && !upd.Draft)
{
string nVersion = Octo.GetLastVersionName();
string nBody = Octo.GetLastVersionBody();
Expand All @@ -94,6 +99,17 @@ private void CmdWindow_Load(object sender, EventArgs e)
{
ResetLog();

this.VersionNumberToolStripMenuItem.Text = version;
this.VersionExtraToolStripMenuItem.Text = release;

// Remove all errorreports.
DirectoryInfo di = new DirectoryInfo("bugreports");

foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}

textBox_Ip.Text = Program.Sm.IpAddress;
if (Program.Sm.IpAddress != "Nintendo 3DS IP")
{
Expand Down Expand Up @@ -153,6 +169,11 @@ public void Addlog(string l)
}
}

public String GetLog()
{
return txtLog.Text;
}

// END of Logging

//________________________________________________________________
Expand Down Expand Up @@ -275,7 +296,7 @@ private void GenerateProcesses()
}
}

private static string FillString(string n, int len)
public string FillString(string n, int len)
{
int ls = len - n.Length;
if (ls <= 0) return n;
Expand All @@ -286,7 +307,7 @@ private static string FillString(string n, int len)
return n;
}

private static string CheckSystem(string n)
public string CheckSystem(string n)
{
string[] sys =
{
Expand Down Expand Up @@ -442,6 +463,7 @@ public string RunCmd(string cmd)
catch (Exception ex)
{
Addlog(ex.Message);
BugReporter br = new BugReporter(ex, "Command execution exception", false);
return "";
}
}
Expand Down Expand Up @@ -818,33 +840,51 @@ private void button_dummy_read_Click(object sender, EventArgs e)

private void button_dummy_write_Click(object sender, EventArgs e)
{
int addr = Convert.ToInt32(textBox_dummy_addr.Text, 16);
uint v = FromLe(Convert.ToUInt32(textBox_dummy_value_hex.Text, 16), (int) numericUpDown_dummy_length.Value);
RunCmd(GenerateWriteString(addr, v, (uint) numericUpDown_dummy_length.Value));
try
{
int addr = Convert.ToInt32(textBox_dummy_addr.Text, 16);
uint v = FromLe(Convert.ToUInt32(textBox_dummy_value_hex.Text, 16), (int)numericUpDown_dummy_length.Value);
RunCmd(GenerateWriteString(addr, v, (uint)numericUpDown_dummy_length.Value));
} catch ( Exception ex)
{
BugReporter br = new BugReporter(ex, @"Dummy HEX write Exception [" + textBox_dummy_addr.Text + @" -> " + textBox_dummy_value_hex + @"]");
}
}

private void button_dummy_write_hex_le_Click(object sender, EventArgs e)
{
int addr = Convert.ToInt32(textBox_dummy_addr.Text, 16);
uint v = Convert.ToUInt32(textBox_dummy_value_hex_le.Text, 16);
RunCmd(GenerateWriteString(addr, v, (uint) numericUpDown_dummy_length.Value));
try
{
int addr = Convert.ToInt32(textBox_dummy_addr.Text, 16);
uint v = Convert.ToUInt32(textBox_dummy_value_hex_le.Text, 16);
RunCmd(GenerateWriteString(addr, v, (uint) numericUpDown_dummy_length.Value));
} catch ( Exception ex)
{
BugReporter br = new BugReporter(ex, @"Dummy HEX write Exception [" + textBox_dummy_addr.Text + @" -> " + textBox_dummy_value_hex + @"]");
}
}

private void button_dummy_write_dec_Click(object sender, EventArgs e)
{
int addr = Convert.ToInt32(textBox_dummy_addr.Text, 16);
uint v = Convert.ToUInt32(textBox_dummy_value_dec.Text, 10);
RunCmd(GenerateWriteString(addr, v, (uint) numericUpDown_dummy_length.Value));
try
{
int addr = Convert.ToInt32(textBox_dummy_addr.Text, 16);
uint v = Convert.ToUInt32(textBox_dummy_value_dec.Text, 10);
RunCmd(GenerateWriteString(addr, v, (uint) numericUpDown_dummy_length.Value));
} catch ( Exception ex)
{
BugReporter br = new BugReporter(ex, @"Dummy HEX write Exception [" + textBox_dummy_addr.Text + @" -> " + textBox_dummy_value_hex + @"]");
}
}

//

private void button_dump_all_Click2(object sender, EventArgs e)
{
String filename = textBox_dump_file.Text;
Memregion mem = Memregions[Memregions.Count - 1];
RunCmd(String.Format("Data(0x{0:X}, 0x{1:X}, filename='{2}', pid=0x{3:X})", 0, mem.Start + mem.Length, filename, GetPid()));
}
//private void button_dump_all_Click2(object sender, EventArgs e)
//{
// String filename = textBox_dump_file.Text;
// Memregion mem = Memregions[Memregions.Count - 1];
// RunCmd(String.Format("Data(0x{0:X}, 0x{1:X}, filename='{2}', pid=0x{3:X})", 0, mem.Start + mem.Length, filename, GetPid()));
//}

private void button_dump_all_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -1010,26 +1050,44 @@ private void button_cfg_read_dummy_Click(object sender, EventArgs e)

private void button_debug_conv_hex_Click(object sender, EventArgs e)
{
int v = Convert.ToInt32(textBox_debug_conv_hex.Text, 16);
try
{
int v = Convert.ToInt32(textBox_debug_conv_hex.Text, 16);

textBox_debug_conv_hex_le.Text = string.Format("{0:X}", FromLe(v, (int) numericUpDown_debug_hextest.Value));
textBox_debug_conv_dec.Text = string.Format("{0}", v);
textBox_debug_conv_hex_le.Text = string.Format("{0:X}", FromLe(v, (int) numericUpDown_debug_hextest.Value));
textBox_debug_conv_dec.Text = string.Format("{0}", v);
} catch ( Exception ex )
{
BugReporter br = new BugReporter(ex, "Debug Convert HEX Exception");
}
}

private void button_debug_conv_hex_le_Click(object sender, EventArgs e)
{
uint v = FromLe(Convert.ToInt32(textBox_debug_conv_hex_le.Text, 16), (int) numericUpDown_debug_hextest.Value);
try
{
uint v = FromLe(Convert.ToInt32(textBox_debug_conv_hex_le.Text, 16), (int) numericUpDown_debug_hextest.Value);

textBox_debug_conv_hex.Text = string.Format("{0:X}", v);
textBox_debug_conv_dec.Text = string.Format("{0}", v);
}
textBox_debug_conv_hex.Text = string.Format("{0:X}", v);
textBox_debug_conv_dec.Text = string.Format("{0}", v);
} catch ( Exception ex )
{
BugReporter br = new BugReporter(ex, "Debug Convert HEXLE Exception");
}
}

private void button_debug_conv_dec_Click(object sender, EventArgs e)
{
int v = Convert.ToInt32(textBox_debug_conv_dec.Text, 10);
try
{
int v = Convert.ToInt32(textBox_debug_conv_dec.Text, 10);

textBox_debug_conv_hex.Text = string.Format("{0:X}", v);
textBox_debug_conv_hex_le.Text = string.Format("{0:X}", FromLe(v, (int) numericUpDown_debug_hextest.Value));
textBox_debug_conv_hex.Text = string.Format("{0:X}", v);
textBox_debug_conv_hex_le.Text = string.Format("{0:X}", FromLe(v, (int) numericUpDown_debug_hextest.Value));
} catch ( Exception ex )
{
BugReporter br = new BugReporter(ex, "Debug Convert DEC Exception");
}
}

// Update tests
Expand Down

0 comments on commit e9230bc

Please sign in to comment.