From 9983e9ed43f8127fda5d37dacf32405f0f1ca3d4 Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Tue, 5 Oct 2021 00:19:05 +0800 Subject: [PATCH] Fix error in parsing ShadowsocksR configurations Fix code style. --- src/parser/subparser.cpp | 11 +++-------- src/script/cron.cpp | 2 +- src/script/script_quickjs.cpp | 8 +++----- src/utils/codepage.cpp | 27 --------------------------- src/utils/md5/md5.cpp | 3 ++- 5 files changed, 9 insertions(+), 42 deletions(-) diff --git a/src/parser/subparser.cpp b/src/parser/subparser.cpp index 3acf46e..d7410af 100644 --- a/src/parser/subparser.cpp +++ b/src/parser/subparser.cpp @@ -528,7 +528,7 @@ void explodeSSConf(std::string content, std::vector &nodes) void explodeSSR(std::string ssr, Proxy &node) { std::string strobfs; - std::string remarks, group, server, port, method, password, protocol, protoparam, obfs, obfsparam, remarks_base64; + std::string remarks, group, server, port, method, password, protocol, protoparam, obfs, obfsparam; ssr = replaceAllDistinct(ssr.substr(6), "\r", ""); ssr = urlSafeBase64Decode(ssr); if(strFind(ssr, "/?")) @@ -537,7 +537,6 @@ void explodeSSR(std::string ssr, Proxy &node) ssr = ssr.substr(0, ssr.find("/?")); group = urlSafeBase64Decode(getUrlArg(strobfs, "group")); remarks = urlSafeBase64Decode(getUrlArg(strobfs, "remarks")); - remarks_base64 = urlSafeBase64Reverse(getUrlArg(strobfs, "remarks")); obfsparam = regReplace(urlSafeBase64Decode(getUrlArg(strobfs, "obfsparam")), "\\s", ""); protoparam = regReplace(urlSafeBase64Decode(getUrlArg(strobfs, "protoparam")), "\\s", ""); } @@ -551,10 +550,7 @@ void explodeSSR(std::string ssr, Proxy &node) if(group.empty()) group = SSR_DEFAULT_GROUP; if(remarks.empty()) - { remarks = server + ":" + port; - remarks_base64 = base64Encode(remarks); - } if(find(ss_ciphers.begin(), ss_ciphers.end(), method) != ss_ciphers.end() && (obfs.empty() || obfs == "plain") && (protocol.empty() || protocol == "origin")) { @@ -570,7 +566,7 @@ void explodeSSRConf(std::string content, std::vector &nodes) { Proxy node; Document json; - std::string remarks, remarks_base64, group, server, port, method, password, protocol, protoparam, obfs, obfsparam, plugin, pluginopts; + std::string remarks, group, server, port, method, password, protocol, protoparam, obfs, obfsparam, plugin, pluginopts; int index = nodes.size(); json.Parse(content.data()); @@ -615,7 +611,6 @@ void explodeSSRConf(std::string content, std::vector &nodes) if(remarks.empty()) remarks = server + ":" + port; - remarks_base64 = GetMember(json["configs"][i], "remarks_base64"); // electron-ssr does not contain this field password = GetMember(json["configs"][i], "password"); method = GetMember(json["configs"][i], "method"); @@ -624,7 +619,7 @@ void explodeSSRConf(std::string content, std::vector &nodes) obfs = GetMember(json["configs"][i], "obfs"); obfsparam = GetMember(json["configs"][i], "obfsparam"); - ssrConstruct(node, group, remarks, remarks_base64, server, port, protocol, method, obfs, password, obfsparam, protoparam); + ssrConstruct(node, group, remarks, server, port, protocol, method, obfs, password, obfsparam, protoparam); node.Id = index; nodes.emplace_back(std::move(node)); node = Proxy(); diff --git a/src/script/cron.cpp b/src/script/cron.cpp index 0c2680e..0d43901 100644 --- a/src/script/cron.cpp +++ b/src/script/cron.cpp @@ -37,7 +37,7 @@ struct script_info int timeout_checker(JSRuntime *rt, void *opaque) { - script_info info = *((script_info*)opaque); + script_info info = *static_cast(opaque); if(info.timeout != 0 && time(NULL) >= info.begin_time + info.timeout) /// timeout reached { writeLog(0, "Script '" + info.name + "' has exceeded timeout " + std::to_string(info.timeout) + ", terminate now.", LOG_LEVEL_WARNING); diff --git a/src/script/script_quickjs.cpp b/src/script/script_quickjs.cpp index c696227..6d15558 100644 --- a/src/script/script_quickjs.cpp +++ b/src/script/script_quickjs.cpp @@ -227,7 +227,7 @@ public: qjs_fetch_Headers headers; std::string cookies; std::string postdata; - qjs_fetch_Request(const std::string &url) : url(url) {} + explicit qjs_fetch_Request(const std::string &url) : url(url) {} }; class qjs_fetch_Response @@ -390,14 +390,12 @@ void script_runtime_init(qjs::Runtime &runtime) JS_SetModuleLoaderFunc(runtime.rt, nullptr, js_module_loader, nullptr); } -int ShowMsgbox(std::string title, std::string content, uint16_t type = 0) +int ShowMsgbox(const std::string &title, std::string content, uint16_t type = 0) { #ifdef _WIN32 if(!type) type = MB_ICONINFORMATION; - title = utf8ToACP(title); - content = utf8ToACP(content); - return MessageBoxA(NULL, content.c_str(), title.c_str(), type); + return MessageBoxA(NULL, utf8ToACP(content).c_str(), utf8ToACP(title).c_str(), type); #else return -1; #endif // _WIN32 diff --git a/src/utils/codepage.cpp b/src/utils/codepage.cpp index 97deb1d..a2b20b8 100644 --- a/src/utils/codepage.cpp +++ b/src/utils/codepage.cpp @@ -71,30 +71,3 @@ std::string utf8ToACP(const std::string &str_src) return str_src; #endif } - -#ifdef _WIN32 -// std::string to wstring -void stringToWstring(std::wstring& szDst, const std::string &str) -{ - std::string temp = str; - int len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)temp.c_str(), -1, NULL,0); - wchar_t* wszUtf8 = new wchar_t[len + 1]; - memset(wszUtf8, 0, len * 2 + 2); - MultiByteToWideChar(CP_ACP, 0, (LPCSTR)temp.c_str(), -1, (LPWSTR)wszUtf8, len); - szDst = wszUtf8; - //std::wstring r = wszUtf8; - delete[] wszUtf8; -} - -std::string wstringToString(LPWSTR str) -{ - std::string result; - size_t srclen = wcslen(str); - size_t len = WideCharToMultiByte(CP_ACP, 0, str, srclen, 0, 0, 0, 0); - result.resize(len); - WideCharToMultiByte(CP_ACP, 0, str, srclen, result.data(), len, 0, 0); - return result; -} -#else -/* Unimplemented: std::codecvt_utf8 */ -#endif // _WIN32 diff --git a/src/utils/md5/md5.cpp b/src/utils/md5/md5.cpp index 6986fbd..e546e0e 100644 --- a/src/utils/md5/md5.cpp +++ b/src/utils/md5/md5.cpp @@ -391,7 +391,8 @@ namespace md5 { message_length[0] = 0; message_length[1] = 0; stored_size = 0; - memset(&stored, 0, BLOCK_SIZE * 2); + memset(stored, 0, BLOCK_SIZE * 2); + memset(signature, 0, MD5_SIZE); finished = false; }