fix: 修复视频无法从vfs加载
This commit is contained in:
30
dllmain.cpp
30
dllmain.cpp
@@ -17,6 +17,9 @@ static BOOL(WINAPI *TrueCloseHandle)(HANDLE hObject) = CloseHandle;
|
|||||||
static DWORD(WINAPI *TrueGetFileSize)(HANDLE hFile, LPDWORD lpFileSizeHigh) = GetFileSize;
|
static DWORD(WINAPI *TrueGetFileSize)(HANDLE hFile, LPDWORD lpFileSizeHigh) = GetFileSize;
|
||||||
static decltype(GetFileSizeEx) *TrueGetFileSizeEx = GetFileSizeEx;
|
static decltype(GetFileSizeEx) *TrueGetFileSizeEx = GetFileSizeEx;
|
||||||
static DWORD(WINAPI *TrueSetFilePointer)(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod) = SetFilePointer;
|
static DWORD(WINAPI *TrueSetFilePointer)(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod) = SetFilePointer;
|
||||||
|
static decltype(GetFileType) *TrueGetFileType = GetFileType;
|
||||||
|
static decltype(GetFileAttributesW) *TrueGetFileAttributesW = GetFileAttributesW;
|
||||||
|
static decltype(GetFileAttributesExW) *TrueGetFileAttributesExW = GetFileAttributesExW;
|
||||||
|
|
||||||
static Config config;
|
static Config config;
|
||||||
static std::wstring defaultFont;
|
static std::wstring defaultFont;
|
||||||
@@ -144,6 +147,27 @@ DWORD WINAPI HookedSetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDi
|
|||||||
return TrueSetFilePointer(hFile, lDistanceToMove, lpDistanceToMoveHigh, dwMoveMethod);
|
return TrueSetFilePointer(hFile, lDistanceToMove, lpDistanceToMoveHigh, dwMoveMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DWORD WINAPI HookedGetFileType(HANDLE hFile) {
|
||||||
|
if (vfs.ContainsHandle(hFile)) {
|
||||||
|
return FILE_TYPE_DISK;
|
||||||
|
}
|
||||||
|
return TrueGetFileType(hFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD WINAPI HookedGetFileAttributesW(LPCWSTR lpFileName) {
|
||||||
|
if (vfs.ContainsFile(lpFileName)) {
|
||||||
|
return FILE_ATTRIBUTE_READONLY;
|
||||||
|
}
|
||||||
|
return TrueGetFileAttributesW(lpFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL WINAPI HookedGetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation) {
|
||||||
|
if (vfs.ContainsFile(lpFileName)) {
|
||||||
|
return vfs.GetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation);
|
||||||
|
}
|
||||||
|
return TrueGetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" __declspec(dllexport) void Attach() {
|
extern "C" __declspec(dllexport) void Attach() {
|
||||||
config.Load("config.txt");
|
config.Load("config.txt");
|
||||||
if (!wchar_util::str_to_wstr(defaultFont, config.configs["defaultFont"], CP_UTF8)) {
|
if (!wchar_util::str_to_wstr(defaultFont, config.configs["defaultFont"], CP_UTF8)) {
|
||||||
@@ -169,6 +193,9 @@ extern "C" __declspec(dllexport) void Attach() {
|
|||||||
DetourAttach(&TrueGetFileSize, HookedGetFileSize);
|
DetourAttach(&TrueGetFileSize, HookedGetFileSize);
|
||||||
DetourAttach(&TrueGetFileSizeEx, HookedGetFileSizeEx);
|
DetourAttach(&TrueGetFileSizeEx, HookedGetFileSizeEx);
|
||||||
DetourAttach(&TrueSetFilePointer, HookedSetFilePointer);
|
DetourAttach(&TrueSetFilePointer, HookedSetFilePointer);
|
||||||
|
DetourAttach(&TrueGetFileType, HookedGetFileType);
|
||||||
|
DetourAttach(&TrueGetFileAttributesW, HookedGetFileAttributesW);
|
||||||
|
DetourAttach(&TrueGetFileAttributesExW, HookedGetFileAttributesExW);
|
||||||
DetourTransactionCommit();
|
DetourTransactionCommit();
|
||||||
std::string stringReplaceFile = config.configs["stringReplaceFile"];
|
std::string stringReplaceFile = config.configs["stringReplaceFile"];
|
||||||
if (!stringReplaceFile.empty()) {
|
if (!stringReplaceFile.empty()) {
|
||||||
@@ -195,6 +222,9 @@ extern "C" __declspec(dllexport) void Detach() {
|
|||||||
DetourDetach(&TrueGetFileSize, HookedGetFileSize);
|
DetourDetach(&TrueGetFileSize, HookedGetFileSize);
|
||||||
DetourDetach(&TrueGetFileSizeEx, HookedGetFileSizeEx);
|
DetourDetach(&TrueGetFileSizeEx, HookedGetFileSizeEx);
|
||||||
DetourDetach(&TrueSetFilePointer, HookedSetFilePointer);
|
DetourDetach(&TrueSetFilePointer, HookedSetFilePointer);
|
||||||
|
DetourDetach(&TrueGetFileType, HookedGetFileType);
|
||||||
|
DetourDetach(&TrueGetFileAttributesW, HookedGetFileAttributesW);
|
||||||
|
DetourDetach(&TrueGetFileAttributesExW, HookedGetFileAttributesExW);
|
||||||
DetourTransactionCommit();
|
DetourTransactionCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
43
vfs.cpp
43
vfs.cpp
@@ -3,6 +3,7 @@
|
|||||||
#include "str_util.h"
|
#include "str_util.h"
|
||||||
#include "fileop.h"
|
#include "fileop.h"
|
||||||
#include "shlwapi.h"
|
#include "shlwapi.h"
|
||||||
|
#include "time_util.h"
|
||||||
|
|
||||||
VFS::VFS() {
|
VFS::VFS() {
|
||||||
WCHAR exePath[MAX_PATH];
|
WCHAR exePath[MAX_PATH];
|
||||||
@@ -42,7 +43,7 @@ bool VFS::AddArchive(std::string path) {
|
|||||||
}
|
}
|
||||||
std::string name = st.name;
|
std::string name = st.name;
|
||||||
name = str_util::str_replace(name, "/", "\\");
|
name = str_util::str_replace(name, "/", "\\");
|
||||||
files[name] = st.size;
|
files[name] = st;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -74,7 +75,7 @@ bool VFS::AddArchiveFromResource(HMODULE hModule, int resourceID) {
|
|||||||
}
|
}
|
||||||
std::string name = st.name;
|
std::string name = st.name;
|
||||||
name = str_util::str_replace(name, "/", "\\");
|
name = str_util::str_replace(name, "/", "\\");
|
||||||
files[name] = st.size;
|
files[name] = st;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -193,7 +194,7 @@ DWORD VFS::GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh) {
|
|||||||
}
|
}
|
||||||
auto data = *f;
|
auto data = *f;
|
||||||
auto name = data.second;
|
auto name = data.second;
|
||||||
auto size = files[name];
|
auto size = files[name].size;
|
||||||
if (lpFileSizeHigh) {
|
if (lpFileSizeHigh) {
|
||||||
*lpFileSizeHigh = size >> 32;
|
*lpFileSizeHigh = size >> 32;
|
||||||
}
|
}
|
||||||
@@ -208,7 +209,7 @@ BOOL VFS::GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize) {
|
|||||||
}
|
}
|
||||||
auto data = *f;
|
auto data = *f;
|
||||||
auto name = data.second;
|
auto name = data.second;
|
||||||
auto size = files[name];
|
auto size = files[name].size;
|
||||||
lpFileSize->LowPart = size & 0xFFFFFFFF;
|
lpFileSize->LowPart = size & 0xFFFFFFFF;
|
||||||
lpFileSize->HighPart = size >> 32;
|
lpFileSize->HighPart = size >> 32;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -239,3 +240,37 @@ DWORD VFS::SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceTo
|
|||||||
std::string VFS::GetBasePath() {
|
std::string VFS::GetBasePath() {
|
||||||
return base_path;
|
return base_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL VFS::GetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation) {
|
||||||
|
std::string path;
|
||||||
|
if (!wchar_util::wstr_to_str(path, lpFileName, CP_UTF8)) {
|
||||||
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
path = str_util::str_replace(path, "/", "\\");
|
||||||
|
if (fileop::isabs(path)) {
|
||||||
|
path = fileop::relpath(path, base_path);
|
||||||
|
}
|
||||||
|
auto c = files.find(path);
|
||||||
|
if (c == files.end()) {
|
||||||
|
SetLastError(ERROR_FILE_NOT_FOUND);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
auto st = (*c).second;
|
||||||
|
if (fInfoLevelId == GetFileExInfoStandard) {
|
||||||
|
if (!lpFileInformation) {
|
||||||
|
SetLastError(ERROR_INVALID_PARAMETER);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
WIN32_FILE_ATTRIBUTE_DATA data;
|
||||||
|
data.dwFileAttributes = FILE_ATTRIBUTE_READONLY;
|
||||||
|
time_util::time_t_to_file_time(st.mtime, &data.ftLastWriteTime);
|
||||||
|
data.ftCreationTime = data.ftLastWriteTime;
|
||||||
|
data.ftLastAccessTime = data.ftLastWriteTime;
|
||||||
|
data.nFileSizeHigh = st.size >> 32;
|
||||||
|
data.nFileSizeLow = st.size & 0xFFFFFFFF;
|
||||||
|
memcpy(lpFileInformation, &data, sizeof(data));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|||||||
3
vfs.hpp
3
vfs.hpp
@@ -40,10 +40,11 @@ class VFS {
|
|||||||
HANDLE CreateFileW(std::wstring path);
|
HANDLE CreateFileW(std::wstring path);
|
||||||
bool ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead);
|
bool ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead);
|
||||||
void CloseHandle(HANDLE hFile);
|
void CloseHandle(HANDLE hFile);
|
||||||
|
BOOL GetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation);
|
||||||
DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
|
DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
|
||||||
BOOL GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize);
|
BOOL GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize);
|
||||||
DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
|
DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
|
||||||
std::unordered_map<std::string, zip_uint64_t, CaseInsensitiveHash, CaseInsensitiveEqual> files;
|
std::unordered_map<std::string, zip_stat_t, CaseInsensitiveHash, CaseInsensitiveEqual> files;
|
||||||
std::string GetBasePath();
|
std::string GetBasePath();
|
||||||
private:
|
private:
|
||||||
std::string base_path;
|
std::string base_path;
|
||||||
|
|||||||
Reference in New Issue
Block a user