mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-04 10:42:04 +00:00
Enhancements
Fix support for parsing some subscriptions with complex passwords. Add replacing all match when using rename_node. Remove support for std::regex for now. Optimize codes.
This commit is contained in:
6 files changed
+177
-39
No files matched your search
+6
-5
@@ -14,7 +14,8 @@ ELSE()
|
|||||||
ADD_COMPILE_OPTIONS(/W4)
|
ADD_COMPILE_OPTIONS(/W4)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
OPTION(USING_STD_REGEX "Use std::regex from C++ library instead of PCRE2." OFF)
|
#remove std::regex support since it is not compatible with group modifiers and slow
|
||||||
|
#OPTION(USING_STD_REGEX "Use std::regex from C++ library instead of PCRE2." OFF)
|
||||||
OPTION(USING_MALLOC_TRIM "Call malloc_trim after processing request to lower memory usage (Your system must support malloc_trim)." OFF)
|
OPTION(USING_MALLOC_TRIM "Call malloc_trim after processing request to lower memory usage (Your system must support malloc_trim)." OFF)
|
||||||
OPTION(USING_MBEDTLS "Use mbedTLS instead of OpenSSL for MD5 calculation." OFF)
|
OPTION(USING_MBEDTLS "Use mbedTLS instead of OpenSSL for MD5 calculation." OFF)
|
||||||
|
|
||||||
@@ -92,14 +93,14 @@ LINK_DIRECTORIES(${YAML_CPP_LIBRARY_DIRS})
|
|||||||
INCLUDE_DIRECTORIES(${YAML_CPP_INCLUDE_DIRS})
|
INCLUDE_DIRECTORIES(${YAML_CPP_INCLUDE_DIRS})
|
||||||
TARGET_LINK_LIBRARIES(subconverter ${YAML_CPP_LIBRARY})
|
TARGET_LINK_LIBRARIES(subconverter ${YAML_CPP_LIBRARY})
|
||||||
|
|
||||||
IF(USING_STD_REGEX STREQUAL "ON")
|
#IF(USING_STD_REGEX STREQUAL "ON")
|
||||||
ADD_DEFINITIONS(-DUSE_STD_REGEX)
|
# ADD_DEFINITIONS(-DUSE_STD_REGEX)
|
||||||
ELSE()
|
#ELSE()
|
||||||
FIND_PACKAGE(PCRE2 REQUIRED)
|
FIND_PACKAGE(PCRE2 REQUIRED)
|
||||||
INCLUDE_DIRECTORIES(${PCRE2_INCLUDE_DIRS})
|
INCLUDE_DIRECTORIES(${PCRE2_INCLUDE_DIRS})
|
||||||
TARGET_LINK_LIBRARIES(subconverter ${PCRE2_LIBRARY})
|
TARGET_LINK_LIBRARIES(subconverter ${PCRE2_LIBRARY})
|
||||||
ADD_DEFINITIONS(-DPCRE2_STATIC)
|
ADD_DEFINITIONS(-DPCRE2_STATIC)
|
||||||
ENDIF()
|
#ENDIF()
|
||||||
|
|
||||||
IF(WIN32)
|
IF(WIN32)
|
||||||
TARGET_LINK_LIBRARIES(subconverter wsock32 ws2_32)
|
TARGET_LINK_LIBRARIES(subconverter wsock32 ws2_32)
|
||||||
|
|||||||
+8
-2
@@ -2038,7 +2038,8 @@ std::string getRewriteRemote(RESPONSE_CALLBACK_ARGS)
|
|||||||
|
|
||||||
std::string parseHostname(inja::Arguments &args)
|
std::string parseHostname(inja::Arguments &args)
|
||||||
{
|
{
|
||||||
std::string data = args.at(0)->get<std::string>();
|
std::string data = args.at(0)->get<std::string>(), hostname;
|
||||||
|
const std::string matcher = R"(^(?i:hostname\s*?=\s*?)(.*?)\s$)";
|
||||||
string_array urls = split(data, ",");
|
string_array urls = split(data, ",");
|
||||||
if(!urls.size())
|
if(!urls.size())
|
||||||
return std::string();
|
return std::string();
|
||||||
@@ -2047,7 +2048,12 @@ std::string parseHostname(inja::Arguments &args)
|
|||||||
for(std::string &x : urls)
|
for(std::string &x : urls)
|
||||||
{
|
{
|
||||||
input_content = webGet(x, proxy, cache_config);
|
input_content = webGet(x, proxy, cache_config);
|
||||||
output_content += regReplace(input_content, "(?:[\\s\\S]*?)^(?i:hostname\\s*?=\\s*?)(.*?)\\s$(?:[\\s\\S]*)", "$1") + ",";
|
regGetMatch(input_content, matcher, 2, NULL, &hostname);
|
||||||
|
if(hostname.size())
|
||||||
|
{
|
||||||
|
output_content += hostname + ",";
|
||||||
|
hostname.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
string_array vArray = split(output_content, ",");
|
string_array vArray = split(output_content, ",");
|
||||||
std::set<std::string> hostnames;
|
std::set<std::string> hostnames;
|
||||||
|
|||||||
+87
-15
@@ -1,5 +1,4 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
//#include <regex>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -9,12 +8,14 @@
|
|||||||
//#include <filesystem>
|
//#include <filesystem>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*
|
||||||
#ifdef USE_STD_REGEX
|
#ifdef USE_STD_REGEX
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#else
|
#else
|
||||||
|
*/
|
||||||
#include <jpcre2.hpp>
|
#include <jpcre2.hpp>
|
||||||
typedef jpcre2::select<char> jp;
|
typedef jpcre2::select<char> jp;
|
||||||
#endif // USE_STD_REGEX
|
//#endif // USE_STD_REGEX
|
||||||
|
|
||||||
#include <rapidjson/document.h>
|
#include <rapidjson/document.h>
|
||||||
|
|
||||||
@@ -534,7 +535,7 @@ std::string replace_all_distinct(std::string str, const std::string &old_value,
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
#ifdef USE_STD_REGEX
|
#ifdef USE_STD_REGEX
|
||||||
bool regValid(const std::string ®)
|
bool regValid(const std::string ®)
|
||||||
{
|
{
|
||||||
@@ -611,42 +612,113 @@ bool regMatch(const std::string &src, const std::string &match)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int regGetMatch(const std::string &src, const std::string &match, size_t group_count, ...)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::regex::flag_type flags = std::regex::extended | std::regex::ECMAScript;
|
||||||
|
std::string target = match;
|
||||||
|
if(match.find("(?i)") == 0)
|
||||||
|
{
|
||||||
|
target.erase(0, 4);
|
||||||
|
flags |= std::regex::icase;
|
||||||
|
}
|
||||||
|
std::regex reg(target, flags);
|
||||||
|
std::smatch result;
|
||||||
|
if(regex_search(src.cbegin(), src.cend(), result, reg))
|
||||||
|
{
|
||||||
|
if(result.size() < group_count - 1)
|
||||||
|
return -1;
|
||||||
|
va_list vl;
|
||||||
|
va_start(vl, group_count);
|
||||||
|
size_t index = 0;
|
||||||
|
while(group_count)
|
||||||
|
{
|
||||||
|
std::string* arg = va_arg(vl, std::string*);
|
||||||
|
if(arg != NULL)
|
||||||
|
*arg = result[index];
|
||||||
|
index++;
|
||||||
|
group_count--;
|
||||||
|
}
|
||||||
|
va_end(vl);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (std::regex_error&)
|
||||||
|
{
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
*/
|
||||||
bool regMatch(const std::string &src, const std::string &target)
|
bool regMatch(const std::string &src, const std::string &match)
|
||||||
{
|
{
|
||||||
jp::Regex reg;
|
jp::Regex reg;
|
||||||
reg.setPattern(target).addModifier("gm").addPcre2Option(PCRE2_ANCHORED|PCRE2_ENDANCHORED|PCRE2_UTF).compile();
|
reg.setPattern(match).addModifier("gm").addPcre2Option(PCRE2_ANCHORED|PCRE2_ENDANCHORED|PCRE2_UTF).compile();
|
||||||
if(!reg)
|
if(!reg)
|
||||||
return false;
|
return false;
|
||||||
return reg.match(src);
|
return reg.match(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool regFind(const std::string &src, const std::string &target)
|
bool regFind(const std::string &src, const std::string &match)
|
||||||
{
|
{
|
||||||
jp::Regex reg;
|
jp::Regex reg;
|
||||||
reg.setPattern(target).addModifier("gm").addPcre2Option(PCRE2_UTF).compile();
|
reg.setPattern(match).addModifier("gm").addPcre2Option(PCRE2_UTF).compile();
|
||||||
if(!reg)
|
if(!reg)
|
||||||
return false;
|
return false;
|
||||||
return reg.match(src);
|
return reg.match(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string regReplace(const std::string &src, const std::string &target, const std::string &rep)
|
std::string regReplace(const std::string &src, const std::string &match, const std::string &rep)
|
||||||
{
|
{
|
||||||
jp::Regex reg;
|
jp::Regex reg;
|
||||||
reg.setPattern(target).addModifier("gm").addPcre2Option(PCRE2_UTF).compile();
|
reg.setPattern(match).addModifier("gm").addPcre2Option(PCRE2_UTF).compile();
|
||||||
if(!reg)
|
if(!reg)
|
||||||
return src;
|
return src;
|
||||||
return reg.replace(src, rep);
|
return reg.replace(src, rep, "g");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool regValid(const std::string &target)
|
bool regValid(const std::string ®)
|
||||||
{
|
{
|
||||||
jp::Regex reg(target);
|
jp::Regex r(reg);
|
||||||
return !!reg;
|
return !!r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // USE_STD_REGEX
|
int regGetMatch(const std::string &src, const std::string &match, size_t group_count, ...)
|
||||||
|
{
|
||||||
|
jp::Regex reg;
|
||||||
|
reg.setPattern(match).addModifier("gm").addPcre2Option(PCRE2_UTF).compile();
|
||||||
|
jp::VecNum vec_num;
|
||||||
|
jp::RegexMatch rm;
|
||||||
|
size_t count = rm.setRegexObject(®).setSubject(src).setNumberedSubstringVector(&vec_num).match();
|
||||||
|
if(!count || count < group_count - 1)
|
||||||
|
return -1;
|
||||||
|
va_list vl;
|
||||||
|
va_start(vl, group_count);
|
||||||
|
size_t index = 0, match_index = 0;
|
||||||
|
while(group_count)
|
||||||
|
{
|
||||||
|
std::string* arg = va_arg(vl, std::string*);
|
||||||
|
if(arg != NULL)
|
||||||
|
*arg = vec_num[match_index][index];
|
||||||
|
index++;
|
||||||
|
group_count--;
|
||||||
|
if(vec_num[match_index].size() <= index)
|
||||||
|
{
|
||||||
|
match_index++;
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
if(vec_num.size() <= match_index)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
va_end(vl);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//#endif // USE_STD_REGEX
|
||||||
|
|
||||||
std::string regTrim(const std::string &src)
|
std::string regTrim(const std::string &src)
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-1
@@ -126,10 +126,11 @@ bool is_str_utf8(const std::string &data);
|
|||||||
std::string getFormData(const std::string &raw_data);
|
std::string getFormData(const std::string &raw_data);
|
||||||
|
|
||||||
void sleep(int interval);
|
void sleep(int interval);
|
||||||
bool regValid(const std::string &target);
|
bool regValid(const std::string ®);
|
||||||
bool regFind(const std::string &src, const std::string &match);
|
bool regFind(const std::string &src, const std::string &match);
|
||||||
std::string regReplace(const std::string &src, const std::string &match, const std::string &rep);
|
std::string regReplace(const std::string &src, const std::string &match, const std::string &rep);
|
||||||
bool regMatch(const std::string &src, const std::string &match);
|
bool regMatch(const std::string &src, const std::string &match);
|
||||||
|
int regGetMatch(const std::string &src, const std::string &match, size_t group_count, ...);
|
||||||
std::string regTrim(const std::string &src);
|
std::string regTrim(const std::string &src);
|
||||||
std::string speedCalc(double speed);
|
std::string speedCalc(double speed);
|
||||||
std::string getMD5(const std::string &data);
|
std::string getMD5(const std::string &data);
|
||||||
|
|||||||
+63
-16
@@ -43,7 +43,6 @@ template <typename T> T safe_as (const YAML::Node& node)
|
|||||||
void explodeVmess(std::string vmess, const std::string &custom_port, nodeInfo &node)
|
void explodeVmess(std::string vmess, const std::string &custom_port, nodeInfo &node)
|
||||||
{
|
{
|
||||||
std::string version, ps, add, port, type, id, aid, net, path, host, tls;
|
std::string version, ps, add, port, type, id, aid, net, path, host, tls;
|
||||||
tribool udp, tfo, scv;
|
|
||||||
Document jsondata;
|
Document jsondata;
|
||||||
std::vector<std::string> vArray;
|
std::vector<std::string> vArray;
|
||||||
if(regMatch(vmess, "vmess://(.*?)\\?(.*)")) //shadowrocket style link
|
if(regMatch(vmess, "vmess://(.*?)\\?(.*)")) //shadowrocket style link
|
||||||
@@ -105,7 +104,7 @@ void explodeVmess(std::string vmess, const std::string &custom_port, nodeInfo &n
|
|||||||
node.remarks = ps;
|
node.remarks = ps;
|
||||||
node.server = add;
|
node.server = add;
|
||||||
node.port = to_int(port, 0);
|
node.port = to_int(port, 0);
|
||||||
node.proxyStr = vmessConstruct(add, port, type, id, aid, net, "auto", path, host, "", tls, udp, tfo, scv);
|
node.proxyStr = vmessConstruct(add, port, type, id, aid, net, "auto", path, host, "", tls);
|
||||||
}
|
}
|
||||||
|
|
||||||
void explodeVmessConf(std::string content, const std::string &custom_port, bool libev, std::vector<nodeInfo> &nodes)
|
void explodeVmessConf(std::string content, const std::string &custom_port, bool libev, std::vector<nodeInfo> &nodes)
|
||||||
@@ -260,8 +259,8 @@ void explodeVmessConf(std::string content, const std::string &custom_port, bool
|
|||||||
|
|
||||||
void explodeSS(std::string ss, bool libev, const std::string &custom_port, nodeInfo &node)
|
void explodeSS(std::string ss, bool libev, const std::string &custom_port, nodeInfo &node)
|
||||||
{
|
{
|
||||||
std::string ps, password, method, server, port, plugins, plugin, pluginopts, addition, group = SS_DEFAULT_GROUP;
|
std::string ps, password, method, server, port, plugins, plugin, pluginopts, addition, group = SS_DEFAULT_GROUP, secret;
|
||||||
std::vector<std::string> args, secret;
|
//std::vector<std::string> args, secret;
|
||||||
ss = replace_all_distinct(ss.substr(5), "/?", "?");
|
ss = replace_all_distinct(ss.substr(5), "/?", "?");
|
||||||
if(strFind(ss, "#"))
|
if(strFind(ss, "#"))
|
||||||
{
|
{
|
||||||
@@ -281,6 +280,7 @@ void explodeSS(std::string ss, bool libev, const std::string &custom_port, nodeI
|
|||||||
}
|
}
|
||||||
if(strFind(ss, "@"))
|
if(strFind(ss, "@"))
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
ss = regReplace(ss, "(.*?)@(.*):(.*)", "$1|$2|$3");
|
ss = regReplace(ss, "(.*?)@(.*):(.*)", "$1|$2|$3");
|
||||||
args = split(ss, "|");
|
args = split(ss, "|");
|
||||||
secret = split(urlsafe_base64_decode(args[0]), ":");
|
secret = split(urlsafe_base64_decode(args[0]), ":");
|
||||||
@@ -290,9 +290,15 @@ void explodeSS(std::string ss, bool libev, const std::string &custom_port, nodeI
|
|||||||
password = secret[1];
|
password = secret[1];
|
||||||
server = args[1];
|
server = args[1];
|
||||||
port = custom_port.empty() ? args[2] : custom_port;
|
port = custom_port.empty() ? args[2] : custom_port;
|
||||||
|
*/
|
||||||
|
if(regGetMatch(ss, "(.*?)@(.*):(.*)", 4, NULL, &secret, &server, &port))
|
||||||
|
return;
|
||||||
|
if(regGetMatch(urlsafe_base64_decode(secret), "(.*?):(.*)", 3, NULL, &method, &password))
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
if(!regMatch(urlsafe_base64_decode(ss), "(.*?):(.*?)@(.*):(.*)"))
|
if(!regMatch(urlsafe_base64_decode(ss), "(.*?):(.*?)@(.*):(.*)"))
|
||||||
return;
|
return;
|
||||||
ss = regReplace(urlsafe_base64_decode(ss), "(.*?):(.*?)@(.*):(.*)", "$1|$2|$3|$4");
|
ss = regReplace(urlsafe_base64_decode(ss), "(.*?):(.*?)@(.*):(.*)", "$1|$2|$3|$4");
|
||||||
@@ -303,7 +309,12 @@ void explodeSS(std::string ss, bool libev, const std::string &custom_port, nodeI
|
|||||||
password = args[1];
|
password = args[1];
|
||||||
server = args[2];
|
server = args[2];
|
||||||
port = custom_port.empty() ? args[3] : custom_port;
|
port = custom_port.empty() ? args[3] : custom_port;
|
||||||
|
*/
|
||||||
|
if(regGetMatch(urlsafe_base64_decode(ss), "(.*?):(.*)@(.*):(.*)", 5, NULL, &method, &password, &server, &port))
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if(custom_port.size())
|
||||||
|
port = custom_port;
|
||||||
if(ps.empty())
|
if(ps.empty())
|
||||||
ps = server + ":" + port;
|
ps = server + ":" + port;
|
||||||
|
|
||||||
@@ -501,6 +512,7 @@ void explodeSSR(std::string ssr, bool ss_libev, bool ssr_libev, const std::strin
|
|||||||
protoparam = regReplace(urlsafe_base64_decode(getUrlArg(strobfs, "protoparam")), "\\s", "");
|
protoparam = regReplace(urlsafe_base64_decode(getUrlArg(strobfs, "protoparam")), "\\s", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
ssr = regReplace(ssr, "(.*):(.*?):(.*?):(.*?):(.*?):(.*)", "$1|$2|$3|$4|$5|$6");
|
ssr = regReplace(ssr, "(.*):(.*?):(.*?):(.*?):(.*?):(.*)", "$1|$2|$3|$4|$5|$6");
|
||||||
strcfg = split(ssr, "|");
|
strcfg = split(ssr, "|");
|
||||||
|
|
||||||
@@ -513,6 +525,12 @@ void explodeSSR(std::string ssr, bool ss_libev, bool ssr_libev, const std::strin
|
|||||||
method = strcfg[3];
|
method = strcfg[3];
|
||||||
obfs = strcfg[4];
|
obfs = strcfg[4];
|
||||||
password = urlsafe_base64_decode(strcfg[5]);
|
password = urlsafe_base64_decode(strcfg[5]);
|
||||||
|
*/
|
||||||
|
if(regGetMatch(ssr, "(.*):(.*?):(.*?):(.*?):(.*?):(.*)", 7, NULL, &server, &port, &protocol, &method, &obfs, &password))
|
||||||
|
return;
|
||||||
|
password = urlsafe_base64_decode(password);
|
||||||
|
if(custom_port.size())
|
||||||
|
port = custom_port;
|
||||||
|
|
||||||
if(group.empty())
|
if(group.empty())
|
||||||
group = SSR_DEFAULT_GROUP;
|
group = SSR_DEFAULT_GROUP;
|
||||||
@@ -700,6 +718,7 @@ void explodeHTTPSub(std::string link, const std::string &custom_port, nodeInfo &
|
|||||||
link = urlsafe_base64_decode(link);
|
link = urlsafe_base64_decode(link);
|
||||||
if(strFind(link, "@"))
|
if(strFind(link, "@"))
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
link = regReplace(link, "(.*?):(.*?)@(.*):(.*)", "$1|$2|$3|$4");
|
link = regReplace(link, "(.*?):(.*?)@(.*):(.*)", "$1|$2|$3|$4");
|
||||||
configs = split(link, "|");
|
configs = split(link, "|");
|
||||||
if(configs.size() != 4)
|
if(configs.size() != 4)
|
||||||
@@ -708,15 +727,22 @@ void explodeHTTPSub(std::string link, const std::string &custom_port, nodeInfo &
|
|||||||
password = configs[1];
|
password = configs[1];
|
||||||
server = configs[2];
|
server = configs[2];
|
||||||
port = configs[3];
|
port = configs[3];
|
||||||
|
*/
|
||||||
|
if(regGetMatch(link, "(.*?):(.*?)@(.*):(.*)", 5, NULL, &username, &password, &server, &port))
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
link = regReplace(link, "(.*):(.*)", "$1|$2");
|
link = regReplace(link, "(.*):(.*)", "$1|$2");
|
||||||
configs = split(link, "|");
|
configs = split(link, "|");
|
||||||
if(configs.size() != 2)
|
if(configs.size() != 2)
|
||||||
return;
|
return;
|
||||||
server = configs[1];
|
server = configs[1];
|
||||||
port = configs[2];
|
port = configs[2];
|
||||||
|
*/
|
||||||
|
if(regGetMatch(link, "(.*):(.*)", 3, NULL, &server, &port))
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(group.empty())
|
if(group.empty())
|
||||||
@@ -753,6 +779,7 @@ void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo
|
|||||||
trojan.erase(pos);
|
trojan.erase(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
trojan = regReplace(trojan, "(.*?)@(.*):(.*)", "$1|$2|$3");
|
trojan = regReplace(trojan, "(.*?)@(.*):(.*)", "$1|$2|$3");
|
||||||
vArray = split(trojan, "|");
|
vArray = split(trojan, "|");
|
||||||
if(vArray.size() != 3)
|
if(vArray.size() != 3)
|
||||||
@@ -761,6 +788,11 @@ void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo
|
|||||||
psk = vArray[0];
|
psk = vArray[0];
|
||||||
server = vArray[1];
|
server = vArray[1];
|
||||||
port = custom_port.empty() ? vArray[2] : custom_port;
|
port = custom_port.empty() ? vArray[2] : custom_port;
|
||||||
|
*/
|
||||||
|
if(regGetMatch(trojan, "(.*?)@(.*):(.*)", 4, NULL, &psk, &server, &port))
|
||||||
|
return;
|
||||||
|
if(custom_port.size())
|
||||||
|
port = custom_port;
|
||||||
|
|
||||||
host = getUrlArg(addition, "peer");
|
host = getUrlArg(addition, "peer");
|
||||||
|
|
||||||
@@ -1148,6 +1180,7 @@ void explodeShadowrocket(std::string rocket, const std::string &custom_port, nod
|
|||||||
addition = rocket.substr(rocket.find("?") + 1);
|
addition = rocket.substr(rocket.find("?") + 1);
|
||||||
rocket = rocket.substr(0, rocket.find("?"));
|
rocket = rocket.substr(0, rocket.find("?"));
|
||||||
|
|
||||||
|
/*
|
||||||
userinfo = split(regReplace(urlsafe_base64_decode(rocket), "(.*?):(.*?)@(.*):(.*)", "$1,$2,$3,$4"), ",");
|
userinfo = split(regReplace(urlsafe_base64_decode(rocket), "(.*?):(.*?)@(.*):(.*)", "$1,$2,$3,$4"), ",");
|
||||||
if(userinfo.size() != 4) // broken link
|
if(userinfo.size() != 4) // broken link
|
||||||
return;
|
return;
|
||||||
@@ -1155,6 +1188,11 @@ void explodeShadowrocket(std::string rocket, const std::string &custom_port, nod
|
|||||||
id = userinfo[1];
|
id = userinfo[1];
|
||||||
add = userinfo[2];
|
add = userinfo[2];
|
||||||
port = custom_port.size() ? custom_port : userinfo[3];
|
port = custom_port.size() ? custom_port : userinfo[3];
|
||||||
|
*/
|
||||||
|
if(regGetMatch(urlsafe_base64_decode(rocket), "(.*?):(.*)@(.*):(.*)", 5, NULL, &cipher, &id, &add, &port))
|
||||||
|
return;
|
||||||
|
if(custom_port.size())
|
||||||
|
port = custom_port;
|
||||||
remarks = UrlDecode(getUrlArg(addition, "remark"));
|
remarks = UrlDecode(getUrlArg(addition, "remark"));
|
||||||
obfs = getUrlArg(addition, "obfs");
|
obfs = getUrlArg(addition, "obfs");
|
||||||
if(obfs.size())
|
if(obfs.size())
|
||||||
@@ -1208,20 +1246,21 @@ void explodeKitsunebi(std::string kit, const std::string &custom_port, nodeInfo
|
|||||||
addition = kit.substr(pos + 1);
|
addition = kit.substr(pos + 1);
|
||||||
kit = kit.substr(0, pos);
|
kit = kit.substr(0, pos);
|
||||||
|
|
||||||
|
/*
|
||||||
userinfo = split(regReplace(kit, "(.*?)@(.*):(.*)", "$1,$2,$3"), ",");
|
userinfo = split(regReplace(kit, "(.*?)@(.*):(.*)", "$1,$2,$3"), ",");
|
||||||
if(userinfo.size() != 3)
|
if(userinfo.size() != 3)
|
||||||
return;
|
return;
|
||||||
id = userinfo[0];
|
id = userinfo[0];
|
||||||
add = userinfo[1];
|
add = userinfo[1];
|
||||||
pos = userinfo[2].find("/");
|
pos = userinfo[2].find("/");
|
||||||
if(pos != userinfo[2].npos)
|
*/
|
||||||
|
if(regGetMatch(kit, "(.*?)@(.*):(.*)", 4, NULL, &id, &add, &port))
|
||||||
|
return;
|
||||||
|
pos = port.find("/");
|
||||||
|
if(pos != port.npos)
|
||||||
{
|
{
|
||||||
port = userinfo[2].substr(0, pos);
|
path = port.substr(pos);
|
||||||
path = userinfo[2].substr(pos);
|
port.erase(pos);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
port = userinfo[2];
|
|
||||||
}
|
}
|
||||||
if(custom_port.size())
|
if(custom_port.size())
|
||||||
port = custom_port;
|
port = custom_port;
|
||||||
@@ -1275,16 +1314,24 @@ bool explodeSurge(std::string surge, const std::string &custom_port, std::vector
|
|||||||
std::string plugin, pluginopts, pluginopts_mode, pluginopts_host = "cloudfront.net", mod_url, mod_md5; //ss
|
std::string plugin, pluginopts, pluginopts_mode, pluginopts_host = "cloudfront.net", mod_url, mod_md5; //ss
|
||||||
std::string id, net, tls, host, edge, path; //v2
|
std::string id, net, tls, host, edge, path; //v2
|
||||||
std::string protocol, protoparam; //ssr
|
std::string protocol, protoparam; //ssr
|
||||||
std::string itemName, itemVal;
|
std::string itemName, itemVal, config;
|
||||||
std::vector<std::string> configs, vArray, headers, header;
|
std::vector<std::string> configs, vArray, headers, header;
|
||||||
tribool udp, tfo, scv;
|
tribool udp, tfo, scv;
|
||||||
|
|
||||||
|
/*
|
||||||
remarks = regReplace(x.second, proxystr, "$1");
|
remarks = regReplace(x.second, proxystr, "$1");
|
||||||
configs = split(regReplace(x.second, proxystr, "$2"), ",");
|
configs = split(regReplace(x.second, proxystr, "$2"), ",");
|
||||||
if(configs.size() < 2 || configs[0] == "direct")
|
*/
|
||||||
|
regGetMatch(x.second, proxystr, 3, NULL, &remarks, &config);
|
||||||
|
configs = split(config, ",");
|
||||||
|
if(configs.size() < 2)
|
||||||
continue;
|
continue;
|
||||||
switch(hash_(configs[0]))
|
switch(hash_(configs[0]))
|
||||||
{
|
{
|
||||||
|
case "direct"_hash:
|
||||||
|
case "reject"_hash:
|
||||||
|
case "reject-tinygif"_hash:
|
||||||
|
continue;
|
||||||
case "custom"_hash: //surge 2 style custom proxy
|
case "custom"_hash: //surge 2 style custom proxy
|
||||||
//remove module detection to speed up parsing and compatible with broken module
|
//remove module detection to speed up parsing and compatible with broken module
|
||||||
/*
|
/*
|
||||||
@@ -2132,11 +2179,11 @@ time_t dateStringToTimestamp(std::string date)
|
|||||||
|
|
||||||
bool getSubInfoFromHeader(std::string &header, std::string &result)
|
bool getSubInfoFromHeader(std::string &header, std::string &result)
|
||||||
{
|
{
|
||||||
std::string pattern = R"((?:[\s\S]*?)^(?i:Subscription-UserInfo): (.*?)\s$(?:[\s\S]*))", retStr;
|
std::string pattern = R"(^(?i:Subscription-UserInfo): (.*?)\s*?$)", retStr;
|
||||||
if(regFind(header, pattern))
|
if(regFind(header, pattern))
|
||||||
{
|
{
|
||||||
retStr = regReplace(header, pattern, "$1");
|
regGetMatch(header, pattern, 2, NULL, &retStr);
|
||||||
if(retStr != header)
|
if(retStr.size())
|
||||||
{
|
{
|
||||||
result = retStr;
|
result = retStr;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -405,6 +405,7 @@ bool matchRange(std::string &range, int target)
|
|||||||
{
|
{
|
||||||
string_array vArray = split(range, ",");
|
string_array vArray = split(range, ",");
|
||||||
bool match = false;
|
bool match = false;
|
||||||
|
std::string range_begin_str, range_end_str;
|
||||||
int range_begin = 0, range_end = 0;
|
int range_begin = 0, range_end = 0;
|
||||||
const std::string reg_num = "-?\\d+", reg_range = "(\\d+)-(\\d+)", reg_not = "\\!(\\d+)", reg_not_range = "\\!(\\d+)-(\\d+)", reg_less = "(\\d+)-", reg_more = "(\\d+)\\+";
|
const std::string reg_num = "-?\\d+", reg_range = "(\\d+)-(\\d+)", reg_not = "\\!(\\d+)", reg_not_range = "\\!(\\d+)-(\\d+)", reg_less = "(\\d+)-", reg_more = "(\\d+)\\+";
|
||||||
for(std::string &x : vArray)
|
for(std::string &x : vArray)
|
||||||
@@ -416,8 +417,13 @@ bool matchRange(std::string &range, int target)
|
|||||||
}
|
}
|
||||||
else if(regMatch(x, reg_range))
|
else if(regMatch(x, reg_range))
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
range_begin = to_int(regReplace(x, reg_range, "$1"), INT_MAX);
|
range_begin = to_int(regReplace(x, reg_range, "$1"), INT_MAX);
|
||||||
range_end = to_int(regReplace(x, reg_range, "$2"), INT_MIN);
|
range_end = to_int(regReplace(x, reg_range, "$2"), INT_MIN);
|
||||||
|
*/
|
||||||
|
regGetMatch(x, reg_range, 3, NULL, &range_begin_str, &range_end_str);
|
||||||
|
range_begin = to_int(range_begin_str, INT_MAX);
|
||||||
|
range_end = to_int(range_end_str, INT_MIN);
|
||||||
if(target >= range_begin && target <= range_end)
|
if(target >= range_begin && target <= range_end)
|
||||||
match = true;
|
match = true;
|
||||||
}
|
}
|
||||||
@@ -428,8 +434,13 @@ bool matchRange(std::string &range, int target)
|
|||||||
}
|
}
|
||||||
else if(regMatch(x, reg_not_range))
|
else if(regMatch(x, reg_not_range))
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
range_begin = to_int(regReplace(x, reg_range, "$1"), INT_MAX);
|
range_begin = to_int(regReplace(x, reg_range, "$1"), INT_MAX);
|
||||||
range_end = to_int(regReplace(x, reg_range, "$2"), INT_MIN);
|
range_end = to_int(regReplace(x, reg_range, "$2"), INT_MIN);
|
||||||
|
*/
|
||||||
|
regGetMatch(x, reg_range, 3, NULL, &range_begin_str, &range_end_str);
|
||||||
|
range_begin = to_int(range_begin_str, INT_MAX);
|
||||||
|
range_end = to_int(range_end_str, INT_MIN);
|
||||||
if(target >= range_begin && target <= range_end)
|
if(target >= range_begin && target <= range_end)
|
||||||
match = false;
|
match = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user