From f18758d4bf4e4b2c4b0080ec5aa61910787e3a17 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 20 May 2026 14:28:01 +0800 Subject: [PATCH] Support socks4/5 URIs and improve userinfo parsing --- v2rayN/ServiceLib/Global.cs | 4 ++++ v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs | 7 +++++-- v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs | 15 ++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 0f28daa9..4b880e7e 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -207,6 +207,10 @@ public class Global public const string NaiveQuicProtocolShare = "naive+quic://"; + public const string SOCKS5Protocol = "socks5://"; + + public const string SOCKS4Protocol = "socks4://"; + public static readonly Dictionary ProtocolShares = new() { { EConfigType.VMess, "vmess://" }, diff --git a/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs b/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs index 611e5159..7691d874 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/FmtHandler.cs @@ -53,7 +53,9 @@ public class FmtHandler { return ShadowsocksFmt.Resolve(str, out msg); } - else if (str.StartsWith(Global.ProtocolShares[EConfigType.SOCKS])) + else if (str.StartsWith(Global.ProtocolShares[EConfigType.SOCKS]) + || str.StartsWith(Global.SOCKS5Protocol) + || str.StartsWith(Global.SOCKS4Protocol)) { return SocksFmt.Resolve(str, out msg); } @@ -65,7 +67,8 @@ public class FmtHandler { return VLESSFmt.Resolve(str, out msg); } - else if (str.StartsWith(Global.ProtocolShares[EConfigType.Hysteria2]) || str.StartsWith(Global.Hysteria2ProtocolShare)) + else if (str.StartsWith(Global.ProtocolShares[EConfigType.Hysteria2]) + || str.StartsWith(Global.Hysteria2ProtocolShare)) { return Hysteria2Fmt.Resolve(str, out msg); } diff --git a/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs b/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs index b3a54301..62b36e07 100644 --- a/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs +++ b/v2rayN/ServiceLib/Handler/Fmt/SocksFmt.cs @@ -99,12 +99,17 @@ public class SocksFmt : BaseFmt }; // parse base64 UserInfo var rawUserInfo = Utils.UrlDecode(parsedUrl.UserInfo); - var userInfo = Utils.Base64Decode(rawUserInfo); - var userInfoParts = userInfo.Split([':'], 2); - if (userInfoParts.Length == 2) + if (rawUserInfo.IsNotEmpty()) { - item.Username = userInfoParts.First(); - item.Password = userInfoParts[1]; + var userInfoParts = rawUserInfo.Contains(':') + ? rawUserInfo.Split(":", 2) + : Utils.Base64Decode(rawUserInfo).Split(":", 2); + + if (userInfoParts.Length == 2) + { + item.Username = userInfoParts.First(); + item.Password = userInfoParts.Last(); + } } return item;