-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
mod boot; | ||
mod delete; | ||
mod dump; | ||
mod import; | ||
mod list; | ||
mod read; | ||
|
||
pub use self::boot::get_entries as get_boot_entries; | ||
pub use self::boot::get_order as get_boot_order; | ||
pub use self::delete::run as delete; | ||
pub use self::dump::run as dump; | ||
pub use self::import::run as import; | ||
pub use self::list::run as list; | ||
pub use self::read::run as read; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::{fs::File, io::Write, path::Path}; | ||
|
||
use uuid::Uuid; | ||
|
||
use efivar::{ | ||
efi::{VariableFlags, VariableName, VariableVendor}, | ||
VarManager, | ||
}; | ||
|
||
fn dump(output_path: &Path, flags: VariableFlags, data: &[u8]) -> Result<(), std::io::Error> { | ||
let mut file = File::create(output_path)?; | ||
file.write_all(&flags.bits().to_le_bytes())?; | ||
file.write_all(data)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn run(reader: Box<dyn VarManager>, name: &str, namespace: Option<Uuid>, output_path: &Path) { | ||
let var = VariableName::new_with_vendor( | ||
name, | ||
namespace.map_or(VariableVendor::Efi, VariableVendor::Custom), | ||
); | ||
|
||
let mut buf = vec![0u8; 512]; | ||
match reader.read(&var, &mut buf) { | ||
Ok((size, flags)) => { | ||
buf.resize(size, 0); | ||
match dump(output_path, flags, &buf) { | ||
Ok(_) => println!( | ||
"Dumped variable {} to file {}", | ||
var, | ||
output_path.canonicalize().unwrap().display() | ||
), | ||
Err(err) => eprintln!("Failed to write to file: {}", err), | ||
} | ||
} | ||
Err(err) => eprintln!("Failed to read variable: {}", err), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::{fs::File, io::Read, path::Path}; | ||
|
||
use uuid::Uuid; | ||
|
||
use byteorder::{LittleEndian, ReadBytesExt}; | ||
|
||
use efivar::{ | ||
efi::{VariableFlags, VariableName, VariableVendor}, | ||
VarManager, | ||
}; | ||
|
||
fn read_var_from_file(input_path: &Path) -> Result<(VariableFlags, Vec<u8>), std::io::Error> { | ||
let mut file = File::open(input_path)?; | ||
|
||
let flags = VariableFlags::from_bits(file.read_u32::<LittleEndian>()?).unwrap(); | ||
let mut data = Vec::new(); | ||
file.read_to_end(&mut data)?; | ||
|
||
Ok((flags, data)) | ||
} | ||
|
||
pub fn run( | ||
mut manager: Box<dyn VarManager>, | ||
input_path: &Path, | ||
name: &str, | ||
namespace: Option<Uuid>, | ||
) { | ||
let var = VariableName::new_with_vendor( | ||
name, | ||
namespace.map_or(VariableVendor::Efi, VariableVendor::Custom), | ||
); | ||
|
||
let (flags, data) = match read_var_from_file(input_path) { | ||
Ok(inner) => inner, | ||
Err(err) => { | ||
eprintln!( | ||
"Failed to read variable from file {}: {}", | ||
input_path.display(), | ||
err | ||
); | ||
return; | ||
} | ||
}; | ||
|
||
match manager.write(&var, flags, &data) { | ||
Ok(()) => println!("Imported variable {} with success", var), | ||
Err(err) => eprintln!("Failed to write variable {}: {}", var, err), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters