Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
strategy:
fail-fast: false
matrix:
msrv: ["1.68"]
msrv: ["1.82"]
steps:
- uses: actions/checkout@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions windivert-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ categories = ["external-ffi-bindings"]
readme = "../README.md"
license = "LGPL-3.0-or-later"
edition = "2021"
rust-version = "1.68"
rust-version = "1.82"
links = "WinDivert"
build = "build/main.rs"

Expand All @@ -24,10 +24,10 @@ vendored = []
static = ["vendored"]

[dependencies]
thiserror = "1"
thiserror = "2"

[dependencies.windows]
version = "0.48"
version = "0.62"
features = [
"Win32_Foundation",
"Win32_System_IO",
Expand Down
3 changes: 2 additions & 1 deletion windivert-sys/src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ pub use error::*;
mod newtypes;
pub use newtypes::*;

use windows::core::BOOL;
use windows::Win32::{
Foundation::{BOOL, HANDLE},
Foundation::HANDLE,
System::IO::OVERLAPPED,
};
/// Default value for queue length parameter.
Expand Down
4 changes: 2 additions & 2 deletions windivert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ static = ["vendored", "windivert-sys/static"]

[dependencies]
etherparse = "0.13"
thiserror = "1"
thiserror = "2"
windivert-sys = { version = "0.10.0", path = "../windivert-sys" }

[dependencies.windows]
version = "0.48"
version = "0.62"
features = [
"Devices_Custom",
"Win32_Devices",
Expand Down
29 changes: 13 additions & 16 deletions windivert/src/divert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use windows::{
System::{
Services::{
CloseServiceHandle, ControlService, OpenSCManagerA, OpenServiceA,
SC_MANAGER_ALL_ACCESS, SERVICE_CONTROL_STOP, SERVICE_STATUS,
SC_MANAGER_ALL_ACCESS, SERVICE_CONTROL_STOP,
},
Threading::{CreateEventA, TlsAlloc, TlsGetValue, TlsSetValue},
},
Expand All @@ -33,6 +33,11 @@ pub struct WinDivert<L: layer::WinDivertLayerTrait> {
_layer: PhantomData<L>,
}

// SAFETY: HANDLE contains a *mut c_void (as of windows 0.58+) but represents
// a Win32 kernel handle which is safe to send and share across threads.
unsafe impl<L: layer::WinDivertLayerTrait> Send for WinDivert<L> {}
unsafe impl<L: layer::WinDivertLayerTrait> Sync for WinDivert<L> {}

/// Recv implementations
impl<L: layer::WinDivertLayerTrait> WinDivert<L> {
/// Open a handle using the specified parameters.
Expand Down Expand Up @@ -60,10 +65,10 @@ impl<L: layer::WinDivertLayerTrait> WinDivert<L> {
pub(crate) fn _get_event(tls_idx: u32) -> Result<HANDLE, WinDivertError> {
let mut event = HANDLE::default();
unsafe {
event.0 = TlsGetValue(tls_idx) as isize;
event.0 = TlsGetValue(tls_idx);
if event.is_invalid() {
event = CreateEventA(None, false, false, None)?;
TlsSetValue(tls_idx, Some(event.0 as *mut c_void));
TlsSetValue(tls_idx, Some(event.0 as *const c_void))?;
}
}
Ok(event)
Expand Down Expand Up @@ -189,26 +194,18 @@ impl WinDivert<()> {

/// Method that tries to uninstall WinDivert driver.
pub fn uninstall() -> WinResult<()> {
let status: *mut SERVICE_STATUS = MaybeUninit::uninit().as_mut_ptr();
let mut status = MaybeUninit::uninit();
unsafe {
let status = status.as_mut_ptr();
let manager = OpenSCManagerA(None, None, SC_MANAGER_ALL_ACCESS)?;
let service = OpenServiceA(
manager,
PCSTR::from_raw("WinDivert".as_ptr()),
SC_MANAGER_ALL_ACCESS,
)?;
let res = ControlService(service, SERVICE_CONTROL_STOP, status);
if !res.as_bool() {
return Err(WinError::from(GetLastError()));
}
let res = CloseServiceHandle(service);
if !res.as_bool() {
return Err(WinError::from(GetLastError()));
}
let res = CloseServiceHandle(manager);
if !res.as_bool() {
return Err(WinError::from(GetLastError()));
}
ControlService(service, SERVICE_CONTROL_STOP, status)?;
CloseServiceHandle(service)?;
CloseServiceHandle(manager)?;
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions windivert/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'a> WinDivertPacket<'a, layer::NetworkLayer> {
)
};
if !res.as_bool() {
return Err(WinDivertError::from(windows::core::Error::from_win32()));
return Err(WinDivertError::from(windows::core::Error::from_thread()));
}
}
Ok(())
Expand Down Expand Up @@ -72,7 +72,7 @@ impl<'a> WinDivertPacket<'a, layer::ForwardLayer> {
)
};
if !res.as_bool() {
return Err(WinDivertError::from(windows::core::Error::from_win32()));
return Err(WinDivertError::from(windows::core::Error::from_thread()));
}
}
Ok(())
Expand Down