diff --git a/src/program/mod.rs b/src/program/mod.rs index 895819e..789db28 100644 --- a/src/program/mod.rs +++ b/src/program/mod.rs @@ -38,10 +38,18 @@ impl Program { unsafe { from_raw_parts(self.base.as_ptr(), self.len) } } + pub fn contains(&self, pattern: &[u8]) -> bool { + self.find(pattern).is_some() + } + pub fn sections(&self) -> &[Section] { &self.sections } + pub fn get_section(&self, name: &str) -> Option<&Section> { + self.sections.iter().find(|section| section.name() == name) + } + pub fn find(&self, pattern: &[u8]) -> Option<*const u8> { self.as_slice() .par_windows(pattern.len()) diff --git a/src/section.rs b/src/section.rs index 948ad95..facd48d 100644 --- a/src/section.rs +++ b/src/section.rs @@ -45,4 +45,8 @@ impl Section { .position_last(|window| window == pattern) .map(|offset| unsafe { self.as_ptr().add(offset) }) } + + pub(crate) fn new(name: &'static str, base: Base, len: usize) -> Self { + Self { name, base, len } + } }