WriteProcessMemory() private method

private WriteProcessMemory ( IntPtr process, IntPtr address, byte buffer, uint size, uint &written ) : bool
process System.IntPtr
address System.IntPtr
buffer byte
size uint
written uint
return bool
Beispiel #1
0
        /// <summary>
        ///     Writes memory at the address
        /// </summary>
        /// <param name="address">Memory address</param>
        /// <param name="buffer">Buffer</param>
        /// <param name="size">Size in bytes</param>
        public void WriteMemory(IntPtr address, byte[] buffer, int size)
        {
            if (isDisposed)
            {
                throw new ObjectDisposedException("Memory");
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (size <= 0)
            {
                throw new ArgumentException("Size must be greater than zero");
            }
            if (address == IntPtr.Zero)
            {
                throw new ArgumentException("Invalid address");
            }

            uint write = 0;

            if (!Win32.WriteProcessMemory(processHandle, address, buffer, (uint)size, ref write) ||
                write != size)
            {
                throw new AccessViolationException();
            }
        }