Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
KiraCoding committed Aug 31, 2024
1 parent bdd2c8d commit 6c4ba07
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/sections.rs
Original file line number Diff line number Diff line change
@@ -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();
}
13 changes: 11 additions & 2 deletions src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Program {
base: Base,
len: usize,
sections: Vec<Section>,
exports: HashMap<&'static str, Symbol>,
}

impl Program {
Expand Down Expand Up @@ -108,10 +109,13 @@ impl Program {
})
.collect();

let exports = Program::parse_export_symbols(nt_headers64, base);

Self {
base,
len,
sections,
exports,
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/symbol.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::Base;

#[derive(Debug)]
pub struct Symbol {
name: &'static str,
base: Base,
Expand Down

0 comments on commit 6c4ba07

Please sign in to comment.