Skip to content

Commit

Permalink
binary rpath improvement wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Aug 21, 2023
1 parent 0730787 commit 97fa33f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions common/bin/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::{BinaryInfo, LibraryInfo};
impl BinaryInfo {
pub fn find_library(&self, name: &str) -> Option<LibraryInfo> {
for rpath in &self.rpath {
let path = Path::new(rpath).join(name);
let path =
Path::new(&rpath.replace("$ORIGIN", &self.dir.as_ref().unwrap().to_string_lossy()))
.join(name);
if let Ok(f) = File::open(&path) {
return LibraryInfo::parse(f, false, path.file_name().unwrap().to_string_lossy())
.map_err(|e| {
Expand All @@ -24,10 +26,11 @@ impl BinaryInfo {
return None;
}

pub fn parse<S, N>(source: S, name: N) -> Result<Self, elf::ParseError>
pub fn parse<S, N, D>(source: S, name: N, dir: Option<D>) -> Result<Self, elf::ParseError>
where
S: std::io::Read + std::io::Seek,
N: AsRef<str>,
D: AsRef<Path>,
{
let mut rpath = Vec::<String>::new();
let mut needed = Vec::<String>::new();
Expand Down Expand Up @@ -89,6 +92,7 @@ impl BinaryInfo {

return Ok(Self {
name: String::from(name.as_ref()),
dir: dir.map(|d| d.as_ref().to_path_buf()),
rpath,
needed,
undefined,
Expand All @@ -106,7 +110,7 @@ mod tests {
fn test_parse() {
let mut content = Cursor::new(include_bytes!("fixtures/sample.bin"));
let info =
BinaryInfo::parse(&mut content, "sample.bin").expect("should not have any error");
BinaryInfo::parse(&mut content, "sample.bin", None).expect("should not have any error");
assert_eq!(info.needed[0], "libc.so.6");
}
}
2 changes: 2 additions & 0 deletions common/bin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::PathBuf;
use serde::{Deserialize, Serialize};

pub mod binary;
Expand All @@ -6,6 +7,7 @@ pub mod library;
#[derive(Debug, Serialize, Deserialize)]
pub struct BinaryInfo {
pub name: String,
pub dir: Option<PathBuf>,
pub rpath: Vec<String>,
pub needed: Vec<String>,
pub undefined: Vec<String>,
Expand Down
2 changes: 2 additions & 0 deletions common/ipk/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl Component<AppInfo> {
)
})?,
exe_path.file_name().unwrap().to_string_lossy(),
exe_path.parent()
)
.map_err(|e| {
Error::new(
Expand Down Expand Up @@ -96,6 +97,7 @@ impl Component<ServiceInfo> {
BinaryInfo::parse(
File::open(dir.join(&exe_path))?,
exe_path.file_name().unwrap().to_string_lossy(),
exe_path.parent()
)
.map_err(|e| {
Error::new(
Expand Down
1 change: 1 addition & 0 deletions common/verify/src/ipk/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl<T> VerifyWithFirmware<ComponentVerifyResult> for Component<T> {
let verify_result = self.verify_bin(
&BinaryInfo {
name: lib.name.clone(),
dir: Default::default(),
rpath: Default::default(),
needed: lib.needed.clone(),
undefined: lib.undefined.clone(),
Expand Down

0 comments on commit 97fa33f

Please sign in to comment.