Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abbiecnt committed Sep 13, 2024
1 parent 7870771 commit e1f7d11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
11 changes: 4 additions & 7 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ impl Base {
let raw_base = unsafe { GetModuleHandleW(PCWSTR::null()).unwrap_unchecked().0.cast() };

// SAFETY: `raw_base` is valid and non-null.
unsafe { Self::new_unchecked(raw_base) }
unsafe { Self::new_unchecked(NonNull::new_unchecked(raw_base)) }
}

#[inline]
/// # Safety
///
///
///
///
pub const unsafe fn add(&self, count: usize) -> NonNull<u8> {
// SAFETY: todo!()
unsafe { self.ptr.add(count) }
Expand All @@ -38,10 +38,7 @@ impl Base {
///
/// `ptr` must be non-null.
#[inline]
pub(crate) const unsafe fn new_unchecked(ptr: *mut u8) -> Self {
// SAFETY: Caller ensures that `ptr` is non-null.
let ptr = unsafe { NonNull::new_unchecked(ptr) };

pub(crate) const unsafe fn new_unchecked(ptr: NonNull<u8>) -> Self {
Self { ptr }
}
}
Expand Down
9 changes: 3 additions & 6 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,10 @@ impl Program {
.name()
.unwrap_or(unsafe { from_utf8_unchecked(&section.Name) });

let base = unsafe {
Base::new_unchecked(base.add(section.VirtualAddress as usize).as_ptr().cast())
};
let base =
unsafe { Base::new_unchecked(base.add(section.VirtualAddress as usize)) };

let len = section.VirtualSize as usize;

Section::new(name, base, len)
Section::new(name, base, section.VirtualSize as usize)
})
.collect();

Expand Down

0 comments on commit e1f7d11

Please sign in to comment.