├── .github └── issue_template.md ├── .gitignore ├── CHANGES ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── packaging └── upload.sh ├── shadowsocks-csharp.sln ├── shadowsocks-csharp ├── 3rd │ ├── SimpleJson.cs │ ├── opendns │ │ ├── DnsQuery.cs │ │ ├── DnsResponse.cs │ │ ├── Enum.cs │ │ └── RR │ │ │ ├── Address.cs │ │ │ ├── MX.cs │ │ │ ├── ResourceRecord.cs │ │ │ ├── ResourceRecordCollection.cs │ │ │ └── SOA.cs │ └── zxing │ │ ├── BarcodeFormat.cs │ │ ├── BaseLuminanceSource.cs │ │ ├── Binarizer.cs │ │ ├── BinaryBitmap.cs │ │ ├── BitmapLuminanceSource.cs │ │ ├── DecodeHintType.cs │ │ ├── EncodeHintType.cs │ │ ├── LuminanceSource.cs │ │ ├── Result.cs │ │ ├── ResultMetadataType.cs │ │ ├── ResultPoint.cs │ │ ├── ResultPointCallback.cs │ │ ├── WriterException.cs │ │ ├── common │ │ ├── BitArray.cs │ │ ├── BitMatrix.cs │ │ ├── BitSource.cs │ │ ├── DecoderResult.cs │ │ ├── DefaultGridSampler.cs │ │ ├── DetectorResult.cs │ │ ├── GlobalHistogramBinarizer.cs │ │ ├── GridSampler.cs │ │ ├── HybridBinarizer.cs │ │ ├── PerspectiveTransform.cs │ │ ├── StringUtils.cs │ │ ├── detector │ │ │ └── MathUtils.cs │ │ └── reedsolomon │ │ │ ├── GenericGF.cs │ │ │ ├── GenericGFPoly.cs │ │ │ ├── ReedSolomonDecoder.cs │ │ │ └── ReedSolomonEncoder.cs │ │ └── qrcode │ │ ├── QRCodeReader.cs │ │ ├── decoder │ │ ├── BitMatrixParser.cs │ │ ├── DataBlock.cs │ │ ├── DataMask.cs │ │ ├── DecodedBitStreamParser.cs │ │ ├── Decoder.cs │ │ ├── ErrorCorrectionLevel.cs │ │ ├── FormatInformation.cs │ │ ├── Mode.cs │ │ ├── QRCodeDecoderMetaData.cs │ │ └── Version.cs │ │ ├── detector │ │ ├── AlignmentPattern.cs │ │ ├── AlignmentPatternFinder.cs │ │ ├── Detector.cs │ │ ├── FinderPattern.cs │ │ ├── FinderPatternFinder.cs │ │ └── FinderPatternInfo.cs │ │ └── encoder │ │ ├── BlockPair.cs │ │ ├── ByteMatrix.cs │ │ ├── Encoder.cs │ │ ├── MaskUtil.cs │ │ ├── MatrixUtil.cs │ │ └── QRCode.cs ├── Controller │ ├── APIServer.cs │ ├── AutoStartup.cs │ ├── FileManager.cs │ ├── GfwListUpdater.cs │ ├── HttpPortForwarder.cs │ ├── HttpProxy.cs │ ├── HttpProxyRunner.cs │ ├── I18N.cs │ ├── Listener.cs │ ├── Local.cs │ ├── Logging.cs │ ├── PACServer.cs │ ├── ProxyAuth.cs │ ├── ProxySocket.cs │ ├── ShadowsocksController.cs │ ├── Socks5Forwarder.cs │ ├── SpeedTest.cs │ ├── SystemProxy.cs │ ├── UpdateChecker.cs │ └── UpdateFreeNode.cs ├── Data │ ├── cn.txt │ ├── libsscrypto.dll.gz │ ├── libsscrypto64.dll.gz │ ├── mgwz.dll.gz │ ├── privoxy.exe.gz │ ├── privoxy_conf.txt │ ├── proxy.pac.txt.gz │ ├── user-rule.txt │ └── zh-tw.txt ├── Encryption │ ├── EncryptorBase.cs │ ├── EncryptorFactory.cs │ ├── IEncryptor.cs │ ├── IVEncryptor.cs │ ├── Libcrypto.cs │ ├── LibcryptoEncryptor.cs │ ├── MbedTLS.cs │ ├── MbedTLSEncryptor.cs │ ├── RSA.cs │ ├── Sodium.cs │ └── SodiumEncryptor.cs ├── Model │ ├── Configuration.cs │ ├── Host.cs │ ├── IPRangeSet.cs │ ├── IPSegment.cs │ ├── LRUCache.cs │ ├── MinSearchTree.cs │ ├── Server.cs │ ├── ServerSelectStrategy.cs │ └── ServerSpeedLog.cs ├── Obfs │ ├── Auth.cs │ ├── AuthChain.cs │ ├── HttpSimpleObfs.cs │ ├── IObfs.cs │ ├── ObfsBase.cs │ ├── ObfsFactory.cs │ ├── Plain.cs │ └── VerifySimpleObfs.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Resources │ ├── 46418775_p0.jpg │ ├── ss16.png │ ├── ss20.png │ ├── ss24.png │ └── ssw128.png ├── Util │ ├── Base64.cs │ ├── CRC.cs │ └── Util.cs ├── View │ ├── ConfigForm.Designer.cs │ ├── ConfigForm.cs │ ├── ConfigForm.resx │ ├── InputPassword.Designer.cs │ ├── InputPassword.cs │ ├── InputPassword.resx │ ├── LogForm.Designer.cs │ ├── LogForm.cs │ ├── LogForm.resx │ ├── MenuViewController.cs │ ├── PortSettingsForm.Designer.cs │ ├── PortSettingsForm.cs │ ├── PortSettingsForm.resx │ ├── QRCodeSplashForm.cs │ ├── ResetPassword.Designer.cs │ ├── ResetPassword.cs │ ├── ResetPassword.resx │ ├── ServerLogForm.Designer.cs │ ├── ServerLogForm.cs │ ├── ServerLogForm.resx │ ├── SettingsForm.Designer.cs │ ├── SettingsForm.cs │ ├── SettingsForm.resx │ ├── ShowTextForm.Designer.cs │ ├── ShowTextForm.cs │ ├── ShowTextForm.resx │ ├── SubscribeForm.Designer.cs │ ├── SubscribeForm.cs │ └── SubscribeForm.resx ├── app.config ├── app.manifest ├── shadowsocks-csharp-console.csproj ├── shadowsocks-csharp.csproj ├── shadowsocks-csharp4.0.csproj └── shadowsocks.ico └── test ├── Properties └── AssemblyInfo.cs ├── UnitTest.cs └── test.csproj /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 之所以写中文,本issue是写给打算写给乱发中文问题的人看的 2 | 3 | 1. 不欢迎小白,不回答诸如软件如何使用,如何搭建,如何配置,使用速度不快,如何提速等等和软件问题无关的问题,或把开发者当成客服的问题 4 | 2. 这里用于反馈软件可能的Bug,软件潜在的问题,和软件功能需求及讨论 5 | 3. 同一个issue不得在不同repo重复发,除非你发现发错地方(这种情况下你自行删除错误的issue),否则直接关闭且不回答问题,严重者拉黑名单 6 | 4. 建议你把问题事先在其它社区或和其它使用者讨论过,以确认不是密码错误,协议或插件错误,或服务器防火墙没关诸如此类本来应该自己解决的问题 7 | 5. 在你确认你需要发问题时,请尽可能提供详细的信息,包括服务端客户端具体版本,及相应log,及相应服务端客户端协议混淆等等的配置。如信息明显过少,则直接close不理踩 8 | 9 | 确认你读完以上内容后,请删除以上所有内容,然后写下你的问题 10 | 11 | Please remove all above then write down your issue -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Backup/ 2 | bin/ 3 | obj/ 4 | pub/ 5 | 7zip*/ 6 | temp/ 7 | shadowsocks-csharp/shadowsocks-csharp.csproj.user 8 | TestResults 9 | *.suo 10 | *.user 11 | *.exe 12 | 13 | /templates 14 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 2.4 2015-07-11 2 | - Support UDP relay 3 | - Support online PAC 4 | - Migrate update checker to GitHub releases 5 | - Other fixes 6 | 7 | 2.3.1 2015-03-06 8 | - Support user rule 9 | 10 | 2.3 2015-01-25 11 | - Use the same port for every profile 12 | - Use the same port for HTTP/Socks5/PAC 13 | - Fix GFWList PAC compatibility issue with IE11 14 | - Encourage users to report to GFWList when no update found 15 | - Minor UI improvements 16 | 17 | 2.2.1 2015-01-18 18 | - Fix QR Code compatibility 19 | 20 | 2.2 2015-01-14 21 | - Support updating PAC from GFWList 22 | - Support adding server by scanning QR Code 23 | - Output timestamp in logs 24 | - Minor fixes 25 | 26 | 2.1.6 2015-01-02 27 | - Fix OPTIONS requests 28 | - Improve logs 29 | 30 | 2.1.5 2014-12-25 31 | - Fix QR Code compatibility with iOS 32 | - Only left button will trigger double click on tray icon 33 | 34 | 2.1.4 2014-12-20 35 | - Fix crash when remarks are too long 36 | 37 | 2.1.3 2014-12-20 38 | - Add Chinese Language 39 | - Fix some UI issues on Windows 8 40 | - Fix some UI issues on high DPI screens 41 | - Log bind error more friendly 42 | - Stability issues 43 | 44 | 2.1.2 2014-12-14 45 | - Fix sometimes Shadowsocks doesn't respond to requests 46 | 47 | 2.1.1 2014-12-14 48 | - Add global proxy option 49 | 50 | 2.1 2014-12-12 51 | - Add salsa20 and chacha20 support 52 | 53 | 2.0.11 2014-11-23 54 | - Fix a crash 55 | - Only switch the system proxy off if we have switched it on 56 | 57 | 2.0.10 2014-11-18 58 | - Minor fixes 59 | - Optimize code 60 | 61 | 2.0.9 2014-11-13 62 | - Fix startup path 63 | - Fix allowed port range for polipo 64 | 65 | 2.0.8 2014-11-12 66 | - Fix data corruption 67 | - Set proxy for PPPoE 68 | - Auto Startup Option 69 | - Support high DPI screens 70 | 71 | 2.0.7 2014-11-11 72 | - Use OpenSSL for now 73 | 74 | 2.0.6 2014-11-10 75 | - Minor bug fixes 76 | 77 | 2.0.5 2014-11-09 78 | - Fix QRCode size 79 | - Share over LAN option 80 | - Log to temp path instead 81 | 82 | 2.0.4 2014-11-09 83 | - Try to fix data corruption 84 | - Remove all configuration except x86 85 | 86 | 2.0.3 2014-11-08 87 | - Support QRCode generation 88 | - Fix compatibility issues with some Chrome version 89 | 90 | 2.0.2 2014-11-08 91 | - Add remarks 92 | - Fix error when polipo is killed 93 | 94 | 2.0.1 2014-11-08 95 | - Check already running 96 | 97 | 2.0 2014-11-08 98 | - Initial release 99 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | How to Contribute 2 | ================= 3 | 4 | Pull Requests 5 | ------------- 6 | 7 | 1. Pull requests are welcome. 8 | 2. Make sure to pass the unit tests. Write unit tests for new modules if 9 | needed. 10 | 11 | Issues 12 | ------ 13 | 14 | 1. Nobody has reported any bugs but posted a lot of questions in the last 15 | few months. So we're closing the issue tracker. 16 | 17 | 18 | [Troubleshooting]: https://github.com/clowwindy/shadowsocks/wiki/Troubleshooting 19 | [mailing lists]: https://groups.google.com/forum/#!forum/shadowsocks 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ShadowsocksR for Windows 2 | ======================= 3 | 4 | [![Build Status]][Appveyor] 5 | 6 | #### Download 7 | 8 | You will need to download and install [7-Zip](http://www.7-zip.org/) in order 9 | to extract the ShadowsocksR archive. 10 | 11 | Download the [latest release] for ShadowsocksR for Windows. 12 | 13 | _Optionally_, right-click on the downloaded 7z file and select 14 | **CRC SHA** > **SHA-256**. Verify that the SHA-256 checksum displayed 15 | matches the expected checksum which was shown on the releases page. 16 | 17 | Right-click on the downloaded 7z file and do **7-Zip** > **Extract Here** 18 | or extract to a new folder. 19 | 20 | _Optionally_, download and install [Gpg4win](https://www.gpg4win.org/). 21 | From the Windows start menu, launch program **Kleopatra**. 22 | Do **File** > **New Certificate** to create a personal OpenPGP key pair. 23 | Save the signing key from 24 | [breakwa11/pubkey](https://github.com/breakwa11/pubkey) as a text file. 25 | Then do **File** > **Import Certificates** to import the signing key text file. 26 | After import, select the signing key and do 27 | **Certificates** > **Certify Certificates**. 28 | You will need to enter the passphrase for your own key. 29 | Finally, do **File** > **Decrypt/Verify Files** for the executable 30 | you propose to use (see below). A message confirming successful verification 31 | of the signature appears against a green background. 32 | Close program **Kleopatra**. 33 | 34 | For >= Windows 8 or with .Net 4.0, using ShadowsocksR-dotnet4.0.exe. 35 | 36 | For <= Windows 7 or with .Net 2.0, using ShadowsocksR-dotnet2.0.exe. 37 | 38 | #### Usage 39 | 40 | 1. Find ShadowsocksR icon in the notification tray 41 | 2. You can add multiple servers in servers menu 42 | 3. Select Enable System Proxy menu to enable system proxy. Please disable other 43 | proxy addons in your browser, or set them to use system proxy 44 | 4. You can also configure your browser proxy manually if you don't want to enable 45 | system proxy. Set Socks5 or HTTP proxy to 127.0.0.1:1080. You can change this 46 | port in Global settings 47 | 5. You can change PAC rules by editing the PAC file. When you save the PAC file 48 | with any editor, ShadowsocksR will notify browsers about the change automatically 49 | 6. You can also update the PAC file from GFWList. Note your modifications to the PAC 50 | file will be lost. However you can put your rules in the user rule file for GFWList. 51 | Don't forget to update from GFWList again after you've edited the user rule 52 | 7. For UDP, you need to use SocksCap or ProxyCap to force programs you want 53 | to proxy to tunnel over ShadowsocksR 54 | 55 | ### Develop 56 | 57 | Visual Studio Express 2012 is recommended. 58 | 59 | #### License 60 | 61 | GPLv3 62 | 63 | Copyright © BreakWa11 2017. Fork from Shadowsocks by clowwindy 64 | 65 | [Appveyor]: https://ci.appveyor.com/project/breakwa11/shadowsocksr-csharp 66 | [Build Status]: https://ci.appveyor.com/api/projects/status/itcxnad1y95gf2x5/branch/master?svg=true 67 | [latest release]: https://github.com/shadowsocksr/shadowsocksr-csharp/releases 68 | -------------------------------------------------------------------------------- /packaging/upload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version=$1 4 | 5 | rsync --progress -e ssh shadowsocks-csharp/bin/x86/Release/Shadowsocks-win-dotnet4.0-$1.zip frs.sourceforge.net:/home/frs/project/shadowsocksgui/dist/ 6 | rsync --progress -e ssh shadowsocks-csharp/bin/x86/Release/Shadowsocks-win-$1.zip frs.sourceforge.net:/home/frs/project/shadowsocksgui/dist/ 7 | -------------------------------------------------------------------------------- /shadowsocks-csharp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "shadowsocks-csharp", "shadowsocks-csharp\shadowsocks-csharp.csproj", "{8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{45913187-0685-4903-B250-DCEF0479CD86}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {0F2A0C8A-6C06-485B-AA13-AEEC19CA9637} = {0F2A0C8A-6C06-485B-AA13-AEEC19CA9637} 11 | {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062} = {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062} 12 | {DC8929F9-CAC8-4286-8CFE-6A70EF0EF835} = {DC8929F9-CAC8-4286-8CFE-6A70EF0EF835} 13 | EndProjectSection 14 | EndProject 15 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "shadowsocks-csharp4.0", "shadowsocks-csharp\shadowsocks-csharp4.0.csproj", "{0F2A0C8A-6C06-485B-AA13-AEEC19CA9637}" 16 | ProjectSection(ProjectDependencies) = postProject 17 | {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062} = {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062} 18 | {DC8929F9-CAC8-4286-8CFE-6A70EF0EF835} = {DC8929F9-CAC8-4286-8CFE-6A70EF0EF835} 19 | EndProjectSection 20 | EndProject 21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "shadowsocks-csharp-console", "shadowsocks-csharp\shadowsocks-csharp-console.csproj", "{DC8929F9-CAC8-4286-8CFE-6A70EF0EF835}" 22 | ProjectSection(ProjectDependencies) = postProject 23 | {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062} = {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062} 24 | EndProjectSection 25 | EndProject 26 | Global 27 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 28 | Debug|Any CPU = Debug|Any CPU 29 | Release|Any CPU = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 32 | {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {45913187-0685-4903-B250-DCEF0479CD86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {45913187-0685-4903-B250-DCEF0479CD86}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {45913187-0685-4903-B250-DCEF0479CD86}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {45913187-0685-4903-B250-DCEF0479CD86}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {0F2A0C8A-6C06-485B-AA13-AEEC19CA9637}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {0F2A0C8A-6C06-485B-AA13-AEEC19CA9637}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {0F2A0C8A-6C06-485B-AA13-AEEC19CA9637}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {0F2A0C8A-6C06-485B-AA13-AEEC19CA9637}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {DC8929F9-CAC8-4286-8CFE-6A70EF0EF835}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {DC8929F9-CAC8-4286-8CFE-6A70EF0EF835}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {DC8929F9-CAC8-4286-8CFE-6A70EF0EF835}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {DC8929F9-CAC8-4286-8CFE-6A70EF0EF835}.Release|Any CPU.Build.0 = Release|Any CPU 48 | EndGlobalSection 49 | GlobalSection(SolutionProperties) = preSolution 50 | HideSolutionNode = FALSE 51 | EndGlobalSection 52 | EndGlobal 53 | -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/opendns/DnsResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Ruy Delgado 3 | * Title: OpenDNS 4 | * Description: DNS Client Library 5 | * Revision: 1.0 6 | * Last Modified: 2005.01.28 7 | * Created On: 2005.01.28 8 | * 9 | * Note: Based on DnsLite by Jaimon Mathew 10 | * */ 11 | 12 | using System; 13 | using System.Net; 14 | using System.Text; 15 | using System.Collections; 16 | using System.Diagnostics; 17 | 18 | namespace OpenDNS 19 | { 20 | /// 21 | /// Response object as result of a dns query message. 22 | /// Will be null unless query succesfull. 23 | /// 24 | public class DnsResponse 25 | { 26 | private int _QueryID; 27 | 28 | //Property Internals 29 | private bool _AuthorativeAnswer; 30 | private bool _IsTruncated; 31 | private bool _RecursionDesired; 32 | private bool _RecursionAvailable; 33 | private ResponseCodes _ResponseCode; 34 | 35 | private ResourceRecordCollection _ResourceRecords; 36 | private ResourceRecordCollection _Answers; 37 | private ResourceRecordCollection _Authorities; 38 | private ResourceRecordCollection _AdditionalRecords; 39 | 40 | //Read Only Public Properties 41 | public int QueryID 42 | { 43 | get { return _QueryID; } 44 | } 45 | 46 | public bool AuthorativeAnswer 47 | { 48 | get { return _AuthorativeAnswer; } 49 | } 50 | 51 | public bool IsTruncated 52 | { 53 | get { return _IsTruncated; } 54 | } 55 | 56 | public bool RecursionRequested 57 | { 58 | get { return _RecursionDesired; } 59 | } 60 | 61 | public bool RecursionAvailable 62 | { 63 | get { return _RecursionAvailable; } 64 | } 65 | 66 | public ResponseCodes ResponseCode 67 | { 68 | get { return _ResponseCode; } 69 | } 70 | 71 | public ResourceRecordCollection Answers 72 | { 73 | get { return _Answers; } 74 | } 75 | 76 | public ResourceRecordCollection Authorities 77 | { 78 | get { return _Authorities; } 79 | } 80 | 81 | public ResourceRecordCollection AdditionalRecords 82 | { 83 | get { return _AdditionalRecords; } 84 | } 85 | 86 | /// 87 | /// Unified collection of Resource Records from Answers, 88 | /// Authorities and Additional. NOT IN REALTIME SYNC. 89 | /// 90 | /// 91 | public ResourceRecordCollection ResourceRecords 92 | { 93 | get 94 | { 95 | if (_ResourceRecords.Count == 0 && _Answers.Count > 0 && _Authorities.Count > 0 && _AdditionalRecords.Count > 0) 96 | { 97 | foreach (ResourceRecord rr in Answers) 98 | this._ResourceRecords.Add(rr); 99 | 100 | foreach (ResourceRecord rr in Authorities) 101 | this._ResourceRecords.Add(rr); 102 | 103 | foreach (ResourceRecord rr in AdditionalRecords) 104 | this._ResourceRecords.Add(rr); 105 | } 106 | 107 | return _ResourceRecords; 108 | } 109 | } 110 | 111 | public DnsResponse(int ID, bool AA, bool TC, bool RD, bool RA, int RC) 112 | { 113 | this._QueryID = ID; 114 | this._AuthorativeAnswer = AA; 115 | this._IsTruncated = TC; 116 | this._RecursionDesired = RD; 117 | this._RecursionAvailable = RA; 118 | this._ResponseCode = (ResponseCodes)RC; 119 | 120 | this._ResourceRecords = new ResourceRecordCollection(); 121 | this._Answers = new ResourceRecordCollection(); 122 | this._Authorities = new ResourceRecordCollection(); 123 | this._AdditionalRecords = new ResourceRecordCollection(); 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/opendns/Enum.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Ruy Delgado 3 | * Title: OpenDNS 4 | * Description: DNS Client Library 5 | * Revision: 1.0 6 | * Last Modified: 2005.01.28 7 | * Created On: 2005.01.28 8 | * 9 | * Note: Based on DnsLite by Jaimon Mathew 10 | * */ 11 | 12 | using System; 13 | 14 | namespace OpenDNS 15 | { 16 | /// 17 | /// Query Result/Response Codes from server 18 | /// 19 | public enum ResponseCodes : int 20 | { 21 | NoError = 0, 22 | FormatError = 1, 23 | ServerFailure = 2, 24 | NameError = 3, 25 | NotImplemented = 4, 26 | Refused = 5, 27 | Reserved = 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 28 | } 29 | 30 | 31 | /// 32 | /// DNS Resource Record Types 33 | /// 34 | public enum Types : int 35 | { 36 | A = 1, 37 | AAAA = 28, 38 | NS = 2, 39 | CNAME = 5, 40 | SOA = 6, 41 | MB = 7, 42 | MG = 8, 43 | MR = 9, 44 | NULL = 10, 45 | WKS = 11, 46 | PTR = 12, 47 | HINFO = 13, 48 | MINFO = 14, 49 | MX = 15, 50 | TXT = 16, 51 | ANY = 255 52 | } 53 | 54 | 55 | /// 56 | /// Query Class or Scope 57 | /// 58 | public enum Classes : int 59 | { 60 | IN = 1, 61 | CS = 2, 62 | CH = 3, 63 | HS = 4, 64 | ANY = 255 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/opendns/RR/Address.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Ruy Delgado 3 | * Title: OpenDNS 4 | * Description: DNS Client Library 5 | * Revision: 1.0 6 | * Last Modified: 2005.01.28 7 | * Created On: 2005.01.28 8 | * 9 | * Note: Based on DnsLite by Jaimon Mathew 10 | * */ 11 | 12 | using System; 13 | using System.Net; 14 | 15 | namespace OpenDNS 16 | { 17 | /// 18 | /// Address Resource Record 19 | /// 20 | public class Address : ResourceRecord 21 | { 22 | public string ResourceAddress; 23 | private IPAddress _IP; 24 | 25 | public IPAddress IP 26 | { 27 | get 28 | { 29 | if (_IP == null) _IP = IPAddress.Parse(ResourceAddress); 30 | return _IP; 31 | } 32 | } 33 | 34 | public Address(string _Name, Types _Type, Classes _Class, int _TimeToLive, string _ResourceAddress):base(_Name, _Type, _Class, _TimeToLive) 35 | { 36 | ResourceAddress = _ResourceAddress; 37 | RText = _ResourceAddress; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/opendns/RR/MX.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Ruy Delgado 3 | * Title: OpenDNS 4 | * Description: DNS Client Library 5 | * Revision: 1.0 6 | * Last Modified: 2005.01.28 7 | * Created On: 2005.01.28 8 | * 9 | * Note: Based on DnsLite by Jaimon Mathew 10 | * */ 11 | 12 | using System; 13 | using System.Text; 14 | 15 | namespace OpenDNS 16 | { 17 | /// 18 | /// MailExchange Resource Record 19 | /// 20 | public class MX : ResourceRecord 21 | { 22 | public int Preference; 23 | public string Exchange; 24 | 25 | public MX(string _Name, Types _Type, Classes _Class, int _TimeToLive, int _Preference, string _Exchange):base(_Name, _Type, _Class, _TimeToLive) 26 | { 27 | Preference = _Preference; 28 | Exchange = _Exchange; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/opendns/RR/ResourceRecord.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Ruy Delgado 3 | * Title: OpenDNS 4 | * Description: DNS Client Library 5 | * Revision: 1.0 6 | * Last Modified: 2005.01.28 7 | * Created On: 2005.01.28 8 | * 9 | * Note: Based on DnsLite by Jaimon Mathew 10 | * */ 11 | 12 | using System; 13 | using System.Text; 14 | 15 | namespace OpenDNS 16 | { 17 | /// 18 | /// Base Resource Record class for objects returned in 19 | /// answers, authorities and additional record DNS responses. 20 | /// 21 | public class ResourceRecord 22 | { 23 | public string Name; 24 | public Types Type; 25 | public Classes Class; 26 | public int TimeToLive; 27 | public string RText; 28 | 29 | public ResourceRecord() 30 | { 31 | } 32 | 33 | public ResourceRecord(string _Name, Types _Type, Classes _Class, int _TimeToLive) 34 | { 35 | this.Name = _Name; 36 | this.Type = _Type; 37 | this.Class = _Class; 38 | this.TimeToLive = _TimeToLive; 39 | } 40 | 41 | public ResourceRecord(string _Name, Types _Type, Classes _Class, int _TimeToLive, string _RText) 42 | { 43 | this.Name = _Name; 44 | this.Type = _Type; 45 | this.Class = _Class; 46 | this.TimeToLive = _TimeToLive; 47 | this.RText = _RText; 48 | } 49 | 50 | public override string ToString() 51 | { 52 | 53 | StringBuilder sb = new StringBuilder(); 54 | sb.Append("Name=" + Name + "&Type=" + Type + "&Class=" + Class + "&TTL="+TimeToLive); 55 | //TODO: Return TTL as minutes? 56 | //TimeSpan timeSpan = new TimeSpan(0, 0, 0, TimeToLive, 0); 57 | 58 | return sb.ToString(); 59 | } 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/opendns/RR/ResourceRecordCollection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Ruy Delgado 3 | * Title: OpenDNS 4 | * Description: DNS Client Library 5 | * Revision: 1.0 6 | * Last Modified: 2005.01.28 7 | * Created On: 2005.01.28 8 | * 9 | * Note: Based on DnsLite by Jaimon Mathew 10 | * */ 11 | 12 | using System; 13 | using System.Collections; 14 | using System.Text; 15 | 16 | namespace OpenDNS 17 | { 18 | /// 19 | /// The Collection Class inherits from ArrayList. It has its own implemenation 20 | /// of Sort based on the sortable fields. 21 | /// 22 | public class ResourceRecordCollection : ArrayList 23 | { 24 | public enum SortFields 25 | { 26 | Name, 27 | TTL 28 | } 29 | 30 | public void Sort(SortFields sortField, bool isAscending) 31 | { 32 | switch (sortField) 33 | { 34 | case SortFields.Name: 35 | base.Sort(new NameComparer()); 36 | break; 37 | case SortFields.TTL: 38 | base.Sort(new TTLComparer()); 39 | break; 40 | } 41 | 42 | if (!isAscending) base.Reverse(); 43 | } 44 | 45 | private sealed class NameComparer : IComparer 46 | { 47 | public int Compare(object x, object y) 48 | { 49 | ResourceRecord first = (ResourceRecord) x; 50 | ResourceRecord second = (ResourceRecord) y; 51 | return first.Name.CompareTo(second.Name); 52 | } 53 | } 54 | 55 | private sealed class TTLComparer : IComparer 56 | { 57 | public int Compare(object x, object y) 58 | { 59 | ResourceRecord first = (ResourceRecord) x; 60 | ResourceRecord second = (ResourceRecord) y; 61 | return first.TimeToLive.CompareTo(second.TimeToLive); 62 | } 63 | } 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/opendns/RR/SOA.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Author: Ruy Delgado 3 | * Title: OpenDNS 4 | * Description: DNS Client Library 5 | * Revision: 1.0 6 | * Last Modified: 2005.01.28 7 | * Created On: 2005.01.28 8 | * 9 | * Note: Based on DnsLite by Jaimon Mathew 10 | * */ 11 | 12 | using System; 13 | using System.Text; 14 | 15 | namespace OpenDNS 16 | { 17 | /// 18 | /// Start of Authority Resource Record 19 | /// 20 | public class SOA : ResourceRecord 21 | { 22 | public string Server; 23 | public string Email; 24 | public long Serial; 25 | public long Refresh; 26 | public long Retry; 27 | public long Expire; 28 | public long Minimum; 29 | 30 | public SOA(string _Name, Types _Type, Classes _Class, int _TimeToLive, string _Server, string _Email, long _Serial, long _Refresh, long _Retry, long _Expire, long _Minimum):base(_Name, _Type, _Class, _TimeToLive) 31 | { 32 | Server = _Server; 33 | Email = _Email; 34 | Serial = _Serial; 35 | Refresh = _Refresh; 36 | Retry = _Retry; 37 | Expire = _Expire; 38 | Minimum = _Minimum; 39 | } 40 | 41 | } 42 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/BarcodeFormat.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | namespace ZXing 18 | { 19 | /// 20 | /// Enumerates barcode formats known to this package. 21 | /// 22 | /// Sean Owen 23 | [System.Flags] 24 | public enum BarcodeFormat 25 | { 26 | /// Aztec 2D barcode format. 27 | AZTEC = 1, 28 | 29 | /// CODABAR 1D format. 30 | CODABAR = 2, 31 | 32 | /// Code 39 1D format. 33 | CODE_39 = 4, 34 | 35 | /// Code 93 1D format. 36 | CODE_93 = 8, 37 | 38 | /// Code 128 1D format. 39 | CODE_128 = 16, 40 | 41 | /// Data Matrix 2D barcode format. 42 | DATA_MATRIX = 32, 43 | 44 | /// EAN-8 1D format. 45 | EAN_8 = 64, 46 | 47 | /// EAN-13 1D format. 48 | EAN_13 = 128, 49 | 50 | /// ITF (Interleaved Two of Five) 1D format. 51 | ITF = 256, 52 | 53 | /// MaxiCode 2D barcode format. 54 | MAXICODE = 512, 55 | 56 | /// PDF417 format. 57 | PDF_417 = 1024, 58 | 59 | /// QR Code 2D barcode format. 60 | QR_CODE = 2048, 61 | 62 | /// RSS 14 63 | RSS_14 = 4096, 64 | 65 | /// RSS EXPANDED 66 | RSS_EXPANDED = 8192, 67 | 68 | /// UPC-A 1D format. 69 | UPC_A = 16384, 70 | 71 | /// UPC-E 1D format. 72 | UPC_E = 32768, 73 | 74 | /// UPC/EAN extension format. Not a stand-alone format. 75 | UPC_EAN_EXTENSION = 65536, 76 | 77 | /// MSI 78 | MSI = 131072, 79 | 80 | /// Plessey 81 | PLESSEY = 262144, 82 | 83 | /// 84 | /// UPC_A | UPC_E | EAN_13 | EAN_8 | CODABAR | CODE_39 | CODE_93 | CODE_128 | ITF | RSS_14 | RSS_EXPANDED 85 | /// without MSI (to many false-positives) 86 | /// 87 | All_1D = UPC_A | UPC_E | EAN_13 | EAN_8 | CODABAR | CODE_39 | CODE_93 | CODE_128 | ITF | RSS_14 | RSS_EXPANDED 88 | } 89 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/Binarizer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | 19 | using ZXing.Common; 20 | 21 | namespace ZXing 22 | { 23 | /// This class hierarchy provides a set of methods to convert luminance data to 1 bit data. 24 | /// It allows the algorithm to vary polymorphically, for example allowing a very expensive 25 | /// thresholding technique for servers and a fast one for mobile. It also permits the implementation 26 | /// to vary, e.g. a JNI version for Android and a Java fallback version for other platforms. 27 | /// 28 | /// dswitkin@google.com (Daniel Switkin) 29 | /// 30 | public abstract class Binarizer 31 | { 32 | private readonly LuminanceSource source; 33 | 34 | /// 35 | /// Initializes a new instance of the class. 36 | /// 37 | /// The source. 38 | protected internal Binarizer(LuminanceSource source) 39 | { 40 | if (source == null) 41 | { 42 | throw new ArgumentException("Source must be non-null."); 43 | } 44 | this.source = source; 45 | } 46 | 47 | /// 48 | /// Gets the luminance source object. 49 | /// 50 | virtual public LuminanceSource LuminanceSource 51 | { 52 | get 53 | { 54 | return source; 55 | } 56 | } 57 | 58 | /// Converts one row of luminance data to 1 bit data. May actually do the conversion, or return 59 | /// cached data. Callers should assume this method is expensive and call it as seldom as possible. 60 | /// This method is intended for decoding 1D barcodes and may choose to apply sharpening. 61 | /// For callers which only examine one row of pixels at a time, the same BitArray should be reused 62 | /// and passed in with each call for performance. However it is legal to keep more than one row 63 | /// at a time if needed. 64 | /// 65 | /// The row to fetch, 0 <= y < bitmap height. 66 | /// An optional preallocated array. If null or too small, it will be ignored. 67 | /// If used, the Binarizer will call BitArray.clear(). Always use the returned object. 68 | /// 69 | /// The array of bits for this row (true means black). 70 | public abstract BitArray getBlackRow(int y, BitArray row); 71 | 72 | /// Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive 73 | /// and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or 74 | /// may not apply sharpening. Therefore, a row from this matrix may not be identical to one 75 | /// fetched using getBlackRow(), so don't mix and match between them. 76 | /// 77 | /// The 2D array of bits for the image (true means black). 78 | public abstract BitMatrix BlackMatrix { get; } 79 | 80 | /// Creates a new object with the same type as this Binarizer implementation, but with pristine 81 | /// state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache 82 | /// of 1 bit data. See Effective Java for why we can't use Java's clone() method. 83 | /// 84 | /// The LuminanceSource this Binarizer will operate on. 85 | /// A new concrete Binarizer implementation object. 86 | public abstract Binarizer createBinarizer(LuminanceSource source); 87 | 88 | /// 89 | /// Gets the width of the luminance source object. 90 | /// 91 | public int Width 92 | { 93 | get { return source.Width; } 94 | } 95 | 96 | /// 97 | /// Gets the height of the luminance source object. 98 | /// 99 | public int Height 100 | { 101 | get { return source.Height; } 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/DecodeHintType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace ZXing 21 | { 22 | /// 23 | /// Encapsulates a type of hint that a caller may pass to a barcode reader to help it 24 | /// more quickly or accurately decode it. It is up to implementations to decide what, 25 | /// if anything, to do with the information that is supplied. 26 | /// 27 | /// 28 | /// Sean Owen 29 | /// dswitkin@google.com (Daniel Switkin) 30 | public enum DecodeHintType 31 | { 32 | /// 33 | /// Unspecified, application-specific hint. Maps to an unspecified . 34 | /// 35 | OTHER, 36 | 37 | /// 38 | /// Image is a pure monochrome image of a barcode. Doesn't matter what it maps to; 39 | /// use = true. 40 | /// 41 | PURE_BARCODE, 42 | 43 | /// 44 | /// Image is known to be of one of a few possible formats. 45 | /// Maps to a of s. 46 | /// 47 | POSSIBLE_FORMATS, 48 | 49 | /// 50 | /// Spend more time to try to find a barcode; optimize for accuracy, not speed. 51 | /// Doesn't matter what it maps to; use = true. 52 | /// 53 | TRY_HARDER, 54 | 55 | /// 56 | /// Specifies what character encoding to use when decoding, where applicable (type String) 57 | /// 58 | CHARACTER_SET, 59 | 60 | /// 61 | /// Allowed lengths of encoded data -- reject anything else. Maps to an int[]. 62 | /// 63 | ALLOWED_LENGTHS, 64 | 65 | /// 66 | /// Assume Code 39 codes employ a check digit. Maps to . 67 | /// 68 | ASSUME_CODE_39_CHECK_DIGIT, 69 | 70 | /// 71 | /// The caller needs to be notified via callback when a possible 72 | /// is found. Maps to a . 73 | /// 74 | NEED_RESULT_POINT_CALLBACK, 75 | 76 | /// 77 | /// Assume MSI codes employ a check digit. Maps to . 78 | /// 79 | ASSUME_MSI_CHECK_DIGIT, 80 | 81 | /// 82 | /// if Code39 could be detected try to use extended mode for full ASCII character set 83 | /// Maps to . 84 | /// 85 | USE_CODE_39_EXTENDED_MODE, 86 | 87 | /// 88 | /// Don't fail if a Code39 is detected but can't be decoded in extended mode. 89 | /// Return the raw Code39 result instead. Maps to . 90 | /// 91 | RELAXED_CODE_39_EXTENDED_MODE, 92 | 93 | /// 94 | /// 1D readers supporting rotation with TRY_HARDER enabled. 95 | /// But BarcodeReader class can do auto-rotating for 1D and 2D codes. 96 | /// Enabling that option prevents 1D readers doing double rotation. 97 | /// BarcodeReader enables that option automatically if "global" auto-rotation is enabled. 98 | /// Maps to . 99 | /// 100 | TRY_HARDER_WITHOUT_ROTATION, 101 | 102 | /// 103 | /// Assume the barcode is being processed as a GS1 barcode, and modify behavior as needed. 104 | /// For example this affects FNC1 handling for Code 128 (aka GS1-128). Doesn't matter what it maps to; 105 | /// use . 106 | /// 107 | ASSUME_GS1, 108 | 109 | /// 110 | /// If true, return the start and end digits in a Codabar barcode instead of stripping them. They 111 | /// are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them 112 | /// to not be. Doesn't matter what it maps to; use . 113 | /// 114 | RETURN_CODABAR_START_END, 115 | 116 | /// 117 | /// Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this. 118 | /// Maps to an of the allowed extension lengths, for example [2], [5], or [2, 5]. 119 | /// If it is optional to have an extension, do not set this hint. If this is set, 120 | /// and a UPC or EAN barcode is found but an extension is not, then no result will be returned 121 | /// at all. 122 | /// 123 | ALLOWED_EAN_EXTENSIONS 124 | } 125 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/EncodeHintType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | namespace ZXing 18 | { 19 | /// 20 | /// These are a set of hints that you may pass to Writers to specify their behavior. 21 | /// 22 | /// dswitkin@google.com (Daniel Switkin) 23 | public enum EncodeHintType 24 | { 25 | /// 26 | /// Specifies the width of the barcode image 27 | /// type: 28 | /// 29 | WIDTH, 30 | 31 | /// 32 | /// Specifies the height of the barcode image 33 | /// type: 34 | /// 35 | HEIGHT, 36 | 37 | /// 38 | /// Don't put the content string into the output image. 39 | /// type: 40 | /// 41 | PURE_BARCODE, 42 | 43 | /// 44 | /// Specifies what degree of error correction to use, for example in QR Codes. 45 | /// Type depends on the encoder. For example for QR codes it's type 46 | /// 47 | /// For Aztec it is of type , representing the minimal percentage of error correction words. 48 | /// Note: an Aztec symbol should have a minimum of 25% EC words. 49 | /// For PDF417 it is of type or (between 0 and 8), 50 | /// 51 | ERROR_CORRECTION, 52 | 53 | /// 54 | /// Specifies what character encoding to use where applicable. 55 | /// type: 56 | /// 57 | CHARACTER_SET, 58 | 59 | /// 60 | /// Specifies margin, in pixels, to use when generating the barcode. The meaning can vary 61 | /// by format; for example it controls margin before and after the barcode horizontally for 62 | /// most 1D formats. 63 | /// type: 64 | /// 65 | MARGIN, 66 | 67 | /// 68 | /// Specifies whether to use compact mode for PDF417. 69 | /// type: 70 | /// 71 | PDF417_COMPACT, 72 | 73 | /// 74 | /// Specifies what compaction mode to use for PDF417. 75 | /// type: 76 | /// 77 | PDF417_COMPACTION, 78 | 79 | /// 80 | /// Specifies the minimum and maximum number of rows and columns for PDF417. 81 | /// type: 82 | /// 83 | PDF417_DIMENSIONS, 84 | 85 | /// 86 | /// Don't append ECI segment. 87 | /// That is against the specification of QR Code but some 88 | /// readers have problems if the charset is switched from 89 | /// ISO-8859-1 (default) to UTF-8 with the necessary ECI segment. 90 | /// If you set the property to true you can use UTF-8 encoding 91 | /// and the ECI segment is omitted. 92 | /// type: 93 | /// 94 | DISABLE_ECI, 95 | 96 | /// 97 | /// Specifies the matrix shape for Data Matrix (type ) 98 | /// 99 | DATA_MATRIX_SHAPE, 100 | 101 | /// 102 | /// Specifies a minimum barcode size (type ). Only applicable to Data Matrix now. 103 | /// 104 | MIN_SIZE, 105 | 106 | /// 107 | /// Specifies a maximum barcode size (type ). Only applicable to Data Matrix now. 108 | /// 109 | MAX_SIZE, 110 | 111 | /// 112 | /// if true, don't switch to codeset C for numbers 113 | /// 114 | CODE128_FORCE_CODESET_B, 115 | 116 | /// 117 | /// Specifies the default encodation for Data Matrix (type ) 118 | /// Make sure that the content fits into the encodation value, otherwise there will be an exception thrown. 119 | /// standard value: Encodation.ASCII 120 | /// 121 | DATA_MATRIX_DEFAULT_ENCODATION, 122 | 123 | /// 124 | /// Specifies the required number of layers for an Aztec code: 125 | /// a negative number (-1, -2, -3, -4) specifies a compact Aztec code 126 | /// 0 indicates to use the minimum number of layers (the default) 127 | /// a positive number (1, 2, .. 32) specifies a normal (non-compact) Aztec code 128 | /// 129 | AZTEC_LAYERS, 130 | } 131 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/ResultMetadataType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | namespace ZXing 18 | { 19 | /// 20 | /// Represents some type of metadata about the result of the decoding that the decoder 21 | /// wishes to communicate back to the caller. 22 | /// 23 | /// Sean Owen 24 | public enum ResultMetadataType 25 | { 26 | /// 27 | /// Unspecified, application-specific metadata. Maps to an unspecified {@link Object}. 28 | /// 29 | OTHER, 30 | 31 | /// 32 | /// Denotes the likely approximate orientation of the barcode in the image. This value 33 | /// is given as degrees rotated clockwise from the normal, upright orientation. 34 | /// For example a 1D barcode which was found by reading top-to-bottom would be 35 | /// said to have orientation "90". This key maps to an {@link Integer} whose 36 | /// value is in the range [0,360). 37 | /// 38 | ORIENTATION, 39 | 40 | /// 41 | ///

2D barcode formats typically encode text, but allow for a sort of 'byte mode' 42 | /// which is sometimes used to encode binary data. While {@link Result} makes available 43 | /// the complete raw bytes in the barcode for these formats, it does not offer the bytes 44 | /// from the byte segments alone.

45 | ///

This maps to a {@link java.util.List} of byte arrays corresponding to the 46 | /// raw bytes in the byte segments in the barcode, in order.

47 | ///
48 | BYTE_SEGMENTS, 49 | 50 | /// 51 | /// Error correction level used, if applicable. The value type depends on the 52 | /// format, but is typically a String. 53 | /// 54 | ERROR_CORRECTION_LEVEL, 55 | 56 | /// 57 | /// For some periodicals, indicates the issue number as an {@link Integer}. 58 | /// 59 | ISSUE_NUMBER, 60 | 61 | /// 62 | /// For some products, indicates the suggested retail price in the barcode as a 63 | /// formatted {@link String}. 64 | /// 65 | SUGGESTED_PRICE, 66 | 67 | /// 68 | /// For some products, the possible country of manufacture as a {@link String} denoting the 69 | /// ISO country code. Some map to multiple possible countries, like "US/CA". 70 | /// 71 | POSSIBLE_COUNTRY, 72 | 73 | /// 74 | /// For some products, the extension text 75 | /// 76 | UPC_EAN_EXTENSION, 77 | 78 | /// 79 | /// If the code format supports structured append and 80 | /// the current scanned code is part of one then the 81 | /// sequence number is given with it. 82 | /// 83 | STRUCTURED_APPEND_SEQUENCE, 84 | 85 | /// 86 | /// If the code format supports structured append and 87 | /// the current scanned code is part of one then the 88 | /// parity is given with it. 89 | /// 90 | STRUCTURED_APPEND_PARITY, 91 | 92 | /// 93 | /// PDF417-specific metadata 94 | /// 95 | PDF417_EXTRA_METADATA, 96 | 97 | /// 98 | /// Aztec-specific metadata 99 | /// 100 | AZTEC_EXTRA_METADATA 101 | } 102 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/ResultPointCallback.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | namespace ZXing 18 | { 19 | /// Callback which is invoked when a possible result point (significant 20 | /// point in the barcode image such as a corner) is found. 21 | /// 22 | /// 23 | /// 24 | /// 25 | public delegate void ResultPointCallback(ResultPoint point); 26 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/WriterException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | 19 | namespace ZXing 20 | { 21 | /// 22 | /// A base class which covers the range of exceptions which may occur when encoding a barcode using 23 | /// the Writer framework. 24 | /// 25 | /// dswitkin@google.com (Daniel Switkin) 26 | [Serializable] 27 | public sealed class WriterException : Exception 28 | { 29 | /// 30 | /// Initializes a new instance of the class. 31 | /// 32 | public WriterException() 33 | { 34 | } 35 | 36 | /// 37 | /// Initializes a new instance of the class. 38 | /// 39 | /// The message. 40 | public WriterException(String message) 41 | :base(message) 42 | { 43 | } 44 | 45 | /// 46 | /// Initializes a new instance of the class. 47 | /// 48 | /// The message. 49 | /// The inner exc. 50 | public WriterException(String message, Exception innerExc) 51 | : base(message, innerExc) 52 | { 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/common/BitSource.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | 19 | namespace ZXing.Common 20 | { 21 | ///

This provides an easy abstraction to read bits at a time from a sequence of bytes, where the 22 | /// number of bits read is not often a multiple of 8.

23 | /// 24 | ///

This class is thread-safe but not reentrant. Unless the caller modifies the bytes array 25 | /// it passed in, in which case all bets are off.

26 | /// 27 | ///
28 | /// Sean Owen 29 | /// 30 | /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source 31 | /// 32 | public sealed class BitSource 33 | { 34 | private readonly byte[] bytes; 35 | private int byteOffset; 36 | private int bitOffset; 37 | 38 | /// bytes from which this will read bits. Bits will be read from the first byte first. 39 | /// Bits are read within a byte from most-significant to least-significant bit. 40 | /// 41 | public BitSource(byte[] bytes) 42 | { 43 | this.bytes = bytes; 44 | } 45 | 46 | /// 47 | /// index of next bit in current byte which would be read by the next call to {@link #readBits(int)}. 48 | /// 49 | public int BitOffset 50 | { 51 | get { return bitOffset; } 52 | } 53 | 54 | /// 55 | /// index of next byte in input byte array which would be read by the next call to {@link #readBits(int)}. 56 | /// 57 | public int ByteOffset 58 | { 59 | get { return byteOffset; } 60 | } 61 | 62 | /// number of bits to read 63 | /// 64 | /// int representing the bits read. The bits will appear as the least-significant 65 | /// bits of the int 66 | /// 67 | /// if numBits isn't in [1,32] or more than is available 68 | public int readBits(int numBits) 69 | { 70 | if (numBits < 1 || numBits > 32 || numBits > available()) 71 | { 72 | throw new ArgumentException(numBits.ToString(), "numBits"); 73 | } 74 | 75 | int result = 0; 76 | 77 | // First, read remainder from current byte 78 | if (bitOffset > 0) 79 | { 80 | int bitsLeft = 8 - bitOffset; 81 | int toRead = numBits < bitsLeft ? numBits : bitsLeft; 82 | int bitsToNotRead = bitsLeft - toRead; 83 | int mask = (0xFF >> (8 - toRead)) << bitsToNotRead; 84 | result = (bytes[byteOffset] & mask) >> bitsToNotRead; 85 | numBits -= toRead; 86 | bitOffset += toRead; 87 | if (bitOffset == 8) 88 | { 89 | bitOffset = 0; 90 | byteOffset++; 91 | } 92 | } 93 | 94 | // Next read whole bytes 95 | if (numBits > 0) 96 | { 97 | while (numBits >= 8) 98 | { 99 | result = (result << 8) | (bytes[byteOffset] & 0xFF); 100 | byteOffset++; 101 | numBits -= 8; 102 | } 103 | 104 | // Finally read a partial byte 105 | if (numBits > 0) 106 | { 107 | int bitsToNotRead = 8 - numBits; 108 | int mask = (0xFF >> bitsToNotRead) << bitsToNotRead; 109 | result = (result << numBits) | ((bytes[byteOffset] & mask) >> bitsToNotRead); 110 | bitOffset += numBits; 111 | } 112 | } 113 | 114 | return result; 115 | } 116 | 117 | /// number of bits that can be read successfully 118 | /// 119 | public int available() 120 | { 121 | return 8 * (bytes.Length - byteOffset) - bitOffset; 122 | } 123 | } 124 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/common/DecoderResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace ZXing.Common 21 | { 22 | /// 23 | /// Encapsulates the result of decoding a matrix of bits. This typically 24 | /// applies to 2D barcode formats. For now it contains the raw bytes obtained, 25 | /// as well as a String interpretation of those bytes, if applicable. 26 | /// Sean Owen 27 | /// 28 | public sealed class DecoderResult 29 | { 30 | public byte[] RawBytes { get; private set; } 31 | 32 | public String Text { get; private set; } 33 | 34 | public IList ByteSegments { get; private set; } 35 | 36 | public String ECLevel { get; private set; } 37 | 38 | public bool StructuredAppend 39 | { 40 | get { return StructuredAppendParity >= 0 && StructuredAppendSequenceNumber >= 0; } 41 | } 42 | 43 | public int ErrorsCorrected { get; set; } 44 | 45 | public int StructuredAppendSequenceNumber { get; private set; } 46 | 47 | public int Erasures { get; set; } 48 | 49 | public int StructuredAppendParity { get; private set; } 50 | 51 | /// 52 | /// Miscellanseous data value for the various decoders 53 | /// 54 | /// The other. 55 | public object Other { get; set; } 56 | 57 | public DecoderResult(byte[] rawBytes, String text, IList byteSegments, String ecLevel) 58 | : this(rawBytes, text, byteSegments, ecLevel, -1, -1) 59 | { 60 | } 61 | 62 | public DecoderResult(byte[] rawBytes, String text, IList byteSegments, String ecLevel, int saSequence, int saParity) 63 | { 64 | if (rawBytes == null && text == null) 65 | { 66 | throw new ArgumentException(); 67 | } 68 | RawBytes = rawBytes; 69 | Text = text; 70 | ByteSegments = byteSegments; 71 | ECLevel = ecLevel; 72 | StructuredAppendParity = saParity; 73 | StructuredAppendSequenceNumber = saSequence; 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/common/DefaultGridSampler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | using System; 17 | 18 | namespace ZXing.Common 19 | { 20 | 21 | /// Sean Owen 22 | /// 23 | /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source 24 | /// 25 | public sealed class DefaultGridSampler : GridSampler 26 | { 27 | public override BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, float p1ToX, float p1ToY, float p2ToX, float p2ToY, float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX, float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY) 28 | { 29 | PerspectiveTransform transform = PerspectiveTransform.quadrilateralToQuadrilateral( 30 | p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, 31 | p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY); 32 | return sampleGrid(image, dimensionX, dimensionY, transform); 33 | } 34 | 35 | public override BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, PerspectiveTransform transform) 36 | { 37 | if (dimensionX <= 0 || dimensionY <= 0) 38 | { 39 | return null; 40 | } 41 | BitMatrix bits = new BitMatrix(dimensionX, dimensionY); 42 | float[] points = new float[dimensionX << 1]; 43 | for (int y = 0; y < dimensionY; y++) 44 | { 45 | int max = points.Length; 46 | //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" 47 | float iValue = (float)y + 0.5f; 48 | for (int x = 0; x < max; x += 2) 49 | { 50 | //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" 51 | points[x] = (float)(x >> 1) + 0.5f; 52 | points[x + 1] = iValue; 53 | } 54 | transform.transformPoints(points); 55 | // Quick check to see if points transformed to something inside the image; 56 | // sufficient to check the endpoints 57 | if (!checkAndNudgePoints(image, points)) 58 | return null; 59 | try 60 | { 61 | for (int x = 0; x < max; x += 2) 62 | { 63 | //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" 64 | bits[x >> 1, y] = image[(int)points[x], (int)points[x + 1]]; 65 | } 66 | } 67 | catch (System.IndexOutOfRangeException) 68 | { 69 | // This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting 70 | // transform gets "twisted" such that it maps a straight line of points to a set of points 71 | // whose endpoints are in bounds, but others are not. There is probably some mathematical 72 | // way to detect this about the transformation that I don't know yet. 73 | // This results in an ugly runtime exception despite our clever checks above -- can't have 74 | // that. We could check each point's coordinates but that feels duplicative. We settle for 75 | // catching and wrapping ArrayIndexOutOfBoundsException. 76 | return null; 77 | } 78 | } 79 | return bits; 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/common/DetectorResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | namespace ZXing.Common 18 | { 19 | ///

Encapsulates the result of detecting a barcode in an image. This includes the raw 20 | /// matrix of black/white pixels corresponding to the barcode, and possibly points of interest 21 | /// in the image, like the location of finder patterns or corners of the barcode in the image.

22 | /// 23 | ///
24 | /// Sean Owen 25 | /// 26 | /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source 27 | /// 28 | public class DetectorResult 29 | { 30 | public BitMatrix Bits { get; private set; } 31 | public ResultPoint[] Points { get; private set; } 32 | 33 | public DetectorResult(BitMatrix bits, ResultPoint[] points) 34 | { 35 | Bits = bits; 36 | Points = points; 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/common/detector/MathUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | 19 | namespace ZXing.Common.Detector 20 | { 21 | public static class MathUtils 22 | { 23 | /// 24 | /// Ends up being a bit faster than {@link Math#round(float)}. This merely rounds its 25 | /// argument to the nearest int, where x.5 rounds up to x+1. 26 | /// 27 | /// The d. 28 | /// 29 | public static int round(float d) 30 | { 31 | return (int)(d + 0.5f); 32 | } 33 | 34 | public static float distance(float aX, float aY, float bX, float bY) 35 | { 36 | float xDiff = aX - bX; 37 | float yDiff = aY - bY; 38 | return (float)Math.Sqrt(xDiff * xDiff + yDiff * yDiff); 39 | } 40 | 41 | public static float distance(int aX, int aY, int bX, int bY) 42 | { 43 | int xDiff = aX - bX; 44 | int yDiff = aY - bY; 45 | return (float)Math.Sqrt(xDiff * xDiff + yDiff * yDiff); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/common/reedsolomon/ReedSolomonEncoder.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Collections.Generic; 19 | 20 | namespace ZXing.Common.ReedSolomon 21 | { 22 | /// 23 | /// Implements Reed-Solomon encoding, as the name implies. 24 | /// 25 | /// Sean Owen 26 | /// William Rucklidge 27 | public sealed class ReedSolomonEncoder 28 | { 29 | private readonly GenericGF field; 30 | private readonly IList cachedGenerators; 31 | 32 | public ReedSolomonEncoder(GenericGF field) 33 | { 34 | this.field = field; 35 | this.cachedGenerators = new List(); 36 | cachedGenerators.Add(new GenericGFPoly(field, new int[] { 1 })); 37 | } 38 | 39 | private GenericGFPoly buildGenerator(int degree) 40 | { 41 | if (degree >= cachedGenerators.Count) 42 | { 43 | var lastGenerator = cachedGenerators[cachedGenerators.Count - 1]; 44 | for (int d = cachedGenerators.Count; d <= degree; d++) 45 | { 46 | var nextGenerator = lastGenerator.multiply(new GenericGFPoly(field, new int[] { 1, field.exp(d - 1 + field.GeneratorBase) })); 47 | cachedGenerators.Add(nextGenerator); 48 | lastGenerator = nextGenerator; 49 | } 50 | } 51 | return cachedGenerators[degree]; 52 | } 53 | 54 | public void encode(int[] toEncode, int ecBytes) 55 | { 56 | if (ecBytes == 0) 57 | { 58 | throw new ArgumentException("No error correction bytes"); 59 | } 60 | var dataBytes = toEncode.Length - ecBytes; 61 | if (dataBytes <= 0) 62 | { 63 | throw new ArgumentException("No data bytes provided"); 64 | } 65 | 66 | var generator = buildGenerator(ecBytes); 67 | var infoCoefficients = new int[dataBytes]; 68 | Array.Copy(toEncode, 0, infoCoefficients, 0, dataBytes); 69 | 70 | var info = new GenericGFPoly(field, infoCoefficients); 71 | info = info.multiplyByMonomial(ecBytes, 1); 72 | 73 | var remainder = info.divide(generator)[1]; 74 | var coefficients = remainder.Coefficients; 75 | var numZeroCoefficients = ecBytes - coefficients.Length; 76 | for (var i = 0; i < numZeroCoefficients; i++) 77 | { 78 | toEncode[dataBytes + i] = 0; 79 | } 80 | 81 | Array.Copy(coefficients, 0, toEncode, dataBytes + numZeroCoefficients, coefficients.Length); 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/qrcode/decoder/ErrorCorrectionLevel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | 19 | namespace ZXing.QrCode.Internal 20 | { 21 | /// 22 | ///

See ISO 18004:2006, 6.5.1. This enum encapsulates the four error correction levels 23 | /// defined by the QR code standard.

24 | ///
25 | /// Sean Owen 26 | public sealed class ErrorCorrectionLevel 27 | { 28 | /// L = ~7% correction 29 | public static readonly ErrorCorrectionLevel L = new ErrorCorrectionLevel(0, 0x01, "L"); 30 | /// M = ~15% correction 31 | public static readonly ErrorCorrectionLevel M = new ErrorCorrectionLevel(1, 0x00, "M"); 32 | /// Q = ~25% correction 33 | public static readonly ErrorCorrectionLevel Q = new ErrorCorrectionLevel(2, 0x03, "Q"); 34 | /// H = ~30% correction 35 | public static readonly ErrorCorrectionLevel H = new ErrorCorrectionLevel(3, 0x02, "H"); 36 | 37 | private static readonly ErrorCorrectionLevel[] FOR_BITS = new [] { M, L, H, Q }; 38 | 39 | private readonly int bits; 40 | 41 | private ErrorCorrectionLevel(int ordinal, int bits, String name) 42 | { 43 | this.ordinal_Renamed_Field = ordinal; 44 | this.bits = bits; 45 | this.name = name; 46 | } 47 | 48 | /// 49 | /// Gets the bits. 50 | /// 51 | public int Bits 52 | { 53 | get 54 | { 55 | return bits; 56 | } 57 | } 58 | 59 | /// 60 | /// Gets the name. 61 | /// 62 | public String Name 63 | { 64 | get 65 | { 66 | return name; 67 | } 68 | } 69 | 70 | private readonly int ordinal_Renamed_Field; 71 | private readonly String name; 72 | 73 | /// 74 | /// Ordinals this instance. 75 | /// 76 | /// 77 | public int ordinal() 78 | { 79 | return ordinal_Renamed_Field; 80 | } 81 | 82 | /// 83 | /// Returns a that represents this instance. 84 | /// 85 | /// 86 | /// A that represents this instance. 87 | /// 88 | public override String ToString() 89 | { 90 | return name; 91 | } 92 | 93 | /// 94 | /// Fors the bits. 95 | /// 96 | /// int containing the two bits encoding a QR Code's error correction level 97 | /// 98 | /// representing the encoded error correction level 99 | /// 100 | public static ErrorCorrectionLevel forBits(int bits) 101 | { 102 | if (bits < 0 || bits >= FOR_BITS.Length) 103 | { 104 | throw new ArgumentException(); 105 | } 106 | return FOR_BITS[bits]; 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/qrcode/decoder/QRCodeDecoderMetaData.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | namespace ZXing.QrCode.Internal 18 | { 19 | /// 20 | /// Meta-data container for QR Code decoding. Instances of this class may be used to convey information back to the 21 | /// decoding caller. Callers are expected to process this. 22 | /// 23 | public sealed class QRCodeDecoderMetaData 24 | { 25 | private readonly bool mirrored; 26 | 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// if set to true [mirrored]. 31 | public QRCodeDecoderMetaData(bool mirrored) 32 | { 33 | this.mirrored = mirrored; 34 | } 35 | 36 | /// 37 | /// true if the QR Code was mirrored. 38 | /// 39 | public bool IsMirrored 40 | { 41 | get { return mirrored; } 42 | } 43 | 44 | /// 45 | /// Apply the result points' order correction due to mirroring. 46 | /// 47 | /// Array of points to apply mirror correction to. 48 | public void applyMirroredCorrection(ResultPoint[] points) 49 | { 50 | if (!mirrored || points == null || points.Length < 3) 51 | { 52 | return; 53 | } 54 | ResultPoint bottomLeft = points[0]; 55 | points[0] = points[2]; 56 | points[2] = bottomLeft; 57 | // No need to 'fix' top-left and alignment pattern. 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/qrcode/detector/AlignmentPattern.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | 19 | namespace ZXing.QrCode.Internal 20 | { 21 | ///

Encapsulates an alignment pattern, which are the smaller square patterns found in 22 | /// all but the simplest QR Codes.

23 | /// 24 | ///
25 | /// Sean Owen 26 | /// 27 | /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source 28 | /// 29 | public sealed class AlignmentPattern : ResultPoint 30 | { 31 | private float estimatedModuleSize; 32 | 33 | internal AlignmentPattern(float posX, float posY, float estimatedModuleSize) 34 | : base(posX, posY) 35 | { 36 | this.estimatedModuleSize = estimatedModuleSize; 37 | } 38 | 39 | ///

Determines if this alignment pattern "about equals" an alignment pattern at the stated 40 | /// position and size -- meaning, it is at nearly the same center with nearly the same size.

41 | ///
42 | internal bool aboutEquals(float moduleSize, float i, float j) 43 | { 44 | if (Math.Abs(i - Y) <= moduleSize && Math.Abs(j - X) <= moduleSize) 45 | { 46 | float moduleSizeDiff = Math.Abs(moduleSize - estimatedModuleSize); 47 | return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize; 48 | } 49 | return false; 50 | } 51 | 52 | /// 53 | /// Combines this object's current estimate of a finder pattern position and module size 54 | /// with a new estimate. It returns a new {@code FinderPattern} containing an average of the two. 55 | /// 56 | /// The i. 57 | /// The j. 58 | /// New size of the module. 59 | /// 60 | internal AlignmentPattern combineEstimate(float i, float j, float newModuleSize) 61 | { 62 | float combinedX = (X + j) / 2.0f; 63 | float combinedY = (Y + i) / 2.0f; 64 | float combinedModuleSize = (estimatedModuleSize + newModuleSize) / 2.0f; 65 | return new AlignmentPattern(combinedX, combinedY, combinedModuleSize); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPattern.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | 19 | namespace ZXing.QrCode.Internal 20 | { 21 | /// 22 | ///

Encapsulates a finder pattern, which are the three square patterns found in 23 | /// the corners of QR Codes. It also encapsulates a count of similar finder patterns, 24 | /// as a convenience to the finder's bookkeeping.

25 | ///
26 | /// Sean Owen 27 | public sealed class FinderPattern : ResultPoint 28 | { 29 | private readonly float estimatedModuleSize; 30 | private int count; 31 | 32 | internal FinderPattern(float posX, float posY, float estimatedModuleSize) 33 | : this(posX, posY, estimatedModuleSize, 1) 34 | { 35 | this.estimatedModuleSize = estimatedModuleSize; 36 | this.count = 1; 37 | } 38 | 39 | internal FinderPattern(float posX, float posY, float estimatedModuleSize, int count) 40 | : base(posX, posY) 41 | { 42 | this.estimatedModuleSize = estimatedModuleSize; 43 | this.count = count; 44 | } 45 | 46 | /// 47 | /// Gets the size of the estimated module. 48 | /// 49 | /// 50 | /// The size of the estimated module. 51 | /// 52 | public float EstimatedModuleSize 53 | { 54 | get 55 | { 56 | return estimatedModuleSize; 57 | } 58 | } 59 | 60 | internal int Count 61 | { 62 | get 63 | { 64 | return count; 65 | } 66 | } 67 | 68 | /* 69 | internal void incrementCount() 70 | { 71 | this.count++; 72 | } 73 | */ 74 | 75 | ///

Determines if this finder pattern "about equals" a finder pattern at the stated 76 | /// position and size -- meaning, it is at nearly the same center with nearly the same size.

77 | ///
78 | internal bool aboutEquals(float moduleSize, float i, float j) 79 | { 80 | if (Math.Abs(i - Y) <= moduleSize && Math.Abs(j - X) <= moduleSize) 81 | { 82 | float moduleSizeDiff = Math.Abs(moduleSize - estimatedModuleSize); 83 | return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize; 84 | 85 | } 86 | return false; 87 | } 88 | 89 | /// 90 | /// Combines this object's current estimate of a finder pattern position and module size 91 | /// with a new estimate. It returns a new {@code FinderPattern} containing a weighted average 92 | /// based on count. 93 | /// 94 | /// The i. 95 | /// The j. 96 | /// New size of the module. 97 | /// 98 | internal FinderPattern combineEstimate(float i, float j, float newModuleSize) 99 | { 100 | int combinedCount = count + 1; 101 | float combinedX = (count * X + j) / combinedCount; 102 | float combinedY = (count * Y + i) / combinedCount; 103 | float combinedModuleSize = (count * estimatedModuleSize + newModuleSize) / combinedCount; 104 | return new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount); 105 | } 106 | } 107 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPatternInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | namespace ZXing.QrCode.Internal 18 | { 19 | /// 20 | ///

Encapsulates information about finder patterns in an image, including the location of 21 | /// the three finder patterns, and their estimated module size.

22 | ///
23 | /// Sean Owen 24 | public sealed class FinderPatternInfo 25 | { 26 | private readonly FinderPattern bottomLeft; 27 | private readonly FinderPattern topLeft; 28 | private readonly FinderPattern topRight; 29 | 30 | /// 31 | /// Initializes a new instance of the class. 32 | /// 33 | /// The pattern centers. 34 | public FinderPatternInfo(FinderPattern[] patternCenters) 35 | { 36 | this.bottomLeft = patternCenters[0]; 37 | this.topLeft = patternCenters[1]; 38 | this.topRight = patternCenters[2]; 39 | } 40 | 41 | /// 42 | /// Gets the bottom left. 43 | /// 44 | public FinderPattern BottomLeft 45 | { 46 | get 47 | { 48 | return bottomLeft; 49 | } 50 | } 51 | 52 | /// 53 | /// Gets the top left. 54 | /// 55 | public FinderPattern TopLeft 56 | { 57 | get 58 | { 59 | return topLeft; 60 | } 61 | } 62 | 63 | /// 64 | /// Gets the top right. 65 | /// 66 | public FinderPattern TopRight 67 | { 68 | get 69 | { 70 | return topRight; 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/qrcode/encoder/BlockPair.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | namespace ZXing.QrCode.Internal 18 | { 19 | internal sealed class BlockPair 20 | { 21 | private readonly byte[] dataBytes; 22 | private readonly byte[] errorCorrectionBytes; 23 | 24 | public BlockPair(byte[] data, byte[] errorCorrection) 25 | { 26 | dataBytes = data; 27 | errorCorrectionBytes = errorCorrection; 28 | } 29 | 30 | public byte[] DataBytes 31 | { 32 | get { return dataBytes; } 33 | } 34 | 35 | public byte[] ErrorCorrectionBytes 36 | { 37 | get { return errorCorrectionBytes; } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/qrcode/encoder/ByteMatrix.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Text; 19 | 20 | namespace ZXing.QrCode.Internal 21 | { 22 | /// 23 | /// JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned 24 | /// 0, 1 and 2 I'm going to use less memory and go with bytes. 25 | /// 26 | /// dswitkin@google.com (Daniel Switkin) 27 | public sealed class ByteMatrix 28 | { 29 | private readonly byte[][] bytes; 30 | private readonly int width; 31 | private readonly int height; 32 | 33 | /// 34 | /// Initializes a new instance of the class. 35 | /// 36 | /// The width. 37 | /// The height. 38 | public ByteMatrix(int width, int height) 39 | { 40 | bytes = new byte[height][]; 41 | for (var i = 0; i < height; i++) 42 | bytes[i] = new byte[width]; 43 | this.width = width; 44 | this.height = height; 45 | } 46 | 47 | /// 48 | /// Gets the height. 49 | /// 50 | public int Height 51 | { 52 | get { return height; } 53 | } 54 | 55 | /// 56 | /// Gets the width. 57 | /// 58 | public int Width 59 | { 60 | get { return width; } 61 | } 62 | 63 | /// 64 | /// Gets or sets the with the specified x. 65 | /// 66 | public int this[int x, int y] 67 | { 68 | get { return bytes[y][x]; } 69 | set { bytes[y][x] = (byte)value; } 70 | } 71 | 72 | /// 73 | /// an internal representation as bytes, in row-major order. array[y][x] represents point (x,y) 74 | /// 75 | public byte[][] Array 76 | { 77 | get { return bytes; } 78 | } 79 | 80 | /// 81 | /// Sets the specified x. 82 | /// 83 | /// The x. 84 | /// The y. 85 | /// The value. 86 | public void set(int x, int y, byte value) 87 | { 88 | bytes[y][x] = value; 89 | } 90 | 91 | /// 92 | /// Sets the specified x. 93 | /// 94 | /// The x. 95 | /// The y. 96 | /// if set to true [value]. 97 | public void set(int x, int y, bool value) 98 | { 99 | bytes[y][x] = (byte)(value ? 1 : 0); 100 | } 101 | 102 | /// 103 | /// Clears the specified value. 104 | /// 105 | /// The value. 106 | public void clear(byte value) 107 | { 108 | for (int y = 0; y < height; ++y) 109 | { 110 | for (int x = 0; x < width; ++x) 111 | { 112 | bytes[y][x] = value; 113 | } 114 | } 115 | } 116 | 117 | /// 118 | /// Returns a that represents this instance. 119 | /// 120 | /// 121 | /// A that represents this instance. 122 | /// 123 | override public String ToString() 124 | { 125 | var result = new StringBuilder(2 * width * height + 2); 126 | for (int y = 0; y < height; ++y) 127 | { 128 | for (int x = 0; x < width; ++x) 129 | { 130 | switch (bytes[y][x]) 131 | { 132 | case 0: 133 | result.Append(" 0"); 134 | break; 135 | case 1: 136 | result.Append(" 1"); 137 | break; 138 | default: 139 | result.Append(" "); 140 | break; 141 | } 142 | } 143 | result.Append('\n'); 144 | } 145 | return result.ToString(); 146 | } 147 | } 148 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/3rd/zxing/qrcode/encoder/QRCode.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 ZXing authors 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | using System; 18 | using System.Text; 19 | 20 | namespace ZXing.QrCode.Internal 21 | { 22 | /// satorux@google.com (Satoru Takabayashi) - creator 23 | /// dswitkin@google.com (Daniel Switkin) - ported from C++ 24 | public sealed class QRCode 25 | { 26 | /// 27 | /// 28 | /// 29 | public static int NUM_MASK_PATTERNS = 8; 30 | 31 | /// 32 | /// Initializes a new instance of the class. 33 | /// 34 | public QRCode() 35 | { 36 | MaskPattern = -1; 37 | } 38 | 39 | /// 40 | /// Gets or sets the mode. 41 | /// 42 | /// 43 | /// The mode. 44 | /// 45 | public Mode Mode { get; set; } 46 | 47 | /// 48 | /// Gets or sets the EC level. 49 | /// 50 | /// 51 | /// The EC level. 52 | /// 53 | public ErrorCorrectionLevel ECLevel { get; set; } 54 | 55 | /// 56 | /// Gets or sets the version. 57 | /// 58 | /// 59 | /// The version. 60 | /// 61 | public Version Version { get; set; } 62 | 63 | /// 64 | /// Gets or sets the mask pattern. 65 | /// 66 | /// 67 | /// The mask pattern. 68 | /// 69 | public int MaskPattern { get; set; } 70 | 71 | /// 72 | /// Gets or sets the matrix. 73 | /// 74 | /// 75 | /// The matrix. 76 | /// 77 | public ByteMatrix Matrix { get; set; } 78 | 79 | /// 80 | /// Returns a that represents this instance. 81 | /// 82 | /// 83 | /// A that represents this instance. 84 | /// 85 | public override String ToString() 86 | { 87 | var result = new StringBuilder(200); 88 | result.Append("<<\n"); 89 | result.Append(" mode: "); 90 | result.Append(Mode); 91 | result.Append("\n ecLevel: "); 92 | result.Append(ECLevel); 93 | result.Append("\n version: "); 94 | if (Version == null) 95 | result.Append("null"); 96 | else 97 | result.Append(Version); 98 | result.Append("\n maskPattern: "); 99 | result.Append(MaskPattern); 100 | if (Matrix == null) 101 | { 102 | result.Append("\n matrix: null\n"); 103 | } 104 | else 105 | { 106 | result.Append("\n matrix:\n"); 107 | result.Append(Matrix.ToString()); 108 | } 109 | result.Append(">>\n"); 110 | return result.ToString(); 111 | } 112 | 113 | /// 114 | /// Check if "mask_pattern" is valid. 115 | /// 116 | /// The mask pattern. 117 | /// 118 | /// true if [is valid mask pattern] [the specified mask pattern]; otherwise, false. 119 | /// 120 | public static bool isValidMaskPattern(int maskPattern) 121 | { 122 | return maskPattern >= 0 && maskPattern < NUM_MASK_PATTERNS; 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/Controller/AutoStartup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using Microsoft.Win32; 4 | 5 | namespace Shadowsocks.Controller 6 | { 7 | class AutoStartup 8 | { 9 | static string Key = "ShadowsocksR_" + Application.StartupPath.GetHashCode(); 10 | static string RegistryRunPath = (IntPtr.Size == 4 ? @"Software\Microsoft\Windows\CurrentVersion\Run" : @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run"); 11 | 12 | public static bool Set(bool enabled) 13 | { 14 | RegistryKey runKey = null; 15 | try 16 | { 17 | string path = Util.Utils.GetExecutablePath(); 18 | runKey = Registry.LocalMachine.OpenSubKey(RegistryRunPath, true); 19 | if (enabled) 20 | { 21 | runKey.SetValue(Key, path); 22 | } 23 | else 24 | { 25 | runKey.DeleteValue(Key); 26 | } 27 | runKey.Close(); 28 | return true; 29 | } 30 | catch //(Exception e) 31 | { 32 | //Logging.LogUsefulException(e); 33 | return Util.Utils.RunAsAdmin("--setautorun") == 0; 34 | } 35 | finally 36 | { 37 | if (runKey != null) 38 | { 39 | try 40 | { 41 | runKey.Close(); 42 | } 43 | catch (Exception e) 44 | { 45 | Logging.LogUsefulException(e); 46 | } 47 | } 48 | } 49 | } 50 | 51 | public static bool Switch() 52 | { 53 | bool enabled = !Check(); 54 | RegistryKey runKey = null; 55 | try 56 | { 57 | string path = Util.Utils.GetExecutablePath(); 58 | runKey = Registry.LocalMachine.OpenSubKey(RegistryRunPath, true); 59 | if (enabled) 60 | { 61 | runKey.SetValue(Key, path); 62 | } 63 | else 64 | { 65 | runKey.DeleteValue(Key); 66 | } 67 | runKey.Close(); 68 | return true; 69 | } 70 | catch (Exception e) 71 | { 72 | Logging.LogUsefulException(e); 73 | return false; 74 | } 75 | finally 76 | { 77 | if (runKey != null) 78 | { 79 | try 80 | { 81 | runKey.Close(); 82 | } 83 | catch (Exception e) 84 | { 85 | Logging.LogUsefulException(e); 86 | } 87 | } 88 | } 89 | } 90 | 91 | public static bool Check() 92 | { 93 | RegistryKey runKey = null; 94 | try 95 | { 96 | string path = Util.Utils.GetExecutablePath(); 97 | runKey = Registry.LocalMachine.OpenSubKey(RegistryRunPath, false); 98 | string[] runList = runKey.GetValueNames(); 99 | runKey.Close(); 100 | foreach (string item in runList) 101 | { 102 | if (item.Equals(Key)) 103 | return true; 104 | } 105 | return false; 106 | } 107 | catch (Exception e) 108 | { 109 | Logging.LogUsefulException(e); 110 | return false; 111 | } 112 | finally 113 | { 114 | if (runKey != null) 115 | { 116 | try 117 | { 118 | runKey.Close(); 119 | } 120 | catch (Exception e) 121 | { 122 | Logging.LogUsefulException(e); 123 | } 124 | } 125 | } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Controller/FileManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.IO.Compression; 5 | using System.Text; 6 | 7 | namespace Shadowsocks.Controller 8 | { 9 | public class FileManager 10 | { 11 | public static bool ByteArrayToFile(string fileName, byte[] content) 12 | { 13 | try 14 | { 15 | System.IO.FileStream _FileStream = 16 | new System.IO.FileStream(fileName, System.IO.FileMode.Create, 17 | System.IO.FileAccess.Write); 18 | _FileStream.Write(content, 0, content.Length); 19 | _FileStream.Close(); 20 | return true; 21 | } 22 | catch (Exception _Exception) 23 | { 24 | Console.WriteLine("Exception caught in process: {0}", 25 | _Exception.ToString()); 26 | } 27 | return false; 28 | } 29 | 30 | public static void UncompressFile(string fileName, byte[] content) 31 | { 32 | FileStream destinationFile = File.Create(fileName); 33 | 34 | // Because the uncompressed size of the file is unknown, 35 | // we are using an arbitrary buffer size. 36 | byte[] buffer = new byte[4096]; 37 | int n; 38 | 39 | using (GZipStream input = new GZipStream(new MemoryStream(content), 40 | CompressionMode.Decompress, false)) 41 | { 42 | while (true) 43 | { 44 | n = input.Read(buffer, 0, buffer.Length); 45 | if (n == 0) 46 | { 47 | break; 48 | } 49 | destinationFile.Write(buffer, 0, n); 50 | } 51 | } 52 | destinationFile.Close(); 53 | } 54 | 55 | public static byte[] DeflateCompress(byte[] content, int index, int count, out int size) 56 | { 57 | size = 0; 58 | try 59 | { 60 | MemoryStream memStream = new MemoryStream(); 61 | using (DeflateStream ds = new DeflateStream(memStream, CompressionMode.Compress)) 62 | { 63 | ds.Write(content, index, count); 64 | } 65 | byte[] buffer = memStream.ToArray(); 66 | size = buffer.Length; 67 | return buffer; 68 | } 69 | catch (Exception _Exception) 70 | { 71 | Console.WriteLine("Exception caught in process: {0}", 72 | _Exception.ToString()); 73 | } 74 | return null; 75 | } 76 | public static byte[] DeflateDecompress(byte[] content, int index, int count, out int size) 77 | { 78 | size = 0; 79 | try 80 | { 81 | byte[] buffer = new byte[16384]; 82 | DeflateStream ds = new DeflateStream(new MemoryStream(content, index, count), CompressionMode.Decompress); 83 | int readsize; 84 | while (true) 85 | { 86 | readsize = ds.Read(buffer, size, buffer.Length - size); 87 | if (readsize == 0) 88 | { 89 | break; 90 | } 91 | size += readsize; 92 | byte[] newbuffer = new byte[buffer.Length * 2]; 93 | buffer.CopyTo(newbuffer, 0); 94 | buffer = newbuffer; 95 | } 96 | return buffer; 97 | } 98 | catch (Exception _Exception) 99 | { 100 | Console.WriteLine("Exception caught in process: {0}", 101 | _Exception.ToString()); 102 | } 103 | return null; 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Controller/I18N.cs: -------------------------------------------------------------------------------- 1 | using Shadowsocks.Properties; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | 7 | namespace Shadowsocks.Controller 8 | { 9 | public class I18N 10 | { 11 | protected static Dictionary Strings; 12 | 13 | static void Init(string res) 14 | { 15 | string[] lines = Regex.Split(res, "\r\n|\r|\n"); 16 | foreach (string line in lines) 17 | { 18 | if (line.StartsWith("#")) 19 | { 20 | continue; 21 | } 22 | string[] kv = Regex.Split(line, "="); 23 | if (kv.Length == 2) 24 | { 25 | string val = Regex.Replace(kv[1], "\\\\n", "\r\n"); 26 | Strings[kv[0]] = val; 27 | } 28 | } 29 | } 30 | static I18N() 31 | { 32 | Strings = new Dictionary(); 33 | 34 | //if (System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag.ToLowerInvariant().StartsWith("zh")) 35 | string name = System.Globalization.CultureInfo.CurrentCulture.Name; 36 | if (name.StartsWith("zh")) 37 | { 38 | if (name == "zh" || name == "zh-CN") 39 | { 40 | Init(Resources.cn); 41 | } 42 | else 43 | { 44 | Init(Resources.zh_tw); 45 | } 46 | } 47 | } 48 | 49 | public static string GetString(string key) 50 | { 51 | if (Strings.ContainsKey(key)) 52 | { 53 | return Strings[key]; 54 | } 55 | else 56 | { 57 | return key; 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Controller/UpdateFreeNode.cs: -------------------------------------------------------------------------------- 1 | using Shadowsocks.Model; 2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Net; 6 | using System.Reflection; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | using System.Xml; 10 | using System.Windows.Forms; 11 | 12 | namespace Shadowsocks.Controller 13 | { 14 | public class UpdateFreeNode 15 | { 16 | private const string UpdateURL = "https://raw.githubusercontent.com/breakwa11/breakwa11.github.io/master/free/freenodeplain.txt"; 17 | 18 | public event EventHandler NewFreeNodeFound; 19 | public string FreeNodeResult; 20 | 21 | public const string Name = "ShadowsocksR"; 22 | 23 | public void CheckUpdate(Configuration config, string URL, bool use_proxy) 24 | { 25 | FreeNodeResult = null; 26 | try 27 | { 28 | WebClient http = new WebClient(); 29 | http.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.3319.102 Safari/537.36"); 30 | http.QueryString["rnd"] = Util.Utils.RandUInt32().ToString(); 31 | if (use_proxy) 32 | { 33 | WebProxy proxy = new WebProxy(IPAddress.Loopback.ToString(), config.localPort); 34 | if (!string.IsNullOrEmpty(config.authPass)) 35 | { 36 | proxy.Credentials = new NetworkCredential(config.authUser, config.authPass); 37 | } 38 | http.Proxy = proxy; 39 | } 40 | else 41 | { 42 | http.Proxy = null; 43 | } 44 | //UseProxy = !UseProxy; 45 | http.DownloadStringCompleted += http_DownloadStringCompleted; 46 | http.DownloadStringAsync(new Uri(URL != null ? URL : UpdateURL)); 47 | } 48 | catch (Exception e) 49 | { 50 | Logging.LogUsefulException(e); 51 | } 52 | } 53 | 54 | private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 55 | { 56 | try 57 | { 58 | string response = e.Result; 59 | FreeNodeResult = response; 60 | 61 | if (NewFreeNodeFound != null) 62 | { 63 | NewFreeNodeFound(this, new EventArgs()); 64 | } 65 | } 66 | catch (Exception ex) 67 | { 68 | if (e.Error != null) 69 | { 70 | Logging.Debug(e.Error.ToString()); 71 | } 72 | Logging.Debug(ex.ToString()); 73 | if (NewFreeNodeFound != null) 74 | { 75 | NewFreeNodeFound(this, new EventArgs()); 76 | } 77 | return; 78 | } 79 | } 80 | } 81 | 82 | public class UpdateSubscribeManager 83 | { 84 | Configuration _config; 85 | List _serverSubscribes; 86 | UpdateFreeNode _updater; 87 | string _URL; 88 | bool _use_proxy; 89 | 90 | public void CreateTask(Configuration config, UpdateFreeNode updater, int index, bool use_proxy) 91 | { 92 | if (_config == null) 93 | { 94 | _config = config; 95 | _updater = updater; 96 | _use_proxy = use_proxy; 97 | if (index < 0) 98 | { 99 | _serverSubscribes = new List(); 100 | for (int i = 0; i < config.serverSubscribes.Count; ++i) 101 | { 102 | _serverSubscribes.Add(config.serverSubscribes[i]); 103 | } 104 | } 105 | else if (index < _config.serverSubscribes.Count) 106 | { 107 | _serverSubscribes = new List(); 108 | _serverSubscribes.Add(config.serverSubscribes[index]); 109 | } 110 | Next(); 111 | } 112 | } 113 | 114 | public bool Next() 115 | { 116 | if (_serverSubscribes.Count == 0) 117 | { 118 | _config = null; 119 | return false; 120 | } 121 | else 122 | { 123 | _URL = _serverSubscribes[0].URL; 124 | _updater.CheckUpdate(_config, _URL, _use_proxy); 125 | _serverSubscribes.RemoveAt(0); 126 | return true; 127 | } 128 | } 129 | 130 | public string URL 131 | { 132 | get 133 | { 134 | return _URL; 135 | } 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Data/libsscrypto.dll.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/Data/libsscrypto.dll.gz -------------------------------------------------------------------------------- /shadowsocks-csharp/Data/libsscrypto64.dll.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/Data/libsscrypto64.dll.gz -------------------------------------------------------------------------------- /shadowsocks-csharp/Data/mgwz.dll.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/Data/mgwz.dll.gz -------------------------------------------------------------------------------- /shadowsocks-csharp/Data/privoxy.exe.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/Data/privoxy.exe.gz -------------------------------------------------------------------------------- /shadowsocks-csharp/Data/privoxy_conf.txt: -------------------------------------------------------------------------------- 1 | listen-address __PRIVOXY_BIND_IP__:__PRIVOXY_BIND_PORT__ 2 | show-on-task-bar 0 3 | activity-animation 0 4 | forward-socks5 / 127.0.0.1:__SOCKS_PORT__ . 5 | hide-console 6 | __BYPASS_ACTION__ 7 | 8 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Data/proxy.pac.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/Data/proxy.pac.txt.gz -------------------------------------------------------------------------------- /shadowsocks-csharp/Data/user-rule.txt: -------------------------------------------------------------------------------- 1 | ! Put user rules line by line in this file. 2 | ! See https://adblockplus.org/en/filter-cheatsheet 3 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Encryption/EncryptorBase.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Cryptography; 2 | using System.Text; 3 | 4 | namespace Shadowsocks.Encryption 5 | { 6 | public struct EncryptorInfo 7 | { 8 | public int key_size; 9 | public int iv_size; 10 | public bool display; 11 | public int type; 12 | public string name; 13 | 14 | public EncryptorInfo(int key, int iv, bool display, int type, string name = "") 15 | { 16 | key_size = key; 17 | iv_size = iv; 18 | this.display = display; 19 | this.type = type; 20 | this.name = name; 21 | } 22 | } 23 | public abstract class EncryptorBase 24 | : IEncryptor 25 | { 26 | public const int MAX_INPUT_SIZE = 65536; 27 | 28 | protected EncryptorBase(string method, string password) 29 | { 30 | Method = method; 31 | Password = password; 32 | } 33 | 34 | protected string Method; 35 | protected string Password; 36 | 37 | protected byte[] GetPasswordHash() 38 | { 39 | byte[] inputBytes = Encoding.UTF8.GetBytes(Password); 40 | byte[] hash = MbedTLS.MD5(inputBytes); 41 | return hash; 42 | } 43 | public abstract bool SetIV(byte[] iv); 44 | public abstract void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength); 45 | 46 | public abstract void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength); 47 | public abstract void ResetEncrypt(); 48 | public abstract void ResetDecrypt(); 49 | 50 | public abstract void Dispose(); 51 | public abstract byte[] getIV(); 52 | public abstract byte[] getKey(); 53 | public abstract EncryptorInfo getInfo(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Encryption/EncryptorFactory.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | namespace Shadowsocks.Encryption 6 | { 7 | public static class EncryptorFactory 8 | { 9 | private static Dictionary _registeredEncryptors; 10 | private static List _registeredEncryptorNames; 11 | 12 | private static Type[] _constructorTypes = new Type[] { typeof(string), typeof(string) }; 13 | 14 | static EncryptorFactory() 15 | { 16 | _registeredEncryptors = new Dictionary(); 17 | _registeredEncryptorNames = new List(); 18 | foreach (string method in NoneEncryptor.SupportedCiphers()) 19 | { 20 | if (!_registeredEncryptorNames.Contains(method)) 21 | { 22 | _registeredEncryptorNames.Add(method); 23 | _registeredEncryptors.Add(method, typeof(NoneEncryptor)); 24 | } 25 | } 26 | 27 | { 28 | foreach (string method in MbedTLSEncryptor.SupportedCiphers()) 29 | { 30 | if (!_registeredEncryptorNames.Contains(method)) 31 | { 32 | _registeredEncryptorNames.Add(method); 33 | _registeredEncryptors.Add(method, typeof(MbedTLSEncryptor)); 34 | } 35 | } 36 | } 37 | if (LibcryptoEncryptor.isSupport()) 38 | { 39 | LibcryptoEncryptor.InitAviable(); 40 | foreach (string method in LibcryptoEncryptor.SupportedCiphers()) 41 | { 42 | if (!_registeredEncryptorNames.Contains(method)) 43 | { 44 | _registeredEncryptorNames.Add(method); 45 | _registeredEncryptors.Add(method, typeof(LibcryptoEncryptor)); 46 | } 47 | } 48 | } 49 | foreach (string method in SodiumEncryptor.SupportedCiphers()) 50 | { 51 | if (!_registeredEncryptorNames.Contains(method)) 52 | { 53 | _registeredEncryptorNames.Add(method); 54 | _registeredEncryptors.Add(method, typeof(SodiumEncryptor)); 55 | } 56 | } 57 | } 58 | 59 | public static List GetEncryptor() 60 | { 61 | return _registeredEncryptorNames; 62 | } 63 | 64 | public static IEncryptor GetEncryptor(string method, string password) 65 | { 66 | if (string.IsNullOrEmpty(method)) 67 | { 68 | method = "aes-256-cfb"; 69 | } 70 | method = method.ToLowerInvariant(); 71 | Type t = _registeredEncryptors[method]; 72 | ConstructorInfo c = t.GetConstructor(_constructorTypes); 73 | IEncryptor result = (IEncryptor)c.Invoke(new object[] { method, password }); 74 | return result; 75 | } 76 | 77 | public static EncryptorInfo GetEncryptorInfo(string method) 78 | { 79 | if (string.IsNullOrEmpty(method)) 80 | { 81 | method = "aes-256-cfb"; 82 | } 83 | method = method.ToLowerInvariant(); 84 | Type t = _registeredEncryptors[method]; 85 | ConstructorInfo c = t.GetConstructor(_constructorTypes); 86 | IEncryptor result = (IEncryptor)c.Invoke(new object[] { method, "0" }); 87 | EncryptorInfo info = result.getInfo(); 88 | result.Dispose(); 89 | return info; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Encryption/IEncryptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Shadowsocks.Encryption 6 | { 7 | public interface IEncryptor : IDisposable 8 | { 9 | bool SetIV(byte[] iv); 10 | void Encrypt(byte[] buf, int length, byte[] outbuf, out int outlength); 11 | void Decrypt(byte[] buf, int length, byte[] outbuf, out int outlength); 12 | void ResetEncrypt(); 13 | void ResetDecrypt(); 14 | byte[] getIV(); 15 | byte[] getKey(); 16 | EncryptorInfo getInfo(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Encryption/MbedTLS.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Runtime.InteropServices; 4 | 5 | using Shadowsocks.Controller; 6 | using Shadowsocks.Properties; 7 | using Shadowsocks.Util; 8 | 9 | namespace Shadowsocks.Encryption 10 | { 11 | public class MbedTLS 12 | { 13 | const string DLLNAME = "libsscrypto"; 14 | 15 | public const int MBEDTLS_ENCRYPT = 1; 16 | public const int MBEDTLS_DECRYPT = 0; 17 | public const int MD5_CTX_SIZE = 88; 18 | 19 | public const int MBEDTLS_MD_MD5 = 3; 20 | public const int MBEDTLS_MD_SHA1 = 4; 21 | public const int MBEDTLS_MD_SHA224 = 5; 22 | public const int MBEDTLS_MD_SHA256 = 6; 23 | public const int MBEDTLS_MD_SHA384 = 7; 24 | public const int MBEDTLS_MD_SHA512 = 8; 25 | public const int MBEDTLS_MD_RIPEMD160 = 9; 26 | 27 | public interface HMAC 28 | { 29 | byte[] ComputeHash(byte[] buffer, int offset, int count); 30 | } 31 | 32 | public class HMAC_MD5 : HMAC 33 | { 34 | byte[] key; 35 | 36 | public HMAC_MD5(byte[] key) 37 | { 38 | this.key = key; 39 | } 40 | 41 | public byte[] ComputeHash(byte[] buffer, int offset, int count) 42 | { 43 | byte[] output = new byte[64]; 44 | ss_hmac_ex(MBEDTLS_MD_MD5, key, key.Length, buffer, offset, count, output); 45 | return output; 46 | } 47 | } 48 | 49 | public class HMAC_SHA1 : HMAC 50 | { 51 | byte[] key; 52 | 53 | public HMAC_SHA1(byte[] key) 54 | { 55 | this.key = key; 56 | } 57 | 58 | public byte[] ComputeHash(byte[] buffer, int offset, int count) 59 | { 60 | byte[] output = new byte[64]; 61 | ss_hmac_ex(MBEDTLS_MD_SHA1, key, key.Length, buffer,offset, count, output); 62 | return output; 63 | } 64 | } 65 | 66 | static MbedTLS() 67 | { 68 | string runningPath = Path.Combine(System.Windows.Forms.Application.StartupPath, @"temp"); // Path.GetTempPath(); 69 | if (!Directory.Exists(runningPath)) 70 | { 71 | Directory.CreateDirectory(runningPath); 72 | } 73 | string dllPath = Path.Combine(runningPath, "libsscrypto.dll"); 74 | try 75 | { 76 | if (IntPtr.Size == 4) 77 | { 78 | FileManager.UncompressFile(dllPath, Resources.libsscrypto_dll); 79 | } 80 | else 81 | { 82 | FileManager.UncompressFile(dllPath, Resources.libsscrypto64_dll); 83 | } 84 | } 85 | catch (IOException) 86 | { 87 | } 88 | catch (Exception e) 89 | { 90 | Logging.LogUsefulException(e); 91 | } 92 | IntPtr module = LoadLibrary(dllPath); 93 | } 94 | 95 | public static byte[] MD5(byte[] input) 96 | { 97 | byte[] output = new byte[16]; 98 | md5(input, input.Length, output); 99 | return output; 100 | } 101 | 102 | public static byte[] SHA1(byte[] input) 103 | { 104 | byte[] output = new byte[20]; 105 | ss_md(MBEDTLS_MD_SHA1, input, 0, input.Length, output); 106 | return output; 107 | } 108 | 109 | public static byte[] SHA512(byte[] input) 110 | { 111 | byte[] output = new byte[64]; 112 | ss_md(MBEDTLS_MD_SHA512, input, 0, input.Length, output); 113 | return output; 114 | } 115 | 116 | [DllImport("Kernel32.dll")] 117 | private static extern IntPtr LoadLibrary(string path); 118 | 119 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 120 | public static extern IntPtr cipher_info_from_string(string cipher_name); 121 | 122 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 123 | public static extern void cipher_init(IntPtr ctx); 124 | 125 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 126 | public static extern int cipher_setup(IntPtr ctx, IntPtr cipher_info); 127 | 128 | // XXX: Check operation before using it 129 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 130 | public static extern int cipher_setkey(IntPtr ctx, byte[] key, int key_bitlen, int operation); 131 | 132 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 133 | public static extern int cipher_set_iv(IntPtr ctx, byte[] iv, int iv_len); 134 | 135 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 136 | public static extern int cipher_reset(IntPtr ctx); 137 | 138 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 139 | public static extern int cipher_update(IntPtr ctx, byte[] input, int ilen, byte[] output, ref int olen); 140 | 141 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 142 | public static extern void cipher_free(IntPtr ctx); 143 | 144 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 145 | public static extern void md5(byte[] input, int ilen, byte[] output); 146 | 147 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 148 | public static extern void ss_md(int md_type, byte[] input, int offset, int ilen, byte[] output); 149 | 150 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 151 | public static extern void ss_hmac_ex(int md_type, byte[] key, int keylen, byte[] input, int offset, int ilen, byte[] output); 152 | 153 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 154 | public static extern int cipher_get_size_ex(); 155 | 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Encryption/RSA.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Security.Cryptography; 4 | using System.IO; 5 | 6 | namespace Shadowsocks.Encryption 7 | { 8 | class RSA 9 | { 10 | public static bool SignatureVerify(string p_strKeyPublic, byte[] rgb, byte[] rgbSignature) 11 | { 12 | try 13 | { 14 | RSACryptoServiceProvider key = new RSACryptoServiceProvider(); 15 | key.FromXmlString(p_strKeyPublic); 16 | RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(key); 17 | deformatter.SetHashAlgorithm("SHA512"); 18 | if (deformatter.VerifySignature(rgb, rgbSignature)) 19 | { 20 | return true; 21 | } 22 | return false; 23 | } 24 | catch 25 | { 26 | return false; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Encryption/Sodium.cs: -------------------------------------------------------------------------------- 1 | using Shadowsocks.Controller; 2 | using Shadowsocks.Properties; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Runtime.InteropServices; 7 | using System.Text; 8 | 9 | namespace Shadowsocks.Encryption 10 | { 11 | public class Sodium 12 | { 13 | const string DLLNAME = "libsscrypto"; 14 | 15 | static Sodium() 16 | { 17 | string dllPath = Path.Combine(Path.Combine(System.Windows.Forms.Application.StartupPath, @"temp"), "libsscrypto.dll"); 18 | try 19 | { 20 | if (IntPtr.Size == 4) 21 | { 22 | FileManager.UncompressFile(dllPath, Resources.libsscrypto_dll); 23 | } 24 | else 25 | { 26 | FileManager.UncompressFile(dllPath, Resources.libsscrypto64_dll); 27 | } 28 | LoadLibrary(dllPath); 29 | } 30 | catch (IOException) 31 | { 32 | } 33 | catch (Exception e) 34 | { 35 | Console.WriteLine(e.ToString()); 36 | } 37 | } 38 | 39 | [DllImport("Kernel32.dll")] 40 | private static extern IntPtr LoadLibrary(string path); 41 | 42 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 43 | public extern static void crypto_stream_salsa20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); 44 | 45 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 46 | public extern static void crypto_stream_chacha20_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); 47 | 48 | [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)] 49 | public extern static int crypto_stream_chacha20_ietf_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, uint ic, byte[] k); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Encryption/SodiumEncryptor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Shadowsocks.Encryption 6 | { 7 | public class SodiumEncryptor 8 | : IVEncryptor, IDisposable 9 | { 10 | const int CIPHER_SALSA20 = 1; 11 | const int CIPHER_CHACHA20 = 2; 12 | const int CIPHER_CHACHA20_IETF = 3; 13 | 14 | const int SODIUM_BLOCK_SIZE = 64; 15 | 16 | protected int _encryptBytesRemaining; 17 | protected int _decryptBytesRemaining; 18 | protected ulong _encryptIC; 19 | protected ulong _decryptIC; 20 | protected byte[] _encryptBuf; 21 | protected byte[] _decryptBuf; 22 | 23 | private delegate void crypto_stream(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k); 24 | private crypto_stream encryptor_delegate; 25 | 26 | public SodiumEncryptor(string method, string password) 27 | : base(method, password) 28 | { 29 | InitKey(method, password); 30 | _encryptBuf = new byte[MAX_INPUT_SIZE + SODIUM_BLOCK_SIZE]; 31 | _decryptBuf = new byte[MAX_INPUT_SIZE + SODIUM_BLOCK_SIZE]; 32 | switch (_cipher) 33 | { 34 | case CIPHER_SALSA20: 35 | encryptor_delegate = Sodium.crypto_stream_salsa20_xor_ic; 36 | break; 37 | case CIPHER_CHACHA20: 38 | encryptor_delegate = Sodium.crypto_stream_chacha20_xor_ic; 39 | break; 40 | case CIPHER_CHACHA20_IETF: 41 | encryptor_delegate = crypto_stream_chacha20_ietf_xor_ic; 42 | break; 43 | } 44 | } 45 | 46 | private static Dictionary _ciphers = new Dictionary { 47 | {"salsa20", new EncryptorInfo(32, 8, true, CIPHER_SALSA20)}, 48 | {"chacha20", new EncryptorInfo(32, 8, true, CIPHER_CHACHA20)}, 49 | {"chacha20-ietf", new EncryptorInfo(32, 12, true, CIPHER_CHACHA20_IETF)}, 50 | }; 51 | 52 | protected override Dictionary getCiphers() 53 | { 54 | return _ciphers; 55 | } 56 | 57 | public static List SupportedCiphers() 58 | { 59 | return new List(_ciphers.Keys); 60 | } 61 | 62 | protected override void cipherUpdate(bool isCipher, int length, byte[] buf, byte[] outbuf) 63 | { 64 | int bytesRemaining; 65 | ulong ic; 66 | byte[] sodiumBuf; 67 | byte[] iv; 68 | if (isCipher) 69 | { 70 | bytesRemaining = _encryptBytesRemaining; 71 | ic = _encryptIC; 72 | sodiumBuf = _encryptBuf; 73 | iv = _encryptIV; 74 | } 75 | else 76 | { 77 | bytesRemaining = _decryptBytesRemaining; 78 | ic = _decryptIC; 79 | sodiumBuf = _decryptBuf; 80 | iv = _decryptIV; 81 | } 82 | int padding = bytesRemaining; 83 | Buffer.BlockCopy(buf, 0, sodiumBuf, padding, length); 84 | encryptor_delegate(sodiumBuf, sodiumBuf, (ulong)(padding + length), iv, ic, _key); 85 | Buffer.BlockCopy(sodiumBuf, padding, outbuf, 0, length); 86 | padding += length; 87 | ic += (ulong)padding / SODIUM_BLOCK_SIZE; 88 | bytesRemaining = padding % SODIUM_BLOCK_SIZE; 89 | 90 | if (isCipher) 91 | { 92 | _encryptBytesRemaining = bytesRemaining; 93 | _encryptIC = ic; 94 | } 95 | else 96 | { 97 | _decryptBytesRemaining = bytesRemaining; 98 | _decryptIC = ic; 99 | } 100 | } 101 | 102 | public override void ResetEncrypt() 103 | { 104 | _encryptIVSent = false; 105 | _encryptIC = 0; 106 | _encryptBytesRemaining = 0; 107 | } 108 | 109 | public override void ResetDecrypt() 110 | { 111 | _decryptIVReceived = 0; 112 | _decryptIC = 0; 113 | _decryptBytesRemaining = 0; 114 | } 115 | 116 | void crypto_stream_chacha20_ietf_xor_ic(byte[] c, byte[] m, ulong mlen, byte[] n, ulong ic, byte[] k) 117 | { 118 | Sodium.crypto_stream_chacha20_ietf_xor_ic(c, m, mlen, n, (uint)ic, k); 119 | } 120 | 121 | public override void Dispose() 122 | { 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Model/Host.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Text; 5 | 6 | namespace Shadowsocks.Model 7 | { 8 | class HostNode 9 | { 10 | public bool include_sub; 11 | public string addr; 12 | public Dictionary subnode; 13 | 14 | public HostNode() 15 | { 16 | include_sub = false; 17 | addr = ""; 18 | subnode = new Dictionary(); 19 | } 20 | 21 | public HostNode(bool sub, string addr) 22 | { 23 | include_sub = sub; 24 | this.addr = addr; 25 | subnode = null; 26 | } 27 | } 28 | 29 | public class HostMap 30 | { 31 | Dictionary root = new Dictionary(); 32 | IPSegment ips = new IPSegment("remoteproxy"); 33 | 34 | static HostMap instance = new HostMap(); 35 | const string HOST_FILENAME = "user.rule"; 36 | 37 | public static HostMap Instance() 38 | { 39 | return instance; 40 | } 41 | 42 | public void Clear(HostMap newInstance) 43 | { 44 | if (newInstance == null) 45 | { 46 | instance = new HostMap(); 47 | } 48 | else 49 | { 50 | instance = newInstance; 51 | } 52 | } 53 | 54 | public void AddHost(string host, string addr) 55 | { 56 | IPAddress ip_addr = null; 57 | if (IPAddress.TryParse(host, out ip_addr)) 58 | { 59 | string[] addr_parts = addr.Split(new char[] { ' ', '\t', }, 2, StringSplitOptions.RemoveEmptyEntries); 60 | if (addr_parts.Length >= 2) 61 | { 62 | ips.insert(new IPAddressCmp(host), new IPAddressCmp(addr_parts[0]), addr_parts[1]); 63 | return; 64 | } 65 | } 66 | 67 | string[] parts = host.Split('.'); 68 | Dictionary node = root; 69 | bool include_sub = false; 70 | int end = 0; 71 | if (parts[0].Length == 0) 72 | { 73 | end = 1; 74 | include_sub = true; 75 | } 76 | for (int i = parts.Length - 1; i > end; --i) 77 | { 78 | if (!node.ContainsKey(parts[i])) 79 | { 80 | node[parts[i]] = new HostNode(); 81 | } 82 | if (node[parts[i]].subnode == null) 83 | { 84 | node[parts[i]].subnode = new Dictionary(); 85 | } 86 | node = node[parts[i]].subnode; 87 | } 88 | node[parts[end]] = new HostNode(include_sub, addr); 89 | } 90 | 91 | public bool GetHost(string host, out string addr) 92 | { 93 | string[] parts = host.Split('.'); 94 | Dictionary node = root; 95 | addr = null; 96 | for (int i = parts.Length - 1; i >= 0; --i) 97 | { 98 | if (!node.ContainsKey(parts[i])) 99 | { 100 | return false; 101 | } 102 | if (node[parts[i]].addr.Length > 0 || node[parts[i]].include_sub) 103 | { 104 | addr = node[parts[i]].addr; 105 | return true; 106 | } 107 | if (node.ContainsKey("*")) 108 | { 109 | addr = node["*"].addr; 110 | return true; 111 | } 112 | if (node[parts[i]].subnode == null) 113 | { 114 | return false; 115 | } 116 | node = node[parts[i]].subnode; 117 | } 118 | return false; 119 | } 120 | 121 | public bool GetIP(IPAddress ip, out string addr) 122 | { 123 | string host = ip.ToString(); 124 | addr = ips.Get(new IPAddressCmp(host)) as string; 125 | return addr != null; 126 | } 127 | 128 | public bool LoadHostFile() 129 | { 130 | string filename = HOST_FILENAME; 131 | string absFilePath = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, filename); 132 | if (System.IO.File.Exists(absFilePath)) 133 | { 134 | try 135 | { 136 | using (System.IO.StreamReader stream = System.IO.File.OpenText(absFilePath)) 137 | { 138 | while (true) 139 | { 140 | string line = stream.ReadLine(); 141 | if (line == null) 142 | break; 143 | if (line.Length > 0 && line.StartsWith("#")) 144 | continue; 145 | string[] parts = line.Split(new char[] { ' ', '\t', }, 2, StringSplitOptions.RemoveEmptyEntries); 146 | if (parts.Length < 2) 147 | continue; 148 | AddHost(parts[0], parts[1]); 149 | } 150 | } 151 | return true; 152 | } 153 | catch 154 | { 155 | return false; 156 | } 157 | } 158 | return false; 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Model/LRUCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Shadowsocks.Controller; 5 | 6 | namespace Shadowsocks.Model 7 | { 8 | public class LRUCache 9 | { 10 | protected Dictionary _store = new Dictionary(); 11 | protected Dictionary _key_2_time = new Dictionary(); 12 | protected Dictionary _time_2_key = new Dictionary(); 13 | protected object _lock = new object(); 14 | protected int _sweep_time; 15 | 16 | public LRUCache(int sweep_time = 60 * 60) 17 | { 18 | _sweep_time = sweep_time; 19 | } 20 | 21 | public void SetTimeout(int time) 22 | { 23 | _sweep_time = time; 24 | } 25 | 26 | public bool isTimeout(K key) 27 | { 28 | lock (_lock) 29 | { 30 | if ((DateTime.Now - _key_2_time[key]).TotalSeconds > _sweep_time) 31 | { 32 | return true; 33 | } 34 | return false; 35 | } 36 | } 37 | 38 | public bool ContainsKey(K key) 39 | { 40 | lock (_lock) 41 | { 42 | return _store.ContainsKey(key); 43 | } 44 | } 45 | 46 | public V Get(K key) 47 | { 48 | lock (_lock) 49 | { 50 | if (_store.ContainsKey(key)) 51 | { 52 | DateTime t = _key_2_time[key]; 53 | _key_2_time.Remove(key); 54 | _time_2_key.Remove(t); 55 | t = DateTime.Now; 56 | while (_time_2_key.ContainsKey(t)) 57 | { 58 | t = t.AddTicks(1); 59 | } 60 | _time_2_key[t] = key; 61 | _key_2_time[key] = t; 62 | return _store[key]; 63 | } 64 | return default(V); 65 | } 66 | } 67 | 68 | public V Set(K key, V val) 69 | { 70 | lock (_lock) 71 | { 72 | DateTime t; 73 | if (_store.ContainsKey(key)) 74 | { 75 | t = _key_2_time[key]; 76 | _key_2_time.Remove(key); 77 | _time_2_key.Remove(t); 78 | } 79 | t = DateTime.Now; 80 | while (_time_2_key.ContainsKey(t)) 81 | { 82 | t = t.AddTicks(1); 83 | } 84 | _time_2_key[t] = key; 85 | _key_2_time[key] = t; 86 | _store[key] = val; 87 | return val; 88 | } 89 | } 90 | 91 | public void Del(K key) 92 | { 93 | lock (_lock) 94 | { 95 | DateTime t; 96 | if (_store.ContainsKey(key)) 97 | { 98 | t = _key_2_time[key]; 99 | _key_2_time.Remove(key); 100 | _time_2_key.Remove(t); 101 | _store.Remove(key); 102 | } 103 | } 104 | } 105 | 106 | public void Sweep() 107 | { 108 | lock (_lock) 109 | { 110 | DateTime now = DateTime.Now; 111 | int sweep = 0; 112 | for (int i = 0; i < 100; ++i) 113 | { 114 | bool finish = false; 115 | foreach (KeyValuePair p in _time_2_key) 116 | { 117 | if ((now - p.Key).TotalSeconds < _sweep_time) 118 | { 119 | finish = true; 120 | break; 121 | } 122 | _key_2_time.Remove(p.Value); 123 | _time_2_key.Remove(p.Key); 124 | _store.Remove(p.Value); 125 | Logging.Debug("sweep [" + p.Key.ToString() + "]: " + p.Value.ToString()); 126 | sweep += 1; 127 | break; 128 | } 129 | if (finish) 130 | break; 131 | } 132 | if (sweep > 0) 133 | { 134 | Logging.Debug("sweep " + sweep.ToString() + " items"); 135 | } 136 | } 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Obfs/IObfs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Shadowsocks.Obfs 4 | { 5 | public class ObfsException : Exception 6 | { 7 | public ObfsException(string info) 8 | : base(info) 9 | { 10 | 11 | } 12 | } 13 | public class ServerInfo 14 | { 15 | public string host; 16 | public int port; 17 | public string param; 18 | public object data; 19 | public int tcp_mss; 20 | public int overhead; 21 | public int buffer_size; 22 | public byte[] iv; 23 | public byte[] key; 24 | public string key_str; 25 | public int head_len; 26 | 27 | public ServerInfo(string host, int port, string param, object data, byte[] iv, string key_str, byte[] key, int head_len, int tcp_mss, int overhead, int buffer_size) 28 | { 29 | this.host = host; 30 | this.port = port; 31 | this.param = param; 32 | this.data = data; 33 | this.iv = iv; 34 | this.key = key; 35 | this.key_str = key_str; 36 | this.head_len = head_len; 37 | this.tcp_mss = tcp_mss; 38 | this.overhead = overhead; 39 | this.buffer_size = buffer_size; 40 | } 41 | 42 | public void SetIV(byte[] iv) 43 | { 44 | this.iv = iv; 45 | } 46 | } 47 | public interface IObfs : IDisposable 48 | { 49 | string Name(); 50 | bool isKeepAlive(); 51 | bool isAlwaysSendback(); 52 | byte[] ClientPreEncrypt(byte[] plaindata, int datalength, out int outlength); 53 | byte[] ClientEncode(byte[] encryptdata, int datalength, out int outlength); 54 | byte[] ClientDecode(byte[] encryptdata, int datalength, out int outlength, out bool needsendback); 55 | byte[] ClientPostDecrypt(byte[] plaindata, int datalength, out int outlength); 56 | byte[] ClientUdpPreEncrypt(byte[] plaindata, int datalength, out int outlength); 57 | byte[] ClientUdpPostDecrypt(byte[] plaindata, int datalength, out int outlength); 58 | object InitData(); 59 | void SetServerInfo(ServerInfo serverInfo); 60 | void SetServerInfoIV(byte[] iv); 61 | long GetSentLength(); 62 | int GetOverhead(); 63 | int GetTcpMSS(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Obfs/ObfsBase.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Shadowsocks.Obfs 6 | { 7 | public abstract class ObfsBase: IObfs 8 | { 9 | protected ObfsBase(string method) 10 | { 11 | Method = method; 12 | } 13 | 14 | protected string Method; 15 | protected ServerInfo Server; 16 | protected long SentLength; 17 | 18 | public abstract Dictionary GetObfs(); 19 | 20 | public string Name() 21 | { 22 | return Method; 23 | } 24 | 25 | public virtual bool isKeepAlive() 26 | { 27 | return false; 28 | } 29 | 30 | public virtual bool isAlwaysSendback() 31 | { 32 | return false; 33 | } 34 | 35 | 36 | public virtual byte[] ClientPreEncrypt(byte[] plaindata, int datalength, out int outlength) 37 | { 38 | outlength = datalength; 39 | return plaindata; 40 | } 41 | public abstract byte[] ClientEncode(byte[] encryptdata, int datalength, out int outlength); 42 | public abstract byte[] ClientDecode(byte[] encryptdata, int datalength, out int outlength, out bool needsendback); 43 | public virtual byte[] ClientPostDecrypt(byte[] plaindata, int datalength, out int outlength) 44 | { 45 | outlength = datalength; 46 | return plaindata; 47 | } 48 | public virtual byte[] ClientUdpPreEncrypt(byte[] plaindata, int datalength, out int outlength) 49 | { 50 | outlength = datalength; 51 | return plaindata; 52 | } 53 | public virtual byte[] ClientUdpPostDecrypt(byte[] plaindata, int datalength, out int outlength) 54 | { 55 | outlength = datalength; 56 | return plaindata; 57 | } 58 | 59 | public virtual object InitData() 60 | { 61 | return null; 62 | } 63 | public virtual void SetServerInfo(ServerInfo serverInfo) 64 | { 65 | Server = serverInfo; 66 | } 67 | public virtual void SetServerInfoIV(byte[] iv) 68 | { 69 | Server.SetIV(iv); 70 | } 71 | public static int GetHeadSize(byte[] plaindata, int defaultValue) 72 | { 73 | if (plaindata == null || plaindata.Length < 2) 74 | return defaultValue; 75 | int head_type = plaindata[0] & 0x7; 76 | if (head_type == 1) 77 | return 7; 78 | if (head_type == 4) 79 | return 19; 80 | if (head_type == 3) 81 | return 4 + plaindata[1]; 82 | if (head_type == 2) 83 | return 4 + plaindata[1]; 84 | return defaultValue; 85 | } 86 | public long GetSentLength() 87 | { 88 | return SentLength; 89 | } 90 | public virtual int GetOverhead() 91 | { 92 | return 0; 93 | } 94 | 95 | public int GetTcpMSS() 96 | { 97 | return Server.tcp_mss; 98 | } 99 | 100 | 101 | #region IDisposable 102 | protected bool _disposed; 103 | 104 | public void Dispose() 105 | { 106 | Dispose(true); 107 | GC.SuppressFinalize(this); 108 | } 109 | 110 | protected virtual void Dispose(bool disposing) 111 | { 112 | lock (this) 113 | { 114 | if (_disposed) 115 | { 116 | return; 117 | } 118 | _disposed = true; 119 | } 120 | } 121 | #endregion 122 | 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Obfs/ObfsFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | 5 | namespace Shadowsocks.Obfs 6 | { 7 | public static class ObfsFactory 8 | { 9 | private static Dictionary _registeredObfs; 10 | 11 | private static Type[] _constructorTypes = new Type[] { typeof(string) }; 12 | 13 | static ObfsFactory() 14 | { 15 | _registeredObfs = new Dictionary(); 16 | foreach (string method in Plain.SupportedObfs()) 17 | { 18 | _registeredObfs.Add(method, typeof(Plain)); 19 | } 20 | foreach (string method in HttpSimpleObfs.SupportedObfs()) 21 | { 22 | _registeredObfs.Add(method, typeof(HttpSimpleObfs)); 23 | } 24 | foreach (string method in TlsTicketAuthObfs.SupportedObfs()) 25 | { 26 | _registeredObfs.Add(method, typeof(TlsTicketAuthObfs)); 27 | } 28 | foreach (string method in VerifyDeflateObfs.SupportedObfs()) 29 | { 30 | _registeredObfs.Add(method, typeof(VerifyDeflateObfs)); 31 | } 32 | #if DEBUG 33 | foreach (string method in AuthSHA1.SupportedObfs()) 34 | { 35 | _registeredObfs.Add(method, typeof(AuthSHA1)); 36 | } 37 | foreach (string method in AuthSHA1V2.SupportedObfs()) 38 | { 39 | _registeredObfs.Add(method, typeof(AuthSHA1V2)); 40 | } 41 | #endif 42 | foreach (string method in AuthSHA1V4.SupportedObfs()) 43 | { 44 | _registeredObfs.Add(method, typeof(AuthSHA1V4)); 45 | } 46 | foreach (string method in AuthAES128SHA1.SupportedObfs()) 47 | { 48 | _registeredObfs.Add(method, typeof(AuthAES128SHA1)); 49 | } 50 | foreach (string method in AuthChain_a.SupportedObfs()) 51 | { 52 | _registeredObfs.Add(method, typeof(AuthChain_a)); 53 | } 54 | foreach (string method in AuthChain_b.SupportedObfs()) 55 | { 56 | _registeredObfs.Add(method, typeof(AuthChain_b)); 57 | } 58 | } 59 | 60 | public static IObfs GetObfs(string method) 61 | { 62 | if (string.IsNullOrEmpty(method)) 63 | { 64 | method = "plain"; 65 | } 66 | method = method.ToLowerInvariant(); 67 | Type t = _registeredObfs[method]; 68 | ConstructorInfo c = t.GetConstructor(_constructorTypes); 69 | IObfs result = (IObfs)c.Invoke(new object[] { method }); 70 | return result; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Obfs/Plain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Shadowsocks.Obfs 5 | { 6 | public class Plain : ObfsBase 7 | { 8 | public Plain(string method) 9 | : base(method) 10 | { 11 | } 12 | private static Dictionary _obfs = new Dictionary { 13 | {"plain", new int[]{0, 0, 0}}, 14 | {"origin", new int[]{0, 0, 0}}, 15 | }; 16 | 17 | public static List SupportedObfs() 18 | { 19 | return new List(_obfs.Keys); 20 | } 21 | 22 | public override Dictionary GetObfs() 23 | { 24 | return _obfs; 25 | } 26 | 27 | public override byte[] ClientEncode(byte[] encryptdata, int datalength, out int outlength) 28 | { 29 | outlength = datalength; 30 | SentLength += outlength; 31 | return encryptdata; 32 | } 33 | public override byte[] ClientDecode(byte[] encryptdata, int datalength, out int outlength, out bool needsendback) 34 | { 35 | outlength = datalength; 36 | needsendback = false; 37 | return encryptdata; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using Shadowsocks.Controller; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | 6 | // 有关程序集的常规信息通过下列属性集 7 | // 控制。更改这些属性值可修改 8 | // 与程序集关联的信息。 9 | [assembly: AssemblyTitle(UpdateChecker.Name)] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct(UpdateChecker.Name)] 14 | [assembly: AssemblyCopyright(UpdateChecker.Copyright)] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // 将 ComVisible 设置为 false 使此程序集中的类型 19 | // 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型, 20 | // 则将该类型上的 ComVisible 属性设置为 true。 21 | [assembly: ComVisible(false)] 22 | 23 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 24 | [assembly: Guid("f8334709-4309-436a-8bbd-6165dcf4a660")] 25 | 26 | // 程序集的版本信息由下面四个值组成: 27 | // 28 | // 主版本 29 | // 次版本 30 | // 内部版本号 31 | // 修订号 32 | // 33 | // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, 34 | // 方法是按如下所示使用“*”: 35 | // [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyVersion(UpdateChecker.Version)] 37 | // [assembly: AssemblyFileVersion("2.0.0")] 38 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Resources/46418775_p0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/Resources/46418775_p0.jpg -------------------------------------------------------------------------------- /shadowsocks-csharp/Resources/ss16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/Resources/ss16.png -------------------------------------------------------------------------------- /shadowsocks-csharp/Resources/ss20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/Resources/ss20.png -------------------------------------------------------------------------------- /shadowsocks-csharp/Resources/ss24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/Resources/ss24.png -------------------------------------------------------------------------------- /shadowsocks-csharp/Resources/ssw128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/Resources/ssw128.png -------------------------------------------------------------------------------- /shadowsocks-csharp/Util/Base64.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace Shadowsocks.Util 5 | { 6 | public static class Base64 7 | { 8 | public static string DecodeBase64(string val) 9 | { 10 | return Encoding.UTF8.GetString(DecodeBase64ToBytes(val)); 11 | } 12 | 13 | public static byte[] DecodeBase64ToBytes(string val) 14 | { 15 | var data = val.PadRight(val.Length + (4 - val.Length % 4) % 4, '='); 16 | return Convert.FromBase64String(data); 17 | } 18 | 19 | public static string EncodeUrlSafeBase64(byte[] val, bool trim) 20 | { 21 | if (trim) 22 | return Convert.ToBase64String(val).Replace('+', '-').Replace('/', '_').TrimEnd('='); 23 | else 24 | return Convert.ToBase64String(val).Replace('+', '-').Replace('/', '_'); 25 | } 26 | 27 | public static byte[] DecodeUrlSafeBase64ToBytes(string val) 28 | { 29 | var data = val.Replace('-', '+').Replace('_', '/').PadRight(val.Length + (4 - val.Length % 4) % 4, '='); 30 | return Convert.FromBase64String(data); 31 | } 32 | 33 | public static string EncodeUrlSafeBase64(string val, bool trim = true) 34 | { 35 | return EncodeUrlSafeBase64(Encoding.UTF8.GetBytes(val), trim); 36 | } 37 | 38 | public static string DecodeUrlSafeBase64(string val) 39 | { 40 | return Encoding.UTF8.GetString(DecodeUrlSafeBase64ToBytes(val)); 41 | } 42 | 43 | public static string DecodeStandardSSRUrlSafeBase64(string val) 44 | { 45 | if (val.IndexOf('=') >= 0) 46 | throw new FormatException(); 47 | return Encoding.UTF8.GetString(DecodeUrlSafeBase64ToBytes(val)); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /shadowsocks-csharp/Util/CRC.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Shadowsocks.Util 6 | { 7 | class CRC32 8 | { 9 | protected static ulong[] Crc32Table = CreateCRC32Table(); 10 | //生成CRC32码表 11 | public static ulong[] CreateCRC32Table() 12 | { 13 | ulong Crc; 14 | Crc32Table = new ulong[256]; 15 | int i, j; 16 | for (i = 0; i < 256; i++) 17 | { 18 | Crc = (ulong)i; 19 | for (j = 8; j > 0; j--) 20 | { 21 | if ((Crc & 1) == 1) 22 | Crc = (Crc >> 1) ^ 0xEDB88320; 23 | else 24 | Crc >>= 1; 25 | } 26 | Crc32Table[i] = Crc; 27 | } 28 | return Crc32Table; 29 | } 30 | 31 | //获取字符串的CRC32校验值 32 | public static ulong CalcCRC32(byte[] input, int len, ulong value = 0xffffffff) 33 | { 34 | return CalcCRC32(input, 0, len, value); 35 | } 36 | public static ulong CalcCRC32(byte[] input, int index, int len, ulong value = 0xffffffff) 37 | { 38 | byte[] buffer = input; 39 | for (int i = index; i < len; i++) 40 | { 41 | value = (value >> 8) ^ Crc32Table[(value & 0xFF) ^ buffer[i]]; 42 | } 43 | return value ^ 0xffffffff; 44 | } 45 | 46 | public static void SetCRC32(byte[] buffer) 47 | { 48 | SetCRC32(buffer, 0, buffer.Length); 49 | } 50 | 51 | public static void SetCRC32(byte[] buffer, int length) 52 | { 53 | SetCRC32(buffer, 0, length); 54 | } 55 | public static void SetCRC32(byte[] buffer, int index, int length) 56 | { 57 | ulong crc = ~CalcCRC32(buffer, index, length - 4); 58 | buffer[length - 1] = (byte)(crc >> 24); 59 | buffer[length - 2] = (byte)(crc >> 16); 60 | buffer[length - 3] = (byte)(crc >> 8); 61 | buffer[length - 4] = (byte)(crc); 62 | } 63 | 64 | public static bool CheckCRC32(byte[] buffer, int length) 65 | { 66 | ulong crc = CalcCRC32(buffer, length); 67 | if (crc != 0xffffffffu) 68 | return false; 69 | return true; 70 | } 71 | } 72 | class Adler32 73 | { 74 | public static ulong CalcAdler32(byte[] input, int len) 75 | { 76 | ulong a = 1; 77 | ulong b = 0; 78 | for (int i = 0; i < len; i++) 79 | { 80 | a += input[i]; 81 | b += a; 82 | } 83 | a %= 65521; 84 | b %= 65521; 85 | return (b << 16) + a; 86 | } 87 | 88 | public static bool CheckAdler32(byte[] input, int len) 89 | { 90 | ulong adler32 = CalcAdler32(input, len - 4); 91 | int checksum = (input[len - 1] << 24) | (input[len - 2] << 16) | (input[len - 3] << 8) | input[len - 4]; 92 | return (int)adler32 == checksum; 93 | } 94 | 95 | public static bool CheckAdler32(byte[] input, int len, uint xor) 96 | { 97 | ulong adler32 = CalcAdler32(input, len - 4) ^ xor; 98 | int checksum = (input[len - 1] << 24) | (input[len - 2] << 16) | (input[len - 3] << 8) | input[len - 4]; 99 | return (int)adler32 == checksum; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /shadowsocks-csharp/View/InputPassword.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Shadowsocks.View 2 | { 3 | partial class InputPassword 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.textPassword = new System.Windows.Forms.TextBox(); 32 | this.buttonOK = new System.Windows.Forms.Button(); 33 | this.label_info = new System.Windows.Forms.Label(); 34 | this.SuspendLayout(); 35 | // 36 | // textPassword 37 | // 38 | this.textPassword.ImeMode = System.Windows.Forms.ImeMode.Off; 39 | this.textPassword.Location = new System.Drawing.Point(41, 44); 40 | this.textPassword.Name = "textPassword"; 41 | this.textPassword.Size = new System.Drawing.Size(330, 21); 42 | this.textPassword.TabIndex = 0; 43 | this.textPassword.UseSystemPasswordChar = true; 44 | // 45 | // buttonOK 46 | // 47 | this.buttonOK.Location = new System.Drawing.Point(131, 76); 48 | this.buttonOK.Name = "buttonOK"; 49 | this.buttonOK.Size = new System.Drawing.Size(151, 28); 50 | this.buttonOK.TabIndex = 1; 51 | this.buttonOK.Text = "OK"; 52 | this.buttonOK.UseVisualStyleBackColor = true; 53 | this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); 54 | // 55 | // label_info 56 | // 57 | this.label_info.AutoSize = true; 58 | this.label_info.Location = new System.Drawing.Point(24, 26); 59 | this.label_info.Name = "label_info"; 60 | this.label_info.Size = new System.Drawing.Size(350, 15); 61 | this.label_info.TabIndex = 2; 62 | this.label_info.Text = "Parse gui-config.json error, maybe require password to decrypt"; 63 | // 64 | // InputPassword 65 | // 66 | this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); 67 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; 68 | this.ClientSize = new System.Drawing.Size(412, 119); 69 | this.Controls.Add(this.label_info); 70 | this.Controls.Add(this.buttonOK); 71 | this.Controls.Add(this.textPassword); 72 | this.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 73 | this.ImeMode = System.Windows.Forms.ImeMode.Off; 74 | this.KeyPreview = true; 75 | this.MaximizeBox = false; 76 | this.MinimizeBox = false; 77 | this.Name = "InputPassword"; 78 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 79 | this.Text = "InputPassword"; 80 | this.TopMost = true; 81 | this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.InputPassword_KeyDown); 82 | this.ResumeLayout(false); 83 | this.PerformLayout(); 84 | 85 | } 86 | 87 | #endregion 88 | 89 | private System.Windows.Forms.TextBox textPassword; 90 | private System.Windows.Forms.Button buttonOK; 91 | private System.Windows.Forms.Label label_info; 92 | } 93 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/View/InputPassword.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using Shadowsocks.Properties; 9 | using Shadowsocks.Controller; 10 | 11 | namespace Shadowsocks.View 12 | { 13 | public partial class InputPassword : Form 14 | { 15 | public string password; 16 | 17 | public InputPassword() 18 | { 19 | InitializeComponent(); 20 | this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); 21 | this.Text = I18N.GetString("InputPassword"); 22 | label_info.Text = I18N.GetString(label_info.Text); 23 | } 24 | 25 | private void buttonOK_Click(object sender, EventArgs e) 26 | { 27 | password = textPassword.Text; 28 | this.DialogResult = DialogResult.OK; 29 | Close(); 30 | } 31 | 32 | private void InputPassword_KeyDown(object sender, KeyEventArgs e) 33 | { 34 | if (e.KeyCode == Keys.Enter) 35 | { 36 | password = textPassword.Text; 37 | this.DialogResult = DialogResult.OK; 38 | Close(); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /shadowsocks-csharp/View/InputPassword.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /shadowsocks-csharp/View/LogForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.IO; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using Shadowsocks.Controller; 10 | using Shadowsocks.Model; 11 | using Shadowsocks.Properties; 12 | 13 | namespace Shadowsocks.View 14 | { 15 | public partial class LogForm : Form 16 | { 17 | private readonly ShadowsocksController _controller; 18 | 19 | private const int MaxReadSize = 65536; 20 | 21 | private string _currentLogFile; 22 | private string _currentLogFileName; 23 | private long _currentOffset; 24 | 25 | public LogForm(ShadowsocksController controller) 26 | { 27 | _controller = controller; 28 | 29 | InitializeComponent(); 30 | 31 | Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); 32 | 33 | UpdateTexts(); 34 | } 35 | 36 | private void UpdateTexts() 37 | { 38 | fileToolStripMenuItem.Text = I18N.GetString("&File"); 39 | clearLogToolStripMenuItem.Text = I18N.GetString("Clear &log"); 40 | showInExplorerToolStripMenuItem.Text = I18N.GetString("Show in &Explorer"); 41 | closeToolStripMenuItem.Text = I18N.GetString("&Close"); 42 | viewToolStripMenuItem.Text = I18N.GetString("&View"); 43 | fontToolStripMenuItem.Text = I18N.GetString("&Font..."); 44 | wrapTextToolStripMenuItem.Text = I18N.GetString("&Wrap Text"); 45 | alwaysOnTopToolStripMenuItem.Text = I18N.GetString("&Always on top"); 46 | Text = I18N.GetString("Log Viewer"); 47 | } 48 | 49 | private void closeToolStripMenuItem_Click(object sender, EventArgs e) 50 | { 51 | Close(); 52 | } 53 | 54 | private void showInExplorerToolStripMenuItem_Click(object sender, EventArgs _) 55 | { 56 | try 57 | { 58 | string argument = "/n" + ",/select," + Logging.LogFile; 59 | System.Diagnostics.Process.Start("explorer.exe", argument); 60 | } 61 | catch (Exception e) 62 | { 63 | Logging.LogUsefulException(e); 64 | } 65 | } 66 | 67 | private void LogForm_Load(object sender, EventArgs e) 68 | { 69 | ReadLog(); 70 | } 71 | 72 | private void ReadLog() 73 | { 74 | var newLogFile = Logging.LogFile; 75 | if (newLogFile != _currentLogFile) 76 | { 77 | _currentOffset = 0; 78 | _currentLogFile = newLogFile; 79 | _currentLogFileName = Logging.LogFileName; 80 | } 81 | 82 | try 83 | { 84 | using ( 85 | var reader = 86 | new StreamReader(new FileStream(newLogFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) 87 | ) 88 | { 89 | if (_currentOffset == 0) 90 | { 91 | var maxSize = reader.BaseStream.Length; 92 | if (maxSize > MaxReadSize) 93 | { 94 | reader.BaseStream.Seek(-MaxReadSize, SeekOrigin.End); 95 | reader.ReadLine(); 96 | } 97 | } 98 | else 99 | { 100 | reader.BaseStream.Seek(_currentOffset, SeekOrigin.Begin); 101 | } 102 | 103 | var txt = reader.ReadToEnd(); 104 | if (!string.IsNullOrEmpty(txt)) 105 | { 106 | logTextBox.AppendText(txt); 107 | logTextBox.ScrollToCaret(); 108 | } 109 | 110 | _currentOffset = reader.BaseStream.Position; 111 | } 112 | } 113 | catch (FileNotFoundException) 114 | { 115 | } 116 | 117 | Text = $@"{I18N.GetString("Log Viewer")} {_currentLogFileName}"; 118 | } 119 | 120 | private void refreshTimer_Tick(object sender, EventArgs e) 121 | { 122 | ReadLog(); 123 | } 124 | 125 | private void LogForm_Shown(object sender, EventArgs e) 126 | { 127 | logTextBox.ScrollToCaret(); 128 | } 129 | 130 | private void fontToolStripMenuItem_Click(object sender, EventArgs e) 131 | { 132 | using (FontDialog fontDialog = new FontDialog()) 133 | { 134 | fontDialog.Font = logTextBox.Font; 135 | if (fontDialog.ShowDialog() == DialogResult.OK) 136 | { 137 | logTextBox.Font = fontDialog.Font; 138 | } 139 | } 140 | } 141 | 142 | private void wrapTextToolStripMenuItem_Click(object sender, EventArgs e) 143 | { 144 | wrapTextToolStripMenuItem.Checked = !wrapTextToolStripMenuItem.Checked; 145 | } 146 | 147 | private void alwaysOnTopToolStripMenuItem_Click(object sender, EventArgs e) 148 | { 149 | alwaysOnTopToolStripMenuItem.Checked = !alwaysOnTopToolStripMenuItem.Checked; 150 | } 151 | 152 | private void wrapTextToolStripMenuItem_CheckedChanged(object sender, EventArgs e) 153 | { 154 | logTextBox.WordWrap = wrapTextToolStripMenuItem.Checked; 155 | logTextBox.ScrollToCaret(); 156 | } 157 | 158 | private void alwaysOnTopToolStripMenuItem_CheckedChanged(object sender, EventArgs e) 159 | { 160 | TopMost = alwaysOnTopToolStripMenuItem.Checked; 161 | } 162 | 163 | private void clearLogToolStripMenuItem_Click(object sender, EventArgs e) 164 | { 165 | Logging.Clear(); 166 | _currentOffset = 0; 167 | logTextBox.Clear(); 168 | } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /shadowsocks-csharp/View/PortSettingsForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /shadowsocks-csharp/View/ResetPassword.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Shadowsocks.View 2 | { 3 | partial class ResetPassword 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.buttonOK = new System.Windows.Forms.Button(); 32 | this.textOld = new System.Windows.Forms.TextBox(); 33 | this.textPassword = new System.Windows.Forms.TextBox(); 34 | this.textPassword2 = new System.Windows.Forms.TextBox(); 35 | this.SuspendLayout(); 36 | // 37 | // buttonOK 38 | // 39 | this.buttonOK.Location = new System.Drawing.Point(107, 132); 40 | this.buttonOK.Name = "buttonOK"; 41 | this.buttonOK.Size = new System.Drawing.Size(75, 23); 42 | this.buttonOK.TabIndex = 3; 43 | this.buttonOK.Text = "OK"; 44 | this.buttonOK.UseVisualStyleBackColor = true; 45 | this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); 46 | // 47 | // textOld 48 | // 49 | this.textOld.Location = new System.Drawing.Point(28, 13); 50 | this.textOld.Name = "textOld"; 51 | this.textOld.Size = new System.Drawing.Size(233, 21); 52 | this.textOld.TabIndex = 0; 53 | this.textOld.UseSystemPasswordChar = true; 54 | // 55 | // textPassword 56 | // 57 | this.textPassword.Location = new System.Drawing.Point(28, 60); 58 | this.textPassword.Name = "textPassword"; 59 | this.textPassword.Size = new System.Drawing.Size(233, 21); 60 | this.textPassword.TabIndex = 1; 61 | this.textPassword.UseSystemPasswordChar = true; 62 | // 63 | // textPassword2 64 | // 65 | this.textPassword2.Location = new System.Drawing.Point(28, 87); 66 | this.textPassword2.Name = "textPassword2"; 67 | this.textPassword2.Size = new System.Drawing.Size(233, 21); 68 | this.textPassword2.TabIndex = 2; 69 | this.textPassword2.UseSystemPasswordChar = true; 70 | // 71 | // ResetPassword 72 | // 73 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 74 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 75 | this.ClientSize = new System.Drawing.Size(284, 167); 76 | this.Controls.Add(this.textPassword2); 77 | this.Controls.Add(this.textPassword); 78 | this.Controls.Add(this.textOld); 79 | this.Controls.Add(this.buttonOK); 80 | this.ImeMode = System.Windows.Forms.ImeMode.Off; 81 | this.KeyPreview = true; 82 | this.Name = "ResetPassword"; 83 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 84 | this.Text = "ResetPassword"; 85 | this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ResetPassword_KeyDown); 86 | this.ResumeLayout(false); 87 | this.PerformLayout(); 88 | 89 | } 90 | 91 | #endregion 92 | 93 | private System.Windows.Forms.Button buttonOK; 94 | private System.Windows.Forms.TextBox textOld; 95 | private System.Windows.Forms.TextBox textPassword; 96 | private System.Windows.Forms.TextBox textPassword2; 97 | } 98 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/View/ResetPassword.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using Shadowsocks.Model; 9 | using Shadowsocks.Properties; 10 | using Shadowsocks.Controller; 11 | 12 | namespace Shadowsocks.View 13 | { 14 | public partial class ResetPassword : Form 15 | { 16 | public ResetPassword() 17 | { 18 | InitializeComponent(); 19 | this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); 20 | this.Text = I18N.GetString("ResetPassword"); 21 | } 22 | 23 | private void buttonOK_Click(object sender, EventArgs e) 24 | { 25 | if (textPassword.Text == textPassword2.Text && Configuration.SetPasswordTry(textOld.Text, textPassword.Text)) 26 | { 27 | Configuration cfg = Configuration.Load(); 28 | Configuration.SetPassword(textPassword.Text); 29 | Configuration.Save(cfg); 30 | Close(); 31 | } 32 | else 33 | { 34 | MessageBox.Show(I18N.GetString("Password NOT match"), "SSR error", MessageBoxButtons.OK); 35 | } 36 | } 37 | 38 | private void ResetPassword_KeyDown(object sender, KeyEventArgs e) 39 | { 40 | if (e.KeyCode == Keys.Enter) 41 | { 42 | if (textOld.Focused) 43 | { 44 | textPassword.Focus(); 45 | } 46 | else if (textPassword.Focused) 47 | { 48 | textPassword2.Focus(); 49 | } 50 | else 51 | { 52 | buttonOK_Click(this, new EventArgs()); 53 | } 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /shadowsocks-csharp/View/ResetPassword.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /shadowsocks-csharp/View/SettingsForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /shadowsocks-csharp/View/ShowTextForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Shadowsocks.View 2 | { 3 | partial class ShowTextForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.textBox = new System.Windows.Forms.TextBox(); 32 | this.PictureQRcode = new System.Windows.Forms.PictureBox(); 33 | ((System.ComponentModel.ISupportInitialize)(this.PictureQRcode)).BeginInit(); 34 | this.SuspendLayout(); 35 | // 36 | // textBox 37 | // 38 | this.textBox.Dock = System.Windows.Forms.DockStyle.Top; 39 | this.textBox.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 40 | this.textBox.Location = new System.Drawing.Point(0, 0); 41 | this.textBox.Multiline = true; 42 | this.textBox.Name = "textBox"; 43 | this.textBox.Size = new System.Drawing.Size(350, 63); 44 | this.textBox.TabIndex = 0; 45 | this.textBox.TextChanged += new System.EventHandler(this.textBox_TextChanged); 46 | this.textBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox_KeyPress); 47 | // 48 | // PictureQRcode 49 | // 50 | this.PictureQRcode.Dock = System.Windows.Forms.DockStyle.Bottom; 51 | this.PictureQRcode.Location = new System.Drawing.Point(0, 68); 52 | this.PictureQRcode.Name = "PictureQRcode"; 53 | this.PictureQRcode.Size = new System.Drawing.Size(350, 350); 54 | this.PictureQRcode.TabIndex = 1; 55 | this.PictureQRcode.TabStop = false; 56 | // 57 | // ShowTextForm 58 | // 59 | this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); 60 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; 61 | this.ClientSize = new System.Drawing.Size(350, 418); 62 | this.Controls.Add(this.PictureQRcode); 63 | this.Controls.Add(this.textBox); 64 | this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 65 | this.Name = "ShowTextForm"; 66 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 67 | this.Text = "ShowTextForm"; 68 | this.TopMost = true; 69 | this.SizeChanged += new System.EventHandler(this.ShowTextForm_SizeChanged); 70 | ((System.ComponentModel.ISupportInitialize)(this.PictureQRcode)).EndInit(); 71 | this.ResumeLayout(false); 72 | this.PerformLayout(); 73 | 74 | } 75 | 76 | #endregion 77 | 78 | private System.Windows.Forms.TextBox textBox; 79 | private System.Windows.Forms.PictureBox PictureQRcode; 80 | } 81 | } -------------------------------------------------------------------------------- /shadowsocks-csharp/View/ShowTextForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using Shadowsocks.Properties; 9 | using ZXing.QrCode.Internal; 10 | 11 | namespace Shadowsocks.View 12 | { 13 | public partial class ShowTextForm : Form 14 | { 15 | public ShowTextForm(string title, string text) 16 | { 17 | this.Icon = Icon.FromHandle(Resources.ssw128.GetHicon()); 18 | InitializeComponent(); 19 | 20 | this.Text = title; 21 | PictureQRcode.Height = this.ClientSize.Height - textBox.Height; 22 | textBox.Text = text; 23 | } 24 | 25 | private void GenQR(string ssconfig) 26 | { 27 | int dpi_mul = Util.Utils.GetDpiMul(); 28 | int width = Math.Min(PictureQRcode.Width, PictureQRcode.Height) * 4 / 4; 29 | try 30 | { 31 | string qrText = ssconfig; 32 | QRCode code = ZXing.QrCode.Internal.Encoder.encode(qrText, ErrorCorrectionLevel.M); 33 | ByteMatrix m = code.Matrix; 34 | int blockSize = Math.Max(width / (m.Width + 2), 1); 35 | Bitmap drawArea = new Bitmap(((m.Width + 2) * blockSize), ((m.Height + 2) * blockSize)); 36 | using (Graphics g = Graphics.FromImage(drawArea)) 37 | { 38 | g.Clear(Color.White); 39 | using (Brush b = new SolidBrush(Color.Black)) 40 | { 41 | for (int row = 0; row < m.Width; row++) 42 | { 43 | for (int col = 0; col < m.Height; col++) 44 | { 45 | if (m[row, col] != 0) 46 | { 47 | g.FillRectangle(b, blockSize * (row + 1), blockSize * (col + 1), 48 | blockSize, blockSize); 49 | } 50 | } 51 | } 52 | } 53 | Bitmap ngnl = Resources.ngnl; 54 | int div = 13, div_l = 5, div_r = 8; 55 | int l = (m.Width * div_l + div - 1) / div * blockSize, r = (m.Width * div_r + div - 1) / div * blockSize; 56 | g.DrawImage(ngnl, new Rectangle(l + blockSize, l + blockSize, r - l, r - l)); 57 | } 58 | PictureQRcode.Image = drawArea; 59 | } 60 | catch 61 | { 62 | 63 | } 64 | } 65 | 66 | private void textBox_TextChanged(object sender, EventArgs e) 67 | { 68 | GenQR(textBox.Text); 69 | } 70 | 71 | private void ShowTextForm_SizeChanged(object sender, EventArgs e) 72 | { 73 | PictureQRcode.Height = this.ClientSize.Height - textBox.Height; 74 | GenQR(textBox.Text); 75 | } 76 | 77 | private void textBox_KeyPress(object sender, KeyPressEventArgs e) 78 | { 79 | // Use KeyPress to avoid the beep when press Ctrl + A, don't do it in KeyDown 80 | if (e.KeyChar == '\x1') 81 | { 82 | textBox.SelectAll(); 83 | e.Handled = true; 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /shadowsocks-csharp/View/ShowTextForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /shadowsocks-csharp/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /shadowsocks-csharp/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | True/PM 14 | 15 | 16 | -------------------------------------------------------------------------------- /shadowsocks-csharp/shadowsocks.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksr-backup/shadowsocksr-csharp/932b86ef57836bdb20fa96d88823174b5ecced60/shadowsocks-csharp/shadowsocks.ico -------------------------------------------------------------------------------- /test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("test")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f74e87ac-7e3a-444b-a1d9-8b91a674c60f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /test/test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {45913187-0685-4903-B250-DCEF0479CD86} 7 | Library 8 | Properties 9 | test 10 | test 11 | v4.5 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | 22 | 23 | 24 | 25 | true 26 | bin\Debug\ 27 | AnyCPU 28 | MinimumRecommendedRules.ruleset 29 | 30 | 31 | bin\Release\ 32 | AnyCPU 33 | MinimumRecommendedRules.ruleset 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | {8c02d2f7-7cdb-4d55-9f25-cd03ef4aa062} 57 | shadowsocks-csharp 58 | 59 | 60 | 61 | 62 | 63 | 64 | False 65 | 66 | 67 | False 68 | 69 | 70 | False 71 | 72 | 73 | False 74 | 75 | 76 | 77 | 78 | 79 | 80 | 87 | --------------------------------------------------------------------------------