/// <summary> /// Writes your own memory address into process' memory and gives you the address address /// for the memory location to use directly functions accepting indirect jumps. /// </summary> /// <param name="addressIntPtr">The address the return address address will point to.</param> /// <returns>Pointer to the passed in address to memory.</returns> public static IntPtr Add(IntPtr addressIntPtr) { // Know what to do SizeCheckResult allocationAction = CheckItemSize(IntPtr.Size); // IntPtr can't be larger than a page (until we get 4096+ bit CPUs), do not check dedicated page. // Allocate new page first if necessary. if (allocationAction == SizeCheckResult.MakeNewPage) { AllocateNewPage(); } // Append to page. return(AppendToPage(addressIntPtr)); }
/// <summary> /// Writes your own memory address into process' memory and gives you the address address /// for the memory location to use directly functions accepting indirect jumps. /// </summary> /// <param name="bytesToWrite">The individual bytes to be written to memory.</param> /// <returns>Pointer to the passed in bytes written to memory.</returns> public static IntPtr Add(byte[] bytesToWrite) { // Know what to do SizeCheckResult allocationAction = CheckItemSize(bytesToWrite.Length); // If the result is that the byte array is too large, allocate the array its own pages as necessary // and write the buffer to the newly allocated pages. if (allocationAction == SizeCheckResult.MakeDedicatedPages) { IntPtr newBufferAddress = Bindings.TargetProcess.AllocateMemory(bytesToWrite.Length); Bindings.TargetProcess.WriteMemoryExternal(newBufferAddress, bytesToWrite); return(newBufferAddress); } else { // Allocate new page first if necessary. if (allocationAction == SizeCheckResult.MakeNewPage) { AllocateNewPage(); } return(AppendToPage(bytesToWrite)); } }