Ejemplo n.º 1
0
        public IntPtr AllocateMemory(int size, IntPtr nearThisAddr)
        {
            MemoryApi.MEMORY_BASIC_INFORMATION mbi;

            while (MemoryApi.VirtualQueryEx(ProcessHandle, nearThisAddr, out mbi, (uint)Marshal.SizeOf(typeof(MemoryApi.MEMORY_BASIC_INFORMATION))) != 0)
            {
                Console.WriteLine(mbi.BaseAddress.ToString("X"));
                if (mbi.State == MemoryApi.MEM_FREE)
                {
                    IntPtr addr = MemoryApi.VirtualAllocEx(ProcessHandle, mbi.BaseAddress, size, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);
                    if ((ulong)addr != 0)
                    {
                        return(addr);
                    }
                }
                nearThisAddr = (IntPtr)((ulong)nearThisAddr - (ulong)0x10000);
            }

            return(new IntPtr());
        }
Ejemplo n.º 2
0
 public IntPtr AllocateMemory(int size)
 {
     return(MemoryApi.VirtualAllocEx(ProcessHandle, new IntPtr(), size, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite));
 }