(path: &str)
| 499 | } |
| 500 | |
| 501 | fn convert_registry_path(path: &str) -> Result<String, NtStatusError> { |
| 502 | if path == r"\Registry\Machine" || path.starts_with(r"\Registry\Machine\") || |
| 503 | path == r"\Registry\User" || path.starts_with(r"\Registry\User\") { |
| 504 | return Ok(path.to_string()); |
| 505 | } |
| 506 | |
| 507 | let hive : &str; |
| 508 | let mut key_path = String::from(""); |
| 509 | if path.contains('\\') { |
| 510 | hive = path.split('\\').next().unwrap(); |
| 511 | key_path = path.split('\\').skip(1).collect::<Vec<&str>>().join("\\"); |
| 512 | } |
| 513 | else { |
| 514 | hive = path; |
| 515 | } |
| 516 | |
| 517 | let mut path: String = match hive.to_uppercase().as_str() { |
| 518 | "HKEY_CLASSES_ROOT" | "HKCR" => { |
| 519 | format!("\\Registry\\Machine\\Software\\Classes\\{}", key_path) |
| 520 | }, |
| 521 | "HKEY_CURRENT_USER" | "HKCU" => { |
| 522 | let user = NtCurrentUserInfo::new()?; |
| 523 | format!("\\Registry\\User\\{}\\{}", user.sid, key_path) |
| 524 | }, |
| 525 | "HKEY_LOCAL_MACHINE" | "HKLM" => { |
| 526 | format!("\\Registry\\Machine\\{}", key_path) |
| 527 | }, |
| 528 | "HKEY_USERS" | "HKU" => { |
| 529 | format!("\\Registry\\User\\{}", key_path) |
| 530 | }, |
| 531 | "HKEY_CURRENT_CONFIG" | "HKCC" => { |
| 532 | format!("\\Registry\\Machine\\System\\CurrentControlSet\\Hardware Profiles\\Current\\{}", key_path) |
| 533 | }, |
| 534 | _ => { |
| 535 | return Err(NtStatusError::new(STATUS_OBJECT_PATH_SYNTAX_BAD, "Invalid registry path.")); |
| 536 | } |
| 537 | }; |
| 538 | |
| 539 | if path.ends_with('\\') { |
| 540 | path.pop(); |
| 541 | } |
| 542 | |
| 543 | Ok(path) |
| 544 | } |
no test coverage detected