lanzatool: remove Path -> String conversion from pe module
... by using OsString, which can handle broken UTF-8 in file names.
This commit is contained in:
parent
3fdf25a5a8
commit
74afcb1eea
|
@ -1,3 +1,4 @@
|
||||||
|
use std::ffi::OsString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
@ -8,8 +9,6 @@ use std::process::Command;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use goblin::pe::PE;
|
use goblin::pe::PE;
|
||||||
|
|
||||||
use crate::utils;
|
|
||||||
|
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
/// Attach all information that lanzaboote needs into the PE binary.
|
/// Attach all information that lanzaboote needs into the PE binary.
|
||||||
|
@ -94,12 +93,11 @@ fn wrap_in_pe(
|
||||||
.open(&image_path)
|
.open(&image_path)
|
||||||
.context("Failed to generate named temp file")?;
|
.context("Failed to generate named temp file")?;
|
||||||
|
|
||||||
let mut args: Vec<String> = sections.iter().flat_map(Section::to_objcopy).collect();
|
let mut args: Vec<OsString> = sections.iter().flat_map(Section::to_objcopy).collect();
|
||||||
let extra_args = vec![
|
|
||||||
utils::path_to_string(stub),
|
[stub.as_os_str(), image_path.as_os_str()]
|
||||||
utils::path_to_string(&image_path),
|
.iter()
|
||||||
];
|
.for_each(|a| args.push(a.into()));
|
||||||
args.extend(extra_args);
|
|
||||||
|
|
||||||
let status = Command::new("objcopy")
|
let status = Command::new("objcopy")
|
||||||
.args(&args)
|
.args(&args)
|
||||||
|
@ -122,12 +120,19 @@ struct Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Section {
|
impl Section {
|
||||||
fn to_objcopy(&self) -> Vec<String> {
|
/// Create objcopy `-add-section` command line parameters that
|
||||||
|
/// attach the section to a PE file.
|
||||||
|
fn to_objcopy(&self) -> Vec<OsString> {
|
||||||
|
// There is unfortunately no format! for OsString, so we cannot
|
||||||
|
// just format a path.
|
||||||
|
let mut map_str: OsString = format!("{}=", self.name).into();
|
||||||
|
map_str.push(&self.file_path);
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
String::from("--add-section"),
|
OsString::from("--add-section"),
|
||||||
format!("{}={}", self.name, utils::path_to_string(&self.file_path)),
|
map_str,
|
||||||
String::from("--change-section-vma"),
|
OsString::from("--change-section-vma"),
|
||||||
format!("{}={:#x}", self.name, self.offset),
|
format!("{}={:#x}", self.name, self.offset).into(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue