R3;在32位进程中得到64位进程映像路径
2016-04-21 12:42
936 查看
32位进程中,所有已知的API函数都无法获得正确的64位进程映像路径。见zyhfut高论:http://bbs.pediy.com/showthread.php?t=129136;只能靠NtQueryInformationProcess和2B;
贴代码以励共勉;
贴代码以励共勉;
typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING, *PUNICODE_STRING;
_Check_return_ BOOL QueryProcessImageFileName( __in HANDLE hProcess, __out_ecount( cchSize ) LPTSTR lpImageFileName, _In_ DWORD cchSize ) { ASSERT( hProcess != NULL ); ASSERT( lpImageFileName != NULL ); ASSERT( cchSize != 0 ); NTSTATUS( WINAPI *NtQueryInformationProcess )(HANDLE, DWORD, LPVOID/* UNICODE_STRING* */, ULONG, PULONG) = NULL; if( NtQueryInformationProcess == NULL ) { HMODULE hNtDll = GetModuleHandle( _T( "ntdll.dll" ) ); VERIFY( hNtDll != NULL ); NtQueryInformationProcess = (PFN_NtQueryInformationProcess)GetProcAddress( hNtDll, "NtQueryInformationProcess" ); VERIFY( NtQueryInformationProcess != NULL ); } __pragma(push_macro( "ProcessImageFileNameWin32" )); #undef ProcessImageFileNameWin32 #define ProcessImageFileNameWin32 (0x2B) #define UNICODE_STRING_LENGTH (sizeof( USHORT ) + sizeof( USHORT ) + sizeof( PWSTR )) WCHAR achImageFileName[MAX_PATH + UNICODE_STRING_LENGTH + 1 ] = { 0 }; if( NtQueryInformationProcess( hProcess, ProcessImageFileNameWin32, achImageFileName, sizeof( achImageFileName ), NULL ) != ERROR_SUCCESS ){ return FALSE; } LPCWSTR lpImageFileNamePtrW = (LPCWSTR)((CHAR*)achImageFileName + UNICODE_STRING_LENGTH); #if defined( _UNICODE ) return SUCCEEDED( StringCbCopyW( lpImageFileName, (size_t)((USHORT)*((CHAR*)achImageFileName+sizeof(USHORT))), lpImageFileNamePtrW ) ); #else USES_CONVERSION; LPCSTR lpImageFileNamePtrA = W2A( lpImageFileNamePtrW ); SIZE_T cchImageFileNameALength = 0; if( FAILED( StringCchLength( lpImageFileNamePtrA, STRSAFE_MAX_LENGTH, (size_t*)&cchImageFileNameALength ) ) ){ return FALSE; } return SUCCEEDED( StringCchCopyN( lpImageFileName, cchSize, lpImageFileNamePtrA, cchImageFileNameALength ) ); #endif __pragma(pop_macro( "ProcessImageFileNameWin32" )); }
相关文章推荐
- 一个神奇的PHP框架:Phalcon 之初识
- 解决JS组件bootstrap table分页实现过程中遇到的问题
- 常用数据类型占内存字节数
- 遇到no changes added to commit时如何正确使用git提交命令
- 第一阶段冲刺个人博客04
- leetcode_092 Reverse Linked List II
- TCP连接状态详解
- tomcat
- 程序员的薪资是如何确定出来的?
- wifi加密类型
- 乐随心动
- 第7周项目1-成员函数、友元函数和一般函数有区别
- gdut校赛决赛题解
- php浏览次数累加代码
- 图片像素英寸厘米之间的单位换算
- 问题解决——apple software update无法卸载
- 那些C++牛人的博客
- HDOJ(HDU) 1708 Fibonacci String
- Educational Codeforces Round 12 C.Simple Strings
- HDOJ(HDU) 1708 Fibonacci String