MCPcopy Index your code
hub / github.com/Kudaes/Dumpy / open_process

Function open_process

dumpy/dinvoke/src/lib.rs:332–363  ·  view source on GitHub ↗

Opens a HANDLE to a process. It will return either a HANDLE object or an Err with a descriptive error message. If the function fails the HANDLE will have value -1 or 0. # Examples ``` let pid = 792u32; let handle = dinvoke::open_process(0x0040, 0, pid).unwrap(); //PROCESS_DUP_HANDLE access right. if handle.0 != 0 && handle.0 != -1 { println!("Handle to process with id {} with PROCESS_DUP_HANDL

(desired_access: u32, inherit_handle: i32, process_id: u32)

Source from the content-addressed store, hash-verified

330/// }
331/// ```
332pub fn open_process(desired_access: u32, inherit_handle: i32, process_id: u32) -> Result<HANDLE, String> {
333
334 unsafe
335 {
336
337 let module_base_address = get_module_base_address(&lc!("kernel32.dll"));
338 let handle;
339 if module_base_address != 0
340 {
341 let function_address = get_function_address(module_base_address, &lc!("OpenProcess"));
342
343 if function_address != 0
344 {
345 let function_ptr: OpenProcess = std::mem::transmute(function_address);
346
347
348 handle = function_ptr(desired_access,inherit_handle,process_id);
349 }
350 else
351 {
352 return Err(lc!("[x] Error obtaining OpenProcess address."));
353 }
354 }
355 else
356 {
357 return Err(lc!("[x] Error obtaining kernel32.dll base address."));
358 }
359
360 Ok(handle)
361 }
362
363}
364
365/// Closes a HANDLE object.
366///

Callers

nothing calls this directly

Calls 2

get_module_base_addressFunction · 0.85
get_function_addressFunction · 0.85

Tested by

no test coverage detected