コード例 #1
0
        /// <summary>
        /// Frees an allocated block of memory in the opened process.
        /// </summary>
        /// <param name="address">Base address of the block of memory to be freed.</param>
        /// <param name="size">Number of bytes to be freed.  This must be zero (0) if using <see cref="MemoryFreeType.MEM_RELEASE"/>.</param>
        /// <param name="freeType">Type of free operation to use.  See <see cref="MemoryFreeType"/>.</param>
        /// <returns>Returns true on success, false on failure.</returns>
        public bool FreeMemory(IntPtr address, int size, MemoryFreeType freeType)
        {
            if (freeType == MemoryFreeType.MEM_RELEASE)
                size = 0;

            return Imports.VirtualFreeEx(ProcessHandle, address, size, freeType);
        }
コード例 #2
0
        /// <summary>
        /// Releases, decommits, or releases and decommits a region of memory within the virtual address space of a specified process.
        /// </summary>
        /// <param name="hProcess">Handle to the process in which memory will be freed.</param>
        /// <param name="dwAddress">A pointer to the starting address of the region of memory to be freed. </param>
        /// <param name="nSize">
        /// The size of the region of memory to free, in bytes.
        ///
        /// If the dwFreeType parameter is MEM_RELEASE, dwSize must be 0 (zero). The function frees the entire region that is reserved in the initial allocation call to VirtualAllocEx.</param>
        /// <param name="dwFreeType">The type of free operation.  See <see cref="MemoryFreeType"/>.</param>
        /// <returns>Returns true on success, false on failure.</returns>
        public static bool FreeMemory(IntPtr hProcess, uint dwAddress, int nSize, MemoryFreeType dwFreeType)
        {
            if (dwFreeType == MemoryFreeType.MEM_RELEASE)
            {
                nSize = 0;
            }

            return(Imports.VirtualFreeEx(hProcess, dwAddress, nSize, dwFreeType));
        }
コード例 #3
0
        /// <summary>
        ///     Frees an allocated block of memory in the opened process.
        /// </summary>
        /// <param name="address">Base address of the block of memory to be freed.</param>
        /// <param name="size">
        ///     Number of bytes to be freed.  This must be zero (0) if using
        ///     <see cref="MemoryFreeType.MEM_RELEASE" />.
        /// </param>
        /// <param name="freeType">Type of free operation to use.  See <see cref="MemoryFreeType" />.</param>
        /// <returns>Returns true on success, false on failure.</returns>
        internal bool FreeMemory(IntPtr address, int size, MemoryFreeType freeType)
        {
            if (freeType == MemoryFreeType.MEM_RELEASE)
            {
                size = 0;
            }

            return(Imports.VirtualFreeEx(ProcessHandle, address, size, freeType));
        }
コード例 #4
0
 public static bool Free(IntPtr address, int size = 0, MemoryFreeType free = MemoryFreeType.MEM_RELEASE)
 {
     if (!Imports.VirtualFree(address, size, free))
     {
         throw new Win32Exception($"[Win32 Error: {Marshal.GetLastWin32Error()}] " +
                                  $"Unable to free memory at 0x{address.ToString($"X{IntPtr.Size}")}[Size: {size}]");
     }
     return(true);
 }
コード例 #5
0
            /// <summary>
            /// Releases, decommits, or releases and decommits a region of pages within the virtual address space of the calling process.
            /// </summary>
            /// <param name="lpAddress">
            /// A pointer to the base address of the region of pages to be freed.
            /// If the dwFreeType parameter is MEM_RELEASE, this parameter must be the base address returned by the VirtualAlloc function when the region of pages is reserved.
            /// </param>
            /// <param name="dwSize">
            /// The size of the region of memory to be freed, in bytes.
            /// If the dwFreeType parameter is MEM_RELEASE, this parameter must be 0 (zero).
            /// The function frees the entire region that is reserved in the initial allocation call to VirtualAlloc.
            /// If the dwFreeType parameter is MEM_DECOMMIT, the function decommits all memory pages that contain one or more bytes in the range from the lpAddress parameter to (lpAddress+dwSize).
            /// This means, for example, that a 2-byte region of memory that straddles a page boundary causes both pages to be decommitted.
            /// If lpAddress is the base address returned by VirtualAlloc and dwSize is 0 (zero), the function decommits the entire region that is allocated by VirtualAlloc.
            /// After that, the entire region is in the reserved state.
            /// </param>
            /// <param name="dwFreeType">
            /// The type of free operation.
            /// </param>
            /// <returns>
            /// If the function succeeds, the return value is nonzero.
            /// If the function fails, the return value is 0 (zero). To get extended error information, call GetLastError.
            /// </returns>
            public static void VirtualFree(IntPtr lpAddress, IntPtr dwSize, MemoryFreeType dwFreeType)
            {
                if ((dwFreeType & MemoryFreeType.MemDecommit) != 0 && (dwFreeType & MemoryFreeType.MemRelease) != 0)
                {
                    throw new InvalidOperationException("Do not use " + nameof(MemoryFreeType.MemDecommit) + " and " + nameof(MemoryFreeType.MemRelease) + " together.");
                }

                VirtualFreeInterop(lpAddress, dwSize, dwFreeType);
            }
コード例 #6
0
        public static bool Free(IntPtr address, int size = 0, MemoryFreeType free = MemoryFreeType.MEM_RELEASE)
        {
            if (!Imports.VirtualFree(address, size, free))
            {
                throw new Win32Exception(string.Format("[Error Code: {0}] Unable to free memory at 0x{1}[Size: {2}]",
                                                       Marshal.GetLastWin32Error(), address.ToString($"X{IntPtr.Size}"), size));
            }

            return(true);
        }
コード例 #7
0
        /// <summary>
        /// Free virtual emmory in a process.
        /// </summary>
        /// <param name="process">The process to free in.</param>
        /// <param name="base_address">Base address of region to free</param>
        /// <param name="region_size">The size of the region.</param>
        /// <param name="free_type">The type to free.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <exception cref="NtException">Thrown on error.</exception>
        public static NtStatus FreeMemory(SafeKernelObjectHandle process,
                                          long base_address, long region_size, MemoryFreeType free_type,
                                          bool throw_on_error)
        {
            IntPtr base_address_ptr = new IntPtr(base_address);
            IntPtr region_size_ptr  = new IntPtr(region_size);

            return(NtSystemCalls.NtFreeVirtualMemory(process, ref base_address_ptr,
                                                     ref region_size_ptr, free_type).ToNtException(throw_on_error));
        }
コード例 #8
0
        public static bool Free(SafeMemoryHandle processHandle, IntPtr address, int size = 0,
                                MemoryFreeType free = MemoryFreeType.MEM_RELEASE)
        {
            if (!Imports.VirtualFreeEx(processHandle, address, size, free))
            {
                throw new Win32Exception(string.Format(
                                             "[Error Code: {0}] Unable to free memory from process handle 0x{1} at 0x{2}[Size: {3}]",
                                             Marshal.GetLastWin32Error(), processHandle.DangerousGetHandle().ToString("X"),
                                             address.ToString($"X{IntPtr.Size}"), size));
            }

            return(true);
        }
コード例 #9
0
 public static bool Free(SafeMemoryHandle processHandle, IntPtr address, int size = 0, MemoryFreeType free = MemoryFreeType.MEM_RELEASE)
 {
     if (!Imports.VirtualFreeEx(processHandle, address, size, free))
     {
         throw new Win32Exception($"[Win32 Error: {Marshal.GetLastWin32Error()}] " +
                                  $"Unable to free memory from process handle " +
                                  $"0x{processHandle.DangerousGetHandle().ToString("X")} at 0x{address.ToString($"X{IntPtr.Size}")}[Size: {size}]");
     }
     return(true);
 }
コード例 #10
0
ファイル: Imports.cs プロジェクト: zaafar/ExileApi
 internal static extern bool VirtualFree(IntPtr lpAddress, int nSize, MemoryFreeType dwFreeType);
コード例 #11
0
 /// <summary>
 /// Free virtual emmory in a process.
 /// </summary>
 /// <param name="process">The process to free in.</param>
 /// <param name="base_address">Base address of region to free</param>
 /// <param name="region_size">The size of the region.</param>
 /// <param name="free_type">The type to free.</param>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static void FreeMemory(SafeKernelObjectHandle process,
                               long base_address, long region_size, MemoryFreeType free_type)
 {
     FreeMemory(process, base_address, region_size, free_type, true);
 }
コード例 #12
0
 internal static extern bool VirtualFreeEx(SafeProcessHandle processHandle, IntPtr baseAddress, int freeSize, MemoryFreeType freeType);
コード例 #13
0
 public static extern bool VirtualFree(IntPtr address, int size, MemoryFreeType freeType);
コード例 #14
0
 internal static extern bool VirtualFree(
     IntPtr lpAddress,
     uint dwSize,
     MemoryFreeType flFreeType);
コード例 #15
0
ファイル: Kernel32.cs プロジェクト: Konard/LinksPlatform
 /// <summary>
 /// Releases, decommits, or releases and decommits a region of pages within the virtual address space of the calling process.
 /// </summary>
 /// <param name="block">A pointer to the base address of the region of pages to be freed.</param>
 /// <param name="sizeInBytes">The size of the region of memory to be freed, in bytes.</param>
 /// <param name="freeType">The type of free operation.</param>
 public static void VirtualFree(void* block, ulong sizeInBytes, MemoryFreeType freeType)
 {
     if (!VirtualFree(new IntPtr(block), new UIntPtr(sizeInBytes), freeType))
         throw new InvalidOperationException(Marshal.GetLastWin32Error().ToString());
 }
コード例 #16
0
 public static extern NtStatus NtFreeVirtualMemory(
     SafeKernelObjectHandle ProcessHandle,
     ref IntPtr BaseAddress,
     ref IntPtr RegionSize,
     MemoryFreeType FreeType
     );
コード例 #17
0
ファイル: Kernel.cs プロジェクト: gitter-badger/LinksPlatform
 public static extern bool VirtualFree(IntPtr blockAddress, UIntPtr sizeInBytes, MemoryFreeType freeType);
コード例 #18
0
 public static extern Boolean VirtualFree(IntPtr address, Int32 size, MemoryFreeType freeType);
コード例 #19
0
 public static extern bool VirtualFree(IntPtr lpAddress, UIntPtr dwSize, MemoryFreeType dwFreeType);
コード例 #20
0
 internal static extern Boolean VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, UInt32 dwSize, MemoryFreeType dwFreeType);
コード例 #21
0
 internal static extern bool VirtualFreeEx(SafeMemoryHandle hProcess, IntPtr dwAddress, int nSize,
                                           MemoryFreeType dwFreeType);
コード例 #22
0
 public static extern bool VirtualFreeEx(IntPtr hProcess, uint dwAddress, int nSize, MemoryFreeType dwFreeType);
コード例 #23
0
ファイル: Imports.cs プロジェクト: perstark/HBRelog
 internal static extern bool VirtualFreeEx(SafeMemoryHandle hProcess, IntPtr dwAddress, int nSize,
     MemoryFreeType dwFreeType);
コード例 #24
0
 private static extern bool VirtualFreeInterop(IntPtr lpAddress, IntPtr dwSize, MemoryFreeType dwFreeType);
コード例 #25
0
        /// <summary>
        /// Free virtual emmory in a process.
        /// </summary>
        /// <param name="process">The process to free in.</param>
        /// <param name="base_address">Base address of region to free</param>
        /// <param name="region_size">The size of the region.</param>
        /// <param name="free_type">The type to free.</param>
        /// <exception cref="NtException">Thrown on error.</exception>
        public static void FreeMemory(SafeKernelObjectHandle process, long base_address, long region_size, MemoryFreeType free_type)
        {
            IntPtr base_address_ptr = new IntPtr(base_address);
            IntPtr region_size_ptr  = new IntPtr(region_size);

            NtSystemCalls.NtFreeVirtualMemory(process, ref base_address_ptr, ref region_size_ptr, free_type).ToNtException();
        }
コード例 #26
0
ファイル: Kernel32.cs プロジェクト: TinkerWorX/SharpCraft
 public static extern Boolean VirtualFree(IntPtr address, Int32 size, MemoryFreeType freeType);
コード例 #27
0
 internal static extern bool VirtualFreeEx(IntPtr h, IntPtr addr, uint size, MemoryFreeType mem_type);
コード例 #28
0
ファイル: Win32Api.cs プロジェクト: argonlefou/DemulShooter
 public static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, UInt32 dwSize, MemoryFreeType dwFreeType);