MCPcopy Create free account
hub / github.com/Kudaes/Split / call_module_entry_point

Function call_module_entry_point

dinvoke/src/lib.rs:475–501  ·  view source on GitHub ↗

Calls the module's entry point with the option DLL_ATTACH_PROCESS. # Examples ```ignore let pe = manualmap::read_and_map_module("c:\\some\\random\\file.dll").unwrap(); let ret = dinvoke::call_module_entry_point(pe.0, pe.1); match ret { Ok(()) => println!("Module entry point successfully executed."), Err(e) => println!("Error ocurred: {}", e) } ```

(pe_info: PeMetadata, module_base_address: i64)

Source from the content-addressed store, hash-verified

473/// }
474/// ```
475pub fn call_module_entry_point(pe_info: PeMetadata, module_base_address: i64) -> Result<(), String> {
476
477 let entry_point;
478 if pe_info.is_32_bit
479 {
480 entry_point = module_base_address + pe_info.opt_header_32.AddressOfEntryPoint as i64;
481 }
482 else
483 {
484 entry_point = module_base_address + pe_info.opt_header_64.address_of_entry_point as i64;
485
486 }
487
488 unsafe
489 {
490 let main: EntryPoint = std::mem::transmute(entry_point);
491 let module = HINSTANCE {0: entry_point as isize};
492 let ret = main(module, DLL_PROCESS_ATTACH, ptr::null_mut());
493
494 if !ret.as_bool()
495 {
496 return Err(lc!("[x] Failed to call module's entry point (DllMain -> DLL_PROCESS_ATTACH)."));
497 }
498
499 Ok(())
500 }
501}
502
503/// Retrieves the address of an exported function from the specified module by its ordinal.
504///

Callers

nothing calls this directly

Calls 1

mainFunction · 0.50

Tested by

no test coverage detected