-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc_enum.h
More file actions
107 lines (84 loc) · 2.57 KB
/
Copy pathproc_enum.h
File metadata and controls
107 lines (84 loc) · 2.57 KB
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
#pragma once
#include "common.h"
// Forward declarations
struct ProcessInfo;
struct ModuleInfo;
// RAII wrapper for snapshot handles
class SnapshotHandle {
private:
HANDLE h_;
public:
explicit SnapshotHandle(DWORD flags, DWORD pid = 0);
~SnapshotHandle();
operator HANDLE() const { return h_; }
bool valid() const { return h_ != INVALID_HANDLE_VALUE; }
// Delete copy operations for safety
SnapshotHandle(const SnapshotHandle&) = delete;
SnapshotHandle& operator=(const SnapshotHandle&) = delete;
};
// Enumeration result codes
enum class EnumResult {
Success,
SnapshotFailed,
AccessDenied,
InvalidPid,
NoResults,
ProcessNotFound
};
// Data structures for returned information
struct ProcessInfo {
DWORD pid;
std::wstring name;
DWORD parentPid;
DWORD threadCount;
ProcessInfo(DWORD p, const std::wstring& n, DWORD parent = 0, DWORD threads = 0);
};
struct ModuleInfo {
void* baseAddress;
DWORD size;
std::wstring name;
std::wstring path;
ModuleInfo(void* base, DWORD sz, const std::wstring& n, const std::wstring& p);
};
// Utility functions
class SystemUtils {
public:
// Check if current process is running with elevated privileges
static bool is_elevated();
// Get error message for last Windows error
static std::wstring get_last_error_message();
// Validate PID range
static bool is_valid_pid(DWORD pid);
// Check if process exists
static bool process_exists(DWORD pid);
};
// Main enumeration class
class ProcessEnumerator {
private:
PROCESSENTRY32W pe_;
MODULEENTRY32W me_;
public:
ProcessEnumerator();
// Enumerate all processes with filtering support
EnumResult enumerate_processes(std::vector<ProcessInfo>& processes,
const std::wstring& filter = L"");
// Enumerate modules for a specific process
EnumResult enumerate_modules(DWORD pid, std::vector<ModuleInfo>& modules);
private:
bool case_insensitive_search(const std::wstring& text, const std::wstring& pattern);
};
// Display functions with improved formatting
class ProcessDisplay {
public:
static void print_processes(const std::vector<ProcessInfo>& processes);
static void print_modules(DWORD pid, const std::vector<ModuleInfo>& modules);
static void print_error(EnumResult result, DWORD pid = 0);
};
// Improved command functions
void cmd_ps_improved(const std::wstring& filter = L"");
void cmd_mods_improved(DWORD pid);
// Original simple functions (for compatibility)
void cmd_ps();
void cmd_mods(DWORD pid);
// Example usage function
void example_usage();