Skip to content

Commit

Permalink
Add wasm pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy committed Aug 16, 2024
1 parent 01def0e commit 3c64f62
Show file tree
Hide file tree
Showing 12 changed files with 4,098 additions and 29 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ license = "MIT"
name = "patchver"
path = "main.rs"

[lib]
path = "lib.rs"

[dependencies]
libsui = "0.3.0"
pico-args = "0.5.0"
35 changes: 35 additions & 0 deletions lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use libsui::Elf;
use libsui::Macho;
use libsui::PortableExecutable;

use libsui::utils;

const CHANNELS: [&str; 4] = ["stable", "lts", "canary", "rc"];
const SECTION: &str = "denover";

pub fn patchver<W: std::io::Write>(
exe: Vec<u8>,
data: String,
out: &mut W,
) -> Result<(), Box<dyn std::error::Error>> {
if !CHANNELS.contains(&data.as_str()) {
panic!("Invalid channel. Expected one of: stable, lts, canary, rc");
}

let data = data.as_bytes().to_vec();
if utils::is_pe(&exe) {
PortableExecutable::from(&exe)?
.write_resource(SECTION, data)?
.build(out)?;
} else if utils::is_macho(&exe) {
Macho::from(exe)?
.write_section(SECTION, data)?
.build_and_sign(out)?;
} else if utils::is_elf(&exe) {
Elf::new(&exe).append(SECTION, &data, out)?;
} else {
panic!("Unsupported file format");
}

Ok(())
}
1 change: 1 addition & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
Loading

0 comments on commit 3c64f62

Please sign in to comment.