获取当前进程已加载模块的文件的完整路径,该模块必须由当前进程加载。
DWORD
WINAPI GetModuleFileName(
_In_opt_
HMODULE
hModule, //模块句柄
_Out_
LPTSTR
lpFilename, //存放地址
_In_
DWORD
nSize //大小
);
#include "stdafx.h"
#include "windows.h"
int main(int argc, char* argv[])
{
char path[80];
GetModuleFileName(0,path,80);
printf("Hello World!\n");
return 0;
}
反汇编代码:
00401210 /$ 8B4424 04 mov eax, dword ptr [esp+4] ; auto.00408A70
00401214 |. 68 04010000 push 80 ; /BufSize = 80
00401219 |. 50 push eax ; |PathBuffer
0040121A |. 6A 00 push 0 ; |hModule = NULL
0040121C |. FF15 6C7040>call dword ptr [<&KERNEL32.GetModule>; \GetModuleFileNameA ;把病毒的文件路径保存在eax里
00401222 |. F7D8 neg eax
00401224 |. 1BC0 sbb eax, eax
00401226 |. F7D8 neg eax
00401228 \. C3 retn