Files
kyoubate-haruka a3443a8b5b Add iohook for GetFileType (#7)
Unity (or mono in that case) is a bit special when it comes to handling file I/O, as before any operation (read, write) it will do a call to `GetFileType` to determine how to set the parameters for the following winapi calls. Handles that we replace with `iohook_open_nul_fd` however don't return the expected `FILE_TYPE_DISK`, as a null handle is a `FILE_TYPE_CHAR` which works by chance for serial ports, but not for files:

Related: https://gitea.tendokyu.moe/TeamTofuShop/segatools/issues/116
Reviewed-on: https://gitea.tendokyu.moe/TeamTofuShop/capnhook/pulls/7
Co-authored-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com>
Co-committed-by: kyoubate-haruka <46010460+kyoubate-haruka@users.noreply.github.com>
2026-07-05 15:33:19 +00:00

54 lines
1.0 KiB
C

#pragma once
#include <windows.h>
#include <stddef.h>
#include <stdint.h>
#include "hook/iobuf.h"
enum irp_op {
IRP_OP_OPEN,
IRP_OP_CLOSE,
IRP_OP_READ,
IRP_OP_WRITE,
IRP_OP_IOCTL,
IRP_OP_FSYNC,
IRP_OP_SEEK,
IRP_OP_FTYPE
};
struct irp {
enum irp_op op;
size_t next_handler;
HANDLE fd;
OVERLAPPED *ovl;
struct const_iobuf write;
struct iobuf read;
uint32_t ioctl;
const wchar_t *open_filename;
uint32_t open_access;
uint32_t open_share;
SECURITY_ATTRIBUTES *open_sa;
uint32_t open_creation;
uint32_t open_flags;
HANDLE *open_tmpl;
uint32_t seek_origin;
int64_t seek_offset;
uint64_t seek_pos;
uint32_t file_type;
};
typedef HRESULT (*iohook_fn_t)(struct irp *irp);
HANDLE iohook_open_dummy_fd(void)
#ifdef __GNUC__
__attribute__((deprecated("Use iohook_open_nul_fd instead")))
#endif
;
HRESULT iohook_open_nul_fd(HANDLE *fd);
HRESULT iohook_push_handler(iohook_fn_t fn);
HRESULT iohook_invoke_next(struct irp *irp);
void iohook_apply_hooks(HMODULE target);