pe-assembler 0.1.1

PE/COFF assembler for Windows instruction sets - strongly typed, object-oriented, zero-dependency core
Documentation
#![doc = include_str!("readme.md")]

/// Library reader module.
pub mod reader;
/// Library writer module.
pub mod writer;

use crate::{
    helpers::CoffReader,
    types::{CoffFileType, CoffInfo, StaticLibrary},
};
use gaia_types::{helpers::open_file, GaiaError};
pub use reader::LibReader;
use std::{
    io::{BufReader, Cursor},
    path::Path,
};
pub use writer::WriteConfig;

/// Configuration for library reading.
#[derive(Copy, Clone, Debug)]
pub struct LibReadConfig {}

/// Reads a static library from a byte array.
pub fn lib_from_bytes(data: &[u8]) -> Result<StaticLibrary, GaiaError> {
    let reader = LibReader::new(Cursor::new(data));
    reader.finish().result
}

/// Reads a static library from a file path.
pub fn lib_from_file<P>(path: P) -> Result<StaticLibrary, GaiaError>
where
    P: AsRef<Path>,
{
    let (file, url) = open_file(path.as_ref())?;
    let reader = LibReader::new(file).with_url(url);
    reader.finish().result
}

/// Gets the COFF file type from a file path.
pub fn lib_file_type<P: AsRef<Path>>(path: P) -> Result<CoffFileType, GaiaError> {
    let (file, url) = open_file(path.as_ref())?;
    let mut reader = LibReader::new(BufReader::new(file)).with_url(url);
    reader.get_coff_header()?;
    todo!()
}

/// Gets the COFF file info from a file path.
pub fn lib_file_info<P: AsRef<Path>>(path: P) -> Result<CoffInfo, GaiaError> {
    let (file, url) = open_file(path.as_ref())?;
    let mut reader = LibReader::new(BufReader::new(file)).with_url(url);
    reader.get_coff_header()?;
    todo!()
}