fix table and rc4; fix exception when shutdown; log to file
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user