// Is the PCD driver supported in current OS bool IsPcdSupported() { UINT type; OS_INFO *info = GetOsInfo(); if (MsIsWindows10()) { // Windows 10 or later never supports PCD driver. return false; } type = info->OsType; if (OS_IS_WINDOWS_NT(type) == false) { // Only on Windows NT series return false; } if (GET_KETA(type, 100) >= 2) { // Good for Windows 2000 or later return true; } // Not good for Windows NT 4.0 or Longhorn return false; }
// Get the version information of Windows void Win32GetWinVer(RPC_WINVER *v) { // Validate arguments if (v == NULL) { return; } Zero(v, sizeof(RPC_WINVER)); v->IsWindows = true; if (OS_IS_WINDOWS_NT(GetOsType()) == false) { // Windows 9x OSVERSIONINFO os; Zero(&os, sizeof(os)); os.dwOSVersionInfoSize = sizeof(os); GetVersionEx(&os); v->Build = LOWORD(os.dwBuildNumber); v->VerMajor = os.dwMajorVersion; v->VerMinor = os.dwMinorVersion; Format(v->Title, sizeof(v->Title), "%s %s", GetOsInfo()->OsProductName, GetOsInfo()->OsVersion); Trim(v->Title); } else { // Windows NT 4.0 SP6 or later OSVERSIONINFOEX os; Zero(&os, sizeof(os)); os.dwOSVersionInfoSize = sizeof(os); Win32GetVersionExInternal((LPOSVERSIONINFOA)&os); v->IsNT = true; v->Build = os.dwBuildNumber; v->ServicePack = os.wServicePackMajor; if (os.wProductType != VER_NT_WORKSTATION) { v->IsServer = true; } v->VerMajor = os.dwMajorVersion; v->VerMinor = os.dwMinorVersion; if (GetOsInfo()->OsServicePack == 0) { StrCpy(v->Title, sizeof(v->Title), GetOsInfo()->OsProductName); } else { Format(v->Title, sizeof(v->Title), "%s Service Pack %u", GetOsInfo()->OsProductName, GetOsInfo()->OsServicePack); } Trim(v->Title); if (InStr(GetOsInfo()->OsVersion, "rc") || InStr(GetOsInfo()->OsVersion, "beta")) { v->IsBeta = true; } } }
// Main process void ViMain() { char tmp[MAX_PATH]; UINT ostype = GetOsInfo()->OsType; VI_SETTING_ARCH *suitable; TOKEN_LIST *t; UINT i; if (OS_IS_WINDOWS_NT(ostype) == false || GET_KETA(ostype, 100) <= 1) { // The OS is too old MsgBox(NULL, MB_ICONEXCLAMATION, _U(IDS_BAD_OS+skip)); return; } Zero(&setting, sizeof(setting)); // Read the inf file Format(tmp, sizeof(tmp), "%s\\%s", MsGetExeDirName(), VI_INF_FILENAME); if (ViLoadInf(&setting, tmp) == false) { // Failure MsgBoxEx(NULL, MB_ICONSTOP, _U(IDS_INF_LOAD_FAILED+skip), VI_INF_FILENAME); return; } ViSetSkip(); // Parse the command line options t = GetCommandLineToken(); for (i = 0;i < t->NumTokens;i++) { char *s = t->Token[i]; if (IsEmptyStr(s) == false) { if (StartWith(s, "/") || StartWith(s, "-")) { if (StrCmpi(&s[1], "web") == 0) { setting.WebMode = true; } } else { StrCpy(setting.SettingPath, sizeof(setting.SettingPath), s); } } } FreeToken(t); suitable = ViGetSuitableArchForCpu(); // Security check if (setting.WebMode) { bool ok = true; if (ViIsInternetFile(suitable->Path) == false) { ok = false; } if (IsEmptyStr(setting.SettingPath) == false) { if (ViIsInternetFile(setting.SettingPath) == false) { ok = false; } } if (ok == false) { // Security breach MsgBox(NULL, MB_ICONEXCLAMATION, _U(IDS_SECURITY_ERROR+skip)); return; } } // Get the current installation state ViLoadCurrentInstalledStates(); if (suitable->Supported == false) { // This CPU isn't supported MsgBox(NULL, MB_ICONEXCLAMATION, _U(IDS_CPU_NOT_SUPPORTED+skip)); return; } if (suitable->CurrentInstalled && suitable->Build <= suitable->CurrentInstalledBuild) { // Do not download client software since it has already been installed setting.DownloadNotRequired = true; } // Show the dialog ViInstallDlg(); }
LIST *GetEthAdapterListInternal() { LIST *o; LIST *ret; UINT size; char *buf; UINT i, j; char *qos_tag = " (Microsoft's Packet Scheduler)"; SU *su = NULL; LIST *su_adapter_list = NULL; // Try to use SeLow if (enable_selow) { su = SuInit(); } o = NewListFast(CompareWpAdapter); size = 200000; buf = ZeroMalloc(size); // Try to enumerate with SeLow if (su != NULL) { su_adapter_list = SuGetAdapterList(su); if (su_adapter_list == NULL) { // Fail to enumerate SuFree(su); su = NULL; //WHERE; is_using_selow = false; } else { //WHERE; is_using_selow = true; } } else { is_using_selow = false; } if (su_adapter_list != NULL) { // If 1 or more adapters are enumerated by SeLow, create adapter list object UINT i; for (i = 0;i < LIST_NUM(su_adapter_list);i++) { SU_ADAPTER_LIST *t = LIST_DATA(su_adapter_list, i); WP_ADAPTER *a = ZeroMalloc(sizeof(WP_ADAPTER)); StrCpy(a->Name, sizeof(a->Name), t->Name); StrCpy(a->Guid, sizeof(a->Guid), t->Guid); StrCpy(a->Title, sizeof(a->Title), t->Info.FriendlyName); TrimCrlf(a->Title); Trim(a->Title); TrimCrlf(a->Title); Trim(a->Title); if (EndWith(a->Title, qos_tag)) { a->Title[StrLen(a->Title) - StrLen(qos_tag)] = 0; TrimCrlf(a->Title); Trim(a->Title); TrimCrlf(a->Title); Trim(a->Title); } Add(o, a); } } else { // When SeLow is not used, create adapter list with SEE or WinPcap if (wp->PacketGetAdapterNames(buf, &size) == false) { Free(buf); return o; } i = 0; if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType)) { // Windows NT if (size >= 2 && buf[0] != 0 && buf[1] != 0) { goto ANSI_STR; } while (true) { wchar_t tmp[MAX_SIZE]; WP_ADAPTER *a; UniStrCpy(tmp, sizeof(tmp), L""); if (*((wchar_t *)(&buf[i])) == 0) { i += sizeof(wchar_t); break; } for (;*((wchar_t *)(&buf[i])) != 0;i += sizeof(wchar_t)) { wchar_t str[2]; str[0] = *((wchar_t *)(&buf[i])); str[1] = 0; UniStrCat(tmp, sizeof(tmp), str); } i += sizeof(wchar_t); a = ZeroMalloc(sizeof(WP_ADAPTER)); UniToStr(a->Name, sizeof(a->Name), tmp); Add(o, a); } } else { // Windows 9x ANSI_STR: while (true) { char tmp[MAX_SIZE]; WP_ADAPTER *a; StrCpy(tmp, sizeof(tmp), ""); if (*((char *)(&buf[i])) == 0) { i += sizeof(char); break; } for (;*((char *)(&buf[i])) != 0;i += sizeof(char)) { char str[2]; str[0] = *((char *)(&buf[i])); str[1] = 0; StrCat(tmp, sizeof(tmp), str); } i += sizeof(char); a = ZeroMalloc(sizeof(WP_ADAPTER)); StrCpy(a->Name, sizeof(a->Name), tmp); Add(o, a); } } for (j = 0;j < LIST_NUM(o);j++) { WP_ADAPTER *a = LIST_DATA(o, j); StrCpy(a->Title, sizeof(a->Title), &buf[i]); i += StrSize(a->Title); // If device description is "Unknown" in Win9x, skip 1 byte if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType)) { if (StrCmp(a->Title, "Unknown") == 0) { if (buf[i] == 0) { i+=sizeof(char); } } } TrimCrlf(a->Title); Trim(a->Title); TrimCrlf(a->Title); Trim(a->Title); if (EndWith(a->Title, qos_tag)) { a->Title[StrLen(a->Title) - StrLen(qos_tag)] = 0; TrimCrlf(a->Title); Trim(a->Title); TrimCrlf(a->Title); Trim(a->Title); } } } for (j = 0;j < LIST_NUM(o);j++) { // Extract GUID WP_ADAPTER *a = LIST_DATA(o, j); if (IsEmptyStr(a->Guid)) { StrCpy(a->Guid, sizeof(a->Guid), a->Name); ReplaceStr(a->Guid, sizeof(a->Guid), a->Guid, "\\Device\\SEE_", ""); ReplaceStr(a->Guid, sizeof(a->Guid), a->Guid, "\\Device\\NPF_", ""); ReplaceStr(a->Guid, sizeof(a->Guid), a->Guid, "\\Device\\PCD_", ""); } } // Sort if (su_adapter_list != NULL) { // Since adapter list made by SeLow is already sorted, don't sort here Sort(o); } ret = NewListFast(CompareWpAdapter); for (i = 0;i < LIST_NUM(o);i++) { WP_ADAPTER *a = LIST_DATA(o, i); ADAPTER *ad; bool is_ethernet = false; bool ok = false; if (SearchStrEx(a->Title, "ppp", 0, false) != INFINITE || SearchStrEx(a->Title, "wan", 0, false) != INFINITE || SearchStrEx(a->Title, "dialup", 0, false) != INFINITE || SearchStrEx(a->Title, "pptp", 0, false) != INFINITE || SearchStrEx(a->Title, "telepho", 0, false) != INFINITE || SearchStrEx(a->Title, "modem", 0, false) != INFINITE || SearchStrEx(a->Title, "ras", 0, false) != INFINITE) { Free(a); continue; } // Determine whether the adapter type is Ethernet if (su == NULL) { // Determine with See ad = wp->PacketOpenAdapter(a->Name); if (ad != NULL) { NetType type; if (wp->PacketGetNetType(ad, &type)) { if (type.LinkType == 0) { is_ethernet = true; } } wp->PacketCloseAdapter(ad); } } else { // In using SeLow, all devices should be Ethernet device is_ethernet = true; } if (is_ethernet) { // Add only Ethernet device char tmp[MAX_SIZE]; UINT k; StrCpy(tmp, sizeof(tmp), a->Title); for (k = 0;;k++) { if (k == 0) { StrCpy(tmp, sizeof(tmp), a->Title); } else { Format(tmp, sizeof(tmp), "%s (%u)", a->Title, k + 1); } ok = true; for (j = 0;j < LIST_NUM(ret);j++) { WP_ADAPTER *aa = LIST_DATA(ret, j); if (StrCmpi(aa->Title, tmp) == 0) { ok = false; } } if (ok) { break; } } StrCpy(a->Title, sizeof(a->Title), tmp); a->Id = Win32EthGenIdFromGuid(a->Guid); Add(ret, a); } if (ok == false) { Free(a); } } Free(buf); Sort(ret); ReleaseList(o); if (su != NULL) { SuFreeAdapterList(su_adapter_list); SuFree(su); } return ret; }
// Installation of WinPcap void EmInstallWinPcap(HWND hWnd, RPC *r) { wchar_t temp_name[MAX_SIZE]; HGLOBAL g; HINSTANCE h; HRSRC hr; UINT size; void *data; IO *io; // Ask whether the user want to start the installation if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("EM_WPCAP_INSTALL")) == IDNO) { return; } // Generate a temporary file name UniFormat(temp_name, sizeof(temp_name), L"%s\\winpcap_installer.exe", MsGetTempDirW()); // Read from the resource h = GetUiDll(); hr = FindResource(h, MAKEINTRESOURCE(BIN_WINPCAP), "BIN"); if (hr == NULL) { RES_ERROR: MsgBox(hWnd, MB_ICONSTOP, _UU("EM_RESOURCE")); return; } g = LoadResource(h, hr); if (g == NULL) { goto RES_ERROR; } size = SizeofResource(h, hr); data = LockResource(g); if (data == NULL) { goto RES_ERROR; } // Write to a temporary file io = FileCreateW(temp_name); if (io == NULL) { goto RES_ERROR; } FileWrite(io, data, size); FileClose(io); // Run if (RunW(temp_name, NULL, false, true) == false) { // Failure FileDeleteW(temp_name); goto RES_ERROR; } FileDeleteW(temp_name); if (r == NULL) { return; } // Message after the end if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType) == false) { // Need to restart the computer MsgBox(hWnd, MB_ICONINFORMATION, _UU("EM_WPCAP_REBOOT1")); } else { // Need to restart the service if (MsgBox(hWnd, MB_ICONQUESTION | MB_YESNO, _UU("EM_WPCAP_REBOOT2")) == IDNO) { // Not restart } else { // Restart RPC_TEST t; RPC_BRIDGE_SUPPORT t2; Zero(&t, sizeof(t)); EcRebootServer(r, &t); SleepThread(500); Zero(&t2, sizeof(t2)); CALL(hWnd, EcGetBridgeSupport(r, &t2)); } } }