1use libsui::Elf;
2use libsui::Macho;
3use libsui::PortableExecutable;
4
5use libsui::utils;
6
7const CHANNELS: [&str; 4] = ["stable", "lts", "canary", "rc"];
8const SECTION: &str = "denover";
9
10pub fn patchver<W: std::io::Write>(
11 exe: Vec<u8>,
12 data: String,
13 out: &mut W,
14) -> Result<(), Box<dyn std::error::Error>> {
15 if !CHANNELS.contains(&data.as_str()) {
16 panic!("Invalid channel. Expected one of: stable, lts, canary, rc");
17 }
18
19 let data = data.as_bytes().to_vec();
20 if utils::is_pe(&exe) {
21 PortableExecutable::from(&exe)?
22 .write_resource(SECTION, data)?
23 .build(out)?;
24 } else if utils::is_macho(&exe) {
25 Macho::from(exe)?
26 .write_section(SECTION, data)?
27 .build_and_sign(out)?;
28 } else if utils::is_elf(&exe) {
29 Elf::new(&exe).append(SECTION, &data, out)?;
30 } else {
31 panic!("Unsupported file format");
32 }
33
34 Ok(())
35}