Documentation
¶
Overview ¶
Package libvhdi provides a pure-Go implementation of the VHD and VHDX virtual disk format support.
This package implements read support for the VHD (Virtual Hard Disk) and VHDX (Virtual Hard Disk v2) formats, written against the Microsoft VHD Image Format Specification and the VHDX Format Specification. It is an independent implementation and shares no code with any C library.
Supported features:
- VHD fixed, dynamic and differencing disks
- VHDX fixed, dynamic and differencing disks
- Sector-granular differencing resolution across a parent chain
- Automatic parent chain resolution, verified against each child's metadata
- VHDX log replay into a read-only in-memory overlay
- Sparse-aware extent mapping with per-link provenance
- Per-format checksum verification
Reads are read-only throughout: no code path writes to an image, and log replay is applied to an overlay so a forensic copy stays byte-identical.
Example usage:
disk, err := libvhdi.OpenFile("disk.vhd")
if err != nil {
log.Fatal(err)
}
defer disk.Close()
buf := make([]byte, 512)
n, err := disk.ReadAt(buf, 0)
if err != nil {
log.Fatal(err)
}
Index ¶
Constants ¶
const ( // Version is the current library version Version = "0.6.0" // Author information Author = "aoiflux" )
Version information
const ( FormatUnknown = types.FileFormatUnknown FormatVHD = types.FileFormatVHD FormatVHDX = types.FileFormatVHDX )
FileFormat constants (re-exported for convenience).
const ( DiskTypeFixed = types.DiskTypeFixed DiskTypeDynamic = types.DiskTypeDynamic DiskTypeDifferential = types.DiskTypeDifferential )
DiskType constants (re-exported for convenience).
const ( // ExtentZero has no backing bytes anywhere in the chain and reads as zeroes. ExtentZero = reader.ExtentZero // ExtentMapped is backed by a contiguous run of bytes in one of the files. ExtentMapped = reader.ExtentMapped // ExtentUnresolved resolves to a parent that is not attached. ExtentUnresolved = reader.ExtentUnresolved )
Extent kinds.
const DefaultMaxChainDepth = reader.DefaultMaxChainDepth
DefaultMaxChainDepth bounds how many disks a differencing chain may contain.
Variables ¶
var ( // ErrParentRequired is returned when a read on a differencing disk resolves // to a parent that has not been attached. Differencing disks fail closed: // silently returning zeroes would be indistinguishable from genuine disk // contents. ErrParentRequired = reader.ErrParentRequired // ErrParentNotFound is returned when a resolver exhausted its search // without locating the parent image. ErrParentNotFound = reader.ErrParentNotFound // ErrParentMismatch is returned when a located image does not match the // parent identity recorded in the child. ErrParentMismatch = reader.ErrParentMismatch // ErrChainTooDeep is returned when a parent chain exceeds the configured // maximum depth. ErrChainTooDeep = reader.ErrChainTooDeep // ErrChainCycle is returned when a parent chain refers back to a disk // already in the chain. ErrChainCycle = reader.ErrChainCycle // ErrSizeUnknown is returned when an image's size can neither be derived // from the reader nor was supplied via Options.Size. ErrSizeUnknown = reader.ErrSizeUnknown // ErrCorruptImage is returned when an image's headers are inconsistent or // describe structures that do not fit the file. ErrCorruptImage = reader.ErrCorruptImage // ErrDirtyImage is returned when a VHDX log cannot be replayed, so the // image may not reflect its last committed state. Set // Options.AllowDirtyImage to read it anyway. ErrDirtyImage = reader.ErrDirtyImage )
Errors reported when opening or reading a disk.
Functions ¶
This section is empty.
Types ¶
type ChainEntry ¶
type ChainEntry = reader.ChainEntry
ChainEntry describes one disk in a differencing chain: the set of files that together constitute the device, which is what an evidence record must name.
type Disk ¶
type Disk = reader.VirtualDisk
Disk represents an open VHD or VHDX virtual disk. Implements io.ReaderAt.
func Open ¶
Open opens a VHD or VHDX image from r, detecting the format automatically and deriving the image size from the reader when possible.
Readers exposing Size, Stat or Seek are all handled, covering *os.File, *bytes.Reader, *strings.Reader, io.SectionReader and fs.File. A bare io.ReaderAt with none of those must set Options.Size for VHD images; VHDX locates every structure from fixed offsets and needs no size.
When opts.ParentResolver is set, differencing parent chains are resolved automatically, so the caller gets a correct contiguous device with no manual SetParent wiring. opts may be nil.
func OpenFile ¶
OpenFile opens a VHD or VHDX virtual disk file by path. Format detection is automatic. The caller must call disk.Close() when done.
func OpenFileWith ¶
OpenFileWith opens a VHD or VHDX file by path with explicit options.
When opts.ParentResolver is nil it defaults to searching the image's own directory, which is where a differencing chain's parents conventionally live.
type Extent ¶
Extent describes a contiguous run of the virtual disk and what backs it, so a caller can read only what is mapped and skip sparse regions. For a differencing chain each mapped extent also identifies which disk supplies it.
type LogReplayStats ¶
type LogReplayStats = reader.LogReplayStats
LogReplayStats describes what a VHDX log replay applied.
type Options ¶
Options controls how a disk is opened. The zero value is safe: parent GUIDs are verified, and differencing disks with no parent fail closed on read.
type ParentRequest ¶
type ParentRequest = reader.ParentRequest
Parent resolution types. A ParentResolver locates the parent image of a differencing disk; DirParentResolver and FSParentResolver cover the common cases.
type ParentResolver ¶
type ParentResolver = reader.ParentResolver
Parent resolution types. A ParentResolver locates the parent image of a differencing disk; DirParentResolver and FSParentResolver cover the common cases.
func DirParentResolver ¶
func DirParentResolver(dirs ...string) ParentResolver
DirParentResolver returns a ParentResolver that searches the child's own directory first, then each supplied directory.
func FSParentResolver ¶
func FSParentResolver(fsys fs.FS) ParentResolver
FSParentResolver returns a ParentResolver that searches an fs.FS.
type ParentResolverFunc ¶
type ParentResolverFunc = reader.ParentResolverFunc
Parent resolution types. A ParentResolver locates the parent image of a differencing disk; DirParentResolver and FSParentResolver cover the common cases.
type ParentSource ¶
type ParentSource = reader.ParentSource
Parent resolution types. A ParentResolver locates the parent image of a differencing disk; DirParentResolver and FSParentResolver cover the common cases.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bat provides Block Allocation Table (BAT) parsing and lookup logic.
|
Package bat provides Block Allocation Table (BAT) parsing and lookup logic. |
|
Package block provides block-level reading and decompression logic for virtual disks.
|
Package block provides block-level reading and decompression logic for virtual disks. |
|
Package diff implements differencing (child) disk resolution over a parent chain.
|
Package diff implements differencing (child) disk resolution over a parent chain. |
|
examples
|
|
|
open
command
open prints metadata and geometry information for a VHD or VHDX virtual disk image.
|
open prints metadata and geometry information for a VHD or VHDX virtual disk image. |
|
readat
command
readat reads bytes from a VHD or VHDX virtual disk at a given offset and hex-dumps them.
|
readat reads bytes from a VHD or VHDX virtual disk at a given offset and hex-dumps them. |
|
internal
|
|
|
binaryutil
Package binaryutil provides endian-aware binary parsing utilities for the vhdi library.
|
Package binaryutil provides endian-aware binary parsing utilities for the vhdi library. |
|
vhdxlog
Package vhdxlog parses and replays the VHDX log.
|
Package vhdxlog parses and replays the VHDX log. |
|
Package metadata provides metadata extraction and decoding for VHDX files.
|
Package metadata provides metadata extraction and decoding for VHDX files. |
|
VHD Dynamic Disk Header Parser
|
VHD Dynamic Disk Header Parser |
|
Package types defines all data structures, enums, and constants for the libvhdi library.
|
Package types defines all data structures, enums, and constants for the libvhdi library. |