Skip to content

Commit 3b03ba0

Browse files
committed
wip: Also read uefi variable
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 52494a1 commit 3b03ba0

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

framework_lib/src/commandline/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
15271527
println!("File");
15281528
println!(" Size: {:>20} B", data.len());
15291529
println!(" Size: {:>20} KB", data.len() / 1024);
1530-
os_specific::set_dbx(&data);
1530+
os_specific::get_dbx();
1531+
//os_specific::set_dbx(&data);
15311532
}
15321533
} else if args.test {
15331534
println!("Self-Test");

framework_lib/src/os_specific.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn get_os_version() -> String {
3838
}
3939

4040
#[cfg(windows)]
41-
use windows::{core::*, Win32::System::WindowsProgramming::*};
41+
use windows::{core::*, Win32::Foundation::*, Win32::System::WindowsProgramming::*};
4242

4343
/// Sleep a number of microseconds
4444
pub fn sleep(micros: u64) {
@@ -72,6 +72,16 @@ pub fn set_dbx(data: &[u8]) -> Option<()> {
7272
set_uefi_var("dbx", "d719b2cb-3d3a-4596-a3bc-dad00e67656f", data, attrs)
7373
}
7474

75+
#[cfg(windows)]
76+
pub fn get_dbx() -> Option<Vec<u8>> {
77+
get_uefi_var(w!("dbx"), w!("d719b2cb-3d3a-4596-a3bc-dad00e67656f"))
78+
}
79+
#[cfg(not(windows))]
80+
pub fn get_dbx() -> Option<Vec<u8>> {
81+
error!("Getting UEFI variable not supported on this OS");
82+
None
83+
}
84+
7585
#[cfg(windows)]
7686
pub fn set_uefi_var(name: &str, guid: &str, value: &[u8], attributes: u32) -> Option<()> {
7787
let res = unsafe {
@@ -94,3 +104,37 @@ pub fn set_uefi_var(name: &str, guid: &str, value: &[u8], attributes: u32) -> Op
94104
error!("Setting UEFI variable not supported on this OS");
95105
None
96106
}
107+
108+
#[cfg(windows)]
109+
pub fn get_uefi_var(name: PCWSTR, guid: PCWSTR) -> Option<Vec<u8>> {
110+
let mut data = [0; 1024];
111+
let mut attributes: u32 = 0;
112+
let (res, error) = unsafe {
113+
let res = GetFirmwareEnvironmentVariableExW(
114+
// PCWSTR
115+
//&HSTRING::from(name),
116+
name,
117+
// PCWSTR
118+
//&HSTRING::from(guid),
119+
guid,
120+
Some(data.as_mut_ptr() as *mut core::ffi::c_void),
121+
data.len() as u32,
122+
Some(&mut attributes),
123+
);
124+
let error = GetLastError();
125+
(res, error)
126+
};
127+
128+
//let data = std::slice::from_raw_parts::<u8>(credentials_ptr as _, count as usize);
129+
130+
println!("Res: {:?}", res);
131+
println!("LastError: {:?}", error);
132+
println!("Data: {:X?}", data);
133+
Some(vec![])
134+
}
135+
136+
#[cfg(not(windows))]
137+
pub fn get_uefi_var(name: &str, guid: &str, value: &[u8], attributes: u32) -> Option<Vec<u8>> {
138+
error!("Getting UEFI variable not supported on this OS");
139+
None
140+
}

0 commit comments

Comments
 (0)