Skip to content

Commit

Permalink
Merge pull request #12 from ModOrganizer2/Develop
Browse files Browse the repository at this point in the history
Release USVFS 0.4.3.0
  • Loading branch information
LostDragonist authored May 4, 2019
2 parents 2f31ad5 + c9ac140 commit ee05b67
Show file tree
Hide file tree
Showing 21 changed files with 1,037 additions and 1,049 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/LePresidente/udis86
url = https://github.com/ModOrganizer2/udis86
[submodule "fmt"]
path = fmt
url = https://github.com/fmtlib/fmt.git
Expand Down
27 changes: 22 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,32 @@ platform:
- x86
environment:
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'))
BOOST_PATH: C:\Libraries\boost_1_69_0
WEBHOOK_URL:
secure: gOKbXaZM9ImtMD5XrYITvdyZUW/az082G9OIN1EC1VZ2CuYaUUM6WY2eiNxaFeOL7/9Jyu/m+Vm1fH54CEyigcUUaxA7d8F5IMWlOgE/7YYdaAFSMUTFD7EK+++3FBYfmU1F/nZ61wsiWE6hB9Au5FpGBSCeQ0Tf8U8m0ybPmD0=
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"
- ps: "echo $env:Platform\nif (${env:Platform} -eq \"x64\") {\n set-item -path Env:BOOST_LIBPATH -value ${Env:BOOST_PATH}\\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 ${Env:BOOST_PATH}\\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"
build:
project: vsbuild/usvfs.sln
parallel: true
verbosity: normal
test: off
artifacts:
- path: bin\usvfs_proxy_$(Platform).exe
name: usvfs_proxy_exe
- path: bin\usvfs_proxy_$(Platform).pdb
name: usvfs_proxy_pdb
- path: lib\usvfs_$(Platform).dll
name: usvfs_dll
- path: lib\usvfs_$(Platform).lib
name: usvfs_lib
- path: lib\usvfs_$(Platform).pdb
name: usvfs_pdb
on_success:
- ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER
- ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1
- ps: ./send.ps1 success $env:WEBHOOK_URL
on_failure:
- ps: $blockRdp = $false; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
- ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER
- ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1
- ps: ./send.ps1 failure $env:WEBHOOK_URL
11 changes: 11 additions & 0 deletions include/usvfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ DLLEXPORT VOID WINAPI BlacklistExecutable(LPWSTR executableName);
*/
DLLEXPORT VOID WINAPI ClearExecutableBlacklist();

/**
* adds a library to be force loaded when the given process is injected
* @param
*/
DLLEXPORT VOID WINAPI ForceLoadLibrary(LPWSTR processName, LPWSTR libraryPath);

/**
* clears all previous calls to ForceLoadLibrary
*/
DLLEXPORT VOID WINAPI ClearLibraryForceLoads();

/**
* 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 2
#define USVFS_VERSION_BUILD 3
#define USVFS_VERSION_REVISION 0

#define USVFS_BUILD_STRING ""
Expand Down
1 change: 1 addition & 0 deletions src/shared/ntdll_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ typedef struct _FILE_REPARSE_POINT_INFORMATION {
ULONG Tag;
} FILE_REPARSE_POINT_INFORMATION, *PFILE_REPARSE_POINT_INFORMATION;

// copied from ntstatus.h
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
#define STATUS_BUFFER_OVERFLOW ((NTSTATUS)0x80000005L)
#define STATUS_NO_MORE_FILES ((NTSTATUS)0x80000006L)
Expand Down
2 changes: 2 additions & 0 deletions src/shared/stringcast_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with usvfs. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once

#include <string>
#include <limits>
#include <boost/type_traits.hpp>
Expand Down
57 changes: 51 additions & 6 deletions src/usvfs_dll/hookcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ using usvfs::shared::SharedMemoryT;
using usvfs::shared::VoidAllocatorT;

using namespace usvfs;
namespace ush = usvfs::shared;

HookContext *HookContext::s_Instance = nullptr;

Expand Down Expand Up @@ -214,15 +215,59 @@ void HookContext::clearExecutableBlacklist()
m_Parameters->processBlacklist.clear();
}

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

if (lpApplicationName) {
std::string appName = ush::string_cast<std::string>(lpApplicationName, ush::CodePage::UTF8);
for (shared::StringT item : m_Parameters->processBlacklist) {
if (boost::algorithm::iends_with(appName, std::string(item.data(), item.size()))) {
spdlog::get("usvfs")->info("application {} is blacklisted", appName);
blacklisted = TRUE;
break;
}
}
}
return FALSE;

if (lpCommandLine) {
std::string cmdLine = ush::string_cast<std::string>(lpCommandLine, ush::CodePage::UTF8);
for (shared::StringT item : m_Parameters->processBlacklist) {
if (boost::algorithm::icontains(cmdLine, std::string(item.data(), item.size()))) {
spdlog::get("usvfs")->info("command line {} is blacklisted", cmdLine);
blacklisted = TRUE;
break;
}
}
}

return blacklisted;
}

void HookContext::forceLoadLibrary(const std::wstring &processName, const std::wstring &libraryPath)
{
m_Parameters->forcedLibraries.push_front(ForcedLibrary(
shared::string_cast<std::string>(processName, shared::CodePage::UTF8).c_str(),
shared::string_cast<std::string>(libraryPath, shared::CodePage::UTF8).c_str(),
m_Parameters->forcedLibraries.get_allocator()));
}

void HookContext::clearLibraryForceLoads()
{
m_Parameters->forcedLibraries.clear();
}

std::vector<std::wstring> HookContext::librariesToForceLoad(const std::wstring &processName)
{
std::vector<std::wstring> results;
for (auto library : m_Parameters->forcedLibraries) {
std::string processNameString = shared::string_cast<std::string>(processName, shared::CodePage::UTF8);
if (stricmp(processNameString.c_str(), library.processName.c_str()) == 0) {
std::wstring libraryPathString = shared::string_cast<std::wstring>(library.libraryPath.c_str(), shared::CodePage::UTF8);
results.push_back(libraryPathString);
}
}
return results;
}

void HookContext::unregisterCurrentProcess()
Expand Down
23 changes: 22 additions & 1 deletion src/usvfs_dll/hookcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ along with usvfs. If not, see <http://www.gnu.org/licenses/>.
#include <boost/thread/shared_lock_guard.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <boost/interprocess/containers/flat_set.hpp>
#include <boost/interprocess/containers/slist.hpp>
#include <memory>
#include <set>
#include <future>
Expand All @@ -54,6 +55,20 @@ void USVFSInitParametersInt(USVFSParameters *parameters,
typedef shared::VoidAllocatorT::rebind<DWORD>::other DWORDAllocatorT;
typedef shared::VoidAllocatorT::rebind<shared::StringT>::other StringAllocatorT;

struct ForcedLibrary {
ForcedLibrary(const char *processName, const char *libraryPath,
const shared::VoidAllocatorT &allocator)
: processName(processName, allocator)
, libraryPath(libraryPath, allocator)
{
}

shared::StringT processName;
shared::StringT libraryPath;
};

typedef shared::VoidAllocatorT::rebind<ForcedLibrary>::other ForcedLibraryAllocatorT;

struct SharedParameters {

SharedParameters() = delete;
Expand All @@ -74,6 +89,7 @@ struct SharedParameters {
, userCount(1)
, processBlacklist(allocator)
, processList(allocator)
, forcedLibraries(allocator)
{
}

Expand All @@ -90,6 +106,7 @@ struct SharedParameters {
boost::container::flat_set<shared::StringT, std::less<shared::StringT>,
StringAllocatorT> processBlacklist;
boost::container::flat_set<DWORD, std::less<DWORD>, DWORDAllocatorT> processList;
boost::container::slist<ForcedLibrary, ForcedLibraryAllocatorT> forcedLibraries;
};


Expand Down Expand Up @@ -200,7 +217,11 @@ class HookContext

void blacklistExecutable(const std::wstring &executableName);
void clearExecutableBlacklist();
BOOL executableBlacklisted(const std::wstring &executableName) const;
BOOL HookContext::executableBlacklisted(LPCWSTR lpApplicationName, LPCWSTR lpCommandLine) const;

void forceLoadLibrary(const std::wstring &processName, const std::wstring &libraryPath);
void clearLibraryForceLoads();
std::vector<std::wstring> librariesToForceLoad(const std::wstring &processName);

void setLogLevel(LogLevel level);
void setCrashDumpsType(CrashDumpsType type);
Expand Down
7 changes: 0 additions & 7 deletions src/usvfs_dll/hookmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,6 @@ void HookManager::initHooks()
installHook(kbaseMod, k32Mod, "GetFileAttributesW", hook_GetFileAttributesW);
installHook(kbaseMod, k32Mod, "SetFileAttributesW", hook_SetFileAttributesW);

// Unfortunately, at least on windows 10 1709 x64 the CreateFileA and CreateFile2 translate
// to CreateFileInternal directly (so hooking CreateFileW alone is not enough)
installHook(kbaseMod, k32Mod, "CreateFileW", hook_CreateFileW);
installHook(kbaseMod, k32Mod, "CreateFileA", hook_CreateFileA);
if (IsWindows8OrGreater())
installHook(kbaseMod, k32Mod, "CreateFile2", hook_CreateFile2, reinterpret_cast<LPVOID*>(&CreateFile2));

installHook(kbaseMod, k32Mod, "CreateDirectoryW", hook_CreateDirectoryW);
installHook(kbaseMod, k32Mod, "RemoveDirectoryW", hook_RemoveDirectoryW);
installHook(kbaseMod, k32Mod, "DeleteFileW", hook_DeleteFileW);
Expand Down
Loading

0 comments on commit ee05b67

Please sign in to comment.