Skip to content

Commit

Permalink
Improve replacing xinput1_3 with xinput9_1 (#583)
Browse files Browse the repository at this point in the history
The previous logic incorrectly loaded compared the whole argument, which may be a path, to the string literal.
This fix checks if the argument ends with the string literal instead.
  • Loading branch information
Jan200101 authored Nov 22, 2023
1 parent aeecd7a commit 90e0376
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion NorthstarDLL/core/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <filesystem>
#include <Psapi.h>

#define XINPUT1_3_DLL "XInput1_3.dll"

AUTOHOOK_INIT()

// called from the ON_DLL_LOAD macros
Expand Down Expand Up @@ -393,8 +395,11 @@ HMODULE, WINAPI, (LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags))
{
HMODULE moduleAddress;

LPCSTR lpLibFileNameEnd = lpLibFileName + strlen(lpLibFileName);
LPCSTR lpLibName = lpLibFileNameEnd - strlen(XINPUT1_3_DLL);

// replace xinput dll with one that has ASLR
if (!strncmp(lpLibFileName, "XInput1_3.dll", 14))
if (lpLibFileName <= lpLibName && !strncmp(lpLibName, XINPUT1_3_DLL, strlen(XINPUT1_3_DLL) + 1))
{
moduleAddress = _LoadLibraryExA("XInput9_1_0.dll", hFile, dwFlags);

Expand Down

0 comments on commit 90e0376

Please sign in to comment.