Skip to content

Commit

Permalink
Merge parser update from subconverter
Browse files Browse the repository at this point in the history
Update icon.
  • Loading branch information
tindy2013 committed Aug 20, 2020
1 parent ffbc4a5 commit 04853b8
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 13 deletions.
Binary file modified base/tools/gui/favicon.ico
Binary file not shown.
Binary file modified res/icon.ico
Binary file not shown.
83 changes: 70 additions & 13 deletions src/speedtestutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ void explodeVmess(std::string vmess, const std::string &custom_port, nodeInfo &n
std::string version, ps, add, port, type, id, aid, net, path, host, tls;
Document jsondata;
std::vector<std::string> vArray;
if(regMatch(vmess, "vmess://(.*?)\\?(.*)")) //shadowrocket style link
if(regMatch(vmess, "vmess://(.*?)@(.*)"))
{
explodeStdVMess(vmess, custom_port, node);
return;
}
else if(regMatch(vmess, "vmess://(.*?)\\?(.*)")) //shadowrocket style link
{
explodeShadowrocket(vmess, custom_port, node);
return;
Expand Down Expand Up @@ -569,25 +574,25 @@ void explodeSSRConf(std::string content, const std::string &custom_port, bool ss

for(unsigned int i = 0; i < json["configs"].Size(); i++)
{
json["configs"][i]["group"] >> group;
group = GetMember(json["configs"][i], "group");
if(group.empty())
group = SSR_DEFAULT_GROUP;
json["configs"][i]["remarks"] >> remarks;
json["configs"][i]["server"] >> server;
remarks = GetMember(json["configs"][i], "remarks");
server = GetMember(json["configs"][i], "server");
port = custom_port.size() ? custom_port : GetMember(json["configs"][i], "server_port");
if(port == "0")
continue;
if(remarks.empty())
remarks = server + ":" + port;

json["configs"][i]["remarks_base64"] >> remarks_base64;
json["configs"][i]["password"] >> password;
json["configs"][i]["method"] >> method;
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");

json["configs"][i]["protocol"] >> protocol;
json["configs"][i]["protocolparam"] >> protoparam;
json["configs"][i]["obfs"] >> obfs;
json["configs"][i]["obfsparam"] >> obfsparam;
protocol = GetMember(json["configs"][i], "protocol");
protoparam = GetMember(json["configs"][i], "protocolparam");
obfs = GetMember(json["configs"][i], "obfs");
obfsparam = GetMember(json["configs"][i], "obfsparam");

node.linkType = SPEEDTEST_MESSAGE_FOUNDSSR;
node.group = group;
Expand Down Expand Up @@ -1133,15 +1138,67 @@ void explodeClash(Node yamlnode, const std::string &custom_port, std::vector<nod
return;
}

void explodeStdVMess(std::string vmess, const std::string &custom_port, nodeInfo &node)
{
std::string add, port, type, id, aid, net, path, host, tls, remarks;
std::string addition;
vmess = vmess.substr(8);
string_size pos;

pos = vmess.rfind("#");
if(pos != vmess.npos)
{
remarks = UrlDecode(vmess.substr(pos + 1));
vmess.erase(pos);
}
const std::string stdvmess_matcher = R"(^([a-z]+)(?:\+([a-z]+))?:([\da-f]{4}(?:[\da-f]{4}-){4}[\da-f]{12})-(\d+)@(.+):(\d+)(?:\/?\?(.*))?$)";
if(regGetMatch(vmess, stdvmess_matcher, 8, 0, &net, &tls, &id, &aid, &add, &port, &addition))
return;

switch(hash_(net))
{
case "tcp"_hash:
case "kcp"_hash:
type = getUrlArg(addition, "type");
break;
case "http"_hash:
case "ws"_hash:
host = getUrlArg(addition, "host");
path = getUrlArg(addition, "path");
break;
case "quic"_hash:
type = getUrlArg(addition, "security");
host = getUrlArg(addition, "type");
path = getUrlArg(addition, "key");
break;
default:
return;
}

if(!custom_port.empty())
port = custom_port;
if(remarks.empty())
remarks = add + ":" + port;

node.linkType = SPEEDTEST_MESSAGE_FOUNDVMESS;
node.group = V2RAY_DEFAULT_GROUP;
node.remarks = remarks;
node.server = add;
node.port = to_int(port, 0);
node.proxyStr = vmessConstruct(node.group, remarks, add, port, type, id, aid, net, "auto", path, host, "", tls);
return;
}

void explodeShadowrocket(std::string rocket, const std::string &custom_port, nodeInfo &node)
{
std::string add, port, type, id, aid, net = "tcp", path, host, tls, cipher, remarks;
std::string obfs; //for other style of link
std::string addition;
rocket = rocket.substr(8);

addition = rocket.substr(rocket.find("?") + 1);
rocket = rocket.substr(0, rocket.find("?"));
string_size pos = rocket.find("?");
addition = rocket.substr(pos + 1);
rocket.erase(pos);

if(regGetMatch(urlsafe_base64_decode(rocket), "(.*?):(.*)@(.*):(.*)", 5, 0, &cipher, &id, &add, &port))
return;
Expand Down
1 change: 1 addition & 0 deletions src/speedtestutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void explodeSSR(std::string ssr, bool ss_libev, bool libev, const std::string &c
void explodeSS(std::string ss, bool libev, const std::string &custom_port, nodeInfo &node);
void explodeTrojan(std::string trojan, const std::string &custom_port, nodeInfo &node);
void explodeQuan(const std::string &quan, const std::string &custom_port, nodeInfo &node);
void explodeStdVMess(std::string vmess, const std::string &custom_port, nodeInfo &node);
void explodeShadowrocket(std::string kit, const std::string &custom_port, nodeInfo &node);
void explodeKitsunebi(std::string kit, const std::string &custom_port, nodeInfo &node);
/// Parse a link
Expand Down

0 comments on commit 04853b8

Please sign in to comment.