WriteProcessMemory() 개인적인 메소드

private WriteProcessMemory ( IntPtr hProcess, UInt32 lpBaseAddress, IntPtr lpSrc, uint nSize, int &lpNumberOfBytesWritten ) : int
hProcess System.IntPtr
lpBaseAddress System.UInt32
lpSrc System.IntPtr
nSize uint
lpNumberOfBytesWritten int
리턴 int
예제 #1
0
        public unsafe int Write(SafeProcessHandle handle, uint offset, uint size, byte *data)
        {
            if (Address == IntPtr.Zero)
            {
                throw new ObjectDisposedException("RemoteMemoryRegion");
            }
            if ((offset + size) > Size)
            {
                throw new ArgumentException("Size too large for region");
            }

            int bytesWritten = 0;
            int result       = Win32.WriteProcessMemory(
                handle.DangerousGetHandle(),
                (uint)(Address.ToInt64() + offset),
                new IntPtr(data), size, out bytesWritten
                );

            if (result == 0 || bytesWritten != size)
            {
                var error = Win32.GetLastError();
                throw new Exception(String.Format("Write failed: Error {0:x8}", error));
            }

            return(bytesWritten);
        }