From 701032bb4f2da9aa4bf76f4b2db4a68071c96b1c Mon Sep 17 00:00:00 2001 From: database64128 Date: Fri, 30 Oct 2020 19:01:11 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=8E=83=20PAC:=20direct=20connection?= =?UTF-8?q?=20for=20private=20IP=20ranges=20by=20@studentmain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shadowsocks-csharp/Data/abp.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/shadowsocks-csharp/Data/abp.js b/shadowsocks-csharp/Data/abp.js index 432a6385..7dd0246c 100644 --- a/shadowsocks-csharp/Data/abp.js +++ b/shadowsocks-csharp/Data/abp.js @@ -793,7 +793,22 @@ for (var i = 0; i < rules.length; i++) { defaultMatcher.add(Filter.fromText(rules[i])); } +// PAC has no v6 support, it sucks +var ip4Re = /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/ + +var privateNet = [ + ["10.0.0.0", "255.0.0.0"], + ["127.0.0.0", "255.0.0.0"], + ["172.16.0.0", "255.240.0.0"], + ["192.168.0.0", "255.255.0.0"], +] + function FindProxyForURL(url, host) { + if (host.match(ip4Re)) { + for (var i = 0; i < privateNet.length; i++) { + if (isInNet(host, privateNet[i][0], privateNet[i][1])) return direct; + } + } if (userrulesMatcher.matchesAny(url, host) instanceof BlockingFilter) { return proxy; } From 344c95e52c23f899f0f862e29917729d1cb0d57f Mon Sep 17 00:00:00 2001 From: ahmadali shafiee Date: Sun, 1 Nov 2020 09:44:54 +0330 Subject: [PATCH 2/9] remove duplicate startup entries fixes #3011 Signed-off-by: ahmadali shafiee --- shadowsocks-csharp/Controller/System/AutoStartup.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/shadowsocks-csharp/Controller/System/AutoStartup.cs b/shadowsocks-csharp/Controller/System/AutoStartup.cs index 97127b66..a25169d1 100644 --- a/shadowsocks-csharp/Controller/System/AutoStartup.cs +++ b/shadowsocks-csharp/Controller/System/AutoStartup.cs @@ -14,7 +14,7 @@ namespace Shadowsocks.Controller // Don't use Application.ExecutablePath // see https://stackoverflow.com/questions/12945805/odd-c-sharp-path-issue - + private static string Key = "Shadowsocks_" + Program.ExecutablePath.GetHashCode(); public static bool Set(bool enabled) @@ -28,6 +28,17 @@ namespace Shadowsocks.Controller logger.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); return false; } + // Remove other startup keys with the same executable path. fixes #3011 + foreach (var valueName in runKey.GetValueNames()) + { + if (valueName == Key) + continue; + + if (string.Equals(runKey.GetValue(valueName).ToString(), Program.ExecutablePath, StringComparison.InvariantCultureIgnoreCase)) + { + runKey.DeleteValue(valueName); + } + } if (enabled) { runKey.SetValue(Key, Program.ExecutablePath); From 753d7709d5fbd6767a5d659aae0658ec0ae05076 Mon Sep 17 00:00:00 2001 From: ahmadali shafiee Date: Mon, 2 Nov 2020 11:08:54 +0330 Subject: [PATCH 3/9] move duplicate key checking to `Check` method Signed-off-by: ahmadali shafiee --- .../Controller/System/AutoStartup.cs | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/shadowsocks-csharp/Controller/System/AutoStartup.cs b/shadowsocks-csharp/Controller/System/AutoStartup.cs index a25169d1..8e89fc8e 100644 --- a/shadowsocks-csharp/Controller/System/AutoStartup.cs +++ b/shadowsocks-csharp/Controller/System/AutoStartup.cs @@ -28,17 +28,6 @@ namespace Shadowsocks.Controller logger.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); return false; } - // Remove other startup keys with the same executable path. fixes #3011 - foreach (var valueName in runKey.GetValueNames()) - { - if (valueName == Key) - continue; - - if (string.Equals(runKey.GetValue(valueName).ToString(), Program.ExecutablePath, StringComparison.InvariantCultureIgnoreCase)) - { - runKey.DeleteValue(valueName); - } - } if (enabled) { runKey.SetValue(Key, Program.ExecutablePath); @@ -82,21 +71,21 @@ namespace Shadowsocks.Controller logger.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); return false; } - string[] runList = runKey.GetValueNames(); - foreach (string item in runList) + // Remove other startup keys with the same executable path. fixes #3011 and also assures compatibility with older versions + foreach (var valueName in runKey.GetValueNames()) + { + if (valueName == Key) + continue; + + if (string.Equals(runKey.GetValue(valueName).ToString(), Program.ExecutablePath, StringComparison.InvariantCultureIgnoreCase)) + { + runKey.DeleteValue(valueName); + } + } + foreach (string item in runKey.GetValueNames()) { if (item.Equals(Key, StringComparison.OrdinalIgnoreCase)) return true; - else if (item.Equals("Shadowsocks", StringComparison.OrdinalIgnoreCase)) // Compatibility with older versions - { - string value = Convert.ToString(runKey.GetValue(item)); - if (Program.ExecutablePath.Equals(value, StringComparison.OrdinalIgnoreCase)) - { - runKey.DeleteValue(item); - runKey.SetValue(Key, Program.ExecutablePath); - return true; - } - } } return false; } From 96650a1f6c5e17e1d7914f41f304995ba81c8927 Mon Sep 17 00:00:00 2001 From: ahmadali shafiee Date: Mon, 2 Nov 2020 11:12:13 +0330 Subject: [PATCH 4/9] combine foreaches Signed-off-by: ahmadali shafiee --- .../Controller/System/AutoStartup.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/shadowsocks-csharp/Controller/System/AutoStartup.cs b/shadowsocks-csharp/Controller/System/AutoStartup.cs index 8e89fc8e..557b8a3f 100644 --- a/shadowsocks-csharp/Controller/System/AutoStartup.cs +++ b/shadowsocks-csharp/Controller/System/AutoStartup.cs @@ -71,23 +71,22 @@ namespace Shadowsocks.Controller logger.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); return false; } - // Remove other startup keys with the same executable path. fixes #3011 and also assures compatibility with older versions + var check = false; foreach (var valueName in runKey.GetValueNames()) { - if (valueName == Key) + if (string.Equals(valueName, Key, StringComparison.InvariantCultureIgnoreCase)) + { + check = true; continue; + } + // Remove other startup keys with the same executable path. fixes #3011 and also assures compatibility with older versions if (string.Equals(runKey.GetValue(valueName).ToString(), Program.ExecutablePath, StringComparison.InvariantCultureIgnoreCase)) { runKey.DeleteValue(valueName); } } - foreach (string item in runKey.GetValueNames()) - { - if (item.Equals(Key, StringComparison.OrdinalIgnoreCase)) - return true; - } - return false; + return check; } catch (Exception e) { From 8b6088d4a19953b1f2fb5de36564acf62e8e7093 Mon Sep 17 00:00:00 2001 From: ahmadali shafiee Date: Mon, 2 Nov 2020 11:38:42 +0330 Subject: [PATCH 5/9] create proper key if different key exists on registry Signed-off-by: ahmadali shafiee --- shadowsocks-csharp/Controller/System/AutoStartup.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shadowsocks-csharp/Controller/System/AutoStartup.cs b/shadowsocks-csharp/Controller/System/AutoStartup.cs index 557b8a3f..853e7a36 100644 --- a/shadowsocks-csharp/Controller/System/AutoStartup.cs +++ b/shadowsocks-csharp/Controller/System/AutoStartup.cs @@ -84,6 +84,8 @@ namespace Shadowsocks.Controller if (string.Equals(runKey.GetValue(valueName).ToString(), Program.ExecutablePath, StringComparison.InvariantCultureIgnoreCase)) { runKey.DeleteValue(valueName); + runKey.SetValue(Key, Program.ExecutablePath); + check = true; } } return check; From 0f08d0882a530c398f1137ca26f972c7d6f99c85 Mon Sep 17 00:00:00 2001 From: ahmadali shafiee Date: Mon, 2 Nov 2020 11:43:04 +0330 Subject: [PATCH 6/9] fix coding style Signed-off-by: ahmadali shafiee --- shadowsocks-csharp/Controller/System/AutoStartup.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/Controller/System/AutoStartup.cs b/shadowsocks-csharp/Controller/System/AutoStartup.cs index 853e7a36..d7e92580 100644 --- a/shadowsocks-csharp/Controller/System/AutoStartup.cs +++ b/shadowsocks-csharp/Controller/System/AutoStartup.cs @@ -74,14 +74,14 @@ namespace Shadowsocks.Controller var check = false; foreach (var valueName in runKey.GetValueNames()) { - if (string.Equals(valueName, Key, StringComparison.InvariantCultureIgnoreCase)) + if (valueName.Equals(Key, StringComparison.InvariantCultureIgnoreCase)) { check = true; continue; } // Remove other startup keys with the same executable path. fixes #3011 and also assures compatibility with older versions - if (string.Equals(runKey.GetValue(valueName).ToString(), Program.ExecutablePath, StringComparison.InvariantCultureIgnoreCase)) + if (Program.ExecutablePath.Equals(runKey.GetValue(valueName).ToString(), StringComparison.InvariantCultureIgnoreCase)) { runKey.DeleteValue(valueName); runKey.SetValue(Key, Program.ExecutablePath); From b2dd2d97dd178401f185250aab22963afca41a01 Mon Sep 17 00:00:00 2001 From: database64128 Date: Thu, 5 Nov 2020 15:09:34 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=94=A0=20No=20case=20conversion=20for?= =?UTF-8?q?=20SIP003=20environment=20variables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Corrects the mistake in 127cb96 and fixes #3013 --- shadowsocks-csharp/Controller/Service/Sip003Plugin.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shadowsocks-csharp/Controller/Service/Sip003Plugin.cs b/shadowsocks-csharp/Controller/Service/Sip003Plugin.cs index 7024c648..c955c7b9 100644 --- a/shadowsocks-csharp/Controller/Service/Sip003Plugin.cs +++ b/shadowsocks-csharp/Controller/Service/Sip003Plugin.cs @@ -122,13 +122,12 @@ namespace Shadowsocks.Controller.Service public string ExpandEnvironmentVariables(string name, StringDictionary environmentVariables = null) { - name = name.ToLower(); // Expand the environment variables from the new process itself if (environmentVariables != null) { foreach(string key in environmentVariables.Keys) { - name = name.Replace($"%{key.ToLower()}%", environmentVariables[key]); + name = name.Replace($"%{key}%", environmentVariables[key]); } } // Also expand the environment variables from current main process (system) From afb415c33cafca32b2b8609a91de8d73c61d6c3d Mon Sep 17 00:00:00 2001 From: database64128 Date: Thu, 5 Nov 2020 15:11:05 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=8F=A0=20Include=20`geosite:private`?= =?UTF-8?q?=20in=20`geositeDirectGroups`=20by=20default?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Also adds it for users upgrading from older versions --- shadowsocks-csharp/Controller/ShadowsocksController.cs | 4 ++++ shadowsocks-csharp/Model/Configuration.cs | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 372b923b..b770ede1 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -101,6 +101,10 @@ namespace Shadowsocks.Controller ProgramUpdated += (o, e) => { + // version update precedures + if (e.OldVersion == "4.3.0.0" || e.OldVersion == "4.3.1.0") + _config.geositeDirectGroups.Add("private"); + logger.Info($"Updated from {e.OldVersion} to {e.NewVersion}"); }; } diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index b955e0f7..9e4cabda 100644 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -86,12 +86,13 @@ namespace Shadowsocks.Model geositeUrl = ""; geositeDirectGroups = new List() { + "private", "cn", - "geolocation-!cn@cn" + "geolocation-!cn@cn", }; geositeProxiedGroups = new List() { - "geolocation-!cn" + "geolocation-!cn", }; geositePreferDirect = false; userAgent = "ShadowsocksWindows/$version"; @@ -308,6 +309,7 @@ namespace Shadowsocks.Model public static void ResetGeositeDirectGroup(ref List geositeDirectGroups) { geositeDirectGroups.Clear(); + geositeDirectGroups.Add("private"); geositeDirectGroups.Add("cn"); geositeDirectGroups.Add("geolocation-!cn@cn"); } From a7eb33ae93425a3ee6e667968327356aa395243a Mon Sep 17 00:00:00 2001 From: database64128 Date: Thu, 5 Nov 2020 15:11:37 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=86=99=20Update=20docs=20and=20bump?= =?UTF-8?q?=20version=20to=204.3.2.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES | 5 +++++ appveyor.yml | 2 +- shadowsocks-csharp/Controller/Service/UpdateChecker.cs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 59a3741b..da1a63be 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +4.3.2.0 2020-11-05 +- PAC: direct connection for private IP ranges by @studentmain (#3008) +- Remove duplicate startup entries (#3012) +- Other minor bug fixes and improvements + 4.3.1.0 2020-10-25 - Update abp.js (#2999) - Separate QR code scanning from MenuViewController (#2995) diff --git a/appveyor.yml b/appveyor.yml index dca480c5..f7c8fbf6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,7 +11,7 @@ # version format # Build version format is taken from UI if it is not set -version: 4.3.1.{build} +version: 4.3.2.{build} # # branches to build # branches: diff --git a/shadowsocks-csharp/Controller/Service/UpdateChecker.cs b/shadowsocks-csharp/Controller/Service/UpdateChecker.cs index 9cdac0de..bc00dde1 100644 --- a/shadowsocks-csharp/Controller/Service/UpdateChecker.cs +++ b/shadowsocks-csharp/Controller/Service/UpdateChecker.cs @@ -33,7 +33,7 @@ namespace Shadowsocks.Controller public event EventHandler CheckUpdateCompleted; - public const string Version = "4.3.1.0"; + public const string Version = "4.3.2.0"; private readonly Version _version; public UpdateChecker()