diff --git a/CHANGES b/CHANGES index 442d5de7..b7838460 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +2.0.4 +- Try to fix data corruption +- Remove all configuration except x86 + 2.0.3 - Support QRCode generation - Fix compatibility issues with some Chrome version diff --git a/LICENSE.txt b/LICENSE.txt index bc72404d..7801cdf2 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -84,18 +84,17 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. qrcodejs -------- -https://github.com/davidshimjs/qrcodejs +QRCode for C#4.0 Silverlight is translation of QRCode for JavaScript +https://github.com/jeromeetienne/jquery-qrcode/ -Copyright (c) 2012 davidshimjs +Copyright (c) 2009 Kazuhiko Arase -Permission is hereby granted, free of charge, -to any person obtaining a copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: +URL: http://www.d-project.com/ -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +Licensed under the MIT license: + http://www.opensource.org/licenses/mit-license.php -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +The word "QR Code" is registered trademark of +DENSO WAVE INCORPORATED + http://www.denso-wave.com/qrcode/faqpatent-e.html diff --git a/README.md b/README.md index 9be979a6..4f52c919 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,10 @@ Shadowsocks for Windows Download [latest release]. +For Windows 7 and older, please download Shadowsocks-win-x.x.x.zip. + +For Windows 8.1 and newer, please download Shadowsocks-win-dotnet4.0-x.x.x.zip. + ### Usage 1. Find Shadowsocks icon in notification tray @@ -25,8 +29,8 @@ Download [latest release]. about the change automatically 5. Please disable other proxy addons in your browser, or set them to use system proxy -6. You may need to install VC 2008 Runtime and .Net 2.0 if Shadowsocks failed to -start +6. You may need to install VC 2008 Runtime and .Net framework if Shadowsocks +failed to start ### License diff --git a/shadowsocks-csharp.sln b/shadowsocks-csharp.sln index c98f328b..46bde1a8 100755 --- a/shadowsocks-csharp.sln +++ b/shadowsocks-csharp.sln @@ -5,19 +5,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "shadowsocks-csharp", "shado EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|Any CPU.Build.0 = Debug|Any CPU {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|x86.ActiveCfg = Debug|x86 {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|x86.Build.0 = Debug|x86 {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Debug|x86.Deploy.0 = Debug|x86 - {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Release|Any CPU.Build.0 = Release|Any CPU {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Release|x86.ActiveCfg = Release|x86 {8C02D2F7-7CDB-4D55-9F25-CD03EF4AA062}.Release|x86.Build.0 = Release|x86 EndGlobalSection diff --git a/shadowsocks-csharp/3rd/QRCodeCS.cs b/shadowsocks-csharp/3rd/QRCodeCS.cs new file mode 100644 index 00000000..a380c978 --- /dev/null +++ b/shadowsocks-csharp/3rd/QRCodeCS.cs @@ -0,0 +1,1209 @@ +//--------------------------------------------------------------------- +// QRCode for C#4.0 Silverlight is translation of QRCode for JavaScript +// https://github.com/jeromeetienne/jquery-qrcode/ +// +// Copyright (c) 2009 Kazuhiko Arase +// +// URL: http://www.d-project.com/ +// +// Licensed under the MIT license: +// http://www.opensource.org/licenses/mit-license.php +// +// The word "QR Code" is registered trademark of +// DENSO WAVE INCORPORATED +// http://www.denso-wave.com/qrcode/faqpatent-e.html +// +//--------------------------------------------------------------------- +namespace QRCode4CS +{ + using System; + using System.Collections.Generic; + + + public class Error : Exception + { + public Error() { } + public Error(string message) : base(message) { } + public Error(string message, Exception inner) : base(message, inner) { } + } + + public enum QRMode : int + { + MODE_NUMBER = 1 << 0, + MODE_ALPHA_NUM = 1 << 1, + MODE_8BIT_BYTE = 1 << 2, + MODE_KANJI = 1 << 3 + } + + public enum QRErrorCorrectLevel : int + { + L = 1, + M = 0, + Q = 3, + H = 2 + } + + public enum QRMaskPattern : int + { + PATTERN000 = 0, + PATTERN001 = 1, + PATTERN010 = 2, + PATTERN011 = 3, + PATTERN100 = 4, + PATTERN101 = 5, + PATTERN110 = 6, + PATTERN111 = 7 + } + + public struct Options + { + public int Width { get; set; } + public int Height { get; set; } + public QRErrorCorrectLevel CorrectLevel { get; set; } + public int TypeNumber { get; set; } + public string Text { get; set; } + + public Options(string text) + : this() + { + Width = 256; + Height = 256; + TypeNumber = 4; + CorrectLevel = QRErrorCorrectLevel.H; + Text = text; + } + } + + internal static class QRUtil + { + internal const int G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0); + internal const int G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0); + internal const int G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1); + internal static readonly int[][] PATTERN_POSITION_TABLE = new int[][] { + new int[] {}, + new int [] {6, 18}, + new int [] {6, 22}, + new int [] {6, 26}, + new int [] {6, 30}, + new int [] {6, 34}, + new int [] {6, 22, 38}, + new int [] {6, 24, 42}, + new int [] {6, 26, 46}, + new int [] {6, 28, 50}, + new int [] {6, 30, 54}, + new int [] {6, 32, 58}, + new int [] {6, 34, 62}, + new int [] {6, 26, 46, 66}, + new int [] {6, 26, 48, 70}, + new int [] {6, 26, 50, 74}, + new int [] {6, 30, 54, 78}, + new int [] {6, 30, 56, 82}, + new int [] {6, 30, 58, 86}, + new int [] {6, 34, 62, 90}, + new int [] {6, 28, 50, 72, 94}, + new int [] {6, 26, 50, 74, 98}, + new int [] {6, 30, 54, 78, 102}, + new int [] {6, 28, 54, 80, 106}, + new int [] {6, 32, 58, 84, 110}, + new int [] {6, 30, 58, 86, 114}, + new int [] {6, 34, 62, 90, 118}, + new int [] {6, 26, 50, 74, 98, 122}, + new int [] {6, 30, 54, 78, 102, 126}, + new int [] {6, 26, 52, 78, 104, 130}, + new int [] {6, 30, 56, 82, 108, 134}, + new int [] {6, 34, 60, 86, 112, 138}, + + new int [] {6, 30, 58, 86, 114, 142}, + new int [] {6, 34, 62, 90, 118, 146}, + new int [] {6, 30, 54, 78, 102, 126, 150}, + new int [] {6, 24, 50, 76, 102, 128, 154}, + new int [] {6, 28, 54, 80, 106, 132, 158}, + new int [] {6, 32, 58, 84, 110, 136, 162}, + new int [] {6, 26, 54, 82, 110, 138, 166}, + new int [] {6, 30, 58, 86, 114, 142, 170} + }; + internal static int GetLengthInBits(QRMode mode, int type) + { + + if (1 <= type && type < 10) + { + + // 1 - 9 + + switch (mode) + { + case QRMode.MODE_NUMBER: return 10; + case QRMode.MODE_ALPHA_NUM: return 9; + case QRMode.MODE_8BIT_BYTE: return 8; + case QRMode.MODE_KANJI: return 8; + default: + throw new Error("mode:" + mode); + } + + } + else if (type < 27) + { + + // 10 - 26 + + switch (mode) + { + case QRMode.MODE_NUMBER: return 12; + case QRMode.MODE_ALPHA_NUM: return 11; + case QRMode.MODE_8BIT_BYTE: return 16; + case QRMode.MODE_KANJI: return 10; + default: + throw new Error("mode:" + mode); + } + + } + else if (type < 41) + { + + // 27 - 40 + + switch (mode) + { + case QRMode.MODE_NUMBER: return 14; + case QRMode.MODE_ALPHA_NUM: return 13; + case QRMode.MODE_8BIT_BYTE: return 16; + case QRMode.MODE_KANJI: return 12; + default: + throw new Error("mode:" + mode); + } + + } + else + { + throw new Error("type:" + type); + } + } + + internal static double GetLostPoint(QRCode qrCode) + { + int moduleCount = qrCode.GetModuleCount(); + double lostPoint = 0; + for (int row = 0; row < moduleCount; row++) + { + + for (int col = 0; col < moduleCount; col++) + { + + var sameCount = 0; + var dark = qrCode.IsDark(row, col); + + for (var r = -1; r <= 1; r++) + { + + if (row + r < 0 || moduleCount <= row + r) + { + continue; + } + + for (var c = -1; c <= 1; c++) + { + + if (col + c < 0 || moduleCount <= col + c) + { + continue; + } + + if (r == 0 && c == 0) + { + continue; + } + + if (dark == qrCode.IsDark((int)((int)row + r), (int)((int)col + c))) + { + sameCount++; + } + } + } + + if (sameCount > 5) + { + lostPoint += (int)(3 + sameCount - 5); + } + } + } + + // LEVEL2 + + for (int row = 0; row < moduleCount - 1; row++) + { + for (int col = 0; col < moduleCount - 1; col++) + { + var count = 0; + if (qrCode.IsDark(row, col)) count++; + if (qrCode.IsDark(row + 1, col)) count++; + if (qrCode.IsDark(row, col + 1)) count++; + if (qrCode.IsDark(row + 1, col + 1)) count++; + if (count == 0 || count == 4) + { + lostPoint += 3; + } + } + } + + // LEVEL3 + + for (int row = 0; row < moduleCount; row++) + { + for (int col = 0; col < moduleCount - 6; col++) + { + if (qrCode.IsDark(row, col) + && !qrCode.IsDark(row, col + 1) + && qrCode.IsDark(row, col + 2) + && qrCode.IsDark(row, col + 3) + && qrCode.IsDark(row, col + 4) + && !qrCode.IsDark(row, col + 5) + && qrCode.IsDark(row, col + 6)) + { + lostPoint += 40; + } + } + } + + for (int col = 0; col < moduleCount; col++) + { + for (int row = 0; row < moduleCount - 6; row++) + { + if (qrCode.IsDark(row, col) + && !qrCode.IsDark(row + 1, col) + && qrCode.IsDark(row + 2, col) + && qrCode.IsDark(row + 3, col) + && qrCode.IsDark(row + 4, col) + && !qrCode.IsDark(row + 5, col) + && qrCode.IsDark(row + 6, col)) + { + lostPoint += 40; + } + } + } + + // LEVEL4 + + int darkCount = 0; + + for (int col = 0; col < moduleCount; col++) + { + for (int row = 0; row < moduleCount; row++) + { + if (qrCode.IsDark(row, col)) + { + darkCount++; + } + } + } + + double ratio = Math.Abs(100.0 * darkCount / moduleCount / moduleCount - 50) / 5; + lostPoint += ratio * 10; + + return lostPoint; + + } + + + + + internal static int GetBCHTypeInfo(int data) + { + int d = (data << 10); + int s = 0; + while ((s = (int)(QRUtil.GetBCHDigit(d) - QRUtil.GetBCHDigit(QRUtil.G15))) >= 0) + { + d ^= (Convert.ToInt32(QRUtil.G15) << s); + } + return (int)((data << 10) | d) ^ QRUtil.G15_MASK; + } + + internal static int GetBCHTypeNumber(int data) + { + int d = data << 12; + while (QRUtil.GetBCHDigit(d) - QRUtil.GetBCHDigit(QRUtil.G18) >= 0) + { + d ^= (QRUtil.G18 << (QRUtil.GetBCHDigit(d) - QRUtil.GetBCHDigit(QRUtil.G18))); + } + return (data << 12) | d; + } + + internal static int GetBCHDigit(int dataInt) + { + + int digit = 0; + uint data = Convert.ToUInt32(dataInt); + while (data != 0) + { + digit++; + data >>= 1; + } + + return digit; + } + + internal static int[] GetPatternPosition(int typeNumber) + { + return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1]; + } + + internal static bool GetMask(QRMaskPattern maskPattern, int i, int j) + { + + switch (maskPattern) + { + + case QRMaskPattern.PATTERN000: return (i + j) % 2 == 0; + case QRMaskPattern.PATTERN001: return i % 2 == 0; + case QRMaskPattern.PATTERN010: return j % 3 == 0; + case QRMaskPattern.PATTERN011: return (i + j) % 3 == 0; + case QRMaskPattern.PATTERN100: return (Math.Floor((double) (i / 2)) + Math.Floor((double) (j / 3))) % 2 == 0; + case QRMaskPattern.PATTERN101: return (i * j) % 2 + (i * j) % 3 == 0; + case QRMaskPattern.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 == 0; + case QRMaskPattern.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 == 0; + + default: + throw new Error("bad maskPattern:" + maskPattern); + } + } + + + + internal static QRPolynomial GetErrorCorrectPolynomial(int errorCorrectLength) + { + QRPolynomial a = new QRPolynomial(new DataCache() { 1 }, 0); + + for (int i = 0; i < errorCorrectLength; i++) + { + a = a.Multiply(new QRPolynomial(new DataCache() { 1, QRMath.GExp(i) }, 0)); + } + + return a; + } + } + + internal struct QRPolynomial + { + private int[] m_num; + public QRPolynomial(DataCache num, int shift) + : this() + { + if (num == null) + { + throw new Error(); + } + + int offset = 0; + + while (offset < num.Count && num[offset] == 0) + { + offset++; + } + + this.m_num = new int[num.Count - offset + shift]; + for (int i = 0; i < num.Count - offset; i++) + { + this.m_num[i] = num[(int)(i + offset)]; + } + } + + public int Get(int index) + { + return this.m_num[(int)index]; + } + + public int GetLength() + { + return (int)this.m_num.Length; + } + + public QRPolynomial Multiply(QRPolynomial e) + { + + var num = new DataCache(this.GetLength() + e.GetLength() - 1); + + for (int i = 0; i < this.GetLength(); i++) + { + for (int j = 0; j < e.GetLength(); j++) + { + num[i + j] ^= QRMath.GExp(QRMath.GLog(this.Get(i)) + QRMath.GLog(e.Get(j))); + } + } + + return new QRPolynomial(num, 0); + } + + public QRPolynomial Mod(QRPolynomial e) + { + + if (Convert.ToInt64(this.GetLength()) - Convert.ToInt64(e.GetLength()) < 0) + { + return this; + } + + int ratio = QRMath.GLog(this.Get(0)) - QRMath.GLog(e.Get(0)); + + var num = new DataCache(this.GetLength()); + + for (int i = 0; i < this.GetLength(); i++) + { + num[i] = this.Get(i); + } + + for (int i = 0; i < e.GetLength(); i++) + { + num[i] ^= QRMath.GExp(QRMath.GLog(e.Get(i)) + ratio); + } + + // recursive call + return new QRPolynomial(num, 0).Mod(e); + } + } + + + internal static class QRMath + { + private static readonly int[] EXP_TABLE; + private static readonly int[] LOG_TABLE; + + static QRMath() + { + EXP_TABLE = new int[256]; + LOG_TABLE = new int[256]; + for (int i = 0; i < 8; i++) + { + QRMath.EXP_TABLE[i] = (int)(1 << (int)i); + } + for (int i = 8; i < 256; i++) + { + QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] + ^ QRMath.EXP_TABLE[i - 5] + ^ QRMath.EXP_TABLE[i - 6] + ^ QRMath.EXP_TABLE[i - 8]; + } + for (int i = 0; i < 255; i++) + { + QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i; + } + } + + internal static int GLog(int n) + { + if (n < 1) + { + throw new Error("glog(" + n + ")"); + } + return QRMath.LOG_TABLE[n]; + } + + internal static int GExp(int n) + { + while (n < 0) + { + n += 255; + } + while (n >= 256) + { + n -= 255; + } + return QRMath.EXP_TABLE[n]; + } + } + + public struct QR8bitByte + { + public QRMode Mode { get; private set; } + private string m_data { get; set; } + + public QR8bitByte(string data) + : this() + { + m_data = data; + Mode = QRMode.MODE_8BIT_BYTE; + } + + public int Length + { + get + { + return m_data.Length; + } + } + + public void Write(QRBitBuffer buffer) + { + for (int i = 0; i < m_data.Length; ++i) + { + //item + buffer.Put(m_data[i], 8); + } + ///buffer = Data; + } + + + } + + internal class DataCache : List + { + public DataCache(int capacity) + : base() + { + for (int i = 0; i < capacity; i++) + { + base.Add(0); + } + } + + public DataCache() + : base() + { + + } + + + } + + internal struct QRRSBlock + { + private static readonly int[][] RS_BLOCK_TABLE = new int[][] { + // L + // M + // Q + // H + + // 1 + new int [] {1, 26, 19}, + new int [] {1, 26, 16}, + new int [] {1, 26, 13}, + new int [] {1, 26, 9}, + + // 2 + new int [] {1, 44, 34}, + new int [] {1, 44, 28}, + new int [] {1, 44, 22}, + new int [] {1, 44, 16}, + + // 3 + new int [] {1, 70, 55}, + new int [] {1, 70, 44}, + new int [] {2, 35, 17}, + new int [] {2, 35, 13}, + + // 4 + new int [] {1, 100, 80}, + new int [] {2, 50, 32}, + new int [] {2, 50, 24}, + new int [] {4, 25, 9}, + + // 5 + new int [] {1, 134, 108}, + new int [] {2, 67, 43}, + new int [] {2, 33, 15, 2, 34, 16}, + new int [] {2, 33, 11, 2, 34, 12}, + + // 6 + new int [] {2, 86, 68}, + new int [] {4, 43, 27}, + new int [] {4, 43, 19}, + new int [] {4, 43, 15}, + + // 7 + new int [] {2, 98, 78}, + new int [] {4, 49, 31}, + new int [] {2, 32, 14, 4, 33, 15}, + new int [] {4, 39, 13, 1, 40, 14}, + + // 8 + new int [] {2, 121, 97}, + new int [] {2, 60, 38, 2, 61, 39}, + new int [] {4, 40, 18, 2, 41, 19}, + new int [] {4, 40, 14, 2, 41, 15}, + + // 9 + new int [] {2, 146, 116}, + new int [] {3, 58, 36, 2, 59, 37}, + new int [] {4, 36, 16, 4, 37, 17}, + new int [] {4, 36, 12, 4, 37, 13}, + + // 10 + new int [] {2, 86, 68, 2, 87, 69}, + new int [] {4, 69, 43, 1, 70, 44}, + new int [] {6, 43, 19, 2, 44, 20}, + new int [] {6, 43, 15, 2, 44, 16} + }; + + + public int DataCount { get; private set; } + public int TotalCount { get; set; } + + public QRRSBlock(int totalCount, int dataCount) + : this() + { + TotalCount = totalCount; + DataCount = dataCount; + } + public static List GetRSBlocks(int typeNumber, QRErrorCorrectLevel errorCorrectLevel) + { + + int[] rsBlock = GetRsBlockTable(typeNumber, errorCorrectLevel); + + if (rsBlock == null) + { + throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel); + } + + int length = (int)rsBlock.Length / 3; + + var list = new List(); + + for (int i = 0; i < length; i++) + { + + int count = rsBlock[i * 3 + 0]; + int totalCount = rsBlock[i * 3 + 1]; + int dataCount = rsBlock[i * 3 + 2]; + + for (int j = 0; j < count; j++) + { + list.Add(new QRRSBlock(totalCount, dataCount)); + } + } + + return list; + } + + private static int[] GetRsBlockTable(int typeNumber, QRErrorCorrectLevel errorCorrectLevel) + { + switch (errorCorrectLevel) + { + case QRErrorCorrectLevel.L: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0]; + case QRErrorCorrectLevel.M: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1]; + case QRErrorCorrectLevel.Q: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2]; + case QRErrorCorrectLevel.H: + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3]; + default: + return null; + } + } + } + + public class QRCode + { + private const int PAD0 = 0xEC; + private const int PAD1 = 0x11; + private List m_dataList = new List(); + private int m_typeNumber; + private DataCache m_dataCache; + private int m_moduleCount; + private bool?[][] m_modules; + private QRErrorCorrectLevel m_errorCorrectLevel; + public QRCode(Options options) + : this(options.TypeNumber, options.CorrectLevel) + { + AddData(options.Text); + } + + public QRCode(int typeNumber, QRErrorCorrectLevel level) + { + m_typeNumber = typeNumber; + m_errorCorrectLevel = level; + m_dataCache = null; + } + + public void AddData(string data) + { + m_dataCache = null; + m_dataList.Add(new QR8bitByte(data)); + } + + public void Make() + { + MakeImpl(false, GetBestMaskPattern()); + } + + private QRMaskPattern GetBestMaskPattern() + { + double minLostPoint = 0; + QRMaskPattern pattern = 0; + for (int i = 0; i < 8; i++) + { + this.MakeImpl(true, (QRMaskPattern)i); + + double lostPoint = QRUtil.GetLostPoint(this); + + if (i == 0 || minLostPoint > lostPoint) + { + minLostPoint = lostPoint; + pattern = (QRMaskPattern)i; + } + } + + return pattern; + } + + + + private void MakeImpl(bool test, QRMaskPattern maskPattern) + { + m_moduleCount = this.m_typeNumber * 4 + 17; + m_modules = new bool?[m_moduleCount][]; + for (int row = 0; row < m_moduleCount; row++) + { + + m_modules[row] = new bool?[(m_moduleCount)]; + + for (var col = 0; col < m_moduleCount; col++) + { + m_modules[row][col] = null; //(col + row) % 3; + } + } + + this.SetupPositionProbePattern(0, 0); + this.SetupPositionProbePattern(m_moduleCount - 7, 0); + this.SetupPositionProbePattern(0, m_moduleCount - 7); + this.SetupPositionAdjustPattern(); + this.SetupTimingPattern(); + this.setupTypeInfo(test, maskPattern); + + if (m_typeNumber >= 7) + { + this.setupTypeNumber(test); + } + + if (this.m_dataCache == null) + { + this.m_dataCache = CreateData(this.m_typeNumber, this.m_errorCorrectLevel, this.m_dataList); + } + + MapData(this.m_dataCache, maskPattern); + + } + + public bool IsDark(int row, int col) + { + return m_modules[(int)row][(int)col].Value; + } + + private void SetupTimingPattern() + { + for (var r = 8; r < this.m_moduleCount - 8; r++) + { + if (this.m_modules[r][6] != null) + { + continue; + } + this.m_modules[r][6] = (r % 2 == 0); + } + + for (var c = 8; c < this.m_moduleCount - 8; c++) + { + if (this.m_modules[6][c] != null) + { + continue; + } + this.m_modules[6][c] = (c % 2 == 0); + } + } + + private void setupTypeNumber(bool test) + { + var bits = QRUtil.GetBCHTypeNumber(m_typeNumber); + + for (var i = 0; i < 18; i++) + { + var mod = (!test && ((bits >> i) & 1) == 1); + this.m_modules[(int)Math.Floor((double) (i / 3))][i % 3 + this.m_moduleCount - 8 - 3] = mod; + } + + for (var i = 0; i < 18; i++) + { + var mod = (!test && ((bits >> i) & 1) == 1); + this.m_modules[i % 3 + this.m_moduleCount - 8 - 3][(int)Math.Floor((double) (i / 3))] = mod; + } + } + private void SetupPositionAdjustPattern() + { + var pos = QRUtil.GetPatternPosition(m_typeNumber); + + for (var i = 0; i < pos.Length; i++) + { + + for (var j = 0; j < pos.Length; j++) + { + + var row = pos[i]; + var col = pos[j]; + + if (this.m_modules[row][col] != null) + { + continue; + } + + for (var r = -2; r <= 2; r++) + { + + for (var c = -2; c <= 2; c++) + { + + if (r == -2 || r == 2 || c == -2 || c == 2 + || (r == 0 && c == 0)) + { + this.m_modules[row + r][col + c] = true; + } + else + { + this.m_modules[row + r][col + c] = false; + } + } + } + } + } + } + + + private void setupTypeInfo(bool test, QRMaskPattern maskPattern) + { + + var data = ((int)this.m_errorCorrectLevel << 3) | (int)maskPattern; + var bits = QRUtil.GetBCHTypeInfo(data); + + // vertical + for (var i = 0; i < 15; i++) + { + + var mod = (!test && ((bits >> i) & 1) == 1); + + if (i < 6) + { + this.m_modules[i][8] = mod; + } + else if (i < 8) + { + this.m_modules[i + 1][8] = mod; + } + else + { + this.m_modules[this.m_moduleCount - 15 + i][8] = mod; + } + } + + // horizontal + for (var i = 0; i < 15; i++) + { + + var mod = (!test && ((bits >> i) & 1) == 1); + + if (i < 8) + { + this.m_modules[8][this.m_moduleCount - i - 1] = mod; + } + else if (i < 9) + { + this.m_modules[8][15 - i - 1 + 1] = mod; + } + else + { + this.m_modules[8][15 - i - 1] = mod; + } + } + + // fixed module + this.m_modules[this.m_moduleCount - 8][8] = (!test); + + } + + private void MapData(DataCache data, QRMaskPattern maskPattern) + { + + int inc = -1; + int row = (int)this.m_moduleCount - 1; + int bitIndex = 7; + int byteIndex = 0; + + for (var col = this.m_moduleCount - 1; col > 0; col -= 2) + { + + if (col == 6) col--; + + while (true) + { + + for (int c = 0; c < 2; c++) + { + + if (this.m_modules[row][col - c] == null) + { + + bool dark = false; + + if (byteIndex < data.Count) + { + dark = (((Convert.ToUInt32(data[byteIndex]) >> bitIndex) & 1) == 1); + } + + bool mask = QRUtil.GetMask(maskPattern, (int)row, col - c); + + if (mask) + { + dark = !dark; + } + + this.m_modules[row][col - c] = dark; + bitIndex--; + + if (bitIndex == -1) + { + byteIndex++; + bitIndex = 7; + } + } + } + + row += inc; + + if (row < 0 || this.m_moduleCount <= row) + { + row -= inc; + inc = -inc; + break; + } + } + } + + } + + private DataCache CreateData(int typeNumber, QRErrorCorrectLevel errorCorrectLevel, List dataList) + { + List rsBlocks = QRRSBlock.GetRSBlocks(typeNumber, errorCorrectLevel); + + var buffer = new QRBitBuffer(); + + for (int i = 0; i < dataList.Count; i++) + { + QR8bitByte data = dataList[i]; + + buffer.Put((int)data.Mode, 4); + buffer.Put(data.Length, QRUtil.GetLengthInBits(data.Mode, typeNumber)); + data.Write(buffer); + } + + // calc num max data. + int totalDataCount = 0; + for (var i = 0; i < rsBlocks.Count; i++) + { + totalDataCount += rsBlocks[i].DataCount; + } + + if (buffer.GetLengthInBits() > totalDataCount * 8) + { + throw new Error("code length overflow. (" + + buffer.GetLengthInBits() + + ">" + + totalDataCount * 8 + + ")"); + } + + // end code + if (buffer.GetLengthInBits() + 4 <= totalDataCount * 8) + { + buffer.Put(0, 4); + } + + // padding + while (buffer.GetLengthInBits() % 8 != 0) + { + buffer.PutBit(false); + } + + // padding + while (true) + { + + if (buffer.GetLengthInBits() >= totalDataCount * 8) + { + break; + } + buffer.Put(QRCode.PAD0, 8); + + if (buffer.GetLengthInBits() >= totalDataCount * 8) + { + break; + } + buffer.Put(QRCode.PAD1, 8); + } + + return CreateBytes(buffer, rsBlocks); + } + + private DataCache CreateBytes(QRBitBuffer buffer, List rsBlocks) + { + + int offset = 0; + + int maxDcCount = 0; + int maxEcCount = 0; + + var dcdata = new DataCache[(rsBlocks.Count)]; + var ecdata = new DataCache[(rsBlocks.Count)]; + + for (int r = 0; r < rsBlocks.Count; r++) + { + + int dcCount = rsBlocks[(int)r].DataCount; + int ecCount = rsBlocks[(int)r].TotalCount - dcCount; + + maxDcCount = Math.Max(maxDcCount, dcCount); + maxEcCount = Math.Max(maxEcCount, ecCount); + + dcdata[r] = new DataCache(dcCount); + + for (int i = 0; i < dcdata[r].Count; i++) + { + dcdata[r][i] = 0xff & buffer.m_buffer[(int)(i + offset)]; + } + offset += dcCount; + + QRPolynomial rsPoly = QRUtil.GetErrorCorrectPolynomial(ecCount); + QRPolynomial rawPoly = new QRPolynomial(dcdata[r], rsPoly.GetLength() - 1); + + var modPoly = rawPoly.Mod(rsPoly); + ecdata[r] = new DataCache(rsPoly.GetLength() - 1); + for (int i = 0; i < ecdata[r].Count; i++) + { + int modIndex = i + modPoly.GetLength() - (int)ecdata[r].Count; + ecdata[r][i] = (modIndex >= 0) ? modPoly.Get(modIndex) : 0; + } + + } + + int totalCodeCount = 0; + for (int i = 0; i < rsBlocks.Count; i++) + { + totalCodeCount += rsBlocks[(int)i].TotalCount; + } + + var data = new DataCache(totalCodeCount); + int index = 0; + + for (int i = 0; i < maxDcCount; i++) + { + for (int r = 0; r < rsBlocks.Count; r++) + { + if (i < dcdata[r].Count) + { + data[index++] = dcdata[r][i]; + } + } + } + + for (int i = 0; i < maxEcCount; i++) + { + for (int r = 0; r < rsBlocks.Count; r++) + { + if (i < ecdata[r].Count) + { + data[index++] = ecdata[r][i]; + } + } + } + + return data; + + } + private void SetupPositionProbePattern(int row, int col) + { + for (int r = -1; r <= 7; r++) + { + + if (row + r <= -1 || this.m_moduleCount <= row + r) continue; + + for (int c = -1; c <= 7; c++) + { + + if (col + c <= -1 || this.m_moduleCount <= col + c) continue; + + if ((0 <= r && r <= 6 && (c == 0 || c == 6)) + || (0 <= c && c <= 6 && (r == 0 || r == 6)) + || (2 <= r && r <= 4 && 2 <= c && c <= 4)) + { + this.m_modules[row + r][col + c] = true; + } + else + { + this.m_modules[row + r][col + c] = false; + } + } + } + } + + public int GetModuleCount() + { + return this.m_moduleCount; + } + + internal int getBestMaskPattern() + { + + double minLostPoint = 0; + int pattern = 0; + + for (int i = 0; i < 8; i++) + { + + this.MakeImpl(true, (QRMaskPattern)i); + + double lostPoint = QRUtil.GetLostPoint(this); + + if (i == 0 || minLostPoint > lostPoint) + { + minLostPoint = lostPoint; + pattern = i; + } + } + + return pattern; + } + } + + public class QRBitBuffer + { + internal List m_buffer = new List(); + private int m_length = 0; + public bool Get(int index) + { + int bufIndex = Convert.ToInt32(Math.Floor((double) (index / 8))); + return ((Convert.ToUInt32(this.m_buffer[bufIndex]) >> (7 - index % 8)) & 1) == 1; + } + + public void Put(int num, int length) + { + for (var i = 0; i < length; i++) + { + this.PutBit(((Convert.ToUInt32(num) >> (length - i - 1)) & 1) == 1); + } + } + + public int GetLengthInBits() + { + return m_length; + } + + public void PutBit(bool bit) + { + + int bufIndex = (int)Math.Floor((double) (this.m_length / 8)); + if (this.m_buffer.Count <= bufIndex) + { + this.m_buffer.Add(0); + } + + if (bit) + { + this.m_buffer[bufIndex] |= (int)(Convert.ToUInt32(0x80) >> (this.m_length % 8)); + } + this.m_length++; + } + } +} diff --git a/shadowsocks-csharp/Controller/Local.cs b/shadowsocks-csharp/Controller/Local.cs index db6c71b8..cace2f57 100755 --- a/shadowsocks-csharp/Controller/Local.cs +++ b/shadowsocks-csharp/Controller/Local.cs @@ -13,7 +13,7 @@ namespace Shadowsocks.Controller { private Server config; //private Encryptor encryptor; - Socket listener; + Socket _listener; public Local(Server config) { this.config = config; @@ -25,24 +25,24 @@ namespace Shadowsocks.Controller try { // Create a TCP/IP socket. - listener = new Socket(AddressFamily.InterNetwork, + _listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint localEndPoint = new IPEndPoint(0, config.local_port); // Bind the socket to the local endpoint and listen for incoming connections. - listener.Bind(localEndPoint); - listener.Listen(100); + _listener.Bind(localEndPoint); + _listener.Listen(100); // Start an asynchronous socket to listen for connections. Console.WriteLine("Shadowsocks started"); - listener.BeginAccept( + _listener.BeginAccept( new AsyncCallback(AcceptCallback), - listener); + _listener); } catch(SocketException) { - listener.Close(); + _listener.Close(); throw; } @@ -50,7 +50,7 @@ namespace Shadowsocks.Controller public void Stop() { - listener.Close(); + _listener.Close(); } @@ -90,7 +90,7 @@ namespace Shadowsocks.Controller //handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, // new AsyncCallback(ReadCallback), state); } - catch (Exception) + catch { //Console.WriteLine(e.Message); } @@ -141,7 +141,7 @@ namespace Shadowsocks.Controller // Connect to the remote endpoint. remote.BeginConnect(remoteEP, - new AsyncCallback(connectCallback), null); + new AsyncCallback(ConnectCallback), null); } catch (Exception e) { @@ -182,17 +182,17 @@ namespace Shadowsocks.Controller ((IDisposable)encryptor).Dispose(); } - private void connectCallback(IAsyncResult ar) + private void ConnectCallback(IAsyncResult ar) { try { // Complete the connection. remote.EndConnect(ar); - Console.WriteLine("Socket connected to {0}", - remote.RemoteEndPoint.ToString()); + //Console.WriteLine("Socket connected to {0}", + // remote.RemoteEndPoint.ToString()); - handshakeReceive(); + HandshakeReceive(); } catch (Exception e) { @@ -201,12 +201,12 @@ namespace Shadowsocks.Controller } } - private void handshakeReceive() + private void HandshakeReceive() { try { connection.BeginReceive(connetionRecvBuffer, 0, 256, 0, - new AsyncCallback(handshakeReceiveCallback), null); + new AsyncCallback(HandshakeReceiveCallback), null); } catch (Exception e) { @@ -215,7 +215,7 @@ namespace Shadowsocks.Controller } } - private void handshakeReceiveCallback(IAsyncResult ar) + private void HandshakeReceiveCallback(IAsyncResult ar) { try { @@ -348,7 +348,6 @@ namespace Shadowsocks.Controller } else { - Console.WriteLine("bytesRead: " + bytesRead.ToString()); this.Close(); } } diff --git a/shadowsocks-csharp/Controller/PACServer.cs b/shadowsocks-csharp/Controller/PACServer.cs index bedce2e4..eab2ff60 100755 --- a/shadowsocks-csharp/Controller/PACServer.cs +++ b/shadowsocks-csharp/Controller/PACServer.cs @@ -33,7 +33,7 @@ namespace Shadowsocks.Controller new AsyncCallback(AcceptCallback), listener); - watchPACFile(); + WatchPacFile(); } public string TouchPACFile() @@ -61,7 +61,7 @@ namespace Shadowsocks.Controller Socket conn = listener.EndAccept(ar); conn.BeginReceive(new byte[1024], 0, 1024, 0, - new AsyncCallback(receiveCallback), conn); + new AsyncCallback(ReceiveCallback), conn); } catch (Exception e) { @@ -69,7 +69,7 @@ namespace Shadowsocks.Controller } } - private string getPACContent() + private string GetPACContent() { if (File.Exists(PAC_FILE)) { @@ -92,17 +92,17 @@ namespace Shadowsocks.Controller return System.Text.Encoding.UTF8.GetString(buffer, 0, n); } } - watchPACFile(); + WatchPacFile(); } - private void receiveCallback(IAsyncResult ar) + private void ReceiveCallback(IAsyncResult ar) { Socket conn = (Socket)ar.AsyncState; try { int bytesRead = conn.EndReceive(ar); - string pac = getPACContent(); + string pac = GetPACContent(); string proxy = "PROXY 127.0.0.1:8123;"; @@ -118,7 +118,7 @@ Connection: Close ", System.Text.Encoding.UTF8.GetBytes(pac).Length) + pac; byte[] response = System.Text.Encoding.UTF8.GetBytes(text); - conn.BeginSend(response, 0, response.Length, 0, new AsyncCallback(sendCallback), conn); + conn.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), conn); } else { @@ -132,13 +132,13 @@ Connection: Close } } - private void sendCallback(IAsyncResult ar) + private void SendCallback(IAsyncResult ar) { Socket conn = (Socket)ar.AsyncState; conn.Shutdown(SocketShutdown.Send); } - private void watchPACFile() + private void WatchPacFile() { if (watcher != null) { @@ -147,14 +147,14 @@ Connection: Close watcher = new FileSystemWatcher(Directory.GetCurrentDirectory()); watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; watcher.Filter = PAC_FILE; - watcher.Changed += watcher_Changed; - watcher.Created += watcher_Changed; - watcher.Deleted += watcher_Changed; - watcher.Renamed += watcher_Changed; + watcher.Changed += Watcher_Changed; + watcher.Created += Watcher_Changed; + watcher.Deleted += Watcher_Changed; + watcher.Renamed += Watcher_Changed; watcher.EnableRaisingEvents = true; } - void watcher_Changed(object sender, FileSystemEventArgs e) + private void Watcher_Changed(object sender, FileSystemEventArgs e) { if (PACFileChanged != null) { diff --git a/shadowsocks-csharp/Controller/PolipoRunner.cs b/shadowsocks-csharp/Controller/PolipoRunner.cs index 1f9802cf..9f3c2187 100755 --- a/shadowsocks-csharp/Controller/PolipoRunner.cs +++ b/shadowsocks-csharp/Controller/PolipoRunner.cs @@ -11,11 +11,11 @@ namespace Shadowsocks.Controller { class PolipoRunner { - private Process process; + private Process _process; public void Start(Server config) { - if (process == null) + if (_process == null) { Process[] existingPolipo = Process.GetProcessesByName("ss_polipo"); foreach (Process p in existingPolipo) @@ -36,34 +36,34 @@ namespace Shadowsocks.Controller FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig)); FileManager.UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe); - process = new Process(); + _process = new Process(); // Configure the process using the StartInfo properties. - process.StartInfo.FileName = temppath + "/ss_polipo.exe"; - process.StartInfo.Arguments = "-c \"" + temppath + "/polipo.conf\""; - process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - process.StartInfo.UseShellExecute = false; - process.StartInfo.CreateNoWindow = true; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.RedirectStandardError = true; + _process.StartInfo.FileName = temppath + "/ss_polipo.exe"; + _process.StartInfo.Arguments = "-c \"" + temppath + "/polipo.conf\""; + _process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + _process.StartInfo.UseShellExecute = false; + _process.StartInfo.CreateNoWindow = true; + _process.StartInfo.RedirectStandardOutput = true; + _process.StartInfo.RedirectStandardError = true; //process.StandardOutput - process.Start(); + _process.Start(); } } public void Stop() { - if (process != null) + if (_process != null) { try { - process.Kill(); - process.WaitForExit(); + _process.Kill(); + _process.WaitForExit(); } catch (InvalidOperationException) { // do nothing } - process = null; + _process = null; } } } diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 4111d2b8..5af0bf38 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -14,7 +14,7 @@ namespace Shadowsocks.Controller private Local local; private PACServer pacServer; - private Configuration config; + private Configuration _config; private PolipoRunner polipoRunner; private bool stopped = false; @@ -31,10 +31,10 @@ namespace Shadowsocks.Controller public ShadowsocksController() { - config = Configuration.Load(); + _config = Configuration.Load(); polipoRunner = new PolipoRunner(); - polipoRunner.Start(config.GetCurrentServer()); - local = new Local(config.GetCurrentServer()); + polipoRunner.Start(_config.GetCurrentServer()); + local = new Local(_config.GetCurrentServer()); try { local.Start(); @@ -47,20 +47,20 @@ namespace Shadowsocks.Controller Console.WriteLine(e.Message); } - updateSystemProxy(); + UpdateSystemProxy(); } public void SaveConfig(Configuration newConfig) { Configuration.Save(newConfig); // some logic in configuration updated the config when saving, we need to read it again - config = Configuration.Load(); + _config = Configuration.Load(); local.Stop(); polipoRunner.Stop(); - polipoRunner.Start(config.GetCurrentServer()); + polipoRunner.Start(_config.GetCurrentServer()); - local = new Local(config.GetCurrentServer()); + local = new Local(_config.GetCurrentServer()); local.Start(); if (ConfigChanged != null) @@ -71,7 +71,7 @@ namespace Shadowsocks.Controller public Server GetCurrentServer() { - return config.GetCurrentServer(); + return _config.GetCurrentServer(); } // always return copy @@ -83,9 +83,9 @@ namespace Shadowsocks.Controller public void ToggleEnable(bool enabled) { - config.enabled = enabled; - updateSystemProxy(); - SaveConfig(config); + _config.enabled = enabled; + UpdateSystemProxy(); + SaveConfig(_config); if (EnableStatusChanged != null) { EnableStatusChanged(this, new EventArgs()); @@ -101,7 +101,7 @@ namespace Shadowsocks.Controller stopped = true; local.Stop(); polipoRunner.Stop(); - if (config.enabled) + if (_config.enabled) { SystemProxy.Disable(); } @@ -124,9 +124,9 @@ namespace Shadowsocks.Controller return "ss://" + base64; } - private void updateSystemProxy() + private void UpdateSystemProxy() { - if (config.enabled) + if (_config.enabled) { SystemProxy.Enable(); } @@ -138,7 +138,7 @@ namespace Shadowsocks.Controller private void pacServer_PACFileChanged(object sender, EventArgs e) { - updateSystemProxy(); + UpdateSystemProxy(); } } diff --git a/shadowsocks-csharp/Controller/SystemProxy.cs b/shadowsocks-csharp/Controller/SystemProxy.cs index 803a326a..884c7260 100755 --- a/shadowsocks-csharp/Controller/SystemProxy.cs +++ b/shadowsocks-csharp/Controller/SystemProxy.cs @@ -1,4 +1,5 @@ -using Microsoft.Win32; +using System.Windows.Forms; +using Microsoft.Win32; using System; using System.Collections.Generic; using System.Runtime.InteropServices; @@ -13,32 +14,52 @@ namespace Shadowsocks.Controller public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int dwBufferLength); public const int INTERNET_OPTION_SETTINGS_CHANGED = 39; public const int INTERNET_OPTION_REFRESH = 37; - static bool settingsReturn, refreshReturn; + static bool _settingsReturn, _refreshReturn; public static void NotifyIE() { // These lines implement the Interface in the beginning of program // They cause the OS to refresh the settings, causing IP to realy update - settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0); - refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0); + _settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0); + _refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0); } public static void Enable() { - RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); - registry.SetValue("ProxyEnable", 0); - registry.SetValue("ProxyServer", ""); - registry.SetValue("AutoConfigURL", "http://127.0.0.1:8090/pac?t=" + GetTimestamp(DateTime.Now)); - SystemProxy.NotifyIE(); + try + { + RegistryKey registry = + Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", + true); + registry.SetValue("ProxyEnable", 0); + registry.SetValue("ProxyServer", ""); + registry.SetValue("AutoConfigURL", "http://127.0.0.1:8090/pac?t=" + GetTimestamp(DateTime.Now)); + SystemProxy.NotifyIE(); + } + catch (Exception) + { + MessageBox.Show("can not change registry!"); + throw; + } } public static void Disable() { - RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); - registry.SetValue("ProxyEnable", 0); - registry.SetValue("ProxyServer", ""); - registry.SetValue("AutoConfigURL", ""); - SystemProxy.NotifyIE(); + try + { + RegistryKey registry = + Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", + true); + registry.SetValue("ProxyEnable", 0); + registry.SetValue("ProxyServer", ""); + registry.SetValue("AutoConfigURL", ""); + SystemProxy.NotifyIE(); + } + catch (Exception) + { + MessageBox.Show("can not change registry!"); + throw; + } } private static String GetTimestamp(DateTime value) diff --git a/shadowsocks-csharp/Data/qrcode.htm b/shadowsocks-csharp/Data/qrcode.htm deleted file mode 100644 index 581f3a11..00000000 --- a/shadowsocks-csharp/Data/qrcode.htm +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - -
- - - diff --git a/shadowsocks-csharp/Data/qrcode.min.js.gz b/shadowsocks-csharp/Data/qrcode.min.js.gz deleted file mode 100644 index 48de1fc9..00000000 Binary files a/shadowsocks-csharp/Data/qrcode.min.js.gz and /dev/null differ diff --git a/shadowsocks-csharp/Encrypt/EncryptorFactory.cs b/shadowsocks-csharp/Encrypt/EncryptorFactory.cs index 422e0c2e..59111a69 100644 --- a/shadowsocks-csharp/Encrypt/EncryptorFactory.cs +++ b/shadowsocks-csharp/Encrypt/EncryptorFactory.cs @@ -1,16 +1,16 @@  -namespace Shadowsocks.Encrypt -{ - public static class EncryptorFactory - { - public static IEncryptor GetEncryptor(string method, string password) - { - if (string.IsNullOrEmpty(method) || method.ToLowerInvariant() == "table") - { - return new TableEncryptor(method, password); - } - - return new PolarSSLEncryptor(method, password); - } - } -} +namespace Shadowsocks.Encrypt +{ + public static class EncryptorFactory + { + public static IEncryptor GetEncryptor(string method, string password) + { + if (string.IsNullOrEmpty(method) || method.ToLowerInvariant() == "table") + { + return new TableEncryptor(method, password); + } + + return new PolarSSLEncryptor(method, password); + } + } +} diff --git a/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs b/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs index d2270196..fdd7ce19 100755 --- a/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs +++ b/shadowsocks-csharp/Encrypt/PolarSSLEncryptor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; +using System.Threading; namespace Shadowsocks.Encrypt { @@ -166,20 +167,24 @@ namespace Shadowsocks.Encrypt randBytes(outbuf, ivLen); InitCipher(ref _encryptCtx, outbuf, true); outlength = length + ivLen; - switch (_cipher) + lock (tempbuf) { - case CIPHER_AES: - PolarSSL.aes_crypt_cfb128(_encryptCtx, PolarSSL.AES_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, tempbuf); - break; - case CIPHER_BF: - PolarSSL.blowfish_crypt_cfb64(_encryptCtx, PolarSSL.BLOWFISH_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, tempbuf); - break; - case CIPHER_RC4: - PolarSSL.arc4_crypt(_encryptCtx, length, buf, tempbuf); - break; + // C# could be multi-threaded + switch (_cipher) + { + case CIPHER_AES: + PolarSSL.aes_crypt_cfb128(_encryptCtx, PolarSSL.AES_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, tempbuf); + break; + case CIPHER_BF: + PolarSSL.blowfish_crypt_cfb64(_encryptCtx, PolarSSL.BLOWFISH_ENCRYPT, length, ref _encryptIVOffset, _encryptIV, buf, tempbuf); + break; + case CIPHER_RC4: + PolarSSL.arc4_crypt(_encryptCtx, length, buf, tempbuf); + break; + } + outlength = length + ivLen; + Buffer.BlockCopy(tempbuf, 0, outbuf, ivLen, outlength); } - outlength = length + ivLen; - Buffer.BlockCopy(tempbuf, 0, outbuf, ivLen, outlength); } else { @@ -205,18 +210,22 @@ namespace Shadowsocks.Encrypt { InitCipher(ref _decryptCtx, buf, false); outlength = length - ivLen; - Buffer.BlockCopy(buf, ivLen, tempbuf, 0, length - ivLen); - switch (_cipher) + lock (tempbuf) { - case CIPHER_AES: - PolarSSL.aes_crypt_cfb128(_decryptCtx, PolarSSL.AES_DECRYPT, length - ivLen, ref _decryptIVOffset, _decryptIV, tempbuf, outbuf); - break; - case CIPHER_BF: - PolarSSL.blowfish_crypt_cfb64(_decryptCtx, PolarSSL.BLOWFISH_DECRYPT, length - ivLen, ref _decryptIVOffset, _decryptIV, tempbuf, outbuf); - break; - case CIPHER_RC4: - PolarSSL.arc4_crypt(_decryptCtx, length - ivLen, tempbuf, outbuf); - break; + // C# could be multi-threaded + Buffer.BlockCopy(buf, ivLen, tempbuf, 0, length - ivLen); + switch (_cipher) + { + case CIPHER_AES: + PolarSSL.aes_crypt_cfb128(_decryptCtx, PolarSSL.AES_DECRYPT, length - ivLen, ref _decryptIVOffset, _decryptIV, tempbuf, outbuf); + break; + case CIPHER_BF: + PolarSSL.blowfish_crypt_cfb64(_decryptCtx, PolarSSL.BLOWFISH_DECRYPT, length - ivLen, ref _decryptIVOffset, _decryptIV, tempbuf, outbuf); + break; + case CIPHER_RC4: + PolarSSL.arc4_crypt(_decryptCtx, length - ivLen, tempbuf, outbuf); + break; + } } } else diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index d5acbe6d..c45bb9f4 100755 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -33,11 +33,11 @@ namespace Shadowsocks.Model public static void CheckServer(Server server) { - checkPort(server.local_port); - checkPort(server.server_port); - checkPassword(server.password); - checkServer(server.server); - checkRemark(server.remarks); + CheckPort(server.local_port); + CheckPort(server.server_port); + CheckPassword(server.password); + CheckServer(server.server); + CheckRemark(server.remarks); } public static Configuration Load() @@ -106,7 +106,7 @@ namespace Shadowsocks.Model }; } - private static void assert(bool condition) + private static void Assert(bool condition) { if (!condition) { @@ -114,7 +114,7 @@ namespace Shadowsocks.Model } } - private static void checkPort(int port) + private static void CheckPort(int port) { if (port <= 0 || port > 65535) { @@ -122,7 +122,7 @@ namespace Shadowsocks.Model } } - private static void checkPassword(string password) + private static void CheckPassword(string password) { if (string.IsNullOrEmpty(password)) { @@ -130,7 +130,7 @@ namespace Shadowsocks.Model } } - private static void checkServer(string server) + private static void CheckServer(string server) { if (string.IsNullOrEmpty(server)) { @@ -138,7 +138,7 @@ namespace Shadowsocks.Model } } - private static void checkRemark(string remark) + private static void CheckRemark(string remark) { //remark is optional } diff --git a/shadowsocks-csharp/Properties/AssemblyInfo.cs b/shadowsocks-csharp/Properties/AssemblyInfo.cs index e6316b3a..02c3eba7 100755 --- a/shadowsocks-csharp/Properties/AssemblyInfo.cs +++ b/shadowsocks-csharp/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值, // 方法是按如下所示使用“*”: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.3")] +[assembly: AssemblyVersion("2.0.4")] // [assembly: AssemblyFileVersion("2.0.0")] diff --git a/shadowsocks-csharp/Properties/Resources.Designer.cs b/shadowsocks-csharp/Properties/Resources.Designer.cs index 077a5ff0..8c4f781e 100755 --- a/shadowsocks-csharp/Properties/Resources.Designer.cs +++ b/shadowsocks-csharp/Properties/Resources.Designer.cs @@ -104,50 +104,5 @@ namespace Shadowsocks.Properties { return ((byte[])(obj)); } } - - /// - /// Looks up a localized string similar to <!doctype html> - ///<html> - ///<head> - ///<script> - /// __QRCODELIB__ - ///</script> - ///<style> - /// body { - /// padding: 10px; - /// margin: 0; - /// } - /// #qrcode { - /// width:300px; - /// height:300px; - /// } - ///</style> - ///</head> - ///<body> - ///<div id="qrcode" name="qrcode"></div> - ///<script type="text/javascript"> - /// function genCode(code) { - /// new QRCode("qrcode", { - /// text: code, - /// width: 300, - /// height: 300, - /// colorDark : "#000000", - /// colorLig [rest of string was truncated]";. - /// - internal static string qrcode { - get { - return ResourceManager.GetString("qrcode", resourceCulture); - } - } - - /// - /// Looks up a localized resource of type System.Byte[]. - /// - internal static byte[] qrcode_min_js { - get { - object obj = ResourceManager.GetObject("qrcode_min_js", resourceCulture); - return ((byte[])(obj)); - } - } } } diff --git a/shadowsocks-csharp/Properties/Resources.resx b/shadowsocks-csharp/Properties/Resources.resx index 520c1732..14c098ec 100755 --- a/shadowsocks-csharp/Properties/Resources.resx +++ b/shadowsocks-csharp/Properties/Resources.resx @@ -130,10 +130,4 @@ ..\Data\proxy.pac.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\Data\qrcode.htm;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312 - - - ..\Data\qrcode.min.js.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - \ No newline at end of file diff --git a/shadowsocks-csharp/View/ConfigForm.Designer.cs b/shadowsocks-csharp/View/ConfigForm.Designer.cs index 6d6f8881..b2d20a84 100755 --- a/shadowsocks-csharp/View/ConfigForm.Designer.cs +++ b/shadowsocks-csharp/View/ConfigForm.Designer.cs @@ -55,6 +55,7 @@ this.ConfigItem = new System.Windows.Forms.MenuItem(); this.menuItem4 = new System.Windows.Forms.MenuItem(); this.editPACFileItem = new System.Windows.Forms.MenuItem(); + this.QRCodeItem = new System.Windows.Forms.MenuItem(); this.aboutItem = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); this.quitItem = new System.Windows.Forms.MenuItem(); @@ -63,7 +64,6 @@ this.AddButton = new System.Windows.Forms.Button(); this.ServerGroupBox = new System.Windows.Forms.GroupBox(); this.ServersListBox = new System.Windows.Forms.ListBox(); - this.QRCodeItem = new System.Windows.Forms.MenuItem(); this.tableLayoutPanel1.SuspendLayout(); this.panel1.SuspendLayout(); this.panel3.SuspendLayout(); @@ -329,6 +329,12 @@ this.editPACFileItem.Text = "Edit &PAC File..."; this.editPACFileItem.Click += new System.EventHandler(this.EditPACFileItem_Click); // + // QRCodeItem + // + this.QRCodeItem.Index = 4; + this.QRCodeItem.Text = "Show &QRCode..."; + this.QRCodeItem.Click += new System.EventHandler(this.QRCodeItem_Click); + // // aboutItem // this.aboutItem.Index = 5; @@ -396,18 +402,13 @@ this.ServersListBox.TabIndex = 5; this.ServersListBox.SelectedIndexChanged += new System.EventHandler(this.ServersListBox_SelectedIndexChanged); // - // QRCodeItem - // - this.QRCodeItem.Index = 4; - this.QRCodeItem.Text = "Show &QRCode..."; - this.QRCodeItem.Click += new System.EventHandler(this.QRCodeItem_Click); - // // ConfigForm // this.AcceptButton = this.OKButton; this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; this.AutoSize = true; + this.CancelButton = this.MyCancelButton; this.ClientSize = new System.Drawing.Size(489, 286); this.Controls.Add(this.ServersListBox); this.Controls.Add(this.ServerGroupBox); diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index 174d10fd..51079ed9 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -29,12 +29,12 @@ namespace Shadowsocks.View controller.ConfigChanged += controller_ConfigChanged; controller.PACFileReadyToOpen += controller_PACFileReadyToOpen; - loadCurrentConfiguration(); + LoadCurrentConfiguration(); } private void controller_ConfigChanged(object sender, EventArgs e) { - loadCurrentConfiguration(); + LoadCurrentConfiguration(); } private void controller_EnableStatusChanged(object sender, EventArgs e) @@ -50,14 +50,14 @@ namespace Shadowsocks.View } - private void showWindow() + private void ShowWindow() { this.Opacity = 1; this.Show(); IPTextBox.Focus(); } - private bool saveOldSelectedServer() + private bool SaveOldSelectedServer() { try { @@ -89,7 +89,7 @@ namespace Shadowsocks.View return false; } - private void loadSelectedServer() + private void LoadSelectedServer() { if (ServersListBox.SelectedIndex >= 0 && ServersListBox.SelectedIndex < modifiedConfiguration.configs.Count) { @@ -102,7 +102,7 @@ namespace Shadowsocks.View EncryptionSelect.Text = server.method == null ? "aes-256-cfb" : server.method; RemarksTextBox.Text = server.remarks; ServerGroupBox.Visible = true; - IPTextBox.Focus(); + //IPTextBox.Focus(); } else { @@ -110,7 +110,7 @@ namespace Shadowsocks.View } } - private void loadConfiguration(Configuration configuration) + private void LoadConfiguration(Configuration configuration) { ServersListBox.Items.Clear(); foreach (Server server in modifiedConfiguration.configs) @@ -119,19 +119,19 @@ namespace Shadowsocks.View } } - private void loadCurrentConfiguration() + private void LoadCurrentConfiguration() { modifiedConfiguration = controller.GetConfiguration(); - loadConfiguration(modifiedConfiguration); + LoadConfiguration(modifiedConfiguration); oldSelectedIndex = modifiedConfiguration.index; ServersListBox.SelectedIndex = modifiedConfiguration.index; - loadSelectedServer(); + LoadSelectedServer(); - updateServersMenu(); + UpdateServersMenu(); enableItem.Checked = modifiedConfiguration.enabled; } - private void updateServersMenu() + private void UpdateServersMenu() { var items = ServersItem.MenuItems; @@ -178,25 +178,25 @@ namespace Shadowsocks.View // we are moving back to oldSelectedIndex or doing a force move return; } - if (!saveOldSelectedServer()) + if (!SaveOldSelectedServer()) { // why this won't cause stack overflow? ServersListBox.SelectedIndex = oldSelectedIndex; return; } - loadSelectedServer(); + LoadSelectedServer(); oldSelectedIndex = ServersListBox.SelectedIndex; } private void AddButton_Click(object sender, EventArgs e) { - if (!saveOldSelectedServer()) + if (!SaveOldSelectedServer()) { return; } Server server = Configuration.GetDefaultServer(); modifiedConfiguration.configs.Add(server); - loadConfiguration(modifiedConfiguration); + LoadConfiguration(modifiedConfiguration); ServersListBox.SelectedIndex = modifiedConfiguration.configs.Count - 1; oldSelectedIndex = ServersListBox.SelectedIndex; } @@ -214,14 +214,14 @@ namespace Shadowsocks.View oldSelectedIndex = modifiedConfiguration.configs.Count - 1; } ServersListBox.SelectedIndex = oldSelectedIndex; - loadConfiguration(modifiedConfiguration); + LoadConfiguration(modifiedConfiguration); ServersListBox.SelectedIndex = oldSelectedIndex; - loadSelectedServer(); + LoadSelectedServer(); } private void Config_Click(object sender, EventArgs e) { - showWindow(); + ShowWindow(); } private void Quit_Click(object sender, EventArgs e) @@ -229,7 +229,7 @@ namespace Shadowsocks.View this.Close(); } - private void showFirstTimeBalloon() + private void ShowFirstTimeBalloon() { if (isFirstRun) { @@ -242,7 +242,7 @@ namespace Shadowsocks.View private void OKButton_Click(object sender, EventArgs e) { - if (!saveOldSelectedServer()) + if (!SaveOldSelectedServer()) { return; } @@ -253,14 +253,14 @@ namespace Shadowsocks.View } controller.SaveConfig(modifiedConfiguration); this.Hide(); - showFirstTimeBalloon(); + ShowFirstTimeBalloon(); } private void CancelButton_Click(object sender, EventArgs e) { this.Hide(); - loadCurrentConfiguration(); - showFirstTimeBalloon(); + LoadCurrentConfiguration(); + ShowFirstTimeBalloon(); } private void ConfigForm_FormClosed(object sender, FormClosedEventArgs e) @@ -275,7 +275,7 @@ namespace Shadowsocks.View private void notifyIcon1_DoubleClick(object sender, EventArgs e) { - showWindow(); + ShowWindow(); } @@ -305,7 +305,9 @@ namespace Shadowsocks.View private void QRCodeItem_Click(object sender, EventArgs e) { - new QRCodeForm(controller.GetQRCodeForCurrentServer()).Show(); + QRCodeForm qrCodeForm = new QRCodeForm(controller.GetQRCodeForCurrentServer()); + qrCodeForm.Icon = this.Icon; + qrCodeForm.Show(); } } } diff --git a/shadowsocks-csharp/View/QRCodeForm.Designer.cs b/shadowsocks-csharp/View/QRCodeForm.Designer.cs index 0a934d71..53037e16 100755 --- a/shadowsocks-csharp/View/QRCodeForm.Designer.cs +++ b/shadowsocks-csharp/View/QRCodeForm.Designer.cs @@ -28,42 +28,56 @@ /// private void InitializeComponent() { - this.QRCodeWebBrowser = new System.Windows.Forms.WebBrowser(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.panel1 = new System.Windows.Forms.Panel(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.panel1.SuspendLayout(); this.SuspendLayout(); // - // QRCodeWebBrowser + // pictureBox1 // - this.QRCodeWebBrowser.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.QRCodeWebBrowser.Location = new System.Drawing.Point(0, 0); - this.QRCodeWebBrowser.Margin = new System.Windows.Forms.Padding(0); - this.QRCodeWebBrowser.MinimumSize = new System.Drawing.Size(20, 20); - this.QRCodeWebBrowser.Name = "QRCodeWebBrowser"; - this.QRCodeWebBrowser.ScriptErrorsSuppressed = true; - this.QRCodeWebBrowser.ScrollBarsEnabled = false; - this.QRCodeWebBrowser.Size = new System.Drawing.Size(200, 200); - this.QRCodeWebBrowser.TabIndex = 0; + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox1.Location = new System.Drawing.Point(10, 10); + this.pictureBox1.Margin = new System.Windows.Forms.Padding(0); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(204, 202); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox1.TabIndex = 1; + this.pictureBox1.TabStop = false; + // + // panel1 + // + this.panel1.Controls.Add(this.pictureBox1); + this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Margin = new System.Windows.Forms.Padding(0); + this.panel1.Name = "panel1"; + this.panel1.Padding = new System.Windows.Forms.Padding(10); + this.panel1.Size = new System.Drawing.Size(224, 222); + this.panel1.TabIndex = 2; // // QRCodeForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.AutoSize = true; - this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.ClientSize = new System.Drawing.Size(204, 202); - this.Controls.Add(this.QRCodeWebBrowser); + this.ClientSize = new System.Drawing.Size(224, 222); + this.Controls.Add(this.panel1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; + this.MinimizeBox = false; this.Name = "QRCodeForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "QRCode"; this.Load += new System.EventHandler(this.QRCodeForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.panel1.ResumeLayout(false); this.ResumeLayout(false); } #endregion - private System.Windows.Forms.WebBrowser QRCodeWebBrowser; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.Panel panel1; } } \ No newline at end of file diff --git a/shadowsocks-csharp/View/QRCodeForm.cs b/shadowsocks-csharp/View/QRCodeForm.cs index 36c2c804..0a0ec840 100755 --- a/shadowsocks-csharp/View/QRCodeForm.cs +++ b/shadowsocks-csharp/View/QRCodeForm.cs @@ -1,4 +1,5 @@ -using Shadowsocks.Properties; +using QRCode4CS; +using Shadowsocks.Properties; using System; using System.Collections.Generic; using System.ComponentModel; @@ -21,32 +22,49 @@ namespace Shadowsocks.View InitializeComponent(); } - private string QRCodeHTML(string ssURL) + private void GenQR(string ssconfig) { - string html = Resources.qrcode; - string qrcodeLib; - - byte[] qrcodeGZ = Resources.qrcode_min_js; - byte[] buffer = new byte[1024 * 1024]; // builtin pac gzip size: maximum 1M - int n; - - using (GZipStream input = new GZipStream(new MemoryStream(qrcodeGZ), - CompressionMode.Decompress, false)) + string qrText = ssconfig; + QRCode4CS.QRCode qrCoded = new QRCode4CS.QRCode(6, QRErrorCorrectLevel.H); + qrCoded.AddData(qrText); + qrCoded.Make(); + int blockSize = 5; + Bitmap drawArea = new Bitmap((qrCoded.GetModuleCount() * blockSize), (qrCoded.GetModuleCount() * blockSize)); + for (int row = 0; row < qrCoded.GetModuleCount(); row++) { - n = input.Read(buffer, 0, buffer.Length); - if (n == 0) + for (int col = 0; col < qrCoded.GetModuleCount(); col++) { - throw new IOException("can not decompress qrcode lib"); + bool isDark = qrCoded.IsDark(row, col); + if (isDark) + { + for (int y = 0; y < blockSize; y++) + { + int myCol = (blockSize * (col - 1)) + (y + blockSize); + for (int x = 0; x < blockSize; x++) + { + drawArea.SetPixel((blockSize * (row - 1)) + (x + blockSize), myCol, Color.Black); + } + } + } + else + { + for (int y = 0; y < blockSize; y++) + { + int myCol = (blockSize * (col - 1)) + (y + blockSize); + for (int x = 0; x < blockSize; x++) + { + drawArea.SetPixel((blockSize * (row - 1)) + (x + blockSize), myCol, Color.White); + } + } + } } - qrcodeLib = System.Text.Encoding.UTF8.GetString(buffer, 0, n); } - string result = html.Replace("__QRCODELIB__", qrcodeLib); - return result.Replace("__SSURL__", ssURL); + pictureBox1.Image = drawArea; } private void QRCodeForm_Load(object sender, EventArgs e) { - QRCodeWebBrowser.DocumentText = QRCodeHTML(code); + GenQR(code); } } } diff --git a/shadowsocks-csharp/app.config b/shadowsocks-csharp/app.config index dde978a0..867ff468 100755 --- a/shadowsocks-csharp/app.config +++ b/shadowsocks-csharp/app.config @@ -1,6 +1,6 @@ - + diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 22422445..c1c08d22 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -21,7 +21,8 @@ 3.5 - + + publish\ true Disk @@ -37,26 +38,6 @@ false true - - true - full - false - bin\Debug\ - TRACE;DEBUG;SIMPLE_JSON_NO_LINQ_EXPRESSION - prompt - 4 - false - true - - - pdbonly - true - bin\Release\ - TRACE;SIMPLE_JSON_NO_LINQ_EXPRESSION - prompt - 4 - false - true bin\x86\Debug\ @@ -65,26 +46,26 @@ x86 prompt ManagedMinimumRules.ruleset + false bin\x86\Release\ - TRACE;SIMPLE_JSON_NO_LINQ_EXPRESSION + TRACE true pdbonly x86 prompt ManagedMinimumRules.ruleset + false - - - + @@ -134,7 +115,6 @@ - SettingsSingleFileGenerator Settings.Designer.cs @@ -147,7 +127,6 @@ -