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

Function load_library_a

dumpy/dinvoke/src/lib.rs:282–314  ·  view source on GitHub ↗

Loads and retrieves a module's base address by dynamically calling LoadLibraryA. It will return either the module's base address or an Err with a descriptive error message. # Examples ``` let ret = dinvoke::load_library_a("ntdll.dll"); match ret { Ok(addr) => if addr != 0 {println!("ntdll.dll base address is 0x{:X}.", addr)}, Err(e) => println!("{}",e), } ```

(module: &str)

Source from the content-addressed store, hash-verified

280/// }
281/// ```
282pub fn load_library_a(module: &str) -> Result<isize, String> {
283
284 unsafe
285 {
286
287 let module_base_address = get_module_base_address(&lc!("kernel32.dll"));
288 let result;
289 if module_base_address != 0
290 {
291 let function_address = get_function_address(module_base_address, &lc!("LoadLibraryA"));
292
293 if function_address != 0
294 {
295 let function_ptr: LoadLibraryA = std::mem::transmute(function_address);
296 let name = CString::new(module.to_string()).expect("CString::new failed");
297 let function_name = PSTR{0: name.as_ptr() as *mut u8};
298
299 result = function_ptr(function_name);
300 }
301 else
302 {
303 return Err(lc!("[x] Error obtaining LoadLibraryA address."));
304 }
305 }
306 else
307 {
308 return Err(lc!("[x] Error obtaining kernel32.dll base address."));
309 }
310
311 Ok(result.0 as isize)
312 }
313
314}
315
316/// Opens a HANDLE to a process.
317///

Callers 3

create_transactionFunction · 0.85
mini_dump_write_dumpFunction · 0.85
rollback_transactionFunction · 0.85

Calls 2

get_module_base_addressFunction · 0.85
get_function_addressFunction · 0.85

Tested by

no test coverage detected