use std::process::ExitCode;
use object_lang::Architecture;
fn main() -> ExitCode {
let mut args = std::env::args().skip(1);
let path = args.next().unwrap_or_else(|| String::from("exit42"));
let (arch, code): (Architecture, &[u8]) = match args.next().as_deref() {
Some("aarch64") => (
Architecture::Aarch64,
&[
0x40, 0x05, 0x80, 0xd2, 0xa8, 0x0b, 0x80, 0xd2, 0x01, 0x00, 0x00, 0xd4, ],
),
_ => (
Architecture::X86_64,
&[
0xbf, 0x2a, 0x00, 0x00, 0x00, 0xb8, 0x3c, 0x00, 0x00, 0x00, 0x0f, 0x05, ],
),
};
let program = match object_lang::elf::executable(arch, code) {
Ok(bytes) => bytes,
Err(err) => {
eprintln!("error: {err}");
return ExitCode::FAILURE;
}
};
if let Err(err) = std::fs::write(&path, &program) {
eprintln!("error: cannot write {path}: {err}");
return ExitCode::FAILURE;
}
println!("wrote {} bytes to {path} ({arch:?})", program.len());
ExitCode::SUCCESS
}