feat(loader): check for wsc service before starting

This commit is contained in:
es3n1n
2025-05-30 12:01:43 +02:00
parent 3583c4636f
commit df93be27ec
13 changed files with 210 additions and 29 deletions

View File

@@ -1,13 +0,0 @@
#pragma once
#include <string_view>
namespace names {
constexpr std::string_view kProjectName = "defendnot";
constexpr std::string_view kRepoUrl = "https://github.com/es3n1n/defendnot";
constexpr std::string_view kDefaultAVName = "dnot.sh";
constexpr std::string_view kVictimProcess = "Taskmgr.exe";
constexpr std::string_view kDllName = "defendnot.dll";
constexpr std::string_view kVersion = "1.2.0";
} // namespace names

View File

@@ -23,7 +23,7 @@ namespace native {
auto function = reinterpret_cast<Ty>(GetProcAddress(mod, function_name.data()));
if (function == nullptr) {
throw std::runtime_error(std::format("unable to obtain {} from {}", module_name, function_name));
throw std::runtime_error(std::format("unable to obtain {} from {}", function_name, module_name));
}
return function;
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "shared/util.hpp"
#include <string_view>
namespace strings {
constexpr std::string_view kProjectName = "defendnot";
constexpr std::string_view kRepoUrl = "https://github.com/es3n1n/defendnot";
constexpr std::string_view kVersion = "1.2.0";
constexpr std::string_view kDefaultAVName = "dnot.sh";
constexpr std::string_view kVictimProcess = "Taskmgr.exe";
constexpr std::string_view kDllName = "defendnot.dll";
constexpr std::string_view kWSCUnavailableError = /// !winserver
"Windows Security Center (WSC) is not available on this machine.\n"
"For more details, please refer to: https://github.com/es3n1n/defendnot/issues/25";
constexpr std::string_view kWSCUnavailableErrorWinServer = /// winserver
"Windows Security Center (WSC) is not available on this machine.\n"
"This typically occurs on Windows Server operating systems, which are not supported by this tool.\n"
"For more details, please refer to: https://github.com/es3n1n/defendnot/issues/17";
inline std::string_view wsc_unavailable_error() noexcept {
if (shared::is_winserver()) {
return kWSCUnavailableErrorWinServer;
}
return kWSCUnavailableError;
}
} // namespace strings

View File

@@ -27,4 +27,10 @@ namespace shared {
freopen_s(reinterpret_cast<FILE**>(stderr), "CONOUT$", "w", stderr);
});
}
inline bool is_winserver() {
OSVERSIONINFOEXW osvi = {sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0, 0, VER_NT_WORKSTATION};
const auto cond_mask = VerSetConditionMask(0, VER_PRODUCT_TYPE, VER_EQUAL);
return !VerifyVersionInfoW(&osvi, VER_PRODUCT_TYPE, cond_mask);
}
} // namespace shared