白速器(原名火速器)应该是目前国内最好用的*吧。
像我这种经常要访问github的用户来说,简直不要太方便了。
原版PC版,有几个不太方便的地方:
- 试用只能1个月,一个月后需要重新注册新邮箱才能继续试用;
- VPN连接断开时,会清除掉代理的pac脚本设定及VPN本地地址过滤,对于已使用PAC脚本和过滤的用户来说不太友好;
这次的破解,主要针对上述两点来进行。
首先,我们破解试用功能,实现用户无感自主自动注册,达到无限制长久使用的目标。
用dnSpy(32bit)打开Whale.exe,发现代码没有混淆。
修改Shadowsocks.Model.Configuration类的public static Configuration Load(string config_str)方法,去掉uuid检测,每次都修改uuid并保存。
修改类Shadowsocks.View.MenuViewController的构造函数,去掉后面三行的升级检测。
修改类Shadowsocks.Controller.ShadowsocksController中的private void internalConnect(Node selectedNode, ProxyMode mode, int retry, string httpcheck)方法
在text = ((nodeDetailPack != null && nodeDetailPack.result != null) ? nodeDetailPack.result.msg : null);语句后面加上if (nodeDetailPack.result.code == 104) { this.Register(Utils.GenerateMd5FromString(Guid.NewGuid().ToString()).Substring(0, 8) + "@163.com", UserCenter.GetInstance().EncryptPwdSucc, ""); return; }
这段代码的意思是,如果没有注册或服务器返回免费套餐到期,就自动注册一个新邮箱帐号并用新帐号登录。
注意这里修改方法会编译不通过,将前面的SimpleJson.DeserializeObject改为SimpleJson.SimpleJson.DeserializeObject即可编译通过。
然后,我们修改代理设置功能,添加保留PAC脚本设置和本地地址过滤功能。
添加一个新类,加入以下代码:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace ZZZ
{
public class IEProxy
{
/// <summary>
/// 清除所有代理设置
/// </summary>
/// <returns></returns>
public static bool ClearAll()
{
return SetProxy(false,false,false,"", "", "");
}
/// <summary>
/// 设置IE代理
/// </summary>
/// <param name="enableProxy">是否启用代理服务器</param>
/// <param name="enablePac">是否启用PAC</param>
/// <param name="enableAutoDetect">是否启用自动检测</param>
/// <param name="proxyAddress">代理服务器地址,设置为null将跳过,设置为空白将清空。</param>
/// <param name="proxyExceptions">代理服务器排除地址列表,设置为null将跳过,设置为空白将清空。</param>
/// <param name="pacPath">PAC地址,设置为null将跳过,设置为空白将清空。</param>
/// <returns>成功返回True,否则返回False</returns>
/// <exception cref="Win32Exception"></exception>
public static bool SetProxy(bool enableProxy, bool enablePac, bool enableAutoDetect, string proxyAddress=null, string proxyExceptions = null, string pacPath = null)
{
InternetPerConnOptionList list = new InternetPerConnOptionList();
int optionCount = 1;
if(proxyAddress!=null) optionCount++;
if(proxyExceptions != null) optionCount++;
if(pacPath != null) optionCount++;
InternetConnectionOption[] options = new InternetConnectionOption[optionCount];
options[0].m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
var flags = PerConnFlags.PROXY_TYPE_DIRECT;
if (enableProxy) flags |= PerConnFlags.PROXY_TYPE_PROXY;
if (enablePac) flags |= PerConnFlags.PROXY_TYPE_AUTO_PROXY_URL;
if (enableAutoDetect) flags |= PerConnFlags.PROXY_TYPE_AUTO_DETECT;
options[0].m_Value.m_Int = (int)flags;
if (proxyAddress != null)
{
options[1].m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_SERVER;
options[1].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(proxyAddress);
}
if (proxyExceptions != null)
{
options[2].m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_BYPASS;
options[2].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(proxyExceptions);
}
if (pacPath != null)
{
options[3].m_Option = PerConnOption.INTERNET_PER_CONN_AUTOCONFIG_URL;
options[3].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(pacPath);
}
// default stuff
list.dwSize = Marshal.SizeOf(list);
list.szConnection = IntPtr.Zero;
list.dwOptionCount = options.Length;
list.dwOptionError = 0;
int optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
// make a pointer out of all that ...
IntPtr optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length);
// copy the array over into that spot in memory ...
for (int i = 0; i < options.Length; ++i)
{
IntPtr opt = new IntPtr(optionsPtr.ToInt32() + (i * optSize));
Marshal.StructureToPtr(options[i], opt, false);
}
list.options = optionsPtr;
// and then make a pointer out of the whole list
IntPtr ipcoListPtr = Marshal.AllocCoTaskMem((Int32)list.dwSize);
Marshal.StructureToPtr(list, ipcoListPtr, false);
// and finally, call the API method!
int returnvalue = NativeMethods.InternetSetOption(IntPtr.Zero,
InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION,
ipcoListPtr, list.dwSize) ? -1 : 0;
if (returnvalue == 0)
{ // get the error codes, they might be helpful
returnvalue = Marshal.GetLastWin32Error();
}
// FREE the data ASAP
Marshal.FreeCoTaskMem(optionsPtr);
Marshal.FreeCoTaskMem(ipcoListPtr);
if (returnvalue > 0)
{ // throw the error codes, they might be helpful
throw new Win32Exception(Marshal.GetLastWin32Error());
}
return (returnvalue < 0);
}
}
#region WinInet structures
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct InternetPerConnOptionList
{
public int dwSize; // size of the INTERNET_PER_CONN_OPTION_LIST struct
public IntPtr szConnection; // connection name to set/query options
public int dwOptionCount; // number of options to set/query
public int dwOptionError; // on error, which option failed
//[MarshalAs(UnmanagedType.)]
public IntPtr options;
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct InternetConnectionOption
{
static readonly int Size;
public PerConnOption m_Option;
public InternetConnectionOptionValue m_Value;
static InternetConnectionOption()
{
InternetConnectionOption.Size = Marshal.SizeOf(typeof(InternetConnectionOption));
}
// Nested Types
[StructLayout(LayoutKind.Explicit)]
public struct InternetConnectionOptionValue
{
// Fields
[FieldOffset(0)]
public System.Runtime.InteropServices.ComTypes.FILETIME m_FileTime;
[FieldOffset(0)]
public int m_Int;
[FieldOffset(0)]
public IntPtr m_StringPtr;
}
}
#endregion
#region WinInet enums
//
// options manifests for Internet{Query|Set}Option
//
public enum InternetOption : uint
{
INTERNET_OPTION_PER_CONNECTION_OPTION = 75
}
//
// Options used in INTERNET_PER_CONN_OPTON struct
//
public enum PerConnOption
{
INTERNET_PER_CONN_FLAGS = 1, // Sets or retrieves the connection type. The Value member will contain one or more of the values from PerConnFlags
INTERNET_PER_CONN_PROXY_SERVER = 2, // Sets or retrieves a string containing the proxy servers.
INTERNET_PER_CONN_PROXY_BYPASS = 3, // Sets or retrieves a string containing the URLs that do not use the proxy server.
INTERNET_PER_CONN_AUTOCONFIG_URL = 4//, // Sets or retrieves a string containing the URL to the automatic configuration script.
}
//
// PER_CONN_FLAGS
//
[Flags]
public enum PerConnFlags
{
PROXY_TYPE_DIRECT = 0x00000001, // direct to net
PROXY_TYPE_PROXY = 0x00000002, // via named proxy
PROXY_TYPE_AUTO_PROXY_URL = 0x00000004, // autoproxy URL
PROXY_TYPE_AUTO_DETECT = 0x00000008 // use autoproxy detection
}
#endregion
internal static class NativeMethods
{
[DllImport("WinInet.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InternetSetOption(IntPtr hInternet, InternetOption dwOption, IntPtr lpBuffer, int dwBufferLength);
}
}
修改Shadowsocks.Controller.SystemProxy类的public static void Update(Configuration config, bool forceDisable)方法
将环境OS版本>6.2的代理修改代码修改为以下:
if (flag2)
{
ZZZ.IEProxy.SetProxy(true, true, true, "127.0.0.1:" + config.localPort.ToString(), null, null);
}
else
{
ZZZ.IEProxy.SetProxy(false, false, false, null, null, null);
}
修改Shadowsocks.Controller.ShadowsocksController类的public void Stop()方法,去掉代理更新的条件。
保存模块即可!! 至此。上述两个目标都已修改完成。实际体验将超乎想象的好。