@@ -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
4444pub 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) ]
7686pub 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