diff --git a/main.cpp b/main.cpp index aee0a05..47fc3a5 100644 --- a/main.cpp +++ b/main.cpp @@ -6,18 +6,34 @@ #include "modules/PolicyDisable.hpp" #include +#include +#include #include #include +#include +#include #include #include #include static std::vector> modules; -std::ofstream *log_out; +static std::ofstream *log_out; char sDetourLibrary[512]; +void log_str(std::string_view str) { + *log_out << str; +} +void log_str(std::wstring_view str) { + using convert_typeX = std::codecvt_utf8; + std::wstring_convert converterX; + log_str(converterX.to_bytes(std::wstring(str))); +} +void log_endl() { + *log_out << "\r\n"; +} + void loadModules() { char buffer[1000]; modules.emplace_back(std::make_unique()); diff --git a/main.h b/main.h index 3a675dd..58c7282 100644 --- a/main.h +++ b/main.h @@ -1,7 +1,10 @@ -#include +#include #define POLICYTOOL_SIZEREQ(x,y) (offsetof(x,y) + sizeof(((x*) NULL)->y)) #define POLICYTOOL_ALIGN(x,y) ((((uintptr_t) (x)) + (((y)/CHAR_BIT)-1)) & ~(((y)/CHAR_BIT)-1)) extern char sDetourLibrary[512]; -extern std::ofstream *log_out; + +void log_str(std::string_view str); +void log_str(std::wstring_view str); +void log_endl(); diff --git a/modules/PolicyDisable.hpp b/modules/PolicyDisable.hpp index c7aba11..17a59a0 100644 --- a/modules/PolicyDisable.hpp +++ b/modules/PolicyDisable.hpp @@ -36,12 +36,14 @@ class PolicyDisable : public ModuleBase { if (sKeyName.find(L"polic") != sKeyName.npos || sKeyName.find(L"Polic") != sKeyName.npos || sKeyName.find(L"POLIC") != sKeyName.npos) { - *log_out << "Denied policy access: " << std::string_view{reinterpret_cast(pNameInfo->Name), pNameInfo->NameLength} << "\r\n"; + log_str("Denied registry access: "); log_str(sKeyName); log_endl(); free(pNameInfo); *ResultLength = 0; return STATUS_OBJECT_NAME_NOT_FOUND; } - *log_out << "Allowed policy access: " << std::string_view{reinterpret_cast(pNameInfo->Name), pNameInfo->NameLength} << "\r\n"; + log_str("Allowed registry access: "); log_str(sKeyName); log_endl(); + } else { + log_str("Bad registry access"); log_endl(); } // clean up