Skip to content

Instantly share code, notes, and snippets.

@popsUlfr
Created October 31, 2018 17:24
Show Gist options
  • Save popsUlfr/363a6a0bf981cc2ae4308bf2cf0758fb to your computer and use it in GitHub Desktop.
Save popsUlfr/363a6a0bf981cc2ae4308bf2cf0758fb to your computer and use it in GitHub Desktop.
Loads a custom ntdll.dll.so in wine for Bayonetta
/* gcc -m32 -O2 -Wall -shared -fPIC -ldl -o ntdll_override.so ntdll_override.c */
#define _GNU_SOURCE
#include <dlfcn.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <stdlib.h>
typedef void* (*wine_dlopen_func_type)(const char *filename, int flag, char *error, size_t errorsize);
void *wine_dlopen(const char *filename, int flag, char *error, size_t errorsize)
{
static const char* NTDLL = "ntdll.dll.so";
static wine_dlopen_func_type wine_dlopen_func = NULL;
if (!wine_dlopen_func)
wine_dlopen_func = (wine_dlopen_func_type)dlsym(RTLD_NEXT, "wine_dlopen");
static char ntdll_path_buf[PATH_MAX+1];
static const char* ntdll_path = NULL;
if (!ntdll_path && !access(NTDLL, R_OK))
ntdll_path = realpath(NTDLL, ntdll_path_buf);
if (ntdll_path) {
const char *c;
if ((c = strrchr(filename, '/')) && *c)
++c;
else
c = filename;
if (!strcmp(c, NTDLL))
filename = ntdll_path;
}
return wine_dlopen_func(filename, flag, error, errorsize);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment