|
@@ -14,11 +14,139 @@
|
|
|
#include <memory>
|
|
|
#include <sstream>
|
|
|
|
|
|
+
|
|
|
+#include <Windows.h>
|
|
|
+#include <Wininet.h>
|
|
|
+#include <Ras.h>
|
|
|
+#include <string>
|
|
|
+#include <vector>
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+#pragma comment(lib, "wininet.lib")
|
|
|
+#pragma comment(lib, "rasapi32.lib")
|
|
|
typedef LONG NTSTATUS, * PNTSTATUS;
|
|
|
#define STATUS_SUCCESS (0x00000000)
|
|
|
|
|
|
typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
|
|
|
|
|
|
+
|
|
|
+void startProxy(const int port)
|
|
|
+{
|
|
|
+ INTERNET_PER_CONN_OPTION_LIST list;
|
|
|
+ DWORD dwBufSize = sizeof(list);
|
|
|
+ list.dwSize = sizeof(list);
|
|
|
+ list.pszConnection = nullptr;
|
|
|
+ auto url = "127.0.0.1:" + std::to_string(port);
|
|
|
+ auto wUrl = std::wstring(url.begin(), url.end());
|
|
|
+ auto fullAddr = new WCHAR[url.length() + 1];
|
|
|
+ wcscpy_s(fullAddr, url.length() + 1, wUrl.c_str());
|
|
|
+ list.dwOptionCount = 2;
|
|
|
+ list.pOptions = new INTERNET_PER_CONN_OPTION[2];
|
|
|
+
|
|
|
+ if (!list.pOptions)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
|
|
|
+ list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT | PROXY_TYPE_PROXY;
|
|
|
+
|
|
|
+ list.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
|
|
|
+ list.pOptions[1].Value.pszValue = fullAddr;
|
|
|
+
|
|
|
+ InternetSetOption(nullptr, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
|
|
|
+
|
|
|
+ RASENTRYNAME entry;
|
|
|
+ entry.dwSize = sizeof(entry);
|
|
|
+ std::vector<RASENTRYNAME> entries;
|
|
|
+ DWORD size = sizeof(entry), count;
|
|
|
+ LPRASENTRYNAME entryAddr = &entry;
|
|
|
+ auto ret = RasEnumEntries(nullptr, nullptr, entryAddr, &size, &count);
|
|
|
+ if (ret == ERROR_BUFFER_TOO_SMALL)
|
|
|
+ {
|
|
|
+ entries.resize(count);
|
|
|
+ entries[0].dwSize = sizeof(RASENTRYNAME);
|
|
|
+ entryAddr = entries.data();
|
|
|
+ ret = RasEnumEntries(nullptr, nullptr, entryAddr, &size, &count);
|
|
|
+ }
|
|
|
+ if (ret != ERROR_SUCCESS)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (DWORD i = 0; i < count; i++)
|
|
|
+ {
|
|
|
+ list.pszConnection = entryAddr[i].szEntryName;
|
|
|
+ InternetSetOption(nullptr, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
|
|
|
+ }
|
|
|
+ delete[] list.pOptions;
|
|
|
+ InternetSetOption(nullptr, INTERNET_OPTION_SETTINGS_CHANGED, nullptr, 0);
|
|
|
+ InternetSetOption(nullptr, INTERNET_OPTION_REFRESH, nullptr, 0);
|
|
|
+}
|
|
|
+
|
|
|
+void stopProxy()
|
|
|
+{
|
|
|
+ INTERNET_PER_CONN_OPTION_LIST list;
|
|
|
+ DWORD dwBufSize = sizeof(list);
|
|
|
+
|
|
|
+ list.dwSize = sizeof(list);
|
|
|
+ list.pszConnection = nullptr;
|
|
|
+ list.dwOptionCount = 1;
|
|
|
+ list.pOptions = new INTERNET_PER_CONN_OPTION[1];
|
|
|
+ if (nullptr == list.pOptions)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
|
|
|
+ list.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
|
|
|
+
|
|
|
+ InternetSetOption(nullptr, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
|
|
|
+
|
|
|
+ RASENTRYNAME entry;
|
|
|
+ entry.dwSize = sizeof(entry);
|
|
|
+ std::vector<RASENTRYNAME> entries;
|
|
|
+ DWORD size = sizeof(entry), count;
|
|
|
+ LPRASENTRYNAME entryAddr = &entry;
|
|
|
+ auto ret = RasEnumEntries(nullptr, nullptr, entryAddr, &size, &count);
|
|
|
+ if (ret == ERROR_BUFFER_TOO_SMALL)
|
|
|
+ {
|
|
|
+ entries.resize(count);
|
|
|
+ entries[0].dwSize = sizeof(RASENTRYNAME);
|
|
|
+ entryAddr = entries.data();
|
|
|
+ ret = RasEnumEntries(nullptr, nullptr, entryAddr, &size, &count);
|
|
|
+ }
|
|
|
+ if (ret != ERROR_SUCCESS)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (DWORD i = 0; i < count; i++)
|
|
|
+ {
|
|
|
+ list.pszConnection = entryAddr[i].szEntryName;
|
|
|
+ InternetSetOption(nullptr, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, dwBufSize);
|
|
|
+ }
|
|
|
+ delete[] list.pOptions;
|
|
|
+ InternetSetOption(nullptr, INTERNET_OPTION_SETTINGS_CHANGED, nullptr, 0);
|
|
|
+ InternetSetOption(nullptr, INTERNET_OPTION_REFRESH, nullptr, 0);
|
|
|
+}
|
|
|
+
|
|
|
+// 检测代理是否启用的函数
|
|
|
+bool isProxyEnabled() {
|
|
|
+ INTERNET_PER_CONN_OPTION_LIST list;
|
|
|
+ DWORD dwBufSize = sizeof(list);
|
|
|
+ list.dwSize = sizeof(list);
|
|
|
+ list.pszConnection = nullptr;
|
|
|
+ list.dwOptionCount = 1;
|
|
|
+ list.pOptions = new INTERNET_PER_CONN_OPTION[1];
|
|
|
+ list.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
|
|
|
+
|
|
|
+ bool proxyEnabled = false;
|
|
|
+ if (InternetQueryOption(nullptr, INTERNET_OPTION_PER_CONNECTION_OPTION, &list, &dwBufSize)) {
|
|
|
+ proxyEnabled = (list.pOptions[0].Value.dwValue & PROXY_TYPE_PROXY) != 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ delete[] list.pOptions;
|
|
|
+ return proxyEnabled;
|
|
|
+}
|
|
|
+
|
|
|
RTL_OSVERSIONINFOW GetRealOSVersion() {
|
|
|
HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
|
|
|
if (hMod) {
|
|
@@ -174,7 +302,20 @@ void WlBaseHelpPlugin::HandleMethodCall(
|
|
|
version_stream << "7";
|
|
|
}
|
|
|
result->Success(flutter::EncodableValue(version_stream.str()));
|
|
|
- } else {
|
|
|
+ } else if (method_call.method_name().compare("startProxy") == 0) {
|
|
|
+ const auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
|
|
|
+ int port = std::get<int>(arguments->at(flutter::EncodableValue("port")));
|
|
|
+ startProxy(port);
|
|
|
+ result->Success();
|
|
|
+ } else if (method_call.method_name().compare("stopProxy") == 0) {
|
|
|
+ stopProxy();
|
|
|
+ result->Success();
|
|
|
+ } else if (method_call.method_name().compare("isProxyEnabled") == 0) {
|
|
|
+ bool enabled = isProxyEnabled();
|
|
|
+ result->Success(flutter::EncodableValue(enabled));
|
|
|
+ } else {
|
|
|
+ result->NotImplemented();
|
|
|
+ } else {
|
|
|
result->NotImplemented();
|
|
|
}
|
|
|
}
|