-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add launcher command line parameter to run legacy binaries from bin_l…
…egacy
- Loading branch information
Showing
7 changed files
with
155 additions
and
60 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. --> | ||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<PropertyGroup Condition="'$(HybridCrtConfiguration)'==''"> | ||
<HybridCrtConfiguration>$(Configuration)</HybridCrtConfiguration> | ||
</PropertyGroup> | ||
|
||
<ItemDefinitionGroup Condition="'$(HybridCrtConfiguration)'=='Debug'"> | ||
<ClCompile> | ||
<!-- We use MultiThreadedDebug, rather than MultiThreadedDebugDLL, to avoid DLL dependencies on VCRUNTIME140d.dll and MSVCP140d.dll. --> | ||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | ||
</ClCompile> | ||
<Link> | ||
<!-- Link statically against the runtime and STL, but link dynamically against the CRT by ignoring the static CRT | ||
lib and instead linking against the Universal CRT DLL import library. This "hybrid" linking mechanism is | ||
supported according to the CRT maintainer. Dynamic linking against the CRT makes the binaries a bit smaller | ||
than they would otherwise be if the CRT, runtime, and STL were all statically linked in. --> | ||
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries);libucrtd.lib</IgnoreSpecificDefaultLibraries> | ||
<AdditionalOptions>%(AdditionalOptions) /defaultlib:ucrtd.lib</AdditionalOptions> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(HybridCrtConfiguration)'=='Release'"> | ||
<ClCompile> | ||
<!-- We use MultiThreaded, rather than MultiThreadedDLL, to avoid DLL dependencies on VCRUNTIME140.dll and MSVCP140.dll. --> | ||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> | ||
</ClCompile> | ||
<Link> | ||
<!-- Link statically against the runtime and STL, but link dynamically against the CRT by ignoring the static CRT | ||
lib and instead linking against the Universal CRT DLL import library. This "hybrid" linking mechanism is | ||
supported according to the CRT maintainer. Dynamic linking against the CRT makes the binaries a bit smaller | ||
than they would otherwise be if the CRT, runtime, and STL were all statically linked in. --> | ||
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries);libucrt.lib</IgnoreSpecificDefaultLibraries> | ||
<AdditionalOptions>%(AdditionalOptions) /defaultlib:ucrt.lib</AdditionalOptions> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,80 @@ | ||
#include <Windows.h> | ||
|
||
static inline __forceinline __declspec(allocator) wchar_t* wstrdup(const wchar_t *_String) { | ||
size_t i = 0; | ||
while (_String[i] != 0) | ||
i++; | ||
wchar_t* ret = (wchar_t *)HeapAlloc(GetProcessHeap(), 0, sizeof(wchar_t) * (i + 1)); | ||
wsprintfW(ret, L"%s", _String); | ||
return ret; | ||
} | ||
#include <windows.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
DWORD __stdcall mainCRTStartup(LPVOID p) { | ||
//Create command, passing all of our arguments | ||
LPWSTR cmdline = GetCommandLineW(); | ||
wchar_t search = ' '; | ||
if (cmdline[0] == '"') { | ||
search = '"'; | ||
cmdline++; | ||
} | ||
while (cmdline[0] != 0) { | ||
cmdline++; | ||
if (cmdline[0] == search) { | ||
cmdline++; | ||
break; | ||
int wmain(int argc, wchar_t* argv[]) { | ||
|
||
STARTUPINFOW startup = {}; | ||
startup.cb = sizeof(startup); | ||
|
||
PROCESS_INFORMATION process = {}; | ||
|
||
wchar_t* path = L"bin\\win64\\Star Ruler 2.exe"; | ||
|
||
size_t size = 0; | ||
for (int i = 0; i < argc; i++) { | ||
if (wcscmp(argv[i], L"--legacy") == 0) { | ||
path = L"bin_legacy\\win64\\Star Ruler 2.exe"; | ||
} | ||
else { | ||
// worst-case estimate of expected escaped argument size, two output characters for every input character | ||
// (to handle quotes and backslashes), one separator space and a leading and trailing quote | ||
// first argument has no space, use it for the null terminator | ||
size += wcslen(argv[i]) * 2 + 3; | ||
} | ||
} | ||
while (cmdline[0] == ' ') { | ||
cmdline++; | ||
} | ||
|
||
STARTUPINFOW startup; | ||
SecureZeroMemory(&startup, sizeof(startup)); | ||
startup.cb = sizeof(startup); | ||
//Create command, passing all of our arguments | ||
|
||
wchar_t* cmdline = malloc(size * sizeof(wchar_t)); | ||
wchar_t* cur = cmdline; | ||
|
||
PROCESS_INFORMATION process; | ||
SecureZeroMemory(&process, sizeof(process)); | ||
for (int i = 0; i < argc; i++) { | ||
if (wcscmp(argv[i], L"--legacy") == 0) { | ||
continue; | ||
} | ||
|
||
for (wchar_t* arg = argv[i]; *arg != L'\0'; arg++) { | ||
if (i != 0) { | ||
*cur++ = L' '; | ||
} | ||
*cur++ = L'"'; | ||
switch (*arg) { | ||
case L'"': | ||
*cur++ = L'\\'; | ||
*cur++ = L'"'; | ||
arg++; | ||
break; | ||
case L'\\': | ||
int backslashes = 0; | ||
do { | ||
backslashes++; | ||
} while (arg[backslashes] == L'\\'); | ||
if (arg[backslashes] != 0 && arg[backslashes] != L'"') { | ||
for (int j = 0; j < backslashes; j++) { | ||
*cur++ = L'\\'; | ||
} | ||
} | ||
else { | ||
for (int j = 0; j < backslashes; j++) { | ||
*cur++ = L'\\'; | ||
*cur++ = L'\\'; | ||
} | ||
} | ||
arg += backslashes; | ||
break; | ||
default: | ||
*cur++ = *arg++; | ||
} | ||
*cur++ = L'"'; | ||
} | ||
} | ||
*cur = L'\0'; | ||
|
||
if(CreateProcessW(L"bin\\win64\\Star Ruler 2.exe", wstrdup(cmdline), NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &startup, &process) != FALSE) { | ||
if (CreateProcessW(path, cmdline, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &startup, &process) != FALSE) { | ||
CloseHandle(process.hProcess); | ||
CloseHandle(process.hThread); | ||
} | ||
free(cmdline); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters