void readPhysicalMemoryMap( HANDLE hPhysMem, u8 *buffer, u64 offset, unsigned int length) { unsigned int totalBytes = 0; unsigned int originalSize = length; unsigned int pageSize = length; if(!hPhysMem) { throw AccessErrorImpl( _("Handle to physical memory was not set or could not be opened.") ); } if(0 == buffer) { throw AccessErrorImpl( _("Error accessing buffer.") ); } while(totalBytes != originalSize ) { DWORD BaseAddr; DWORD PhysAddr = static_cast<DWORD>(offset); // OK, first get the page that has the requested offset. This // function will round-down physaddr to the nearest page boundary, // and the pageSize will change to the size of the page if (!MapMem(hPhysMem, (PVOID) &BaseAddr, &PhysAddr, reinterpret_cast<PDWORD>(&pageSize))) { throw AccessErrorImpl( _("Error mapping physical memory.") ); } //Find the index into the page based on requested offset unsigned int index = static_cast<DWORD>(offset) - PhysAddr; // Only continue to copy if the index is within the pageSize and // we still need bytes while( index < pageSize && totalBytes != originalSize) { u64 tmp = BaseAddr + index; // extra tmp to satisfy vc++ /w4 buffer[totalBytes] = *reinterpret_cast<u8 *>(tmp); index++; totalBytes++; } u64 tmp = BaseAddr; // extra tmp to satisfy vc++ /w4 if (!UnMapMem(reinterpret_cast<PVOID>(tmp))) { throw AccessErrorImpl( _("Error unmapping physical memory.")); } // If the inner while loop exited due to the end of the page, we // need to update the offset and the remaining size and map // another page offset = PhysAddr + index; pageSize = originalSize-totalBytes; } }
/* * MapVGA -- * * Map the VGA memory window (0xA0000-0xAFFFF) as read/write memory for * the process for use in probing memory. */ Byte *MapVGA() { return( MapMem(0xA0000,0x10000) ); }