Skip to content

Commit

Permalink
Changed parameter name allocationSize back to size.
Browse files Browse the repository at this point in the history
  • Loading branch information
KulaGGin committed Jan 6, 2020
1 parent ac00ce7 commit 0681a65
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Memory/memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ public void InjectDLL(String strDLLName)
/// <remarks>Please ensure that you use the proper replaceCount
/// if you replace halfway in an instruction you may cause bad things</remarks>
/// <returns>UIntPtr to created code cave for use for later deallocation</returns>
public UIntPtr CreateCodeCave(string code, byte[] newBytes, int replaceCount, int allocationSize = 0x1000, string file = "")
public UIntPtr CreateCodeCave(string code, byte[] newBytes, int replaceCount, int size = 0x1000, string file = "")
{
if (replaceCount < 5)
return UIntPtr.Zero; // returning UIntPtr.Zero instead of throwing an exception
Expand All @@ -1466,16 +1466,16 @@ public UIntPtr CreateCodeCave(string code, byte[] newBytes, int replaceCount, in

for(var i = 0; i < 10 && caveAddress == UIntPtr.Zero; i++)
{
caveAddress = VirtualAllocEx(pHandle, FindFreeBlockForRegion(prefered, (uint)allocationSize),
(uint)allocationSize, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
caveAddress = VirtualAllocEx(pHandle, FindFreeBlockForRegion(prefered, (uint)size),
(uint)size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);

if (caveAddress == UIntPtr.Zero)
prefered = UIntPtr.Add(prefered, 0x10000);
}

// Failed to allocate memory around the address we wanted let windows handle it and hope for the best?
if (caveAddress == UIntPtr.Zero)
caveAddress = VirtualAllocEx(pHandle, UIntPtr.Zero, (uint)allocationSize, MEM_COMMIT | MEM_RESERVE,
caveAddress = VirtualAllocEx(pHandle, UIntPtr.Zero, (uint)size, MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);

int nopsNeeded = replaceCount > 5 ? replaceCount - 5 : 0;
Expand Down

0 comments on commit 0681a65

Please sign in to comment.