Skip to content

Commit 5721257

Browse files
authored
Handle ordinals in GetProcAddress detour (#66)
As it turns out, symbols exported by a DLL don't necessary have to have text symbols - but they do have a number, the symbol ordinal, which is a valid way to address and access the symbol. GetProcAddress supports this behaviour - in this case, the ordinal is passed as the pointer value. Which, in Doorstop's detour, still gets treated as a string, and which subsequently causes lstrcmp to segfault under some very specific conditions (i.e. when the calling module tries to resolve a procedure by its ordinal). In my case Unity 6 was accessing the 0x65 ordinal of d3d12.dll (located in system directory). (Did some poking - the symbol is named, which is weird, and named "D3D12CreateDevice", which checks out.) As per GetProcAddress docs, if the value of the lpProcName pointer is an ordinal, high-word value of the pointer must be zero. This pull request addresses that quirk by inserting HIWORD macro as an additional condition to the detour check routine. GetProcAddress docs: https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress
1 parent 4b2d10a commit 5721257

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/windows/entrypoint.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ void capture_mono_path(void *handle) {
137137

138138
bool_t initialized = FALSE;
139139
void *WINAPI get_proc_address_detour(void *module, char *name) {
140+
// If the lpProcName pointer contains an ordinal rather than a string,
141+
// high-word value of the pointer is zero (see PR #66)
140142
#define REDIRECT_INIT(init_name, init_func, target, extra_init) \
141-
if (lstrcmpA(name, init_name) == 0) { \
143+
if (HIWORD(name) && lstrcmpA(name, init_name) == 0) { \
142144
if (!initialized) { \
143145
initialized = TRUE; \
144146
LOG("Got %S at %p", init_name, module); \

0 commit comments

Comments
 (0)