Browse Source

3.4.0

pull/373/head
breakwa11 9 years ago
parent
commit
50e9d2a93d
12 changed files with 2048 additions and 81 deletions
  1. +3
    -0
      shadowsocks-csharp.sln
  2. +1
    -1
      shadowsocks-csharp/Controller/GfwListUpdater.cs
  3. +358
    -46
      shadowsocks-csharp/Controller/Local.cs
  4. +1573
    -0
      shadowsocks-csharp/Controller/TDP.cs
  5. +1
    -1
      shadowsocks-csharp/Controller/UpdateChecker.cs
  6. +3
    -3
      shadowsocks-csharp/Data/cn.txt
  7. +44
    -0
      shadowsocks-csharp/Util/CRC.cs
  8. +54
    -27
      shadowsocks-csharp/View/ConfigForm.Designer.cs
  9. +4
    -0
      shadowsocks-csharp/View/ConfigForm.cs
  10. +3
    -3
      shadowsocks-csharp/View/MenuViewController.cs
  11. +2
    -0
      shadowsocks-csharp/shadowsocks-csharp.csproj
  12. +2
    -0
      shadowsocks-csharp/shadowsocks-csharp4.0.csproj

+ 3
- 0
shadowsocks-csharp.sln View File

@@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "shadowsocks-csharp", "shadowsocks-csharp\shadowsocks-csharp.csproj", "{8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}"
ProjectSection(ProjectDependencies) = postProject
{0F2A0C8A-6C06-485B-AA13-AEEC19CA9637} = {0F2A0C8A-6C06-485B-AA13-AEEC19CA9637}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{45913187-0685-4903-B250-DCEF0479CD86}"
ProjectSection(ProjectDependencies) = postProject


+ 1
- 1
shadowsocks-csharp/Controller/GfwListUpdater.cs View File

@@ -12,7 +12,7 @@ namespace Shadowsocks.Controller
{
public class GFWListUpdater
{
private const string GFWLIST_URL = "https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt";
private const string GFWLIST_URL = "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt";
private static string PAC_FILE = PACServer.PAC_FILE;


+ 358
- 46
shadowsocks-csharp/Controller/Local.cs View File

@@ -7,6 +7,130 @@ using Shadowsocks.Encryption;
using Shadowsocks.Model;
using System.Timers;

/*
shadowsocks TCP/UDP rand data packet (Server + Client)
+------+------+----------+----------------+
| Ver. | size | Rnd DATA | TCP/UDP packet |
+------+------+----------+----------------+
| 1 | 1 | Variable | Variable |
+------+------+----------+----------------+
Ver: always 0x80
size: Rnd DATA size

shadowsocks TCP/UDP rand data packet 2 (Server + Client)
+------+----------------+
| Ver. | TCP/UDP packet |
+------+----------------+
| 1 | Variable |
+------+----------------+
Ver: always 0x81

shadowsocks TCP/UDP rand data packet (Server + Client)
+------+------+----------+----------------+
| Ver. | size | Rnd DATA | TCP/UDP packet |
+------+------+----------+----------------+
| 1 | 2 | Variable | Variable |
+------+------+----------+----------------+
Ver: always 0x82
*/

/*

shadowsocks UDP Request Connect (Client)
+------+-----+-----------+----------+----------+-------+
| Ver. | Cmd | requestid | local id | Rnd DATA | CRC32 |
+------+-----+-----------+----------+----------+-------+
| 1 | 1 | 2 | 4 | Variable | 4 |
+------+-----+-----------+----------+----------+-------+
Ver: always 8
Cmd: 0
Rnd DATA: size from 2 to 32, fill with 0 is ok

shadowsocks UDP Request Connect Recv (Server) -------------------------- TODO port/ip redir
+------+-----+-----------+-----+----------+-----------+
| Ver. | Cmd | requestid |state| Rnd DATA | requestid |
+------+-----+-----------+-----+----------+-----------+
| 1 | 1 | 2 | 1 | Variable | 2 |
+------+-----+-----------+-----+----------+-----------+
Cmd: 1
Rnd DATA: size from 0 to 32, the same as below
state:
* 0 Reject
* 1 Connected
* 2 Connected Remote
* 3 Error
* 4 Disconnected
* 5 Redirect
Note: client should save the requestid for next communication if state is 1

shadowsocks UDP Request Connect Remote (Client)
+------+-----+-----------+----------+------+----------+----------+----------+-------+
| Ver. | Cmd | requestid | local id | ATYP | DST.ADDR | DST.PORT | Rnd DATA | CRC32 |
+------+-----+-----------+----------+------+----------+----------+----------+-------+
| 1 | 1 | 2 | 4 | 1 | Variable | 2 | Variable | 4 |
+------+-----+-----------+----------+------+----------+----------+----------+-------+
Cmd: 2
ATYP: 1: IPv4; 4: IPv6; 3: a host name need resolved

shadowsocks UDP Request Connect Remote Recv (Server)
+------+-----+-----------+-----+----------+-----------+
| Ver. | Cmd | requestid |state| Rnd DATA | requestid |
+------+-----+-----------+-----+----------+-----------+
| 1 | 1 | 2 | 1 | Variable | 2 |
+------+-----+-----------+-----+----------+-----------+
Cmd: 3

================== start proxy

Post Data (Server + Client) ------------------------ TODO compress support
+------+-----+-----------+------------------+-------------------+-----------+----------+---------------+-------------------+
| Ver. | Cmd | requestid | local id(Client) | recv next pack id | pack id | DATA | CRC32(Client) | requestid(Server) |
+------+-----+-----------+------------------+-------------------+-----------+----------+---------------+-------------------+
| 1 | 1 | 2 | 4 | 4 | 4 | Payload | 4 | 2 |
+------+-----+-----------+------------------+-------------------+-----------+----------+---------------+-------------------+
Cmd: 4
local id: Server not send the id back
Note:
* We should split a big tcp packet (> 1400 bytes) into random size.
* Otherwise, we should add 0x80 rand header, size is more then 0 and less then 8 for performance reason.

Syn status (Client + Server)
+------+-----+-----------+------------------+-------------------+-------------+----------+---------------+-------------------+
| Ver. | Cmd | requestid | local id(Client) | recv next pack id | max send id | ids | CRC32(Client) | requestid(Server) |
+------+-----+-----------+------------------+-------------------+-------------+----------+---------------+-------------------+
| 1 | 1 | 2 | 4 | 4 | 4 | Variable | 4 | 2 |
+------+-----+-----------+------------------+-------------------+-------------+----------+---------------+-------------------+
Cmd: 5
ids: An array of id which offset of "recv next pack id" include your missing packets, 2 bytes each. Should add an extra byte randomly


Post Data (Server + Client)
+------+-----+-----------+------------------+-------------------+-----------+----------+---------------+-------------------+
| Ver. | Cmd | requestid | local id(Client) | recv next pack id | pack id | DATA | CRC32(Client) | requestid(Server) |
+------+-----+-----------+------------------+-------------------+-----------+----------+---------------+-------------------+
| 1 | 1 | 2 | 4 | 8 | 8 | Payload | 4 | 2 |
+------+-----+-----------+------------------+-------------------+-----------+----------+---------------+-------------------+
Cmd: 6

Syn status (Client + Server)
+------+-----+-----------+------------------+-------------------+-------------+----------+---------------+-------------------+
| Ver. | Cmd | requestid | local id(Client) | recv next pack id | max send id | ids | CRC32(Client) | requestid(Server) |
+------+-----+-----------+------------------+-------------------+-------------+----------+---------------+-------------------+
| 1 | 1 | 2 | 4 | 8 | 8 | Variable | 4 | 2 |
+------+-----+-----------+------------------+-------------------+-------------+----------+---------------+-------------------+
Cmd: 7


Disconnect (Server + Client)
+------+-----+-----------+------------------+----------+---------------+-------------------+
| Ver. | Cmd | requestid | local id(Client) | Rnd DATA | CRC32(Client) | requestid(Server) |
+------+-----+-----------+------------------+----------+---------------+-------------------+
| 1 | 1 | 2 | 4 | Variable | 4 | 2 |
+------+-----+-----------+------------------+----------+---------------+-------------------+
Cmd: 8

*/

namespace Shadowsocks.Controller
{

@@ -29,7 +153,7 @@ namespace Shadowsocks.Controller
Handler handler = new Handler();

//handler.config = _config;
handler.getCurrentServer = delegate(bool usingRandom, bool forceRandom) { return _config.GetCurrentServer(usingRandom, forceRandom); };
handler.getCurrentServer = delegate (bool usingRandom, bool forceRandom) { return _config.GetCurrentServer(usingRandom, forceRandom); };
handler.connection = socket;
handler.reconnectTimesRemain = _config.reconnectTimes;

@@ -42,6 +166,7 @@ namespace Shadowsocks.Controller
handler.socks5RemotePassword = _config.socks5Pass;
}
handler.TTL = _config.TTL;
handler.autoSwitchOff = _config.autoban;

handler.Start(firstPacket, length);
return true;
@@ -116,6 +241,8 @@ namespace Shadowsocks.Controller
public int socks5RemotePort = 0;
public string socks5RemoteUsername;
public string socks5RemotePassword;
// auto ban
public bool autoSwitchOff = true;
// Reconnect
public int reconnectTimesRemain = 0;
protected int reconnectTimes = 0;
@@ -126,6 +253,8 @@ namespace Shadowsocks.Controller
protected Socket remote;
protected Socket remoteUDP;
protected IPEndPoint remoteUDPEndPoint;
// TDP
protected TDPHandler remoteTDP;
// Connect command
protected byte command;
// Init data
@@ -161,10 +290,10 @@ namespace Shadowsocks.Controller
protected bool connectionUDPIdle;
protected bool remoteTCPIdle;
protected bool remoteUDPIdle;
protected bool remoteTDPIdle;

protected SpeedTester speedTester = new SpeedTester();
protected int lastErrCode;
protected bool autoSwitchOff = true;
protected Random random = new Random();
protected Timer timer;
protected object timerLock = new object();
@@ -384,6 +513,19 @@ namespace Shadowsocks.Controller

CloseSocket(ref remote);
CloseSocket(ref remoteUDP);
if (remoteTDP != null)
{
try
{
remoteTDP.Shutdown();
//remoteTDP.Close();
}
catch (Exception e)
{
Logging.LogUsefulException(e);
}
remoteTDP = null;
}

connectionShutdown = false;
remoteShutdown = false;
@@ -426,6 +568,10 @@ namespace Shadowsocks.Controller
IPEndPoint remoteEP = new IPEndPoint(ipAddress, serverPort);
remoteUDPEndPoint = remoteEP;

if (server.tcp_over_udp && connectionUDP == null)
{
remoteTDP = new TDPHandler();
}
if (socks5RemotePort != 0
|| connectionUDP == null && !server.tcp_over_udp
|| connectionUDP != null && server.udp_over_tcp)
@@ -449,6 +595,13 @@ namespace Shadowsocks.Controller
}
}

if (remoteTDP != null && server.tcp_over_udp && socks5RemotePort == 0)
{
speedTester.BeginConnect();
remoteTDP.BeginConnect(server.method, server.password, remoteEP, "", 0,
new AsyncCallback(ConnectCallback), null);
}
else
{
// Connect to the remote endpoint.
if (socks5RemotePort == 0 && connectionUDP != null && !server.udp_over_tcp)
@@ -568,6 +721,19 @@ namespace Shadowsocks.Controller
CloseSocket(ref connectionUDP);
CloseSocket(ref remote);
CloseSocket(ref remoteUDP);
if (remoteTDP != null)
{
try
{
remoteTDP.Shutdown();
//remoteTDP.Close();
}
catch (Exception e)
{
Logging.LogUsefulException(e);
}
remoteTDP = null;
}

lock (encryptionLock)
{
@@ -1036,7 +1202,6 @@ namespace Shadowsocks.Controller
}
else
{
RspSocks5TCPHeader();
if (socks5RemotePort > 0)
{
if (server.tcp_over_udp)
@@ -1044,6 +1209,7 @@ namespace Shadowsocks.Controller
command = 3;
}
}
RspSocks5TCPHeader();
}
}
else
@@ -1166,13 +1332,24 @@ namespace Shadowsocks.Controller
try
{
// Complete the connection.
if (remoteTDP == null || socks5RemotePort != 0)
{
remote.EndConnect(ar);
}
else
{
remoteTDP.EndConnect(ar);
}
if (socks5RemotePort > 0)
{
if (ConnectProxyServer(server.server, server.server_port, remote, (int)SocketError.ConnectionReset))
{
if (server.tcp_over_udp && remoteTDP != null)
{
remoteTDP.BeginConnect(server.method, server.password, remoteUDPEndPoint, server.server, server.server_port,
new AsyncCallback(ConnectTDPCallback), null);
return;
}
}
else
{
@@ -1205,6 +1382,38 @@ namespace Shadowsocks.Controller
}
}

private void ConnectTDPCallback(IAsyncResult ar)
{
if (closed)
{
return;
}
try
{
remoteTDP.EndConnect(ar);

speedTester.EndConnect();
server.ServerSpeedLog().AddConnectTime((int)(speedTester.timeConnectEnd - speedTester.timeConnectBegin).TotalMilliseconds);

ConnectState _state = this.State;
if (_state == ConnectState.CONNECTING)
{
this.State = ConnectState.CONNECTED;
StartPipe();
}
else if (_state == ConnectState.CONNECTED)
{
//ERROR
}
}
catch (Exception e)
{
LogSocketException(e);
if (!Logging.LogSocketException(server.remarks, server.server, e))
Logging.LogUsefulException(e);
this.Close();
}
}
// do/end xxx tcp/udp Recv
private void doConnectionTCPRecv()
{
@@ -1296,6 +1505,29 @@ namespace Shadowsocks.Controller
return 0;
}

private void doRemoteTDPRecv()
{
if (remoteTDP != null && remoteTDPIdle)
{
//IPEndPoint sender = new IPEndPoint(remoteUDP.AddressFamily == AddressFamily.InterNetworkV6 ? IPAddress.IPv6Any : IPAddress.Any, 0);
//EndPoint tempEP = (EndPoint)sender;
remoteTDPIdle = false;
remoteTDP.BeginReceiveFrom(remoteRecvBuffer, RecvSize,
new AsyncCallback(PipeRemoteTDPReceiveCallback), null);
}
}

private int endRemoteTDPRecv(IAsyncResult ar, ref EndPoint endPoint)
{
if (remoteTDP != null)
{
int bytesRead = remoteTDP.EndReceiveFrom(ar, ref endPoint);
remoteTDPIdle = true;
return bytesRead;
}
return 0;
}

// 2 sides connection start
private void StartPipe()
{
@@ -1310,6 +1542,7 @@ namespace Shadowsocks.Controller
connectionUDPIdle = true;
remoteTCPIdle = true;
remoteUDPIdle = true;
remoteTDPIdle = true;

connectionPacketNumber = 0;
remoteUDPRecvBufferLength = 0;
@@ -1321,6 +1554,18 @@ namespace Shadowsocks.Controller
{
if (connectionUDP == null) // TCP
{
if (server.tcp_over_udp &&
remoteTDP != null)
{
doRemoteTDPRecv();
//RemoteTDPSend(remoteHeaderSendBuffer, remoteHeaderSendBuffer.Length);
//remoteHeaderSendBuffer = null;
}
else
{
//RemoteSend(remoteHeaderSendBuffer, remoteHeaderSendBuffer.Length);
//remoteHeaderSendBuffer = null;
}
}
else // UDP
{
@@ -1472,6 +1717,73 @@ namespace Shadowsocks.Controller
}
}

// end ReceiveCallback
private void PipeRemoteTDPReceiveCallback(IAsyncResult ar)
{
if (closed)
{
return;
}
try
{
IPEndPoint sender = new IPEndPoint(remoteTDP.AddressFamily == AddressFamily.InterNetworkV6 ? IPAddress.IPv6Any : IPAddress.Any, 0);
EndPoint tempEP = (EndPoint)sender;

int bytesRead = endRemoteTDPRecv(ar, ref tempEP);
ResetTimeout(TTL);

if (bytesRead > 0)
{
int bytesToSend = bytesRead;
//byte[] buffer = new byte[bytesToSend];
//Array.Copy(remoteRecvBuffer, buffer, bytesToSend);
//if (connectionUDP == null)
// Logging.LogBin(LogLevel.Debug, "remote recv", buffer, bytesToSend);
//else
// Logging.LogBin(LogLevel.Debug, "udp remote recv", buffer, bytesToSend);
lock (decryptionLock)
{
if (closed)
{
return;
}
Array.Copy(remoteRecvBuffer, remoteSendBuffer, bytesToSend);
}
server.ServerSpeedLog().AddDownloadBytes(bytesToSend);
server.ServerSpeedLog().HasData();
speedTester.AddDownloadSize(bytesToSend);

ConnectionSend(remoteSendBuffer, bytesToSend);
}
else
{
//Console.WriteLine("bytesRead: " + bytesRead.ToString());
connection.Shutdown(SocketShutdown.Send);
connectionShutdown = true;
if (lastErrCode == 0)
{
lastErrCode = 8;
if (speedTester.sizeDownload == 0)
{
server.ServerSpeedLog().AddNoDataTimes();
if (server.ServerSpeedLog().ErrorContinurousTimes >= AutoSwitchOffErrorTimes && autoSwitchOff)
{
server.setEnable(false);
}
}
}
CheckClose();
}
}
catch (Exception e)
{
LogSocketException(e);
if (!Logging.LogSocketException(server.remarks, server.server, e))
Logging.LogUsefulException(e);
this.Close();
}
}

private bool RemoveRemoteUDPRecvBufferHeader(ref int bytesRead)
{
if (socks5RemotePort > 0)
@@ -1523,48 +1835,6 @@ namespace Shadowsocks.Controller
bytesToSend += 3;
}

public static byte[] ParseUDPHeader(byte[] buffer, ref int len)
{
if (buffer.Length == 0)
return buffer;
if (buffer[0] == 0x81)
{
len = len - 1;
byte[] ret = new byte[len];
Array.Copy(buffer, 1, ret, 0, len);
return ret;
}
if (buffer[0] == 0x80 && len >= 2)
{
int ofbs_len = buffer[1];
if (ofbs_len + 2 < len)
{
len = len - ofbs_len - 2;
byte[] ret = new byte[len];
Array.Copy(buffer, ofbs_len + 2, ret, 0, len);
return ret;
}
}
if (buffer[0] == 0x82 && len >= 3)
{
int ofbs_len = (buffer[1] << 8) + buffer[2];
if (ofbs_len + 3 < len)
{
len = len - ofbs_len - 3;
byte[] ret = new byte[len];
Array.Copy(buffer, ofbs_len + 3, ret, 0, len);
return ret;
}
}
if (len < buffer.Length)
{
byte[] ret = new byte[len];
Array.Copy(buffer, ret, len);
return ret;
}
return buffer;
}

// end ReceiveCallback
private void PipeRemoteUDPReceiveCallback(IAsyncResult ar)
{
@@ -1596,7 +1866,7 @@ namespace Shadowsocks.Controller
}
encryptorUDP.Reset();
encryptorUDP.Decrypt(remoteRecvBuffer, bytesRead, decryptBuffer, out bytesToSend);
decryptBuffer = ParseUDPHeader(decryptBuffer, ref bytesToSend);
decryptBuffer = TDPHandler.ParseUDPHeader(decryptBuffer, ref bytesToSend);
AddRemoteUDPRecvBufferHeader(decryptBuffer, ref bytesToSend);
}
if (connectionUDP == null)
@@ -1692,6 +1962,13 @@ namespace Shadowsocks.Controller
remote.BeginSend(connetionSendBuffer, 0, bytesToSend, 0, new AsyncCallback(PipeRemoteSendCallback), null);
}

private void RemoteTDPSend(byte[] bytes, int length)
{
server.ServerSpeedLog().AddUploadBytes(length);
speedTester.AddUploadSize(length);
remoteTDP.BeginSendTo(bytes, length, new AsyncCallback(PipeRemoteTDPSendCallback), null);
}

private void RemoteSendto(byte[] bytes, int length, bool obfs, int obfs_max = 40)
{
int bytesToSend;
@@ -1827,6 +2104,12 @@ namespace Shadowsocks.Controller
{
Logging.LogBin(LogLevel.Debug, "remote send", connetionRecvBuffer, bytesRead);
}
if (server.tcp_over_udp &&
remoteTDP != null)
{
RemoteTDPSend(connetionRecvBuffer, bytesRead);
}
else
{
{
RemoteSend(connetionRecvBuffer, bytesRead);
@@ -1835,6 +2118,12 @@ namespace Shadowsocks.Controller
}
else
{
if (server.tcp_over_udp &&
remoteTDP != null)
{
remoteTDP.Shutdown();
}
else
{
remote.Shutdown(SocketShutdown.Send);
}
@@ -1952,6 +2241,27 @@ namespace Shadowsocks.Controller
}
}

private void PipeRemoteTDPSendCallback(IAsyncResult ar)
{
if (closed)
{
return;
}
try
{
//remoteTDP.EndSendTo(ar);
doConnectionTCPRecv();
doConnectionUDPRecv();
}
catch (Exception e)
{
LogSocketException(e);
if (!Logging.LogSocketException(server.remarks, server.server, e))
Logging.LogUsefulException(e);
this.Close();
}
}

private void PipeConnectionSendCallback(IAsyncResult ar)
{
if (closed)
@@ -1963,6 +2273,7 @@ namespace Shadowsocks.Controller
connection.EndSend(ar);
doRemoteTCPRecv();
doRemoteUDPRecv();
doRemoteTDPRecv();
}
catch (Exception e)
{
@@ -1984,6 +2295,7 @@ namespace Shadowsocks.Controller
connectionUDP.EndSendTo(ar);
doRemoteTCPRecv();
doRemoteUDPRecv();
doRemoteTDPRecv();
}
catch (Exception e)
{


+ 1573
- 0
shadowsocks-csharp/Controller/TDP.cs
File diff suppressed because it is too large
View File


+ 1
- 1
shadowsocks-csharp/Controller/UpdateChecker.cs View File

@@ -21,7 +21,7 @@ namespace Shadowsocks.Controller
public const string Name = "ShadowsocksR";
public const string Copyright = "Copyright © BreakWall 2015";
public const string Version = "3.3.6";
public const string Version = "3.4.0";
public const string FullVersion = Version + " Final";
private static bool UseProxy = true;


+ 3
- 3
shadowsocks-csharp/Data/cn.txt View File

@@ -48,13 +48,13 @@ Encryption=加密
Remarks=备注

Adv. Setting=高级选项
TCPoverUDP=TCP over UDP
UDPoverTCP=UDP over TCP
UDPoverUDP=UDP over UDP
Obfs TCP=混淆TCP协议头
Obfs UDP=混淆UDP协议
NOT all server support belows=以下选项不是所有服务端都支持
TCP over TCP if not checked=不打钩使用 TCP over TCP
UDP over UDP if not checked=不打钩使用 UDP over UDP
UDP over TCP if not checked=不打钩使用 UDP over TCP
Recommend checked=保留功能
Checked if server support=服务端支持的话打钩
Link=链接
@@ -67,7 +67,7 @@ LowException=低错误优先
SelectedFirst=选中优先
AutoBan=自动禁用出错服务器

Socks5 Proxy=Socks5代理(连接服务器用
Socks5 Proxy=Socks5代理(前置代理
Socks5 Proxy On=开启Socks5
Username=用户名



+ 44
- 0
shadowsocks-csharp/Util/CRC.cs View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Shadowsocks.Util
{
class CRC32
{
static protected ulong[] Crc32Table;
//生成CRC32码表
static public void CreateCRC32Table()
{
ulong Crc;
Crc32Table = new ulong[256];
int i, j;
for (i = 0; i < 256; i++)
{
Crc = (ulong)i;
for (j = 8; j > 0; j--)
{
if ((Crc & 1) == 1)
Crc = (Crc >> 1) ^ 0xEDB88320;
else
Crc >>= 1;
}
Crc32Table[i] = Crc;
}
}

//获取字符串的CRC32校验值
static public ulong CalcCRC32(byte[] input, int len, ulong value = 0xffffffff)
{
//生成码表
if (Crc32Table == null)
CreateCRC32Table();
byte[] buffer = input;
for (int i = 0; i < len; i++)
{
value = (value >> 8) ^ Crc32Table[(value & 0xFF) ^ buffer[i]];
}
return value ^ 0xffffffff;
}
}
}

+ 54
- 27
shadowsocks-csharp/View/ConfigForm.Designer.cs View File

@@ -49,6 +49,8 @@
this.LabelNote = new System.Windows.Forms.Label();
this.LabelExpertSetting = new System.Windows.Forms.Label();
this.PasswordLabel = new System.Windows.Forms.CheckBox();
this.TCPoverUDPLabel = new System.Windows.Forms.Label();
this.CheckTCPoverUDP = new System.Windows.Forms.CheckBox();
this.panel2 = new System.Windows.Forms.Panel();
this.DeleteButton = new System.Windows.Forms.Button();
this.AddButton = new System.Windows.Forms.Button();
@@ -117,24 +119,26 @@
this.tableLayoutPanel1.Controls.Add(this.PasswordTextBox, 1, 2);
this.tableLayoutPanel1.Controls.Add(this.EncryptionLabel, 0, 3);
this.tableLayoutPanel1.Controls.Add(this.EncryptionSelect, 1, 3);
this.tableLayoutPanel1.Controls.Add(this.LabelLink, 0, 9);
this.tableLayoutPanel1.Controls.Add(this.TextLink, 1, 9);
this.tableLayoutPanel1.Controls.Add(this.LabelLink, 0, 10);
this.tableLayoutPanel1.Controls.Add(this.TextLink, 1, 10);
this.tableLayoutPanel1.Controls.Add(this.RemarksLabel, 0, 4);
this.tableLayoutPanel1.Controls.Add(this.RemarksTextBox, 1, 4);
this.tableLayoutPanel1.Controls.Add(this.ObfsUDPLabel, 0, 8);
this.tableLayoutPanel1.Controls.Add(this.CheckObfsUDP, 1, 8);
this.tableLayoutPanel1.Controls.Add(this.ObfsTCPLabel, 0, 7);
this.tableLayoutPanel1.Controls.Add(this.UDPoverTCPLabel, 0, 6);
this.tableLayoutPanel1.Controls.Add(this.CheckObfsTCP, 1, 7);
this.tableLayoutPanel1.Controls.Add(this.CheckUDPoverUDP, 1, 6);
this.tableLayoutPanel1.Controls.Add(this.ObfsUDPLabel, 0, 9);
this.tableLayoutPanel1.Controls.Add(this.CheckObfsUDP, 1, 9);
this.tableLayoutPanel1.Controls.Add(this.ObfsTCPLabel, 0, 8);
this.tableLayoutPanel1.Controls.Add(this.UDPoverTCPLabel, 0, 7);
this.tableLayoutPanel1.Controls.Add(this.CheckObfsTCP, 1, 8);
this.tableLayoutPanel1.Controls.Add(this.CheckUDPoverUDP, 1, 7);
this.tableLayoutPanel1.Controls.Add(this.LabelNote, 1, 5);
this.tableLayoutPanel1.Controls.Add(this.LabelExpertSetting, 0, 5);
this.tableLayoutPanel1.Controls.Add(this.PasswordLabel, 0, 2);
this.tableLayoutPanel1.Controls.Add(this.TCPoverUDPLabel, 0, 6);
this.tableLayoutPanel1.Controls.Add(this.CheckTCPoverUDP, 1, 6);
this.tableLayoutPanel1.Location = new System.Drawing.Point(8, 21);
this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(0);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.Padding = new System.Windows.Forms.Padding(3);
this.tableLayoutPanel1.RowCount = 10;
this.tableLayoutPanel1.RowCount = 11;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
@@ -145,8 +149,8 @@
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(304, 270);
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(304, 294);
this.tableLayoutPanel1.TabIndex = 0;
//
// IPLabel
@@ -236,7 +240,7 @@
//
this.LabelLink.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.LabelLink.AutoSize = true;
this.LabelLink.Location = new System.Drawing.Point(58, 246);
this.LabelLink.Location = new System.Drawing.Point(58, 270);
this.LabelLink.Name = "LabelLink";
this.LabelLink.Size = new System.Drawing.Size(28, 14);
this.LabelLink.TabIndex = 11;
@@ -245,7 +249,7 @@
// TextLink
//
this.TextLink.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.TextLink.Location = new System.Drawing.Point(92, 242);
this.TextLink.Location = new System.Drawing.Point(92, 266);
this.TextLink.MaxLength = 32;
this.TextLink.Name = "TextLink";
this.TextLink.Size = new System.Drawing.Size(206, 22);
@@ -278,7 +282,7 @@
//
this.ObfsUDPLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.ObfsUDPLabel.AutoSize = true;
this.ObfsUDPLabel.Location = new System.Drawing.Point(27, 220);
this.ObfsUDPLabel.Location = new System.Drawing.Point(27, 244);
this.ObfsUDPLabel.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
this.ObfsUDPLabel.Name = "ObfsUDPLabel";
this.ObfsUDPLabel.Size = new System.Drawing.Size(59, 14);
@@ -288,7 +292,7 @@
// CheckObfsUDP
//
this.CheckObfsUDP.AutoSize = true;
this.CheckObfsUDP.Location = new System.Drawing.Point(92, 218);
this.CheckObfsUDP.Location = new System.Drawing.Point(92, 242);
this.CheckObfsUDP.Name = "CheckObfsUDP";
this.CheckObfsUDP.Size = new System.Drawing.Size(144, 18);
this.CheckObfsUDP.TabIndex = 28;
@@ -299,7 +303,7 @@
//
this.ObfsTCPLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.ObfsTCPLabel.AutoSize = true;
this.ObfsTCPLabel.Location = new System.Drawing.Point(28, 196);
this.ObfsTCPLabel.Location = new System.Drawing.Point(28, 220);
this.ObfsTCPLabel.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
this.ObfsTCPLabel.Name = "ObfsTCPLabel";
this.ObfsTCPLabel.Size = new System.Drawing.Size(58, 14);
@@ -311,7 +315,7 @@
//
this.UDPoverTCPLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.UDPoverTCPLabel.AutoSize = true;
this.UDPoverTCPLabel.Location = new System.Drawing.Point(10, 172);
this.UDPoverTCPLabel.Location = new System.Drawing.Point(10, 196);
this.UDPoverTCPLabel.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
this.UDPoverTCPLabel.Name = "UDPoverTCPLabel";
this.UDPoverTCPLabel.Size = new System.Drawing.Size(76, 14);
@@ -321,7 +325,7 @@
// CheckObfsTCP
//
this.CheckObfsTCP.AutoSize = true;
this.CheckObfsTCP.Location = new System.Drawing.Point(92, 194);
this.CheckObfsTCP.Location = new System.Drawing.Point(92, 218);
this.CheckObfsTCP.Name = "CheckObfsTCP";
this.CheckObfsTCP.Size = new System.Drawing.Size(144, 18);
this.CheckObfsTCP.TabIndex = 27;
@@ -332,7 +336,7 @@
// CheckUDPoverUDP
//
this.CheckUDPoverUDP.AutoSize = true;
this.CheckUDPoverUDP.Location = new System.Drawing.Point(92, 170);
this.CheckUDPoverUDP.Location = new System.Drawing.Point(92, 194);
this.CheckUDPoverUDP.Name = "CheckUDPoverUDP";
this.CheckUDPoverUDP.Size = new System.Drawing.Size(187, 18);
this.CheckUDPoverUDP.TabIndex = 26;
@@ -373,6 +377,27 @@
this.PasswordLabel.UseVisualStyleBackColor = true;
this.PasswordLabel.CheckedChanged += new System.EventHandler(this.PasswordLabel_CheckedChanged);
//
// TCPoverUDPLabel
//
this.TCPoverUDPLabel.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.TCPoverUDPLabel.AutoSize = true;
this.TCPoverUDPLabel.Location = new System.Drawing.Point(10, 172);
this.TCPoverUDPLabel.Margin = new System.Windows.Forms.Padding(3, 5, 3, 5);
this.TCPoverUDPLabel.Name = "TCPoverUDPLabel";
this.TCPoverUDPLabel.Size = new System.Drawing.Size(76, 14);
this.TCPoverUDPLabel.TabIndex = 23;
this.TCPoverUDPLabel.Text = "TCPoverUDP";
//
// CheckTCPoverUDP
//
this.CheckTCPoverUDP.AutoSize = true;
this.CheckTCPoverUDP.Location = new System.Drawing.Point(92, 170);
this.CheckTCPoverUDP.Name = "CheckTCPoverUDP";
this.CheckTCPoverUDP.Size = new System.Drawing.Size(185, 18);
this.CheckTCPoverUDP.TabIndex = 26;
this.CheckTCPoverUDP.Text = "TCP over TCP if not checked";
this.CheckTCPoverUDP.UseVisualStyleBackColor = true;
//
// panel2
//
this.panel2.Anchor = System.Windows.Forms.AnchorStyles.Top;
@@ -414,7 +439,7 @@
this.ServerGroupBox.Location = new System.Drawing.Point(218, 0);
this.ServerGroupBox.Margin = new System.Windows.Forms.Padding(12, 0, 0, 0);
this.ServerGroupBox.Name = "ServerGroupBox";
this.ServerGroupBox.Size = new System.Drawing.Size(316, 309);
this.ServerGroupBox.Size = new System.Drawing.Size(316, 333);
this.ServerGroupBox.TabIndex = 6;
this.ServerGroupBox.TabStop = false;
this.ServerGroupBox.Text = "Server";
@@ -464,7 +489,7 @@
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(740, 487);
this.tableLayoutPanel2.Size = new System.Drawing.Size(740, 511);
this.tableLayoutPanel2.TabIndex = 7;
//
// Socks5ProxyGroup
@@ -473,7 +498,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.Socks5ProxyGroup.AutoSize = true;
this.Socks5ProxyGroup.Controls.Add(this.tableLayoutPanel9);
this.Socks5ProxyGroup.Location = new System.Drawing.Point(218, 309);
this.Socks5ProxyGroup.Location = new System.Drawing.Point(218, 333);
this.Socks5ProxyGroup.Margin = new System.Windows.Forms.Padding(12, 0, 0, 0);
this.Socks5ProxyGroup.Name = "Socks5ProxyGroup";
this.Socks5ProxyGroup.Size = new System.Drawing.Size(316, 178);
@@ -603,7 +628,7 @@
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel7.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tableLayoutPanel7.Size = new System.Drawing.Size(200, 481);
this.tableLayoutPanel7.Size = new System.Drawing.Size(200, 505);
this.tableLayoutPanel7.TabIndex = 16;
//
// CheckAutoBan
@@ -611,7 +636,7 @@
this.CheckAutoBan.Anchor = System.Windows.Forms.AnchorStyles.None;
this.CheckAutoBan.AutoSize = true;
this.tableLayoutPanel7.SetColumnSpan(this.CheckAutoBan, 2);
this.CheckAutoBan.Location = new System.Drawing.Point(63, 449);
this.CheckAutoBan.Location = new System.Drawing.Point(63, 461);
this.CheckAutoBan.Name = "CheckAutoBan";
this.CheckAutoBan.Size = new System.Drawing.Size(73, 18);
this.CheckAutoBan.TabIndex = 17;
@@ -716,14 +741,14 @@
this.tableLayoutPanel8.RowCount = 2;
this.tableLayoutPanel8.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel8.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel8.Size = new System.Drawing.Size(200, 303);
this.tableLayoutPanel8.Size = new System.Drawing.Size(200, 327);
this.tableLayoutPanel8.TabIndex = 17;
//
// LinkUpdate
//
this.LinkUpdate.Anchor = System.Windows.Forms.AnchorStyles.None;
this.LinkUpdate.AutoSize = true;
this.LinkUpdate.Location = new System.Drawing.Point(39, 244);
this.LinkUpdate.Location = new System.Drawing.Point(39, 256);
this.LinkUpdate.Margin = new System.Windows.Forms.Padding(5);
this.LinkUpdate.Name = "LinkUpdate";
this.LinkUpdate.Size = new System.Drawing.Size(122, 14);
@@ -740,7 +765,7 @@
this.tableLayoutPanel10.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel10.Controls.Add(this.tableLayoutPanel3, 0, 2);
this.tableLayoutPanel10.Controls.Add(this.tableLayoutPanel5, 0, 1);
this.tableLayoutPanel10.Location = new System.Drawing.Point(548, 334);
this.tableLayoutPanel10.Location = new System.Drawing.Point(548, 358);
this.tableLayoutPanel10.Name = "tableLayoutPanel10";
this.tableLayoutPanel10.RowCount = 3;
this.tableLayoutPanel10.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
@@ -985,6 +1010,8 @@
private System.Windows.Forms.CheckBox CheckSocks5Proxy;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel10;
private System.Windows.Forms.CheckBox CheckAutoBan;
private System.Windows.Forms.Label TCPoverUDPLabel;
private System.Windows.Forms.CheckBox CheckTCPoverUDP;
}
}

+ 4
- 0
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -63,10 +63,12 @@ namespace Shadowsocks.View
RemarksLabel.Text = I18N.GetString("Remarks");
LabelExpertSetting.Text = I18N.GetString(LabelExpertSetting.Text);
TCPoverUDPLabel.Text = I18N.GetString(TCPoverUDPLabel.Text);
UDPoverTCPLabel.Text = I18N.GetString(UDPoverTCPLabel.Text);
ObfsTCPLabel.Text = I18N.GetString(ObfsTCPLabel.Text);
ObfsUDPLabel.Text = I18N.GetString(ObfsUDPLabel.Text);
LabelNote.Text = I18N.GetString(LabelNote.Text);
CheckTCPoverUDP.Text = I18N.GetString(CheckTCPoverUDP.Text);
CheckUDPoverUDP.Text = I18N.GetString(CheckUDPoverUDP.Text);
CheckObfsTCP.Text = I18N.GetString(CheckObfsTCP.Text);
CheckObfsUDP.Text = I18N.GetString(CheckObfsUDP.Text);
@@ -124,6 +126,7 @@ namespace Shadowsocks.View
password = PasswordTextBox.Text,
method = EncryptionSelect.Text,
remarks = RemarksTextBox.Text,
tcp_over_udp = CheckTCPoverUDP.Checked,
udp_over_tcp = CheckUDPoverUDP.Checked,
obfs_tcp = CheckObfsTCP.Checked,
obfs_udp = CheckObfsUDP.Checked
@@ -204,6 +207,7 @@ namespace Shadowsocks.View
ProxyPortTextBox.Text = _modifiedConfiguration.localPort.ToString();
EncryptionSelect.Text = server.method ?? "aes-256-cfb";
RemarksTextBox.Text = server.remarks;
CheckTCPoverUDP.Checked = server.tcp_over_udp;
CheckUDPoverUDP.Checked = server.udp_over_tcp;
CheckObfsTCP.Checked = server.obfs_tcp;
CheckObfsUDP.Checked = server.obfs_udp;


+ 3
- 3
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -84,9 +84,9 @@ namespace Shadowsocks.View
ShowConfigForm();
}
//timerDelayCheckUpdate = new System.Timers.Timer(1000 * 10.0);
//timerDelayCheckUpdate.Elapsed += timer_Elapsed;
//timerDelayCheckUpdate.Start();
timerDelayCheckUpdate = new System.Timers.Timer(1000 * 10.0);
timerDelayCheckUpdate.Elapsed += timer_Elapsed;
timerDelayCheckUpdate.Start();
}
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)


+ 2
- 0
shadowsocks-csharp/shadowsocks-csharp.csproj View File

@@ -131,6 +131,7 @@
<Compile Include="Controller\Listener.cs" />
<Compile Include="Controller\Logging.cs" />
<Compile Include="Controller\PortForwarder.cs" />
<Compile Include="Controller\TDP.cs" />
<Compile Include="Controller\UpdateChecker.cs" />
<Compile Include="Encryption\EncryptorBase.cs" />
<Compile Include="Encryption\EncryptorFactory.cs" />
@@ -149,6 +150,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Util\CRC.cs" />
<Compile Include="Util\Util.cs" />
<Compile Include="View\ConfigForm.cs">
<SubType>Form</SubType>


+ 2
- 0
shadowsocks-csharp/shadowsocks-csharp4.0.csproj View File

@@ -131,6 +131,7 @@
<Compile Include="Controller\Listener.cs" />
<Compile Include="Controller\Logging.cs" />
<Compile Include="Controller\PortForwarder.cs" />
<Compile Include="Controller\TDP.cs" />
<Compile Include="Controller\UpdateChecker.cs" />
<Compile Include="Encryption\EncryptorBase.cs" />
<Compile Include="Encryption\EncryptorFactory.cs" />
@@ -149,6 +150,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Util\CRC.cs" />
<Compile Include="Util\Util.cs" />
<Compile Include="View\ConfigForm.cs">
<SubType>Form</SubType>


Loading…
Cancel
Save