Skip to content

Commit 3b4ad47

Browse files
committed
Bug fixes
Fix support for exporting SSD-Android compatible SSD subscriptions. Fix format error in exporting SIP002 subscriptions.
1 parent c38c1b4 commit 3b4ad47

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/misc.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,3 +935,33 @@ std::string getFormData(const std::string &raw_data)
935935
}
936936
return file;
937937
}
938+
939+
std::string UTF8ToCodePoint(std::string data)
940+
{
941+
std::stringstream ss;
942+
int charcode = 0;
943+
for(std::string::size_type i = 0; i < data.size(); i++)
944+
{
945+
charcode = data[i] & 0xff;
946+
if((charcode >> 7) == 0)
947+
{
948+
ss<<data[i];
949+
}
950+
else if((charcode >> 5) == 6)
951+
{
952+
ss<<"\\u"<<std::hex<<((data[i + 1] & 0x3f) | (data[i] & 0x1f) << 6);
953+
i++;
954+
}
955+
else if((charcode >> 4) == 14)
956+
{
957+
ss<<"\\u"<<std::hex<<((data[i + 2] & 0x3f) | (data[i + 1] & 0x3f) << 6 | (data[i] & 0xf) << 12);
958+
i += 2;
959+
}
960+
else if((charcode >> 3) == 30)
961+
{
962+
ss<<"\\u"<<std::hex<<((data[i + 3] & 0x3f) | (data[i + 2] & 0x3f) << 6 | (data[i + 1] & 0x3f) << 12 | (data[i] & 0x7) << 18);
963+
i += 3;
964+
}
965+
}
966+
return ss.str();
967+
}

src/misc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void removeUTF8BOM(std::string &data);
5353
int shortAssemble(unsigned short num_a, unsigned short num_b);
5454
void shortDisassemble(int source, unsigned short &num_a, unsigned short &num_b);
5555
int to_int(std::string &s, int def_vaule = 0);
56+
std::string UTF8ToCodePoint(std::string data);
5657

5758
std::string fileGet(std::string path, bool binary = true);
5859
int fileWrite(std::string path, std::string content, bool overwrite);

src/subexport.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ std::string netchToSS(std::vector<nodeInfo> &nodes, extra_settings &ext)
954954
switch(x.linkType)
955955
{
956956
case SPEEDTEST_MESSAGE_FOUNDSS:
957-
proxyStr = "ss://" + urlsafe_base64_encode(method + ":" + password + "@" + hostname + ":" + port);
957+
proxyStr = "ss://" + urlsafe_base64_encode(method + ":" + password) + "@" + hostname + ":" + port;
958958
if(plugin.size() && pluginopts.size())
959959
{
960960
proxyStr += "/?plugin=" + UrlEncode(plugin + ";" +pluginopts);
@@ -963,7 +963,7 @@ std::string netchToSS(std::vector<nodeInfo> &nodes, extra_settings &ext)
963963
break;
964964
case SPEEDTEST_MESSAGE_FOUNDSSR:
965965
if(std::count(ss_ciphers.begin(), ss_ciphers.end(), method) > 0 && protocol == "origin" && obfs == "plain")
966-
proxyStr = "ss://" + urlsafe_base64_encode(method + ":" + password + "@" + hostname + ":" + port) + "#" + UrlEncode(remark);
966+
proxyStr = "ss://" + urlsafe_base64_encode(method + ":" + password) + "@" + hostname + ":" + port + "#" + UrlEncode(remark);
967967
break;
968968
default:
969969
continue;
@@ -1317,7 +1317,7 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, extra_s
13171317
{
13181318
json.Parse(x.proxyStr.data());
13191319

1320-
remark = x.remarks;
1320+
remark = "\"" + replace_all_distinct(UTF8ToCodePoint(x.remarks), "\\u1f1", "\\ud83c\\udd") + "\"";
13211321
hostname = GetMember(json, "Hostname");
13221322
port = (unsigned short)stoi(GetMember(json, "Port"));
13231323
password = GetMember(json, "Password");
@@ -1348,7 +1348,7 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, extra_s
13481348
writer.Key("plugin_options");
13491349
writer.String(pluginopts.data());
13501350
writer.Key("remarks");
1351-
writer.String(remark.data());
1351+
writer.RawValue(remark.data(), remark.size(), rapidjson::Type::kStringType);
13521352
writer.Key("id");
13531353
writer.Int(index);
13541354
writer.EndObject();
@@ -1367,7 +1367,7 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, extra_s
13671367
writer.String(password.data());
13681368
writer.String(pluginopts.data());
13691369
writer.Key("remarks");
1370-
writer.String(remark.data());
1370+
writer.RawValue(remark.data(), remark.size(), rapidjson::Type::kStringType);
13711371
writer.Key("id");
13721372
writer.Int(index);
13731373
writer.EndObject();

0 commit comments

Comments
 (0)