Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added capability to hide the shim'd application #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions shim/shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions shmake/shmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<wstring>(&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<vector<wstring>>(&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 its an app in the PATH.");
("capabilities,c", po::wvalue<vector<wstring>>(&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
{
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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... ";

{
Expand Down