ScopedDisableWow64FsRedirection::ScopedDisableWow64FsRedirection() { if (IsWow64()) _redirected = DisableWow64FsRedirection(&_ctx); }
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; }