Skip to content

Commit

Permalink
Merge pull request #10 from ModOrganizer2/Develop
Browse files Browse the repository at this point in the history
Release USVFS 0.4.2.0
  • Loading branch information
LostDragonist authored Dec 20, 2018
2 parents 32c9f4d + 5c109dd commit 2f31ad5
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
url = https://github.com/asmjit/asmjit.git
[submodule "udis86"]
path = udis86
url = https://github.com/vmt/udis86
url = https://github.com/LePresidente/udis86
[submodule "fmt"]
path = fmt
url = https://github.com/fmtlib/fmt.git
Expand Down
26 changes: 14 additions & 12 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
version: 1.0.{build}
image: Visual Studio 2017
init:
- ps: echo $Env:Arch $Env:Platform $Env:Boost_Addressmode
configuration: Release
platform:
- x64
- x86
environment:
matrix:
- Platform: x64
Boost_Addressmode: 64
Arch: x64
- Platform: win32
Boost_Addressmode: 32
Arch: x86
GTEST_PATH: C:\Libraries\googletest
BOOST_PATH: C:\Libraries\boost_1_66_0
install:
- ps: $blockRdp = $false; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
build_script:
- 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"
test_script:
before_build:
- 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"
build:
project: vsbuild/usvfs.sln
parallel: true
verbosity: normal
test: off
on_failure:
- ps: $blockRdp = $false; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
5 changes: 5 additions & 0 deletions include/usvfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ DLLEXPORT BOOL WINAPI CreateVFSDump(LPSTR buffer, size_t *size);
*/
DLLEXPORT VOID WINAPI BlacklistExecutable(LPWSTR executableName);

/**
* clears the executable blacklist
*/
DLLEXPORT VOID WINAPI ClearExecutableBlacklist();

/**
* print debugging info about the vfs. The format is currently not fixed and may
* change between usvfs versions
Expand Down
2 changes: 1 addition & 1 deletion include/usvfs_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#define USVFS_VERSION_MAJOR 0
#define USVFS_VERSION_MINOR 4
#define USVFS_VERSION_BUILD 1
#define USVFS_VERSION_BUILD 2
#define USVFS_VERSION_REVISION 0

#define USVFS_BUILD_STRING ""
Expand Down
20 changes: 20 additions & 0 deletions src/shared/shmlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ along with usvfs. If not, see <http://www.gnu.org/licenses/>.
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/operations.hpp>
#include <limits>
#include <algorithm>
#include <ShlObj.h>
#include <comutil.h>
#pragma warning(pop)

#pragma warning(disable : 4996)

#pragma comment(lib, "comsuppw")

using namespace boost::interprocess;

SHMLogger *SHMLogger::s_Instance = nullptr;
Expand Down Expand Up @@ -194,3 +199,18 @@ void spdlog::sinks::shm_sink::output(level::level_enum lev,
m_DroppedMessages.fetch_add(1, std::memory_order_relaxed);
}
}

void __cdecl boost::interprocess::ipcdetail::get_shared_dir(std::string &shared_dir)
{
PWSTR path;
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &path))) {
_bstr_t bPath(path);
shared_dir = (char*)bPath;
shared_dir += "\\USVFS";
} else {
shared_dir = "C:\\ProgramData\\USVFS";
}
boost::filesystem::path boostPath(shared_dir);
if (!boost::filesystem::exists(boostPath))
boost::filesystem::create_directories(boostPath);
}
18 changes: 17 additions & 1 deletion src/usvfs_dll/hookcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ along with usvfs. If not, see <http://www.gnu.org/licenses/>.
#include <usvfsparameters.h>
#include <shared_memory.h>
#include "loghelpers.h"

#include <boost/algorithm/string/predicate.hpp>

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

void HookContext::clearExecutableBlacklist()
{
m_Parameters->processBlacklist.clear();
}

BOOL HookContext::executableBlacklisted(const std::wstring &executableName) const
{
for (shared::StringT exec : m_Parameters->processBlacklist) {
if (boost::algorithm::iends_with(executableName,
"\\" + std::string(exec.data(), exec.size()))) {
return TRUE;
}
}
return FALSE;
}

void HookContext::unregisterCurrentProcess()
{
auto iter = m_Parameters->processList.find(::GetCurrentProcessId());
Expand Down
2 changes: 2 additions & 0 deletions src/usvfs_dll/hookcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class HookContext
std::vector<DWORD> registeredProcesses() const;

void blacklistExecutable(const std::wstring &executableName);
void clearExecutableBlacklist();
BOOL executableBlacklisted(const std::wstring &executableName) const;

void setLogLevel(LogLevel level);
void setCrashDumpsType(CrashDumpsType type);
Expand Down
68 changes: 52 additions & 16 deletions src/usvfs_dll/hooks/kernel32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ class RerouteW
}
else
{
if (m_PathCreated)
addDirectoryMapping(context, fs::path(m_RealPath).parent_path(), fs::path(m_FileName).parent_path());
//if (m_PathCreated)
//addDirectoryMapping(context, fs::path(m_RealPath).parent_path(), fs::path(m_FileName).parent_path());

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

void removeMapping(const usvfs::HookContext::ConstPtr &readContext, bool directory = false)
{
bool addToDelete = false;
bool dontAddToDelete = false;

// We need to track deleted files even if they were not rerouted (i.e. files deleted from the real folder which there is
// a virtualized mapped folder on top of it). Since we don't want to add, *every* file which is deleted we check this:
if (!directory) {
Expand All @@ -305,7 +308,7 @@ class RerouteW
found = true;
}
if (found)
k32DeleteTracker.insert(m_RealPath, m_FileName);
addToDelete = true;
}

if (wasRerouted()) {
Expand All @@ -324,6 +327,7 @@ class RerouteW
parent = fs::path(parent).parent_path().wstring();
if (k32FakeDirTracker.contains(parent))
{
dontAddToDelete = true;
if (RemoveDirectoryW(parent.c_str())) {
k32FakeDirTracker.erase(parent);
spdlog::get("usvfs")->info("removed empty fake directory: {}", string_cast<std::string>(parent));
Expand All @@ -339,6 +343,9 @@ class RerouteW
}
}
}
if (addToDelete && !dontAddToDelete) {
k32DeleteTracker.insert(m_RealPath, m_FileName);
}
}

static bool createFakePath(fs::path path, LPSECURITY_ATTRIBUTES securityAttributes)
Expand Down Expand Up @@ -807,20 +814,49 @@ BOOL WINAPI usvfs::hook_CreateProcessInternalW(
newToken);
POST_REALCALL

BOOL blacklisted = FALSE;
if (applicationReroute.fileName()) {
auto context = READ_CONTEXT();
if (context->executableBlacklisted(applicationReroute.fileName())) {
spdlog::get("hooks")->info(
"not injecting {} as application is blacklisted",
ush::string_cast<std::string>(
applicationReroute.fileName(),
ush::CodePage::UTF8
)
);
blacklisted = TRUE;
}
} else if (cmdReroute.fileName()) {
auto context = READ_CONTEXT();
if (context->executableBlacklisted(cmdReroute.fileName())) {
spdlog::get("hooks")->info(
"not injecting {} as command line is blacklisted",
ush::string_cast<std::string>(
cmdReroute.fileName(),
ush::CodePage::UTF8
)
);
blacklisted = TRUE;
}
}

if (res)
{
try {
injectProcess(dllPath, callParameters, *lpProcessInformation);
} catch (const std::exception &e) {
spdlog::get("hooks")
->error("failed to inject into {0}: {1}",
lpApplicationName != nullptr
? log::wrap(applicationReroute.fileName())
: log::wrap(static_cast<LPCWSTR>(lpCommandLine)),
e.what());
if (!blacklisted) {
try {
injectProcess(dllPath, callParameters, *lpProcessInformation);
} catch (const std::exception &e) {
spdlog::get("hooks")
->error("failed to inject into {0}: {1}",
lpApplicationName != nullptr
? log::wrap(applicationReroute.fileName())
: log::wrap(static_cast<LPCWSTR>(lpCommandLine)),
e.what());
}
}

// resume unless process is suposed to start suspended
// resume unless process is supposed to start suspended
if (!susp && (ResumeThread(lpProcessInformation->hThread) == (DWORD)-1)) {
spdlog::get("hooks")->error("failed to inject into spawned process");
res = FALSE;
Expand All @@ -830,9 +866,10 @@ BOOL WINAPI usvfs::hook_CreateProcessInternalW(
LOG_CALL()
.PARAM(lpApplicationName)
.PARAM(applicationReroute.fileName())
.PARAM(cmdline)
.PARAM(cmdReroute.fileName())
.PARAM(res)
.PARAM(callContext.lastError());
.PARAM(callContext.lastError())
.PARAM(cmdline);
HOOK_END

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

bool usedRewrite = false;


if (boost::algorithm::icontains(lpFileName, tempPathStr)) {
PRE_REALCALL
//Force the mutEXHook to match NtQueryDirectoryFile so it calls the non hooked NtQueryDirectoryFile.
Expand Down
5 changes: 5 additions & 0 deletions src/usvfs_dll/usvfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,11 @@ VOID WINAPI BlacklistExecutable(LPWSTR executableName)
context->blacklistExecutable(executableName);
}

VOID WINAPI ClearExecutableBlacklist()
{
context->clearExecutableBlacklist();
}


VOID WINAPI PrintDebugInfo()
{
Expand Down
4 changes: 2 additions & 2 deletions src/usvfs_helper/inject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ void usvfs::injectProcess(const std::wstring &applicationPath
+ ush::string_cast<std::string>(exePath.wstring()))
<< ex_win_errcode(result.errorCode));
} else {
// wait for proxy completion. this shouldn't take long, 5 seconds is very generous
switch (WaitForSingleObject(result.processInfo.hProcess, 5000)) {
// wait for proxy completion. this shouldn't take long, 15 seconds is very generous
switch (WaitForSingleObject(result.processInfo.hProcess, 15000)) {
case WAIT_TIMEOUT: {
spdlog::get("usvfs")->debug("proxy timeout");
TerminateProcess(result.processInfo.hProcess, 1);
Expand Down
Loading

0 comments on commit 2f31ad5

Please sign in to comment.