Skip to content

Commit 2f31ad5

Browse files
Merge pull request #10 from ModOrganizer2/Develop
Release USVFS 0.4.2.0
2 parents 32c9f4d + 5c109dd commit 2f31ad5

19 files changed

Lines changed: 194 additions & 53 deletions

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
url = https://github.com/asmjit/asmjit.git
44
[submodule "udis86"]
55
path = udis86
6-
url = https://github.com/vmt/udis86
6+
url = https://github.com/LePresidente/udis86
77
[submodule "fmt"]
88
path = fmt
99
url = https://github.com/fmtlib/fmt.git

appveyor.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
version: 1.0.{build}
22
image: Visual Studio 2017
3-
init:
4-
- ps: echo $Env:Arch $Env:Platform $Env:Boost_Addressmode
3+
configuration: Release
4+
platform:
5+
- x64
6+
- x86
57
environment:
6-
matrix:
7-
- Platform: x64
8-
Boost_Addressmode: 64
9-
Arch: x64
10-
- Platform: win32
11-
Boost_Addressmode: 32
12-
Arch: x86
8+
GTEST_PATH: C:\Libraries\googletest
9+
BOOST_PATH: C:\Libraries\boost_1_66_0
1310
install:
1411
- ps: $blockRdp = $false; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
15-
build_script:
16-
- ps: "New-Item c:\\projects\\usvfs\\build -type directory\nNew-Item c:\\projects\\install -type directory\nNew-Item c:\\temp -type directory\n\ngit clone --depth=1 --branch=master https://github.com/TanninOne/spdlog.git c:\\libraries\\spdlog 2> $null\ngit clone --depth=1 --branch=3.0.0 https://github.com/fmtlib/fmt.git c:\\libraries\\fmtlib 2> $null\ngit clone --depth=1 --branch=master https://github.com/google/googletest.git c:\\libraries\\googletest 2> $null\ngit clone --branch=master https://github.com/kobalicek/asmjit.git c:\\libraries\\asmjit 2> $null\ngit clone --depth=1 --branch=v1.7.2 https://github.com/vmt/udis86.git c:\\libraries\\udis86 2> $null\n\nSet-Location -Path c:\\libraries\\googletest \ncmake . -Dgtest_force_shared_crt=ON -DBUILD_GMOCK=OFF -DBUILD_GTEST=ON -DCMAKE_GENERATOR_PLATFORM=\"$Env:Platform\" -G\"Visual Studio 15 2017\"\ncmake --build . --config Release -- /p:Platform=$Env:Platform\nCopy-Item C:\\Libraries\\googletest\\googletest\\Release\\gtest.lib c:\\libraries\\googletest\\googletest\n\nSet-Location -Path c:\\libraries\\fmtlib\ncmake . -DCMAKE_GENERATOR_PLATFORM=\"$Env:Platform\" -DCMAKE_BUILD_TYPE=Release -G\"Visual Studio 15 2017\"\ncmake --build . --config Release\nCopy-Item c:\\libraries\\fmtlib\\fmt\\Release\\fmt.lib c:\\libraries\\fmtlib\n\nSet-Location -Path c:\\libraries\\asmjit\ngit checkout fb9f82cb61df36aa513d054e748dc6769045f33e\ncmake . -DASMJIT_STATIC=TRUE -DASMJIT_DISABLE_COMPILER=TRUE -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=\"$Env:Platform\" -G\"Visual Studio 15 2017\"\ncmake --build . --config Release\nRename-Item c:\\libraries\\asmjit\\Release c:\\libraries\\asmjit\\build\n\nSet-Location -Path c:\\libraries\\udis86\\BuildVS2010\n& 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\Common7\\IDE\\devenv.exe' /Upgrade .\\udis86.sln\nStart-Sleep -s 15\nmsbuild.exe udis86.sln /t:Clean\nmsbuild.exe build.proj /t:BuildRelease_$Env:Arch\nCopy-Item c:\\libraries\\udis86\\BuildVS2010\\build\\lib\\x64\\libudis86.lib c:\\libraries\\udis86\n\nSet-Location -Path C:\\Libraries\\boost_1_65_1\n.\"C:\\Python27-x64\\Scripts\\pip.exe\" install \"patch==1.*\"\n.\"C:\\Python27-x64\\python.exe\" -m patch \"C:\\projects\\usvfs\\patches\\type_traits_vs15_fix.patch\"\n.\\bootstrap.bat\n.\\b2 address-model=\"$Env:Boost_Addressmode\" toolset=msvc-14.1 windows-api=desktop variant=release link=static threading=multi runtime-link=shared --with-filesystem --with-date_time --with-thread --with-locale\n\nSet-Location -Path c:\\projects\\usvfs\\build\ncmake .. -DPROJ_ARCH=\"$Env:Arch\" -DCMAKE_GENERATOR_PLATFORM=\"$Env:Platform\" -DCMAKE_BUILD_TYPE=Release -DDEPENDENCIES_DIR=c:\\libraries -G\"Visual Studio 15 2017\"\ncmake --build . --config Release\n\nNew-Item c:\\projects\\usvfs\\install -type directory\n\nCopy-Item c:\\projects\\usvfs\\build\\testinject_bin\\Release\\testinject_bin.exe c:\\projects\\usvfs\\build\\tinjectlib_test\\Release\nCopy-Item c:\\projects\\usvfs\\build\\testinject_dll\\Release\\testinject_dll.dll c:\\projects\\usvfs\\build\\tinjectlib_test\\Release\nCopy-Item c:\\projects\\usvfs\\build\\testinject_dll\\Release\\testinject_dll.dll c:\\projects\\usvfs\\build\\tinjectlib_test\\Release\\testinject_dll-d.dll\nCopy-Item c:\\projects\\usvfs\\build\\usvfs\\Release\\usvfs_$Env:Arch.dll c:\\projects\\usvfs\\build\\usvfs_test\\Release\nctest -VV -C Release"
17-
test_script:
12+
before_build:
13+
- ps: "echo $env:Platform\nif (${env:Platform} -eq \"x64\") {\n set-item -path Env:BOOST_LIBPATH -value C:\\Libraries\\boost_1_66_0\\lib64-msvc-14.1\n set-item -path Env:GTEST_BUILDDIR -value c:\\libraries\\googletest\\build \n}\nElse {\n set-item -path Env:BOOST_LIBPATH -value C:\\Libraries\\boost_1_66_0\\lib32-msvc-14.1\n set-item -path Env:GTEST_BUILDDIR -value c:\\libraries\\googletest\\build_32\n}\n\n. git clone --depth=1 --branch=master https://github.com/google/googletest.git c:\\libraries\\googletest 2> $null\nNew-Item $Env:GTEST_BUILDDIR -type directory\nSet-Location -Path $Env:GTEST_BUILDDIR\n. cmd /c \"`\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat`\" $env:Platform && cmake -G `\"NMake Makefiles`\" -DCMAKE_BUILD_TYPE=Release ..`\"\"\n. cmd /c \"`\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat`\" $env:Platform && nmake\"\n\nSet-Location -Path c:\\projects\\usvfs\\vsbuild\n#Tempory fix due to that appveyor has boost lib files in a custom output folder\nGet-ChildItem -Path *.props -recurse | ForEach {If (Get-Content $_.FullName | Select-String -Pattern '\\$\\(BOOST_PATH\\)\\\\.*\\\\lib') {(Get-Content $_ | ForEach {$_ -replace '\\$\\(BOOST_PATH\\)\\\\.*\\\\lib', \"$Env:BOOST_LIBPATH\"}) | Set-Content $_ }}\n\n#Need to tell usvfs to not use the BOOST_BUILDID\nGet-ChildItem -Path *.props -recurse | ForEach {If (Get-Content $_.FullName | Select-String -Pattern 'BOOST_LIB_BUILDID=x86;') {(Get-Content $_ | ForEach {$_ -replace 'BOOST_LIB_BUILDID=x86;', \"\"}) | Set-Content $_ }}\n\nSet-Location -Path c:\\projects\\usvfs\ngit submodule -q update --init --recursive\nSet-Location -Path c:\\projects\\usvfs\\udis86\ngit pull -q origin master"
14+
build:
15+
project: vsbuild/usvfs.sln
16+
parallel: true
17+
verbosity: normal
18+
test: off
19+
on_failure:
1820
- ps: $blockRdp = $false; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

include/usvfs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ DLLEXPORT BOOL WINAPI CreateVFSDump(LPSTR buffer, size_t *size);
139139
*/
140140
DLLEXPORT VOID WINAPI BlacklistExecutable(LPWSTR executableName);
141141

142+
/**
143+
* clears the executable blacklist
144+
*/
145+
DLLEXPORT VOID WINAPI ClearExecutableBlacklist();
146+
142147
/**
143148
* print debugging info about the vfs. The format is currently not fixed and may
144149
* change between usvfs versions

include/usvfs_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#define USVFS_VERSION_MAJOR 0
44
#define USVFS_VERSION_MINOR 4
5-
#define USVFS_VERSION_BUILD 1
5+
#define USVFS_VERSION_BUILD 2
66
#define USVFS_VERSION_REVISION 0
77

88
#define USVFS_BUILD_STRING ""

src/shared/shmlogger.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ along with usvfs. If not, see <http://www.gnu.org/licenses/>.
2525
#include <boost/interprocess/ipc/message_queue.hpp>
2626
#include <boost/format.hpp>
2727
#include <boost/algorithm/string.hpp>
28+
#include <boost/filesystem/operations.hpp>
2829
#include <limits>
2930
#include <algorithm>
31+
#include <ShlObj.h>
32+
#include <comutil.h>
3033
#pragma warning(pop)
3134

3235
#pragma warning(disable : 4996)
3336

37+
#pragma comment(lib, "comsuppw")
38+
3439
using namespace boost::interprocess;
3540

3641
SHMLogger *SHMLogger::s_Instance = nullptr;
@@ -194,3 +199,18 @@ void spdlog::sinks::shm_sink::output(level::level_enum lev,
194199
m_DroppedMessages.fetch_add(1, std::memory_order_relaxed);
195200
}
196201
}
202+
203+
void __cdecl boost::interprocess::ipcdetail::get_shared_dir(std::string &shared_dir)
204+
{
205+
PWSTR path;
206+
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &path))) {
207+
_bstr_t bPath(path);
208+
shared_dir = (char*)bPath;
209+
shared_dir += "\\USVFS";
210+
} else {
211+
shared_dir = "C:\\ProgramData\\USVFS";
212+
}
213+
boost::filesystem::path boostPath(shared_dir);
214+
if (!boost::filesystem::exists(boostPath))
215+
boost::filesystem::create_directories(boostPath);
216+
}

src/usvfs_dll/hookcontext.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ along with usvfs. If not, see <http://www.gnu.org/licenses/>.
2626
#include <usvfsparameters.h>
2727
#include <shared_memory.h>
2828
#include "loghelpers.h"
29-
29+
#include <boost/algorithm/string/predicate.hpp>
3030

3131
namespace bi = boost::interprocess;
3232
using usvfs::shared::SharedMemoryT;
@@ -209,6 +209,22 @@ void HookContext::blacklistExecutable(const std::wstring &executableName)
209209
m_Parameters->processBlacklist.get_allocator()));
210210
}
211211

212+
void HookContext::clearExecutableBlacklist()
213+
{
214+
m_Parameters->processBlacklist.clear();
215+
}
216+
217+
BOOL HookContext::executableBlacklisted(const std::wstring &executableName) const
218+
{
219+
for (shared::StringT exec : m_Parameters->processBlacklist) {
220+
if (boost::algorithm::iends_with(executableName,
221+
"\\" + std::string(exec.data(), exec.size()))) {
222+
return TRUE;
223+
}
224+
}
225+
return FALSE;
226+
}
227+
212228
void HookContext::unregisterCurrentProcess()
213229
{
214230
auto iter = m_Parameters->processList.find(::GetCurrentProcessId());

src/usvfs_dll/hookcontext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ class HookContext
199199
std::vector<DWORD> registeredProcesses() const;
200200

201201
void blacklistExecutable(const std::wstring &executableName);
202+
void clearExecutableBlacklist();
203+
BOOL executableBlacklisted(const std::wstring &executableName) const;
202204

203205
void setLogLevel(LogLevel level);
204206
void setCrashDumpsType(CrashDumpsType type);

src/usvfs_dll/hooks/kernel32.cpp

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ class RerouteW
276276
}
277277
else
278278
{
279-
if (m_PathCreated)
280-
addDirectoryMapping(context, fs::path(m_RealPath).parent_path(), fs::path(m_FileName).parent_path());
279+
//if (m_PathCreated)
280+
//addDirectoryMapping(context, fs::path(m_RealPath).parent_path(), fs::path(m_FileName).parent_path());
281281

282282
spdlog::get("hooks")->info("mapping file in vfs: {}, {}",
283283
ush::string_cast<std::string>(m_RealPath, ush::CodePage::UTF8),
@@ -291,6 +291,9 @@ class RerouteW
291291

292292
void removeMapping(const usvfs::HookContext::ConstPtr &readContext, bool directory = false)
293293
{
294+
bool addToDelete = false;
295+
bool dontAddToDelete = false;
296+
294297
// We need to track deleted files even if they were not rerouted (i.e. files deleted from the real folder which there is
295298
// a virtualized mapped folder on top of it). Since we don't want to add, *every* file which is deleted we check this:
296299
if (!directory) {
@@ -305,7 +308,7 @@ class RerouteW
305308
found = true;
306309
}
307310
if (found)
308-
k32DeleteTracker.insert(m_RealPath, m_FileName);
311+
addToDelete = true;
309312
}
310313

311314
if (wasRerouted()) {
@@ -324,6 +327,7 @@ class RerouteW
324327
parent = fs::path(parent).parent_path().wstring();
325328
if (k32FakeDirTracker.contains(parent))
326329
{
330+
dontAddToDelete = true;
327331
if (RemoveDirectoryW(parent.c_str())) {
328332
k32FakeDirTracker.erase(parent);
329333
spdlog::get("usvfs")->info("removed empty fake directory: {}", string_cast<std::string>(parent));
@@ -339,6 +343,9 @@ class RerouteW
339343
}
340344
}
341345
}
346+
if (addToDelete && !dontAddToDelete) {
347+
k32DeleteTracker.insert(m_RealPath, m_FileName);
348+
}
342349
}
343350

344351
static bool createFakePath(fs::path path, LPSECURITY_ATTRIBUTES securityAttributes)
@@ -807,20 +814,49 @@ BOOL WINAPI usvfs::hook_CreateProcessInternalW(
807814
newToken);
808815
POST_REALCALL
809816

817+
BOOL blacklisted = FALSE;
818+
if (applicationReroute.fileName()) {
819+
auto context = READ_CONTEXT();
820+
if (context->executableBlacklisted(applicationReroute.fileName())) {
821+
spdlog::get("hooks")->info(
822+
"not injecting {} as application is blacklisted",
823+
ush::string_cast<std::string>(
824+
applicationReroute.fileName(),
825+
ush::CodePage::UTF8
826+
)
827+
);
828+
blacklisted = TRUE;
829+
}
830+
} else if (cmdReroute.fileName()) {
831+
auto context = READ_CONTEXT();
832+
if (context->executableBlacklisted(cmdReroute.fileName())) {
833+
spdlog::get("hooks")->info(
834+
"not injecting {} as command line is blacklisted",
835+
ush::string_cast<std::string>(
836+
cmdReroute.fileName(),
837+
ush::CodePage::UTF8
838+
)
839+
);
840+
blacklisted = TRUE;
841+
}
842+
}
843+
810844
if (res)
811845
{
812-
try {
813-
injectProcess(dllPath, callParameters, *lpProcessInformation);
814-
} catch (const std::exception &e) {
815-
spdlog::get("hooks")
816-
->error("failed to inject into {0}: {1}",
817-
lpApplicationName != nullptr
818-
? log::wrap(applicationReroute.fileName())
819-
: log::wrap(static_cast<LPCWSTR>(lpCommandLine)),
820-
e.what());
846+
if (!blacklisted) {
847+
try {
848+
injectProcess(dllPath, callParameters, *lpProcessInformation);
849+
} catch (const std::exception &e) {
850+
spdlog::get("hooks")
851+
->error("failed to inject into {0}: {1}",
852+
lpApplicationName != nullptr
853+
? log::wrap(applicationReroute.fileName())
854+
: log::wrap(static_cast<LPCWSTR>(lpCommandLine)),
855+
e.what());
856+
}
821857
}
822858

823-
// resume unless process is suposed to start suspended
859+
// resume unless process is supposed to start suspended
824860
if (!susp && (ResumeThread(lpProcessInformation->hThread) == (DWORD)-1)) {
825861
spdlog::get("hooks")->error("failed to inject into spawned process");
826862
res = FALSE;
@@ -830,9 +866,10 @@ BOOL WINAPI usvfs::hook_CreateProcessInternalW(
830866
LOG_CALL()
831867
.PARAM(lpApplicationName)
832868
.PARAM(applicationReroute.fileName())
833-
.PARAM(cmdline)
869+
.PARAM(cmdReroute.fileName())
834870
.PARAM(res)
835-
.PARAM(callContext.lastError());
871+
.PARAM(callContext.lastError())
872+
.PARAM(cmdline);
836873
HOOK_END
837874

838875
return res;
@@ -2048,7 +2085,6 @@ HANDLE WINAPI usvfs::hook_FindFirstFileExW(LPCWSTR lpFileName, FINDEX_INFO_LEVEL
20482085

20492086
bool usedRewrite = false;
20502087

2051-
20522088
if (boost::algorithm::icontains(lpFileName, tempPathStr)) {
20532089
PRE_REALCALL
20542090
//Force the mutEXHook to match NtQueryDirectoryFile so it calls the non hooked NtQueryDirectoryFile.

src/usvfs_dll/usvfs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,11 @@ VOID WINAPI BlacklistExecutable(LPWSTR executableName)
716716
context->blacklistExecutable(executableName);
717717
}
718718

719+
VOID WINAPI ClearExecutableBlacklist()
720+
{
721+
context->clearExecutableBlacklist();
722+
}
723+
719724

720725
VOID WINAPI PrintDebugInfo()
721726
{

src/usvfs_helper/inject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ void usvfs::injectProcess(const std::wstring &applicationPath
154154
+ ush::string_cast<std::string>(exePath.wstring()))
155155
<< ex_win_errcode(result.errorCode));
156156
} else {
157-
// wait for proxy completion. this shouldn't take long, 5 seconds is very generous
158-
switch (WaitForSingleObject(result.processInfo.hProcess, 5000)) {
157+
// wait for proxy completion. this shouldn't take long, 15 seconds is very generous
158+
switch (WaitForSingleObject(result.processInfo.hProcess, 15000)) {
159159
case WAIT_TIMEOUT: {
160160
spdlog::get("usvfs")->debug("proxy timeout");
161161
TerminateProcess(result.processInfo.hProcess, 1);

0 commit comments

Comments
 (0)