Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abbiecnt committed Aug 27, 2024
1 parent d211921 commit 924810a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 4 additions & 0 deletions src/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

0 comments on commit 924810a

Please sign in to comment.