Skip to content

Commit

Permalink
[BUGFIX] Protect logging on stdout by a mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Jun 13, 2024
1 parent d9a0c6b commit ea6068e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hh_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,21 @@ void HHScanner::printScanRoundStats(size_t found, size_t ignored_count)
{
if (!found && hh_args.names_list.size() > 0) {
if (!hh_args.quiet) {
const std::lock_guard<std::mutex> stdOutLock(g_stdOutMutex);
std::cout << "[WARNING] No process from the list: {" << util::list_to_str(hh_args.names_list) << "} was found!" << std::endl;
}
}
if (!found && hh_args.pids_list.size() > 0) {
if (!hh_args.quiet) {
const std::lock_guard<std::mutex> stdOutLock(g_stdOutMutex);
std::cout << "[WARNING] No process from the list: {" << util::list_to_str(hh_args.pids_list) << "} was found!" << std::endl;
}
}
if (ignored_count > 0) {
if (!hh_args.quiet) {
std::string info1 = (ignored_count > 1) ? "processes" : "process";
std::string info2 = (ignored_count > 1) ? "were" : "was";
const std::lock_guard<std::mutex> stdOutLock(g_stdOutMutex);
std::cout << "[INFO] " << std::dec << ignored_count << " " << info1 << " from the list : {" << util::list_to_str(hh_args.ignored_names_list) << "} " << info2 << " ignored!" << std::endl;
}
}
Expand All @@ -181,6 +184,7 @@ size_t HHScanner::scanProcesses(HHScanReport &my_report)
HANDLE hProcessSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnapShot == INVALID_HANDLE_VALUE) {
const DWORD err = GetLastError();
const std::lock_guard<std::mutex> stdOutLock(g_stdOutMutex);
std::cerr << "[-] Could not create modules snapshot. Error: " << std::dec << err << std::endl;
return 0;
}
Expand All @@ -191,6 +195,7 @@ size_t HHScanner::scanProcesses(HHScanReport &my_report)
//check all modules in the process, including the main module:
if (!Process32First(hProcessSnapShot, &pe32)) {
CloseHandle(hProcessSnapShot);
const std::lock_guard<std::mutex> stdOutLock(g_stdOutMutex);
std::cerr << "[-] Could not enumerate processes. Error: " << GetLastError() << std::endl;
return 0;
}
Expand Down

0 comments on commit ea6068e

Please sign in to comment.