From 6c4ba076c3c3b72421af3ea0af167a10454e0cad Mon Sep 17 00:00:00 2001 From: KiraCoding <38864051+KiraCoding@users.noreply.github.com> Date: Sat, 31 Aug 2024 22:12:33 +0200 Subject: [PATCH] wip --- examples/sections.rs | 9 +++++++++ src/program.rs | 13 +++++++++++-- src/symbol.rs | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/sections.rs b/examples/sections.rs index 1e911c7..9006edb 100644 --- a/examples/sections.rs +++ b/examples/sections.rs @@ -1,5 +1,14 @@ use inka::program; +#[no_mangle] +#[export_name = "test_c"] +#[inline(never)] +pub extern "C" fn test() { + println!("Hi"); +} + fn main() { dbg!(program()); + + test(); } diff --git a/src/program.rs b/src/program.rs index 4b32dae..b7ae544 100644 --- a/src/program.rs +++ b/src/program.rs @@ -23,6 +23,7 @@ pub struct Program { base: Base, len: usize, sections: Vec
, + exports: HashMap<&'static str, Symbol>, } impl Program { @@ -108,10 +109,13 @@ impl Program { }) .collect(); + let exports = Program::parse_export_symbols(nt_headers64, base); + Self { base, len, sections, + exports, } } @@ -146,11 +150,16 @@ impl Program { 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) } + export_directory.Base as u16; + 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, func_rva); + let symbol = Symbol::new(name, base); symbols.insert(name, symbol); } diff --git a/src/symbol.rs b/src/symbol.rs index 7a654c9..08413fb 100644 --- a/src/symbol.rs +++ b/src/symbol.rs @@ -1,5 +1,6 @@ use crate::Base; +#[derive(Debug)] pub struct Symbol { name: &'static str, base: Base,