Skip to content

Commit cc51402

Browse files
authored
Merge pull request #176 from ReClassNET/NativeInt
Added support for native integer sizes
2 parents 062cced + 802fb66 commit cc51402

File tree

14 files changed

+206
-13
lines changed

14 files changed

+206
-13
lines changed

ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public class CSharpCodeGenerator : ICodeGenerator
2222
[typeof(Int16Node)] = "short",
2323
[typeof(Int32Node)] = "int",
2424
[typeof(Int64Node)] = "long",
25+
[typeof(NIntNode)] = "IntPtr",
2526
[typeof(UInt8Node)] = "byte",
2627
[typeof(UInt16Node)] = "ushort",
2728
[typeof(UInt32Node)] = "uint",
2829
[typeof(UInt64Node)] = "ulong",
30+
[typeof(NUIntNode)] = "UIntPtr",
2931

3032
[typeof(FunctionPtrNode)] = "IntPtr",
3133
[typeof(Utf8TextPtrNode)] = "IntPtr",

ReClass.NET/CodeGenerator/CppCodeGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,15 @@ public CppCodeGenerator(CppTypeMapping typeMapping)
136136
[typeof(Int16Node)] = typeMapping.TypeInt16,
137137
[typeof(Int32Node)] = typeMapping.TypeInt32,
138138
[typeof(Int64Node)] = typeMapping.TypeInt64,
139+
[typeof(NIntNode)] = typeMapping.TypeNInt,
139140
[typeof(Matrix3x3Node)] = typeMapping.TypeMatrix3x3,
140141
[typeof(Matrix3x4Node)] = typeMapping.TypeMatrix3x4,
141142
[typeof(Matrix4x4Node)] = typeMapping.TypeMatrix4x4,
142143
[typeof(UInt8Node)] = typeMapping.TypeUInt8,
143144
[typeof(UInt16Node)] = typeMapping.TypeUInt16,
144145
[typeof(UInt32Node)] = typeMapping.TypeUInt32,
145146
[typeof(UInt64Node)] = typeMapping.TypeUInt64,
147+
[typeof(NUIntNode)] = typeMapping.TypeNUInt,
146148
[typeof(Utf8CharacterNode)] = typeMapping.TypeUtf8Text,
147149
[typeof(Utf16CharacterNode)] = typeMapping.TypeUtf16Text,
148150
[typeof(Utf32CharacterNode)] = typeMapping.TypeUtf32Text,

ReClass.NET/DataExchange/ReClass/ReClassNetFile.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.Contracts;
44
using System.Linq;
@@ -54,13 +54,15 @@ static ReClassNetFile()
5454
typeof(Int16Node),
5555
typeof(Int32Node),
5656
typeof(Int64Node),
57+
typeof(NIntNode),
5758
typeof(Matrix3x3Node),
5859
typeof(Matrix3x4Node),
5960
typeof(Matrix4x4Node),
6061
typeof(UInt8Node),
6162
typeof(UInt16Node),
6263
typeof(UInt32Node),
6364
typeof(UInt64Node),
65+
typeof(NUIntNode),
6466
typeof(Utf8TextNode),
6567
typeof(Utf8TextPtrNode),
6668
typeof(Utf16TextNode),

ReClass.NET/Forms/MainForm.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,10 @@ private void searchForEqualValuesToolStripMenuItem_Click(object sender, EventArg
595595
comparer = new ArrayOfBytesMemoryComparer(node.ReadValueFromMemory(selectedNode.Memory));
596596
break;
597597
case FloatNode node:
598-
comparer = new FloatMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, 2, node.ReadValueFromMemory(selectedNode.Memory), 0);
598+
comparer = new FloatMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, 2, node.ReadValueFromMemory(selectedNode.Memory), 0.0f);
599599
break;
600600
case DoubleNode node:
601-
comparer = new DoubleMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, 2, node.ReadValueFromMemory(selectedNode.Memory), 0);
601+
comparer = new DoubleMemoryComparer(ScanCompareType.Equal, ScanRoundMode.Normal, 2, node.ReadValueFromMemory(selectedNode.Memory), 0.0);
602602
break;
603603
case Int8Node node:
604604
comparer = new ByteMemoryComparer(ScanCompareType.Equal, (byte)node.ReadValueFromMemory(selectedNode.Memory), 0);
@@ -619,11 +619,31 @@ private void searchForEqualValuesToolStripMenuItem_Click(object sender, EventArg
619619
comparer = new IntegerMemoryComparer(ScanCompareType.Equal, (int)node.ReadValueFromMemory(selectedNode.Memory), 0);
620620
break;
621621
case Int64Node node:
622-
comparer = new LongMemoryComparer(ScanCompareType.Equal, node.ReadValueFromMemory(selectedNode.Memory), 0);
622+
comparer = new LongMemoryComparer(ScanCompareType.Equal, node.ReadValueFromMemory(selectedNode.Memory), 0L);
623623
break;
624624
case UInt64Node node:
625-
comparer = new LongMemoryComparer(ScanCompareType.Equal, (long)node.ReadValueFromMemory(selectedNode.Memory), 0);
625+
comparer = new LongMemoryComparer(ScanCompareType.Equal, (long)node.ReadValueFromMemory(selectedNode.Memory), 0L);
626626
break;
627+
case NIntNode node:
628+
{
629+
var value = node.ReadValueFromMemory(selectedNode.Memory);
630+
#if RECLASSNET64
631+
comparer = new LongMemoryComparer(ScanCompareType.Equal, value.ToInt64(), 0L);
632+
#else
633+
comparer = new IntegerMemoryComparer(ScanCompareType.Equal, value.ToInt32(), 0);
634+
#endif
635+
break;
636+
}
637+
case NUIntNode node:
638+
{
639+
var value = node.ReadValueFromMemory(selectedNode.Memory);
640+
#if RECLASSNET64
641+
comparer = new LongMemoryComparer(ScanCompareType.Equal, (long)value.ToUInt64(), 0L);
642+
#else
643+
comparer = new IntegerMemoryComparer(ScanCompareType.Equal, (int)value.ToUInt32(), 0);
644+
#endif
645+
break;
646+
}
627647
case Utf8TextNode node:
628648
comparer = new StringMemoryComparer(node.ReadValueFromMemory(selectedNode.Memory), Encoding.UTF8, true);
629649
break;
@@ -716,7 +736,7 @@ private void shrinkClassToolStripMenuItem_Click(object sender, EventArgs e)
716736
}
717737
}
718738

719-
#endregion
739+
#endregion
720740

721741
private void MainForm_DragEnter(object sender, DragEventArgs e)
722742
{

ReClass.NET/Memory/MemoryBuffer.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Diagnostics.Contracts;
33
using System.Runtime.InteropServices;
44
using System.Text;
@@ -326,6 +326,20 @@ public IntPtr ReadIntPtr(int offset)
326326
#endif
327327
}
328328

329+
/// <summary>Reads a <see cref="UIntPtr"/> from the specific offset.</summary>
330+
/// <param name="offset">The offset into the data.</param>
331+
/// <returns>The data read as <see cref="UIntPtr"/> or 0 if the offset is outside the data.</returns>
332+
public UIntPtr ReadUIntPtr(int offset)
333+
{
334+
Contract.Requires(offset >= 0);
335+
336+
#if RECLASSNET64
337+
return (UIntPtr)ReadUInt64(offset);
338+
#else
339+
return (UIntPtr)ReadUInt32(offset);
340+
#endif
341+
}
342+
329343
#endregion
330344

331345
public string ReadString(Encoding encoding, int offset, int length)

ReClass.NET/Nodes/NIntNode.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Drawing;
3+
using System.Globalization;
4+
using ReClassNET.Controls;
5+
using ReClassNET.Extensions;
6+
using ReClassNET.Memory;
7+
using ReClassNET.UI;
8+
9+
namespace ReClassNET.Nodes
10+
{
11+
public class NIntNode : BaseNumericNode
12+
{
13+
public override int MemorySize => IntPtr.Size;
14+
15+
public override void GetUserInterfaceInfo(out string name, out Image icon)
16+
{
17+
name = "NInt";
18+
icon = Properties.Resources.B16x16_Button_NInt;
19+
}
20+
21+
public override Size Draw(DrawContext context, int x, int y)
22+
{
23+
var value = ReadValueFromMemory(context.Memory)
24+
#if RECLASSNET64
25+
.ToInt64();
26+
#else
27+
.ToInt32();
28+
#endif
29+
return DrawNumeric(context, x, y, context.IconProvider.Signed, "NInt", value.ToString(), $"0x{value:X}");
30+
}
31+
32+
public override void Update(HotSpot spot)
33+
{
34+
base.Update(spot);
35+
36+
if (spot.Id == 0 || spot.Id == 1)
37+
{
38+
#if RECLASSNET64
39+
if (long.TryParse(spot.Text, out var val) || spot.Text.TryGetHexString(out var hexValue) && long.TryParse(hexValue, NumberStyles.HexNumber, null, out val))
40+
{
41+
spot.Process.WriteRemoteMemory(spot.Address, val);
42+
}
43+
#else
44+
if (int.TryParse(spot.Text, out var val) || spot.Text.TryGetHexString(out var hexValue) && int.TryParse(hexValue, NumberStyles.HexNumber, null, out val))
45+
{
46+
spot.Process.WriteRemoteMemory(spot.Address, val);
47+
}
48+
#endif
49+
}
50+
}
51+
52+
public IntPtr ReadValueFromMemory(MemoryBuffer memory)
53+
{
54+
return memory.ReadIntPtr(Offset);
55+
}
56+
}
57+
}

ReClass.NET/Nodes/NUIntNode.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Drawing;
3+
using System.Globalization;
4+
using ReClassNET.Controls;
5+
using ReClassNET.Extensions;
6+
using ReClassNET.Memory;
7+
using ReClassNET.UI;
8+
9+
namespace ReClassNET.Nodes
10+
{
11+
public class NUIntNode : BaseNumericNode
12+
{
13+
public override int MemorySize => UIntPtr.Size;
14+
15+
public override void GetUserInterfaceInfo(out string name, out Image icon)
16+
{
17+
name = "NUInt";
18+
icon = Properties.Resources.B16x16_Button_NUInt;
19+
}
20+
21+
public override Size Draw(DrawContext context, int x, int y)
22+
{
23+
var value = ReadValueFromMemory(context.Memory)
24+
#if RECLASSNET64
25+
.ToUInt64();
26+
#else
27+
.ToUInt32();
28+
#endif
29+
return DrawNumeric(context, x, y, context.IconProvider.Unsigned, "NUInt", value.ToString(), $"0x{value:X}");
30+
}
31+
32+
public override void Update(HotSpot spot)
33+
{
34+
base.Update(spot);
35+
36+
if (spot.Id == 0 || spot.Id == 1)
37+
{
38+
#if RECLASSNET64
39+
if (ulong.TryParse(spot.Text, out var val) || spot.Text.TryGetHexString(out var hexValue) && ulong.TryParse(hexValue, NumberStyles.HexNumber, null, out val))
40+
{
41+
spot.Process.WriteRemoteMemory(spot.Address, val);
42+
}
43+
#else
44+
if (uint.TryParse(spot.Text, out var val) || spot.Text.TryGetHexString(out var hexValue) && uint.TryParse(hexValue, NumberStyles.HexNumber, null, out val))
45+
{
46+
spot.Process.WriteRemoteMemory(spot.Address, val);
47+
}
48+
#endif
49+
}
50+
}
51+
52+
public UIntPtr ReadValueFromMemory(MemoryBuffer memory)
53+
{
54+
return memory.ReadUIntPtr(Offset);
55+
}
56+
}
57+
}

ReClass.NET/Project/CppTypeMapping.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Xml.Linq;
1+
using System.Xml.Linq;
22
using ReClassNET.Util;
33

44
namespace ReClassNET.Project
@@ -11,11 +11,13 @@ public class CppTypeMapping
1111
public string TypeInt16 { get; set; } = "int16_t";
1212
public string TypeInt32 { get; set; } = "int32_t";
1313
public string TypeInt64 { get; set; } = "int64_t";
14+
public string TypeNInt { get; set; } = "ptrdiff_t";
1415

1516
public string TypeUInt8 { get; set; } = "uint8_t";
1617
public string TypeUInt16 { get; set; } = "uint16_t";
1718
public string TypeUInt32 { get; set; } = "uint32_t";
1819
public string TypeUInt64 { get; set; } = "uint64_t";
20+
public string TypeNUInt { get; set; } = "size_t";
1921

2022
public string TypeFloat { get; set; } = "float";
2123
public string TypeDouble { get; set; } = "double";
@@ -43,10 +45,12 @@ internal XElement Serialize(string name)
4345
XElementSerializer.ToXml(nameof(TypeInt16), TypeInt16),
4446
XElementSerializer.ToXml(nameof(TypeInt32), TypeInt32),
4547
XElementSerializer.ToXml(nameof(TypeInt64), TypeInt64),
48+
XElementSerializer.ToXml(nameof(TypeNInt), TypeNInt),
4649
XElementSerializer.ToXml(nameof(TypeUInt8), TypeUInt8),
4750
XElementSerializer.ToXml(nameof(TypeUInt16), TypeUInt16),
4851
XElementSerializer.ToXml(nameof(TypeUInt32), TypeUInt32),
4952
XElementSerializer.ToXml(nameof(TypeUInt64), TypeUInt64),
53+
XElementSerializer.ToXml(nameof(TypeNUInt), TypeNUInt),
5054
XElementSerializer.ToXml(nameof(TypeFloat), TypeFloat),
5155
XElementSerializer.ToXml(nameof(TypeDouble), TypeDouble),
5256
XElementSerializer.ToXml(nameof(TypeVector2), TypeVector2),
@@ -69,10 +73,12 @@ internal void Deserialize(XElement element)
6973
XElementSerializer.TryRead(element, nameof(TypeInt16), e => TypeInt16 = XElementSerializer.ToString(e));
7074
XElementSerializer.TryRead(element, nameof(TypeInt32), e => TypeInt32 = XElementSerializer.ToString(e));
7175
XElementSerializer.TryRead(element, nameof(TypeInt64), e => TypeInt64 = XElementSerializer.ToString(e));
76+
XElementSerializer.TryRead(element, nameof(TypeNInt), e => TypeNInt = XElementSerializer.ToString(e));
7277
XElementSerializer.TryRead(element, nameof(TypeUInt8), e => TypeUInt8 = XElementSerializer.ToString(e));
7378
XElementSerializer.TryRead(element, nameof(TypeUInt16), e => TypeUInt16 = XElementSerializer.ToString(e));
7479
XElementSerializer.TryRead(element, nameof(TypeUInt32), e => TypeUInt32 = XElementSerializer.ToString(e));
7580
XElementSerializer.TryRead(element, nameof(TypeUInt64), e => TypeUInt64 = XElementSerializer.ToString(e));
81+
XElementSerializer.TryRead(element, nameof(TypeNUInt), e => TypeNUInt = XElementSerializer.ToString(e));
7682
XElementSerializer.TryRead(element, nameof(TypeFloat), e => TypeFloat = XElementSerializer.ToString(e));
7783
XElementSerializer.TryRead(element, nameof(TypeDouble), e => TypeDouble = XElementSerializer.ToString(e));
7884
XElementSerializer.TryRead(element, nameof(TypeVector2), e => TypeVector2 = XElementSerializer.ToString(e));

ReClass.NET/Properties/Resources.Designer.cs

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ReClass.NET/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,10 @@
511511
<data name="B16x16_Button_Union" type="System.Resources.ResXFileRef, System.Windows.Forms">
512512
<value>..\Resources\Images\B16x16_Button_Union.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
513513
</data>
514+
<data name="B16x16_Button_NInt" type="System.Resources.ResXFileRef, System.Windows.Forms">
515+
<value>..\Resources\Images\B16x16_Button_NInt.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
516+
</data>
517+
<data name="B16x16_Button_NUInt" type="System.Resources.ResXFileRef, System.Windows.Forms">
518+
<value>..\Resources\Images\B16x16_Button_NUInt.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
519+
</data>
514520
</root>

0 commit comments

Comments
 (0)