ASI loghook (удаление логов)

scandalque

Известный
Автор темы
17
7
Версия SA-MP
  1. Любая
описание: удаляет логи от плагинов или скриптов (cleo.log, moonloader.log и прочее)
советую оставить название как есть (!loghook.asi)


C++:
#include "minhook/include/MinHook.h"
#include <filesystem>

std::filesystem::path to_lower(const std::filesystem::path& path) {
    std::string path_str = path.string();
    std::transform(path_str.begin(), path_str.end(), path_str.begin(),
        [](unsigned char c) -> unsigned char { return std::tolower(c); });
    return std::filesystem::path(path_str);
}

using createfile_p = HANDLE(WINAPI*)(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
createfile_p createfile_orig;

HANDLE WINAPI createfile_hook(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
    LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
    DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
    if (to_lower(std::filesystem::path(lpFileName).extension()) == ".log")
    {
        auto aa = createfile_orig(lpFileName, dwDesiredAccess, dwShareMode | FILE_SHARE_DELETE, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
        DeleteFileW(lpFileName);
        return aa; // возвращаем, чтобы modloader не выдавал ошибку
    }
    return createfile_orig(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}

class entry
{
public:
    entry();
}g_entry;

entry::entry()
{
    MH_Initialize();
    auto createfile_ptr = (std::uintptr_t)GetProcAddress(GetModuleHandleA("kernel32.dll"), "CreateFileW");
    if (createfile_ptr) MH_CreateHook(reinterpret_cast<void*>(createfile_ptr), &createfile_hook, reinterpret_cast<void**>(&createfile_orig));
    MH_EnableHook(MH_ALL_HOOKS);
}
 

Вложения

  • !loghook.asi
    24.5 KB · Просмотры: 24