From 40be01370bbb68730efc0bef4f69ac81d7af7453 Mon Sep 17 00:00:00 2001 From: Alan Davies Date: Tue, 14 Jan 2025 16:34:08 +0000 Subject: [PATCH] Added capability to hide the shim'd application --- shim/shim.cpp | 17 ++++++++++++----- shmake/shmake.cpp | 9 ++++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/shim/shim.cpp b/shim/shim.cpp index effceb7..574363a 100644 --- a/shim/shim.cpp +++ b/shim/shim.cpp @@ -9,14 +9,16 @@ using namespace std; const wstring CMD_TOKEN{ L"%s" }; -void get_caps(const wstring& caps_str, bool& clipboard, bool& no_kill) +void get_caps(const wstring& caps_str, bool& clipboard, bool& no_kill, bool& hide) { - auto detect_cap = [&clipboard, &no_kill](const wstring& cap_name) + auto detect_cap = [&clipboard, &no_kill, &hide](const wstring& cap_name) { if (cap_name == L"clipboard") clipboard = true; else if (cap_name == L"no-kill") no_kill = true; + else if (cap_name == L"hide") + hide = true; }; wstring cap_name; @@ -47,7 +49,8 @@ int wmain(int argc, wchar_t* argv[], wchar_t *envp[]) bool cap_clipboard = false; bool cap_no_kill = false; - get_caps(caps_str, cap_clipboard, cap_no_kill); + bool cap_hide = false; + get_caps(caps_str, cap_clipboard, cap_no_kill, cap_hide); // args auto args = args_pattern; @@ -76,6 +79,11 @@ int wmain(int argc, wchar_t* argv[], wchar_t *envp[]) PROCESS_INFORMATION pi = { 0 }; si.cb = sizeof(si); + // create process in suspended state in case we need to do some adjustments before it executes + DWORD creation_flags = CREATE_SUSPENDED; + if (cap_hide) + creation_flags |= CREATE_NO_WINDOW; + //wcout << L"launching " << full_cmd << endl; if(!::CreateProcess( @@ -84,8 +92,7 @@ int wmain(int argc, wchar_t* argv[], wchar_t *envp[]) NULL, // lpProcessAttributes NULL, // lpThreadAttributes TRUE, // bInheritHandles - // create process in suspended state in case we need to do some adjustments before it executes - CREATE_SUSPENDED, // dwCreationFlags + creation_flags, // dwCreationFlags NULL, // lpEnvironment NULL, // lpCurrentDirectory &si, diff --git a/shmake/shmake.cpp b/shmake/shmake.cpp index 6659dfa..6655dd4 100644 --- a/shmake/shmake.cpp +++ b/shmake/shmake.cpp @@ -36,8 +36,8 @@ int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) "Command line to execute. By default arguments are passed through as is, but you can pass any string and use %s as substitute for the original arguments.") ("app-path", po::wvalue(&app_path)->default_value(L"", ""), "App path to use instead of 'input' when launching the shim. This is useful when you need to launch a different program, but still copy version and icon information from the 'input'.") - ("capabilities,c", po::wvalue>(&caps)->multitoken(), "Capabilities i.e. what target app is allowed to do. By default clipboard access is allowed. Supported options: clipboard - allow clipboard access, no-kill - do not kill target process when shim exits. You can pass multiple capabilities i.e. -c clipboard no-kill") - ("keep-relative", po::bool_switch()->default_value(false), "Switch that ask to not transform input and app-path to absolute path, but keep them relative. Pay attention that if you specify a output path, input should probably not be relative, but app-path still can be, especially if it’s an app in the PATH."); + ("capabilities,c", po::wvalue>(&caps)->multitoken(), "Capabilities i.e. what target app is allowed to do. By default clipboard access is allowed. Supported options: clipboard - allow clipboard access, no-kill - do not kill target process when shim exits, hide - do not display the shim'd program window when it runs. You can pass multiple capabilities i.e. -c clipboard no-kill") + ("keep-relative", po::bool_switch()->default_value(false), "Switch that ask to not transform input and app-path to absolute path, but keep them relative. Pay attention that if you specify a output path, input should probably not be relative, but app-path still can be, especially if it's an app in the PATH."); try { @@ -66,6 +66,8 @@ int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) } fs::path input_path(input); + const bool hide = (std::find(caps.begin(), caps.end(), L"hide") != caps.end()); + wstring caps_str; if (!caps.empty()) { @@ -115,7 +117,8 @@ int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) try { - bool is_console = is_console_exe(input); + // Force GUI-style shim if we are hiding the shim'd application + bool is_console = !hide && is_console_exe(input); wcout << "extracting " << (is_console ? L"terminal" : L"GUI") << " shim... "; {