1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| VOID InitProcessListView(HWND hDlg){ LV_COLUMN lv; HWND hListProcess;
memset(&lv,0,sizeof(LV_COLUMN)); hListProcess = GetDlgItem(hDlg,IDC_LIST_PROCESS); SendMessage(hListProcess,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT,LVS_EX_FULLROWSELECT);
lv.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; lv.pszText = _T("PID"); lv.cx = 50; lv.iSubItem = 0; ListView_InsertColumn(hListProcess, 0, &lv); lv.pszText = _T("进程名"); lv.cx = 100; lv.iSubItem = 1; ListView_InsertColumn(hListProcess, 1, &lv); lv.pszText = _T("进程地址"); lv.cx = 100; lv.iSubItem = 2; ListView_InsertColumn(hListProcess, 2, &lv); lv.pszText = _T("镜像基址"); lv.cx = 100; lv.iSubItem = 3; ListView_InsertColumn(hListProcess, 3, &lv); lv.pszText = _T("镜像大小"); lv.cx = 100; lv.iSubItem = 4; ListView_InsertColumn(hListProcess, 4, &lv);
DWORD procPid[1024], retnBytes, procCount, retnBytes2; unsigned int i; HMODULE hMod[1024]; HANDLE hProcess; TCHAR szModAbsPath[MAX_PATH];
LPSTR processData[5] = {0}; LPSTR moduleName; TCHAR processId[100]; TCHAR imageBase[100]; TCHAR sizeOfImage[100]; LPSTR delim;
if (EnumProcesses(procPid, sizeof(procPid), &retnBytes)) { procCount = retnBytes / sizeof(DWORD); SetProcessPrivilege("SeDebugPrivilege", 1); for (i = 0; i < procCount; i++) { hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, procPid[i]); if (hProcess != NULL) { EnumProcessModules(hProcess, hMod, sizeof(hMod), &retnBytes2); GetModuleFileNameEx(hProcess, hMod[0], szModAbsPath, sizeof(szModAbsPath));
if (strstr(szModAbsPath, _T("\\SystemRoot")) != NULL) { char* szModNameTemp = strrep(szModAbsPath,_T("\\SystemRoot"),_T("C:\\Windows")); strcpy(szModAbsPath, szModNameTemp); }
ReadPEFile(szModAbsPath, &pFileBuffer); pDosHeader = (PIMAGE_DOS_HEADER) pFileBuffer; pNTHeader = (PIMAGE_NT_HEADERS) ((DWORD) pFileBuffer + pDosHeader->e_lfanew); pFileHeader = (PIMAGE_FILE_HEADER) (((DWORD) pNTHeader) + 4); pOptionHeader = (PIMAGE_OPTIONAL_HEADER32) ((DWORD) pFileHeader + IMAGE_SIZEOF_FILE_HEADER);
sprintf(processId, _T("%d"), procPid[i]); processData[0] = processId;
delim = _T("\\"); moduleName = CutAndGetLast(szModAbsPath, delim); processData[1] = moduleName;
processData[2] = szModAbsPath;
sprintf(imageBase, _T("0x%08X"), pOptionHeader->ImageBase); processData[3] =imageBase;
sprintf(sizeOfImage, _T("0x%08X"), pOptionHeader->SizeOfImage); processData[4] = sizeOfImage;
InsertRow(hListProcess, processData);
free(pFileBuffer); } CloseHandle(hProcess); } SetProcessPrivilege("SeDebugPrivilege", 0); }
}
|