Documentation
¶
Overview ¶
Package report defines versioned JSON documents describing VHD and VHDX images.
Why these types are separate from the parse structs ¶
The structures in types are how the formats are laid out on disk. Hanging json tags on them would tie the on-disk parse to the on-the-wire schema, so renaming a parser field would silently break every stored report. These are separate data transfer objects, converted from the reader's view, and they change only when the schema is meant to.
What makes a report forensically usable ¶
A report has to be readable years later by a tool that was not built against the library that produced it. That imposes three things, and every document here carries all three:
- A schema version, so a consumer can refuse a document it does not understand rather than misread it.
- Provenance: which image, how large, which library version, when. A report that does not identify its own input is an assertion without a subject.
- The caveats. If the image was recovered from a fallback footer, or a parent could not be verified, the document says so. A report that presents a recovered reconstruction as an intact read is worse than no report.
Zero dependencies ¶
This package is part of the core module and imports only the standard library and libvhdi's own packages. That is deliberate: the file-level ChangeReport types live here too, so a pipeline that reads and validates change reports never has to import a filesystem library. Only the code that *produces* them does.
Index ¶
- Constants
- func Write(w io.Writer, doc any) error
- type AllocationOptions
- type AllocationReport
- type AllocationTotals
- type ChainLink
- type ChainReport
- type ChangeEndpoint
- type ChangeOptions
- type ChangeReport
- type ChangeTier
- type ChangeTotals
- type ChangedFile
- type ChangedVolume
- type Check
- type CheckStatus
- type CheckpointLineage
- type CheckpointNode
- type CheckpointReport
- type DiskReport
- type Extent
- type FileRange
- type Geometry
- type Header
- type IntegrityReport
- type Kind
- type Library
- type Options
- type Provenance
- type Source
- type Warning
Constants ¶
const SchemaVersion = 1
SchemaVersion is the version of every document this package produces.
It increments when a field is removed, renamed, or changes meaning. Adding a field does not increment it, so a consumer that ignores unknown fields keeps working across additive changes.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AllocationOptions ¶
type AllocationOptions struct {
Options
// IncludeExtents puts the full extent list in the document.
//
// Off by default because a fragmented large device produces millions of
// entries. Turn it on when the consumer actually walks them, such as a
// sparse copier driving its reads from the document.
IncludeExtents bool
// MaxExtents caps how many are included, with zero meaning no cap. When the
// cap truncates the list, ExtentCount still reports the true total, so a
// consumer can tell a truncated document from a complete one.
MaxExtents int
}
AllocationOptions controls an allocation report.
type AllocationReport ¶
type AllocationReport struct {
// Header is embedded, so its fields appear at the top level of the
// document rather than nested under a key.
Header
Source Source `json:"source"`
Geometry Geometry `json:"geometry"`
Totals AllocationTotals `json:"totals"`
// Extents tile the whole address space in order, when included.
//
// They are omitted by default: a fragmented multi-terabyte device can have
// millions of them, which makes a document nobody can open. The totals
// answer most questions on their own.
Extents []Extent `json:"extents,omitempty"`
// ExtentCount is the number of extents, reported whether or not they are
// included -- so a document without them still says how many there were.
ExtentCount int `json:"extent_count"`
Warnings []Warning `json:"warnings,omitempty"`
}
AllocationReport describes which parts of a device are backed by data, which is what a sparse-aware acquisition needs in order to read only what exists.
func Allocation ¶
func Allocation(ctx context.Context, d *reader.VirtualDisk, opts *AllocationOptions) (*AllocationReport, error)
Allocation builds a report describing which parts of a device hold data.
type AllocationTotals ¶
type AllocationTotals struct {
// Mapped is backed by real bytes in some image in the chain.
Mapped int64 `json:"mapped"`
// Zero was never written anywhere in the chain.
Zero int64 `json:"zero"`
// ZeroedByChild was explicitly cleared by a differencing disk.
ZeroedByChild int64 `json:"zeroed_by_child"`
// Unresolved needs an image that is not attached, so its contents are
// unknown. It is neither present nor absent, and counting it as either
// would be a guess.
Unresolved int64 `json:"unresolved"`
// Total is the device's virtual size and equals the sum of the four above.
Total int64 `json:"total"`
MappedHuman string `json:"mapped_human"`
TotalHuman string `json:"total_human"`
}
AllocationTotals accounts for every byte of the address space.
The four categories are exhaustive and disjoint, so their sum equals the virtual size. A document where it does not is one the producer got wrong, and stating the total lets a consumer check.
type ChainLink ¶
type ChainLink struct {
// Index is the link's position: 0 is the disk the report was built from,
// 1 its parent, and so on.
Index int `json:"index"`
Path string `json:"path,omitempty"`
Format string `json:"format"`
DiskType string `json:"disk_type"`
Identifier string `json:"identifier,omitempty"`
ParentIdentifier string `json:"parent_identifier,omitempty"`
ParentFilename string `json:"parent_filename,omitempty"`
VirtualSize uint64 `json:"virtual_size"`
IsDifferencing bool `json:"is_differencing"`
HasLog bool `json:"has_log"`
LogReplayed bool `json:"log_replayed"`
// Role is this link's part in a Hyper-V chain: "base" or "checkpoint".
Role string `json:"role"`
}
ChainLink is one image in a differencing chain.
type ChainReport ¶
type ChainReport struct {
// Header is embedded, so its fields appear at the top level of the
// document rather than nested under a key.
Header
Source Source `json:"source"`
// Links are the images, leaf first.
Links []ChainLink `json:"links"`
// Complete reports whether every link the chain needs is attached. When
// false the device cannot be fully read, and the ranges backed by the
// missing images fail rather than returning zeroes.
Complete bool `json:"complete"`
// IncompleteReason explains a false Complete.
IncompleteReason string `json:"incomplete_reason,omitempty"`
Warnings []Warning `json:"warnings,omitempty"`
}
ChainReport describes the set of files that together constitute one device, which is what an evidence record has to name.
func Chain ¶
func Chain(d *reader.VirtualDisk, opts *Options) (*ChainReport, error)
Chain builds a report describing a disk's differencing chain.
type ChangeEndpoint ¶
type ChangeEndpoint struct {
Path string `json:"path,omitempty"`
Identifier string `json:"identifier,omitempty"`
ChainIndex int `json:"chain_index"`
}
ChangeEndpoint identifies one end of a comparison.
type ChangeOptions ¶
type ChangeOptions struct {
Options
// IncludeExtents puts the changed byte ranges in the document.
IncludeExtents bool
// MaxExtents caps how many are included; zero means no cap.
MaxExtents int
}
ChangeOptions controls a change report.
type ChangeReport ¶
type ChangeReport struct {
// Header is embedded, so its fields appear at the top level of the
// document rather than nested under a key.
Header
Source Source `json:"source"`
// Tier says how the report was produced and therefore what it can be
// trusted to say.
Tier ChangeTier `json:"tier"`
// From and To identify the two states compared. From is the checkpoint
// changes are measured since; To is the disk the report was built from.
From ChangeEndpoint `json:"from"`
To ChangeEndpoint `json:"to"`
// Totals account for the changed bytes.
Totals ChangeTotals `json:"totals"`
// Extents are the changed byte ranges, included on request.
Extents []Extent `json:"extents,omitempty"`
ExtentCount int `json:"extent_count"`
// Volumes is present only at the file or journal tier. Its absence means
// no filesystem analysis was run, not that no files changed.
Volumes []ChangedVolume `json:"volumes,omitempty"`
Warnings []Warning `json:"warnings,omitempty"`
}
ChangeReport describes what a checkpoint wrote.
At the block tier Volumes is absent entirely: the document says which byte ranges changed and makes no claim about files. That is a complete and useful document on its own, and the tier field says which it is so a consumer cannot mistake an absent Volumes for "no files changed".
func Change ¶
func Change(ctx context.Context, d *reader.VirtualDisk, sinceChainIndex int, opts *ChangeOptions) (*ChangeReport, error)
Change builds a block-level change report: which ranges of the device were written by the disks nearer the leaf than sinceChainIndex.
The result is a complete document at the block tier. The change module fills in Volumes to produce a file-level one; this package defines the schema for both so that reading a change report never requires a filesystem library.
type ChangeTier ¶
type ChangeTier string
ChangeTier says how a change report was produced, and therefore what it can be trusted to say.
const ( // TierBlock means only block-level detection ran: the document says which // byte ranges changed and nothing about files. TierBlock ChangeTier = "block" // TierFile means a filesystem parser attributed the changed ranges to // files, but renames are inferred rather than proven. TierFile ChangeTier = "file" // TierJournal means a filesystem journal corroborated the renames, which is // the only high-fidelity source for them. TierJournal ChangeTier = "journal" )
type ChangeTotals ¶
type ChangeTotals struct {
// Written is the bytes a disk in range wrote with data.
Written int64 `json:"written"`
// Cleared is the bytes a disk in range explicitly zeroed, which is how a
// deletion shows up. VHD cannot express this, so it is always zero on a VHD
// chain -- and that is a limitation of the format, not of the analysis.
Cleared int64 `json:"cleared"`
// Unresolved is the bytes whose state could not be determined because an
// image in the chain is missing. Neither changed nor unchanged.
Unresolved int64 `json:"unresolved"`
// Total is the device's virtual size, for proportion.
Total int64 `json:"total"`
WrittenHuman string `json:"written_human"`
TotalHuman string `json:"total_human"`
}
ChangeTotals accounts for the bytes a comparison found.
type ChangedFile ¶
type ChangedFile struct {
// Path is the file's full path on the volume.
Path string `json:"path"`
// Change is "added", "deleted", "modified" or "renamed".
Change string `json:"change"`
// PreviousPath is set for a rename.
PreviousPath string `json:"previous_path,omitempty"`
// FileNumber and Generation are the filesystem's identity for the file.
// Generation is the reuse counter; without it a recycled file number is
// indistinguishable from the original file being modified.
FileNumber uint64 `json:"file_number"`
Generation uint64 `json:"generation"`
// Stream names an alternate data stream, empty for the file's main
// contents.
Stream string `json:"stream,omitempty"`
// Size is the file's length after the change.
Size int64 `json:"size"`
// ChangedRanges are the byte ranges within the file that changed, when the
// producer can narrow it that far.
ChangedRanges []FileRange `json:"changed_ranges,omitempty"`
// Confidence is "proven" or "inferred". A rename detected without a journal
// is inference, and a report that does not say so overstates itself.
Confidence string `json:"confidence,omitempty"`
}
ChangedFile is one file a change report attributes a change to.
These types live in the core module on purpose. The schema belongs in one place so its versioning stays coherent, and it means a pipeline that reads and validates change reports never imports a filesystem library -- only the code that produces them does.
type ChangedVolume ¶
type ChangedVolume struct {
// Filesystem names the format, such as "ntfs" or "ext4".
Filesystem string `json:"filesystem"`
// VolumeIdentity is the volume's own identifier, which is what confirms two
// checkpoint states describe the same volume. Comparing two different
// volumes would report every file as changed.
VolumeIdentity string `json:"volume_identity,omitempty"`
// BaseOffset is the volume's offset within the disk. Changed ranges from
// libvhdi are whole-disk absolute and a filesystem's are volume-relative,
// so this is what relates them -- and getting it wrong produces a confident
// wrong answer rather than an error.
BaseOffset int64 `json:"base_offset"`
// Files are the changed files.
Files []ChangedFile `json:"files"`
// Notes record why the volume's result is limited, such as a filesystem
// with no stable file identity making rename detection inferential.
Notes []string `json:"notes,omitempty"`
}
ChangedVolume groups the changes found on one volume of a disk.
type Check ¶
type Check struct {
// Name identifies the structure, spelled as the specification spells it.
Name string `json:"name"`
// Status is the outcome.
Status CheckStatus `json:"status"`
// Offset is where the structure lives, when it has a fixed location.
Offset int64 `json:"offset,omitempty"`
// Detail explains a failure, or adds context to a pass.
Detail string `json:"detail,omitempty"`
}
Check is one structural verification and its outcome.
Opening an image already verifies most of these, but pass or fail is all a caller learns: the open succeeds or it does not. An integrity report makes each verdict individually reportable, which is what lets an examiner say *which* structure of a damaged image is intact.
type CheckStatus ¶
type CheckStatus string
CheckStatus is the outcome of one structural check.
const ( // StatusPass means the structure was present and verified. StatusPass CheckStatus = "pass" // StatusFail means the structure was present and did not verify. StatusFail CheckStatus = "fail" // StatusAbsent means the structure does not exist in this image. A VHDX has // no footer; a fixed VHD has no dynamic header. Absent is not a failure, // and a report that conflated the two would show every VHDX failing half // its checks. StatusAbsent CheckStatus = "absent" // StatusNotApplicable means the structure exists but this check does not // apply to it. StatusNotApplicable CheckStatus = "not_applicable" )
type CheckpointLineage ¶
type CheckpointLineage struct {
// Paths are the images, root first, that together constitute one device.
Paths []string `json:"paths"`
// Complete reports whether the lineage starts at a disk needing no parent.
// False means the images present cannot reconstruct the device.
Complete bool `json:"complete"`
// CheckpointCount is how many differencing images the lineage holds.
CheckpointCount int `json:"checkpoint_count"`
}
CheckpointLineage is one path through the tree, root first.
type CheckpointNode ¶
type CheckpointNode struct {
Path string `json:"path"`
// Readable reports whether the image could be probed. An unreadable image
// stays in the document rather than being dropped: a corrupt file in a
// checkpoint directory is a finding, and it may be the link that would have
// joined two halves of the tree.
Readable bool `json:"readable"`
Error string `json:"error,omitempty"`
Format string `json:"format,omitempty"`
DiskType string `json:"disk_type,omitempty"`
// Role is "base", "checkpoint" or "unknown".
Role string `json:"role"`
// HasCheckpointExtension reports Hyper-V's .avhdx naming convention.
//
// It is separate from Role because the extension is a convention, not a
// format: a renamed differencing disk is still a checkpoint and a base disk
// given the extension is not one. A disagreement between the two is worth
// showing rather than resolving.
HasCheckpointExtension bool `json:"has_checkpoint_extension"`
Identifier string `json:"identifier,omitempty"`
LinkIdentity string `json:"link_identity,omitempty"`
ParentIdentifier string `json:"parent_identifier,omitempty"`
ParentFilename string `json:"parent_filename,omitempty"`
VirtualSize uint64 `json:"virtual_size,omitempty"`
FileSize int64 `json:"file_size"`
HasLog bool `json:"has_log"`
// Depth is how many images lie between this one and its root.
Depth int `json:"depth"`
// ParentPath and ChildPaths give the tree's edges by file, which is how a
// person reads it.
ParentPath string `json:"parent_path,omitempty"`
ChildPaths []string `json:"child_paths,omitempty"`
}
CheckpointNode is one image in a discovered chain tree.
type CheckpointReport ¶
type CheckpointReport struct {
// Header is embedded, so its fields appear at the top level of the
// document rather than nested under a key.
Header
// Directory is the folder that was scanned.
Directory string `json:"directory"`
// Nodes are every image found, ordered by path.
Nodes []CheckpointNode `json:"nodes"`
// RootPaths and LeafPaths name the ends of the tree.
RootPaths []string `json:"root_paths"`
LeafPaths []string `json:"leaf_paths"`
// Branched reports more than one leaf.
//
// A branched tree has no single current disk. Which leaf a virtual machine
// is using is recorded in its configuration, not in the disks, so this
// document reports the branches and does not guess.
Branched bool `json:"branched"`
// Lineages is one entry per leaf: every distinct device the directory
// describes.
Lineages []CheckpointLineage `json:"lineages"`
// SkippedFiles are files in the directory that are not disk images, such as
// the .vmcx and .vmrs a Hyper-V machine folder holds. They are listed
// separately so they do not read as failures.
SkippedFiles []string `json:"skipped_files,omitempty"`
// UnreadablePaths names the images that could not be probed.
UnreadablePaths []string `json:"unreadable_paths,omitempty"`
// Limitations records what this document cannot say, so its silence is not
// mistaken for a finding.
Limitations []string `json:"limitations,omitempty"`
}
CheckpointReport describes a directory of images and the chain tree they form.
func Checkpoint ¶
func Checkpoint(ctx context.Context, dir string, opts *reader.DiscoverOptions) (*CheckpointReport, error)
Checkpoint builds a report describing a directory of images.
type DiskReport ¶
type DiskReport struct {
// Header is embedded, so its fields appear at the top level of the
// document rather than nested under a key.
Header
Source Source `json:"source"`
Geometry Geometry `json:"geometry"`
Provenance Provenance `json:"provenance"`
// NeedsParent reports a differencing image whose chain is incomplete.
// Reads into the missing ranges fail rather than returning zeroes.
NeedsParent bool `json:"needs_parent"`
ParentIdentifier string `json:"parent_identifier,omitempty"`
ParentFilename string `json:"parent_filename,omitempty"`
ParentResolveNote string `json:"parent_resolve_note,omitempty"`
// Warnings are the caveats for this image and its chain.
Warnings []Warning `json:"warnings,omitempty"`
}
DiskReport describes a single image.
func Disk ¶
func Disk(d *reader.VirtualDisk, opts *Options) (*DiskReport, error)
Disk builds a report describing one image.
type Extent ¶
type Extent struct {
// VirtualOffset and Length bound the run in the device's address space.
VirtualOffset int64 `json:"virtual_offset"`
Length int64 `json:"length"`
// Kind is one of "mapped", "zero", "zeroed-by-child" or "unresolved".
//
// The distinction between "zero" and "zeroed-by-child" is not cosmetic:
// both read as zeroes, but the second is a write by a differencing disk
// that overrode its parent, which is how a deletion appears at block level.
Kind string `json:"kind"`
// FileOffset is where the run lives in the backing file, present only for a
// mapped run.
FileOffset int64 `json:"file_offset,omitempty"`
// ChainIndex identifies the backing image: 0 is the disk the report was
// built from, 1 its parent, and so on. Path names it.
ChainIndex int `json:"chain_index"`
Path string `json:"path,omitempty"`
}
Extent is one contiguous run of the virtual disk and what backs it.
type Geometry ¶
type Geometry struct {
VirtualSize uint64 `json:"virtual_size"`
VirtualSizeHuman string `json:"virtual_size_human"`
BlockSize uint32 `json:"block_size"`
LogicalSectorSize uint32 `json:"logical_sector_size"`
PhysicalSectorSize uint32 `json:"physical_sector_size"`
// HasCHS distinguishes a VHD that recorded a zero geometry from a VHDX,
// which has no CHS field at all. Those are different facts.
HasCHS bool `json:"has_chs"`
Cylinders uint16 `json:"cylinders,omitempty"`
Heads uint8 `json:"heads,omitempty"`
SectorsPerTrack uint8 `json:"sectors_per_track,omitempty"`
}
Geometry is the physical shape an image reports for itself.
type Header ¶
type Header struct {
// SchemaVersion is the schema this document was written against.
SchemaVersion int `json:"schema_version"`
// Kind names the document type.
Kind Kind `json:"kind"`
// Generated is when the document was produced, in UTC.
Generated time.Time `json:"generated"`
// Library identifies the code that produced it.
Library Library `json:"library"`
}
Header is common to every document.
type IntegrityReport ¶
type IntegrityReport struct {
// Header is embedded, so its fields appear at the top level of the
// document rather than nested under a key.
Header
Source Source `json:"source"`
Format string `json:"format"`
// Checks are the individual verdicts, in the order the structures are read.
Checks []Check `json:"checks"`
// Healthy is true when no check failed. An absent structure does not make
// an image unhealthy.
Healthy bool `json:"healthy"`
// Opened reports whether the image could be opened at all. A false value
// with a populated Checks list is the interesting case: it says which
// structures survived.
Opened bool `json:"opened"`
// OpenError explains a false Opened.
OpenError string `json:"open_error,omitempty"`
Warnings []Warning `json:"warnings,omitempty"`
}
IntegrityReport records the per-structure verdicts for one image.
func Integrity ¶
Integrity verifies an image's structures one at a time and records each verdict.
Unlike the other reports this takes a path rather than an open disk, because the interesting case is an image that will not open. Checking each structure independently is what turns "this file is corrupt" into "the trailing footer is gone but the mirror and the dynamic header are intact", which is the difference between an image being written off and being recovered.
type Kind ¶
type Kind string
Kind names the type of a document, so a consumer can dispatch on one field without guessing from the shape.
type Library ¶
type Library struct {
// Module is the Go module path, and Version its version as recorded in the
// producing binary's build information.
//
// Version can be "(devel)" or "unknown". Those are honest answers: a report
// generator must be able to record that its own version could not be
// determined rather than fail or invent one.
Module string `json:"module"`
Version string `json:"version"`
}
Library identifies the producing code, so a report can be attributed.
type Options ¶
type Options struct {
// Hash computes the SHA-256 of each image file.
//
// It is off by default because it reads every byte of every file in the
// chain, which on a chain of large images is minutes of I/O -- a cost a
// caller should choose rather than discover.
Hash bool
}
Options controls what a report includes.
type Provenance ¶
type Provenance struct {
Format string `json:"format"`
DiskType string `json:"disk_type"`
CreatorApplication string `json:"creator_application,omitempty"`
CreatorVersion string `json:"creator_version,omitempty"`
CreatorOS string `json:"creator_os,omitempty"`
// Created is the image's own creation timestamp, omitted when the image
// recorded none. That absence is itself a fact, and inventing an epoch date
// to fill it would state something the image does not say.
Created *time.Time `json:"created,omitempty"`
// Identifier is the image's own GUID and DataWriteIdentifier the GUID VHDX
// rewrites on every modification -- which is what a differencing child
// records to name its parent. Both are canonical strings rather than byte
// arrays, which would serialise as sixteen numbers.
Identifier string `json:"identifier,omitempty"`
DataWriteIdentifier string `json:"data_write_identifier,omitempty"`
// OriginalSize is the disk's size at creation where the geometry's virtual
// size is its size now. A difference is the only record of an expansion.
OriginalSize uint64 `json:"original_size,omitempty"`
// SavedState marks a VHD saved from a running machine, whose filesystem is
// crash-consistent rather than cleanly unmounted.
SavedState bool `json:"saved_state"`
// LeaveBlocksAllocated marks a VHDX where blocks are never returned to the
// free pool, so an allocated block does not imply live data.
LeaveBlocksAllocated bool `json:"leave_blocks_allocated"`
// FooterSource says which copy of the VHD footer was used. Anything but
// "trailing" means the image was recovered rather than read intact.
// HasLog and LogReplayed describe the VHDX log state.
HasLog bool `json:"has_log"`
LogReplayed bool `json:"log_replayed"`
}
Provenance describes what produced an image and how much of the read can be trusted.
type Source ¶
type Source struct {
// Path is the file the image was opened from, empty when it was opened from
// a reader that names no file.
Path string `json:"path,omitempty"`
// FileSize is the length of the backing file in bytes, which is distinct
// from the virtual size of the device it describes.
FileSize int64 `json:"file_size"`
// SHA256 is the digest of the image *file*, lowercase hex, present only when
// the caller asked for it. It is the file's digest, not the decoded device's
// -- two images with identical contents but different block layouts have
// different file digests and the same device digest.
SHA256 string `json:"sha256,omitempty"`
}
Source identifies the image a document describes.
A report that does not identify its own input is an assertion with no subject, so every document carries one of these.
type Warning ¶
type Warning struct {
// Kind classifies the warning. Match on this rather than on Message.
Kind string `json:"kind"`
// Path is the image the warning concerns.
Path string `json:"path,omitempty"`
// Message is a human-readable explanation, meant to be shown rather than
// parsed.
Message string `json:"message"`
}
Warning is a caveat about an image or its chain that did not prevent it being read.