1 // 启动程序.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <Windows.h> 6 #include <TlHelp32.h> 7 #include <iostream> 8 #include <Psapi.h> 9 10 #pragma comment(lib,"psapi.lib") 11 using namespace std; 12 BOOL IsX64PEFile(WCHAR* wzProcessFullPath); 13 BOOL GetProcessIDByProcessImageName(WCHAR* wzProcessImageName,DWORD* dwTargetProcessID); 14 BOOL EnableDebugPrivilege(); 15 int _tmain(int argc, _TCHAR* argv[]) 16 { 17 18 19 if (EnableDebugPrivilege()==FALSE) // 进行提权 20 { 21 return 0; 22 } 23 24 DWORD dwTargetProcessID = 0; 25 HANDLE hTargetProcess = NULL; 26 27 28 29 if(GetProcessIDByProcessImageName(L"EnumProcessByForce应用程序.exe",&dwTargetProcessID)==FALSE) 30 { 31 return 0; 32 } 33 hTargetProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE,dwTargetProcessID); 34 if (hTargetProcess==NULL) 35 { 36 return 0; 37 } 38 HMODULE hModule = NULL; 39 DWORD cbNeeded = 0; 40 41 WCHAR wzProcessFullPath[MAX_PATH] = {0}; 42 //进程文件的绝对路径 43 EnumProcessModules(hTargetProcess, &hModule, sizeof(hModule),&cbNeeded); 44 45 cout<<GetLastError()<<endl; 46 //得到自身的完整名称 47 48 /* 49 50 DWORD GetModuleFileNameEx( 51 HANDLE hProcess, 52 HMODULE hModule, 53 LPTSTR lpFilename, 54 DWORD nSize 55 ); 56 57 */ 58 DWORD dwReturn = GetModuleFileNameEx(hTargetProcess, hModule, 59 wzProcessFullPath, 60 MAX_PATH); 61 62 63 CloseHandle(hTargetProcess); 64 65 66 67 68 WCHAR wzHookIATFullPath[MAX_PATH] = {0}; 69 70 GetCurrentDirectory(MAX_PATH,wzHookIATFullPath); 71 72 WCHAR* v1 = wzHookIATFullPath+wcslen(wzHookIATFullPath); 73 74 75 int i = 0; 76 while (v1--) 77 { 78 if (*v1==L'\') 79 { 80 i++; 81 if (i==3) // 注意 调试和编译生成的文件位置不同 调试状态下 i == 2; 82 { 83 break; 84 } 85 86 } 87 } 88 89 *v1 = '