From cf5f6500af6ae18b37805f52ce015a6cf0c0ed4f Mon Sep 17 00:00:00 2001 From: KiraCoding <38864051+KiraCoding@users.noreply.github.com> Date: Fri, 13 Sep 2024 06:54:02 +0200 Subject: [PATCH] wip --- src/program.rs | 54 ++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/program.rs b/src/program.rs index 86971f7..fea72ca 100644 --- a/src/program.rs +++ b/src/program.rs @@ -145,34 +145,32 @@ 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 - .section_headers() - .iter() - .map(|section| { - let name = section.name().unwrap(); - - let base = unsafe { - Base::new_unchecked( - base.add(section.VirtualAddress as usize).as_ptr().cast(), - ) - }; - - let len = section.VirtualSize as usize; - - Section::new(name, base, len) - }) - .collect(); - - Self { - base, - len, - sections, - } + let pe = unsafe { PeView::module(base.as_nonnull().as_ptr()) }; + + let len = pe.nt_headers().OptionalHeader.SizeOfImage as usize; + + let sections = pe + .section_headers() + .iter() + .map(|section| { + let name = section + .name() + .unwrap_or(unsafe { from_utf8_unchecked(§ion.Name) }); + + let base = unsafe { + Base::new_unchecked(base.add(section.VirtualAddress as usize).as_ptr().cast()) + }; + + let len = section.VirtualSize as usize; + + Section::new(name, base, len) + }) + .collect(); + + Self { + base, + len, + sections, } } }