Skip to content

Added support for native integer sizes #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public class CSharpCodeGenerator : ICodeGenerator
[typeof(Int16Node)] = "short",
[typeof(Int32Node)] = "int",
[typeof(Int64Node)] = "long",
[typeof(NIntNode)] = "IntPtr",
[typeof(UInt8Node)] = "byte",
[typeof(UInt16Node)] = "ushort",
[typeof(UInt32Node)] = "uint",
[typeof(UInt64Node)] = "ulong",
[typeof(NUIntNode)] = "UIntPtr",

[typeof(FunctionPtrNode)] = "IntPtr",
[typeof(Utf8TextPtrNode)] = "IntPtr",
Expand Down
2 changes: 2 additions & 0 deletions ReClass.NET/CodeGenerator/CppCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@ public CppCodeGenerator(CppTypeMapping typeMapping)
[typeof(Int16Node)] = typeMapping.TypeInt16,
[typeof(Int32Node)] = typeMapping.TypeInt32,
[typeof(Int64Node)] = typeMapping.TypeInt64,
[typeof(NIntNode)] = typeMapping.TypeNInt,
[typeof(Matrix3x3Node)] = typeMapping.TypeMatrix3x3,
[typeof(Matrix3x4Node)] = typeMapping.TypeMatrix3x4,
[typeof(Matrix4x4Node)] = typeMapping.TypeMatrix4x4,
[typeof(UInt8Node)] = typeMapping.TypeUInt8,
[typeof(UInt16Node)] = typeMapping.TypeUInt16,
[typeof(UInt32Node)] = typeMapping.TypeUInt32,
[typeof(UInt64Node)] = typeMapping.TypeUInt64,
[typeof(NUIntNode)] = typeMapping.TypeNUInt,
[typeof(Utf8CharacterNode)] = typeMapping.TypeUtf8Text,
[typeof(Utf16CharacterNode)] = typeMapping.TypeUtf16Text,
[typeof(Utf32CharacterNode)] = typeMapping.TypeUtf32Text,
Expand Down
4 changes: 3 additions & 1 deletion ReClass.NET/DataExchange/ReClass/ReClassNetFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
Expand Down Expand Up @@ -54,13 +54,15 @@ static ReClassNetFile()
typeof(Int16Node),
typeof(Int32Node),
typeof(Int64Node),
typeof(NIntNode),
typeof(Matrix3x3Node),
typeof(Matrix3x4Node),
typeof(Matrix4x4Node),
typeof(UInt8Node),
typeof(UInt16Node),
typeof(UInt32Node),
typeof(UInt64Node),
typeof(NUIntNode),
typeof(Utf8TextNode),
typeof(Utf8TextPtrNode),
typeof(Utf16TextNode),
Expand Down
30 changes: 25 additions & 5 deletions ReClass.NET/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,10 @@ private void searchForEqualValuesToolStripMenuItem_Click(object sender, EventArg
comparer = new ArrayOfBytesMemoryComparer(node.ReadValueFromMemory(selectedNode.Memory));
break;
case FloatNode node:
comparer = new FloatMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, 2, node.ReadValueFromMemory(selectedNode.Memory), 0);
comparer = new FloatMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, 2, node.ReadValueFromMemory(selectedNode.Memory), 0.0f);
break;
case DoubleNode node:
comparer = new DoubleMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, 2, node.ReadValueFromMemory(selectedNode.Memory), 0);
comparer = new DoubleMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, 2, node.ReadValueFromMemory(selectedNode.Memory), 0.0);
break;
case Int8Node node:
comparer = new ByteMemoryComparer(ScanCompareType.Equal, (byte)node.ReadValueFromMemory(selectedNode.Memory), 0);
Expand All @@ -619,11 +619,31 @@ private void searchForEqualValuesToolStripMenuItem_Click(object sender, EventArg
comparer = new IntegerMemoryComparer(ScanCompareType.Equal, (int)node.ReadValueFromMemory(selectedNode.Memory), 0);
break;
case Int64Node node:
comparer = new LongMemoryComparer(ScanCompareType.Equal, node.ReadValueFromMemory(selectedNode.Memory), 0);
comparer = new LongMemoryComparer(ScanCompareType.Equal, node.ReadValueFromMemory(selectedNode.Memory), 0L);
break;
case UInt64Node node:
comparer = new LongMemoryComparer(ScanCompareType.Equal, (long)node.ReadValueFromMemory(selectedNode.Memory), 0);
comparer = new LongMemoryComparer(ScanCompareType.Equal, (long)node.ReadValueFromMemory(selectedNode.Memory), 0L);
break;
case NIntNode node:
{
var value = node.ReadValueFromMemory(selectedNode.Memory);
#if RECLASSNET64
comparer = new LongMemoryComparer(ScanCompareType.Equal, value.ToInt64(), 0L);
#else
comparer = new IntegerMemoryComparer(ScanCompareType.Equal, value.ToInt32(), 0);
#endif
break;
}
case NUIntNode node:
{
var value = node.ReadValueFromMemory(selectedNode.Memory);
#if RECLASSNET64
comparer = new LongMemoryComparer(ScanCompareType.Equal, (long)value.ToUInt64(), 0L);
#else
comparer = new IntegerMemoryComparer(ScanCompareType.Equal, (int)value.ToUInt32(), 0);
#endif
break;
}
case Utf8TextNode node:
comparer = new StringMemoryComparer(node.ReadValueFromMemory(selectedNode.Memory), Encoding.UTF8, true);
break;
Expand Down Expand Up @@ -716,7 +736,7 @@ private void shrinkClassToolStripMenuItem_Click(object sender, EventArgs e)
}
}

#endregion
#endregion

private void MainForm_DragEnter(object sender, DragEventArgs e)
{
Expand Down
16 changes: 15 additions & 1 deletion ReClass.NET/Memory/MemoryBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -326,6 +326,20 @@ public IntPtr ReadIntPtr(int offset)
#endif
}

/// <summary>Reads a <see cref="UIntPtr"/> from the specific offset.</summary>
/// <param name="offset">The offset into the data.</param>
/// <returns>The data read as <see cref="UIntPtr"/> or 0 if the offset is outside the data.</returns>
public UIntPtr ReadUIntPtr(int offset)
{
Contract.Requires(offset >= 0);

#if RECLASSNET64
return (UIntPtr)ReadUInt64(offset);
#else
return (UIntPtr)ReadUInt32(offset);
#endif
}

#endregion

public string ReadString(Encoding encoding, int offset, int length)
Expand Down
57 changes: 57 additions & 0 deletions ReClass.NET/Nodes/NIntNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Drawing;
using System.Globalization;
using ReClassNET.Controls;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.UI;

namespace ReClassNET.Nodes
{
public class NIntNode : BaseNumericNode
{
public override int MemorySize => IntPtr.Size;

public override void GetUserInterfaceInfo(out string name, out Image icon)
{
name = "NInt";
icon = Properties.Resources.B16x16_Button_NInt;
}

public override Size Draw(DrawContext context, int x, int y)
{
var value = ReadValueFromMemory(context.Memory)
#if RECLASSNET64
.ToInt64();
#else
.ToInt32();
#endif
return DrawNumeric(context, x, y, context.IconProvider.Signed, "NInt", value.ToString(), $"0x{value:X}");
}

public override void Update(HotSpot spot)
{
base.Update(spot);

if (spot.Id == 0 || spot.Id == 1)
{
#if RECLASSNET64
if (long.TryParse(spot.Text, out var val) || spot.Text.TryGetHexString(out var hexValue) && long.TryParse(hexValue, NumberStyles.HexNumber, null, out val))
{
spot.Process.WriteRemoteMemory(spot.Address, val);
}
#else
if (int.TryParse(spot.Text, out var val) || spot.Text.TryGetHexString(out var hexValue) && int.TryParse(hexValue, NumberStyles.HexNumber, null, out val))
{
spot.Process.WriteRemoteMemory(spot.Address, val);
}
#endif
}
}

public IntPtr ReadValueFromMemory(MemoryBuffer memory)
{
return memory.ReadIntPtr(Offset);
}
}
}
57 changes: 57 additions & 0 deletions ReClass.NET/Nodes/NUIntNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Drawing;
using System.Globalization;
using ReClassNET.Controls;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.UI;

namespace ReClassNET.Nodes
{
public class NUIntNode : BaseNumericNode
{
public override int MemorySize => UIntPtr.Size;

public override void GetUserInterfaceInfo(out string name, out Image icon)
{
name = "NUInt";
icon = Properties.Resources.B16x16_Button_NUInt;
}

public override Size Draw(DrawContext context, int x, int y)
{
var value = ReadValueFromMemory(context.Memory)
#if RECLASSNET64
.ToUInt64();
#else
.ToUInt32();
#endif
return DrawNumeric(context, x, y, context.IconProvider.Unsigned, "NUInt", value.ToString(), $"0x{value:X}");
}

public override void Update(HotSpot spot)
{
base.Update(spot);

if (spot.Id == 0 || spot.Id == 1)
{
#if RECLASSNET64
if (ulong.TryParse(spot.Text, out var val) || spot.Text.TryGetHexString(out var hexValue) && ulong.TryParse(hexValue, NumberStyles.HexNumber, null, out val))
{
spot.Process.WriteRemoteMemory(spot.Address, val);
}
#else
if (uint.TryParse(spot.Text, out var val) || spot.Text.TryGetHexString(out var hexValue) && uint.TryParse(hexValue, NumberStyles.HexNumber, null, out val))
{
spot.Process.WriteRemoteMemory(spot.Address, val);
}
#endif
}
}

public UIntPtr ReadValueFromMemory(MemoryBuffer memory)
{
return memory.ReadUIntPtr(Offset);
}
}
}
8 changes: 7 additions & 1 deletion ReClass.NET/Project/CppTypeMapping.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Xml.Linq;
using System.Xml.Linq;
using ReClassNET.Util;

namespace ReClassNET.Project
Expand All @@ -11,11 +11,13 @@ public class CppTypeMapping
public string TypeInt16 { get; set; } = "int16_t";
public string TypeInt32 { get; set; } = "int32_t";
public string TypeInt64 { get; set; } = "int64_t";
public string TypeNInt { get; set; } = "ptrdiff_t";

public string TypeUInt8 { get; set; } = "uint8_t";
public string TypeUInt16 { get; set; } = "uint16_t";
public string TypeUInt32 { get; set; } = "uint32_t";
public string TypeUInt64 { get; set; } = "uint64_t";
public string TypeNUInt { get; set; } = "size_t";

public string TypeFloat { get; set; } = "float";
public string TypeDouble { get; set; } = "double";
Expand Down Expand Up @@ -43,10 +45,12 @@ internal XElement Serialize(string name)
XElementSerializer.ToXml(nameof(TypeInt16), TypeInt16),
XElementSerializer.ToXml(nameof(TypeInt32), TypeInt32),
XElementSerializer.ToXml(nameof(TypeInt64), TypeInt64),
XElementSerializer.ToXml(nameof(TypeNInt), TypeNInt),
XElementSerializer.ToXml(nameof(TypeUInt8), TypeUInt8),
XElementSerializer.ToXml(nameof(TypeUInt16), TypeUInt16),
XElementSerializer.ToXml(nameof(TypeUInt32), TypeUInt32),
XElementSerializer.ToXml(nameof(TypeUInt64), TypeUInt64),
XElementSerializer.ToXml(nameof(TypeNUInt), TypeNUInt),
XElementSerializer.ToXml(nameof(TypeFloat), TypeFloat),
XElementSerializer.ToXml(nameof(TypeDouble), TypeDouble),
XElementSerializer.ToXml(nameof(TypeVector2), TypeVector2),
Expand All @@ -69,10 +73,12 @@ internal void Deserialize(XElement element)
XElementSerializer.TryRead(element, nameof(TypeInt16), e => TypeInt16 = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeInt32), e => TypeInt32 = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeInt64), e => TypeInt64 = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeNInt), e => TypeNInt = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeUInt8), e => TypeUInt8 = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeUInt16), e => TypeUInt16 = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeUInt32), e => TypeUInt32 = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeUInt64), e => TypeUInt64 = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeNUInt), e => TypeNUInt = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeFloat), e => TypeFloat = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeDouble), e => TypeDouble = XElementSerializer.ToString(e));
XElementSerializer.TryRead(element, nameof(TypeVector2), e => TypeVector2 = XElementSerializer.ToString(e));
Expand Down
24 changes: 22 additions & 2 deletions ReClass.NET/Properties/Resources.Designer.cs

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

6 changes: 6 additions & 0 deletions ReClass.NET/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,10 @@
<data name="B16x16_Button_Union" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Images\B16x16_Button_Union.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="B16x16_Button_NInt" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Images\B16x16_Button_NInt.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="B16x16_Button_NUInt" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Images\B16x16_Button_NUInt.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
9 changes: 8 additions & 1 deletion ReClass.NET/ReClass.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@
<Compile Include="Nodes\ClassUtil.cs" />
<Compile Include="Nodes\EnumNode.cs" />
<Compile Include="Nodes\FunctionNode.cs" />
<Compile Include="Nodes\NIntNode.cs" />
<Compile Include="Nodes\NodeUuid.cs" />
<Compile Include="Nodes\PointerNode.cs" />
<Compile Include="Nodes\NUIntNode.cs" />
<Compile Include="Nodes\UnionNode.cs" />
<Compile Include="Project\CppTypeMapping.cs" />
<Compile Include="Project\EnumDescription.cs" />
Expand Down Expand Up @@ -1011,7 +1013,12 @@
<ItemGroup>
<None Include="Resources\Images\B16x16_Button_Union.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="Resources\Images\B16x16_Button_NInt.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Images\B16x16_Button_NUInt.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">powershell -Command "((Get-Date).ToUniversalTime()).ToString(\"yyyy\/MM\/dd HH:mm:ss\") | Out-File '$(ProjectDir)Resources\BuildDate.txt'"</PreBuildEvent>
Expand Down
Binary file added ReClass.NET/Resources/Images/B16x16_Button_NInt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ReClass.NET/Resources/Images/B16x16_Button_NUInt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ReClass.NET/UI/NodeTypesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ internal static class NodeTypesBuilder
static NodeTypesBuilder()
{
defaultNodeTypeGroupList.Add(new[] { typeof(Hex64Node), typeof(Hex32Node), typeof(Hex16Node), typeof(Hex8Node) });
defaultNodeTypeGroupList.Add(new[] { typeof(Int64Node), typeof(Int32Node), typeof(Int16Node), typeof(Int8Node) });
defaultNodeTypeGroupList.Add(new[] { typeof(UInt64Node), typeof(UInt32Node), typeof(UInt16Node), typeof(UInt8Node) });
defaultNodeTypeGroupList.Add(new[] { typeof(NIntNode), typeof(Int64Node), typeof(Int32Node), typeof(Int16Node), typeof(Int8Node) });
defaultNodeTypeGroupList.Add(new[] { typeof(NUIntNode), typeof(UInt64Node), typeof(UInt32Node), typeof(UInt16Node), typeof(UInt8Node) });
defaultNodeTypeGroupList.Add(new[] { typeof(BoolNode), typeof(BitFieldNode), typeof(EnumNode) });
defaultNodeTypeGroupList.Add(new[] { typeof(FloatNode), typeof(DoubleNode) });
defaultNodeTypeGroupList.Add(new[] { typeof(Vector4Node), typeof(Vector3Node), typeof(Vector2Node), typeof(Matrix4x4Node), typeof(Matrix3x4Node), typeof(Matrix3x3Node) });
Expand Down