Files
TeamTofuShop_segatools/common/platform/ewf.h
T
kyoubate-haruka d5bde32df7 ewf: implement EWF virtualization (#84)
(Yeah, I know the OS may cache disk reads, but that wasn't the concern)

The ALLS series of cabs runs EWF to prevent anything from being written to C:\.

This PR adds another layer to iohook to redirect specific open/read/write/close operations to a virtual file table to prevent disk activity, and thus simulate the presence of EWF. This was mainly aimed at ALPB's billing files. Seriously, look at this - especially the timestamps, Sega wtf are you doing.

This does not affect other path hooks. It's turned off by default and will throw an error if the current executable resides on C:\.

Tested with FGO and APMv3.

![22bf755754[1].png](/attachments/31771aee-2e4d-4e4f-85e3-c5eec63c6f78)

Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/segatools/pulls/84
Co-authored-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com>
Co-committed-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com>
2025-12-25 00:04:30 +01:00

42 lines
1.2 KiB
C

#pragma once
#include <windows.h>
#include <stdbool.h>
#include <stddef.h>
#define EWF_MAX_VIRTUAL_FILES 255
#define EWF_MAX_HANDLES 50000
#define EWF_DEFAULT_FILE_BUFFER_SIZE 1024
struct ewf_config {
bool enable;
bool full;
};
// A virtual file that we are storing in memory.
struct ewf_virtual_file {
// The handle that we use internally. This is NULL for a handle that doesn't exist and non-NULL for a handle that maps to a virtual file.
HANDLE virtual_handle;
// The path that is being virtualized (ex. C:\sample.txt).
wchar_t path[MAX_PATH];
// The current length of the virtual file.
size_t length;
// The current length of the allocated data buffer.
size_t alloc_length;
// Pointer to some buffer holding file data. This is guaranteed to be at least length bytes in size. If length is zero, this may be NULL.
void* data;
};
// An open handle to a ewf_virtual_file.
struct ewf_real_handle {
// The "real" handle passed to the application as a result of CreateFile, etc.
HANDLE real_handle;
// The virtual file the real handle points to.
struct ewf_virtual_file* virtual_file;
// The current read offset.
size_t offset;
};
HRESULT ewf_hook_init(const struct ewf_config* config);