Commit Graph
58 Commits
Author SHA1 Message Date
kyoubate-haruka a3443a8b5b Add iohook for GetFileType (#7)
Unity (or mono in that case) is a bit special when it comes to handling file I/O, as before any operation (read, write) it will do a call to `GetFileType` to determine how to set the parameters for the following winapi calls. Handles that we replace with `iohook_open_nul_fd` however don't return the expected `FILE_TYPE_DISK`, as a null handle is a `FILE_TYPE_CHAR` which works by chance for serial ports, but not for files:

Related: https://gitea.tendokyu.moe/TeamTofuShop/segatools/issues/116
Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/capnhook/pulls/7
Co-authored-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com>
Co-committed-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com>
2026-07-05 15:33:19 +00:00
Gl0w1amp 35169a5057 Remove global Sleep(1) from uart_handle_read (#6)
This removes the global Sleep(1) workaround that was originally added to prevent memory leaks caused by tight polling loops.

While it helped with the mai2 memory leak, introducing artificial latency here negatively impacts other UART devices (e.g., breaking slider inputs in chusan). The proper fix has now been implemented downstream in `segatools` by rate-limiting the specific `led15070` board instead. Therefore, this global hack is no longer needed and can be safely removed.

Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/capnhook/pulls/6
Co-authored-by: Gl0w1amp <gl0w1amp@noreply.gitea.tendokyu.moe>
Co-committed-by: Gl0w1amp <gl0w1amp@noreply.gitea.tendokyu.moe>
2026-03-09 16:33:23 +00:00
Dniel97 4e192325bc Merge pull request 'Fix busy loop in uart_handle_read causing high CPU usage and memory leaks' (#3) from Gl0w1amp/capnhook:master into master
Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/capnhook/pulls/3
2025-12-21 17:49:57 +00:00
Dniel97 1e31f76d3e Fix 32bit SetFilePointer 2025-12-21 18:31:02 +01:00
Gl0w1amp 34a2716827 Add delay in uart_handle_read() to prevent tight polling loop and memory leaks
Added Sleep(1) to uart_handle_read when no data is available to simulate
hardware I/O latency. This prevents the hook from entering a tight polling
loop, which was causing high CPU usage and massive memory leaks.
2025-11-29 05:32:56 +00:00
octocat 252465b23f Fix deadlock in uart_handle_read() (#2)
The loop this commit removed tries to sleep and wait for the IO DLL
to write something to uart->readable. It doesn't work for two reasons:

1. When uart_handle_read() is sleeping, its caller holds the lock
   for the resource, meaning nothing can be writen, and it always times out.

2. Even without the deadlock problem, due to timer resolution limit
   on Windows, Sleep(1) does not actually sleep 1ms.
   Instead it sleeps over 15ms by default.

The symptom is a noticable input lag, and lost inputs.
This commit tries to fix that.

Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/capnhook/pulls/2
Co-authored-by: octocat <git.rascal570@passinbox.com>
Co-committed-by: octocat <git.rascal570@passinbox.com>
2025-10-12 10:07:25 +00:00
Hay1tsme dafd0aa336 Implement ilufang's ERROR_IO_PENDING for empty serial reads 2025-02-09 04:50:10 -05:00
Hay1tsme 4633c51d58 remove precompiled headers 2025-02-04 11:05:07 -05:00
Hay1tsme 5e44ceea22 properly set link in procaddr hook (thanks Treeskin!) 2025-01-27 02:01:57 -05:00
Hay1tsme cbffaed804 fix my_GetCommModemStatus 2025-01-20 03:16:51 -05:00
Kevin Trocolli b595e4bf8a implement GEEKiDoS' procaddr hook fix 2024-11-09 12:45:14 -05:00
Kevin Trocolli f060250e1b Merge pull request #1 from akechi-haruka/serialhook
serial: fix flow flags
2024-10-10 12:08:55 -04:00
Haruka 47cb508a05 serial: fix flow flags 2024-10-10 11:20:53 +02:00
Hay1tsme 1122b83a29 uart: add modem IOCTLS 2024-08-20 11:29:32 -04:00
Kevin Trocolli 09306229f1 iohook: add hook for GetCommModemStatus 2024-02-21 00:33:25 -05:00
Kevin Trocolli dbdcd61b3a procaddr: fix what I broke with the last push 2023-12-10 19:23:58 -05:00
Kevin Trocolli 24b2667ba3 procaddr: add const 2023-12-10 19:08:56 -05:00
Kevin Trocolli 6b732bfbd6 add io and serial to procaddr table 2023-12-10 18:59:02 -05:00
Kevin Trocolli aaeed25995 impl procaddr hook 2023-12-10 18:41:10 -05:00
Kevin Trocolli 888d068d58 allow iohook and serial_hook to land on DLLs loaded after initialization 2023-11-30 02:18:50 -05:00
Matt Bilker f0e5f82028 hook/iohook.c: Fix race condition at during iohook initialization
- If another DLL being loaded spawns a thread that begins doing I/O,
  then there is a race condition where `hook_table_apply` is still
  applying the hooks and has not returned yet but the hooked functions
  are called by those other threads. This causes the assert on
  `iohook_initted` to trigger.

- The easy fix is to always enter the mutex to ensure the hooks have
  been applied and function addresses for `CreateFileW` and
  `SetFilePointerEx` have been resolved.
2021-10-25 11:20:48 -04:00
Decaf Code 69f7e3b48c hook/iohook.c: Add iohook_open_nul_fd()
This provides a replacement for iohook_open_dummy_fd() whose error
handling is more consistent with the rest of this library.
2019-11-03 10:57:33 -05:00
Decaf Code f084531454 hook/iobuf.c: Add readers and writers for 64-bit uints 2019-10-18 19:05:37 -04:00
Decaf Code 51e674b75a Remove -Wall from CFLAGS
Meson has its own mechanisms for configuring warning levels.
2019-10-18 19:05:06 -04:00
Decaf Code 16e187651e hook/hr.c: Split out hr_to_win32_error() 2019-09-04 13:29:25 -04:00
Decaf Code 8d2a67f64d s/__amd64/_M_AMD64/
Newer MSVC seems to use a different preprocessor symbol to denote
64-bit builds.
2019-05-02 19:37:11 -04:00
Decaf Code 6fad9ad7f7 Use Meson get_argument_syntax()
Newer versions of Meson introduce a more reliable way to detect
the compiler's expected command-line argument style.
2019-05-01 21:00:59 -04:00
Decaf Code dfb7fbf219 Remove PCH source file
Newer versions of Meson create this automatically for MSVC builds.
2019-05-01 21:00:11 -04:00
Decaf Code 2ed2be349e hook/table.c: Add hacks to deal with Win32 apisets 2019-03-03 19:46:30 -05:00
Decaf Code 8846e4d46f inject: Detect remote LoadLibrary failure 2019-03-03 19:46:30 -05:00
Decaf Code c5f08113a5 Tag v0.2.2
I forgot to update the Meson version for the past few releases.
whoops.
2018-11-23 14:05:53 -05:00
Decaf Code 1b99fb16b8 hook/iohook.c: Remove ioctl asserts
These assertions don't seem to hold for certain real ioctl errors.
2018-11-23 13:58:25 -05:00
Decaf Code b58369f9e1 inject/options.c: Fix signedness mismatch 2018-11-23 13:58:25 -05:00
Decaf Code bfee3db861 Fix MSVC compatibility issues
Project now builds in Visual Studio 2017, probably earlier versions
too as long as they support enough of C99.
2018-11-23 13:58:25 -05:00
Decaf Code d985965639 Fix non-PCH build 2018-11-23 13:46:49 -05:00
Decaf Code 2f7df12fc8 hook/iohook.c: Fix DeviceIoControl error path 2018-11-20 19:49:38 -05:00
Decaf Code 7526c7274a hook/table.c: Populate links from first match
The loaded module list is kept in the order the modules are first
loaded. Using the first loaded module (i.e. the EXE) will help
ensure that multiple hook DLLs stack correctly. Previously the link
was taken from the most-recently loaded module.
2018-11-20 13:17:34 -05:00
Decaf Code a956987fe0 hook/process.c: Fix 64-bit startup hijack
Start address goes in RCX in 64-bit mode, EAX in 32-bit mode.
2018-11-13 20:06:40 -05:00
Matt Bilker 3df87b35e3 hook/table.c: Import assert.h 2018-11-13 20:05:56 -05:00
Decaf Code de528c108f hooklib/uart.c: Add emulated UART 2018-11-10 11:24:57 -05:00
Decaf Code 6465ab6f09 hooklib/serial.c: Add iohook wrappers for Win32 UART ops 2018-11-10 11:24:57 -05:00
Decaf Code 74697b7cb3 hooklib: Add empty static library 2018-11-10 11:24:57 -05:00
Decaf Code 71bbe49615 inject: Add initial DLL injector tool 2018-11-10 11:24:57 -05:00
Decaf Code ceea0677a4 hook/args.c: Add command line recovery helper 2018-11-10 11:24:57 -05:00
Decaf Code d77e6d15cf hook/com-proxy.c: Add COM proxying mechanism 2018-11-10 11:24:57 -05:00
Decaf Code 73c893168c hook/iohook.c: Add Win32 I/O interception mechanism 2018-11-10 11:24:57 -05:00
Decaf Code 80c1f73f85 hook/iobuf.c: Add IO buffer descriptors 2018-11-08 14:08:36 -05:00
Decaf Code 6a80ed1875 hook/process.c: Add process startup interceptor 2018-11-08 14:08:36 -05:00
Decaf Code 7d3203b6b1 hook/hr.c: Add HRESULT helpers 2018-11-08 14:08:36 -05:00
Decaf Code a5b3a5c48b hook/table.c: Add IAT hooking mechanism 2018-11-07 11:51:14 -05:00