mirror of
https://github.com/2dust/v2rayN.git
synced 2025-05-15 20:58:07 +00:00
regex vmess url
This commit is contained in:
parent
e313e004eb
commit
4e8ea374d8
1 changed files with 41 additions and 28 deletions
|
@ -1199,7 +1199,7 @@ namespace v2rayN.Handler
|
||||||
int indexSplit = result.IndexOf("?");
|
int indexSplit = result.IndexOf("?");
|
||||||
if (indexSplit > 0)
|
if (indexSplit > 0)
|
||||||
{
|
{
|
||||||
vmessItem = ResolveVmess4Vmess(result) ?? ResolveVmess4Kitsunebi(result);
|
vmessItem = ResolveStdVmess(result) ?? ResolveVmess4Kitsunebi(result);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1469,52 +1469,63 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static VmessItem ResolveVmess4Vmess(string result)
|
private static readonly Regex StdVmessUserInfo = new Regex(
|
||||||
|
@"^(?<network>[a-z]+)(\+(?<streamSecurity>[a-z]+))?:(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})-(?<alterId>[0-9]+)$");
|
||||||
|
|
||||||
|
private static VmessItem ResolveStdVmess(string result)
|
||||||
{
|
{
|
||||||
VmessItem i = new VmessItem();
|
VmessItem i = new VmessItem
|
||||||
|
{
|
||||||
|
configType = (int)EConfigType.Vmess,
|
||||||
|
security = "auto"
|
||||||
|
};
|
||||||
|
|
||||||
Uri u = new Uri(result);
|
Uri u = new Uri(result);
|
||||||
|
|
||||||
var uinfo = u.UserInfo;
|
|
||||||
var uinfo12 = uinfo.Split(':');
|
|
||||||
if (uinfo12.Length != 2) return null;
|
|
||||||
var user = uinfo12[0];
|
|
||||||
var pass = uinfo12[1];
|
|
||||||
var passsp = pass.LastIndexOf('-');
|
|
||||||
var id = pass.Substring(0, passsp);
|
|
||||||
var aid = pass.Substring(passsp + 1);
|
|
||||||
i.address = u.IdnHost;
|
i.address = u.IdnHost;
|
||||||
i.port = u.Port;
|
i.port = u.Port;
|
||||||
i.id = id;
|
|
||||||
i.alterId = int.Parse(aid);
|
|
||||||
i.remarks = u.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);
|
i.remarks = u.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);
|
||||||
|
|
||||||
|
|
||||||
var query = u.Query;
|
|
||||||
|
|
||||||
var q = HttpUtility.ParseQueryString(u.Query);
|
var q = HttpUtility.ParseQueryString(u.Query);
|
||||||
|
|
||||||
if (user.EndsWith("+tls"))
|
var m = StdVmessUserInfo.Match(u.UserInfo);
|
||||||
|
if (!m.Success) return null;
|
||||||
|
|
||||||
|
i.id = m.Groups["id"].Value;
|
||||||
|
if (!int.TryParse(m.Groups["alterId"].Value, out int aid))
|
||||||
{
|
{
|
||||||
user = user.Split('+')[0];
|
return null;
|
||||||
i.streamSecurity = "tls";
|
|
||||||
// TODO tlsServerName
|
|
||||||
}
|
}
|
||||||
i.network = user;
|
i.alterId = aid;
|
||||||
switch (user)
|
|
||||||
|
if (m.Groups["streamSecurity"].Success)
|
||||||
|
{
|
||||||
|
i.streamSecurity = m.Groups["streamSecurity"].Value;
|
||||||
|
}
|
||||||
|
switch (i.streamSecurity)
|
||||||
|
{
|
||||||
|
case "tls":
|
||||||
|
// TODO tls config
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (!string.IsNullOrWhiteSpace(i.streamSecurity))
|
||||||
|
return null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
i.network = m.Groups["network"].Value;
|
||||||
|
switch (i.network)
|
||||||
{
|
{
|
||||||
case "tcp":
|
case "tcp":
|
||||||
string t1 = q["type"] ?? "none";
|
string t1 = q["type"] ?? "none";
|
||||||
i.headerType = t1;
|
i.headerType = t1;
|
||||||
// TODO t = http, parse http option
|
// TODO http option
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "kcp":
|
case "kcp":
|
||||||
string t2 = q["type"] ?? "none";
|
i.headerType = q["type"] ?? "none";
|
||||||
i.headerType = t2;
|
// TODO kcp seed
|
||||||
// TODO seed
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "ws":
|
case "ws":
|
||||||
string p1 = q["path"] ?? "/";
|
string p1 = q["path"] ?? "/";
|
||||||
string h1 = q["host"] ?? "";
|
string h1 = q["host"] ?? "";
|
||||||
|
@ -1539,6 +1550,8 @@ namespace v2rayN.Handler
|
||||||
i.path = k;
|
i.path = k;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
|
Loading…
Reference in a new issue