mirror of
https://github.com/asdlokj1qpi233/subconverter.git
synced 2026-11-03 10:12:50 +00:00
Enhancements
Fix compatibility with some non-standard subscriptions. Fix group option not detected in Trojan links. Optimize codes.
This commit is contained in:
5 files changed
+24
-19
No files matched your search
+1
-4
@@ -87,10 +87,7 @@ std::string parseProxy(const std::string &source)
|
|||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define basic_types "DOMAIN", "DOMAIN-SUFFIX", "DOMAIN-KEYWORD", "IP-CIDR", "SRC-IP-CIDR", "GEOIP", "MATCH", "FINAL"
|
extern string_array clash_rule_type, surge_rule_type, quanx_rule_type;
|
||||||
const string_array clash_rule_type = {basic_types, "IP-CIDR6", "SRC-PORT", "DST-PORT"};
|
|
||||||
const string_array surge_rule_type = {basic_types, "IP-CIDR6", "USER-AGENT", "URL-REGEX", "AND", "OR", "NOT", "PROCESS-NAME", "IN-PORT", "DEST-PORT", "SRC-IP"};
|
|
||||||
const string_array quanx_rule_type = {basic_types, "USER-AGENT", "HOST", "HOST-SUFFIX", "HOST-KEYWORD"};
|
|
||||||
const std::map<std::string, ruleset_type> ruleset_types = {{"clash-domain:", RULESET_CLASH_DOMAIN}, {"clash-ipcidr:", RULESET_CLASH_IPCIDR}, {"clash-classic:", RULESET_CLASH_CLASSICAL}, \
|
const std::map<std::string, ruleset_type> ruleset_types = {{"clash-domain:", RULESET_CLASH_DOMAIN}, {"clash-ipcidr:", RULESET_CLASH_IPCIDR}, {"clash-classic:", RULESET_CLASH_CLASSICAL}, \
|
||||||
{"quanx:", RULESET_QUANX}, {"surge:", RULESET_SURGE}};
|
{"quanx:", RULESET_QUANX}, {"surge:", RULESET_SURGE}};
|
||||||
|
|
||||||
|
|||||||
+9
-4
@@ -198,7 +198,7 @@ std::string UrlDecode(const std::string& str)
|
|||||||
/*
|
/*
|
||||||
static inline bool is_base64(unsigned char c)
|
static inline bool is_base64(unsigned char c)
|
||||||
{
|
{
|
||||||
return (isalnum(c) || (c == '+') || (c == '/'));
|
return (isalnum(c) || (c == '+') || (c == '/') || (c == '-') || (c == '_'));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -280,7 +280,12 @@ std::string base64_decode(const std::string &encoded_string, bool accept_urlsafe
|
|||||||
{
|
{
|
||||||
uchar = encoded_string[in_]; // make compiler happy
|
uchar = encoded_string[in_]; // make compiler happy
|
||||||
if (!(accept_urlsafe ? itable[uchar] : (itable[uchar] == 1))) // break away from the while condition
|
if (!(accept_urlsafe ? itable[uchar] : (itable[uchar] == 1))) // break away from the while condition
|
||||||
|
{
|
||||||
|
ret += uchar; // not base64 encoded data, copy to result
|
||||||
|
in_++;
|
||||||
|
i = 0;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
char_array_4[i++] = uchar;
|
char_array_4[i++] = uchar;
|
||||||
in_++;
|
in_++;
|
||||||
if (i == 4)
|
if (i == 4)
|
||||||
@@ -696,10 +701,10 @@ bool regFind(const std::string &src, const std::string &match)
|
|||||||
return reg.match(src, "g");
|
return reg.match(src, "g");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string regReplace(const std::string &src, const std::string &match, const std::string &rep, bool global)
|
std::string regReplace(const std::string &src, const std::string &match, const std::string &rep, bool global, bool multiline)
|
||||||
{
|
{
|
||||||
jp::Regex reg;
|
jp::Regex reg;
|
||||||
reg.setPattern(match).addModifier("m").addPcre2Option(PCRE2_UTF|PCRE2_MULTILINE|PCRE2_ALT_BSUX).compile();
|
reg.setPattern(match).addModifier(multiline ? "m" : "").addPcre2Option(PCRE2_UTF|PCRE2_MULTILINE|PCRE2_ALT_BSUX).compile();
|
||||||
if(!reg)
|
if(!reg)
|
||||||
return src;
|
return src;
|
||||||
return reg.replace(src, rep, global ? "gx" : "x");
|
return reg.replace(src, rep, global ? "gx" : "x");
|
||||||
@@ -747,7 +752,7 @@ int regGetMatch(const std::string &src, const std::string &match, size_t group_c
|
|||||||
|
|
||||||
std::string regTrim(const std::string &src)
|
std::string regTrim(const std::string &src)
|
||||||
{
|
{
|
||||||
return regReplace(src, "^\\s*?([\\s\\S]*)\\s*$", "$1", false);
|
return regReplace(src, "^\\s*([\\s\\S]*)\\s*$", "$1", false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string speedCalc(double speed)
|
std::string speedCalc(double speed)
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ std::string getFormData(const std::string &raw_data);
|
|||||||
void sleep(int interval);
|
void sleep(int interval);
|
||||||
bool regValid(const std::string ®);
|
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, bool global = true);
|
std::string regReplace(const std::string &src, const std::string &match, const std::string &rep, bool global = true, bool multiline = true);
|
||||||
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, ...);
|
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);
|
||||||
|
|||||||
@@ -719,7 +719,7 @@ void explodeHTTPSub(std::string link, const std::string &custom_port, nodeInfo &
|
|||||||
|
|
||||||
void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo &node)
|
void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo &node)
|
||||||
{
|
{
|
||||||
std::string server, port, psk, addition, remark, host;
|
std::string server, port, psk, addition, group, remark, host;
|
||||||
tribool tfo, scv;
|
tribool tfo, scv;
|
||||||
trojan.erase(0, 9);
|
trojan.erase(0, 9);
|
||||||
string_size pos = trojan.rfind("#");
|
string_size pos = trojan.rfind("#");
|
||||||
@@ -746,18 +746,21 @@ void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo
|
|||||||
host = getUrlArg(addition, "peer");
|
host = getUrlArg(addition, "peer");
|
||||||
tfo = getUrlArg(addition, "tfo");
|
tfo = getUrlArg(addition, "tfo");
|
||||||
scv = getUrlArg(addition, "allowInsecure");
|
scv = getUrlArg(addition, "allowInsecure");
|
||||||
|
group = UrlDecode(getUrlArg(addition, "group"));
|
||||||
|
|
||||||
if(remark.empty())
|
if(remark.empty())
|
||||||
remark = server + ":" + port;
|
remark = server + ":" + port;
|
||||||
if(host.empty() && !isIPv4(server) && !isIPv6(server))
|
if(host.empty() && !isIPv4(server) && !isIPv6(server))
|
||||||
host = server;
|
host = server;
|
||||||
|
if(group.empty())
|
||||||
|
group = TROJAN_DEFAULT_GROUP;
|
||||||
|
|
||||||
node.linkType = SPEEDTEST_MESSAGE_FOUNDTROJAN;
|
node.linkType = SPEEDTEST_MESSAGE_FOUNDTROJAN;
|
||||||
node.group = TROJAN_DEFAULT_GROUP;
|
node.group = group;
|
||||||
node.remarks = remark;
|
node.remarks = remark;
|
||||||
node.server = server;
|
node.server = server;
|
||||||
node.port = to_int(port, 1);
|
node.port = to_int(port, 1);
|
||||||
node.proxyStr = trojanConstruct(node.group, remark, server, port, psk, host, true, tribool(), tfo, scv);
|
node.proxyStr = trojanConstruct(group, remark, server, port, psk, host, true, tribool(), tfo, scv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void explodeQuan(const std::string &quan, const std::string &custom_port, nodeInfo &node)
|
void explodeQuan(const std::string &quan, const std::string &custom_port, nodeInfo &node)
|
||||||
@@ -1140,7 +1143,7 @@ void explodeShadowrocket(std::string rocket, const std::string &custom_port, nod
|
|||||||
port = custom_port;
|
port = custom_port;
|
||||||
if(port == "0")
|
if(port == "0")
|
||||||
return;
|
return;
|
||||||
remarks = UrlDecode(getUrlArg(addition, "remark"));
|
remarks = UrlDecode(getUrlArg(addition, "remarks"));
|
||||||
obfs = getUrlArg(addition, "obfs");
|
obfs = getUrlArg(addition, "obfs");
|
||||||
if(obfs.size())
|
if(obfs.size())
|
||||||
{
|
{
|
||||||
@@ -1996,7 +1999,7 @@ void explodeSub(std::string sub, bool sslibev, bool ssrlibev, const std::string
|
|||||||
//try to parse as normal subscription
|
//try to parse as normal subscription
|
||||||
if(!processed)
|
if(!processed)
|
||||||
{
|
{
|
||||||
sub = urlsafe_base64_decode(trim(sub));
|
sub = urlsafe_base64_decode(sub);
|
||||||
if(regFind(sub, "(vmess|shadowsocks|http|trojan)\\s*?="))
|
if(regFind(sub, "(vmess|shadowsocks|http|trojan)\\s*?="))
|
||||||
{
|
{
|
||||||
if(explodeSurge(sub, custom_port, nodes, sslibev))
|
if(explodeSurge(sub, custom_port, nodes, sslibev))
|
||||||
|
|||||||
+5
-5
@@ -34,11 +34,11 @@ const string_array clash_ssr_ciphers = {"rc4-md5", "aes-128-ctr", "aes-192-ctr",
|
|||||||
|
|
||||||
/// rule type lists
|
/// rule type lists
|
||||||
#define basic_types "DOMAIN", "DOMAIN-SUFFIX", "DOMAIN-KEYWORD", "IP-CIDR", "SRC-IP-CIDR", "GEOIP", "MATCH", "FINAL"
|
#define basic_types "DOMAIN", "DOMAIN-SUFFIX", "DOMAIN-KEYWORD", "IP-CIDR", "SRC-IP-CIDR", "GEOIP", "MATCH", "FINAL"
|
||||||
const string_array clash_rule_type = {basic_types, "IP-CIDR6", "SRC-PORT", "DST-PORT"};
|
string_array clash_rule_type = {basic_types, "IP-CIDR6", "SRC-PORT", "DST-PORT"};
|
||||||
const string_array surge2_rule_type = {basic_types, "IP-CIDR6", "USER-AGENT", "URL-REGEX", "PROCESS-NAME", "IN-PORT", "DEST-PORT", "SRC-IP"};
|
string_array surge2_rule_type = {basic_types, "IP-CIDR6", "USER-AGENT", "URL-REGEX", "PROCESS-NAME", "IN-PORT", "DEST-PORT", "SRC-IP"};
|
||||||
const string_array surge_rule_type = {basic_types, "IP-CIDR6", "USER-AGENT", "URL-REGEX", "AND", "OR", "NOT", "PROCESS-NAME", "IN-PORT", "DEST-PORT", "SRC-IP"};
|
string_array surge_rule_type = {basic_types, "IP-CIDR6", "USER-AGENT", "URL-REGEX", "AND", "OR", "NOT", "PROCESS-NAME", "IN-PORT", "DEST-PORT", "SRC-IP"};
|
||||||
const string_array quanx_rule_type = {basic_types, "USER-AGENT", "HOST", "HOST-SUFFIX", "HOST-KEYWORD"};
|
string_array quanx_rule_type = {basic_types, "USER-AGENT", "HOST", "HOST-SUFFIX", "HOST-KEYWORD"};
|
||||||
const string_array surfb_rule_type = {basic_types, "IP-CIDR6", "PROCESS-NAME", "IN-PORT", "DEST-PORT", "SRC-IP"};
|
string_array surfb_rule_type = {basic_types, "IP-CIDR6", "PROCESS-NAME", "IN-PORT", "DEST-PORT", "SRC-IP"};
|
||||||
|
|
||||||
std::string hostnameToIPAddr(const std::string &host)
|
std::string hostnameToIPAddr(const std::string &host)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user