Exemple #1
0
        private void LoadRegions()
        {
            try
            {
                _regions = new List <UnsafeNativeMethods.MEMORY_BASIC_INFORMATION>();
                var address = new IntPtr();
                while (true)
                {
                    var info   = new UnsafeNativeMethods.MEMORY_BASIC_INFORMATION();
                    var result = UnsafeNativeMethods.VirtualQueryEx(MemoryHandler.Instance.ProcessHandle, address, out info, (uint)Marshal.SizeOf(info));
                    if (0 == result)
                    {
                        break;
                    }
                    if (!MemoryHandler.Instance.IsSystemModule(info.BaseAddress) && 0 != (info.State & MemCommit) && 0 != (info.Protect & Writable) && 0 == (info.Protect & PageGuard))
                    {
                        _regions.Add(info);
                    }
                    else
                    {
                        MemoryHandler.Instance.RaiseException(Logger, new Exception(info.ToString()));
                    }
                    unchecked
                    {
                        switch (IntPtr.Size)
                        {
                        case sizeof(int):
                            address = new IntPtr(info.BaseAddress.ToInt32() + info.RegionSize.ToInt32());
                            break;

                        default:
                            address = new IntPtr(info.BaseAddress.ToInt64() + info.RegionSize.ToInt64());
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MemoryHandler.Instance.RaiseException(Logger, ex, true);
            }
        }
Exemple #2
0
        private void LoadRegions()
        {
            try {
                this._regions = new List <UnsafeNativeMethods.MEMORY_BASIC_INFORMATION>();
                IntPtr address = IntPtr.Zero;
                while (true)
                {
                    UnsafeNativeMethods.MEMORY_BASIC_INFORMATION info = new UnsafeNativeMethods.MEMORY_BASIC_INFORMATION();
                    int result = UnsafeNativeMethods.VirtualQueryEx(this._memoryHandler.ProcessHandle, address, out info, (uint)Marshal.SizeOf(info));
                    if (result == 0)
                    {
                        break;
                    }

                    if (!this._memoryHandler.IsSystemModule(info.BaseAddress) && (info.State & MemCommit) != 0 && (info.Protect & Writable) != 0 && (info.Protect & PageGuard) == 0)
                    {
                        this._regions.Add(info);
                    }
                    else
                    {
                        this._memoryHandler.RaiseException(Logger, new Exception(info.ToString()));
                    }

                    unchecked {
                        switch (IntPtr.Size)
                        {
                        case sizeof(int):
                            address = new IntPtr(info.BaseAddress.ToInt32() + info.RegionSize.ToInt32());
                            break;

                        default:
                            address = new IntPtr(info.BaseAddress.ToInt64() + info.RegionSize.ToInt64());
                            break;
                        }
                    }
                }
            }
            catch (Exception ex) {
                this._memoryHandler.RaiseException(Logger, ex);
            }
        }