Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abbiecnt committed Aug 30, 2024
1 parent e8e1c5f commit bdd2c8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/program.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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);
}
Expand Down
8 changes: 7 additions & 1 deletion src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ use crate::Base;
pub struct Symbol {
name: &'static str,
base: Base,
}
}

impl Symbol {
pub(crate) fn new(name: &'static str, base: Base) -> Self {
Self { name, base }
}
}

0 comments on commit bdd2c8d

Please sign in to comment.