From c1d0fe75d267f33724c38af95efc7b1c050dc160 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 17 Jun 2021 08:54:00 +0200 Subject: Temporary abort on fail to read file.. if its being modified while reading --- src/plugins/youtube/Signature.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'src/plugins/youtube/Signature.cpp') diff --git a/src/plugins/youtube/Signature.cpp b/src/plugins/youtube/Signature.cpp index 8c87817..7631182 100644 --- a/src/plugins/youtube/Signature.cpp +++ b/src/plugins/youtube/Signature.cpp @@ -4,6 +4,7 @@ #include "../../../include/DownloadUtils.hpp" #include "../../../include/StringUtils.hpp" #include "../../../include/Program.hpp" +#include "../../../include/NetUtils.hpp" #include #include #include @@ -18,6 +19,26 @@ namespace QuickMedia { static std::mutex update_signature_mutex; static const int timeout_default_sec = 60 * 5; // 5 minutes + static bool is_whitespace(char c) { + switch(c) { + case ' ': + case '\r': + case '\n': + case '\t': + return true; + } + return false; + } + + static std::string remove_whitespaces(const std::string &str) { + std::string result; + for(char c : str) { + if(!is_whitespace(c)) + result += c; + } + return result; + } + bool YoutubeSignatureDecryptor::js_code_to_operations(const std::string &function_body_str, const std::string &var_body_str, std::vector &new_func_calls, std::map &new_func_decls) { std::vector function_body; string_split(function_body_str, ';', [&function_body](const char *str, size_t size) { @@ -77,7 +98,7 @@ namespace QuickMedia { std::string func_name = func_decl_str.substr(0, func_name_split_index); func_name = strip(func_name); std::string function_body = func_decl_str.substr(func_start_index + 1); - function_body = strip(function_body); + function_body = strip(remove_whitespaces(function_body)); if(!function_body.empty() && function_body.back() == '}') function_body.pop_back(); @@ -86,8 +107,12 @@ namespace QuickMedia { decrypt_function = DecryptFunction::REVERSE; else if(function_body == "a.splice(0,b)") decrypt_function = DecryptFunction::SPLICE; - else + else if(function_body.find("a[0]=a[b%a.length]") != std::string::npos) decrypt_function = DecryptFunction::SWAP; + else { + fprintf(stderr, "Unexpected decryption function body: |%s|\n", function_body.c_str()); + return false; + } //fprintf(stderr, "declared function: %s, body: |%s|\n", func_name.c_str(), function_body.c_str()); new_func_decls[std::move(func_name)] = decrypt_function; } @@ -216,7 +241,7 @@ namespace QuickMedia { break; } case DecryptFunction::SWAP: { - if(sig.empty()) { + if(sig.empty() || func_call.arg < 0) { fprintf(stderr, "YoutubeSignatureDecryptor: sig unexpectedly empty in swap\n"); } else { char c = sig[0]; @@ -229,7 +254,7 @@ namespace QuickMedia { } sig_key = sp; - sig_value = sig; + sig_value = url_param_encode(sig); return true; } -- cgit v1.2.3