Skip to content

Commit 3885ff8

Browse files
authored
Fix Shadowsocks Fmt (2dust#8462)
1 parent 12abf38 commit 3885ff8

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

v2rayN/ServiceLib/Handler/Fmt/ShadowsocksFmt.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ public class ShadowsocksFmt : BaseFmt
5757
{
5858
pluginArgs += "mode=websocket;";
5959
pluginArgs += $"host={item.RequestHost};";
60-
pluginArgs += $"path={item.Path};";
60+
// https://github.com/shadowsocks/v2ray-plugin/blob/e9af1cdd2549d528deb20a4ab8d61c5fbe51f306/args.go#L172
61+
// Equal signs and commas [and backslashes] must be escaped with a backslash.
62+
var path = item.Path.Replace("\\", "\\\\").Replace("=", "\\=").Replace(",", "\\,");
63+
pluginArgs += $"path={path};";
6164
}
6265
else if (item.Network == nameof(ETransport.quic))
6366
{
@@ -75,8 +78,6 @@ public class ShadowsocksFmt : BaseFmt
7578

7679
var base64Content = cert.Replace(beginMarker, "").Replace(endMarker, "").Trim();
7780

78-
// https://github.com/shadowsocks/v2ray-plugin/blob/e9af1cdd2549d528deb20a4ab8d61c5fbe51f306/args.go#L172
79-
// Equal signs and commas [and backslashes] must be escaped with a backslash.
8081
base64Content = base64Content.Replace("=", "\\=");
8182

8283
pluginArgs += $"certRaw={base64Content};";
@@ -85,6 +86,7 @@ public class ShadowsocksFmt : BaseFmt
8586
if (pluginArgs.Length > 0)
8687
{
8788
plugin = "v2ray-plugin";
89+
pluginArgs += "mux=0;";
8890
}
8991
}
9092

@@ -222,6 +224,7 @@ public class ShadowsocksFmt : BaseFmt
222224
var path = pluginParts.FirstOrDefault(t => t.StartsWith("path="));
223225
var hasTls = pluginParts.Any(t => t == "tls");
224226
var certRaw = pluginParts.FirstOrDefault(t => t.StartsWith("certRaw="));
227+
var mux = pluginParts.FirstOrDefault(t => t.StartsWith("mux="));
225228

226229
var modeValue = mode.Replace("mode=", "");
227230
if (modeValue == "websocket")
@@ -234,7 +237,9 @@ public class ShadowsocksFmt : BaseFmt
234237
}
235238
if (!path.IsNullOrEmpty())
236239
{
237-
item.Path = path.Replace("path=", "");
240+
var pathValue = path.Replace("path=", "");
241+
pathValue = pathValue.Replace("\\=", "=").Replace("\\,", ",").Replace("\\\\", "\\");
242+
item.Path = pathValue;
238243
}
239244
}
240245
else if (modeValue == "quic")
@@ -258,6 +263,16 @@ public class ShadowsocksFmt : BaseFmt
258263
item.Cert = certPem;
259264
}
260265
}
266+
267+
if (!mux.IsNullOrEmpty())
268+
{
269+
var muxValue = mux.Replace("mux=", "");
270+
var muxCount = muxValue.ToInt();
271+
if (muxCount > 0)
272+
{
273+
return null;
274+
}
275+
}
261276
}
262277
}
263278

v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxOutboundService.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ private async Task<int> GenOutbound(ProfileItem node, Outbound4Sbox outbound)
4646
{
4747
pluginArgs += "mode=websocket;";
4848
pluginArgs += $"host={node.RequestHost};";
49-
pluginArgs += $"path={node.Path};";
49+
// https://github.com/shadowsocks/v2ray-plugin/blob/e9af1cdd2549d528deb20a4ab8d61c5fbe51f306/args.go#L172
50+
// Equal signs and commas [and backslashes] must be escaped with a backslash.
51+
var path = node.Path.Replace("\\", "\\\\").Replace("=", "\\=").Replace(",", "\\,");
52+
pluginArgs += $"path={path};";
5053
}
5154
else if (node.Network == nameof(ETransport.quic))
5255
{
@@ -64,8 +67,6 @@ private async Task<int> GenOutbound(ProfileItem node, Outbound4Sbox outbound)
6467

6568
var base64Content = cert.Replace(beginMarker, "").Replace(endMarker, "").Trim();
6669

67-
// https://github.com/shadowsocks/v2ray-plugin/blob/e9af1cdd2549d528deb20a4ab8d61c5fbe51f306/args.go#L172
68-
// Equal signs and commas [and backslashes] must be escaped with a backslash.
6970
base64Content = base64Content.Replace("=", "\\=");
7071

7172
pluginArgs += $"certRaw={base64Content};";
@@ -74,6 +75,9 @@ private async Task<int> GenOutbound(ProfileItem node, Outbound4Sbox outbound)
7475
if (pluginArgs.Length > 0)
7576
{
7677
outbound.plugin = "v2ray-plugin";
78+
pluginArgs += "mux=0;";
79+
// pluginStr remove last ';'
80+
pluginArgs = pluginArgs[..^1];
7781
outbound.plugin_opts = pluginArgs;
7882
}
7983
}

0 commit comments

Comments
 (0)