|
|
|
@ -6,7 +6,7 @@ use std::hash::Hash; |
|
|
|
|
use std::io::{BufReader, BufRead, Error, ErrorKind}; |
|
|
|
|
use std::os::unix; |
|
|
|
|
use std::path::{Component, Path, PathBuf}; |
|
|
|
|
use std::process::{Command, Stdio}; |
|
|
|
|
use std::process::Command; |
|
|
|
|
|
|
|
|
|
struct NonRepeatingQueue<T> { |
|
|
|
|
queue: VecDeque<T>, |
|
|
|
@ -42,7 +42,6 @@ fn patch_elf<S: AsRef<OsStr>, P: AsRef<OsStr>>(mode: S, path: P) -> Result<Strin |
|
|
|
|
let output = Command::new("patchelf") |
|
|
|
|
.arg(&mode) |
|
|
|
|
.arg(&path) |
|
|
|
|
.stderr(Stdio::inherit()) |
|
|
|
|
.output()?; |
|
|
|
|
if output.status.success() { |
|
|
|
|
Ok(String::from_utf8(output.stdout).expect("Failed to parse output")) |
|
|
|
@ -51,16 +50,15 @@ fn patch_elf<S: AsRef<OsStr>, P: AsRef<OsStr>>(mode: S, path: P) -> Result<Strin |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn copy_file<P: AsRef<Path> + AsRef<OsStr>, S: AsRef<Path>>( |
|
|
|
|
fn copy_file<P: AsRef<Path> + AsRef<OsStr>, S: AsRef<Path> + AsRef<OsStr>>( |
|
|
|
|
source: P, |
|
|
|
|
target: S, |
|
|
|
|
queue: &mut NonRepeatingQueue<Box<Path>>, |
|
|
|
|
) -> Result<(), Error> { |
|
|
|
|
fs::copy(&source, target)?; |
|
|
|
|
fs::copy(&source, &target)?; |
|
|
|
|
|
|
|
|
|
if !Command::new("ldd").arg(&source).output()?.status.success() { |
|
|
|
|
//stdout(Stdio::inherit()).stderr(Stdio::inherit()).
|
|
|
|
|
println!("{:?} is not dynamically linked. Not recursing.", OsStr::new(&source)); |
|
|
|
|
// Not dynamically linked - no need to recurse
|
|
|
|
|
return Ok(()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -91,6 +89,17 @@ fn copy_file<P: AsRef<Path> + AsRef<OsStr>, S: AsRef<Path>>( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Make file writable to strip it
|
|
|
|
|
let mut permissions = fs::metadata(&target)?.permissions(); |
|
|
|
|
permissions.set_readonly(false); |
|
|
|
|
fs::set_permissions(&target, permissions)?; |
|
|
|
|
|
|
|
|
|
// Strip further than normal
|
|
|
|
|
if !Command::new("strip").arg("--strip-all").arg(OsStr::new(&target)).output()?.status.success() { |
|
|
|
|
println!("{:?} was not successfully stripped.", OsStr::new(&target)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -200,7 +209,6 @@ fn main() -> Result<(), Error> { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
while let Some(obj) = queue.pop_front() { |
|
|
|
|
println!("{:?}", obj); |
|
|
|
|
handle_path(out_path, &*obj, &mut queue)?; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|