Browse Source

fix table and rc4; fix exception when shutdown; log to file

tags/2.3
clowwindy 12 years ago
parent
commit
5dc798511b
3 changed files with 40 additions and 5 deletions
  1. +15
    -4
      shadowsocks-csharp/Encryptor.cs
  2. +8
    -1
      shadowsocks-csharp/Local.cs
  3. +17
    -0
      shadowsocks-csharp/Program.cs

+ 15
- 4
shadowsocks-csharp/Encryptor.cs View File

@@ -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) public byte[] Encrypt(byte[] buf, int length)
{ {
switch (method) switch (method)
@@ -235,11 +246,11 @@ namespace shadowsocks_csharp
case "table": case "table":
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
buf[i] = encryptTable[buf[i]]; buf[i] = encryptTable[buf[i]];
return buf;
return byteArrayWith(buf, length);
break; break;
case "rc4": case "rc4":
rc4.Encrypt(encryptTable, buf, length); rc4.Encrypt(encryptTable, buf, length);
return buf;
return byteArrayWith(buf, length);
break; break;
default: default:
return sslEncrypt(buf, length); return sslEncrypt(buf, length);
@@ -252,11 +263,11 @@ namespace shadowsocks_csharp
case "table": case "table":
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
buf[i] = decryptTable[buf[i]]; buf[i] = decryptTable[buf[i]];
return buf;
return byteArrayWith(buf, length);
break; break;
case "rc4": case "rc4":
rc4.Decrypt(decryptTable, buf, length); rc4.Decrypt(decryptTable, buf, length);
return buf;
return byteArrayWith(buf, length);
break; break;
default: default:
return sslDecrypt(buf, length); return sslDecrypt(buf, length);


+ 8
- 1
shadowsocks-csharp/Local.cs View File

@@ -131,7 +131,14 @@ namespace shadowsocks_csharp
connection.Shutdown(SocketShutdown.Send); connection.Shutdown(SocketShutdown.Send);
if (remote != null) if (remote != null)
{ {
remote.Shutdown(SocketShutdown.Send);
try
{
remote.Shutdown(SocketShutdown.Send);
}
catch (SocketException e)
{
Console.WriteLine(e.ToString());
}
} }
encryptor.Dispose(); encryptor.Dispose();
} }


+ 17
- 0
shadowsocks-csharp/Program.cs View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
namespace shadowsocks_csharp namespace shadowsocks_csharp
@@ -12,9 +13,25 @@ namespace shadowsocks_csharp
[STAThread] [STAThread]
static void Main() 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.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); Application.Run(new Form1());
} }
} }
} }

Loading…
Cancel
Save