1
0
Fork 0
mirror of https://gitlab.com/niansa/PolicyToolLib.git synced 2025-03-06 20:48:27 +01:00

Improved logging

This commit is contained in:
Nils Sauer 2023-01-18 16:18:21 +01:00
parent 4f37a51591
commit cd0ebef412
3 changed files with 26 additions and 5 deletions

View file

@ -6,18 +6,34 @@
#include "modules/PolicyDisable.hpp"
#include <fstream>
#include <string>
#include <string_view>
#include <vector>
#include <memory>
#include <locale>
#include <codecvt>
#include <windows.h>
#include <winbase.h>
#include <detours.h>
static std::vector<std::unique_ptr<ModuleBase>> 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<wchar_t>;
std::wstring_convert<convert_typeX, wchar_t> 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<LibInherit>());

7
main.h
View file

@ -1,7 +1,10 @@
#include <fstream>
#include <string_view>
#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();

View file

@ -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<char*>(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<char*>(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