mirror-ac/module/module.cpp

72 lines
1.7 KiB
C++
Raw Normal View History

#include "module.h"
#include <Windows.h>
#include "client/message_queue.h"
#include "dispatcher/dispatcher.h"
2024-05-11 14:54:58 +02:00
#include "crypt/crypt.h"
#include <Psapi.h>
bool module::get_module_information(module_information *out) {
BOOL ret = FALSE;
HMODULE module = {0};
MODULEINFO info = {0};
ret = GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCSTR)get_module_information, &module);
if (!ret)
return false;
ret = GetModuleInformation(GetCurrentProcess(), module, (LPMODULEINFO)&info,
sizeof(info));
if (!ret)
return false;
if (!GetModuleFileNameA(module, out->path, MAX_PATH))
return false;
out->base_address = info.lpBaseOfDll;
out->size = info.SizeOfImage;
LOG_INFO("base: %llx", out->base_address);
LOG_INFO("size: %lx", out->size);
LOG_INFO("path: %s", out->path);
return true;
}
2024-05-11 14:54:58 +02:00
2024-05-05 12:42:22 +02:00
void module::run(HINSTANCE hinstDLL) {
AllocConsole();
2024-05-11 14:54:58 +02:00
FILE *file = NULL;
2024-05-05 12:42:22 +02:00
freopen_s(&file, "CONOUT$", "w", stdout);
freopen_s(&file, "CONIN$", "r", stdin);
LPTSTR pipe_name = (LPTSTR)L"\\\\.\\pipe\\DonnaACPipe";
LPCWSTR driver_name = L"\\\\.\\DonnaAC";
module::module_information info = {0};
if (!module::get_module_information(&info)) {
LOG_ERROR("get_module_information: %x", GetLastError());
fclose(stdout);
fclose(stdin);
FreeConsole();
FreeLibraryAndExitThread(hinstDLL, 0);
return;
}
2024-05-05 12:42:22 +02:00
client::message_queue queue(pipe_name);
dispatcher::dispatcher dispatch(driver_name, queue, &info);
2024-05-05 12:42:22 +02:00
dispatch.run();
fclose(stdout);
fclose(stdin);
FreeConsole();
FreeLibraryAndExitThread(hinstDLL, 0);
}
2024-05-05 12:42:22 +02:00
void module::terminate() {}