Skip to content

Commit

Permalink
Fix #16
Browse files Browse the repository at this point in the history
Changed to always target x86
Fixed not actually exiting when closing message box on exception
  • Loading branch information
valarnin committed May 2, 2016
1 parent 16bb44d commit eac203c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 10 deletions.
4 changes: 2 additions & 2 deletions NTRDebuggerTool/NTRDebuggerTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
Expand All @@ -39,7 +39,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
Expand Down
1 change: 1 addition & 0 deletions NTRDebuggerTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static void Main(string[] args)
{
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType).Error(null, ex);
MessageBox.Show("An exception has occurred. Check the log file at " + System.IO.Path.GetTempPath() + System.IO.Path.DirectorySeparatorChar + "NTRDebuggerTool-Log.txt");
Application.Exit();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions NTRDebuggerTool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("290cd39f-c191-4212-9985-0584c9200acc")]
[assembly: AssemblyVersion("0.8.6.1")]
[assembly: AssemblyFileVersion("0.8.6.1")]
[assembly: AssemblyVersion("0.8.6.2")]
[assembly: AssemblyFileVersion("0.8.6.2")]
103 changes: 97 additions & 6 deletions NTRDebuggerTool/Remote/NTRPacketReceiverThread.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using NTRDebuggerTool.Forms.FormEnums;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Xml;
Expand Down Expand Up @@ -322,25 +321,26 @@ private bool CheckCriteria(uint RealAddress, byte[] RemoteValue)
{
return false;
}
return IsIncreasedBy(RealAddress, RemoteValue);
return GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress]).CompareTo(GetValueFromByteArray(RemoteValue)) == BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].SearchValue, 0);
case SearchTypeBase.DecreasedBy:
if (!NTRConnection.SearchCriteria[0].AddressesFound.ContainsKey(RealAddress))
{
return false;
}
return GetValueFromByteArray(RemoteValue).CompareTo(GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress])) == BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].SearchValue, 0);
return IsDecreasedBy(RealAddress, RemoteValue);
case SearchTypeBase.Increased:
if (!NTRConnection.SearchCriteria[0].AddressesFound.ContainsKey(RealAddress))
{
return false;
}
return GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress]).CompareTo(GetValueFromByteArray(RemoteValue)) > 0;
return GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress]).CompareTo(GetValueFromByteArray(RemoteValue)) < 0;
case SearchTypeBase.Decreased:
if (!NTRConnection.SearchCriteria[0].AddressesFound.ContainsKey(RealAddress))
{
return false;
}
return GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress]).CompareTo(GetValueFromByteArray(RemoteValue)) < 0;
return GetValueFromByteArray(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress]).CompareTo(GetValueFromByteArray(RemoteValue)) > 0;
case SearchTypeBase.Same:
if (!NTRConnection.SearchCriteria[0].AddressesFound.ContainsKey(RealAddress))
{
Expand All @@ -358,8 +358,6 @@ private bool CheckCriteria(uint RealAddress, byte[] RemoteValue)
default:
throw new InvalidOperationException("Invalid search type " + NTRConnection.SearchCriteria[0].SearchType.ToString() + " passed to NTRPacketReceiverThread.CheckCriteria");
}


}

private IComparable GetValueFromByteArray(byte[] Value)
Expand All @@ -383,6 +381,99 @@ private IComparable GetValueFromByteArray(byte[] Value)
}
}

private bool IsIncreasedBy(uint RealAddress, byte[] RemoteValue)
{
checked
{
switch (NTRConnection.SearchCriteria[0].DataType)
{
case DataTypeExact.Bytes1:
return NTRConnection.SearchCriteria[0].AddressesFound[RealAddress][0] ==
RemoteValue[0] - NTRConnection.SearchCriteria[0].SearchValue[0];
case DataTypeExact.Bytes2:
return BitConverter.ToUInt16(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) ==
BitConverter.ToUInt16(RemoteValue, 0) - BitConverter.ToUInt16(NTRConnection.SearchCriteria[0].SearchValue, 0);
case DataTypeExact.Bytes4:
return BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) ==
BitConverter.ToUInt32(RemoteValue, 0) - BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].SearchValue, 0);
case DataTypeExact.Bytes8:
return BitConverter.ToUInt64(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) ==
BitConverter.ToUInt64(RemoteValue, 0) - BitConverter.ToUInt64(NTRConnection.SearchCriteria[0].SearchValue, 0);
case DataTypeExact.Float:
return IsLessThan(BitConverter.ToSingle(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0),
BitConverter.ToSingle(RemoteValue, 0) + BitConverter.ToSingle(NTRConnection.SearchCriteria[0].SearchValue, 0));
case DataTypeExact.Double:
return IsLessThan(BitConverter.ToDouble(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0),
BitConverter.ToDouble(RemoteValue, 0) + BitConverter.ToDouble(NTRConnection.SearchCriteria[0].SearchValue, 0));
default:
throw new InvalidOperationException("Invalid data type " + NTRConnection.SearchCriteria[0].DataType.ToString() + " passed to NTRPacketReceiverThread.GetValueFromByteArray");
}
}
}

private bool IsDecreasedBy(uint RealAddress, byte[] RemoteValue)
{
checked
{
switch (NTRConnection.SearchCriteria[0].DataType)
{
case DataTypeExact.Bytes1:
return NTRConnection.SearchCriteria[0].AddressesFound[RealAddress][0] ==
RemoteValue[0] + NTRConnection.SearchCriteria[0].SearchValue[0];
case DataTypeExact.Bytes2:
return BitConverter.ToUInt16(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) ==
BitConverter.ToUInt16(RemoteValue, 0) + BitConverter.ToUInt16(NTRConnection.SearchCriteria[0].SearchValue, 0);
case DataTypeExact.Bytes4:
return BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) ==
BitConverter.ToUInt32(RemoteValue, 0) + BitConverter.ToUInt32(NTRConnection.SearchCriteria[0].SearchValue, 0);
case DataTypeExact.Bytes8:
return BitConverter.ToUInt64(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0) ==
BitConverter.ToUInt64(RemoteValue, 0) + BitConverter.ToUInt64(NTRConnection.SearchCriteria[0].SearchValue, 0);
case DataTypeExact.Float:
return IsGreaterThan(BitConverter.ToSingle(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0),
BitConverter.ToSingle(RemoteValue, 0) + BitConverter.ToSingle(NTRConnection.SearchCriteria[0].SearchValue, 0));
case DataTypeExact.Double:
return IsGreaterThan(BitConverter.ToDouble(NTRConnection.SearchCriteria[0].AddressesFound[RealAddress], 0),
BitConverter.ToDouble(RemoteValue, 0) + BitConverter.ToDouble(NTRConnection.SearchCriteria[0].SearchValue, 0));
default:
throw new InvalidOperationException("Invalid data type " + NTRConnection.SearchCriteria[0].DataType.ToString() + " passed to NTRPacketReceiverThread.GetValueFromByteArray");
}
}
}

#endregion

#region Handle comparison of precision numbers (float, double)

private bool IsLessThan(float Left, float Right)
{
checked
{
return Left < Right + float.Epsilon;
}
}
private bool IsGreaterThan(float Left, float Right)
{
checked
{
return Left + float.Epsilon > Right;
}
}
private bool IsLessThan(double Left, double Right)
{
checked
{
return Left < Right + double.Epsilon;
}
}
private bool IsGreaterThan(double Left, double Right)
{
checked
{
return Left + double.Epsilon > Right;
}
}

#endregion
}
}

0 comments on commit eac203c

Please sign in to comment.