在去除前面的那些东西之后,我们的内存块里面还有一堆MEM_MAPPED的内容,就像这样的块:
MSDN里面这样解释MEM_MAPPED这种类型:
Indicates that the memory pages within the region are mapped into the view of a section.
很自然地我们想用GetMappedFileName来看看映射到这些 内存区域的文件名,于是发现了下面几个块的确是做了文件映射:
那么其它东西是哪里来的?
使用GetLastError取错误信息:“error: 000003ee : 文件所在 的卷已被外部改变,因此打开的文件不再有效。”,诡异得很!一怒之下使用UnmapViewOfFile将 这些内存块给Unmap了,不幸的是程序就这样挂掉了!
写段代码查询一下当前打开的句柄,看看有没 有file mapping的内容:
void enum_handles(HANDLE hProcess)
{
// 枚举已经打 开的句柄,取其名称
HMODULE hNtDll = NULL; // nt.dll句柄
ZWQUERYSYSTEMINFORMATION ZwQuerySystemInformation = NULL;
NTQUERYOBJECT NtQueryObject = NULL;
SYSTEM_HANDLE_INFORMATION *hInfo = NULL;
int nNumHandle = 0, i; // 句柄数 量
NTSTATUS Status;
ULONG nSize, nCount;
char cBuffer[0x40000], cInfoBuffer [0x1000];
OBJECT_ALL_INFORMATION *pInfo;
OBJECT_NAME_INFORMATION* pName;
DWORD nId = GetProcessId(hProcess);
// 取导出函数
hNtDll = GetModuleHandle( "ntdll.dll" );
ZwQuerySystemInformation = ( ZWQUERYSYSTEMINFORMATION )GetProcAddress( hNtDll, "ZwQuerySystemInformation" );
NtQueryObject = ( NTQUERYOBJECT )GetProcAddress( hNtDll, "NtQueryObject" );
// 查询句柄信息
Status = ZwQuerySystemInformation (SystemHandleInformation,
cBuffer,
0x40000,
&nSize);
if (NT_SUCCESS(Status))
{
nNumHandle = *(PULONG)cBuffer;
hInfo = (SYSTEM_HANDLE_INFORMATION*)(cBuffer + 4);
nCount = 0;
for(i = 0; i < nNumHandle; i++)
{
if(hInfo[i].ProcessId != nId) continue;
Status = NtQueryObject(hInfo[i].Handle, ObjectAllInformation, cInfoBuffer, 0x1000, &nSize);
if(NT_SUCCESS(Status))
{
pInfo = (OBJECT_ALL_INFORMATION*)cInfoBuffer;
nCount++;
……………………….
}
}
}
}