示例#1
0
        public unsafe static void VirtualQueryEx(IntPtr processHandle, IntPtr lpAddress, out ProcessMemoryReaderApi.MEMORY_BASIC_INFORMATION64 lpBuffer, uint dwLength)
        {
            bool Is32Bit;

            //First check if we are a 32 bit OS, in which case target process cannot be 64 bit
            if (sizeof(IntPtr) == (int)DataTypeSize.Int32)
            {
                Is32Bit = true;
            }
            else
            {
                ProcessMemoryReaderApi.IsWow64Process(processHandle, out Is32Bit);
            }

            if (!Is32Bit)
            {
                ProcessMemoryReaderApi.VirtualQueryEx(processHandle, lpAddress, out lpBuffer, dwLength);
            }
            else
            {
                ProcessMemoryReaderApi.MEMORY_BASIC_INFORMATION32 lpBuffer32;
                ProcessMemoryReaderApi.VirtualQueryEx(processHandle.ToInt32(), lpAddress.ToInt32(), out lpBuffer32, dwLength);

                lpBuffer.AllocationBase    = lpBuffer32.AllocationBase;
                lpBuffer.AllocationProtect = lpBuffer32.AllocationProtect;
                lpBuffer.BaseAddress       = lpBuffer32.BaseAddress;
                lpBuffer.lType             = lpBuffer32.Type;
                lpBuffer.Protect           = lpBuffer32.Protect;
                lpBuffer.RegionSize        = (UInt64)lpBuffer32.RegionSize;
                lpBuffer.State             = lpBuffer32.State;
                lpBuffer.__alignment1      = 0;
                lpBuffer.__alignment2      = 0;
            }
        }