Skip to main content

Module attach

Module attach 

Source
Expand description

Attach to a CoreCLR game’s already-running runtime from a native mod loaded before the runtime starts (via LD_PRELOAD on Linux, or an injected DLL on Windows).

CoreCLR has no public “attach to the running runtime” C API: coreclr_create_delegate needs the host handle and domain id the game’s host created, and the runtime initialises only once per process. So we capture them as the game creates them — inline-hooking the loader to see coreclr arrive (it is loaded late and resolved dynamically, so symbol interposition misses it), then inline-hooking coreclr_initialize to read its output.

The loader differs per platform (dlopen / LoadLibraryExW); everything else, including the coreclr_initialize hook, is shared. Requires x86_64, where the inline-hook trampoline works. With the captured ClrHost, ClrHost::attach builds a Runtime bound to that CLR.

Structs§

ClrHost
A handle to the game’s running CoreCLR, captured from coreclr_initialize.

Functions§

diag
Appends a line to /tmp/hao-diag.log — early-attach diagnostics that work before any tracing subscriber exists (and from signal-unsafe spots where stdout may be redirected by the host process).
ensure_loader_hook
Installs the loader hook (dlopen / LoadLibraryExW) so that the runtime’s library load is detected as early as possible.
on_clr_init
Runs callback once the game’s CoreCLR host has been captured. Call it from a mod’s entry point (which the loader runs before the game starts the runtime).