Skip to content
This repository was archived by the owner on Feb 18, 2026. It is now read-only.

Commit 3521161

Browse files
committed
+ | Process class that will be used as base for Threat class
1 parent c8c03b4 commit 3521161

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Threat/Process.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include "Process.hpp"
2+
3+
Process::Process(const wchar_t *processName) {
4+
HANDLE hSnapshot;
5+
PROCESSENTRY32 processEntry = {};
6+
BOOL hResult;
7+
8+
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
9+
if (hSnapshot == INVALID_HANDLE_VALUE) {
10+
std::cerr << "Failed to create snapshot of processes" << std::endl;
11+
return;
12+
}
13+
14+
processEntry.dwSize = sizeof(PROCESSENTRY32);
15+
hResult = Process32First(hSnapshot, &processEntry);
16+
17+
while (hResult) {
18+
if (wcscmp(processName, processEntry.szExeFile) == 0) {
19+
processId = processEntry.th32ProcessID;
20+
break;
21+
}
22+
hResult = Process32Next(hSnapshot, &processEntry);
23+
}
24+
25+
if (processId == 0) {
26+
std::wcerr << "Failed to find " << processName << std::endl;
27+
}
28+
29+
CloseHandle(hSnapshot);
30+
}
31+
32+
Process::~Process() {
33+
CloseHandle(hProcess);
34+
}
35+
36+
DWORD Process::GetProcessId() const {
37+
return processId;
38+
}
39+
40+
HANDLE Process::GetProcessHandle() const {
41+
return hProcess;
42+
}

Threat/Process.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
3+
#include <Windows.h>
4+
#include <iostream>
5+
#include <TlHelp32.h>
6+
7+
class Process {
8+
private:
9+
DWORD processId = 0;
10+
HANDLE hProcess = NULL;
11+
public:
12+
Process() = delete;
13+
Process(const wchar_t *processName);
14+
~Process();
15+
16+
DWORD GetProcessId() const;
17+
HANDLE GetProcessHandle() const;
18+
};

0 commit comments

Comments
 (0)