|
7 | 7 |
|
8 | 8 | int main() |
9 | 9 | { |
10 | | - |
| 10 | + WCHAR szCurrentDirectory[MAX_PATH]; |
| 11 | + |
11 | 12 | //SetPrivilege |
12 | 13 | if (!SetPrivilege(SE_DEBUG_NAME, TRUE)) |
13 | 14 | { |
14 | 15 | OutputDebugString(L"SetPrivilege ERROR\n"); |
15 | 16 | return 0; |
16 | 17 | } |
17 | 18 |
|
18 | | - DoSearchProcess(NULL); |
19 | | - //DoReleaseSemaphoreStatus(); |
| 19 | + GetModuleDirectory(szCurrentDirectory); |
| 20 | + |
| 21 | + ReadTargetListAndDo(szCurrentDirectory); |
| 22 | + |
| 23 | + DoReleaseSemaphoreStatus(); |
20 | 24 |
|
21 | 25 | return 0; |
22 | 26 | } |
23 | 27 |
|
24 | 28 |
|
| 29 | +void GetModuleDirectory(PWCHAR szCurrentDirectory) |
| 30 | +{ |
| 31 | + DWORD dwCurDirPathLen; |
| 32 | + dwCurDirPathLen = GetModuleFileName(NULL, szCurrentDirectory, MAX_PATH); |
| 33 | + if (!dwCurDirPathLen) |
| 34 | + { |
| 35 | + printf("GetModuleFileName ERROR\n"); |
| 36 | + return; |
| 37 | + } |
| 38 | + SIZE_T i = 0; |
| 39 | + StringCbLengthW(szCurrentDirectory, MAX_PATH, &i); |
| 40 | + if (0 == i) |
| 41 | + { |
| 42 | + return; |
| 43 | + } |
| 44 | + for (; i > 0 && L'\\' != szCurrentDirectory[i - 1]; i--) {} |
| 45 | + szCurrentDirectory[i] = L'\0'; |
| 46 | + OutputDebugString(szCurrentDirectory); |
| 47 | + OutputDebugString(L"\n"); |
| 48 | + |
| 49 | +} |
| 50 | + |
| 51 | +void ReadTargetListAndDo(LPCWCHAR szCurrentDirectory) { |
| 52 | + WCHAR szListDirectory[MAX_PATH]; |
| 53 | + WCHAR szProcName[MAX_PATH]; |
| 54 | + WCHAR szBuf[2]; |
| 55 | + DWORD dwNumRead; |
| 56 | + HANDLE hFile = NULL; |
| 57 | + |
| 58 | + StringCbCopy(szListDirectory, MAX_PATH, szCurrentDirectory); |
| 59 | + StringCbCat(szListDirectory, MAX_PATH, L"TargetList.txt"); |
| 60 | + OutputDebugString(szListDirectory); |
| 61 | + OutputDebugString(L"\n"); |
| 62 | + hFile = CreateFile(szListDirectory, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 63 | + if (INVALID_HANDLE_VALUE == hFile) |
| 64 | + { |
| 65 | + OutputDebugString(L"TargetList.txt NOT FOUND\n"); |
| 66 | + return; |
| 67 | + } |
| 68 | + StringCbCopy(szProcName, MAX_PATH, L""); |
| 69 | + while (TRUE) |
| 70 | + { |
| 71 | + ReadFile(hFile, szBuf, 2, &dwNumRead, NULL); |
| 72 | + szBuf[1] = L'\0'; |
| 73 | + if (0 == dwNumRead) |
| 74 | + { |
| 75 | + CloseHandle(hFile); |
| 76 | + break; |
| 77 | + } |
| 78 | + if (L'\r' == *szBuf) |
| 79 | + { |
| 80 | + OutputDebugString(szProcName); |
| 81 | + OutputDebugString(L" in TargetList\n"); |
| 82 | + DoSearchProcess(szProcName); |
| 83 | + StringCbCopy(szProcName, MAX_PATH, L""); |
| 84 | + continue; |
| 85 | + |
| 86 | + } |
| 87 | + if (L'\n' == *szBuf) |
| 88 | + { |
| 89 | + continue; |
| 90 | + } |
| 91 | + StringCbCat(szProcName, MAX_PATH, szBuf); |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | + |
25 | 96 | void DoSearchProcess(LPCWCHAR szProcessName) |
26 | 97 | { |
27 | 98 | DWORD dwPId = 0; |
|
0 commit comments