nyarime/gho

GitHub: nyarime/gho

纯 Go 实现的 Norton Ghost GHO 磁盘镜像解析库与 CLI 工具,支持镜像读取、解压、创建与头标志修复,无 CGo 依赖。

Stars: 87 | Forks: 6

# gho [![Go Reference](https://pkg.go.dev/badge/github.com/nyarime/gho.svg)](https://pkg.go.dev/github.com/nyarime/gho) [![Go Report Card](https://goreportcard.com/badge/github.com/nyarime/gho)](https://goreportcard.com/report/github.com/nyarime/gho) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 用于解析 **Norton Ghost GHO** 磁盘镜像文件的纯 Go 库和 CLI 工具。 无 C 依赖。无 CGo。单一二进制文件。 ## 功能 - 解析 GHO 文件/分区头和记录结构 - 解压 **Fast LZ (Z1)** 压缩的分区 - 从原始分区数据**创建** GHO 镜像 - **修复** GHO 头(相当于 ghofixup.exe — 通过 PRNG 密码修改 CD/分卷标志) - 提取 MBR/Track 0 数据和分区表 - 流式解压(内存占用恒定,支持任意镜像大小) - 支持 Ghost 11.x–12.x 格式 ## 安装 ``` # Library go get github.com/nyarime/gho # CLI 工具 go install github.com/nyarime/gho/cmd/gho@latest ``` ## CLI 用法 ``` # 显示镜像信息 gho info disk.gho # 将所有分区提取到目录 gho extract disk.gho output/ # 从分区镜像创建 GHO 镜像 (+ 可选 MBR) gho create output.gho partition.img mbr.bin # 修改 header flags (相当于 ghofixup.exe) gho fixup disk.gho cd # Set spanned/CD bit gho fixup disk.gho cd- # Clear spanned/CD bit gho fixup disk.gho span # Toggle CD flag ``` 示例输出: ``` GHO Image Summary File Type: 1 (1=single, 9=span) Compression: 2 (Fast/Z1) Image ID: 0x12345678 MBR Partitions: 1 P0: type=0x83 LBA=2016 size=102240 (49.9 MB) Data Partitions: 1 Partition 0: 3 spans, 42816212 bytes compressed data Decompressing partition 0... Saved partition 0: output/partition-0.img (51.4 MB) ``` ## 库用法 ``` package main import ( "bytes" "fmt" "log" "github.com/nyarime/gho" ) func main() { img, err := gho.Open("disk.gho") if err != nil { log.Fatal(err) } defer img.Close() // Print summary fmt.Print(img.Summary()) // Access MBR partition table for i, p := range img.MBRPartitions() { fmt.Printf("Partition %d: type=%#x, LBA=%d, size=%d sectors\n", i, p.Type, p.LBAStart, p.LBASize) } // Decompress partition 0 to memory var buf bytes.Buffer if err := img.DecompressPartition(0, &buf); err != nil { log.Fatal(err) } fmt.Printf("Decompressed: %d bytes\n", buf.Len()) } ``` ### 创建 GHO 镜像 ``` w, _ := gho.Create("output.gho", gho.CompressionNone) w.WriteTrack0(mbrData, 63) // MBR + boot sectors w.WritePartition(partFile) // raw partition data (io.Reader) w.Close() ``` ### 修改头标志 (ghofixup) ``` // Set CD/spanned bit (like ghofixup.exe cd) gho.ModifyHeader("disk.gho", gho.FixupCD) // Toggle span flag gho.ModifyHeader("disk.gho", gho.FixupSpan) ``` ## GHO 格式 Norton Ghost GHO 文件按以下结构存储磁盘/分区镜像: ``` ┌──────────────────────────────────────┐ │ File Header (512 bytes) │ Magic: FE EF, compression type, ID ├──────────────────────────────────────┤ │ Record: Track 0 (type 0x0006) │ 6-byte header + MBR + boot sectors ├──────────────────────────────────────┤ │ Record: Partition (type 0x0603) │ 20-byte partition descriptor ├──────────────────────────────────────┤ │ FEEF Partition Header (512 bytes) │ Per-partition compression settings ├──────────────────────────────────────┤ │ Compressed Blocks │ [2B len][block data]... │ ├─ Block: 2B stored_len + data │ 32KB decompressed per block │ ├─ Block: ... │ │ └─ Block: ... │ ├──────────────────────────────────────┤ │ Record: Continuation (type 0x0703) │ Additional data spans ├──────────────────────────────────────┤ │ (optional FEEF + more blocks) │ ├──────────────────────────────────────┤ │ Record: End (type 0x0023) │ End of image marker └──────────────────────────────────────┘ ``` **压缩**:每个块解压后为 32KB。块数据的第一个字节表示类型: - `0x01` → 未压缩(偏移量 4 处的原始数据) - 其他 → Fast LZ 压缩(自定义 LZ77 变体,带有 4096 项哈希表) **记录**:每个记录都有一个 10 字节的头部:`[4B type][4B magic 0x012F18D8][2B body_len]` ## Fast LZ 算法 Fast LZ 解压算法是通过逆向工程从 Norton Ghost 11.5.1 中提取的。它是一个自定义的 LZ77 变体,使用了: - 16 位控制字(bit 0 = 字面量,bit 1 = 匹配引用) - 4096 项哈希表,哈希函数为:`h = ((-24993 * (b2 ^ (16 * (b1 ^ (16 * b0))))) >> 4) & 0xFFF` - 编码哈希索引 + 额外长度的 2 字节匹配 token - 最小匹配长度为 3 字节 ## 支持的格式 | Ghost 版本 | 压缩 | 状态 | |---|---|---| | 11.x–12.x | 无 (Z0) | ✅ 读取 + 写入 | || 11.x–12.x | Fast LZ (Z1) | ✅ 读取 + 写入 | | 11.x–12.x | High/zlib (Z3–Z9) | ✅ 读取 + 写入 | | 加密镜像 | CRC-16 cipher | ✅ 读取 + 写入 | | 分卷文件 (.ghs) | 多文件 | ✅ 读取 | ## 许可证 MIT — 详见 [LICENSE](LICENSE)。 ## 致谢 由 [Nyarime](https://github.com/nyarime) 从 Norton Ghost 11.5.1 逆向工程。 [Nyarc](https://nyarc.bbie.net) 固件分析工具包的一部分。
标签:EVTX分析, Golang, Norton Ghost, 安全编程, 数据解析, 日志审计, 磁盘镜像解析