From 15caad3e4a352aac8f6e9c55737538ad12cfd118 Mon Sep 17 00:00:00 2001 From: numbers Date: Thu, 8 Feb 2024 20:17:33 -0500 Subject: [PATCH] imagebase::as_slice imagebase::as_slice_mut &imagebase::add &imageabse::sub --- src/win32/pe_image.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/win32/pe_image.rs b/src/win32/pe_image.rs index 1cffc5a..6a869a7 100644 --- a/src/win32/pe_image.rs +++ b/src/win32/pe_image.rs @@ -235,6 +235,18 @@ impl ImageBase { self.as_ptr()..self.as_ptr() + self.nt_header().optional_header.size_of_image as usize } + pub unsafe fn as_slice(&self) -> &[u8] { + let ptr = self.as_ptr() as *const u8; + let size = self.nt_header().optional_header.size_of_image as usize; + core::slice::from_raw_parts(ptr, size) + } + + pub unsafe fn as_slice_mut(&self) -> &mut [u8] { + let ptr = self.as_ptr() as *mut u8; + let size = self.nt_header().optional_header.size_of_image as usize; + core::slice::from_raw_parts_mut(ptr, size) + } + } impl ImageNTHeaders64 {