Run server with escaped hook_script argument

Unlike what would be expected, adb shell just concatenates the arguments as strings same
as if they were just separated by spaces. Sending the commands in one argument
or sending as multiple arguments doesn't preduce any different outcome.
Sad but that's how adb works.

try:
adb shell 'am broadcast'
vs
adb shell am broadcast

If they both work, means there's no reasonable way to deliver the arguments as-is.
They have to be escaped.
This commit is contained in:
brunoais 2022-04-16 14:50:59 +01:00
parent 2ea9cdd022
commit 4287759e06
2 changed files with 19 additions and 0 deletions

View file

@ -93,6 +93,7 @@ sc_server_params_copy(struct sc_server_params *dst,
COPY(crop);
COPY(codec_options);
COPY(encoder_name);
COPY(hook_script);
COPY(tcpip_dst);
#undef COPY
@ -233,6 +234,23 @@ execute_server(struct sc_server *server,
if (params->encoder_name) {
ADD_PARAM("encoder_name=%s", params->encoder_name);
}
if (params->hook_script) {
char* requoted_hook;
int64_t replace_result = sc_str_find_replace(params->hook_script, "'", "'\"'\"'", &requoted_hook);
switch(replace_result){
case -2:
LOG_OOM();
break;
case -1:
case 0:
ADD_PARAM("hook_script='%s'", params->hook_script);
break;
default:
ADD_PARAM("hook_script='%s'", requoted_hook);
free(requoted_hook);
}
}
if (params->power_off_on_close) {
ADD_PARAM("power_off_on_close=true");
}

View file

@ -39,6 +39,7 @@ struct sc_server_params {
bool show_touches;
bool stay_awake;
bool force_adb_forward;
const char * hook_script;
bool power_off_on_close;
bool clipboard_autosync;
bool downsize_on_error;