clr_assembler/formats/dll/
mod.rs

1pub use self::{reader::DllReader, writer::DllWriter};
2use crate::program::ClrProgram;
3use gaia_types::{helpers::open_file, GaiaError};
4use std::{io::Cursor, path::Path};
5
6pub mod reader;
7pub mod writer;
8
9/// .NET PE 文件惰性读取器
10///
11/// 该类负责读取和解析 .NET 程序集文件,提供以下功能:
12/// - 检查文件是否为有效的 .NET 程序集
13/// - 解析 CLR 头和元数据
14/// - 提取程序集的基本信息
15/// - 验证程序集的完整性
16/// - 支持惰性读取和完整解析两种模式
17#[derive(Clone, Debug)]
18pub struct DllReadConfig {
19    pub assembly_ref_fallback_names: Vec<String>,
20}
21
22impl Default for DllReadConfig {
23    fn default() -> Self {
24        Self { assembly_ref_fallback_names: Vec::new() }
25    }
26}
27
28/// 从文件路径读取 .NET 程序集
29pub fn dll_from_file(file_path: &Path) -> Result<ClrProgram, GaiaError> {
30    let config = DllReadConfig::default();
31    let (file, url) = open_file(file_path)?;
32    let mut dll_reader = DllReader::new(file, &config);
33    dll_reader.to_clr_program()
34}
35
36/// 从字节数组读取 .NET 程序集
37pub fn dll_from_bytes(_bytes: &[u8]) -> Result<ClrProgram, GaiaError> {
38    let config = DllReadConfig::default();
39    let mut dll_reader = DllReader::new(Cursor::new(_bytes), &config);
40    dll_reader.to_clr_program()
41}
42
43/// 检查文件是否为 .NET 程序集(DLL)
44pub fn is_dotnet_dll(_file_path: &Path) -> Result<bool, GaiaError> {
45    // TODO: 实现检查逻辑
46    todo!()
47}
48
49/// 从文件路径读取 .NET 程序集,返回诊断结果
50pub fn read_dotnet_assembly(file_path: &Path, options: &DllReadConfig) -> Result<ClrProgram, GaiaError> {
51    let (file, url) = open_file(file_path)?;
52    let mut dll_reader = DllReader::new(file, options);
53    dll_reader.to_clr_program()
54}