diff --git a/carolhook/controlbd.c b/carolhook/controlbd.c index a59fe65..63a65f4 100644 --- a/carolhook/controlbd.c +++ b/carolhook/controlbd.c @@ -8,8 +8,6 @@ #include "hook/iobuf.h" #include "hook/iohook.h" -#include "hook/table.h" - #include "carolhook/carol-dll.h" #include "carolhook/controlbd.h" @@ -38,39 +36,6 @@ static struct uart controlbd_uart; static uint8_t controlbd_written_bytes[520]; static uint8_t controlbd_readable_bytes[520]; -static BOOL WINAPI my_CreateProcessA( - LPCSTR lpApplicationName, - LPSTR lpCommandLine, - LPSECURITY_ATTRIBUTES lpProcessAttributes, - LPSECURITY_ATTRIBUTES lpThreadAttributes, - BOOL bInheritHandles, - DWORD dwCreationFlags, - LPVOID lpEnvironment, - LPCSTR lpCurrentDirectory, - LPSTARTUPINFOA lpStartupInfo, - LPPROCESS_INFORMATION lpProcessInformation -); -static BOOL (WINAPI *next_CreateProcessA)( - LPCSTR lpApplicationName, - LPSTR lpCommandLine, - LPSECURITY_ATTRIBUTES lpProcessAttributes, - LPSECURITY_ATTRIBUTES lpThreadAttributes, - BOOL bInheritHandles, - DWORD dwCreationFlags, - LPVOID lpEnvironment, - LPCSTR lpCurrentDirectory, - LPSTARTUPINFOA lpStartupInfo, - LPPROCESS_INFORMATION lpProcessInformation -); - -static const struct hook_symbol win32_hooks[] = { - { - .name = "CreateProcessA", - .patch = my_CreateProcessA, - .link = (void **) &next_CreateProcessA - } -}; - HRESULT controlbd_hook_init(const struct controlbd_config *cfg) { if (!cfg->enable) { @@ -85,12 +50,6 @@ HRESULT controlbd_hook_init(const struct controlbd_config *cfg) controlbd_uart.readable.bytes = controlbd_readable_bytes; controlbd_uart.readable.nbytes = sizeof(controlbd_readable_bytes); - hook_table_apply( - NULL, - "kernel32.dll", - win32_hooks, - _countof(win32_hooks)); - dprintf("Control Board: Init\n"); return iohook_push_handler(controlbd_handle_irp); @@ -378,50 +337,3 @@ static HRESULT controlbd_req_ack_any(uint8_t cmd) return iobuf_write(&controlbd_uart.readable, &resp, sizeof(resp)); } - -static BOOL WINAPI my_CreateProcessA( - LPCSTR lpApplicationName, - LPSTR lpCommandLine, - LPSECURITY_ATTRIBUTES lpProcessAttributes, - LPSECURITY_ATTRIBUTES lpThreadAttributes, - BOOL bInheritHandles, - DWORD dwCreationFlags, - LPVOID lpEnvironment, - LPCSTR lpCurrentDirectory, - LPSTARTUPINFOA lpStartupInfo, - LPPROCESS_INFORMATION lpProcessInformation -) -{ - dprintf("Control Board: my_CreateProcessA Hit! %s\n", lpCommandLine); - if (strncmp(".\\15312firm\\firmupdate_1113.exe", lpCommandLine, 31)) { - return next_CreateProcessA( - lpApplicationName, - lpCommandLine, - lpProcessAttributes, - lpThreadAttributes, - bInheritHandles, - dwCreationFlags, - lpEnvironment, - lpCurrentDirectory, - lpStartupInfo, - lpProcessInformation - ); - } - - dprintf("Control Board: Hooking child process\n"); - char new_cmd[MAX_PATH] = "inject -d -k carolhook.dll "; - strcat_s(new_cmd, MAX_PATH, lpCommandLine); - - return next_CreateProcessA( - lpApplicationName, - new_cmd, - lpProcessAttributes, - lpThreadAttributes, - bInheritHandles, - dwCreationFlags, - lpEnvironment, - lpCurrentDirectory, - lpStartupInfo, - lpProcessInformation - ); -} \ No newline at end of file diff --git a/carolhook/dllmain.c b/carolhook/dllmain.c index 55608c7..a80ea07 100644 --- a/carolhook/dllmain.c +++ b/carolhook/dllmain.c @@ -19,6 +19,7 @@ #include "hooklib/serial.h" #include "hooklib/spike.h" +#include "hooklib/createprocess.h" #include "platform/platform.h" @@ -122,7 +123,12 @@ static DWORD CALLBACK carol_pre_startup(void) if (FAILED(hr)) { goto fail; } - + + hr = createprocess_push_hook_a(".\\15312firm\\firmupdate_1113.exe", "inject -d -k carolhook.dll ", NULL); + + if (FAILED(hr)) { + goto fail; + } /* Initialize debug helpers */ spike_hook_init(L".\\segatools.ini");