From 7af699240ed9ee369f50b9196c4fa4bd823a45b0 Mon Sep 17 00:00:00 2001 From: tuxuser <462620+tuxuser@users.noreply.github.com> Date: Fri, 23 Aug 2024 07:00:42 +0200 Subject: [PATCH 1/3] feat(daemon): Add impersonate crate, show rare-achievement-toast when starting SSH/SFTP daemon --- crates/impersonate/Cargo.lock | 217 ++++ crates/impersonate/Cargo.toml | 19 + crates/impersonate/src/lib.rs | 155 +++ crates/impersonate/src/process_list.rs | 212 ++++ crates/solstice_daemon/Cargo.lock | 9 + crates/solstice_daemon/Cargo.toml | 5 + crates/solstice_daemon/src/main.rs | 15 + crates/solstice_daemon/src/toast.rs | 55 + crates/solstice_daemon/src/winrt.rs | 1526 ++++++++++++++++++++++++ 9 files changed, 2213 insertions(+) create mode 100644 crates/impersonate/Cargo.lock create mode 100644 crates/impersonate/Cargo.toml create mode 100644 crates/impersonate/src/lib.rs create mode 100644 crates/impersonate/src/process_list.rs create mode 100644 crates/solstice_daemon/src/toast.rs create mode 100644 crates/solstice_daemon/src/winrt.rs diff --git a/crates/impersonate/Cargo.lock b/crates/impersonate/Cargo.lock new file mode 100644 index 0000000..c54676a --- /dev/null +++ b/crates/impersonate/Cargo.lock @@ -0,0 +1,217 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "impersonate" +version = "0.1.0" +dependencies = [ + "tracing", + "windows", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core", + "windows-targets", +] + +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/crates/impersonate/Cargo.toml b/crates/impersonate/Cargo.toml new file mode 100644 index 0000000..5b2bd05 --- /dev/null +++ b/crates/impersonate/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "impersonate" +version = "0.1.0" +edition = "2021" + +[dependencies] +tracing = "0.1.40" +windows = { version = "0.58.0", features = [ + "Win32_Security", + "Win32_System_Threading", + "Win32_System_ProcessStatus", + "Win32_System_Com", + "Win32_System_WindowsProgramming", + "Win32_System_SystemServices" +] } + +[features] +default = [] + diff --git a/crates/impersonate/src/lib.rs b/crates/impersonate/src/lib.rs new file mode 100644 index 0000000..5cd2a79 --- /dev/null +++ b/crates/impersonate/src/lib.rs @@ -0,0 +1,155 @@ +/// Reference: https://github.com/joaovarelas/steal-token-rs/blob/main/src/main.rs +use tracing::{error, debug}; +use windows::core::PSTR; +use windows::Win32::Foundation::{BOOL, FALSE, HANDLE, LUID, TRUE}; +use windows::Win32::Security::{AdjustTokenPrivileges, RevertToSelf}; +use windows::Win32::Security::LUID_AND_ATTRIBUTES; +use windows::Win32::Security::PRIVILEGE_SET; +use windows::Win32::Security::{ + DuplicateTokenEx, LookupPrivilegeValueW, PrivilegeCheck, SecurityImpersonation, + TokenImpersonation, SE_DEBUG_NAME, SE_PRIVILEGE_ENABLED, TOKEN_ACCESS_MASK, TOKEN_ALL_ACCESS, + TOKEN_ASSIGN_PRIMARY, TOKEN_DUPLICATE, TOKEN_IMPERSONATE, TOKEN_PRIVILEGES, TOKEN_QUERY, +}; +use windows::Win32::System::SystemServices::MAXIMUM_ALLOWED; +use windows::Win32::System::Threading::OpenProcess; +use windows::Win32::System::Threading::{ + GetCurrentProcess, OpenProcessToken, SetThreadToken, PROCESS_QUERY_INFORMATION, +}; +use windows::Win32::System::WindowsProgramming::GetUserNameA; + +mod process_list; + +pub struct Impersonate { + current_process: HANDLE, + original_token: HANDLE, +} + +impl Impersonate { + pub fn create() -> Self { + let own = unsafe { GetCurrentProcess() }; + let orig_token = Self::get_impersonation_token(own).unwrap(); + Self { + current_process: own, + original_token: orig_token, + } + } + + fn get_impersonation_token(process_handle: HANDLE) -> Result> { + let mut token_handle = HANDLE::default(); + let mut new_token = HANDLE::default(); + + unsafe { + OpenProcessToken( + process_handle, + TOKEN_QUERY | TOKEN_IMPERSONATE | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY, + &mut token_handle, + )?; + + DuplicateTokenEx( + token_handle, + TOKEN_ACCESS_MASK(MAXIMUM_ALLOWED), + None, + SecurityImpersonation, + TokenImpersonation, + &mut new_token, + )?; + } + + Ok(new_token) + } + + pub fn get_username() -> Result> { + let mut buffer = vec![0u8; 257]; + let lpbuffer: PSTR = PSTR(buffer.as_mut_ptr()); + let mut pcbbuffer: u32 = buffer.len() as u32; + + unsafe { + GetUserNameA(lpbuffer, &mut pcbbuffer)?; + } + + let username = String::from_utf8(buffer)?.trim_end_matches("\0").to_owned(); + Ok(username) + } + + fn enable_debug_privilege(&mut self) -> Result<(), Box> { + unsafe { + let mut luid: LUID = LUID { + LowPart: 0, + HighPart: 0, + }; + + LookupPrivilegeValueW(None, SE_DEBUG_NAME, &mut luid)?; + OpenProcessToken(self.current_process, TOKEN_ALL_ACCESS, &mut self.original_token)?; + + let token_priv: TOKEN_PRIVILEGES = TOKEN_PRIVILEGES { + PrivilegeCount: 1, + Privileges: [LUID_AND_ATTRIBUTES { + Luid: luid, + Attributes: SE_PRIVILEGE_ENABLED, + }], + }; + + AdjustTokenPrivileges(self.original_token, FALSE, Some(&token_priv), 0, None, None)?; + + let mut priv_set: PRIVILEGE_SET = PRIVILEGE_SET { + PrivilegeCount: 1, + Control: 1u32, // PRIVILEGE_SET_ALL_NECESSARY + Privilege: [LUID_AND_ATTRIBUTES { + Luid: luid, + Attributes: SE_PRIVILEGE_ENABLED, + }], + }; + + let mut priv_enabled: BOOL = BOOL(1); + PrivilegeCheck(self.original_token, &mut priv_set, &mut priv_enabled)?; + + debug!("SeDebugPrivilege is: {:?}", priv_enabled); + } + + Ok(()) + } + + pub fn do_impersonate_pid(&mut self, pid: u32) -> Result<(), Box> { + unsafe { + let proc_handle = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, pid)?; + let new_token = Impersonate::get_impersonation_token(proc_handle)?; + SetThreadToken(None, new_token)?; + } + Ok(()) + } + + pub fn do_impersonate_process_name(&mut self, process_name: &str) -> Result<(), Box> { + self.enable_debug_privilege().or_else(|e| { + error!("Failed to enable debug privilege, err: {e:?}"); + Err(e) + })?; + + let mut pid = 0; + for p in process_list::get_process_list()? { + if p.name.to_lowercase() == process_name.to_lowercase() { + pid = p.id; + debug!("Found PID for {process_name} -> {pid}"); + } + } + + if pid == 0 { + return Err(format!("Failed to get target PID for process: {process_name:?}").into()); + } + + + self.do_impersonate_pid(pid) + } + + pub fn revert_to_self() -> Result<(), Box> { + unsafe { + RevertToSelf()?; + Ok(()) + } + } +} + +impl Drop for Impersonate { + fn drop(&mut self) { + let _ = Self::revert_to_self(); + } +} diff --git a/crates/impersonate/src/process_list.rs b/crates/impersonate/src/process_list.rs new file mode 100644 index 0000000..ca78858 --- /dev/null +++ b/crates/impersonate/src/process_list.rs @@ -0,0 +1,212 @@ +/// Reference: https://bazizi.github.io/2022/12/29/enumerating-windows-processes-using-Rust.html + +use std::error::Error; +use std::fmt::Display; +use windows::Win32::Foundation::{CloseHandle, BOOL, WIN32_ERROR}; +use windows::Win32::Foundation::{GetLastError, MAX_PATH}; +use windows::Win32::Foundation::{HANDLE, HMODULE}; +use windows::Win32::System::ProcessStatus::EnumProcessModules; +use windows::Win32::System::ProcessStatus::EnumProcesses; +use windows::Win32::System::ProcessStatus::GetModuleBaseNameA; +use windows::Win32::System::ProcessStatus::GetModuleFileNameExA; +use windows::Win32::System::Threading::OpenProcess; +use windows::Win32::System::Threading::{PROCESS_QUERY_INFORMATION, PROCESS_VM_READ}; +use tracing::debug; +use tracing::error; + +const DEFAULT_BUFF_SIZE: usize = 1024; + +type Result = std::result::Result>; + +#[derive(Debug)] +pub struct ProcessModule { + pub name: String, + pub path: String, + pub id: u32, +} + +#[derive(Debug)] +pub struct CustomError { + pub message: String, + pub code: Option, +} + +impl Display for CustomError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + +impl Error for CustomError {} + +struct AutoProcessHandle { + handle: HANDLE, +} + +// RAI-style deallocator for the process handle +impl Drop for AutoProcessHandle { + fn drop(&mut self) { + if self.handle.is_invalid() { + return; + } + + if let Err(e) = unsafe { CloseHandle(self.handle) } { + error!("Failed to drop process handle {:?}", self.handle); + }; + } +} + +fn get_process_ids() -> Result> { + let mut process_ids = Vec::with_capacity(DEFAULT_BUFF_SIZE); + process_ids.resize(DEFAULT_BUFF_SIZE, 0); + let mut cb_needed: u32 = 0; + + match unsafe { + EnumProcesses( + process_ids.as_mut_ptr(), + process_ids.len().try_into()?, + &mut cb_needed, + ) + } { + Ok(_) => { + debug!("{} bytes is needed to store all process info", cb_needed); + } + _ => { + return Err(CustomError { + message: "EnumProcesses failed".to_owned(), + code: Some(unsafe { GetLastError() }), + } + .into()) + } + } + + if cb_needed != process_ids.len().try_into()? { + return Ok(process_ids); + } + + // The buffer isn't large enough so we need to reallocate + process_ids.resize(cb_needed as usize / std::mem::size_of::(), 0); + + if let Err(e) = unsafe { + EnumProcesses( + process_ids.as_mut_ptr(), + (process_ids.len() * std::mem::size_of::()).try_into()?, + &mut cb_needed, + ) + } { + return Err(CustomError { + message: "EnumProcesses failed".to_owned(), + code: Some(unsafe { GetLastError() }), + } + .into()) + } + + assert_ne!(cb_needed, process_ids.len().try_into()?); + + Ok(process_ids) +} + +fn get_module_handle(process_handle: HANDLE) -> Result { + let mut module_handle = HMODULE::default(); + + let mut cb_needed = 0; + if let Err(e) = unsafe { EnumProcessModules(process_handle, &mut module_handle, 0, &mut cb_needed) } { + return Err(CustomError { + message: "EnumProcessModules failed".to_owned(), + code: Some(unsafe { GetLastError() }), + } + .into()) + }; + + Ok(module_handle) +} + +fn get_process_module_info( + process_handle: HANDLE, + process_id: u32, + module_handle: HMODULE, +) -> Result> { + let mut module_path = Vec::::with_capacity(MAX_PATH.try_into()?); + module_path.resize(MAX_PATH.try_into()?, 0); + + match unsafe { + GetModuleFileNameExA( + process_handle, + module_handle, + &mut module_path, + ) + } { + 0 => { + return Ok(None); + } + _ => {} + }; + + let mut module_name = Vec::::with_capacity(MAX_PATH.try_into()?); + module_name.resize(MAX_PATH.try_into()?, 0); + + match unsafe { + GetModuleBaseNameA( + process_handle, + module_handle, + &mut module_name, + ) + } { + 0 => { + return Ok(None); + } + _ => {} + }; + + Ok(Some(ProcessModule { + name: String::from_iter( + module_name + .iter() + .take_while(|&&x| x != 0) + .map(|&x| x as char), + ), + path: String::from_iter( + module_path + .iter() + .take_while(|&&x| x != 0) + .map(|&x| x as char), + ), + id: process_id, + })) +} + +pub fn get_process_list() -> Result> { + let mut process_module_infos = Vec::new(); + + let process_ids = get_process_ids()?; + let inherit_handle = BOOL(0); + + for i in 0..process_ids.len() { + let process_handle = unsafe { + OpenProcess( + PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, + inherit_handle, + process_ids[i], + ) + }; + + match process_handle { + Ok(process_handle) => { + // RAII-style process handle + let process_handle = AutoProcessHandle { + handle: process_handle, + }; + + let module_handle = get_module_handle(process_handle.handle)?; + if let Some(process_module_info) = + get_process_module_info(process_handle.handle, process_ids[i], module_handle)? + { + process_module_infos.push(process_module_info); + } + }, + Err(_) => continue, + } + } + + Ok(process_module_infos) +} diff --git a/crates/solstice_daemon/Cargo.lock b/crates/solstice_daemon/Cargo.lock index 9d0e2e1..51a0e2f 100644 --- a/crates/solstice_daemon/Cargo.lock +++ b/crates/solstice_daemon/Cargo.lock @@ -765,6 +765,14 @@ dependencies = [ "cc", ] +[[package]] +name = "impersonate" +version = "0.1.0" +dependencies = [ + "tracing", + "windows", +] + [[package]] name = "inout" version = "0.1.3" @@ -1766,6 +1774,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-trait", + "impersonate", "pbkdf2 0.12.2", "portable-pty", "rand_core", diff --git a/crates/solstice_daemon/Cargo.toml b/crates/solstice_daemon/Cargo.toml index 5eb178d..91b1da9 100644 --- a/crates/solstice_daemon/Cargo.toml +++ b/crates/solstice_daemon/Cargo.toml @@ -29,7 +29,12 @@ windows = { version = "0.58.0", features = [ "Win32_Security", "Win32_NetworkManagement_WindowsFilteringPlatform", "Win32_System_Rpc", + + # WinRT + "Data_Xml_Dom", + "UI_Notifications", ] } +impersonate = { path = "../impersonate" } [target.'cfg(windows)'.dependencies] winreg = "0.52" diff --git a/crates/solstice_daemon/src/main.rs b/crates/solstice_daemon/src/main.rs index 6979004..d627860 100644 --- a/crates/solstice_daemon/src/main.rs +++ b/crates/solstice_daemon/src/main.rs @@ -18,9 +18,12 @@ use std::path; use tracing::debug; use tracing::error; +use impersonate::Impersonate; + mod firewall; mod sftp; mod ssh; +mod toast; // Janky hack to address https://github.com/tokio-rs/tracing/issues/1817 struct NewType(Pretty); @@ -90,6 +93,18 @@ async fn main() { } debug!("using config dir: {config_dir:?}"); + let mut impersonate = Impersonate::create(); + if let Ok(_) = impersonate.do_impersonate_process_name("XboxUI.exe") { + if let Err(e) = toast::show_toast() { + error!("Failed to show toast notification: {:?}", e); + } + if let Err(e) = Impersonate::revert_to_self() { + error!("Failed to revert impersonation: {:?}", e); + } + } else { + error!("Failed to impersonate to show toast notification"); + } + if let Err(e) = crate::ssh::start_ssh_server(SSH_LISTEN_PORT, config_dir).await { error!("{}", e); } diff --git a/crates/solstice_daemon/src/toast.rs b/crates/solstice_daemon/src/toast.rs new file mode 100644 index 0000000..ffd1a3b --- /dev/null +++ b/crates/solstice_daemon/src/toast.rs @@ -0,0 +1,55 @@ +use windows::core::HSTRING; +use windows::Data::Xml::Dom::XmlDocument; +use windows::UI; + + +pub static NOTIFIER_IDS: [&str; 19] = [ + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Collection", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.GameDVR", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Achievements", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Party", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.GameInvites", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Tournaments", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Social", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Messages", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Clubs", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Broadcasts", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.System", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.ActivityAlerts", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Tests_Legacy", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.NPS", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.ContentBlocks", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Pins", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.XboxCare", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Tests_Settings", + "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Tests", +]; + +pub fn show_toast() -> Result<(), Box> { + let id = "XboxOneSystemToasts!Windows.Xbox.SystemToasts.Achievements"; + let doc_text = +r#" + + + Collateral Damage + achieved! + SSH/SFTP Server started! + Port 22/TCP + + + + + +"#; + let encoded_text: Vec = doc_text.encode_utf16().collect(); + + let doc = XmlDocument::new()?; + doc.LoadXml(&HSTRING::from_wide(&encoded_text)?)?; + + let encoded_id: Vec = id.encode_utf16().collect(); + let notification = UI::Notifications::ToastNotification::CreateToastNotification(&doc)?; + let notifier = UI::Notifications::ToastNotificationManager::CreateToastNotifierWithId(&HSTRING::from_wide(&encoded_id)?)?; + + notifier.Show(¬ification)?; + Ok(()) +} \ No newline at end of file diff --git a/crates/solstice_daemon/src/winrt.rs b/crates/solstice_daemon/src/winrt.rs new file mode 100644 index 0000000..3372695 --- /dev/null +++ b/crates/solstice_daemon/src/winrt.rs @@ -0,0 +1,1526 @@ +// Bindings generated by `windows-bindgen` 0.58.0 + +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] +pub mod Xbox { + pub mod System { + pub mod Internal { + pub mod Power { + windows_core::imp::define_interface!( + IPowerPropertiesStatics, + IPowerPropertiesStatics_Vtbl, + 0xc434745e_17fd_4a13_94c9_997e2dd41e64 + ); + impl windows_core::RuntimeType for IPowerPropertiesStatics { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::for_interface::(); + } + #[repr(C)] + pub struct IPowerPropertiesStatics_Vtbl { + pub base__: windows_core::IInspectable_Vtbl, + pub AllowAutoSystemUpdate: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) + -> windows_core::HRESULT, + pub SetAllowAutoSystemUpdate: + unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) -> windows_core::HRESULT, + pub AllowInstantOn: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) + -> windows_core::HRESULT, + pub SetAllowInstantOn: unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) + -> windows_core::HRESULT, + pub WakeXboxOnVoice: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) + -> windows_core::HRESULT, + pub SetWakeXboxOnVoice: unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) + -> windows_core::HRESULT, + pub SystemIdleTimeout: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut u32, + ) + -> windows_core::HRESULT, + pub SetSystemIdleTimeout: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + ) + -> windows_core::HRESULT, + pub ShutDownConsole: + unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + pub SleepConsole: + unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + pub RestartConsole: + unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + pub FastGameResume: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) + -> windows_core::HRESULT, + pub SetFastGameResume: unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) + -> windows_core::HRESULT, + pub ExternalStorageSelectiveSuspend: + unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) -> windows_core::HRESULT, + pub SetExternalStorageSelectiveSuspend: + unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) -> windows_core::HRESULT, + pub InstantOnTitleID: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut u32, + ) + -> windows_core::HRESULT, + pub SetInstantOnTitleID: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + ) + -> windows_core::HRESULT, + pub PowerChime: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut PowerChimeMode, + ) + -> windows_core::HRESULT, + pub SetPowerChime: unsafe extern "system" fn( + *mut core::ffi::c_void, + PowerChimeMode, + ) + -> windows_core::HRESULT, + pub AllowAutoContentUpdates: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) + -> windows_core::HRESULT, + pub SetAllowAutoContentUpdates: + unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) -> windows_core::HRESULT, + pub PromptEnableAutoUpdates: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) + -> windows_core::HRESULT, + pub SetPromptEnableAutoUpdates: + unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) -> windows_core::HRESULT, + pub Allow4KAssetDownloads: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) + -> windows_core::HRESULT, + pub SetAllow4KAssetDownloads: + unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) -> windows_core::HRESULT, + pub AllowRemoteInstall: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) + -> windows_core::HRESULT, + pub SetAllowRemoteInstall: unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) + -> windows_core::HRESULT, + pub AllowRemoteManagement: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) + -> windows_core::HRESULT, + pub SetAllowRemoteManagement: + unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) -> windows_core::HRESULT, + pub NotifyHomeReady: + unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + pub SystemForceIdleTimeout: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut u32, + ) + -> windows_core::HRESULT, + pub SetSystemForceIdleTimeout: + unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + ) -> windows_core::HRESULT, + pub DisableBootAnimationAudio: + unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) -> windows_core::HRESULT, + pub SetDisableBootAnimationAudio: + unsafe extern "system" fn( + *mut core::ffi::c_void, + bool, + ) -> windows_core::HRESULT, + pub CarbonAwareRsPlus: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut bool, + ) + -> windows_core::HRESULT, + pub ActiveHourMode: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut AdjustedActiveHourMode, + ) + -> windows_core::HRESULT, + pub SetActiveHourMode: unsafe extern "system" fn( + *mut core::ffi::c_void, + AdjustedActiveHourMode, + ) + -> windows_core::HRESULT, + pub ActiveHourStart: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut u32, + ) + -> windows_core::HRESULT, + pub SetActiveHourStart: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + ) + -> windows_core::HRESULT, + pub ActiveHourEnd: unsafe extern "system" fn( + *mut core::ffi::c_void, + *mut u32, + ) + -> windows_core::HRESULT, + pub SetActiveHourEnd: unsafe extern "system" fn( + *mut core::ffi::c_void, + u32, + ) + -> windows_core::HRESULT, + pub StartGipEnrollMode: + unsafe extern "system" fn(*mut core::ffi::c_void) -> windows_core::HRESULT, + } + pub struct PowerProperties; + impl PowerProperties { + pub fn AllowAutoSystemUpdate() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).AllowAutoSystemUpdate)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetAllowAutoSystemUpdate(value: bool) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetAllowAutoSystemUpdate)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn AllowInstantOn() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).AllowInstantOn)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetAllowInstantOn(value: bool) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetAllowInstantOn)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn WakeXboxOnVoice() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).WakeXboxOnVoice)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetWakeXboxOnVoice(value: bool) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetWakeXboxOnVoice)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn SystemIdleTimeout() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).SystemIdleTimeout)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetSystemIdleTimeout(value: u32) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetSystemIdleTimeout)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn ShutDownConsole() -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).ShutDownConsole)( + windows_core::Interface::as_raw(this), + ) + .ok() + }) + } + pub fn SleepConsole() -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SleepConsole)( + windows_core::Interface::as_raw(this), + ) + .ok() + }) + } + pub fn RestartConsole() -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).RestartConsole)( + windows_core::Interface::as_raw(this), + ) + .ok() + }) + } + pub fn FastGameResume() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).FastGameResume)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetFastGameResume(value: bool) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetFastGameResume)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn ExternalStorageSelectiveSuspend() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ExternalStorageSelectiveSuspend)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetExternalStorageSelectiveSuspend( + value: bool, + ) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this) + .SetExternalStorageSelectiveSuspend)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn InstantOnTitleID() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).InstantOnTitleID)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetInstantOnTitleID(value: u32) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetInstantOnTitleID)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn PowerChime() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).PowerChime)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetPowerChime(value: PowerChimeMode) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetPowerChime)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn AllowAutoContentUpdates() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).AllowAutoContentUpdates)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetAllowAutoContentUpdates(value: bool) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetAllowAutoContentUpdates)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn PromptEnableAutoUpdates() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).PromptEnableAutoUpdates)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetPromptEnableAutoUpdates(value: bool) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetPromptEnableAutoUpdates)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn Allow4KAssetDownloads() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).Allow4KAssetDownloads)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetAllow4KAssetDownloads(value: bool) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetAllow4KAssetDownloads)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn AllowRemoteInstall() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).AllowRemoteInstall)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetAllowRemoteInstall(value: bool) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetAllowRemoteInstall)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn AllowRemoteManagement() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).AllowRemoteManagement)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetAllowRemoteManagement(value: bool) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetAllowRemoteManagement)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn NotifyHomeReady() -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).NotifyHomeReady)( + windows_core::Interface::as_raw(this), + ) + .ok() + }) + } + pub fn SystemForceIdleTimeout() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).SystemForceIdleTimeout)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetSystemForceIdleTimeout(value: u32) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetSystemForceIdleTimeout)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn DisableBootAnimationAudio() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).DisableBootAnimationAudio)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetDisableBootAnimationAudio(value: bool) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetDisableBootAnimationAudio)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn CarbonAwareRsPlus() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).CarbonAwareRsPlus)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn ActiveHourMode() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ActiveHourMode)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetActiveHourMode( + value: AdjustedActiveHourMode, + ) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetActiveHourMode)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn ActiveHourStart() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ActiveHourStart)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetActiveHourStart(value: u32) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetActiveHourStart)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn ActiveHourEnd() -> windows_core::Result { + Self::IPowerPropertiesStatics(|this| unsafe { + let mut result__ = core::mem::zeroed(); + (windows_core::Interface::vtable(this).ActiveHourEnd)( + windows_core::Interface::as_raw(this), + &mut result__, + ) + .map(|| result__) + }) + } + pub fn SetActiveHourEnd(value: u32) -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).SetActiveHourEnd)( + windows_core::Interface::as_raw(this), + value, + ) + .ok() + }) + } + pub fn StartGipEnrollMode() -> windows_core::Result<()> { + Self::IPowerPropertiesStatics(|this| unsafe { + (windows_core::Interface::vtable(this).StartGipEnrollMode)( + windows_core::Interface::as_raw(this), + ) + .ok() + }) + } + #[doc(hidden)] + pub fn IPowerPropertiesStatics< + R, + F: FnOnce(&IPowerPropertiesStatics) -> windows_core::Result, + >( + callback: F, + ) -> windows_core::Result { + static SHARED: windows_core::imp::FactoryCache< + PowerProperties, + IPowerPropertiesStatics, + > = windows_core::imp::FactoryCache::new(); + SHARED.call(callback) + } + } + impl windows_core::RuntimeName for PowerProperties { + const NAME: &'static str = "Windows.Xbox.System.Internal.Power.PowerProperties"; + } + #[repr(transparent)] + #[derive(PartialEq, Eq, Copy, Clone, Default)] + pub struct AdjustedActiveHourMode(pub i32); + impl AdjustedActiveHourMode { + pub const Automatic: Self = Self(0i32); + pub const Manual: Self = Self(1i32); + pub const AlwaysActive: Self = Self(2i32); + } + impl windows_core::TypeKind for AdjustedActiveHourMode { + type TypeKind = windows_core::CopyType; + } + impl core::fmt::Debug for AdjustedActiveHourMode { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_tuple("AdjustedActiveHourMode") + .field(&self.0) + .finish() + } + } + impl windows_core::RuntimeType for AdjustedActiveHourMode { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::from_slice( + b"enum(Windows.Xbox.System.Internal.Power.AdjustedActiveHourMode;i4)", + ); + } + #[repr(transparent)] + #[derive(PartialEq, Eq, Copy, Clone, Default)] + pub struct PowerChimeMode(pub i32); + impl PowerChimeMode { + pub const On: Self = Self(0i32); + pub const OnlyPowerButtonAndVoice: Self = Self(1i32); + pub const Off: Self = Self(2i32); + } + impl windows_core::TypeKind for PowerChimeMode { + type TypeKind = windows_core::CopyType; + } + impl core::fmt::Debug for PowerChimeMode { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_tuple("PowerChimeMode").field(&self.0).finish() + } + } + impl windows_core::RuntimeType for PowerChimeMode { + const SIGNATURE: windows_core::imp::ConstBuffer = + windows_core::imp::ConstBuffer::from_slice( + b"enum(Windows.Xbox.System.Internal.Power.PowerChimeMode;i4)", + ); + } + pub trait IPowerPropertiesStatics_Impl: Sized { + fn AllowAutoSystemUpdate(&self) -> windows_core::Result; + fn SetAllowAutoSystemUpdate(&self, value: bool) -> windows_core::Result<()>; + fn AllowInstantOn(&self) -> windows_core::Result; + fn SetAllowInstantOn(&self, value: bool) -> windows_core::Result<()>; + fn WakeXboxOnVoice(&self) -> windows_core::Result; + fn SetWakeXboxOnVoice(&self, value: bool) -> windows_core::Result<()>; + fn SystemIdleTimeout(&self) -> windows_core::Result; + fn SetSystemIdleTimeout(&self, value: u32) -> windows_core::Result<()>; + fn ShutDownConsole(&self) -> windows_core::Result<()>; + fn SleepConsole(&self) -> windows_core::Result<()>; + fn RestartConsole(&self) -> windows_core::Result<()>; + fn FastGameResume(&self) -> windows_core::Result; + fn SetFastGameResume(&self, value: bool) -> windows_core::Result<()>; + fn ExternalStorageSelectiveSuspend(&self) -> windows_core::Result; + fn SetExternalStorageSelectiveSuspend( + &self, + value: bool, + ) -> windows_core::Result<()>; + fn InstantOnTitleID(&self) -> windows_core::Result; + fn SetInstantOnTitleID(&self, value: u32) -> windows_core::Result<()>; + fn PowerChime(&self) -> windows_core::Result; + fn SetPowerChime(&self, value: PowerChimeMode) -> windows_core::Result<()>; + fn AllowAutoContentUpdates(&self) -> windows_core::Result; + fn SetAllowAutoContentUpdates(&self, value: bool) -> windows_core::Result<()>; + fn PromptEnableAutoUpdates(&self) -> windows_core::Result; + fn SetPromptEnableAutoUpdates(&self, value: bool) -> windows_core::Result<()>; + fn Allow4KAssetDownloads(&self) -> windows_core::Result; + fn SetAllow4KAssetDownloads(&self, value: bool) -> windows_core::Result<()>; + fn AllowRemoteInstall(&self) -> windows_core::Result; + fn SetAllowRemoteInstall(&self, value: bool) -> windows_core::Result<()>; + fn AllowRemoteManagement(&self) -> windows_core::Result; + fn SetAllowRemoteManagement(&self, value: bool) -> windows_core::Result<()>; + fn NotifyHomeReady(&self) -> windows_core::Result<()>; + fn SystemForceIdleTimeout(&self) -> windows_core::Result; + fn SetSystemForceIdleTimeout(&self, value: u32) -> windows_core::Result<()>; + fn DisableBootAnimationAudio(&self) -> windows_core::Result; + fn SetDisableBootAnimationAudio(&self, value: bool) + -> windows_core::Result<()>; + fn CarbonAwareRsPlus(&self) -> windows_core::Result; + fn ActiveHourMode(&self) -> windows_core::Result; + fn SetActiveHourMode( + &self, + value: AdjustedActiveHourMode, + ) -> windows_core::Result<()>; + fn ActiveHourStart(&self) -> windows_core::Result; + fn SetActiveHourStart(&self, value: u32) -> windows_core::Result<()>; + fn ActiveHourEnd(&self) -> windows_core::Result; + fn SetActiveHourEnd(&self, value: u32) -> windows_core::Result<()>; + fn StartGipEnrollMode(&self) -> windows_core::Result<()>; + } + impl windows_core::RuntimeName for IPowerPropertiesStatics { + const NAME: &'static str = + "Windows.Xbox.System.Internal.Power.IPowerPropertiesStatics"; + } + impl IPowerPropertiesStatics_Vtbl { + pub const fn new( + ) -> IPowerPropertiesStatics_Vtbl + where + Identity: IPowerPropertiesStatics_Impl, + { + unsafe extern "system" fn AllowAutoSystemUpdate< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::AllowAutoSystemUpdate(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetAllowAutoSystemUpdate< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetAllowAutoSystemUpdate(this, value) + .into() + } + unsafe extern "system" fn AllowInstantOn< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::AllowInstantOn(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetAllowInstantOn< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetAllowInstantOn(this, value).into() + } + unsafe extern "system" fn WakeXboxOnVoice< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::WakeXboxOnVoice(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetWakeXboxOnVoice< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetWakeXboxOnVoice(this, value).into() + } + unsafe extern "system" fn SystemIdleTimeout< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut u32, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::SystemIdleTimeout(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetSystemIdleTimeout< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: u32, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetSystemIdleTimeout(this, value).into() + } + unsafe extern "system" fn ShutDownConsole< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::ShutDownConsole(this).into() + } + unsafe extern "system" fn SleepConsole< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SleepConsole(this).into() + } + unsafe extern "system" fn RestartConsole< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::RestartConsole(this).into() + } + unsafe extern "system" fn FastGameResume< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::FastGameResume(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetFastGameResume< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetFastGameResume(this, value).into() + } + unsafe extern "system" fn ExternalStorageSelectiveSuspend< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::ExternalStorageSelectiveSuspend( + this, + ) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetExternalStorageSelectiveSuspend< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetExternalStorageSelectiveSuspend( + this, value, + ) + .into() + } + unsafe extern "system" fn InstantOnTitleID< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut u32, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::InstantOnTitleID(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetInstantOnTitleID< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: u32, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetInstantOnTitleID(this, value).into() + } + unsafe extern "system" fn PowerChime< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut PowerChimeMode, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::PowerChime(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetPowerChime< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: PowerChimeMode, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetPowerChime(this, value).into() + } + unsafe extern "system" fn AllowAutoContentUpdates< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::AllowAutoContentUpdates(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetAllowAutoContentUpdates< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetAllowAutoContentUpdates(this, value) + .into() + } + unsafe extern "system" fn PromptEnableAutoUpdates< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::PromptEnableAutoUpdates(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetPromptEnableAutoUpdates< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetPromptEnableAutoUpdates(this, value) + .into() + } + unsafe extern "system" fn Allow4KAssetDownloads< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::Allow4KAssetDownloads(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetAllow4KAssetDownloads< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetAllow4KAssetDownloads(this, value) + .into() + } + unsafe extern "system" fn AllowRemoteInstall< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::AllowRemoteInstall(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetAllowRemoteInstall< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetAllowRemoteInstall(this, value).into() + } + unsafe extern "system" fn AllowRemoteManagement< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::AllowRemoteManagement(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetAllowRemoteManagement< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetAllowRemoteManagement(this, value) + .into() + } + unsafe extern "system" fn NotifyHomeReady< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::NotifyHomeReady(this).into() + } + unsafe extern "system" fn SystemForceIdleTimeout< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut u32, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::SystemForceIdleTimeout(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetSystemForceIdleTimeout< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: u32, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetSystemForceIdleTimeout(this, value) + .into() + } + unsafe extern "system" fn DisableBootAnimationAudio< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::DisableBootAnimationAudio(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetDisableBootAnimationAudio< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetDisableBootAnimationAudio(this, value) + .into() + } + unsafe extern "system" fn CarbonAwareRsPlus< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut bool, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::CarbonAwareRsPlus(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn ActiveHourMode< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut AdjustedActiveHourMode, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::ActiveHourMode(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetActiveHourMode< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: AdjustedActiveHourMode, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetActiveHourMode(this, value).into() + } + unsafe extern "system" fn ActiveHourStart< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut u32, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::ActiveHourStart(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetActiveHourStart< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: u32, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetActiveHourStart(this, value).into() + } + unsafe extern "system" fn ActiveHourEnd< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + result__: *mut u32, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + match IPowerPropertiesStatics_Impl::ActiveHourEnd(this) { + Ok(ok__) => { + result__.write(core::mem::transmute_copy(&ok__)); + windows_core::HRESULT(0) + } + Err(err) => err.into(), + } + } + unsafe extern "system" fn SetActiveHourEnd< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + value: u32, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::SetActiveHourEnd(this, value).into() + } + unsafe extern "system" fn StartGipEnrollMode< + Identity: windows_core::IUnknownImpl, + const OFFSET: isize, + >( + this: *mut core::ffi::c_void, + ) -> windows_core::HRESULT + where + Identity: IPowerPropertiesStatics_Impl, + { + let this: &Identity = + &*((this as *const *const ()).offset(OFFSET) as *const Identity); + IPowerPropertiesStatics_Impl::StartGipEnrollMode(this).into() + } + Self { + base__: windows_core::IInspectable_Vtbl::new::< + Identity, + IPowerPropertiesStatics, + OFFSET, + >(), + AllowAutoSystemUpdate: AllowAutoSystemUpdate::, + SetAllowAutoSystemUpdate: SetAllowAutoSystemUpdate::, + AllowInstantOn: AllowInstantOn::, + SetAllowInstantOn: SetAllowInstantOn::, + WakeXboxOnVoice: WakeXboxOnVoice::, + SetWakeXboxOnVoice: SetWakeXboxOnVoice::, + SystemIdleTimeout: SystemIdleTimeout::, + SetSystemIdleTimeout: SetSystemIdleTimeout::, + ShutDownConsole: ShutDownConsole::, + SleepConsole: SleepConsole::, + RestartConsole: RestartConsole::, + FastGameResume: FastGameResume::, + SetFastGameResume: SetFastGameResume::, + ExternalStorageSelectiveSuspend: ExternalStorageSelectiveSuspend::< + Identity, + OFFSET, + >, + SetExternalStorageSelectiveSuspend: SetExternalStorageSelectiveSuspend::< + Identity, + OFFSET, + >, + InstantOnTitleID: InstantOnTitleID::, + SetInstantOnTitleID: SetInstantOnTitleID::, + PowerChime: PowerChime::, + SetPowerChime: SetPowerChime::, + AllowAutoContentUpdates: AllowAutoContentUpdates::, + SetAllowAutoContentUpdates: SetAllowAutoContentUpdates::< + Identity, + OFFSET, + >, + PromptEnableAutoUpdates: PromptEnableAutoUpdates::, + SetPromptEnableAutoUpdates: SetPromptEnableAutoUpdates::< + Identity, + OFFSET, + >, + Allow4KAssetDownloads: Allow4KAssetDownloads::, + SetAllow4KAssetDownloads: SetAllow4KAssetDownloads::, + AllowRemoteInstall: AllowRemoteInstall::, + SetAllowRemoteInstall: SetAllowRemoteInstall::, + AllowRemoteManagement: AllowRemoteManagement::, + SetAllowRemoteManagement: SetAllowRemoteManagement::, + NotifyHomeReady: NotifyHomeReady::, + SystemForceIdleTimeout: SystemForceIdleTimeout::, + SetSystemForceIdleTimeout: SetSystemForceIdleTimeout::, + DisableBootAnimationAudio: DisableBootAnimationAudio::, + SetDisableBootAnimationAudio: SetDisableBootAnimationAudio::< + Identity, + OFFSET, + >, + CarbonAwareRsPlus: CarbonAwareRsPlus::, + ActiveHourMode: ActiveHourMode::, + SetActiveHourMode: SetActiveHourMode::, + ActiveHourStart: ActiveHourStart::, + SetActiveHourStart: SetActiveHourStart::, + ActiveHourEnd: ActiveHourEnd::, + SetActiveHourEnd: SetActiveHourEnd::, + StartGipEnrollMode: StartGipEnrollMode::, + } + } + pub fn matches(iid: &windows_core::GUID) -> bool { + iid == &::IID + } + } + } + } + } +} From 6a11ca7c500606b8399dca69cb2dee7d4d31195a Mon Sep 17 00:00:00 2001 From: tuxuser <462620+tuxuser@users.noreply.github.com> Date: Fri, 23 Aug 2024 07:02:39 +0200 Subject: [PATCH 2/3] feat(ci): Add impersonate crate to be build --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6f56dd3..19c2c3b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - component: [shellcode_utils, solstice_loader, shellcode_stage1, shellcode_stage1_network, shellcode_stage2, shellcode_gen, solstice_daemon, payload_server] + component: [shellcode_utils, impersonate, solstice_loader, shellcode_stage1, shellcode_stage1_network, shellcode_stage2, shellcode_gen, solstice_daemon, payload_server] include: - component: solstice_daemon features: firewall From 6d3736318905ccc34591d4af57322151c0dd5307 Mon Sep 17 00:00:00 2001 From: tuxuser <462620+tuxuser@users.noreply.github.com> Date: Sun, 8 Sep 2024 23:10:26 +0200 Subject: [PATCH 3/3] fix(daemon): Clearer error handling --- crates/impersonate/src/lib.rs | 8 +++++++- crates/solstice_daemon/src/main.rs | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/crates/impersonate/src/lib.rs b/crates/impersonate/src/lib.rs index 5cd2a79..89cabe4 100644 --- a/crates/impersonate/src/lib.rs +++ b/crates/impersonate/src/lib.rs @@ -104,6 +104,10 @@ impl Impersonate { PrivilegeCheck(self.original_token, &mut priv_set, &mut priv_enabled)?; debug!("SeDebugPrivilege is: {:?}", priv_enabled); + + if priv_enabled.0 == 0 { + return Err("Failed to set enable debug privilege".into()); + } } Ok(()) @@ -113,7 +117,9 @@ impl Impersonate { unsafe { let proc_handle = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, pid)?; let new_token = Impersonate::get_impersonation_token(proc_handle)?; - SetThreadToken(None, new_token)?; + if let Err(e) = SetThreadToken(None, new_token) { + return Err("Failed to set thread token, err: {e:?}".into()); + } } Ok(()) } diff --git a/crates/solstice_daemon/src/main.rs b/crates/solstice_daemon/src/main.rs index d627860..a70ebb1 100644 --- a/crates/solstice_daemon/src/main.rs +++ b/crates/solstice_daemon/src/main.rs @@ -94,15 +94,18 @@ async fn main() { debug!("using config dir: {config_dir:?}"); let mut impersonate = Impersonate::create(); - if let Ok(_) = impersonate.do_impersonate_process_name("XboxUI.exe") { - if let Err(e) = toast::show_toast() { - error!("Failed to show toast notification: {:?}", e); + match impersonate.do_impersonate_process_name("XboxUI.exe") { + Ok(_) => { + if let Err(e) = toast::show_toast() { + error!("Failed to show toast notification: {:?}", e); + } + if let Err(e) = Impersonate::revert_to_self() { + error!("Failed to revert impersonation: {:?}", e); + } + }, + Err(e) => { + error!("Failed to impersonate to show toast notification, err={e:?}"); } - if let Err(e) = Impersonate::revert_to_self() { - error!("Failed to revert impersonation: {:?}", e); - } - } else { - error!("Failed to impersonate to show toast notification"); } if let Err(e) = crate::ssh::start_ssh_server(SSH_LISTEN_PORT, config_dir).await {