Skip to content

Commit 805d618

Browse files
committed
Added IntPtr.ToInt64Bits.
1 parent 1e92aba commit 805d618

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

ReClass.NET/Extensions/IntPtrExtensions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,34 @@ public static int CompareToRange(this IntPtr address, IntPtr start, IntPtr end)
115115
}
116116
return CompareTo(address, start);
117117
}
118+
119+
/// <summary>
120+
/// Changes the behaviour of ToInt64 in x86 mode.
121+
/// IntPtr(int.MaxValue + 1) = (int)0x80000000 (-2147483648) = (long)0xFFFFFFFF80000000
122+
/// This method converts the value to (long)0x0000000080000000 (2147483648).
123+
/// </summary>
124+
/// <param name="ptr"></param>
125+
/// <returns></returns>
126+
[Pure]
127+
[DebuggerStepThrough]
128+
public static long ToInt64Bits(this IntPtr ptr)
129+
{
130+
#if RECLASSNET64
131+
return ptr.ToInt64();
132+
#else
133+
var value = ptr.ToInt64();
134+
135+
if (value < 0)
136+
{
137+
var intValue = ptr.ToInt32();
138+
if (value == intValue)
139+
{
140+
value = intValue & 0xFFFFFFFFL;
141+
}
142+
}
143+
144+
return value;
145+
#endif
146+
}
118147
}
119148
}

0 commit comments

Comments
 (0)