From 1ec0749bcf86d1c17c1fbd3fd112b25f793f25ef Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Sat, 13 Jan 2018 22:24:31 +0100 Subject: [PATCH] [ACLAYERS] Add Google Chrome shim that will automatically force the commandline to include --no-sandbox --- dll/appcompat/shims/layer/CMakeLists.txt | 1 + dll/appcompat/shims/layer/chrome.c | 109 +++++++++++++++++++++++++++++++ media/sdb/sysmain.xml | 15 +++++ 3 files changed, 125 insertions(+) create mode 100644 dll/appcompat/shims/layer/chrome.c diff --git a/dll/appcompat/shims/layer/CMakeLists.txt b/dll/appcompat/shims/layer/CMakeLists.txt index f62c8dd13c..c8db0b234b 100644 --- a/dll/appcompat/shims/layer/CMakeLists.txt +++ b/dll/appcompat/shims/layer/CMakeLists.txt @@ -4,6 +4,7 @@ include_directories(${SHIMLIB_DIR}) spec2def(aclayers.dll layer.spec) list(APPEND SOURCE + chrome.c dispmode.c versionlie.c vmhorizon.c diff --git a/dll/appcompat/shims/layer/chrome.c b/dll/appcompat/shims/layer/chrome.c new file mode 100644 index 0000000000..202e04e801 --- /dev/null +++ b/dll/appcompat/shims/layer/chrome.c @@ -0,0 +1,109 @@ +/* + * PROJECT: ReactOS 'Layers' Shim library + * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) + * PURPOSE: Shim for Google Chrome + * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen@reactos.org) + */ + +#define WIN32_NO_STATUS +#include +#include +#include +#include "ntndk.h" + +#define SHIM_NS GoogleChrome +#include + +static LPSTR SHIM_OBJ_NAME(g_NewCommandLineA) = NULL; +static LPWSTR SHIM_OBJ_NAME(g_NewCommandLineW) = NULL; +static const WCHAR szAppendArgument[] = L" --no-sandbox"; + +typedef LPWSTR(WINAPI* GETCOMMANDLINEWPROC)(VOID); +typedef LPSTR(WINAPI* GETCOMMANDLINEAPROC)(VOID); + +static void InitCommandLine(VOID) +{ + LPWSTR CommandLine = CALL_SHIM(1, GETCOMMANDLINEWPROC)(); + if (CommandLine && wcsstr(CommandLine, szAppendArgument)) + { + SHIM_MSG("Parent process already passed commandline, noop\n"); + SHIM_OBJ_NAME(g_NewCommandLineW) = CommandLine; + SHIM_OBJ_NAME(g_NewCommandLineA) = CALL_SHIM(0, GETCOMMANDLINEAPROC)(); + return; + } + + if (CommandLine) + { + UNICODE_STRING NewCommandLineW = { 0 }; + ANSI_STRING NewCommandLineA; + SIZE_T Len = wcslen(CommandLine); + Len += wcslen(szAppendArgument) + 1; + + NewCommandLineW.MaximumLength = Len * sizeof(WCHAR); + NewCommandLineW.Buffer = ShimLib_ShimMalloc(NewCommandLineW.MaximumLength); + if (NewCommandLineW.Buffer) + { + RtlAppendUnicodeToString(&NewCommandLineW, CommandLine); + RtlAppendUnicodeToString(&NewCommandLineW, szAppendArgument); + } + else + { + RtlInitUnicodeString(&NewCommandLineW, CommandLine); + SHIM_WARN("Unable to create new command line\n"); + } + + SHIM_OBJ_NAME(g_NewCommandLineW) = NewCommandLineW.Buffer; + + if (!NT_SUCCESS(RtlUnicodeStringToAnsiString(&NewCommandLineA, &NewCommandLineW, TRUE))) + { + SHIM_OBJ_NAME(g_NewCommandLineA) = CALL_SHIM(0, GETCOMMANDLINEAPROC)(); + SHIM_WARN("Unable to convert commandlineW to commandlineA\n"); + } + else + { + SHIM_OBJ_NAME(g_NewCommandLineA) = NewCommandLineA.Buffer; + } + } +} + + +LPSTR WINAPI SHIM_OBJ_NAME(APIHook_GetCommandLineA)(VOID) +{ + if (!SHIM_OBJ_NAME(g_NewCommandLineA)) + { + SHIM_MSG("Calling InitCommandLine\n"); + InitCommandLine(); + } + return SHIM_OBJ_NAME(g_NewCommandLineA); +} + +LPWSTR WINAPI SHIM_OBJ_NAME(APIHook_GetCommandLineW)(VOID) +{ + if (!SHIM_OBJ_NAME(g_NewCommandLineW)) + { + SHIM_MSG("Calling InitCommandLine\n"); + InitCommandLine(); + } + return SHIM_OBJ_NAME(g_NewCommandLineW); +} + +BOOL WINAPI SHIM_OBJ_NAME(Notify)(DWORD fdwReason, PVOID ptr) +{ + if (fdwReason == SHIM_REASON_INIT) + { + if (!SHIM_OBJ_NAME(g_NewCommandLineA)) + { + SHIM_MSG("Calling InitCommandLine\n"); + InitCommandLine(); + } + } + return TRUE; +} + +#define SHIM_NOTIFY_FN SHIM_OBJ_NAME(Notify) +#define SHIM_NUM_HOOKS 2 +#define SHIM_SETUP_HOOKS \ + SHIM_HOOK(0, "KERNEL32.DLL", "GetCommandLineA", SHIM_OBJ_NAME(APIHook_GetCommandLineA)) \ + SHIM_HOOK(1, "KERNEL32.DLL", "GetCommandLineW", SHIM_OBJ_NAME(APIHook_GetCommandLineW)) + +#include diff --git a/media/sdb/sysmain.xml b/media/sdb/sysmain.xml index 7ab4a616f3..337dc7914f 100644 --- a/media/sdb/sysmain.xml +++ b/media/sdb/sysmain.xml @@ -188,6 +188,9 @@ acgenral.dll + + aclayers.dll + aclayers.dll @@ -306,5 +309,17 @@ + + + + + Google Chrome + Google Inc. + Google Chrome + chrome.exe + chrome_exe + + + \ No newline at end of file -- 2.12.2.windows.1