saadtahir-dev/libewf-spm

GitHub: saadtahir-dev/libewf-spm

将 libewf 封装为 Swift Package,提供 macOS 上读取和挂载 EWF/EnCase 取证磁盘镜像的原生 Swift 接口与捆绑工具。

Stars: 0 | Forks: 0

# libewf-spm 一个 Swift Package (SPM),封装了 Joachim Metz 开发的 [libewf](https://github.com/libyal/libewf),作为一个通用静态库,用于在 macOS 上读取 Expert Witness Format (EWF / EnCase) 取证磁盘镜像,并附带捆绑的 mount 和 info 工具。 ## 这是什么 `libewf-spm` 提供了 Swift API 和预编译的二进制文件,用于在 macOS 上处理 EWF (`.e01`, `.ex01`, `.s01`) 取证镜像。它在静态 `Clibewf` target 后封装了 libewf,并暴露了版本查询、捆绑工具解析以及用于直接访问库的 C 头文件。 该包附带了一个预编译的通用胖静态库 (`libewf.a`) 以及捆绑的命令行工具 —— 无需单独安装 libewf。 ## 系统要求 - macOS 12.0+ - Xcode 15+ - [macFUSE](https://osxfuse.github.io/) 5.x (`ewfmount` 运行时需要) - [Homebrew OpenSSL](https://formulae.brew.sh/formula/openssl@3) (`brew install openssl@3`) —— `ewfmount` 运行时需要 ## 安装说明 添加到你的 `Package.swift` 中: ``` dependencies: [ .package(url: "https://github.com/saadtahir-dev/libewf-spm.git", from: "1.0.0") ], targets: [ .target( name: "YourTarget", dependencies: [ .product(name: "libewf", package: "libewf-spm") ] ) ] ``` 在本地与其他取证包一起开发: ``` dependencies: [ .package(path: "../libewf-spm") ], targets: [ .target( name: "YourTarget", dependencies: [ .product(name: "libewf", package: "libewf-spm") ] ) ] ``` 或者通过 Xcode 添加:**File → Add Package Dependencies** → 粘贴仓库 URL。 ## 使用说明 ``` import libewf // Get library version let version = EWFReader.getVersion() print("libewf version: \(version)") // Resolve bundled tools (for mounting via Process) if let ewfmount = EWFToolLocator.bundledToolPath("ewfmount"), let ewfinfo = EWFToolLocator.bundledToolPath("ewfinfo") { print("ewfmount: \(ewfmount)") print("ewfinfo: \(ewfinfo)") // Launch ewfmount with Process, or use ImageMounter } ``` 对于编程式字节级读取,请使用 `Clibewf` 模块,并通过 `Sources/Clibewf/include` 中附带头文件提供的 libewf C API (`libewf_handle_t`)。 ## API ### `EWFReader` | Method | Description | |---|---| | `static func getVersion() -> String` | 返回链接的 libewf 版本字符串 (例如 `"20251220"`)。 | ### `EWFToolLocator` 解析 `ClibewfResources` 资源 bundle (`bin/`) 中捆绑可执行文件的路径。首次成功查找后结果会被缓存。 | Method | Description | |---|---| | `static func bundledToolPath(_ tool: String) -> String?` | 按名称返回捆绑工具的文件系统路径,如果未找到或不可执行则返回 `nil`。 | 常用工具名称:`"ewfmount"`、`"ewfinfo"`。 ### `Clibewf` 暴露 `libewf.h` 及相关头文件的 C 模块。在预编译的 `libewf.a` 静态归档文件上通过 `-force_load` 链接。当您需要超越 Swift 便利层进行读/写操作时,请使用它来直接访问 `libewf_handle_*`。 ## 支持的格式 | Format | Extension | Support | |---|---|---| | EnCase / EWF (EWF-E01) | `.e01` | 支持 | | EnCase / EWF (EWFX) | `.ex01` | 支持 | | SMART / s01 | `.s01` | 支持 | | 分段片段 | `.e01`, `.e02`, … | 支持 (打开第一个片段;libewf 将自动匹配整个集合) | ## 捆绑库 一个通用胖静态库附带在 `Sources/Clibewf/` 中: | Library | Version | Purpose | |---|---|---| | `libewf.a` | 20251220 | EWF 读/写实现 (静态链接) | 以下系统库在构建时链接 (无需捆绑): | Library | Source | |---|---| | `libz` | macOS 系统 (`/usr/lib/libz.1.dylib`) | | `libbz2` | macOS 系统 (`/usr/lib/libbz2.1.0.dylib`) | ## 捆绑工具 预编译的命令行工具附带在 `Sources/ClibewfResources/bin/` 中,并在运行时通过 `EWFToolLocator` 解析: | Tool | Purpose | macFUSE required | |---|---|---| | `ewfmount` | 通过 FUSE 将 EWF 镜像挂载为原始块设备 | 是 | | `ewfinfo` | 输出镜像元数据和完整性信息 | 否 | | Property | Value | |---|---| | Architectures | Universal (arm64 + x86_64) | | FUSE linkage | `libfuse3.4.dylib` (macFUSE 5.x) | | OpenSSL linkage | `/opt/homebrew/opt/openssl@3/lib/libssl.3.dylib` (动态链接 — 必须安装 Homebrew) | | Resolution | `ClibewfResources` SPM 资源 bundle | ## macFUSE 兼容性 `ewfmount` 需要安装并加载 macFUSE。捆绑的二进制文件链接到 macFUSE 的 `libfuse3.4.dylib`。 libewf 的 FUSE 挂载代码已针对 macFUSE 5.x 进行了修补:`ewftools/mount_fuse.c` 中的 `fuse_darwin_attr` 边界层在回调边界处,将 POSIX `struct stat` 字段与 macFUSE 的 `fuse_darwin_attr` 字段进行了映射。 有关构建步骤、修补程序详情和故障排除,请参阅 [swift-forensic-playbook](https://github.com/saadtahir-dev/swift-forensic-playbook)。 ## 从源码构建 请参阅 [swift-forensic-playbook](https://github.com/saadtahir-dev/swift-forensic-playbook) 获取完整的分步指南,涵盖以下内容: - 将 libewf 和 libyal 依赖项构建为通用静态库 - 在构建时启用 OpenSSL、zlib 和 bzip2 支持 - 将 macFUSE 5.x 的 `fuse_darwin_attr` 补丁应用到 `ewftools/mount_fuse.c` - 将 `ewfmount` 和 `ewfinfo` 捆绑到 SPM 资源 target 中 - 创建 SPM 包结构 ## 许可证 MIT — 请参阅 [LICENSE](./LICENSE) ## 相关项目 - [swift-forensic-playbook](https://github.com/saadtahir-dev/swift-forensic-playbook) — 将取证镜像库构建为 Swift Package 的指南 - [libyal/libewf](https://github.com/libyal/libewf) — 上游 libewf 库 - [ImageMounter](https://github.com/saadtahir-dev/ImageMounter) — macOS 取证镜像挂载服务 (使用 `EWFToolLocator` 进行 EWF 挂载)
标签:CIDR输入, Clibewf, C语言封装, EnCase, EWF, ewfinfo, ewfmount, HTTP工具, libewf, macFUSE, SPM, Swift Package Manager, Xcode, 云安全监控, 取证, 域渗透, 安全测试工具, 客户端加密, 开源库, 搜索引擎爬虫, 数字取证, 文件系统, 电子数据取证, 磁盘分析, 磁盘镜像, 自动化脚本, 镜像挂载, 镜像解析, 静态分析, 静态库