bool InstallDllToSystem32(char *src_dirname, char *src_filename, char *dst_filename) { char system32[MAX_PATH]; char src_fullpath[MAX_PATH]; char dst_fullpath[MAX_PATH]; SeStrCpy(src_fullpath, sizeof(src_fullpath), src_dirname); SeStrCat(src_fullpath, sizeof(src_fullpath), "\\"); SeStrCat(src_fullpath, sizeof(src_fullpath), src_filename); if (Is64BitCode() || IsWow64() == false) { GetSystemDirectoryA(system32, sizeof(system32)); } else { GetSystemWow64DirectoryA(system32, sizeof(system32)); } SeStrCpy(dst_fullpath, sizeof(dst_fullpath), system32); SeStrCat(dst_fullpath, sizeof(dst_fullpath), "\\"); SeStrCat(dst_fullpath, sizeof(dst_fullpath), dst_filename); if (IsWin10PcapFile(dst_fullpath) == false) { char dst_backup[MAX_PATH]; SeStrCpy(dst_backup, sizeof(dst_backup), dst_fullpath); SeStrCat(dst_backup, sizeof(dst_backup), ".bak"); CopyFileA(dst_fullpath, dst_backup, false); } LABEL_RETRY: if (CopyFileA(src_fullpath, dst_fullpath, false) == false) { char tmp[MAX_SIZE]; wsprintfA(tmp, "The installation of the DLL file to the path \"%s\" failed.\r\n\r\n" "Make sure that there are no running programs using WinPcap DLL.", dst_fullpath); if (MessageBoxA(NULL, tmp, INSTALLER_TITLE, MB_ICONEXCLAMATION | MB_SYSTEMMODAL | MB_RETRYCANCEL) == IDRETRY) { goto LABEL_RETRY; } return false; } return true; }
bool UninstallDllFromSystem32(char *dst_filename) { char system32[MAX_PATH]; char dst_fullpath[MAX_PATH]; char bak_fullpath[MAX_PATH]; bool ret; if (Is64BitCode() || IsWow64() == false) { GetSystemDirectoryA(system32, sizeof(system32)); } else { GetSystemWow64DirectoryA(system32, sizeof(system32)); } SeStrCpy(dst_fullpath, sizeof(dst_fullpath), system32); SeStrCat(dst_fullpath, sizeof(dst_fullpath), "\\"); SeStrCat(dst_fullpath, sizeof(dst_fullpath), dst_filename); SeStrCpy(bak_fullpath, sizeof(bak_fullpath), dst_fullpath); SeStrCat(bak_fullpath, sizeof(bak_fullpath), ".bak"); LABEL_RETRY: ret = DeleteFileA(dst_fullpath); if (ret == false) { char tmp[MAX_SIZE]; wsprintfA(tmp, "Deleting the file \"%s\" failed.\r\n\r\n" "Make sure that there are no running programs using WinPcap DLL.", dst_fullpath); if (MessageBoxA(NULL, tmp, INSTALLER_TITLE, MB_ICONEXCLAMATION | MB_SYSTEMMODAL | MB_RETRYCANCEL) == IDRETRY) { goto LABEL_RETRY; } return false; } MoveFileA(bak_fullpath, dst_fullpath); return true; }
// SE_SEC_CONFIG の初期化 void SeVpn6InitSecConfig(SE_VPN6 *v6, SE_SEC_CONFIG *c) { SE_VPN_CONFIG *vc; SE_IPV6_ADDR zero_ip = Se6ZeroIP(); // 引数チェック if (v6 == NULL || c == NULL) { return; } vc = v6->Vpn->Config; SeZero(c, sizeof(SE_SEC_CONFIG)); SeIkeInitIPv6Address(&c->MyIpAddress, &v6->Vpn->IPv6_Physical->GlobalIpAddress); SeIkeInitIPv6Address(&c->MyVirtualIpAddress, &zero_ip); SeIkeInitIPv6Address(&c->VpnGatewayAddress, &vc->VpnGatewayAddressV6); c->VpnAuthMethod = vc->VpnAuthMethodV6; SeStrCpy(c->VpnPassword, sizeof(c->VpnPassword), vc->VpnPasswordV6); SeStrCpy(c->VpnIdString, sizeof(c->VpnIdString), vc->VpnIdStringV6); SeStrCpy(c->VpnCertName, sizeof(c->VpnCertName), vc->VpnCertNameV6); SeStrCpy(c->VpnCaCertName, sizeof(c->VpnCaCertName), vc->VpnCaCertNameV6); SeStrCpy(c->VpnRsaKeyName, sizeof(c->VpnRsaKeyName), vc->VpnRsaKeyNameV6); c->VpnPhase1Crypto = vc->VpnPhase1CryptoV6; c->VpnPhase1Hash = vc->VpnPhase1HashV6; c->VpnPhase1LifeKilobytes = vc->VpnPhase1LifeKilobytesV6; c->VpnPhase1LifeSeconds = vc->VpnPhase1LifeSecondsV6; c->VpnWaitPhase2BlankSpan = vc->VpnWaitPhase2BlankSpanV6; c->VpnPhase2Crypto = vc->VpnPhase2CryptoV6; c->VpnPhase2Hash = vc->VpnPhase2HashV6; c->VpnPhase2LifeKilobytes = vc->VpnPhase2LifeKilobytesV6; c->VpnPhase2LifeSeconds = vc->VpnPhase2LifeSecondsV6; c->VpnConnectTimeout = vc->VpnConnectTimeoutV6; c->VpnIdleTimeout = vc->VpnIdleTimeoutV6; SeIkeInitIPv6Address(&c->VpnPingTarget, &vc->VpnPingTargetV6); c->VpnPingInterval = vc->VpnPingIntervalV6; c->VpnPingMsgSize = vc->VpnPingMsgSizeV6; c->VpnSpecifyIssuer = vc->VpnSpecifyIssuerV6; }
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; }