From 891369805a94d41a27a9742797071901484ccb42 Mon Sep 17 00:00:00 2001 From: hollow87 Date: Fri, 19 Mar 2021 19:48:09 -0500 Subject: [PATCH] Implemented changes per @ArmYof0n3 in issue #100 --- Memory/memory.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Memory/memory.cs b/Memory/memory.cs index 40d4f66..8f483ea 100644 --- a/Memory/memory.cs +++ b/Memory/memory.cs @@ -1629,7 +1629,6 @@ public UIntPtr CreateCodeCave(string code, byte[] newBytes, int replaceCount, in { jmpBytes[i] = 0x90; } - WriteBytes(address, jmpBytes); byte[] caveBytes = new byte[5 + newBytes.Length]; offset = (int)(((long)address + jmpBytes.Length) - ((long)caveAddress + newBytes.Length) - 5); @@ -1639,6 +1638,7 @@ public UIntPtr CreateCodeCave(string code, byte[] newBytes, int replaceCount, in BitConverter.GetBytes(offset).CopyTo(caveBytes, newBytes.Length + 1); WriteBytes(caveAddress, caveBytes); + WriteBytes(address, jmpBytes); return caveAddress; } @@ -1739,10 +1739,10 @@ private UIntPtr FindFreeBlockForRegion(UIntPtr baseAddress, uint size) previous = current; current = UIntPtr.Add(mbi.BaseAddress, (int)mbi.RegionSize); - if ((long)current > (long)maxAddress) + if ((long)current >= (long)maxAddress) return ret; - if ((long)previous > (long)current) + if ((long)previous >= (long)current) return ret; // Overflow }