|
game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
|
Utilities for safely building shell commands. More...
#include <shell_utils.h>
Static Public Member Functions | |
| static std::string | buildCommand (const std::vector< std::string > &args, const std::map< std::string, std::string > &envVars={}) |
| Build a complete shell command from parts. | |
| static std::string | buildCommandWithWrapper (const std::string &wrapper, const std::vector< std::string > &args, const std::map< std::string, std::string > &envVars={}) |
| Build command with a wrapper (e.g., game-performance, mangohud). | |
| static std::string | buildJsonArray (const std::vector< std::string > &items) |
| Build a JSON array from strings. | |
| static std::string | buildJsonObject (const std::map< std::string, std::string > &pairs) |
| Build a JSON object from key-value pairs. | |
| static std::string | escapeArg (const std::string &arg) |
| Escape a string for safe use as a shell argument. | |
| static std::string | escapeForDoubleQuotes (const std::string &arg) |
| Escape a string for use in double quotes. | |
| static std::string | escapeJson (const std::string &str) |
| Escape a string for JSON. | |
| static std::string | escapePath (const std::string &path, bool allowTraversal=false) |
| Escape a path for shell use with validation. | |
| static std::string | formatEnvVar (const std::string &name, const std::string &value) |
| Format an environment variable assignment safely. | |
| static std::string | formatEnvVars (const std::map< std::string, std::string > &envVars, bool skipInvalid=true) |
| Format multiple environment variables safely. | |
| static bool | isSafePath (const std::string &path) |
| Check if a path is safe (no directory traversal, no special chars). | |
| static bool | isValidEnvName (const std::string &name) |
| Validate an environment variable name. | |
| static std::vector< std::string > | splitArgs (const std::string &args) |
| Split a shell argument string into tokens, respecting quoting. | |
Utilities for safely building shell commands.
Provides functions to escape shell arguments and environment variables to prevent command injection attacks. All methods are static.
Definition at line 47 of file shell_utils.h.
|
inlinestatic |
Build a complete shell command from parts.
| args | Command and arguments (args[0] is the command) |
| envVars | Optional environment variables to prepend |
Example: buildCommand({"wine", "/path/to/game.exe", "--flag"}, {{"WINEPREFIX", "/home/user/.wine"}}) Returns: "WINEPREFIX='/home/user/.wine' wine '/path/to/game.exe' '--flag'"
Definition at line 240 of file shell_utils.h.
|
inlinestatic |
Build command with a wrapper (e.g., game-performance, mangohud).
| wrapper | The wrapper command (e.g., "game-performance", "mangohud") |
| args | Command and arguments |
| envVars | Environment variables |
Definition at line 344 of file shell_utils.h.
|
inlinestatic |
Build a JSON array from strings.
| items | Vector of strings |
Definition at line 516 of file shell_utils.h.
References escapeJson().
|
inlinestatic |
Build a JSON object from key-value pairs.
| pairs | Map of keys to values |
Definition at line 493 of file shell_utils.h.
References escapeJson().
|
inlinestatic |
Escape a string for safe use as a shell argument.
| arg | The argument to escape |
Uses single quotes with proper escaping of embedded single quotes. This is the safest method as single-quoted strings prevent all shell expansion except for the quote character itself.
Example: "hello'world" becomes "'hello'\''world'"
Definition at line 65 of file shell_utils.h.
Referenced by LegendaryIntegration::authenticateWithCode(), CachyOSGameConfig::buildEnvVars(), UMULauncher::buildLaunchCommand(), anonymous_namespace{game_process.cpp}::buildWrapperChain(), FileDownloadService::calculateChecksum(), UMULauncher::createPrefix(), UMULauncher::Impl::detectUMURun(), FileDownloadService::download(), UMULauncher::downloadGEProton(), SteamCDN::downloadImage(), UMULauncher::downloadUMUProton(), escapePath(), PrefixSnapshotService::exportSnapshot(), anonymous_namespace{wine_dependency_manager.cpp}::findExecutable(), formatEnvVar(), ProcessExecutor::getProcessPid(), FileDownloadService::getRemoteFileSize(), PrefixSnapshotService::importSnapshot(), ProcessExecutor::isProcessRunning(), ArchiveExtractService::isToolInstalled(), FileDownloadService::isUrlAccessible(), GOGIntegration::launchGame(), ArchiveExtractService::listContents(), WineDependencyManager::removeDLLOverride(), UMULauncher::runWinetricks(), and WineDependencyManager::setDLLOverride().
|
inlinestatic |
Escape a string for use in double quotes.
| arg | The argument to escape |
Escapes characters that have special meaning in double quotes: $, backtick, \\endiskip, ", !, and newlines.
Note: Caller must add the surrounding double quotes. Prefer escapeArg() with single quotes when possible.
Definition at line 108 of file shell_utils.h.
Referenced by ProcessExecutor::getProcessPid(), and ProcessExecutor::isProcessRunning().
|
inlinestatic |
Escape a string for JSON.
| str | The string to escape |
Definition at line 440 of file shell_utils.h.
Referenced by buildJsonArray(), buildJsonObject(), and HLTBService::search().
|
inlinestatic |
Escape a path for shell use with validation.
| path | The path to escape |
| allowTraversal | If false (default), reject paths with .. |
Definition at line 422 of file shell_utils.h.
References escapeArg(), and isSafePath().
|
inlinestatic |
Format an environment variable assignment safely.
| name | Variable name (must be valid - checked) |
| value | Variable value (will be escaped) |
Example: formatEnvVar("PATH", "/usr/bin:/tmp") returns "PATH='/usr/bin:/tmp'"
Definition at line 184 of file shell_utils.h.
References escapeArg(), and isValidEnvName().
Referenced by formatEnvVars().
|
inlinestatic |
Format multiple environment variables safely.
| envVars | Map of variable names to values |
| skipInvalid | If true, skip invalid names; if false, return empty on any invalid |
Definition at line 200 of file shell_utils.h.
References formatEnvVar(), and isValidEnvName().
|
inlinestatic |
Check if a path is safe (no directory traversal, no special chars).
| path | The path to check |
Rejects paths with:
Definition at line 385 of file shell_utils.h.
Referenced by escapePath().
|
inlinestatic |
Validate an environment variable name.
| name | The variable name to validate |
Valid names match: [A-Za-z_][A-Za-z0-9_]*
Definition at line 150 of file shell_utils.h.
Referenced by UMULauncher::buildLaunchCommand(), UMULauncher::buildLaunchComponents(), formatEnvVar(), and formatEnvVars().
|
inlinestatic |
Split a shell argument string into tokens, respecting quoting.
| args | The argument string (e.g., "--arg \"value with spaces\" --other") |
Handles single-quoted and double-quoted groups. Each returned token is the raw (unquoted) value; pass each through escapeArg() before appending to a shell command. This replaces the insecure "use as-is when quotes detected" pattern that was a shell-injection vector.
Definition at line 274 of file shell_utils.h.
References None.