mirror of
https://github.com/djhackersdev/bemanitools.git
synced 2024-11-27 16:00:52 +01:00
Add in more filesystem hooks
This commit is contained in:
parent
402d0d4ca4
commit
d7235c3c2c
@ -1,6 +1,7 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -12,14 +13,56 @@
|
||||
#include "util/mem.h"
|
||||
|
||||
static BOOL STDCALL my_SetCurrentDirectoryA(LPCTSTR lpPathName);
|
||||
static HANDLE STDCALL my_FindFirstFileA(
|
||||
LPCSTR lpFileName,
|
||||
LPWIN32_FIND_DATAA lpFindFileData);
|
||||
static HANDLE STDCALL my_CreateFileA(
|
||||
LPCSTR lpFileName,
|
||||
DWORD dwDesiredAccess,
|
||||
DWORD dwShareMode,
|
||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
DWORD dwCreationDisposition,
|
||||
DWORD dwFlagsAndAttributes,
|
||||
HANDLE hTemplateFile);
|
||||
static BOOL WINAPI my_CreateDirectoryA(
|
||||
LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
|
||||
|
||||
static BOOL(STDCALL *real_SetCurrentDirectoryA)(LPCTSTR lpPathName);
|
||||
static HANDLE(STDCALL *real_FindFirstFileA)(
|
||||
LPCSTR lpFileName,
|
||||
LPWIN32_FIND_DATAA lpFindFileData);
|
||||
static HANDLE(STDCALL *real_CreateFileA)(
|
||||
LPCSTR lpFileName,
|
||||
DWORD dwDesiredAccess,
|
||||
DWORD dwShareMode,
|
||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
DWORD dwCreationDisposition,
|
||||
DWORD dwFlagsAndAttributes,
|
||||
HANDLE hTemplateFile);
|
||||
static BOOL(WINAPI *real_CreateDirectoryA)(
|
||||
LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
|
||||
|
||||
static const struct hook_symbol filesystem_hook_syms[] = {
|
||||
{
|
||||
.name = "CreateFileA",
|
||||
.patch = my_CreateFileA,
|
||||
.link = (void **) &real_CreateFileA
|
||||
},
|
||||
{
|
||||
.name = "SetCurrentDirectoryA",
|
||||
.patch = my_SetCurrentDirectoryA,
|
||||
.link = (void **) &real_SetCurrentDirectoryA,
|
||||
},
|
||||
{
|
||||
.name = "FindFirstFileA",
|
||||
.patch = my_FindFirstFileA,
|
||||
.link = (void **) &real_FindFirstFileA
|
||||
},
|
||||
{
|
||||
.name = "CreateDirectoryA",
|
||||
.patch = my_CreateDirectoryA,
|
||||
.link = (void **) &real_CreateDirectoryA
|
||||
},
|
||||
};
|
||||
|
||||
void ddrhook1_get_launcher_path_parts(char **output_path, char **output_foldername) {
|
||||
@ -82,24 +125,121 @@ void ddrhook1_get_launcher_path_parts(char **output_path, char **output_folderna
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL STDCALL my_SetCurrentDirectoryA(LPCTSTR lpPathName)
|
||||
static char *ddrhook1_filesystem_get_path(LPCTSTR path)
|
||||
{
|
||||
if (stricmp(lpPathName, "D:/HDX") == 0
|
||||
|| stricmp(lpPathName, "D:\\HDX") == 0) {
|
||||
char *new_path;
|
||||
ddrhook1_get_launcher_path_parts(&new_path, NULL);
|
||||
char *new_path = NULL;
|
||||
|
||||
if (new_path != NULL) {
|
||||
bool r = real_SetCurrentDirectoryA(new_path);
|
||||
log_misc("Changed directory %s -> %s", lpPathName, new_path);
|
||||
free(new_path);
|
||||
return r;
|
||||
// Hardcoded paths: D:/HDX, E:/conf, E:/conf/nvram, E:/conf/raw
|
||||
if (stricmp(path, "D:/HDX") == 0
|
||||
|| stricmp(path, "D:\\HDX") == 0) {
|
||||
ddrhook1_get_launcher_path_parts(&new_path, NULL);
|
||||
} else if (strnicmp(path, "E:/conf", 7) == 0
|
||||
|| strnicmp(path, "E:\\conf", 7) == 0) {
|
||||
char *launcher_folder;
|
||||
char *conf_path;
|
||||
|
||||
ddrhook1_get_launcher_path_parts(NULL, &launcher_folder);
|
||||
conf_path = strstr(path, "conf");
|
||||
|
||||
if (conf_path && launcher_folder) {
|
||||
new_path = (char*)xmalloc(MAX_PATH);
|
||||
sprintf(new_path, "%s\\%s", launcher_folder, conf_path);
|
||||
}
|
||||
}
|
||||
|
||||
return new_path;
|
||||
}
|
||||
|
||||
static BOOL STDCALL my_SetCurrentDirectoryA(LPCTSTR lpPathName)
|
||||
{
|
||||
char *new_path = ddrhook1_filesystem_get_path(lpPathName);
|
||||
|
||||
if (new_path != NULL) {
|
||||
bool r = real_SetCurrentDirectoryA(new_path);
|
||||
log_misc("SetCurrentDirectoryA remapped path %s -> %s", lpPathName, new_path);
|
||||
free(new_path);
|
||||
return r;
|
||||
}
|
||||
|
||||
return real_SetCurrentDirectoryA(lpPathName);
|
||||
}
|
||||
|
||||
static HANDLE STDCALL my_FindFirstFileA(
|
||||
LPCSTR lpFileName,
|
||||
LPWIN32_FIND_DATAA lpFindFileData)
|
||||
{
|
||||
char *new_path = ddrhook1_filesystem_get_path(lpFileName);
|
||||
|
||||
if (new_path) {
|
||||
HANDLE r = real_FindFirstFileA(
|
||||
new_path,
|
||||
lpFindFileData);
|
||||
|
||||
log_misc("FindFirstFileA remapped path: %s -> %s\n", lpFileName, new_path);
|
||||
|
||||
free(new_path);
|
||||
return r;
|
||||
}
|
||||
|
||||
return real_FindFirstFileA(
|
||||
lpFileName,
|
||||
lpFindFileData);
|
||||
}
|
||||
|
||||
static HANDLE STDCALL my_CreateFileA(
|
||||
LPCSTR lpFileName,
|
||||
DWORD dwDesiredAccess,
|
||||
DWORD dwShareMode,
|
||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
DWORD dwCreationDisposition,
|
||||
DWORD dwFlagsAndAttributes,
|
||||
HANDLE hTemplateFile)
|
||||
{
|
||||
char *new_path = ddrhook1_filesystem_get_path(lpFileName);
|
||||
|
||||
if (new_path) {
|
||||
HANDLE r = real_CreateFileA(
|
||||
new_path,
|
||||
dwDesiredAccess,
|
||||
dwShareMode,
|
||||
lpSecurityAttributes,
|
||||
dwCreationDisposition,
|
||||
dwFlagsAndAttributes,
|
||||
hTemplateFile);
|
||||
|
||||
log_misc("CreateFileA remapped path %s -> %s", lpFileName, new_path);
|
||||
|
||||
free(new_path);
|
||||
return r;
|
||||
}
|
||||
|
||||
return real_CreateFileA(
|
||||
new_path ? new_path : lpFileName,
|
||||
dwDesiredAccess,
|
||||
dwShareMode,
|
||||
lpSecurityAttributes,
|
||||
dwCreationDisposition,
|
||||
dwFlagsAndAttributes,
|
||||
hTemplateFile);
|
||||
}
|
||||
|
||||
BOOL WINAPI my_CreateDirectoryA(
|
||||
LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
||||
{
|
||||
char *new_path = ddrhook1_filesystem_get_path(lpPathName);
|
||||
|
||||
if (new_path) {
|
||||
BOOL r = real_CreateDirectoryA(new_path, lpSecurityAttributes);
|
||||
|
||||
log_misc("CreateDirectoryA remapped path %s -> %s", lpPathName, new_path);
|
||||
|
||||
free(new_path);
|
||||
return r;
|
||||
}
|
||||
|
||||
return real_CreateDirectoryA(lpPathName, lpSecurityAttributes);
|
||||
}
|
||||
|
||||
void ddrhook1_filesystem_hook_init()
|
||||
{
|
||||
hook_table_apply(
|
||||
|
Loading…
Reference in New Issue
Block a user