-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPSAPI.cpp
139 lines (110 loc) · 3.17 KB
/
PSAPI.cpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* C++ Windows process, module enumeration class
*
* Written by Lee, JaeKil
* mailto:juria@gtech.co.kr
*
* Copyright (c) 1998-1999.
*
* This code may be used in compiled form in any way you desire. This
* file may be redistributed unmodified by any means PROVIDING it is
* not sold for profit without the authors written consent, and
* providing that this notice and the authors name and all copyright
* notices remains intact. If the source code in this file is used in
* any commercial application then a statement along the lines of
* "Portions copyright (c) Chris Maunder, 1998" must be included in
* the startup banner, "About" box or printed documentation. An email
* letting me know that you are using it would be nice as well. That's
* not much to ask considering the amount of work that went into this.
*
* This file is provided "as is" with no expressed or implied warranty.
* The author accepts no liability for any damage/loss of business that
* this product may cause.
*
* Expect bugs!
*
* Please use and enjoy, and let me know of any bugs/mods/improvements
* that you have found/implemented and I will fix/incorporate them into
* this file.
*/
// PSAPI.cpp: implementation of the CPSAPI class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "PSAPI.h"
#include <tlhelp32.h>
#include <vdmdbg.h>
#include <tchar.h>
#include <VersionHelpers.h>
#define MAX_HANDLE_COUNT 1024
#pragma comment(lib, "psapi.lib")
//////////////////////////////////////////////////////////////////////
// CPSAPI Construction/Destruction
CPSAPI::CPSAPI()
{
}
BOOL CPSAPI::Initialize(void)
{
return TRUE;
}
CPSAPI::~CPSAPI()
{
}
BOOL CPSAPI::EnumDeviceDrivers(void)
{
return FALSE;
}
BOOL CPSAPI::EnumProcesses(void)
{
DWORD aProcesses[MAX_HANDLE_COUNT];
DWORD cbNeeded, cProcesses;
if (!::EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
return FALSE;
cProcesses = cbNeeded / sizeof(DWORD);
for (unsigned int i = 0; i < cProcesses; i++)
{
if (aProcesses[i] != 0)
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, aProcesses[i]);
if (NULL != hProcess)
{
HMODULE hMod;
DWORD cbNeeded;
if (::EnumProcessModules(hProcess, &hMod, sizeof(hMod),
&cbNeeded))
{
GetModuleBaseName(hProcess, hMod, szProcessName,
sizeof(szProcessName) / sizeof(TCHAR));
if (OnProcess(szProcessName, aProcesses[i]) == FALSE)
{
CloseHandle(hProcess);
return FALSE;
}
}
CloseHandle(hProcess);
}
}
}
return TRUE;
}
BOOL CPSAPI::EnumProcessModules(DWORD dwProcessId)
{
return FALSE;
}
//////////////////////////////////////////////////////////////////////
// CPSAPI Overridables
BOOL CPSAPI::OnDeviceDriver(LPVOID lpImageBase)
{
return TRUE;
}
BOOL CPSAPI::OnProcess(LPCTSTR lpszFileName, DWORD ProcessID)
{
return TRUE;
}
BOOL CPSAPI::OnModule(HMODULE hModule, LPCTSTR lpszModuleName, LPCTSTR lpszPathName)
{
return TRUE;
}