From db7bcda8ec7e93814275bc62cfa3ee5c295e2ad0 Mon Sep 17 00:00:00 2001 From: KiraCoding <38864051+KiraCoding@users.noreply.github.com> Date: Sun, 1 Sep 2024 21:04:40 +0200 Subject: [PATCH] wip --- src/lib.rs | 2 -- src/program.rs | 58 ++------------------------------------------------ src/symbol.rs | 13 ----------- 3 files changed, 2 insertions(+), 71 deletions(-) delete mode 100644 src/symbol.rs diff --git a/src/lib.rs b/src/lib.rs index 8d23df3..24e06d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,7 @@ mod base; mod program; mod section; -mod symbol; pub use base::Base; pub use program::{program, Program}; pub use section::Section; -pub use symbol::Symbol; diff --git a/src/program.rs b/src/program.rs index b7ae544..ef24eca 100644 --- a/src/program.rs +++ b/src/program.rs @@ -1,16 +1,14 @@ -use crate::{Base, Section, Symbol}; -use core::ffi::c_char; +use crate::{Base, Section}; use core::ops::Index; use core::ptr::NonNull; use core::slice::{from_raw_parts, SliceIndex}; use rayon::iter::IndexedParallelIterator; use rayon::slice::ParallelSlice; -use std::collections::HashMap; 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, IMAGE_EXPORT_DIRECTORY}; +use windows::Win32::System::SystemServices::IMAGE_DOS_HEADER; static PROGRAM: LazyLock = LazyLock::new(Program::init); @@ -23,7 +21,6 @@ pub struct Program { base: Base, len: usize, sections: Vec
, - exports: HashMap<&'static str, Symbol>, } impl Program { @@ -109,63 +106,12 @@ impl Program { }) .collect(); - let exports = Program::parse_export_symbols(nt_headers64, base); - Self { base, len, sections, - exports, } } - - fn parse_export_symbols(nt_headers: &IMAGE_NT_HEADERS64, base: Base) -> HashMap<&str, Symbol> { - let mut symbols = HashMap::new(); - - let export_directory_rva = nt_headers.OptionalHeader.DataDirectory[0].VirtualAddress; - - if export_directory_rva == 0 { - return symbols; - } - - let export_directory: &IMAGE_EXPORT_DIRECTORY = - unsafe { &*(base.add(export_directory_rva as usize).as_ptr().cast()) }; - - let name_ptrs = - unsafe { base.add(export_directory.AddressOfNames as usize).as_ptr() } as *const u32; - - let func_ptrs = unsafe { - base.add(export_directory.AddressOfFunctions as usize) - .as_ptr() - } as *const u32; - - let ordinals = unsafe { - base.add(export_directory.AddressOfNameOrdinals as usize) - .as_ptr() - } as *const u16; - - for i in 0..export_directory.NumberOfNames { - let name_rva = unsafe { *name_ptrs.add(i as usize) }; - let name_ptr = unsafe { base.add(name_rva as usize).as_ptr() }; - let name = unsafe { std::ffi::CStr::from_ptr(name_ptr as *const c_char) } - .to_str() - .unwrap(); - - println!("{}", name); - - let ordinal = unsafe { *ordinals.add(i as usize) }; - let func_rva = unsafe { *func_ptrs.add(ordinal as usize) }; - let func_addr = unsafe { base.add(func_rva as usize) }; - - let base = unsafe { Base::new_unchecked(func_addr.as_ptr()) }; - - let symbol = Symbol::new(name, base); - - symbols.insert(name, symbol); - } - - symbols - } } impl> Index for Program { diff --git a/src/symbol.rs b/src/symbol.rs deleted file mode 100644 index 08413fb..0000000 --- a/src/symbol.rs +++ /dev/null @@ -1,13 +0,0 @@ -use crate::Base; - -#[derive(Debug)] -pub struct Symbol { - name: &'static str, - base: Base, -} - -impl Symbol { - pub(crate) fn new(name: &'static str, base: Base) -> Self { - Self { name, base } - } -}