Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
KiraCoding committed Sep 13, 2024
1 parent cf5f650 commit 36c4338
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Empty file added src/header.rs
Empty file.
2 changes: 0 additions & 2 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ impl Program {

fn init() -> Self {
let base = Base::program();

let pe = unsafe { PeView::module(base.as_nonnull().as_ptr()) };

let len = pe.nt_headers().OptionalHeader.SizeOfImage as usize;

let sections = pe
Expand Down
6 changes: 6 additions & 0 deletions src/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,23 @@ impl Section {
}

pub fn contains(&self, pattern: &[u8]) -> bool {
assert!(pattern.len() >= 1);

self.find(pattern).is_some()
}

pub fn find(&self, pattern: &[u8]) -> Option<NonNull<u8>> {
assert!(pattern.len() >= 1);

self.as_slice()
.par_windows(pattern.len())
.position_first(|window| window == pattern)
.map(|offset| unsafe { self.base.add(offset) })
}

pub fn rfind(&self, pattern: &[u8]) -> Option<NonNull<u8>> {
assert!(pattern.len() >= 1);

self.as_slice()
.par_windows(pattern.len())
.position_last(|window| window == pattern)
Expand Down

0 comments on commit 36c4338

Please sign in to comment.