diff --git a/shadowsocks-csharp/Encryptor.cs b/shadowsocks-csharp/Encryptor.cs index 73437a1..366e2d4 100755 --- a/shadowsocks-csharp/Encryptor.cs +++ b/shadowsocks-csharp/Encryptor.cs @@ -228,6 +228,17 @@ namespace shadowsocks_csharp } } + public byte[] byteArrayWith(byte[] buf, int length) + { + if (buf.Length == length) + { + return buf; + } + byte[] result = new byte[length]; + System.Buffer.BlockCopy(buf, 0, result, 0, length); + return result; + } + public byte[] Encrypt(byte[] buf, int length) { switch (method) @@ -235,11 +246,11 @@ namespace shadowsocks_csharp case "table": for (int i = 0; i < length; i++) buf[i] = encryptTable[buf[i]]; - return buf; + return byteArrayWith(buf, length); break; case "rc4": rc4.Encrypt(encryptTable, buf, length); - return buf; + return byteArrayWith(buf, length); break; default: return sslEncrypt(buf, length); @@ -252,11 +263,11 @@ namespace shadowsocks_csharp case "table": for (int i = 0; i < length; i++) buf[i] = decryptTable[buf[i]]; - return buf; + return byteArrayWith(buf, length); break; case "rc4": rc4.Decrypt(decryptTable, buf, length); - return buf; + return byteArrayWith(buf, length); break; default: return sslDecrypt(buf, length); diff --git a/shadowsocks-csharp/Local.cs b/shadowsocks-csharp/Local.cs index 9467fe9..4af521b 100755 --- a/shadowsocks-csharp/Local.cs +++ b/shadowsocks-csharp/Local.cs @@ -131,7 +131,14 @@ namespace shadowsocks_csharp connection.Shutdown(SocketShutdown.Send); if (remote != null) { - remote.Shutdown(SocketShutdown.Send); + try + { + remote.Shutdown(SocketShutdown.Send); + } + catch (SocketException e) + { + Console.WriteLine(e.ToString()); + } } encryptor.Dispose(); } diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index 9656d67..12cf932 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Windows.Forms; namespace shadowsocks_csharp @@ -12,9 +13,25 @@ namespace shadowsocks_csharp [STAThread] static void Main() { + try + { + FileStream fs = new FileStream("shadowsocks.log", FileMode.Append); + TextWriter tmp = Console.Out; + StreamWriter sw = new StreamWriter(fs); + sw.AutoFlush = true; + Console.SetOut(sw); + Console.SetError(sw); + + } + catch (IOException e) + { + Console.WriteLine(e.ToString()); + } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); + + } } }