// Get whether the current OS is supported by SeLow bool SuIsSupportedOs(bool on_install) { if (MsRegReadIntEx2(REG_LOCAL_MACHINE, SL_REG_KEY_NAME, "EnableSeLow", false, true) != 0) { // Force enable return true; } if (MsRegReadIntEx2(REG_LOCAL_MACHINE, SL_REG_KEY_NAME, "DisableSeLow", false, true) != 0) { // Force disable return false; } if (MsIsWindows10()) { // Windows 10 or later are always supported. return true; } if (on_install) { // If Microsoft Routing and Remote Access service is running, // then return false. if (MsIsServiceRunning("RemoteAccess")) { return false; } } // If the Su driver is currently running, // then return true. if (MsIsServiceRunning(SL_PROTOCOL_NAME)) { return true; } // Currently Windows 8.1 or later are supported if (MsIsWindows81() == false) { return false; } if (on_install == false) { // If Microsoft Routing and Remote Access service is running, // then return false. if (MsIsServiceRunning("RemoteAccess")) { return false; } } return true; }
// Start the installation process void ViInstallProcessStart(HWND hWnd, VI_INSTALL_DLG *d) { wchar_t *exew; bool ok; char instdir[MAX_PATH]; char hamcore[MAX_PATH]; // Validate arguments if (hWnd == NULL || d == NULL) { return; } ViGenerateVpnSMgrTempDirName(instdir, sizeof(instdir), ViGetSuitableArchForCpu()->Build); ConbinePath(hamcore, sizeof(hamcore), instdir, "hamcore.se2"); exew = setting.DownloadedInstallerPathW; d->NoClose = true; Hide(hWnd, IDCANCEL); SetPos(hWnd, P_PROGRESS, 100); Hide(hWnd, P_PROGRESS); Hide(hWnd, S_SIZEINFO); SetText(hWnd, S_STATUS, _U(IDS_INSTALLSTART+skip)); ok = true; if (setting.DownloadNotRequired == false) { if (setting.WebMode && ViCheckExeSign(hWnd, exew) == false) { // The digital signature is not reliable ok = false; } else { // Installation HANDLE hProcess; SHELLEXECUTEINFOW info; // Run Zero(&info, sizeof(info)); info.cbSize = sizeof(info); info.lpVerb = L"open"; info.lpFile = exew; info.fMask = SEE_MASK_NOCLOSEPROCESS; info.lpParameters = L"/HIDESTARTCOMMAND:1 /DISABLEAUTOIMPORT:1 /ISWEBINSTALLER:1"; info.nShow = SW_SHOWNORMAL; if (ShellExecuteExW(&info) == false) { MsgBox(hWnd, MB_ICONSTOP, _U(IDS_INSTALLSTART_ERROR+skip)); ok = false; } else { hProcess = info.hProcess; // Wait for the install process to complete while (true) { if (WaitForSingleObject(hProcess, 50) != WAIT_TIMEOUT) { break; } DoEvents(hWnd); } CloseHandle(hProcess); } } } if (ok && d->WindowsShutdowning == false) { VI_SETTING_ARCH *a = ViGetSuitableArchForCpu(); wchar_t arg[MAX_PATH]; wchar_t exe[MAX_PATH]; char *arg1 = "/easy"; // Hide the screen Hide(hWnd, 0); if (setting.NormalMode) { arg1 = "/normal"; } // (Just in case) start the VPN Client service if (MsIsServiceRunning("vpnclient") == false) { MsStartService("vpnclient"); } // Wait for that the service becomes available SwWaitForVpnClientPortReady(0); if (UniIsEmptyStr(setting.DownloadedSettingPathW) == false) { // Start a connection by importing the configuration file into the VPN Client UniFormat(arg, sizeof(arg), L"%S \"%s\"", arg1, setting.DownloadedSettingPathW); } else { // Just start the Connection Manager UniFormat(arg, sizeof(arg), L"%S", arg1); } // Get the installation state ViLoadCurrentInstalledStatusForArch(a); if (a->CurrentInstalled) { HANDLE h; wchar_t filename[MAX_PATH]; StrToUni(filename, sizeof(filename), a->VpnCMgrExeFileName); ConbinePathW(exe, sizeof(exe), a->CurrentInstalledPathW, filename); // Start the Connection Manager h = MsRunAsUserExW(exe, arg, false); if (h != NULL) { if (UniIsEmptyStr(setting.DownloadedSettingPathW) == false) { sleep_before_exit = true; } CloseHandle(h); } } } d->NoClose = false; Close(hWnd); }
bool SuInstallDriverInner(bool force) { wchar_t sys_fullpath[MAX_PATH]; UINT current_sl_ver = 0; bool ret = false; wchar_t src_cat[MAX_PATH]; wchar_t src_inf[MAX_PATH]; wchar_t src_sys[MAX_PATH]; wchar_t dst_cat[MAX_PATH]; wchar_t dst_inf[MAX_PATH]; wchar_t dst_sys[MAX_PATH]; wchar_t tmp_dir[MAX_PATH]; char *cpu_type = MsIsX64() ? "x64" : "x86"; if (SuIsSupportedOs(true) == false) { // Unsupported OS return false; } CombinePathW(tmp_dir, sizeof(tmp_dir), MsGetWindowsDirW(), L"Temp"); MakeDirExW(tmp_dir); UniStrCat(tmp_dir, sizeof(tmp_dir), L"\\selowtmp"); MakeDirExW(tmp_dir); // Confirm whether the driver is currently installed CombinePathW(sys_fullpath, sizeof(sys_fullpath), MsGetSystem32DirW(), L"drivers\\SeLow_%S.sys"); UniFormat(sys_fullpath, sizeof(sys_fullpath), sys_fullpath, cpu_type); if (IsFileExistsW(sys_fullpath)) { char *path; // Read the current version from the registry current_sl_ver = MsRegReadIntEx2(REG_LOCAL_MACHINE, SL_REG_KEY_NAME, (MsIsWindows10() ? SL_REG_VER_VALUE_WIN10 : SL_REG_VER_VALUE), false, true); path = MsRegReadStrEx2(REG_LOCAL_MACHINE, SL_REG_KEY_NAME, "ImagePath", false, true); if (IsEmptyStr(path) || IsFileExists(path) == false || MsIsServiceInstalled(SL_PROTOCOL_NAME) == false) { current_sl_ver = 0; } Free(path); } if (force == false && current_sl_ver >= SL_VER) { // Newer version has already been installed Debug("Newer SeLow is Installed. %u >= %u\n", current_sl_ver, SL_VER); return true; } // Copy necessary files to a temporary directory UniFormat(src_sys, sizeof(src_sys), L"|DriverPackages\\%S\\%S\\SeLow_%S.sys", (MsIsWindows10() ? "SeLow_Win10" : "SeLow_Win8"), cpu_type, cpu_type); if (MsIsWindows8() == false) { // Windows Vista and Windows 7 uses SHA-1 catalog files UniFormat(src_cat, sizeof(src_cat), L"|DriverPackages\\SeLow_Win8\\%S\\inf.cat", cpu_type); } else { // Windows 8 or above uses SHA-256 catalog files UniFormat(src_cat, sizeof(src_cat), L"|DriverPackages\\SeLow_Win8\\%S\\inf2.cat", cpu_type); if (MsIsWindows10()) { // Windows 10 uses WHQL catalog files UniFormat(src_cat, sizeof(src_cat), L"|DriverPackages\\SeLow_Win10\\%S\\SeLow_Win10_%S.cat", cpu_type, cpu_type); } } UniFormat(src_inf, sizeof(src_inf), L"|DriverPackages\\%S\\%S\\SeLow_%S.inf", (MsIsWindows10() ? "SeLow_Win10" : "SeLow_Win8"), cpu_type, cpu_type); UniFormat(dst_sys, sizeof(dst_cat), L"%s\\SeLow_%S.sys", tmp_dir, cpu_type); UniFormat(dst_cat, sizeof(dst_cat), L"%s\\SeLow_%S_%S.cat", tmp_dir, (MsIsWindows10() ? "Win10" : "Win8"), cpu_type); UniFormat(dst_inf, sizeof(dst_inf), L"%s\\SeLow_%S.inf", tmp_dir, cpu_type); if (FileCopyW(src_sys, dst_sys) && FileCopyW(src_cat, dst_cat) && FileCopyW(src_inf, dst_inf)) { NO_WARNING *nw; nw = MsInitNoWarningEx(SL_USER_AUTO_PUSH_TIMER); if (MsIsWindows10()) { if (MsIsServiceInstalled(SL_PROTOCOL_NAME) == false && MsIsServiceRunning(SL_PROTOCOL_NAME) == false) { // On Windows 10, if there are no SwLow service installed, then uinstall the protocol driver first. // TODO: currently do nothing. On some versions of Windows 10 beta builds it is necessary to do something... } } if (MsIsWindows10()) { // Delete garbage INFs SuDeleteGarbageInfs(); } // Call the installer if (InstallNdisProtocolDriver(dst_inf, L"SeLow", SL_USER_INSTALL_LOCK_TIMEOUT) == false) { Debug("InstallNdisProtocolDriver Error.\n"); } else { Debug("InstallNdisProtocolDriver Ok.\n"); // Copy manually because there are cases where .sys file is not copied successfully for some reason FileCopyW(src_sys, sys_fullpath); ret = true; // Write the version number into the registry MsRegWriteIntEx2(REG_LOCAL_MACHINE, SL_REG_KEY_NAME, (MsIsWindows10() ? SL_REG_VER_VALUE_WIN10 : SL_REG_VER_VALUE), SL_VER, false, true); // Set to automatic startup MsRegWriteIntEx2(REG_LOCAL_MACHINE, SL_REG_KEY_NAME, "Start", SERVICE_SYSTEM_START, false, true); } MsFreeNoWarning(nw); } else { Debug("Fail Copying Files.\n"); } if (ret) { // If the service is installed this time, start and wait until the enumeration is completed SuFree(SuInitEx(180 * 1000)); } return ret; }
bool IPsecWin7InitDriverInner() { char sys_filename[MAX_PATH]; bool install_driver = true; HANDLE hEngine; UINT ret; FWPM_SESSION0 session; UINT id; FWPM_CALLOUT0 callout; Format(sys_filename, sizeof(sys_filename), IPSEC_WIN7_DST_SYS, MsGetSystem32Dir()); if (IsFileExists(sys_filename) && MsIsServiceInstalled(IPSEC_WIN7_DRIVER_NAME)) { if (GetCurrentIPsecWin7DriverBuild() >= CEDAR_BUILD) { // Not to install since the latest version has been already installed install_driver = false; } } if (install_driver) { char src_filename[MAX_PATH]; if (MsIsWindows10() == false) { Format(src_filename, sizeof(src_filename), "|DriverPackages\\Wfp\\%s\\pxwfp_%s.sys", (MsIsX64() ? "x64" : "x86"), (MsIsX64() ? "x64" : "x86")); } else { Format(src_filename, sizeof(src_filename), "|DriverPackages\\Wfp_Win10\\%s\\pxwfp_%s.sys", (MsIsX64() ? "x64" : "x86"), (MsIsX64() ? "x64" : "x86")); } // Copy the driver if (FileCopy(src_filename, sys_filename) == false) { Debug("%s copy failed. %u\n", sys_filename, GetLastError()); if (IsFileExists(sys_filename) == false) { Debug("%s failed. Abort.\n", sys_filename); return false; } } else { Debug("%s copied.\n", sys_filename); } // Set the build number SetCurrentIPsecWin7DriverBuild(); } // Get whether the device drivers is already installed if (MsIsServiceInstalled(IPSEC_WIN7_DRIVER_NAME) == false) { wchar_t sys_filename_w[MAX_PATH]; StrToUni(sys_filename_w, sizeof(sys_filename_w), sys_filename); // Run a new installation if (MsInstallDeviceDriverW(IPSEC_WIN7_DRIVER_NAME, IPSEC_WIN7_DRIVER_TITLE, sys_filename_w, NULL) == false) { // Installation failed Debug("MsInstallDeviceDriverW failed.\n"); return false; } } // Start if the device driver is stopped if (MsIsServiceRunning(IPSEC_WIN7_DRIVER_NAME) == false) { if (MsStartService(IPSEC_WIN7_DRIVER_NAME) == false) { // Start failure Debug("MsStartService failed.\n"); return false; } Debug("%s service started.\n", IPSEC_WIN7_DRIVER_NAME); } else { Debug("%s service was already started.\n", IPSEC_WIN7_DRIVER_NAME); } // Open the WFP Zero(&session, sizeof(session)); ret = api->FwpmEngineOpen0(NULL, RPC_C_AUTHN_DEFAULT, NULL, &session, &hEngine); if (ret) { Debug("FwpmEngineOpen0 failed.\n"); return false; } // Create the Callout Driver (IPv4) Zero(&callout, sizeof(callout)); callout.calloutKey = GUID_WFP_CALLOUT_DRIVER_V4; callout.applicableLayer = FWPM_LAYER_INBOUND_IPPACKET_V4; callout.displayData.name = IPSEC_WIN7_DRIVER_TITLE_V4; ret = api->FwpmCalloutAdd0(hEngine, &callout, NULL, &id); if (ret) { Debug("FwpmCalloutAdd0 for IPv4 Failed: 0x%X\n", ret); } else { Debug("FwpmCalloutAdd0 for IPv4 Ok.\n"); } // Create the Callout Driver (IPv6) Zero(&callout, sizeof(callout)); callout.calloutKey = GUID_WFP_CALLOUT_DRIVER_V6; callout.applicableLayer = FWPM_LAYER_INBOUND_IPPACKET_V6; callout.displayData.name = IPSEC_WIN7_DRIVER_TITLE_V6; ret = api->FwpmCalloutAdd0(hEngine, &callout, NULL, &id); if (ret) { Debug("FwpmCalloutAdd0 for IPv6 Failed: 0x%X\n", ret); } else { Debug("FwpmCalloutAdd0 for IPv6 Ok.\n"); } api->FwpmEngineClose0(hEngine); return true; }