Closes a HANDLE object. It will return either a boolean value or an Err with a descriptive error message. If the function fails the bool value returned will be false. # 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 { let r = dinvoke::close_handle(handle).unwrap(); if r { println!
(handle: HANDLE)
| 383 | /// } |
| 384 | /// ``` |
| 385 | pub fn close_handle(handle: HANDLE) -> Result<bool,String> { |
| 386 | unsafe |
| 387 | { |
| 388 | |
| 389 | let module_base_address = get_module_base_address(&lc!("kernel32.dll")); |
| 390 | let ret; |
| 391 | if module_base_address != 0 |
| 392 | { |
| 393 | let function_address = get_function_address(module_base_address, &lc!("CloseHandle")); |
| 394 | |
| 395 | if function_address != 0 |
| 396 | { |
| 397 | let function_ptr: CloseHandle = std::mem::transmute(function_address); |
| 398 | |
| 399 | |
| 400 | ret = function_ptr(handle); |
| 401 | } |
| 402 | else |
| 403 | { |
| 404 | return Err(lc!("[x] Error obtaining CloseHandle address.")); |
| 405 | } |
| 406 | } |
| 407 | else |
| 408 | { |
| 409 | return Err(lc!("[x] Error obtaining kernel32.dll base address.")); |
| 410 | } |
| 411 | |
| 412 | if ret == 0 |
| 413 | { |
| 414 | return Ok(false); |
| 415 | } |
| 416 | |
| 417 | Ok(true) |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | /// Dynamically calls QueryFullProcessImageNameW. |
| 422 | /// |
no test coverage detected