From bdd2c8d5d6ce14da8be838eb5a7683946ff4459f Mon Sep 17 00:00:00 2001 From: KiraCoding <38864051+KiraCoding@users.noreply.github.com> Date: Fri, 30 Aug 2024 21:36:22 +0200 Subject: [PATCH] wip --- src/program.rs | 18 ++++++++---------- src/symbol.rs | 8 +++++++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/program.rs b/src/program.rs index fedd39a..4b32dae 100644 --- a/src/program.rs +++ b/src/program.rs @@ -1,4 +1,4 @@ -use crate::{Base, Section}; +use crate::{Base, Section, Symbol}; use core::ffi::c_char; use core::ops::Index; use core::ptr::NonNull; @@ -115,7 +115,7 @@ impl Program { } } - fn parse_export_symbols(nt_headers: &IMAGE_NT_HEADERS64, base: Base) { + 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; @@ -129,10 +129,12 @@ impl Program { 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() @@ -142,17 +144,13 @@ impl Program { 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_string_lossy() - .into_owned(); - + .to_str() + .unwrap(); + let ordinal = unsafe { *ordinals.add(i as usize) } + export_directory.Base as u16; let func_rva = unsafe { *func_ptrs.add(ordinal as usize) }; - let symbol = ExportSymbol { - name: name.clone(), - address: func_rva, - ordinal, - }; + let symbol = Symbol::new(name, func_rva); symbols.insert(name, symbol); } diff --git a/src/symbol.rs b/src/symbol.rs index 9e3531d..7a654c9 100644 --- a/src/symbol.rs +++ b/src/symbol.rs @@ -3,4 +3,10 @@ use crate::Base; pub struct Symbol { name: &'static str, base: Base, -} \ No newline at end of file +} + +impl Symbol { + pub(crate) fn new(name: &'static str, base: Base) -> Self { + Self { name, base } + } +}