Skip to content

Commit

Permalink
Debugging counts
Browse files Browse the repository at this point in the history
  • Loading branch information
eschan145 committed Jan 18, 2025
1 parent b0eedd3 commit 8e455df
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ DK_API int monitor_executables(int interval) {
int count = 0;

while (running) {
// dieknow::sweep();
dieknow::sweep();
std::this_thread::sleep_for(std::chrono::seconds(interval));
}
return count;
Expand Down Expand Up @@ -286,7 +286,9 @@ bool taskkill(DWORD identifier) {
}

void sweep() {
std::cout << "Sweeping\n";
int count = 0;
int total_count = 0;

HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (snapshot == INVALID_HANDLE_VALUE) {
Expand All @@ -300,6 +302,7 @@ void sweep() {

if (Process32First(snapshot, &pe32)) {
do {
total_count++;
for (const auto& entry :
std::filesystem::directory_iterator(FOLDER_PATH)) {
if (entry.is_directory()) {
Expand All @@ -312,7 +315,11 @@ void sweep() {
.string();
if (_stricmp(pe32.szExeFile, name.c_str()) == 0) {
dieknow::taskkill(pe32.th32ProcessID);
count++;
}

if (count >= 2)
break;
}
}
}
Expand All @@ -322,6 +329,11 @@ void sweep() {
error("Failed to enumerate through processes! Error code: " +
last_error() + "\n");
}

CloseHandle(snapshot);

std::cout << "Sweep completed. Total executables scanned: " << total_count
<< ", processes terminated: " << count << "\n";
}

DK_API void start_monitoring(const char* folder_path) {
Expand Down

0 comments on commit 8e455df

Please sign in to comment.