diff --git a/Cargo.toml b/Cargo.toml index 07c527f..a48b4c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,4 @@ version = "0.58.0" features = [ "Win32_System_LibraryLoader", "Win32_System_SystemServices", - "Win32_System_Diagnostics_Debug", - "Win32_System_SystemInformation", ] diff --git a/src/header.rs b/src/header.rs index e69de29..1e5322d 100644 --- a/src/header.rs +++ b/src/header.rs @@ -0,0 +1,28 @@ +use crate::Base; +use core::slice::from_raw_parts; + +#[derive(Debug)] +pub struct Header { + base: Base, + len: usize, +} + +impl Header { + /// Returns a base pointer of this section. + #[inline] + pub fn base(&self) -> Base { + self.base + } + + /// Returns the length of this section. + #[inline] + #[allow(clippy::len_without_is_empty)] + pub fn len(&self) -> usize { + self.len + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + unsafe { from_raw_parts(self.base.as_nonnull().as_ptr(), self.len) } + } +} diff --git a/src/lib.rs b/src/lib.rs index a6ab644..4ba1406 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,13 @@ //! # Inka mod base; +mod header; mod program; mod section; pub use base::Base; +pub use header::Header; pub use program::{program, Program}; pub use section::Section; + +pub type Name = &'static str; \ No newline at end of file diff --git a/src/section.rs b/src/section.rs index 5b77c4c..e7b8839 100644 --- a/src/section.rs +++ b/src/section.rs @@ -1,4 +1,4 @@ -use crate::Base; +use crate::{Base, Name}; use core::ops::Index; use core::ptr::NonNull; use core::slice::{from_raw_parts, SliceIndex}; @@ -8,7 +8,7 @@ use rayon::slice::ParallelSlice; /// Represents a `Section` of the program in memory, providing access to its name, base address, and length. #[derive(Debug)] pub struct Section { - name: &'static str, + name: Name, base: Base, len: usize, }