Skip to content

Add uintptr_t and intptr_t data types (#134) #145

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

Closed
wants to merge 5 commits into from
Closed
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
6 changes: 4 additions & 2 deletions ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ namespace ReClassNET.CodeGenerator
{
public class CSharpCodeGenerator : ICodeGenerator
{
private static readonly Dictionary<Type, string> nodeTypeToTypeDefinationMap = new Dictionary<Type, string>
{
private static readonly Dictionary<Type, string> nodeTypeToTypeDefinationMap = new Dictionary<Type, string> {
[typeof(DoubleNode)] = "double",
[typeof(FloatNode)] = "float",
[typeof(BoolNode)] = "bool",
[typeof(Int8Node)] = "sbyte",
[typeof(Int16Node)] = "short",
[typeof(Int32Node)] = "int",
[typeof(Int64Node)] = "long",
[typeof(IntPtrNode)] = "IntPtr",
[typeof(UInt8Node)] = "byte",
[typeof(UInt16Node)] = "ushort",
[typeof(UInt32Node)] = "uint",
[typeof(UInt64Node)] = "ulong",
[typeof(UIntPtrNode)] = "UIntPtr",

[typeof(FunctionPtrNode)] = "IntPtr",
[typeof(Utf8TextPtrNode)] = "IntPtr",
Expand All @@ -51,6 +52,7 @@ public string GenerateCode(IReadOnlyList<ClassNode> classes, IReadOnlyList<EnumD
iw.WriteLine();
iw.WriteLine("// Warning: The C# code generator doesn't support all node types!");
iw.WriteLine();
iw.WriteLine("using System;");
iw.WriteLine("using System.Runtime.InteropServices;");

iw.WriteLine("// optional namespace, only for vectors");
Expand Down
5 changes: 3 additions & 2 deletions ReClass.NET/CodeGenerator/CppCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ private class Utf32CharacterNode : BaseNode

public CppCodeGenerator(CppTypeMapping typeMapping)
{
nodeTypeToTypeDefinationMap = new Dictionary<Type, string>
{
nodeTypeToTypeDefinationMap = new Dictionary<Type, string> {
[typeof(BoolNode)] = typeMapping.TypeBool,
[typeof(DoubleNode)] = typeMapping.TypeDouble,
[typeof(FloatNode)] = typeMapping.TypeFloat,
Expand All @@ -136,13 +135,15 @@ public CppCodeGenerator(CppTypeMapping typeMapping)
[typeof(Int16Node)] = typeMapping.TypeInt16,
[typeof(Int32Node)] = typeMapping.TypeInt32,
[typeof(Int64Node)] = typeMapping.TypeInt64,
[typeof(IntPtrNode)] = typeMapping.TypeIntPtr,
[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(UIntPtrNode)] = typeMapping.TypeUIntPtr,
[typeof(Utf8CharacterNode)] = typeMapping.TypeUtf8Text,
[typeof(Utf16CharacterNode)] = typeMapping.TypeUtf16Text,
[typeof(Utf32CharacterNode)] = typeMapping.TypeUtf32Text,
Expand Down
2 changes: 2 additions & 0 deletions ReClass.NET/DataExchange/ReClass/ReClassNetFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ static ReClassNetFile()
typeof(Int16Node),
typeof(Int32Node),
typeof(Int64Node),
typeof(IntPtrNode),
typeof(Matrix3x3Node),
typeof(Matrix3x4Node),
typeof(Matrix4x4Node),
typeof(UInt8Node),
typeof(UInt16Node),
typeof(UInt32Node),
typeof(UInt64Node),
typeof(UIntPtrNode),
typeof(Utf8TextNode),
typeof(Utf8TextPtrNode),
typeof(Utf16TextNode),
Expand Down
2,464 changes: 1,232 additions & 1,232 deletions ReClass.NET/Forms/MainForm.Designer.cs

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions ReClass.NET/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ private void selectedNodeContextMenuStrip_Opening(object sender, CancelEventArgs
case UInt32Node _:
case Int64Node _:
case UInt64Node _:
case IntPtrNode _:
case UIntPtrNode _:
case Utf8TextNode _:
case Utf16TextNode _:
case Utf32TextNode _:
Expand Down Expand Up @@ -617,6 +619,12 @@ private void searchForEqualValuesToolStripMenuItem_Click(object sender, EventArg
case UInt64Node node:
comparer = new LongMemoryComparer(ScanCompareType.Equal, (long)node.ReadValueFromMemory(selectedNode.Memory), 0);
break;
case UIntPtrNode node:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not correct? If you have a x86 process it should be an IntegerMemoryComparer and not the 64bit LongMemoryComparer.

comparer = new LongMemoryComparer(ScanCompareType.Equal, (long)node.ReadValueFromMemory(selectedNode.Memory), 0);
break;
case IntPtrNode node:
comparer = new LongMemoryComparer(ScanCompareType.Equal, node.ReadValueFromMemory(selectedNode.Memory).ToInt64(), 0);
break;
case Utf8TextNode node:
comparer = new StringMemoryComparer(node.ReadValueFromMemory(selectedNode.Memory), Encoding.UTF8, true);
break;
Expand Down
2,098 changes: 1,071 additions & 1,027 deletions ReClass.NET/Forms/SettingsForm.Designer.cs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions ReClass.NET/Forms/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ private void SetTypedefinitionBindings()
SetBinding(int16TypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeInt16));
SetBinding(int32TypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeInt32));
SetBinding(int64TypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeInt64));
SetBinding(intPtrTypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeIntPtr));
SetBinding(uint8TypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeUInt8));
SetBinding(uint16TypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeUInt16));
SetBinding(uint32TypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeUInt32));
SetBinding(uint64TypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeUInt64));
SetBinding(uintPtrTypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeUIntPtr));
SetBinding(floatTypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeFloat));
SetBinding(doubleTypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeDouble));
SetBinding(vector2TypeTextBox, nameof(TextBox.Text), typeMapping, nameof(CppTypeMapping.TypeVector2));
Expand Down
14 changes: 14 additions & 0 deletions ReClass.NET/Memory/MemoryBuffer.cs
Original file line number Diff line number Diff line change
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)ReadInt64(offset);
#else
return (UIntPtr)ReadUInt32(offset);
#endif
}

#endregion

public string ReadString(Encoding encoding, int offset, int length)
Expand Down
5 changes: 4 additions & 1 deletion ReClass.NET/Nodes/Hex64Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public override string GetToolTipText(HotSpot spot)
{
var value = spot.Memory.ReadObject<UInt64FloatDoubleData>(Offset);

return $"Int64: {value.LongValue}\nUInt64: 0x{value.ULongValue:X016}\nFloat: {value.FloatValue:0.000}\nDouble: {value.DoubleValue:0.000}";
return @$"Int64: {value.LongValue}
UInt64: 0x{value.ULongValue:X016}
Float: {value.FloatValue:0.000}
Double: {value.DoubleValue:0.000}";
}

public override Size Draw(ViewInfo view, int x, int y)
Expand Down
54 changes: 54 additions & 0 deletions ReClass.NET/Nodes/IntPtrNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Drawing;
using System.Globalization;
using ReClassNET.Extensions;
using ReClassNET.Memory;
using ReClassNET.UI;

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

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

public override Size Draw(ViewInfo view, int x, int y)
{
var value = ReadValueFromMemory(view.Memory);
return DrawNumeric(view, x, y, Icons.Signed, "IntPtr", value.ToString(), $"0x{value.ToString("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, (IntPtr)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, (UIntPtr)val);
}
#endif
}
}

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

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

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

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

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, (UIntPtr)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, (UIntPtr)val);
}
#endif
}
}

public UIntPtr ReadValueFromMemory(MemoryBuffer memory)
{
return memory.ReadUIntPtr(Offset);
}
}
}
7 changes: 7 additions & 0 deletions ReClass.NET/Project/CppTypeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ namespace ReClassNET.Project
public class CppTypeMapping
{
public string TypeBool { get; set; } = "bool";
public string TypeSize { get; set; } = "size_t";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type is never used.


public string TypeInt8 { get; set; } = "int8_t";
public string TypeInt16 { get; set; } = "int16_t";
public string TypeInt32 { get; set; } = "int32_t";
public string TypeInt64 { get; set; } = "int64_t";
public string TypeIntPtr { get; set; } = "intptr_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 TypeUIntPtr { get; set; } = "uintptr_t";

public string TypeFloat { get; set; } = "float";
public string TypeDouble { get; set; } = "double";
Expand Down Expand Up @@ -43,10 +46,12 @@ internal XElement Serialize(string name)
XElementSerializer.ToXml(nameof(TypeInt16), TypeInt16),
XElementSerializer.ToXml(nameof(TypeInt32), TypeInt32),
XElementSerializer.ToXml(nameof(TypeInt64), TypeInt64),
XElementSerializer.ToXml(nameof(TypeIntPtr), TypeIntPtr),
XElementSerializer.ToXml(nameof(TypeUInt8), TypeUInt8),
XElementSerializer.ToXml(nameof(TypeUInt16), TypeUInt16),
XElementSerializer.ToXml(nameof(TypeUInt32), TypeUInt32),
XElementSerializer.ToXml(nameof(TypeUInt64), TypeUInt64),
XElementSerializer.ToXml(nameof(TypeUIntPtr), TypeUIntPtr),
XElementSerializer.ToXml(nameof(TypeFloat), TypeFloat),
XElementSerializer.ToXml(nameof(TypeDouble), TypeDouble),
XElementSerializer.ToXml(nameof(TypeVector2), TypeVector2),
Expand All @@ -69,10 +74,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(TypeIntPtr), e => TypeIntPtr = 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(TypeUIntPtr), e => TypeUIntPtr = 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_Int_Ptr" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Images\B16x16_Button_Int_Ptr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="B16x16_Button_UInt_Ptr" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Images\B16x16_Button_UInt_Ptr.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
8 changes: 8 additions & 0 deletions ReClass.NET/ReClass.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,10 @@
<Compile Include="Nodes\ClassUtil.cs" />
<Compile Include="Nodes\EnumNode.cs" />
<Compile Include="Nodes\FunctionNode.cs" />
<Compile Include="Nodes\IntPtrNode.cs" />
<Compile Include="Nodes\NodeUuid.cs" />
<Compile Include="Nodes\PointerNode.cs" />
<Compile Include="Nodes\UIntPtrNode.cs" />
<Compile Include="Nodes\UnionNode.cs" />
<Compile Include="Project\CppTypeMapping.cs" />
<Compile Include="Project\EnumDescription.cs" />
Expand Down Expand Up @@ -1009,6 +1011,12 @@
<ItemGroup>
<None Include="Resources\Images\B16x16_Button_Union.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Images\B16x16_Button_Int_Ptr.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Images\B16x16_Button_UInt_Ptr.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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading