Skip to content

Commit

Permalink
prevent crashes in GetCode
Browse files Browse the repository at this point in the history
  • Loading branch information
erfg12 committed Apr 8, 2022
1 parent f1bf950 commit 63f7d4e
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions Memory/memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ public bool ChangeProtection(string code, MemoryProtection newProtection, out Me
public UIntPtr GetCode(string name, string path = "", int size = 8)
{
string theCode = "";
if (mProc == null)
return UIntPtr.Zero;

if (mProc.Is64Bit)
{
//Debug.WriteLine("Changing to 64bit code...");
Expand All @@ -377,7 +380,17 @@ public UIntPtr GetCode(string name, string path = "", int size = 8)
if (theCode.Contains(" "))
theCode = theCode.Replace(" ", String.Empty);

if (!theCode.Contains("+") && !theCode.Contains(",")) return new UIntPtr(Convert.ToUInt32(theCode, 16));
if (!theCode.Contains("+") && !theCode.Contains(","))
{
try
{
return new UIntPtr(Convert.ToUInt32(theCode, 16));
} catch
{
Console.WriteLine("Error in GetCode(). Failed to read address " + theCode);
return UIntPtr.Zero;
}
}

string newOffsets = theCode;

Expand Down Expand Up @@ -522,7 +535,17 @@ public UIntPtr Get64BitCode(string name, string path = "", int size = 16)

byte[] memoryAddress = new byte[size];

if (!theCode.Contains("+") && !theCode.Contains(",")) return new UIntPtr(Convert.ToUInt64(theCode, 16));
if (!theCode.Contains("+") && !theCode.Contains(","))
{
try {
return new UIntPtr(Convert.ToUInt64(theCode, 16));
}
catch
{
Console.WriteLine("Error in GetCode(). Failed to read address " + theCode);
return UIntPtr.Zero;
}
}

if (newOffsets.Contains(','))
{
Expand Down

0 comments on commit 63f7d4e

Please sign in to comment.