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/// 将 PE 程序写入到指定路径的 EXE 文件
19///
20/// 这是一个高级 API 函数,隐藏了 ExeWriter 的直接使用细节。
21///
22/// # 参数
23///
24/// * `pe` - 要写入的 PE 程序
25/// * `path` - 输出文件路径
26///
27/// # 返回值
28///
29/// 成功时返回文件的 URL,失败时返回 GaiaError
30///
31/// # 示例
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 = /* 创建 PE 程序 */;
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}