예제 #1
0
SU *SuInitEx(UINT wait_for_bind_complete_tick)
{
    void *h;
    SU *u;
    UINT read_size;
    bool flag = false;
    UINT64 giveup_tick = 0;
    static bool flag2 = false; // flag2 must be global

    if (SuIsSupportedOs(false) == false)
    {
        // Unsupported OS
        return NULL;
    }

LABEL_RETRY:

    // Open the device driver
    h = CreateFileA(SL_BASIC_DEVICE_FILENAME_WIN32, GENERIC_READ | GENERIC_WRITE,
                    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);

    if (h == INVALID_HANDLE_VALUE)
    {
        Debug("CreateFileA(%s) Failed.\n", SL_BASIC_DEVICE_FILENAME_WIN32);

        // Start the service if it fails to start the device driver
        if (flag == false)
        {
            if (MsStartService(SL_PROTOCOL_NAME) == false)
            {
                Debug("MsStartService(%s) Failed.\n", SL_PROTOCOL_NAME);

                if (MsIsWindows10())
                {
                    if (flag2 == false)
                    {
                        flag2 = true;

                        if (SuInstallDriver(true))
                        {
                            goto LABEL_RETRY;
                        }
                    }
                }
            }
            else
            {
                Debug("MsStartService(%s) Ok.\n", SL_PROTOCOL_NAME);
                flag = true;

                goto LABEL_RETRY;
            }
        }
        return NULL;
    }

    //Debug("CreateFileA(%s) Ok.\n", SL_BASIC_DEVICE_FILENAME_WIN32);

    u = ZeroMalloc(sizeof(SU));

    giveup_tick = Tick64() + (UINT64)wait_for_bind_complete_tick;

    if (wait_for_bind_complete_tick == 0)
    {
        if (ReadFile(h, &u->AdapterInfoList, sizeof(u->AdapterInfoList), &read_size, NULL) == false ||
                u->AdapterInfoList.Signature != SL_SIGNATURE)
        {
            // Signature reception failure
            Debug("Bad Signature.\n");

            Free(u);
            CloseHandle(h);

            return NULL;
        }
    }
    else
    {
        while (giveup_tick >= Tick64())
        {
            // Wait until the enumeration is completed
            if (ReadFile(h, &u->AdapterInfoList, sizeof(u->AdapterInfoList), &read_size, NULL) == false ||
                    u->AdapterInfoList.Signature != SL_SIGNATURE)
            {
                // Signature reception failure
                Debug("Bad Signature.\n");

                Free(u);
                CloseHandle(h);

                return NULL;
            }

            if (u->AdapterInfoList.EnumCompleted)
            {
                // Complete enumeration
                Debug("Bind Completed! %u\n", u->AdapterInfoList.EnumCompleted);
                break;
            }

            // Incomplete enumeration
            Debug("Waiting for Bind Complete.\n");

            SleepThread(25);
        }
    }

    u->hFile = h;

    return u;
}
예제 #2
0
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;
}
예제 #3
0
// 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);
}
예제 #4
0
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, char *CmdLine, int CmdShow)
{
	bool uninstall_mode = false;
	char exe_name[MAX_PATH];
	char exe_dir[MAX_PATH];
	UINT os_ver = GetWindowsVersion();

	CoInitialize(NULL);

	DisableWow64FsRedirection();

	if (SeStartWith(CmdLine, "/uninstall"))
	{
		uninstall_mode = true;
	}

	GetModuleFileNameA(hInst, exe_name, sizeof(exe_name));
	SeGetDirNameFromFilePath(exe_dir, sizeof(exe_dir), exe_name);

	if (uninstall_mode == false)
	{
		char driver_inf_filename[MAX_PATH] = {0};
		bool install_driver = false;

		// Check the Windows version
		if (os_ver == OS_UNKNOWN)
		{
			MessageBoxA(NULL, "This operating system is not supported by Win10Pcap.\r\n\r\n"
				"Win10Pcap requires Windows 7, Server 2008 R2, Windows 8, Windows 8.1, Windows Server 2012, Windows Server 2012 R2 or Windows 10.",
				INSTALLER_TITLE,
				MB_ICONSTOP | MB_SYSTEMMODAL);
			return -1;
		}

		SeStrCpy(driver_inf_filename, sizeof(driver_inf_filename), exe_dir);
		if (os_ver == OS_WIN10)
		{
			SeStrCat(driver_inf_filename, sizeof(driver_inf_filename), "\\drivers\\win10");
		}
		else
		{
			SeStrCat(driver_inf_filename, sizeof(driver_inf_filename), "\\drivers\\win78");
		}
		SeStrCat(driver_inf_filename, sizeof(driver_inf_filename), "\\Win10Pcap.inf");

		// Install the device driver
		if (Is64BitCode())
		{
			// x64
			install_driver = true;
		}
		else if (IsWow64() == false)
		{
			// x86
			install_driver = true;
		}
		else
		{
			// Do nothing.
		}

		if (install_driver)
		{
LABEL_RETRY_INSTALL_DRIVER:

			if (InstallNdisProtocolDriver(driver_inf_filename, L"Win10Pcap", 60 * 1000) == false)
			{
				if (MessageBoxA(NULL, "The install process of the Win10Pcap NDIS device driver failed.", 
					INSTALLER_TITLE,
					MB_ICONEXCLAMATION | MB_SYSTEMMODAL | MB_RETRYCANCEL) == IDRETRY)
				{
					goto LABEL_RETRY_INSTALL_DRIVER;
				}
				else
				{
					return -1;
				}
			}

			MsStartService("Win10Pcap");
		}

		if (InstallDllToSystem32(exe_dir, "Packet.dll", "Packet.dll") == false ||
			InstallDllToSystem32(exe_dir, "wpcap.dll", "wpcap.dll") == false)
		{
			return -1;
		}

		if (Is64BitCode() == false && Is64BitWindows())
		{
			// Run x64
			char x64_exe[MAX_PATH];

			wsprintfA(x64_exe, "%s\\..\\x64\\Installer.exe", exe_dir);

			Win32RunAndWaitProcess(x64_exe, CmdLine, false, false, INFINITE);
		}
	}
	else
	{
		bool uninstall_driver = false;

		UninstallDllFromSystem32("Packet.dll");
		UninstallDllFromSystem32("wpcap.dll");

		// Install the device driver
		if (Is64BitCode())
		{
			// x64
			uninstall_driver = true;
		}
		else if (IsWow64() == false)
		{
			// x86
			uninstall_driver = true;
		}
		else
		{
			// Do nothing.
		}

		if (uninstall_driver)
		{
LABEL_RETRY_UNINSTALL_DRIVER:
			if (UninstallNdisProtocolDriver(L"Win10Pcap", 60 * 1000) == false)
			{
				if (MessageBoxA(NULL, "The uninstall process of the Win10Pcap NDIS device driver failed.", 
					INSTALLER_TITLE,
					MB_ICONEXCLAMATION | MB_SYSTEMMODAL | MB_RETRYCANCEL) == IDRETRY)
				{
					goto LABEL_RETRY_UNINSTALL_DRIVER;
				}
			}
		}

		if (Is64BitCode() == false && Is64BitWindows())
		{
			// Run x64
			char x64_exe[MAX_PATH];

			wsprintfA(x64_exe, "%s\\..\\x64\\Installer.exe", exe_dir);

			Win32RunAndWaitProcess(x64_exe, CmdLine, false, false, INFINITE);
		}
	}

	CoUninitialize();

	return 0;
}