[windows_kext] Update windows-rs

This commit is contained in:
Vladimir Stoilov
2024-06-28 16:06:30 +03:00
parent 2d9d433945
commit 81bee82b8f
12 changed files with 92 additions and 83 deletions

View File

@@ -1,6 +1,6 @@
use windows_sys::{
Wdk::Foundation::{DEVICE_OBJECT, DRIVER_OBJECT, IRP},
Win32::Foundation::{HANDLE, NTSTATUS},
Wdk::Foundation::{DEVICE_OBJECT, DRIVER_DISPATCH, DRIVER_OBJECT, DRIVER_UNLOAD},
Win32::Foundation::HANDLE,
};
use crate::{
@@ -23,11 +23,6 @@ pub struct Driver {
}
unsafe impl Sync for Driver {}
// This is a workaround for current state of wdk bindings.
// TODO: replace with official version when they are correct: https://github.com/microsoft/wdkmetadata/issues/59
pub type UnloadFnType = unsafe extern "system" fn(driver_object: *const DRIVER_OBJECT);
pub type MjFnType = unsafe extern "system" fn(&mut DEVICE_OBJECT, &mut IRP) -> NTSTATUS;
impl Driver {
pub(crate) fn new(
driver_object: *mut DRIVER_OBJECT,
@@ -50,54 +45,54 @@ impl Driver {
return unsafe { self.device_object.as_mut() };
}
pub fn set_driver_unload(&mut self, driver_unload: UnloadFnType) {
pub fn set_driver_unload(&mut self, driver_unload: DRIVER_UNLOAD) {
if let Some(driver) = unsafe { self.driver_object.as_mut() } {
driver.DriverUnload = Some(unsafe { core::mem::transmute(driver_unload) })
driver.DriverUnload = driver_unload
}
}
pub fn set_read_fn(&mut self, mj_fn: MjFnType) {
pub fn set_read_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(windows_sys::Wdk::System::SystemServices::IRP_MJ_READ, mj_fn);
}
pub fn set_write_fn(&mut self, mj_fn: MjFnType) {
pub fn set_write_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(
windows_sys::Wdk::System::SystemServices::IRP_MJ_WRITE,
mj_fn,
);
}
pub fn set_create_fn(&mut self, mj_fn: MjFnType) {
pub fn set_create_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(
windows_sys::Wdk::System::SystemServices::IRP_MJ_CREATE,
mj_fn,
);
}
pub fn set_device_control_fn(&mut self, mj_fn: MjFnType) {
pub fn set_device_control_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(
windows_sys::Wdk::System::SystemServices::IRP_MJ_DEVICE_CONTROL,
mj_fn,
);
}
pub fn set_close_fn(&mut self, mj_fn: MjFnType) {
pub fn set_close_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(
windows_sys::Wdk::System::SystemServices::IRP_MJ_CLOSE,
mj_fn,
);
}
pub fn set_cleanup_fn(&mut self, mj_fn: MjFnType) {
pub fn set_cleanup_fn(&mut self, mj_fn: DRIVER_DISPATCH) {
self.set_major_fn(
windows_sys::Wdk::System::SystemServices::IRP_MJ_CLEANUP,
mj_fn,
);
}
fn set_major_fn(&mut self, fn_index: u32, mj_fn: MjFnType) {
fn set_major_fn(&mut self, fn_index: u32, mj_fn: DRIVER_DISPATCH) {
if let Some(driver) = unsafe { self.driver_object.as_mut() } {
driver.MajorFunction[fn_index as usize] = Some(unsafe { core::mem::transmute(mj_fn) })
driver.MajorFunction[fn_index as usize] = mj_fn
}
}
}

View File

@@ -270,7 +270,7 @@ impl WdfObjectAttributes {
evt_destroy_callback: None,
execution_level: WdfExecutionLevel::InheritFromParent,
synchronization_scope: WdfSynchronizationScope::InheritFromParent,
parent_object: 0,
parent_object: core::ptr::null_mut(),
context_size_override: 0,
context_type_info: core::ptr::null(),
}

View File

@@ -1,7 +1,7 @@
use super::{callout_data::CalloutData, ffi, layer::Layer};
use crate::ffi::FwpsCalloutClassifyFn;
use alloc::{borrow::ToOwned, format, string::String};
use windows_sys::Wdk::Foundation::DEVICE_OBJECT;
use windows_sys::{Wdk::Foundation::DEVICE_OBJECT, Win32::Foundation::HANDLE};
pub enum FilterType {
Resettable,
@@ -49,13 +49,13 @@ impl Callout {
pub fn register_filter(
&mut self,
filter_engine_handle: isize,
filter_engine_handle: HANDLE,
sublayer_guid: u128,
) -> Result<(), String> {
match ffi::register_filter(
filter_engine_handle,
sublayer_guid,
&format!("{}-filter", self.name),
&self.name,
&self.description,
self.guid,
self.layer,
@@ -75,14 +75,14 @@ impl Callout {
pub(crate) fn register_callout(
&mut self,
filter_engine_handle: isize,
filter_engine_handle: HANDLE,
device_object: *mut DEVICE_OBJECT,
callout_fn: FwpsCalloutClassifyFn,
) -> Result<(), String> {
match ffi::register_callout(
device_object,
filter_engine_handle,
&format!("{}-callout", self.name),
&self.name,
&self.description,
self.guid,
self.layer,

View File

@@ -140,7 +140,7 @@ impl<'a> CalloutData<'a> {
packet_list: Option<TransportPacketList>,
) -> Result<ClassifyDefer, String> {
unsafe {
let mut completion_context = 0;
let mut completion_context: HANDLE = core::ptr::null_mut();
if let Some(completion_handle) = (*self.metadata).get_completion_handle() {
let status = FwpsPendOperation0(completion_handle, &mut completion_context);
check_ntstatus(status)?;

View File

@@ -192,7 +192,7 @@ impl Drop for FilterEngine {
}
}
if self.handle != 0 && self.handle != INVALID_HANDLE_VALUE {
if !self.handle.is_null() && self.handle != INVALID_HANDLE_VALUE {
_ = ffi::filter_engine_close(self.handle);
}
}

View File

@@ -163,7 +163,7 @@ impl Injector {
let status = if packet_list.inbound {
FwpsInjectTransportReceiveAsync0(
self.transport_inject_handle,
0,
core::ptr::null_mut(),
core::ptr::null_mut(),
0,
address_family,
@@ -177,7 +177,7 @@ impl Injector {
} else {
FwpsInjectTransportSendAsync1(
self.transport_inject_handle,
0,
core::ptr::null_mut(),
packet_list.endpoint_handle,
0,
&mut send_params,
@@ -222,7 +222,7 @@ impl Injector {
unsafe {
FwpsInjectNetworkReceiveAsync0(
inject_handle,
0,
core::ptr::null_mut(),
0,
UNSPECIFIED_COMPARTMENT_ID,
inject_info.interface_index,
@@ -237,7 +237,7 @@ impl Injector {
unsafe {
FwpsInjectNetworkSendAsync0(
inject_handle,
0,
core::ptr::null_mut(),
0,
UNSPECIFIED_COMPARTMENT_ID,
nbl,
@@ -269,7 +269,7 @@ impl Injector {
} else {
self.packet_inject_handle_v4
};
if inject_handle == INVALID_HANDLE_VALUE || inject_handle == 0 {
if inject_handle == INVALID_HANDLE_VALUE || inject_handle.is_null() {
return false;
}
@@ -309,19 +309,19 @@ impl Drop for Injector {
fn drop(&mut self) {
unsafe {
if self.transport_inject_handle != INVALID_HANDLE_VALUE
&& self.transport_inject_handle != 0
&& !self.transport_inject_handle.is_null()
{
FwpsInjectionHandleDestroy0(self.transport_inject_handle);
self.transport_inject_handle = INVALID_HANDLE_VALUE;
}
if self.packet_inject_handle_v4 != INVALID_HANDLE_VALUE
&& self.packet_inject_handle_v4 != 0
&& !self.packet_inject_handle_v4.is_null()
{
FwpsInjectionHandleDestroy0(self.packet_inject_handle_v4);
self.packet_inject_handle_v4 = INVALID_HANDLE_VALUE;
}
if self.packet_inject_handle_v6 != INVALID_HANDLE_VALUE
&& self.packet_inject_handle_v6 != 0
&& !self.packet_inject_handle_v6.is_null()
{
FwpsInjectionHandleDestroy0(self.packet_inject_handle_v6);
self.packet_inject_handle_v6 = INVALID_HANDLE_VALUE;