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

Function call_module_entry_point

dumpy/dinvoke/src/lib.rs:136–162  ·  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); ```

(pe_info: &PeMetadata, module_base_address: isize)

Source from the content-addressed store, hash-verified

134/// let ret = dinvoke::call_module_entry_point(&pe.0, pe.1);
135/// ```
136pub fn call_module_entry_point(pe_info: &PeMetadata, module_base_address: isize) -> Result<(), String> {
137
138 let entry_point: isize;
139 if pe_info.is_32_bit
140 {
141 entry_point = module_base_address + pe_info.opt_header_32.AddressOfEntryPoint as isize;
142 }
143 else
144 {
145 entry_point = module_base_address + pe_info.opt_header_64.address_of_entry_point as isize;
146
147 }
148
149 unsafe
150 {
151 let main: EntryPoint = std::mem::transmute(entry_point);
152 let module = HINSTANCE {0: entry_point as isize};
153 let ret = main(module, DLL_PROCESS_ATTACH, ptr::null_mut());
154
155 if !ret.as_bool()
156 {
157 return Err(lc!("[x] Failed to call module's entry point (DllMain -> DLL_PROCESS_ATTACH)."));
158 }
159
160 Ok(())
161 }
162}
163
164/// Retrieves the address of an exported function from the specified module by its ordinal.
165///

Callers

nothing calls this directly

Calls 1

mainFunction · 0.50

Tested by

no test coverage detected