From 446f41deacd0fdfc1646c7ac5a25d167e84ba6e5 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Mon, 3 Mar 2025 20:34:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0VFS=E7=B1=BB=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=A7=E5=B0=8F=E5=86=99=E4=B8=8D=E6=95=8F?= =?UTF-8?q?=E6=84=9F=E7=9A=84=E6=96=87=E4=BB=B6=E6=9F=A5=E6=89=BE=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E6=9C=AA=E6=89=BE=E5=88=B0?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dllmain.cpp | 12 ++++++------ vfs.cpp | 6 ++++++ vfs.hpp | 24 +++++++++++++++++++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/dllmain.cpp b/dllmain.cpp index 70a02bd..5fa03b7 100644 --- a/dllmain.cpp +++ b/dllmain.cpp @@ -262,9 +262,9 @@ extern "C" __declspec(dllexport) void Attach() { DetourAttach(&TrueCloseHandle, HookedCloseHandle); DetourAttach(&TrueGetFileSize, HookedGetFileSize); DetourAttach(&TrueSetFilePointer, HookedSetFilePointer); - DetourAttach(&OriginalFindFirstFileExW, HookedFindFirstFileExW); - DetourAttach(&OriginalFindNextFileW, HookedFindNextFileW); - DetourAttach(&OriginalFindClose, HookedFindClose); + // DetourAttach(&OriginalFindFirstFileExW, HookedFindFirstFileExW); + // DetourAttach(&OriginalFindNextFileW, HookedFindNextFileW); + // DetourAttach(&OriginalFindClose, HookedFindClose); DetourTransactionCommit(); #if _DEBUG while( !::IsDebuggerPresent() ) @@ -284,9 +284,9 @@ extern "C" __declspec(dllexport) void Detach() { DetourDetach(&TrueCloseHandle, HookedCloseHandle); DetourDetach(&TrueGetFileSize, HookedGetFileSize); DetourDetach(&TrueSetFilePointer, HookedSetFilePointer); - DetourDetach(&OriginalFindFirstFileExW, HookedFindFirstFileExW); - DetourDetach(&OriginalFindNextFileW, HookedFindNextFileW); - DetourDetach(&OriginalFindClose, HookedFindClose); + // DetourDetach(&OriginalFindFirstFileExW, HookedFindFirstFileExW); + // DetourDetach(&OriginalFindNextFileW, HookedFindNextFileW); + // DetourDetach(&OriginalFindClose, HookedFindClose); DetourTransactionCommit(); } diff --git a/vfs.cpp b/vfs.cpp index 002c586..814c09f 100644 --- a/vfs.cpp +++ b/vfs.cpp @@ -75,6 +75,12 @@ HANDLE VFS::CreateFileW(std::wstring path) { } str = fileop::relpath(str, base_path); str = str_util::str_replace(str, "\\", "/"); + auto c = files.find(str); + if (c == files.end()) { + SetLastError(ERROR_FILE_NOT_FOUND); + return INVALID_HANDLE_VALUE; + } + str = (*c).first; zip_t* archive = nullptr; zip_uint64_t index = 0; for (auto a : archives) { diff --git a/vfs.hpp b/vfs.hpp index c70821f..c80ad33 100644 --- a/vfs.hpp +++ b/vfs.hpp @@ -3,6 +3,28 @@ #include #include #include +#include "str_util.h" + +struct CaseInsensitiveHash { + size_t operator()(const std::string& str) const { + // 创建字符串的小写副本 + std::string lowercaseStr = str_util::tolower(str); + + // 对小写字符串使用标准哈希函数 + return std::hash{}(lowercaseStr); + } +}; + +// 比较函数,忽略大小写 +struct CaseInsensitiveEqual { + bool operator()(const std::string& left, const std::string& right) const { + return left.size() == right.size() && + std::equal(left.begin(), left.end(), right.begin(), + [](unsigned char a, unsigned char b) { + return std::tolower(a) == std::tolower(b); + }); + } +}; class VFS { public: @@ -17,7 +39,7 @@ class VFS { void CloseHandle(HANDLE hFile); DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh); DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod); - std::unordered_map files; + std::unordered_map files; std::string GetBasePath(); private: std::string base_path;