Beispiel #1
0
        /// <summary>
        ///   Reads _count bytes from specified process memory
        /// </summary>
        /// <param name="_hProcess">Opened process handle</param>
        /// <param name="_targetAddress">Address to read from</param>
        /// <param name="_count">Bytes count to read</param>
        /// <returns></returns>
        public static byte[] ReadBytes(IntPtr _hProcess, IntPtr _targetAddress, int _count)
        {
            if (_hProcess == IntPtr.Zero)
            {
                throw new Exception("Target process handle == IntPtr.Zero, open process first");
            }
            var ret = new byte[_count];
            int numRead;

            if (OnyxNative.ReadProcessMemory(_hProcess, _targetAddress, ret, _count, out numRead) && numRead == _count)
            {
                return(ret);
            }
            else
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }