Skip to main content

pe_assembler/
lib.rs

1#![deny(missing_debug_implementations, missing_copy_implementations)]
2#![warn(missing_docs, rustdoc::missing_crate_level_docs)]
3#![doc = include_str!("readme.md")]
4#![doc(html_logo_url = "https://raw.githubusercontent.com/oovm/shape-rs/dev/projects/images/Trapezohedron.svg")]
5#![doc(html_favicon_url = "https://raw.githubusercontent.com/oovm/shape-rs/dev/projects/images/Trapezohedron.svg")]
6
7use crate::{formats::exe::writer::ExeWriter, helpers::PeWriter, types::PeProgram};
8use gaia_types::{
9    helpers::{create_file, Url},
10    Result,
11};
12use std::path::Path;
13
14pub mod formats;
15pub mod helpers;
16pub mod types;
17
18/// Write a PE program to an EXE file at the specified path
19///
20/// This is a high-level API function that hides the direct usage details of ExeWriter.
21///
22/// # Parameters
23///
24/// * `pe` - The PE program to write
25/// * `path` - Output file path
26///
27/// # Return Value
28///
29/// Returns the file URL on success, or a GaiaError on failure
30///
31/// # Example
32///
33/// ```rust,no_run
34/// # use pe_assembler::exe_write_path;
35/// # use std::path::Path;
36///
37/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
38/// // let pe_program = /* create PE program */;
39/// // let output_path = Path::new("output.exe");
40/// // let url = exe_write_path(&pe_program, output_path)?;
41/// # Ok(())
42/// # }
43/// ```
44pub fn exe_write_path(pe: &PeProgram, path: &Path) -> Result<Url> {
45    let (file, url) = create_file(path)?;
46    let mut exe = ExeWriter::new(file);
47    exe.write_program(pe)?;
48    Ok(url)
49}