How to run an executable file from a protected uncompressed archive? I read on various forums, but I did not find an answer in Rust. Found some code but libraries were removed
use std::process::{Command, Stdio};
use std::path::Path;
use std::io::{Read, Write};
use byteorder::{LittleEndian, ByteOrder};
use std::fs::File;
use rust_7z::SevenZipArchive;
fn main() -> std::io::Result<()> {
let archive_path = "/path/to/archive.7z";
let password = "password";
let mut file = File::open(archive_path)?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
let archive = SevenZipArchive::new(&buffer[..], password)?;
for entry in archive.iter() {
let file_name = entry.filename();
if file_name.ends_with(".exe") {
let file_info = entry.get_reader()?;
let size = file_info.size()?;
let mut stream_reader = file_info.into_read();
let mut bytes = vec![0; size as usize];
stream_reader.read_exact(&mut bytes)?;
let mut command = Command::new(Path::new(file_name));
command.stdin(Stdio::inherit());
command.stdout(Stdio::inherit());
command.stderr(Stdio::inherit());
let _ = command.spawn();
}
}
Ok(())
}
The archive contains 3 files, and you need to run one of the files without unpacking it.