Compare commits

...
21 Commits
Author SHA1 Message Date
noisyfox 24db6438bd Update CHANGES and bump version 2016-11-07 16:52:28 +11:00
noisyfox c908caa584 Use OpenRegKey 2016-11-06 01:25:22 +11:00
noisyfox a16e80743c Open .net download page automatically 2016-11-06 00:59:03 +11:00
noisyfox aa9fd8ec06 Check .NET Framework version on startup 2016-11-05 23:23:04 +11:00
noisyfox 02124ff3ad Update README.md 2016-11-05 22:07:17 +11:00
Noisyfox eec899b9a3 Merge pull request #847 from celeron533/master
Update README.md
2016-11-04 22:08:18 +11:00
Noisyfox 1979131e12 Merge pull request #857 from wongsyrone/master
Minor update
2016-11-04 21:51:38 +11:00
celeron533 c09af5fe0f Update README.md 2016-10-31 12:30:41 +08:00
Syrone Wong 816e2b351d Update mbed TLS to 2.4.0
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-29 22:47:58 +08:00
Syrone Wong 217e818339 Cleanup
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-26 16:50:28 +08:00
Syrone Wong f06f6f2fbb Refine power mode handling
- enlarge timeout to 10 seconds
- detach event handler before exiting
- output log if success

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-24 08:27:49 +08:00
Syrone Wong 89b7043a4e Update CHANGES and bump version
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-21 09:57:08 +08:00
Syrone Wong 9c438ee745 Misc
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-21 08:17:28 +08:00
Syrone Wong ce26bc15a9 Refine random generator handling
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-20 08:15:47 +08:00
Syrone Wong 4b99a5c210 Make registry opening more generic
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-20 08:05:25 +08:00
Syrone Wong 5721769c6d Refine Remote Access Service query for WinVista and later
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-16 16:43:11 +08:00
Syrone Wong 1c1cc62235 System proxy support for Remote Access Service
e.g. Dial-up connection and VPN

- use INTERNET_OPTION_PROXY_SETTINGS_CHANGED instead of INTERNET_OPTION_SETTINGS_CHANGED

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-16 12:36:12 +08:00
Jiangzhuo 3fe8484b8b Fix link to GFWList (#793)
Thanks to @jiangzhuo
2016-10-14 19:46:20 +08:00
Syrone Wong 131114f0c2 Fix #779
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-12 09:36:17 +08:00
Syrone Wong 74ad98d9ce Distinguish unhandled error type
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-12 07:40:42 +08:00
Syrone Wong 90ae73057e Misc
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
2016-10-11 17:00:19 +08:00
18 changed files with 347 additions and 93 deletions
+10
View File
@@ -1,3 +1,13 @@
3.3.5 2016-11-7
- Improve system power mode handling
- Update mbed TLS to 2.4.0
- Check .NET Framework version on startup
3.3.4 2016-10-21
- Fix IE dial-up and VPN connection proxy settings
not changed since release 3.3.3.
- Fix a UI bug
3.3.3 2016-10-10
- Add timeout support for server and forward proxy,
only integer is allowed
+6 -4
View File
@@ -32,7 +32,7 @@ port in `Servers -> Edit Servers`
1. You can change PAC rules by editing the PAC file. When you save the PAC file
with any editor, Shadowsocks will notify browsers about the change automatically
2. You can also update PAC file from [GFWList] (maintained by 3rd party)
2. You can also update PAC file from [GFWList] \(maintained by 3rd party)
3. You can also use online PAC URL
#### Server Auto Switching
@@ -96,16 +96,18 @@ system temp folder, create a `shadowsocks_portable_mode.txt` into shadowsocks fo
#### Develop
Visual Studio 2015 is required.
[Visual Studio 2015] & [.NET Framework 4.6.2 Developer Pack] are required.
#### License
GPLv3
[Appveyor]: https://ci.appveyor.com/project/wongsyrone/shadowsocks-windows-0cn3i
[Build Status]: https://ci.appveyor.com/api/projects/status/47784ryn365vw56w/branch/master?svg=true
[Appveyor]: https://ci.appveyor.com/project/Noisyfox/shadowsocks-windows
[Build Status]: https://ci.appveyor.com/api/projects/status/04idbevayrghcrh7/branch/master?svg=true
[latest release]: https://github.com/shadowsocks/shadowsocks-csharp/releases
[GFWList]: https://github.com/gfwlist/gfwlist
[Servers]: https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#linux--server-side
[中文说明]: https://github.com/shadowsocks/shadowsocks-windows/wiki/Shadowsocks-Windows-%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E
[Visual Studio 2015]: https://www.visualstudio.com/downloads/
[.NET Framework 4.6.2 Developer Pack]: https://www.microsoft.com/download/details.aspx?id=53321
@@ -23,7 +23,7 @@ namespace Shadowsocks.Controller
public string LatestVersionLocalName;
public event EventHandler CheckUpdateCompleted;
public const string Version = "3.3.3";
public const string Version = "3.3.5";
private class CheckUpdateTimer : System.Timers.Timer
{
@@ -15,7 +15,7 @@ namespace Shadowsocks.Controller
try
{
string path = Application.ExecutablePath;
runKey = Utils.OpenUserRegKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
runKey = Utils.OpenRegKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
if ( runKey == null ) {
Logging.Error( @"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run" );
return false;
@@ -54,7 +54,7 @@ namespace Shadowsocks.Controller
try
{
string path = Application.ExecutablePath;
runKey = Utils.OpenUserRegKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
runKey = Utils.OpenRegKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
if (runKey == null) {
Logging.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run");
return false;
+1
View File
@@ -130,6 +130,7 @@ System Proxy On: =系统代理已启用:
Running: Port {0}=正在运行:端口 {0}
Unexpected error, shadowsocks will exit. Please report to=非预期错误,Shadowsocks将退出。请提交此错误到
Unsupported operating system, use Windows Vista at least.=不支持的操作系统版本,最低需求为Windows Vista。
Unsupported .NET Framework, please update to 4.6.2 or later.=当前 .NET Framework 版本过低,请升级至4.6.2或更新版本。
Proxy request failed=代理请求失败
Proxy handshake failed=代理握手失败
Register hotkey failed=注册热键失败
Binary file not shown.
+1
View File
@@ -130,6 +130,7 @@ System Proxy On: =系統代理已啟用:
Running: Port {0}=正在運行:連接埠號碼 {0}
Unexpected error, shadowsocks will exit. Please report to=非預期錯誤,Shadowsocks將退出。請提交此錯誤到
Unsupported operating system, use Windows Vista at least.=不支持的作業系統版本,最低需求為Windows Vista。
Unsupported .NET Framework, please update to 4.6.2 or later.=當前 .NET Framework 版本過低,最低需求為4.6.2。
Proxy request failed=代理請求失敗
Proxy handshake failed=代理握手失敗
Register hotkey failed=註冊捷徑鍵失敗
+4 -4
View File
@@ -237,10 +237,10 @@ namespace Shadowsocks.Encryption
protected static void randBytes(byte[] buf, int length)
{
byte[] temp = new byte[length];
RNGCryptoServiceProvider rngServiceProvider = new RNGCryptoServiceProvider();
rngServiceProvider.GetBytes(temp);
temp.CopyTo(buf, 0);
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
{
rng.GetBytes(buf, 0, length);
}
}
public override void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength)
+26 -6
View File
@@ -31,6 +31,17 @@ namespace Shadowsocks
return;
}
// Check .NET Framework version
if (!Utils.IsSupportedRuntimeVersion())
{
MessageBox.Show(I18N.GetString("Unsupported .NET Framework, please update to 4.6.2 or later."),
"Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Process.Start(
"http://dotnetsocial.cloudapp.net/GetDotnet?tfm=.NETFramework,Version=v4.6.2");
return;
}
Utils.ReleaseMemory(true);
using (Mutex mutex = new Mutex(false, $"Global\\Shadowsocks_{Application.StartupPath.GetHashCode()}"))
{
@@ -43,7 +54,6 @@ namespace Shadowsocks
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ApplicationExit += (sender, args) => HotKeys.Destroy();
if (!mutex.WaitOne(0, false))
{
@@ -85,7 +95,7 @@ namespace Shadowsocks
Logging.Error(e.ExceptionObject?.ToString());
MessageBox.Show(
$"{I18N.GetString("Unexpected error, shadowsocks will exit. Please report to")} https://github.com/shadowsocks/shadowsocks-windows/issues {Environment.NewLine}{e.ExceptionObject?.ToString()}",
"Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
"Shadowsocks non-UI Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
@@ -96,7 +106,7 @@ namespace Shadowsocks
Logging.Error(errorMsg);
MessageBox.Show(
$"{I18N.GetString("Unexpected error, shadowsocks will exit. Please report to")} https://github.com/shadowsocks/shadowsocks-windows/issues {Environment.NewLine}{errorMsg}",
"Shadowsocks Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
"Shadowsocks UI Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
@@ -108,7 +118,7 @@ namespace Shadowsocks
Logging.Info("os wake up");
if (_controller != null)
{
System.Timers.Timer timer = new System.Timers.Timer(5 * 1000);
System.Timers.Timer timer = new System.Timers.Timer(10 * 1000);
timer.Elapsed += Timer_Elapsed;
timer.AutoReset = false;
timer.Enabled = true;
@@ -116,7 +126,11 @@ namespace Shadowsocks
}
break;
case PowerModes.Suspend:
_controller?.Stop();
if (_controller != null)
{
_controller.Stop();
Logging.Info("controller stopped");
}
Logging.Info("os suspend");
break;
}
@@ -126,7 +140,11 @@ namespace Shadowsocks
{
try
{
_controller?.Start();
if (_controller != null)
{
_controller.Start();
Logging.Info("controller started");
}
}
catch (Exception ex)
{
@@ -150,6 +168,8 @@ namespace Shadowsocks
private static void Application_ApplicationExit(object sender, EventArgs e)
{
SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
HotKeys.Destroy();
if (_controller != null)
{
_controller.Stop();
@@ -11,21 +11,7 @@ namespace Shadowsocks.Util.ProcessManagement
*/
public class Job : IDisposable
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr CreateJobObject(IntPtr a, string lpName);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, UInt32 cbJobObjectInfoLength);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CloseHandle(IntPtr hObject);
private IntPtr handle = IntPtr.Zero;
private bool disposed;
public Job()
{
@@ -62,36 +48,6 @@ namespace Shadowsocks.Util.ProcessManagement
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (disposed) return;
disposed = true;
if (disposing) { }
Close();
}
private void Close()
{
if (handle != IntPtr.Zero)
{
CloseHandle(handle);
handle = IntPtr.Zero;
}
}
~Job()
{
Dispose(false);
}
public bool AddProcess(IntPtr processHandle)
{
var succ = AssignProcessToJobObject(handle, processHandle);
@@ -109,6 +65,56 @@ namespace Shadowsocks.Util.ProcessManagement
return AddProcess(Process.GetProcessById(processId).Handle);
}
#region IDisposable
private bool disposed;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposed) return;
disposed = true;
if (disposing)
{
// no managed objects to free
}
if (handle != IntPtr.Zero)
{
CloseHandle(handle);
handle = IntPtr.Zero;
}
}
~Job()
{
Dispose(false);
}
#endregion
#region Interop
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr CreateJobObject(IntPtr a, string lpName);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, UInt32 cbJobObjectInfoLength);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool CloseHandle(IntPtr hObject);
#endregion
}
#region Helper classes
@@ -30,7 +30,13 @@ namespace Shadowsocks.Util.SystemProxy
INTERNET_OPTION_SETTINGS_CHANGED = 39,
// Causes the proxy data to be reread from the registry for a handle.
INTERNET_OPTION_REFRESH = 37
INTERNET_OPTION_REFRESH = 37,
// Alerts the current WinInet instance that proxy settings have changed
// and that they must update with the new settings.
// To alert all available WinInet instances, set the Buffer parameter of
// InternetSetOption to NULL and BufferLength to 0 when passing this option.
INTERNET_OPTION_PROXY_SETTINGS_CHANGED = 95
}
}
@@ -22,7 +22,7 @@ using System.Runtime.InteropServices;
namespace Shadowsocks.Util.SystemProxy
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct INTERNET_PER_CONN_OPTION_LIST : IDisposable
{
public int Size;
@@ -26,7 +26,7 @@ namespace Shadowsocks.Util.SystemProxy
/// <summary>
/// Sets an Internet option.
/// </summary>
[DllImport("wininet.dll", CharSet = CharSet.Ansi, SetLastError = true)]
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern bool InternetSetOption(
IntPtr hInternet,
INTERNET_OPTION dwOption,
+148
View File
@@ -0,0 +1,148 @@
using System.Runtime.InteropServices;
namespace Shadowsocks.Util.SystemProxy
{
internal static class RemoteAccessService
{
private enum RasFieldSizeConstants
{
#region original header
//#if (WINVER >= 0x400)
//#define RAS_MaxEntryName 256
//#define RAS_MaxDeviceName 128
//#define RAS_MaxCallbackNumber RAS_MaxPhoneNumber
//#else
//#define RAS_MaxEntryName 20
//#define RAS_MaxDeviceName 32
//#define RAS_MaxCallbackNumber 48
//#endif
#endregion
RAS_MaxEntryName = 256,
RAS_MaxPath = 260
}
private const int ERROR_SUCCESS = 0;
private const int RASBASE = 600;
private const int ERROR_BUFFER_TOO_SMALL = RASBASE + 3;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
private struct RasEntryName
{
#region original header
//#define RASENTRYNAMEW struct tagRASENTRYNAMEW
//RASENTRYNAMEW
//{
// DWORD dwSize;
// WCHAR szEntryName[RAS_MaxEntryName + 1];
//
//#if (WINVER >= 0x500)
// //
// // If this flag is REN_AllUsers then its a
// // system phonebook.
// //
// DWORD dwFlags;
// WCHAR szPhonebookPath[MAX_PATH + 1];
//#endif
//};
//
//#define RASENTRYNAMEA struct tagRASENTRYNAMEA
//RASENTRYNAMEA
//{
// DWORD dwSize;
// CHAR szEntryName[RAS_MaxEntryName + 1];
//
//#if (WINVER >= 0x500)
// DWORD dwFlags;
// CHAR szPhonebookPath[MAX_PATH + 1];
//#endif
//};
#endregion
public int dwSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)RasFieldSizeConstants.RAS_MaxEntryName + 1)]
public string szEntryName;
public int dwFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)RasFieldSizeConstants.RAS_MaxPath + 1)]
public string szPhonebookPath;
}
[DllImport("rasapi32.dll", CharSet = CharSet.Auto)]
private static extern uint RasEnumEntries(
// reserved, must be NULL
string reserved,
// pointer to full path and file name of phone-book file
string lpszPhonebook,
// buffer to receive phone-book entries
[In, Out] RasEntryName[] lprasentryname,
// size in bytes of buffer
ref int lpcb,
// number of entries written to buffer
out int lpcEntries
);
/// <summary>
/// Get all entries from RAS
/// </summary>
/// <param name="allConns"></param>
/// <returns>
/// 0: success with entries
/// 1: success but no entries found
/// 2: failed
/// </returns>
public static uint GetAllConns(ref string[] allConns)
{
int lpNames = 0;
int entryNameSize = 0;
int lpSize = 0;
uint retval = ERROR_SUCCESS;
RasEntryName[] names = null;
entryNameSize = Marshal.SizeOf(typeof(RasEntryName));
// Windows Vista or later: To determine the required buffer size, call RasEnumEntries
// with lprasentryname set to NULL. The variable pointed to by lpcb should be set to zero.
// The function will return the required buffer size in lpcb and an error code of ERROR_BUFFER_TOO_SMALL.
retval = RasEnumEntries(null, null, null, ref lpSize, out lpNames);
if (retval == ERROR_BUFFER_TOO_SMALL)
{
names = new RasEntryName[lpNames];
for (int i = 0; i < names.Length; i++)
{
names[i].dwSize = entryNameSize;
}
retval = RasEnumEntries(null, null, names, ref lpSize, out lpNames);
}
if (retval == ERROR_SUCCESS)
{
if (lpNames == 0)
{
// no entries found.
return 1;
}
allConns = new string[names.Length];
for (int i = 0; i < names.Length; i++)
{
allConns[i] = names[i].szEntryName;
}
return 0;
}
else
{
return 2;
}
}
}
}
+47 -11
View File
@@ -19,17 +19,19 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Shadowsocks.Controller;
namespace Shadowsocks.Util.SystemProxy
{
public static class WinINet
{
/// <summary>
/// Set IE settings for LAN connection.
/// Set IE settings.
/// </summary>
public static void SetIEProxy(bool enable, bool global, string proxyServer, string pacURL)
private static void SetIEProxy(bool enable, bool global, string proxyServer, string pacURL, string connName)
{
List<INTERNET_PER_CONN_OPTION> _optionlist = new List<INTERNET_PER_CONN_OPTION>();
if (enable)
{
if (global)
@@ -38,17 +40,18 @@ namespace Shadowsocks.Util.SystemProxy
_optionlist.Add(new INTERNET_PER_CONN_OPTION
{
dwOption = (int)INTERNET_PER_CONN_OptionEnum.INTERNET_PER_CONN_FLAGS_UI,
Value = { dwValue = (int)INTERNET_OPTION_PER_CONN_FLAGS_UI.PROXY_TYPE_PROXY }
Value = { dwValue = (int)(INTERNET_OPTION_PER_CONN_FLAGS_UI.PROXY_TYPE_PROXY
| INTERNET_OPTION_PER_CONN_FLAGS_UI.PROXY_TYPE_DIRECT) }
});
_optionlist.Add(new INTERNET_PER_CONN_OPTION
{
dwOption = (int)INTERNET_PER_CONN_OptionEnum.INTERNET_PER_CONN_PROXY_SERVER,
Value = { pszValue = Marshal.StringToHGlobalAnsi(proxyServer) }
Value = { pszValue = Marshal.StringToHGlobalAuto(proxyServer) }
});
_optionlist.Add(new INTERNET_PER_CONN_OPTION
{
dwOption = (int)INTERNET_PER_CONN_OptionEnum.INTERNET_PER_CONN_PROXY_BYPASS,
Value = { pszValue = Marshal.StringToHGlobalAnsi("<local>") }
Value = { pszValue = Marshal.StringToHGlobalAuto("<local>") }
});
}
else
@@ -62,7 +65,7 @@ namespace Shadowsocks.Util.SystemProxy
_optionlist.Add(new INTERNET_PER_CONN_OPTION
{
dwOption = (int)INTERNET_PER_CONN_OptionEnum.INTERNET_PER_CONN_AUTOCONFIG_URL,
Value = { pszValue = Marshal.StringToHGlobalAnsi(pacURL) }
Value = { pszValue = Marshal.StringToHGlobalAuto(pacURL) }
});
}
}
@@ -101,8 +104,9 @@ namespace Shadowsocks.Util.SystemProxy
// Return the unmanaged size of an object in bytes.
optionList.Size = Marshal.SizeOf(optionList);
// IntPtr.Zero means LAN connection.
optionList.Connection = IntPtr.Zero;
optionList.Connection = connName.IsNullOrEmpty()
? IntPtr.Zero // NULL means LAN
: Marshal.StringToHGlobalAuto(connName); // TODO: not working if contains Chinese
optionList.OptionCount = _optionlist.Count;
optionList.OptionError = 0;
@@ -132,15 +136,47 @@ namespace Shadowsocks.Util.SystemProxy
// Notify the system that the registry settings have been changed and cause
// the proxy data to be reread from the registry for a handle.
NativeMethods.InternetSetOption(
bReturn = NativeMethods.InternetSetOption(
IntPtr.Zero,
INTERNET_OPTION.INTERNET_OPTION_SETTINGS_CHANGED,
INTERNET_OPTION.INTERNET_OPTION_PROXY_SETTINGS_CHANGED,
IntPtr.Zero, 0);
if (!bReturn)
{
Logging.Error("InternetSetOption:INTERNET_OPTION_PROXY_SETTINGS_CHANGED");
}
NativeMethods.InternetSetOption(
bReturn = NativeMethods.InternetSetOption(
IntPtr.Zero,
INTERNET_OPTION.INTERNET_OPTION_REFRESH,
IntPtr.Zero, 0);
if (!bReturn)
{
Logging.Error("InternetSetOption:INTERNET_OPTION_REFRESH");
}
}
public static void SetIEProxy(bool enable, bool global, string proxyServer, string pacURL)
{
string[] allConnections = null;
var ret = RemoteAccessService.GetAllConns(ref allConnections);
if (ret == 2)
throw new Exception("Cannot get all connections");
if (ret == 1)
{
// no entries, only set LAN
SetIEProxy(enable, global, proxyServer, pacURL, null);
}
else if (ret == 0)
{
// found entries, set LAN and each connection
SetIEProxy(enable, global, proxyServer, pacURL, null);
foreach (string connName in allConnections)
{
SetIEProxy(enable, global, proxyServer, pacURL, connName);
}
}
}
}
}
+40 -17
View File
@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Windows.Forms;
using Microsoft.Win32;
using Shadowsocks.Controller;
@@ -211,7 +208,7 @@ namespace Shadowsocks.Util
return new BandwidthScaleInfo(f, unit, scale);
}
public static RegistryKey OpenUserRegKey( string name, bool writable )
public static RegistryKey OpenRegKey(string name, bool writable, RegistryHive hive = RegistryHive.CurrentUser)
{
// we are building x86 binary for both x86 and x64, which will
// cause problem when opening registry key
@@ -219,29 +216,25 @@ namespace Shadowsocks.Util
if (name.IsNullOrEmpty()) throw new ArgumentException(nameof(name));
try
{
RegistryKey userKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser,
RegistryKey userKey = RegistryKey.OpenBaseKey(hive,
Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32)
.OpenSubKey(name, writable);
return userKey;
}
catch (UnauthorizedAccessException uae)
{
Logging.LogUsefulException(uae);
return null;
}
catch (SecurityException se)
{
Logging.LogUsefulException(se);
return null;
}
catch (ArgumentException ae)
{
MessageBox.Show("OpenUserRegKey: " + ae.ToString());
MessageBox.Show("OpenRegKey: " + ae.ToString());
return null;
}
catch (Exception e)
{
Logging.LogUsefulException(e);
return null;
}
}
public static bool IsWinVistaOrHigher() {
public static bool IsWinVistaOrHigher()
{
return Environment.OSVersion.Version.Major > 5;
}
@@ -249,5 +242,35 @@ namespace Shadowsocks.Util
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetProcessWorkingSetSize(IntPtr process,
UIntPtr minimumWorkingSetSize, UIntPtr maximumWorkingSetSize);
// See: https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
public static bool IsSupportedRuntimeVersion()
{
/*
* +-----------------------------------------------------------------+----------------------------+
* | Version | Value of the Release DWORD |
* +-----------------------------------------------------------------+----------------------------+
* | .NET Framework 4.6.2 installed on Windows 10 Anniversary Update | 394802 |
* | .NET Framework 4.6.2 installed on all other Windows OS versions | 394806 |
* +-----------------------------------------------------------------+----------------------------+
*/
const int minSupportedRelease = 394802;
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
using (var ndpKey = OpenRegKey(subkey, false, RegistryHive.LocalMachine))
{
if (ndpKey?.GetValue("Release") != null)
{
var releaseKey = (int)ndpKey.GetValue("Release");
if (releaseKey >= minSupportedRelease)
{
return true;
}
}
}
return false;
}
}
}
+1 -1
View File
@@ -296,7 +296,7 @@ namespace Shadowsocks.View
{
int index = ServersListBox.SelectedIndex;
Server server = _modifiedConfiguration.configs[index];
object item = ServersListBox.SelectedItem;
object item = ServersListBox.Items[index];
_modifiedConfiguration.configs.Remove(server);
_modifiedConfiguration.configs.Insert(index + step, server);
@@ -190,6 +190,7 @@
<Compile Include="Util\SystemProxy\INTERNET_PER_CONN_OPTION.cs" />
<Compile Include="Util\SystemProxy\INTERNET_PER_CONN_OPTION_LIST.cs" />
<Compile Include="Util\SystemProxy\NativeMethods.cs" />
<Compile Include="Util\SystemProxy\RAS.cs" />
<Compile Include="Util\SystemProxy\WinINet.cs" />
<Compile Include="Util\Util.cs" />
<Compile Include="View\ConfigForm.cs">