mirror of
https://github.com/Noratrieb/portability.git
synced 2026-01-14 15:55:04 +01:00
stuff
This commit is contained in:
parent
00afbbfea3
commit
d8c08d9359
3 changed files with 20 additions and 2 deletions
9
README.md
Normal file
9
README.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# portability
|
||||
|
||||
a PE loader for educational purposes.
|
||||
|
||||
## references
|
||||
|
||||
- https://learn.microsoft.com/en-us/windows/win32/debug/pe-format
|
||||
- https://learn.microsoft.com/en-us/archive/msdn-magazine/2002/february/inside-windows-win32-portable-executable-file-format-in-detail
|
||||
- https://learn.microsoft.com/en-us/archive/msdn-magazine/2002/march/inside-windows-an-in-depth-look-into-the-win32-portable-executable-file-format-part-2
|
||||
11
src/lib.rs
11
src/lib.rs
|
|
@ -253,6 +253,8 @@ pub fn execute(file: File, pe: &[u8]) {
|
|||
// just some arbitrary offset that probably won't collide with anything
|
||||
let base = optional_header.image_base as usize + 0xFFFFFF0000;
|
||||
|
||||
assert_eq!(base & (4096 - 1), 0);
|
||||
|
||||
let map = unsafe { crate::mmap::map(file).unwrap() };
|
||||
|
||||
// allocate the sections.
|
||||
|
|
@ -274,7 +276,14 @@ pub fn execute(file: File, pe: &[u8]) {
|
|||
} else {
|
||||
crate::mmap::Mode::Read
|
||||
};
|
||||
let address = std::ptr::with_exposed_provenance(base + section.virtual_address as usize);
|
||||
let address =
|
||||
std::ptr::with_exposed_provenance::<()>(base + section.virtual_address as usize);
|
||||
dbg!(section);
|
||||
|
||||
// assert stuff is aligned (yes 4096 as a hardcoded page is bad)
|
||||
//assert_eq!(section.pointer_to_raw_data & (4096 - 1), 0);
|
||||
assert_eq!(address.addr() & (4096 - 1), 0);
|
||||
|
||||
unsafe {
|
||||
map.view(
|
||||
mode,
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ mod imp {
|
|||
self.0,
|
||||
match mode {
|
||||
Mode::Read => FILE_MAP_READ,
|
||||
Mode::Write => FILE_MAP_READ | FILE_MAP_COPY,
|
||||
Mode::Write => FILE_MAP_COPY,
|
||||
Mode::Execute => FILE_MAP_READ | FILE_MAP_EXECUTE,
|
||||
},
|
||||
(file_offset << 32) as u32,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue