Skip to content

Commit 4c1d00a

Browse files
committed
try to set variable from windows
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 4851feb commit 4c1d00a

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

framework_lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ features = [
7373
"Win32_System_Ioctl",
7474
"Win32_System_SystemInformation",
7575
"Win32_System_SystemServices",
76+
"Win32_System_WindowsProgramming",
7677
# For HID devices
7778
"Win32_Devices_DeviceAndDriverInstallation",
7879
"Win32_Devices_HumanInterfaceDevice",

framework_lib/src/os_specific.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub fn get_os_version() -> String {
3737
}
3838
}
3939

40+
#[cfg(windows)]
41+
use windows::{core::*, Win32::System::WindowsProgramming::*};
42+
4043
/// Sleep a number of microseconds
4144
pub fn sleep(micros: u64) {
4245
let duration = Duration::from_micros(micros);
@@ -51,3 +54,24 @@ pub fn sleep(micros: u64) {
5154
uefi::boot::stall(duration);
5255
}
5356
}
57+
58+
#[cfg(windows)]
59+
pub fn set_dbx() -> Option<()> {
60+
set_uefi_var("dbx", "d719b2cb-3d3a-4596-a3bc-dad00e67656f", &[], 0)
61+
}
62+
63+
#[cfg(windows)]
64+
pub fn set_uefi_var(name: &str, guid: &str, value: &[u8], attributes: u32) -> Option<()> {
65+
unsafe {
66+
SetFirmwareEnvironmentVariableExW(
67+
// PCWSTR
68+
&HSTRING::from(name),
69+
// PCWSTR
70+
&HSTRING::from(guid),
71+
Some(value.as_ptr() as *const core::ffi::c_void),
72+
value.len() as u32,
73+
attributes,
74+
)
75+
.ok()
76+
}
77+
}

0 commit comments

Comments
 (0)