aboutsummaryrefslogtreecommitdiff
path: root/libs/usvfs/src/usvfs_proxy
diff options
context:
space:
mode:
Diffstat (limited to 'libs/usvfs/src/usvfs_proxy')
-rw-r--r--libs/usvfs/src/usvfs_proxy/CMakeLists.txt15
-rw-r--r--libs/usvfs/src/usvfs_proxy/main.cpp221
-rw-r--r--libs/usvfs/src/usvfs_proxy/version.rc40
3 files changed, 0 insertions, 276 deletions
diff --git a/libs/usvfs/src/usvfs_proxy/CMakeLists.txt b/libs/usvfs/src/usvfs_proxy/CMakeLists.txt
deleted file mode 100644
index 47614ee..0000000
--- a/libs/usvfs/src/usvfs_proxy/CMakeLists.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-cmake_minimum_required(VERSION 3.16)
-
-find_package(Boost CONFIG REQUIRED COMPONENTS filesystem)
-
-add_executable(usvfs_proxy main.cpp version.rc)
-target_link_libraries(usvfs_proxy PRIVATE usvfs_dll shared usvfs_helper)
-set_target_properties(usvfs_proxy
- PROPERTIES
- RUNTIME_OUTPUT_NAME usvfs_proxy${ARCH_POSTFIX}
- RUNTIME_OUTPUT_DIRECTORY_DEBUG ${USVFS_BINDIR}
- RUNTIME_OUTPUT_DIRECTORY_RELEASE ${USVFS_BINDIR}
-)
-
-install(TARGETS usvfs_proxy EXPORT usvfs${ARCH_POSTFIX}Targets)
-install(FILES $<TARGET_PDB_FILE:usvfs_proxy> DESTINATION pdb OPTIONAL)
diff --git a/libs/usvfs/src/usvfs_proxy/main.cpp b/libs/usvfs/src/usvfs_proxy/main.cpp
deleted file mode 100644
index 88d4696..0000000
--- a/libs/usvfs/src/usvfs_proxy/main.cpp
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
-Userspace Virtual Filesystem
-
-Copyright (C) 2015 Sebastian Herbord. All rights reserved.
-
-This file is part of usvfs.
-
-usvfs is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-usvfs is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-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/>.
-*/
-
-#include "pch.h"
-#include <../usvfs_dll/hookcontext.h>
-#include <Psapi.h>
-#include <WinUser.h>
-#include <boost/algorithm/string/predicate.hpp>
-#include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
-#include <inject.h>
-#include <shared_memory.h>
-#include <sharedparameters.h>
-#include <shmlogger.h>
-#include <spdlog/spdlog.h>
-#include <usvfsparameters.h>
-#include <winapi.h>
-
-namespace bi = boost::interprocess;
-namespace bfs = boost::filesystem;
-using usvfs::SharedParameters;
-using usvfs::shared::SharedMemoryT;
-
-template <typename T>
-T getParameter(std::vector<std::string>& arguments, const std::string& key,
- bool consume)
-{
- auto iter = std::find(arguments.begin(), arguments.end(), std::string("--") + key);
- if ((iter != arguments.end()) && ((iter + 1) != arguments.end())) {
- T result = boost::lexical_cast<T>(*(iter + 1));
- if (consume) {
- arguments.erase(iter, iter + 2);
- }
- return result;
- } else {
- throw std::runtime_error(std::string("argument missing " + key));
- }
-}
-
-template <typename T>
-T getParameter(std::vector<std::string>& arguments, const std::string& key,
- const T& def, bool consume)
-{
- auto iter = std::find(arguments.begin(), arguments.end(), std::string("--") + key);
- if ((iter != arguments.end()) && ((iter + 1) != arguments.end())) {
- T result = boost::lexical_cast<T>(*(iter + 1));
- if (consume) {
- arguments.erase(iter, iter + 2);
- }
- return result;
- } else {
- return def;
- }
-}
-
-static void exceptionDialog(int line, int num, ...)
-{
- va_list args;
- va_start(args, num);
-
- std::wstring wstr;
- WCHAR buf[256];
- wstr.append(L"Unhandled USVFS proxy exception (line ");
- wsprintf(buf, L"%d): ", line);
- wstr.append(buf);
- for (int i = 0; i < num; i++) {
- wsprintf(buf, L"%S", va_arg(args, const char*));
- if (i < num - 1)
- wsprintf(buf, L", ");
- wstr.append(buf);
- }
-
- MessageBox(NULL, wstr.data(), NULL, MB_OK);
-
- va_end(args);
-}
-
-int main(int argc, char** argv)
-{
- std::shared_ptr<spdlog::logger> logger;
-
- std::vector<std::string> arguments;
- std::copy(argv + 1, argv + argc, std::back_inserter(arguments));
-
- std::string instance;
- try {
- SHMLogger::open("usvfs");
- logger = spdlog::create<usvfs::sinks::shm_sink>("usvfs", "usvfs");
- logger->set_pattern("%H:%M:%S.%e [%L] (proxy) %v");
-
- instance = getParameter<std::string>(arguments, "instance", true);
- } catch (const std::exception& e) {
- if (logger.get() == nullptr) {
- exceptionDialog(__LINE__, 1, e.what());
- return 1;
- }
- try {
- logger->critical("{}", e.what());
- } catch (const spdlog::spdlog_ex& e2) {
- exceptionDialog(__LINE__, 2, e.what(), e2.what());
- // no way to log this
- } catch (const std::exception&) {
- logger->critical(e.what());
- }
- return 1;
- }
-
- try {
- std::string executable =
- getParameter<std::string>(arguments, "executable", "", true);
- int pid = getParameter<int>(arguments, "pid", 0, true);
- int tid = getParameter<int>(arguments, "tid", 0, true);
-
- logger->info("instance: {}", instance);
- logger->info("exe: {}", executable);
- logger->info("pid: {}", pid);
-
- if (executable.empty() && (pid == 0)) {
- logger->warn("not all required settings set");
- return 1;
- }
-
- SharedMemoryT configurationSHM(bi::open_only, instance.c_str());
- if (!configurationSHM.check_sanity()) {
- logger->warn("failed to connect to vfs");
- return 1;
- }
- logger->info("size: {}", configurationSHM.get_size());
- logger->info("addr: {0:p}", configurationSHM.get_address());
- logger->info("objs: {}", configurationSHM.get_num_named_objects());
- std::pair<SharedParameters*, SharedMemoryT::size_type> params =
- configurationSHM.find<SharedParameters>("parameters");
- if (params.first == nullptr) {
- logger->error("failed to open shared configuration for {}", instance);
- return 1;
- }
-
- boost::filesystem::path p(winapi::wide::getModuleFileName(nullptr));
-
- if (executable.empty()) {
- HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
- HANDLE threadHandle = INVALID_HANDLE_VALUE;
- if (tid != 0) {
- threadHandle = OpenThread(THREAD_ALL_ACCESS, FALSE, tid);
- }
-
- BOOL blacklisted = FALSE;
- TCHAR szModName[MAX_PATH];
-
- if (GetModuleFileNameEx(processHandle, NULL, szModName,
- sizeof(szModName) / sizeof(TCHAR))) {
- const auto appName = usvfs::shared::string_cast<std::string>(szModName);
-
- if (params.first->executableBlacklisted(appName, {})) {
- logger->info("not injecting {} as application is blacklisted", appName);
- blacklisted = TRUE;
- }
- }
-
- if (!blacklisted) {
- usvfs::injectProcess(p.parent_path().wstring(), params.first->makeLocal(),
- processHandle, threadHandle);
- }
- } else {
- winapi::process::Result process =
- winapi::ansi::createProcess(executable)
- .arguments(arguments.begin(), arguments.end())
- .workingDirectory(bfs::path(executable).parent_path().string())
- .suspended()();
-
- if (!process.valid) {
- return 1;
- }
-
- BOOL blacklisted = FALSE;
-
- if (params.first->executableBlacklisted(executable, {})) {
- logger->info("not injecting {} as application is blacklisted", executable);
-
- blacklisted = TRUE;
- }
-
- if (!blacklisted) {
- usvfs::injectProcess(p.parent_path().wstring(), params.first->makeLocal(),
- process.processInfo);
- }
-
- ResumeThread(process.processInfo.hThread);
- }
-
- return 0;
- } catch (const std::exception& e) {
- try {
- logger->critical("unhandled exception: {}", e.what());
- logExtInfo(e);
- } catch (const spdlog::spdlog_ex& e2) {
- // no way to log this
- exceptionDialog(__LINE__, 2, e.what(), e2.what());
- } catch (const std::exception&) {
- logger->critical(e.what());
- }
- }
-}
diff --git a/libs/usvfs/src/usvfs_proxy/version.rc b/libs/usvfs/src/usvfs_proxy/version.rc
deleted file mode 100644
index 03652c2..0000000
--- a/libs/usvfs/src/usvfs_proxy/version.rc
+++ /dev/null
@@ -1,40 +0,0 @@
-#include "Winver.h"
-#include "..\..\include\usvfs\usvfs_version.h"
-
-#define VER_FILEVERSION USVFS_VERSION_MAJOR,USVFS_VERSION_MINOR,USVFS_VERSION_BUILD,USVFS_VERSION_REVISION
-#define VER_FILEVERSION_STR USVFS_VERSION_STRING
-
-#define VER_PRODUCTVERSION USVFS_VERSION_MAJOR,USVFS_VERSION_MINOR,USVFS_VERSION_BUILD,USVFS_VERSION_REVISION
-#define VER_PRODUCTVERSION_STR USVFS_VERSION_STRING
-
-VS_VERSION_INFO VERSIONINFO
-FILEVERSION VER_FILEVERSION
-PRODUCTVERSION VER_PRODUCTVERSION
-FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
-FILEFLAGS (0)
-FILEOS VOS__WINDOWS32
-FILETYPE VFT_DLL
-FILESUBTYPE VFT2_UNKNOWN
-BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904B0"
- BEGIN
- VALUE "FileVersion", VER_FILEVERSION_STR
- VALUE "CompanyName", "Mod Organizer 2 Team\0"
- VALUE "FileDescription", "USVFS Proxy\0"
-#ifdef _WIN64
- VALUE "OriginalFilename", "usvfs_proxy_x64.exe\0"
-#else
- VALUE "OriginalFilename", "usvfs_proxy_x86.exe\0"
-#endif
- VALUE "ProductName", "USVFS\0"
- VALUE "ProductVersion", VER_PRODUCTVERSION_STR
- END
- END
-
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x0409L, 1200
- END
-END