diff --git a/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs b/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs index e5b1ca749fc..0bbf9620970 100644 --- a/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs +++ b/shadowsocks-csharp/Encryption/MbedTLSEncryptor.cs @@ -118,11 +118,6 @@ public override void Dispose() GC.SuppressFinalize(this); } - ~MbedTLSEncryptor() - { - Dispose(false); - } - protected virtual void Dispose(bool disposing) { lock (this) diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index 3c0a79a38e9..d5b0e1c56c1 100755 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -150,6 +150,7 @@ public class Configuration private LRUCache uricache = new LRUCache(180); private static string CONFIG_FILE = "gui-config.json"; + private static string CONFIG_FILE_BACKUP = "gui-config.json.backup"; public static void SetPassword(string password) { @@ -560,6 +561,20 @@ public static void Save(Configuration config) sw.Write(jsonString); sw.Flush(); } + + if (File.Exists(CONFIG_FILE_BACKUP)) + { + DateTime dt = File.GetLastWriteTimeUtc(CONFIG_FILE_BACKUP); + DateTime now = DateTime.Now; + if ((now - dt).TotalHours > 4) + { + File.Copy(CONFIG_FILE, CONFIG_FILE_BACKUP, true); + } + } + else + { + File.Copy(CONFIG_FILE, CONFIG_FILE_BACKUP, true); + } } catch (IOException e) { diff --git a/shadowsocks-csharp/Model/ServerSpeedLog.cs b/shadowsocks-csharp/Model/ServerSpeedLog.cs index 7f4ed1df3f8..69a0c21eeff 100644 --- a/shadowsocks-csharp/Model/ServerSpeedLog.cs +++ b/shadowsocks-csharp/Model/ServerSpeedLog.cs @@ -432,6 +432,12 @@ protected static void UpdateTransLog(List transLog, int bytes, DateTim const int base_time_diff = 100; const int max_time_diff = 3 * base_time_diff; int time_diff = (int)(now - transLog[transLog.Count - 1].recvTime).TotalMilliseconds; + if (time_diff < 0) + { + transLog.Clear(); + transLog.Add(new TransLog(bytes, now)); + return; + } if (time_diff < base_time_diff) { transLog[transLog.Count - 1].times++; diff --git a/shadowsocks-csharp/Obfs/AuthAkarin.cs b/shadowsocks-csharp/Obfs/AuthAkarin.cs index 11386fa57cd..0391e803220 100644 --- a/shadowsocks-csharp/Obfs/AuthAkarin.cs +++ b/shadowsocks-csharp/Obfs/AuthAkarin.cs @@ -62,6 +62,15 @@ public override Dictionary GetObfs() return _obfs; } + protected override void Disposing() + { + if (encryptor != null) + { + encryptor.Dispose(); + encryptor = null; + } + } + public override object InitData() { return new AuthDataAesChain(); @@ -167,17 +176,13 @@ public void PackData(byte[] data, int datalength, byte[] outdata, out int outlen { byte[] rnd_data = new byte[rand_len]; random.NextBytes(rnd_data); - encryptor.Encrypt(data, datalength, data, out datalength); if (datalength > 0) { + encryptor.Encrypt(data, datalength, data, out datalength); + Array.Copy(data, 0, outdata, start_pos, datalength); if (rand_len > 0) { - Array.Copy(data, 0, outdata, start_pos, datalength); - Array.Copy(rnd_data, 0, outdata, start_pos + datalength, rand_len); - } - else - { - Array.Copy(data, 0, outdata, start_pos, datalength); + rnd_data.CopyTo(outdata, start_pos + datalength); } } else diff --git a/shadowsocks-csharp/Obfs/AuthChain.cs b/shadowsocks-csharp/Obfs/AuthChain.cs index ceeb13ada76..8a40a3b7750 100644 --- a/shadowsocks-csharp/Obfs/AuthChain.cs +++ b/shadowsocks-csharp/Obfs/AuthChain.cs @@ -103,6 +103,15 @@ public override Dictionary GetObfs() return _obfs; } + protected override void Disposing() + { + if (encryptor != null) + { + encryptor.Dispose(); + encryptor = null; + } + } + public override object InitData() { return new AuthDataAesChain(); diff --git a/shadowsocks-csharp/Obfs/ObfsBase.cs b/shadowsocks-csharp/Obfs/ObfsBase.cs index d17446ae9e8..b9e970aef18 100644 --- a/shadowsocks-csharp/Obfs/ObfsBase.cs +++ b/shadowsocks-csharp/Obfs/ObfsBase.cs @@ -116,8 +116,14 @@ protected virtual void Dispose(bool disposing) return; } _disposed = true; + Disposing(); } } + + protected virtual void Disposing() + { + + } #endregion } diff --git a/shadowsocks-csharp/View/LogForm.cs b/shadowsocks-csharp/View/LogForm.cs index 8919bdc5f7c..f48b8803e5f 100644 --- a/shadowsocks-csharp/View/LogForm.cs +++ b/shadowsocks-csharp/View/LogForm.cs @@ -113,7 +113,9 @@ private void ReadLog() catch (FileNotFoundException) { } - + catch (ArgumentNullException) + { + } Text = $@"{I18N.GetString("Log Viewer")} {_currentLogFileName}"; } diff --git a/shadowsocks-csharp/View/ServerLogForm.cs b/shadowsocks-csharp/View/ServerLogForm.cs index bb53e3a9292..69f9c907c54 100644 --- a/shadowsocks-csharp/View/ServerLogForm.cs +++ b/shadowsocks-csharp/View/ServerLogForm.cs @@ -258,7 +258,7 @@ public void UpdateLogThread() { Configuration config = controller.GetCurrentConfiguration(); ServerSpeedLogShow[] _ServerSpeedLogList = new ServerSpeedLogShow[config.configs.Count]; - for (int i = 0; i < config.configs.Count; ++i) + for (int i = 0; i < config.configs.Count && i < _ServerSpeedLogList.Length; ++i) { _ServerSpeedLogList[i] = config.configs[i].ServerSpeedLog().Translate(); }