Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigate Wine _stricmp issue. #9

Merged
merged 1 commit into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ LDFLAGS := \
OBJS := \
obj/dll/rugburn/main.o \
obj/hooks/kernel32/inject.o \
obj/hooks/msvcr100/msvcr100.o \
obj/hooks/user32/window.o \
obj/hooks/ws2_32/redir.o \
obj/hooks/wininet/netredir.o \
Expand Down
30 changes: 24 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/hooks/hooks.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "hooks.h"

#include "kernel32/inject.h"
#include "msvcr100/msvcr100.h"
#include "user32/window.h"
#include "wininet/netredir.h"
#include "ws2_32/redir.h"

VOID InitHooks() {
InitInjectHook();
InitMsvcr100Hook();
InitWindowHook();
InitNetRedirHook();
InitRedirHook();
Expand Down
56 changes: 56 additions & 0 deletions src/hooks/msvcr100/msvcr100.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "msvcr100.h"
#include "../../patch.h"

typedef int (__cdecl* STRICMPFNPTR)(const char *s1, const char *s2);
typedef char *(__cdecl* SETLOCALEFNPTR)(int category, const char *locale);

static HMODULE hMsvcr100Module = NULL;
static STRICMPFNPTR pStricmp = NULL;
static SETLOCALEFNPTR pSetLocale = NULL;

int lower(int c) {
return (c >= 'A' && c <= 'Z') ? c + 'a' - 'A' : c;
}

int __cdecl StricmpHook(const char *s1, const char *s2) {
int result = 0;
if (!s1 || !s2) return 0x7fffffff;
while (!result) {
result = lower(*s1) - lower(*s2);
if (!*s1 || !*s2) break;
s1++, s2++;
}
return result;
}

VOID InitMsvcr100Hook() {
const char *oldlocale;
int result;

hMsvcr100Module = LoadLib("msvcr100");
if (!hMsvcr100Module) {
Log("Not checking for Wine _stricmp bug: msvcr100 not found.\n");
return;
}

pStricmp = GetProc(hMsvcr100Module, "_stricmp");
pSetLocale = GetProc(hMsvcr100Module, "setlocale");
oldlocale = pSetLocale(2, NULL);
if (!pStricmp || !pSetLocale) {
Log("Not checking for Wine _stricmp bug: msvcr100 functions not found.\n");
}

Log("Checking for Wine _stricmp bug; current locale: %s - Temporarily switching to Kor.\n", oldlocale);

pSetLocale(2, "Kor");
result = pStricmp("\xB3\xA1", "\xBC\xBC");
pSetLocale(2, oldlocale);

if (result == 0) {
Log("Wine _stricmp bug detected; mitigating.\n");
pStricmp = HookProc(hMsvcr100Module, "_stricmp", StricmpHook);
} else {
Log("Wine _stricmp bug not detected.\n");
}
}

8 changes: 8 additions & 0 deletions src/hooks/msvcr100/msvcr100.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef HOOKS_MSVCR100_MSVCR100_H
#define HOOKS_MSVCR100_MSVCR100_H

#include "../../common.h"

VOID InitMsvcr100Hook();

#endif