From 4287759e06a932f7c7e944987768baf65e3d8239 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sat, 16 Apr 2022 14:50:59 +0100 Subject: [PATCH] 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. --- app/src/server.c | 18 ++++++++++++++++++ app/src/server.h | 1 + 2 files changed, 19 insertions(+) diff --git a/app/src/server.c b/app/src/server.c index c02390a4..712a6f4a 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -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"); } diff --git a/app/src/server.h b/app/src/server.h index 5f630ca8..cf52e963 100644 --- a/app/src/server.h +++ b/app/src/server.h @@ -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;