diff --git a/src/server/handlers/windows.rs b/src/server/handlers/windows.rs index 3ca4361..39e925e 100644 --- a/src/server/handlers/windows.rs +++ b/src/server/handlers/windows.rs @@ -205,28 +205,8 @@ impl Handler for WindowsHandler { impl Handler for WindowsHandler { fn handle(&self, req: VirtualQueryExRequest) -> VirtualQueryExResponse { - unsafe { - let mut data = - std::mem::MaybeUninit::::uninit().assume_init(); - let size = VirtualQueryEx( - req.handle as HANDLE, - req.base_address as LPCVOID, - &mut data, - std::mem::size_of::(), - ); - - if size != 0 { - VirtualQueryExResponse { - info: Some(RegionInfo { - protection: data.Protect, - memory_type: data.Type, - base_address: data.BaseAddress as u64, - size: data.RegionSize as u64, - }), - } - } else { - VirtualQueryExResponse { info: None } - } + VirtualQueryExResponse { + info: unsafe { virtual_query_ex(req.handle, req.base_address as usize) }, } } } @@ -243,31 +223,10 @@ impl Handler for WindowsHandler { let mut address = 0usize; loop { - let option = unsafe { - let mut data = - std::mem::MaybeUninit::::uninit().assume_init(); - let size = VirtualQueryEx( - req.handle as HANDLE, - address as LPCVOID, - &mut data, - std::mem::size_of::(), - ); - - if size != 0 { - address += data.RegionSize; - - Some(RegionInfo { - protection: data.Protect, - memory_type: data.Type, - base_address: data.BaseAddress as u64, - size: data.RegionSize as u64, - }) - } else { - None - } - }; + let option = unsafe { virtual_query_ex(req.handle, address) }; if let Some(info) = option { + address += info.size as usize; items.push(info); } else { break; @@ -277,3 +236,24 @@ impl Handler for WindowsHandler { VirtualQueryExFullResponse { info: items } } } + +unsafe fn virtual_query_ex(handle: i32, address: usize) -> Option { + let mut data = std::mem::MaybeUninit::::uninit().assume_init(); + let size = VirtualQueryEx( + handle as HANDLE, + address as LPCVOID, + &mut data, + std::mem::size_of::(), + ); + + if size != 0 { + Some(RegionInfo { + protection: data.Protect, + memory_type: data.Type, + base_address: data.BaseAddress as u64, + size: data.RegionSize as u64, + }) + } else { + None + } +}