public static IntPtr CreateRemotePointer(IntPtr hProcess, byte[] pData, int flProtect) { if (pData == null || hProcess == IntPtr.Zero) { return(IntPtr.Zero); } IntPtr lpAddress = PInvoke.VirtualAllocEx(hProcess, IntPtr.Zero, (uint)pData.Length, 12288, flProtect); if (lpAddress != IntPtr.Zero && PInvoke.WriteProcessMemory(hProcess, lpAddress, pData, pData.Length, out uint lpNumberOfBytesRead) && lpNumberOfBytesRead == pData.Length || lpAddress == IntPtr.Zero) { return(lpAddress); } PInvoke.VirtualFreeEx(hProcess, lpAddress, 0, 32768); lpAddress = IntPtr.Zero; return(lpAddress); }