@@ -90,180 +90,6 @@ namespace Shadowsocks.Controller | |||||
return valid_lines.ToArray(); | return valid_lines.ToArray(); | ||||
} | } | ||||
/* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ | |||||
public string[] GetDomains() | |||||
{ | |||||
List<string> lines = new List<string>(GetValidLines()); | |||||
lines.AddRange(GetBuildIn()); | |||||
List<string> domains = new List<string>(lines.Count); | |||||
for (int i = 0; i < lines.Count; i++) | |||||
{ | |||||
string line = lines[i]; | |||||
if (line.IndexOf(".*") >= 0) | |||||
continue; | |||||
if (line.StartsWith("http://")) | |||||
line = line.Substring(7); | |||||
else if (line.StartsWith("https://")) | |||||
line = line.Substring(8); | |||||
if (line.IndexOf("*") >= 0) | |||||
line = line.Replace("*", "/"); | |||||
if (line.StartsWith("||")) | |||||
while (line.StartsWith("||")) | |||||
line = line.Substring(2); | |||||
else if (line.StartsWith("|")) | |||||
line = line.TrimStart('|'); | |||||
else if (line.StartsWith(".")) | |||||
line = line.TrimStart('.'); | |||||
if (line.StartsWith("!")) | |||||
continue; | |||||
else if (line.StartsWith("[")) | |||||
continue; | |||||
else if (line.StartsWith("@")) | |||||
continue; /*ignore white list*/ | |||||
int pos = line.IndexOfAny(new char[] { '/' }); | |||||
if (pos >= 0) | |||||
line = line.Substring(0, pos); | |||||
if (line.Length > 0) | |||||
domains.Add(line); | |||||
} | |||||
return RemoveDuplicate(domains.ToArray()); | |||||
} | |||||
/* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ | |||||
public string[] GetReducedDomains() | |||||
{ | |||||
string[] domains = GetDomains(); | |||||
List<string> new_domains = new List<string>(domains.Length); | |||||
TldIndex tldIndex = GetTldIndex(); | |||||
foreach (string domain in domains) | |||||
{ | |||||
string last_root_domain = null; | |||||
int pos; | |||||
pos = domain.LastIndexOf('.'); | |||||
last_root_domain = domain.Substring(pos + 1); | |||||
if (!tldIndex.Contains(last_root_domain)) | |||||
continue; | |||||
while (pos > 0) | |||||
{ | |||||
pos = domain.LastIndexOf('.', pos - 1); | |||||
last_root_domain = domain.Substring(pos + 1); | |||||
if (tldIndex.Contains(last_root_domain)) | |||||
continue; | |||||
else | |||||
break; | |||||
} | |||||
if (last_root_domain != null) | |||||
new_domains.Add(last_root_domain); | |||||
} | |||||
return RemoveDuplicate(new_domains.ToArray()); | |||||
} | |||||
private string[] RemoveDuplicate(string[] src) | |||||
{ | |||||
List<string> list = new List<string>(src.Length); | |||||
Dictionary<string, string> dic = new Dictionary<string, string>(src.Length); | |||||
foreach (string s in src) | |||||
{ | |||||
if (!dic.ContainsKey(s)) | |||||
{ | |||||
dic.Add(s, s); | |||||
list.Add(s); | |||||
} | |||||
} | |||||
return list.ToArray(); | |||||
} | |||||
private string[] GetTlds() | |||||
{ | |||||
string[] tlds = null; | |||||
byte[] pacGZ = Resources.tld_txt; | |||||
byte[] buffer = new byte[1024]; | |||||
int n; | |||||
using (MemoryStream sb = new MemoryStream()) | |||||
{ | |||||
using (GZipStream input = new GZipStream(new MemoryStream(pacGZ), | |||||
CompressionMode.Decompress, false)) | |||||
{ | |||||
while ((n = input.Read(buffer, 0, buffer.Length)) > 0) | |||||
{ | |||||
sb.Write(buffer, 0, n); | |||||
} | |||||
} | |||||
tlds = System.Text.Encoding.UTF8.GetString(sb.ToArray()) | |||||
.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); | |||||
} | |||||
return tlds; | |||||
} | |||||
private TldIndex GetTldIndex() | |||||
{ | |||||
string[] tlds = GetTlds(); | |||||
TldIndex index = new TldIndex(); | |||||
foreach (string tld in tlds) | |||||
{ | |||||
index.Add(tld); | |||||
} | |||||
return index; | |||||
} | |||||
private string[] GetBuildIn() | |||||
{ | |||||
string[] buildin = null; | |||||
byte[] builtinGZ = Resources.builtin_txt; | |||||
byte[] buffer = new byte[1024]; | |||||
int n; | |||||
using (MemoryStream sb = new MemoryStream()) | |||||
{ | |||||
using (GZipStream input = new GZipStream(new MemoryStream(builtinGZ), | |||||
CompressionMode.Decompress, false)) | |||||
{ | |||||
while ((n = input.Read(buffer, 0, buffer.Length)) > 0) | |||||
{ | |||||
sb.Write(buffer, 0, n); | |||||
} | |||||
} | |||||
buildin = System.Text.Encoding.UTF8.GetString(sb.ToArray()) | |||||
.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); | |||||
} | |||||
return buildin; | |||||
} | |||||
public class TldIndex | |||||
{ | |||||
List<string> patterns = new List<string>(); | |||||
IDictionary<string, string> dic = new Dictionary<string, string>(); | |||||
public void Add(string tld) | |||||
{ | |||||
if (string.IsNullOrEmpty(tld)) | |||||
return; | |||||
if (tld.IndexOfAny(new char[] { '*', '?' }) >= 0) | |||||
{ | |||||
patterns.Add("^" + Regex.Escape(tld).Replace("\\*", ".*").Replace("\\?", ".") + "$"); | |||||
} | |||||
else if (!dic.ContainsKey(tld)) | |||||
{ | |||||
dic.Add(tld, tld); | |||||
} | |||||
} | |||||
public bool Contains(string tld) | |||||
{ | |||||
if (dic.ContainsKey(tld)) | |||||
return true; | |||||
foreach (string pattern in patterns) | |||||
{ | |||||
if (Regex.IsMatch(tld, pattern)) | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -70,16 +70,6 @@ namespace Shadowsocks.Properties { | |||||
} | } | ||||
} | } | ||||
/// <summary> | |||||
/// Looks up a localized resource of type System.Byte[]. | |||||
/// </summary> | |||||
internal static byte[] builtin_txt { | |||||
get { | |||||
object obj = ResourceManager.GetObject("builtin_txt", resourceCulture); | |||||
return ((byte[])(obj)); | |||||
} | |||||
} | |||||
/// <summary> | /// <summary> | ||||
/// Looks up a localized string similar to Shadowsocks=Shadowsocks | /// Looks up a localized string similar to Shadowsocks=Shadowsocks | ||||
///Enable=启用代理 | ///Enable=启用代理 | ||||
@@ -205,15 +195,5 @@ namespace Shadowsocks.Properties { | |||||
return ((System.Drawing.Bitmap)(obj)); | return ((System.Drawing.Bitmap)(obj)); | ||||
} | } | ||||
} | } | ||||
/// <summary> | |||||
/// Looks up a localized resource of type System.Byte[]. | |||||
/// </summary> | |||||
internal static byte[] tld_txt { | |||||
get { | |||||
object obj = ResourceManager.GetObject("tld_txt", resourceCulture); | |||||
return ((byte[])(obj)); | |||||
} | |||||
} | |||||
} | } | ||||
} | } |
@@ -121,9 +121,6 @@ | |||||
<data name="abp_js" type="System.Resources.ResXFileRef, System.Windows.Forms"> | <data name="abp_js" type="System.Resources.ResXFileRef, System.Windows.Forms"> | ||||
<value>..\Data\abp.js.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | <value>..\Data\abp.js.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||||
</data> | </data> | ||||
<data name="builtin_txt" type="System.Resources.ResXFileRef, System.Windows.Forms"> | |||||
<value>..\Data\builtin.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||||
</data> | |||||
<data name="cn" type="System.Resources.ResXFileRef, System.Windows.Forms"> | <data name="cn" type="System.Resources.ResXFileRef, System.Windows.Forms"> | ||||
<value>..\data\cn.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> | <value>..\data\cn.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> | ||||
</data> | </data> | ||||
@@ -151,7 +148,4 @@ | |||||
<data name="ssw128" type="System.Resources.ResXFileRef, System.Windows.Forms"> | <data name="ssw128" type="System.Resources.ResXFileRef, System.Windows.Forms"> | ||||
<value>..\Resources\ssw128.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> | <value>..\Resources\ssw128.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> | ||||
</data> | </data> | ||||
<data name="tld_txt" type="System.Resources.ResXFileRef, System.Windows.Forms"> | |||||
<value>..\Data\tld.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | |||||
</data> | |||||
</root> | </root> |
@@ -102,6 +102,11 @@ | |||||
<Compile Include="Controller\PACServer.cs" /> | <Compile Include="Controller\PACServer.cs" /> | ||||
<Compile Include="Model\Server.cs" /> | <Compile Include="Model\Server.cs" /> | ||||
<Compile Include="Model\Configuration.cs" /> | <Compile Include="Model\Configuration.cs" /> | ||||
<Compile Include="Properties\Resources.Designer.cs"> | |||||
<AutoGen>True</AutoGen> | |||||
<DesignTime>True</DesignTime> | |||||
<DependentUpon>Resources.resx</DependentUpon> | |||||
</Compile> | |||||
<Compile Include="Util\Util.cs" /> | <Compile Include="Util\Util.cs" /> | ||||
<Compile Include="View\ConfigForm.cs"> | <Compile Include="View\ConfigForm.cs"> | ||||
<SubType>Form</SubType> | <SubType>Form</SubType> | ||||
@@ -128,14 +133,9 @@ | |||||
</EmbeddedResource> | </EmbeddedResource> | ||||
<EmbeddedResource Include="Properties\Resources.resx"> | <EmbeddedResource Include="Properties\Resources.resx"> | ||||
<Generator>ResXFileCodeGenerator</Generator> | <Generator>ResXFileCodeGenerator</Generator> | ||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | |||||
<SubType>Designer</SubType> | <SubType>Designer</SubType> | ||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | |||||
</EmbeddedResource> | </EmbeddedResource> | ||||
<Compile Include="Properties\Resources.Designer.cs"> | |||||
<AutoGen>True</AutoGen> | |||||
<DependentUpon>Resources.resx</DependentUpon> | |||||
<DesignTime>True</DesignTime> | |||||
</Compile> | |||||
<EmbeddedResource Include="View\QRCodeForm.resx"> | <EmbeddedResource Include="View\QRCodeForm.resx"> | ||||
<DependentUpon>QRCodeForm.cs</DependentUpon> | <DependentUpon>QRCodeForm.cs</DependentUpon> | ||||
</EmbeddedResource> | </EmbeddedResource> | ||||
@@ -144,13 +144,11 @@ | |||||
<SubType>Designer</SubType> | <SubType>Designer</SubType> | ||||
</None> | </None> | ||||
<None Include="Data\abp.js.gz" /> | <None Include="Data\abp.js.gz" /> | ||||
<None Include="Data\builtin.txt.gz" /> | |||||
<None Include="Data\libsscrypto.dll.gz" /> | <None Include="Data\libsscrypto.dll.gz" /> | ||||
<None Include="Data\polipo.exe.gz" /> | <None Include="Data\polipo.exe.gz" /> | ||||
<None Include="Data\proxy.pac.txt.gz" /> | <None Include="Data\proxy.pac.txt.gz" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<None Include="Data\tld.txt.gz" /> | |||||
<None Include="Resources\ss20.png" /> | <None Include="Resources\ss20.png" /> | ||||
<None Include="Resources\ss16.png" /> | <None Include="Resources\ss16.png" /> | ||||
<None Include="Resources\ss24.png" /> | <None Include="Resources\ss24.png" /> | ||||