add polipo runner
This commit is contained in:
@@ -13,6 +13,7 @@ namespace shadowsocks_csharp
|
||||
Local local;
|
||||
PACServer pacServer;
|
||||
Config config;
|
||||
PolipoRunner polipoRunner;
|
||||
|
||||
public Form1()
|
||||
{
|
||||
@@ -55,9 +56,18 @@ namespace shadowsocks_csharp
|
||||
if (local != null)
|
||||
{
|
||||
local.Stop();
|
||||
if (polipoRunner != null)
|
||||
{
|
||||
polipoRunner.Stop();
|
||||
}
|
||||
}
|
||||
local = new Local(config);
|
||||
local.Start();
|
||||
if (polipoRunner == null)
|
||||
{
|
||||
polipoRunner = new PolipoRunner();
|
||||
}
|
||||
polipoRunner.Start(config);
|
||||
|
||||
}
|
||||
|
||||
@@ -108,6 +118,7 @@ namespace shadowsocks_csharp
|
||||
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
if (local != null) local.Stop();
|
||||
if (polipoRunner != null) polipoRunner.Stop();
|
||||
}
|
||||
|
||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
using shadowsocks_csharp.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace shadowsocks_csharp
|
||||
{
|
||||
class PolipoRunner
|
||||
{
|
||||
private Process process;
|
||||
private bool ByteArrayToFile(string fileName, byte[] content)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.IO.FileStream _FileStream =
|
||||
new System.IO.FileStream(fileName, System.IO.FileMode.Create,
|
||||
System.IO.FileAccess.Write);
|
||||
_FileStream.Write(content, 0, content.Length);
|
||||
_FileStream.Close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception _Exception)
|
||||
{
|
||||
Console.WriteLine("Exception caught in process: {0}",
|
||||
_Exception.ToString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void Start(Config config)
|
||||
{
|
||||
if (process == null)
|
||||
{
|
||||
string temppath = Path.GetTempPath();
|
||||
string polipoConfig = Resources.polipo_config;
|
||||
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", config.local_port.ToString());
|
||||
ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));
|
||||
ByteArrayToFile(temppath + "/polipo.exe", Resources.polipo);
|
||||
|
||||
process = new Process();
|
||||
// Configure the process using the StartInfo properties.
|
||||
process.StartInfo.FileName = temppath + "/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();
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (process != null)
|
||||
{
|
||||
process.Kill();
|
||||
process.WaitForExit();
|
||||
process = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace shadowsocks_csharp
|
||||
{
|
||||
class SystemProxy
|
||||
{
|
||||
|
||||
[DllImport("wininet.dll")]
|
||||
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;
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
|
||||
registry.SetValue("ProxyEnable", 1);
|
||||
registry.SetValue("ProxyServer", "127.0.0.1:8123");
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
|
||||
registry.SetValue("ProxyEnable", 0);
|
||||
registry.SetValue("ProxyServer", "");
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
# Uncomment this if you want to use a parent SOCKS proxy:
|
||||
|
||||
socksParentProxy = "127.0.0.1:1080"
|
||||
socksParentProxy = "127.0.0.1:__SOCKS_PORT__"
|
||||
socksProxyType = socks5
|
||||
|
||||
# Uncomment this if you want to scrub private information from the log:
|
||||
|
||||
@@ -96,6 +96,7 @@
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Local.cs" />
|
||||
<Compile Include="PolipoRunner.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
|
||||
Reference in New Issue
Block a user