阅读:1764回复:1
通过句柄查询文件名或设备名BOOL CKlAntiApiCall::GetFileNameFromHandle(HANDLE hFile,TCHAR * pszFilename) { BOOL bSuccess=FALSE; POBJECT_NAME_INFORMATION oni = NULL; oni= (POBJECT_NAME_INFORMATION) new WCHAR[256]; if(oni) { ULONG rt=0; HMODULE hModule=LoadLibrary(_T("ntdll.dll")); if( !hModule) { delete [](WCHAR *)oni; return FALSE; } m_PZwQueryObject=(P_ZWQUERYOBJECT)GetProcAddress(hModule,"ZwQueryObject"); if(m_PZwQueryObject) { NTSTATUS status = m_PZwQueryObject(hFile, ObjectNameInformation, oni, 256*sizeof(WCHAR), &rt); if(NT_SUCCESS(status)) { RtlCopyMemory(pszFilename,oni->Name.Buffer,oni->Name.Length); bSuccess =TRUE; } } delete [](WCHAR *)oni; FreeLibrary(hModule); } return(bSuccess); } 注意szFileName必须保证大于256字符,否则发生意外,恕不承担。当然,你也可以改进一下函数调用,输入缓冲区长度。 |
|
|
沙发#
发布于:2012-09-17 21:32
顶楼主。。。。
|
|