1
0
mirror of synced 2024-12-17 22:55:52 +01:00
bananatools/exvs2hook/dllmain.c
2023-09-24 01:19:40 -04:00

93 lines
2.0 KiB
C

#include <windows.h>
#include <stdlib.h>
#include "exvs2hook/config.h"
#include "exvs2hook/exvs2-dll.h"
#include "exvs2hook/jvs.h"
#include "amcus/amcus.h"
#include "hook/process.h"
#include "hooklib/serial.h"
#include "board/bpreader.h"
#include "board/qr.h"
#include "platform/platform.h"
#include "gfxhook/gfx.h"
#include "gfxhook/dxgi.h"
#include "util/dprintf.h"
static HMODULE exvs2_hook_mod;
static process_entry_t exvs2_startup;
static struct exvs2_hook_config exvs2_hook_cfg;
static DWORD CALLBACK exvs2_pre_startup(void)
{
HRESULT hr;
dprintf("--- Begin exvs2_pre_startup ---\n");
exvs2_hook_config_load(&exvs2_hook_cfg, L".\\bananatools.ini");
serial_hook_init();
struct dongle_info dinfo;
dinfo.vid = 0x0B9A;
dinfo.pid = 0x0C20;
wcscpy_s(dinfo.manufacturer, _countof(dinfo.manufacturer), L"UFD 3.0");
wcscpy_s(dinfo.product, _countof(dinfo.product), L"Silicon-Power8G");
hr = platform_hook_init(&exvs2_hook_cfg.platform, PLATFORM_BNA1, exvs2_jvs_init, exvs2_hook_mod, dinfo);
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
hr = exvs2_dll_init(&exvs2_hook_cfg.dll, exvs2_hook_mod);
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
hr = bpreader_init(&exvs2_hook_cfg.reader, 4);
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
hr = amcus_hook_init(&exvs2_hook_cfg.amcus);
if (FAILED(hr)) {
ExitProcess(EXIT_FAILURE);
}
gfx_hook_init(&exvs2_hook_cfg.gfx);
gfx_dxgi_hook_init(&exvs2_hook_cfg.gfx, exvs2_hook_mod);
dprintf("--- End exvs2_pre_startup ---\n");
return exvs2_startup();
}
BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx)
{
HRESULT hr;
if (cause != DLL_PROCESS_ATTACH) {
return TRUE;
}
exvs2_hook_mod = mod;
hr = process_hijack_startup(exvs2_pre_startup, &exvs2_startup);
if (!SUCCEEDED(hr)) {
dprintf("Failed to hijack process startup: %x\n", (int) hr);
}
return SUCCEEDED(hr);
}