Skip to content

Commit

Permalink
Fix various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
valarnin committed Apr 3, 2016
1 parent 8dfea9a commit 0111eff
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 13 deletions.
12 changes: 10 additions & 2 deletions NTRDebuggerTool/Forms/MainForm.Designer.cs

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

76 changes: 65 additions & 11 deletions NTRDebuggerTool/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ private void GUIUpdateTimer_Tick(object sender, EventArgs e)

public string GetDisplayForByteArray(byte[] p)
{
switch (ThreadEventDispatcher.CurrentSelectedDataType)
return GetDisplayForByteArray(p, ThreadEventDispatcher.CurrentSelectedDataType);
}

public string GetDisplayForByteArray(byte[] p, DataTypeExact DataType)
{
switch (DataType)
{
case DataTypeExact.Bytes1: //1 Byte
return ((uint)p[0]).ToString();
Expand Down Expand Up @@ -321,6 +326,7 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
NTRConnection.Disconnect();
this.EventDispatcherThread.Abort();
this.ButtonStateThread.Abort();
Application.Exit();
}

private void ButtonAddResults_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -384,6 +390,7 @@ private void SetMemory(int RowIndex)

if (IsValidMemoryAddress(Address))
{
ValuesGrid[1, RowIndex].ToolTipText = Utilities.GetStringFromByteArray(BitConverter.GetBytes(Address).Reverse().ToArray());
uint ProcessID = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Processes.Text.Split('|')[0]), 0);
switch (DataTypeExactTool.GetValue((string)ValuesGrid[3, RowIndex].Value))
{
Expand Down Expand Up @@ -463,13 +470,17 @@ private uint ResolvePointer(Match Match)
Address = BitConverter.ToUInt32(Data, 0);
Pointers[Pointer] = Address;
}
else if (!IsValidMemoryAddress(Pointer))
{
return 0;
}
else
{
Address = Pointers[Pointer];
}
}

if (!string.IsNullOrWhiteSpace(OffsetString))
if (Address != 0 && !string.IsNullOrWhiteSpace(OffsetString))
{
OffsetString = OffsetString.Replace("[", "").Replace("]", "");
Address += BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(OffsetString.PadLeft(8, '0')).Reverse().ToArray(), 0);
Expand All @@ -479,11 +490,26 @@ private uint ResolvePointer(Match Match)
}

private byte[] GetMemoryAtAddress(string ProcessID, string Address, DataTypeExact DataType)
{
return GetMemoryAtAddress(BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(ProcessID), 0), BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Address).Reverse().ToArray(), 0), DataType);
}

private byte[] GetMemoryAtAddress(uint ProcessID, string Address, DataTypeExact DataType)
{
return GetMemoryAtAddress(ProcessID, BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Address).Reverse().ToArray(), 0), DataType);
}

private byte[] GetMemoryAtAddress(string ProcessID, uint Address, DataTypeExact DataType)
{
return GetMemoryAtAddress(BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(ProcessID), 0), Address, DataType);
}

private byte[] GetMemoryAtAddress(uint ProcessID, uint Address, DataTypeExact DataType)
{
SearchCriteria Criteria = new SearchCriteria();
Criteria.ProcessID = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(ProcessID), 0);
Criteria.ProcessID = ProcessID;
Criteria.DataType = DataType;
Criteria.StartAddress = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(Address).Reverse().ToArray(), 0);
Criteria.StartAddress = Address;
Criteria.Length = Criteria.Size = GetSearchMemorySize(DataType);
Criteria.SearchType = SearchTypeBase.Unknown;
Criteria.SearchValue = new byte[] { 0 };
Expand Down Expand Up @@ -651,10 +677,6 @@ private void ValuesGridContextMenuStrip_ItemClicked(object sender, ToolStripItem
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);
Expand All @@ -664,13 +686,45 @@ private void ValuesGridContextMenuStrip_ItemClicked(object sender, ToolStripItem
ValuesGrid.Rows.Add();
break;
case "ValuesGridConvertCode":
foreach (DataGridViewRow Row in ValuesGrid.SelectedRows)
foreach (DataGridViewCell Cell in ValuesGrid.SelectedCells)
{
Row.Cells[1].Value = ConvertCode((string)Row.Cells[1].Value);
Cell.OwningRow.Cells[1].Value = ConvertCode((string)Cell.OwningRow.Cells[1].Value);
}
break;
case "ValuesGridRefreshItem":
foreach (DataGridViewCell Cell in ValuesGrid.SelectedCells)
{
Cell.OwningRow.Cells[1].Value = ConvertCode((string)Cell.OwningRow.Cells[1].Value);
string TextAddress = (string)Cell.OwningRow.Cells[1].Value;
uint Address;

if (HexRegex.IsMatch(TextAddress))
{
Address = BitConverter.ToUInt32(Utilities.GetByteArrayFromByteString(TextAddress).Reverse().ToArray(), 0); ;
}
else
{
Match TopMatch = ParserRegex.Match(TextAddress);

if (!TopMatch.Success)
{
return;
}

Pointers.Clear();
Address = ResolvePointer(TopMatch);
Pointers.Clear();
}

if (!IsValidMemoryAddress(Address) || Cell.OwningRow.Cells[3].Value == null)
{
continue;
}

DataTypeExact DataType = DataTypeExactTool.GetValue((string)Cell.OwningRow.Cells[3].Value);

byte[] Value = GetMemoryAtAddress(Processes.Text.Split('|')[0], Address, DataType);

Cell.OwningRow.Cells[2].Value = GetDisplayForByteArray(Value, DataType);
}
break;
}
Expand Down

0 comments on commit 0111eff

Please sign in to comment.