Remove exe / com wrapper around openrct2.dll for Windows (#10727)

We get repeated reports of people saying the game is incorrectly reported as a virus. It is becoming more inconvenient for players and even myself, because when we attempt to download a build, it is immediately deleted by scanners (including the default for Windows: Windows Defender).

One scanner is not too much of an issue, but the game is flagged by almost half of available scanners as reported by VirusTotal.

So why is it being flagged?

Windows has a very annoying concept, the subsystem for a binary. The console subsystem allows stdin / stdout as you would expect, just like posix. Unfortunately if a user runs a console subsystem binary from the desktop or explorer, the game will be opened under conhost and thus you get a console showing alongside the game window. This is not a good user experience for most players. To resolve this, you can use the windows subsystem, but this will detach stdin and stdout immediately on launch. There are hacks that can be done in code to allocate a new console but I found this to not work very well with stdin or other terminal emulators.

My solution to the problem was to have two binaries: openrct2.exe and openrct2.com. Both are executable but openrct2.exe is windows subsystem, openrct2.com is console subsystem. The desktop shortcut opens openrct2.exe with no console window showing. Typing openrct2 on the command line will execute openrct2.com (as .com has higher PATH precedence than .exe by default) with working stdin and stdout. In order to reduce the size, I have the entire game inside openrct2.dll and then supply two tiny wrapper EXEs that simply route main(...) into the DLL.

These wrapper EXEs are the problem, they are very small and do nothing but call into a DLL, this must match virus signatures too closely and their size probably reduces the data available for the scanner to analyse.

So as I can not find any other way of achieving my goal of a cli and gui version of OpenRCT2, this changes the build to publish openrct2 as a single executable (rather than a DLL + wrapper EXE), and then duplicate the entire ~10MB exe again and flip the subsystem flag. The installer and zip size won't be affected as this extra size will be completely compressed out, but when unpacked will lead to an extra ~10MB on disc. But I think it is a fair compromise.

VirusTotal now reports all artefacts as safe, for now anyway.
This commit is contained in:
Ted John 2020-02-18 11:35:27 +00:00 committed by GitHub
parent d3db4f5cf8
commit a8b5304786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 60 additions and 186 deletions

View File

@ -174,7 +174,6 @@ Section "!OpenRCT2" Section1
; Copy executable
File /oname=${OPENRCT2_EXE} ${BINARY_DIR}\${OPENRCT2_EXE}
File /oname=${OPENRCT2_COM} ${BINARY_DIR}\${OPENRCT2_COM}
File /oname=openrct2.dll ${BINARY_DIR}\openrct2.dll
; Create the Registry Entries
WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OpenRCT2" "Comments" "Visit ${APPURLLINK}"
@ -243,7 +242,6 @@ Section "Uninstall"
Delete "$INSTDIR\contributors.md"
Delete "$INSTDIR\${OPENRCT2_EXE}"
Delete "$INSTDIR\${OPENRCT2_COM}"
Delete "$INSTDIR\openrct2.dll"
Delete "$INSTDIR\INSTALL.LOG"
; Data files

View File

@ -3,15 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29411.138
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2-dll", "src\openrct2-dll\openrct2-dll.vcxproj", "{7B8DB129-79EF-417E-B372-8A18E009D261}"
ProjectSection(ProjectDependencies) = postProject
{8DD8AB7D-2EA6-44E3-8265-BAF08E832951} = {8DD8AB7D-2EA6-44E3-8265-BAF08E832951}
{D24D94F6-2A74-480C-B512-629C306CE92F} = {D24D94F6-2A74-480C-B512-629C306CE92F}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2-win", "src\openrct2-win\openrct2-win.vcxproj", "{7A9A57D5-7006-4208-A290-5491BA3C8808}"
ProjectSection(ProjectDependencies) = postProject
{7B8DB129-79EF-417E-B372-8A18E009D261} = {7B8DB129-79EF-417E-B372-8A18E009D261}
{B6808F71-30B4-4499-8FF6-0B1C86391842} = {B6808F71-30B4-4499-8FF6-0B1C86391842}
{8DD8AB7D-2EA6-44E3-8265-BAF08E832951} = {8DD8AB7D-2EA6-44E3-8265-BAF08E832951}
{D24D94F6-2A74-480C-B512-629C306CE92F} = {D24D94F6-2A74-480C-B512-629C306CE92F}
@ -21,7 +14,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libopenrct2", "src\openrct2
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "test\tests\tests.vcxproj", "{62B020FA-E4FB-4C6E-B32A-DC999470F155}"
ProjectSection(ProjectDependencies) = postProject
{7B8DB129-79EF-417E-B372-8A18E009D261} = {7B8DB129-79EF-417E-B372-8A18E009D261}
{B6808F71-30B4-4499-8FF6-0B1C86391842} = {B6808F71-30B4-4499-8FF6-0B1C86391842}
{8DD8AB7D-2EA6-44E3-8265-BAF08E832951} = {8DD8AB7D-2EA6-44E3-8265-BAF08E832951}
{7A9A57D5-7006-4208-A290-5491BA3C8808} = {7A9A57D5-7006-4208-A290-5491BA3C8808}
@ -36,7 +28,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libopenrct2ui", "src\openrc
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openrct2-cli", "src\openrct2-cli\openrct2-cli.vcxproj", "{B6808F71-30B4-4499-8FF6-0B1C86391842}"
ProjectSection(ProjectDependencies) = postProject
{7B8DB129-79EF-417E-B372-8A18E009D261} = {7B8DB129-79EF-417E-B372-8A18E009D261}
{D24D94F6-2A74-480C-B512-629C306CE92F} = {D24D94F6-2A74-480C-B512-629C306CE92F}
EndProjectSection
EndProject
@ -48,14 +39,6 @@ Global
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|Win32.ActiveCfg = Debug|Win32
{7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|Win32.Build.0 = Debug|Win32
{7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|x64.ActiveCfg = Debug|x64
{7B8DB129-79EF-417E-B372-8A18E009D261}.Debug|x64.Build.0 = Debug|x64
{7B8DB129-79EF-417E-B372-8A18E009D261}.Release|Win32.ActiveCfg = Release|Win32
{7B8DB129-79EF-417E-B372-8A18E009D261}.Release|Win32.Build.0 = Release|Win32
{7B8DB129-79EF-417E-B372-8A18E009D261}.Release|x64.ActiveCfg = Release|x64
{7B8DB129-79EF-417E-B372-8A18E009D261}.Release|x64.Build.0 = Release|x64
{7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|Win32.ActiveCfg = Debug|Win32
{7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|Win32.Build.0 = Debug|Win32
{7A9A57D5-7006-4208-A290-5491BA3C8808}.Debug|x64.ActiveCfg = Debug|x64
@ -101,7 +84,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7B8DB129-79EF-417E-B372-8A18E009D261} = {2202A816-377D-4FA0-A7AF-7D4105F8A4FB}
{7A9A57D5-7006-4208-A290-5491BA3C8808} = {2202A816-377D-4FA0-A7AF-7D4105F8A4FB}
{D24D94F6-2A74-480C-B512-629C306CE92F} = {2202A816-377D-4FA0-A7AF-7D4105F8A4FB}
{62B020FA-E4FB-4C6E-B32A-DC999470F155} = {480B577D-4E4A-4757-9A42-28A9AD33E6B0}

View File

@ -19,7 +19,7 @@ if [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]]; then
rm $destination
fi
7z a -r $destination \
openrct2.exe openrct2.com openrct2.dll data \
openrct2.exe openrct2.com data \
../distribution/changelog.txt \
../distribution/contributors.md \
../distribution/licence.txt \

View File

@ -17,9 +17,7 @@ echo -e "\033[0;36mCreating symbols archive for OpenRCT2...\033[0m"
if [[ -f $destination ]]; then
rm $destination
fi
7z a $destination \
openrct2.exe openrct2.com openrct2.dll \
openrct2-dll.pdb openrct2-win.pdb
7z a $destination openrct2.exe openrct2.com openrct2-win.pdb
destination=$(cygpath -w $(readlink -f $destination))
printf '\033[0;32m%s\033[0m\n' "${destination} created successfully"

View File

@ -1,89 +0,0 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
// Windows.h needs to be included first
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef CreateWindow
// Then the rest
#include <openrct2-ui/Ui.h>
#include <openrct2-ui/UiContext.h>
#include <openrct2-ui/audio/AudioContext.h>
#include <openrct2/Context.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/audio/AudioContext.h>
#include <openrct2/ui/UiContext.h>
#include <shellapi.h>
#include <stdio.h>
#include <stdlib.h>
using namespace OpenRCT2;
using namespace OpenRCT2::Audio;
using namespace OpenRCT2::Ui;
#define DLLEXPORT extern "C" __declspec(dllexport)
static char** GetCommandLineArgs(int argc, wchar_t** argvW);
static void FreeCommandLineArgs(int argc, char** argv);
static char* ConvertWideChartoUTF8(const wchar_t* src);
DLLEXPORT int LaunchOpenRCT2(int argc, wchar_t** argvW)
{
char** argv = GetCommandLineArgs(argc, argvW);
if (argv == nullptr)
{
puts("Unable to fetch command line arguments.");
return -1;
}
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
int exitCode = NormalisedMain(argc, const_cast<const char**>(argv));
FreeCommandLineArgs(argc, argv);
return exitCode;
}
static char** GetCommandLineArgs(int argc, wchar_t** argvW)
{
// Allocate UTF-8 strings
char** argv = (char**)malloc(argc * sizeof(char*));
if (argv == nullptr)
{
return nullptr;
}
// Convert to UTF-8
for (int i = 0; i < argc; i++)
{
argv[i] = ConvertWideChartoUTF8(argvW[i]);
}
return argv;
}
static void FreeCommandLineArgs(int argc, char** argv)
{
// Free argv
for (int i = 0; i < argc; i++)
{
free(argv[i]);
}
free(argv);
}
static char* ConvertWideChartoUTF8(const wchar_t* src)
{
int srcLen = lstrlenW(src);
int sizeReq = WideCharToMultiByte(CP_UTF8, 0, src, srcLen, nullptr, 0, nullptr, nullptr);
char* result = (char*)calloc(1, sizeReq + 1);
WideCharToMultiByte(CP_UTF8, 0, src, srcLen, result, sizeReq, nullptr, nullptr);
return result;
}

View File

@ -1,62 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="'$(SolutionDir)'==''">..\..\</SolutionDir>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{7B8DB129-79EF-417E-B372-8A18E009D261}</ProjectGuid>
<RootNamespace>openrct2-dll</RootNamespace>
<ProjectName>openrct2-dll</ProjectName>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<Import Project="..\..\openrct2.common.props" />
<PropertyGroup>
<TargetName>openrct2</TargetName>
<LibraryPath>$(SolutionDir)bin;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions Condition="'$(Configuration)'=='DebugTests' OR '$(Configuration)'=='ReleaseTests'">__NOENTRYPOINT__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>$(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<AdditionalDependencies>libopenrct2.lib;libopenrct2ui.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ProgramDatabaseFile>$(OutDir)openrct2-dll.pdb</ProgramDatabaseFile>
</Link>
<Lib>
<TargetMachine Condition="'$(Platform)'=='Win32'">MachineX86</TargetMachine>
<TargetMachine Condition="'$(Platform)'=='x64'">MachineX64</TargetMachine>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ResourceCompile Include="..\..\resources\OpenRCT2.rc" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="openrct2-dll.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

View File

@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright (c) 2014-2019 OpenRCT2 developers
* Copyright (c) 2014-2020 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
@ -7,8 +7,8 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
// Windows.h needs to be included first
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
// Enable visual styles
@ -16,13 +16,65 @@
linker, \
"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define DLLIMPORT extern "C"
DLLIMPORT int LaunchOpenRCT2(int argc, wchar_t** argv);
// Then the rest
#include <openrct2-ui/Ui.h>
#include <stdio.h>
#include <stdlib.h>
static char** GetCommandLineArgs(int argc, wchar_t** argvW);
static void FreeCommandLineArgs(int argc, char** argv);
static char* ConvertWideChartoUTF8(const wchar_t* src);
/**
* Windows entry point to OpenRCT2 with a console window using a traditional C main function.
*/
int wmain(int argc, wchar_t** argvW, [[maybe_unused]] wchar_t* envp)
{
return LaunchOpenRCT2(argc, argvW);
auto argv = GetCommandLineArgs(argc, argvW);
if (argv == nullptr)
{
puts("Unable to fetch command line arguments.");
return -1;
}
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
auto exitCode = NormalisedMain(argc, const_cast<const char**>(argv));
FreeCommandLineArgs(argc, argv);
return exitCode;
}
static char** GetCommandLineArgs(int argc, wchar_t** argvW)
{
// Allocate UTF-8 strings
auto argv = (char**)malloc(argc * sizeof(char*));
if (argv != nullptr)
{
// Convert to UTF-8
for (int i = 0; i < argc; i++)
{
argv[i] = ConvertWideChartoUTF8(argvW[i]);
}
}
return argv;
}
static void FreeCommandLineArgs(int argc, char** argv)
{
// Free argv
for (int i = 0; i < argc; i++)
{
free(argv[i]);
}
free(argv);
}
static char* ConvertWideChartoUTF8(const wchar_t* src)
{
auto srcLen = lstrlenW(src);
auto sizeReq = WideCharToMultiByte(CP_UTF8, 0, src, srcLen, nullptr, 0, nullptr, nullptr);
auto result = static_cast<char*>(calloc(1, static_cast<size_t>(sizeReq) + 1));
WideCharToMultiByte(CP_UTF8, 0, src, srcLen, result, sizeReq, nullptr, nullptr);
return result;
}

View File

@ -34,17 +34,12 @@
<TargetName>openrct2</TargetName>
<LibraryPath>$(SolutionDir)bin;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions Condition="'$(Configuration)'=='DebugTests' OR '$(Configuration)'=='ReleaseTests'">__NOENTRYPOINT__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>$(OPENRCT2_CL_ADDITIONALOPTIONS) %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>
<AdditionalDependencies>openrct2.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libopenrct2.lib;libopenrct2ui.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ProgramDatabaseFile>$(OutDir)openrct2-win.pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
</Link>