Skip to main content

pe_assembler/formats/lib/
mod.rs

1#![doc = include_str!("readme.md")]
2
3/// Library reader module.
4pub mod reader;
5/// Library writer module.
6pub mod writer;
7
8use crate::{
9    helpers::CoffReader,
10    types::{CoffFileType, CoffInfo, StaticLibrary},
11};
12use gaia_types::{helpers::open_file, GaiaError};
13pub use reader::LibReader;
14use std::{
15    io::{BufReader, Cursor},
16    path::Path,
17};
18pub use writer::WriteConfig;
19
20/// Configuration for library reading.
21#[derive(Copy, Clone, Debug)]
22pub struct LibReadConfig {}
23
24/// Reads a static library from a byte array.
25pub fn lib_from_bytes(data: &[u8]) -> Result<StaticLibrary, GaiaError> {
26    let reader = LibReader::new(Cursor::new(data));
27    reader.finish().result
28}
29
30/// Reads a static library from a file path.
31pub fn lib_from_file<P>(path: P) -> Result<StaticLibrary, GaiaError>
32where
33    P: AsRef<Path>,
34{
35    let (file, url) = open_file(path.as_ref())?;
36    let reader = LibReader::new(file).with_url(url);
37    reader.finish().result
38}
39
40/// Gets the COFF file type from a file path.
41pub fn lib_file_type<P: AsRef<Path>>(path: P) -> Result<CoffFileType, GaiaError> {
42    let (file, url) = open_file(path.as_ref())?;
43    let mut reader = LibReader::new(BufReader::new(file)).with_url(url);
44    reader.get_coff_header()?;
45    todo!()
46}
47
48/// Gets the COFF file info from a file path.
49pub fn lib_file_info<P: AsRef<Path>>(path: P) -> Result<CoffInfo, GaiaError> {
50    let (file, url) = open_file(path.as_ref())?;
51    let mut reader = LibReader::new(BufReader::new(file)).with_url(url);
52    reader.get_coff_header()?;
53    todo!()
54}