Exemplo n.º 1
0
        /// <summary>
        ///     Allocates a block of memory in the target process.
        /// </summary>
        /// <param name="_hProcess">Handle to the process in which memory will be allocated.</param>
        /// <param name="_bytesCount">Number of bytes to be allocated.  Default is 0x1000.</param>
        /// <param name="_allocationType">The type of memory allocation.  See <see cref="OnyxNative.MemoryAllocType" /></param>
        /// <param name="_protectType">
        ///     The memory protection for the region of pages to be allocated. If the pages are being
        ///     committed, you can specify any one of the <see cref="OnyxNative.MemoryProtectType" /> constants.
        /// </param>
        /// <returns>Returns zero on failure, or the base address of the allocated block of memory on success.</returns>
        public static IntPtr AllocateMemory(IntPtr _hProcess, uint _bytesCount, uint _allocationType, uint _protectType)
        {
            var result = OnyxNative.VirtualAllocEx(_hProcess, IntPtr.Zero, _bytesCount, _allocationType, _protectType);

            if (result == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
            return(result);
        }