Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/parser/subparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3222,7 +3222,10 @@ void explodeSub(std::string sub, std::vector<Proxy> &nodes)
//try to parse as normal subscription
if(!processed)
{
sub = urlSafeBase64Decode(sub);
if(isBase64(sub))
{
sub = urlSafeBase64Decode(sub);
}
if(regFind(sub, "(vmess|shadowsocks|http|trojan)\\s*?="))
{
if(explodeSurge(sub, nodes))
Expand Down
21 changes: 21 additions & 0 deletions src/utils/base64/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,24 @@ std::string urlSafeBase64Encode(const std::string &string_to_encode)
{
return urlSafeBase64Apply(base64Encode(string_to_encode));
}
bool isBase64(const std::string &string_to_check)
{
if (string_to_check.empty())
return false;

string_size len = string_to_check.size();
if (len % 4 != 0)
return false;

for (string_size i = 0; i < len; i++)
{
unsigned char c = string_to_check[i];
if (base64_chars.find(c) == std::string::npos && c != '=')
return false;

if (c == '=' && i < len - 2)
return false;
}

return true;
}
2 changes: 2 additions & 0 deletions src/utils/base64/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ std::string urlSafeBase64Reverse(const std::string &encoded_string);
std::string urlSafeBase64Decode(const std::string &encoded_string);
std::string urlSafeBase64Encode(const std::string &string_to_encode);

bool isBase64(const std::string &string_to_check);

#endif // BASE64_H_INCLUDED