diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2021-01-28 21:59:52 +0000 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2021-01-29 14:22:01 +0000 |
| commit | 7b05ea25293fbba979752b139b913fd8a8b0b554 (patch) | |
| tree | d7c3b389d93b7d6aea20676c4b1c9dd84f42a7b2 | |
| parent | 067f9bc6c599d774a5807a940ca896f9c5866912 (diff) | |
| download | mullvadvpn-7b05ea25293fbba979752b139b913fd8a8b0b554.tar.xz mullvadvpn-7b05ea25293fbba979752b139b913fd8a8b0b554.zip | |
Use new version-metadata in core
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | talpid-core/Cargo.toml | 3 | ||||
| -rw-r--r-- | talpid-core/src/dns/windows/mod.rs | 42 |
3 files changed, 6 insertions, 41 deletions
diff --git a/Cargo.lock b/Cargo.lock index a15f06b68e..b5ba8a132e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2559,6 +2559,7 @@ dependencies = [ "socket2", "system-configuration", "talpid-dbus", + "talpid-platform-metadata", "talpid-types", "tempfile", "tokio", @@ -2609,7 +2610,6 @@ version = "0.1.0" dependencies = [ "rs-release", "talpid-dbus", - "utf16_lit", "winapi 0.3.9", ] diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml index 1a698402f2..78295fe25d 100644 --- a/talpid-core/Cargo.toml +++ b/talpid-core/Cargo.toml @@ -72,9 +72,10 @@ tun = "0.5" [target.'cfg(windows)'.dependencies] widestring = "0.4" winreg = { version = "0.7", features = ["transactions"] } -winapi = { version = "0.3.6", features = ["handleapi", "ifdef", "libloaderapi", "netioapi", "stringapiset", "synchapi", "winbase", "winuser"] } +winapi = { version = "0.3.6", features = [ "combaseapi", "handleapi", "ifdef", "libloaderapi", "netioapi", "stringapiset", "synchapi", "winbase", "winuser"] } socket2 = "0.3" pnet_packet = "0.26" +talpid-platform-metadata = { path = "../talpid-platform-metadata" } [build-dependencies] tonic-build = { version = "0.3", default-features = false, features = ["transport", "prost"] } diff --git a/talpid-core/src/dns/windows/mod.rs b/talpid-core/src/dns/windows/mod.rs index 17165c2364..59f6ee349d 100644 --- a/talpid-core/src/dns/windows/mod.rs +++ b/talpid-core/src/dns/windows/mod.rs @@ -2,15 +2,9 @@ use crate::logging::windows::{log_sink, LogSink}; use lazy_static::lazy_static; use log::{error, trace, warn}; -use std::{ - env, ffi::OsString, io, iter, mem, net::IpAddr, os::windows::ffi::OsStrExt, path::Path, ptr, -}; +use std::{env, io, net::IpAddr, path::Path}; use talpid_types::ErrorExt; use widestring::WideCString; -use winapi::um::{ - libloaderapi::{GetModuleHandleW, GetProcAddress}, - winnt::RTL_OSVERSIONINFOW, -}; use winreg::{ enums::{HKEY_LOCAL_MACHINE, REG_MULTI_SZ}, transaction::Transaction, @@ -222,8 +216,8 @@ fn reset_dns_cache_policy() -> Result<(), Error> { } fn is_minimum_windows10() -> bool { - match is_minimum_windows10_inner() { - Ok(result) => result, + match talpid_platform_metadata::WindowsVersion::new() { + Ok(version_info) => version_info.major_version() >= 10, Err(error) => { error!( "{}", @@ -234,36 +228,6 @@ fn is_minimum_windows10() -> bool { } } -fn is_minimum_windows10_inner() -> Result<bool, io::Error> { - let rtl_get_version: extern "stdcall" fn(*mut RTL_OSVERSIONINFOW); - - let module_name: Vec<u16> = OsString::from("ntdll") - .as_os_str() - .encode_wide() - .chain(iter::once(0u16)) - .collect(); - - let ntdll = unsafe { GetModuleHandleW(module_name.as_ptr()) }; - if ntdll == ptr::null_mut() { - return Err(io::Error::last_os_error()); - } - - let function_address = - unsafe { GetProcAddress(ntdll, b"RtlGetVersion\0" as *const _ as *const i8) }; - if function_address == ptr::null_mut() { - return Err(io::Error::last_os_error()); - } - - rtl_get_version = unsafe { mem::transmute(function_address) }; - - let mut version_info: RTL_OSVERSIONINFOW = unsafe { std::mem::zeroed() }; - version_info.dwOSVersionInfoSize = mem::size_of_val(&version_info) as u32; - rtl_get_version(&mut version_info); - - Ok(version_info.dwMajorVersion >= 10) -} - - ffi_error!(InitializationResult, Error::Initialization); ffi_error!(DeinitializationResult, Error::Deinitialization); ffi_error!(SettingResult, Error::Setting); |
