Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abbiecnt committed Sep 3, 2024
1 parent 3e8ee74 commit 0e36603
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 13 additions & 3 deletions src/base.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use core::fmt::{Formatter, Pointer, Result};
use core::ptr::NonNull;
use std::fmt::Debug;
use windows::core::PCWSTR;
use windows::Win32::System::LibraryLoader::GetModuleHandleW;

/// Thread-safe `Base` pointer
#[derive(Clone, Copy)]
Expand All @@ -19,10 +21,18 @@ impl Base {
unsafe { self.ptr.add(count) }
}

pub(crate) fn program() -> Self {
let raw_base = unsafe { GetModuleHandleW(PCWSTR::null()).unwrap_unchecked().0.cast() };

// SAFETY: todo!()
unsafe { Self::new_unchecked(raw_base) }
}

pub(crate) unsafe fn new_unchecked(ptr: *mut u8) -> Self {
Self {
ptr: unsafe { NonNull::new_unchecked(ptr) },
}
// SAFETY: todo!()
let ptr = unsafe { NonNull::new_unchecked(ptr) };

Self { ptr }
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use core::slice::{from_raw_parts, SliceIndex};
use rayon::iter::IndexedParallelIterator;
use rayon::slice::ParallelSlice;
use std::sync::LazyLock;
use windows::core::PCWSTR;
use windows::Win32::System::Diagnostics::Debug::{IMAGE_NT_HEADERS64, IMAGE_SECTION_HEADER};
use windows::Win32::System::LibraryLoader::GetModuleHandleW;
use windows::Win32::System::SystemServices::IMAGE_DOS_HEADER;

static PROGRAM: LazyLock<Program> = LazyLock::new(Program::init);
Expand Down Expand Up @@ -70,9 +68,7 @@ impl Program {
}

fn init() -> Self {
let base = unsafe {
Base::new_unchecked(GetModuleHandleW(PCWSTR::null()).unwrap_unchecked().0.cast())
};
let base = Base::program();

let dos_header = base.as_ptr() as *const IMAGE_DOS_HEADER;
let nt_headers64: &IMAGE_NT_HEADERS64 =
Expand Down

0 comments on commit 0e36603

Please sign in to comment.