diff --git a/libafl/Cargo.toml b/libafl/Cargo.toml index f0f0ac7b81..a532f598b6 100644 --- a/libafl/Cargo.toml +++ b/libafl/Cargo.toml @@ -99,10 +99,10 @@ lock_api = "0.4.3" regex = "1.4.5" [target.'cfg(windows)'.dependencies] -windows = { version = "0.29.0", features = ["std", "Win32_Foundation", "Win32_System_Threading", "Win32_System_Diagnostics_Debug", "Win32_System_Kernel", "Win32_System_Memory", "Win32_Security"] } +windows = { version = "0.37.0", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_System_Diagnostics_Debug", "Win32_System_Kernel", "Win32_System_Memory", "Win32_Security"] } [target.'cfg(windows)'.build-dependencies] -windows = "0.29.0" +windows = "0.37.0" #[profile.release] #lto = true diff --git a/libafl/src/bolts/shmem.rs b/libafl/src/bolts/shmem.rs index c9f20fe1c7..935c5c536a 100644 --- a/libafl/src/bolts/shmem.rs +++ b/libafl/src/bolts/shmem.rs @@ -1165,7 +1165,8 @@ pub mod win32_shmem { const INVALID_HANDLE_VALUE: isize = -1; use windows::{ - Win32::Foundation::{CloseHandle, BOOL, HANDLE, PSTR}, + core::PCSTR, + Win32::Foundation::{CloseHandle, BOOL, HANDLE}, Win32::System::Memory::{ CreateFileMappingA, MapViewOfFile, OpenFileMappingA, UnmapViewOfFile, FILE_MAP_ALL_ACCESS, PAGE_READWRITE, @@ -1205,14 +1206,9 @@ pub mod win32_shmem { PAGE_READWRITE, 0, map_size as u32, - PSTR(map_str_bytes.as_mut_ptr()), - ); - if handle == HANDLE(0) { - return Err(Error::unknown(format!( - "Cannot create shared memory {}", - String::from_utf8_lossy(map_str_bytes) - ))); - } + PCSTR(map_str_bytes.as_mut_ptr()), + )?; + let map = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, map_size) as *mut u8; if map.is_null() { return Err(Error::unknown(format!( @@ -1235,16 +1231,11 @@ pub mod win32_shmem { let map_str_bytes = id.id; // Unlike MapViewOfFile this one needs u32 let handle = OpenFileMappingA( - FILE_MAP_ALL_ACCESS, + FILE_MAP_ALL_ACCESS.0, BOOL(0), - PSTR(map_str_bytes.as_ptr() as *mut _), - ); - if handle == HANDLE(0) { - return Err(Error::unknown(format!( - "Cannot open shared memory {}", - String::from_utf8_lossy(&map_str_bytes) - ))); - } + PCSTR(map_str_bytes.as_ptr() as *mut _), + )?; + let map = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, map_size) as *mut u8; if map.is_null() { return Err(Error::unknown(format!( diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index 33b5fb6c9b..b728b8cfe3 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -1096,12 +1096,6 @@ mod windows_exception_handler { compiler_fence(Ordering::SeqCst); ExitProcess(1); - - LeaveCriticalSection( - (data.critical as *mut RTL_CRITICAL_SECTION) - .as_mut() - .unwrap(), - ); } } compiler_fence(Ordering::SeqCst); diff --git a/libafl/src/lib.rs b/libafl/src/lib.rs index 264da7a2cf..1b27ecc1fa 100644 --- a/libafl/src/lib.rs +++ b/libafl/src/lib.rs @@ -374,6 +374,13 @@ impl From for Error { } } +#[cfg(windows)] +impl From for Error { + fn from(err: windows::core::Error) -> Self { + Self::unknown(format!("Windows API error: {:?}", err)) + } +} + #[cfg(feature = "python")] impl From for Error { fn from(err: pyo3::PyErr) -> Self {