Documentation
¶
Overview ¶
Package rompatcher parses, inspects, creates, and applies common ROM patch formats. It provides memory-backed helpers, cancellable random-access file patching, validation, ordered patch chains, ZIP input selection, and ROM header/checksum compatibility operations.
Index ¶
- Variables
- func AdditionalChecksum(data []byte, name string) string
- func Adler32(data []byte) uint32
- func Apply(source, patchData []byte, options ApplyOptions) ([]byte, error)
- func ApplyFile(sourcePath, patchPath, outputPath string, opts ApplyOptions) error
- func ApplyFileContext(ctx context.Context, sourcePath, patchPath, outputPath string, ...) error
- func ApplyParsedWithOptions(source []byte, p Patch, opts ApplyOptions) ([]byte, error)
- func ApplyReaderAt(ctx context.Context, source io.ReaderAt, sourceSize int64, patch io.ReaderAt, ...) (int64, error)
- func ApplyWithOptions(source, patchData []byte, opts ApplyOptions) ([]byte, error)
- func CRC16(data []byte) uint16
- func CRC32(data []byte) uint32
- func CreateFile(originalPath, modifiedPath, outputPath string, format Format, ...) error
- func DefaultPatchedPath(sourcePath string) string
- func ExtractZIP(path, entry string, kind InputKind, maxSize uint64, dst io.Writer) (string, error)
- func FixROMChecksum(data []byte, name string) bool
- func MD5(data []byte) string
- func ReadZIP(path, entry string, kind InputKind, maxSize uint64) ([]byte, string, error)
- func ReadZIPBytes(data []byte, entry string, kind InputKind, maxSize uint64) ([]byte, string, error)
- func SHA1(data []byte) string
- func WriteFileAtomic(path string, data []byte) error
- type APSGBAPatch
- func (p *APSGBAPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
- func (APSGBAPatch) Description() string
- func (*APSGBAPatch) Format() Format
- func (p *APSGBAPatch) MarshalBinary() ([]byte, error)
- func (p *APSGBAPatch) ValidateSource(source []byte) bool
- func (p *APSGBAPatch) ValidationInfo() *ValidationInfo
- type APSN64Patch
- func (p *APSN64Patch) Apply(source []byte, options ApplyOptions) ([]byte, error)
- func (p *APSN64Patch) Description() string
- func (*APSN64Patch) Format() Format
- func (p *APSN64Patch) MarshalBinary() ([]byte, error)
- func (p *APSN64Patch) ValidateSource(source []byte) bool
- func (p *APSN64Patch) ValidationInfo() *ValidationInfo
- type ApplyOptions
- type ArchiveEntry
- type ArtifactInfo
- type BDFPatch
- type BPSPatch
- func (p *BPSPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
- func (p *BPSPatch) Description() string
- func (*BPSPatch) Format() Format
- func (p *BPSPatch) MarshalBinary() ([]byte, error)
- func (p *BPSPatch) ValidateSource(source []byte) bool
- func (p *BPSPatch) ValidationInfo() *ValidationInfo
- type ChainResult
- type ChainStep
- type CreateOptions
- type DryRunResult
- type Format
- type HashInfo
- type HeaderInfo
- type IPS32Patch
- func (p *IPS32Patch) Apply(source []byte, options ApplyOptions) ([]byte, error)
- func (IPS32Patch) Description() string
- func (*IPS32Patch) Format() Format
- func (p *IPS32Patch) MarshalBinary() ([]byte, error)
- func (IPS32Patch) ValidateSource([]byte) bool
- func (IPS32Patch) ValidationInfo() *ValidationInfo
- type IPSPatch
- type InputKind
- type Inspection
- type PMSRPatch
- func (p *PMSRPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
- func (PMSRPatch) Description() string
- func (*PMSRPatch) Format() Format
- func (*PMSRPatch) MarshalBinary() ([]byte, error)
- func (*PMSRPatch) ValidateSource(source []byte) bool
- func (*PMSRPatch) ValidationInfo() *ValidationInfo
- type PPFPatch
- func (p *PPFPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
- func (p *PPFPatch) Description() string
- func (*PPFPatch) Format() Format
- func (p *PPFPatch) MarshalBinary() ([]byte, error)
- func (p *PPFPatch) ValidateSource(source []byte) bool
- func (p *PPFPatch) ValidationInfo() *ValidationInfo
- type Patch
- type Progress
- type RUPPatch
- func (p *RUPPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
- func (p *RUPPatch) Description() string
- func (*RUPPatch) Format() Format
- func (p *RUPPatch) MarshalBinary() ([]byte, error)
- func (p *RUPPatch) ValidateSource(source []byte) bool
- func (p *RUPPatch) ValidationInfo() *ValidationInfo
- type UPSPatch
- func (p *UPSPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
- func (UPSPatch) Description() string
- func (*UPSPatch) Format() Format
- func (p *UPSPatch) MarshalBinary() ([]byte, error)
- func (p *UPSPatch) ValidateSource(source []byte) bool
- func (p *UPSPatch) ValidationInfo() *ValidationInfo
- type VCDIFFPatch
- func (p *VCDIFFPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
- func (VCDIFFPatch) Description() string
- func (*VCDIFFPatch) Format() Format
- func (*VCDIFFPatch) MarshalBinary() ([]byte, error)
- func (VCDIFFPatch) ValidateSource([]byte) bool
- func (VCDIFFPatch) ValidationInfo() *ValidationInfo
- type ValidationInfo
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownFormat = errors.New("rompatcher: unknown patch format") ErrInvalidPatch = errors.New("rompatcher: invalid patch") ErrSourceMismatch = errors.New("rompatcher: source checksum mismatch") ErrTargetMismatch = errors.New("rompatcher: target checksum mismatch") ErrPatchMismatch = errors.New("rompatcher: patch checksum mismatch") ErrOutputTooLarge = errors.New("rompatcher: requested output exceeds the configured size limit") ErrUnsupported = errors.New("rompatcher: operation is not supported by this format") ErrUnexpectedEnd = errors.New("rompatcher: unexpected end of patch") ErrAmbiguousArchive = errors.New("rompatcher: archive contains multiple candidate entries") )
Functions ¶
func AdditionalChecksum ¶
func ApplyFile ¶
func ApplyFile(sourcePath, patchPath, outputPath string, opts ApplyOptions) error
func ApplyFileContext ¶
func ApplyFileContext(ctx context.Context, sourcePath, patchPath, outputPath string, opts ApplyOptions) error
func ApplyParsedWithOptions ¶
func ApplyParsedWithOptions(source []byte, p Patch, opts ApplyOptions) ([]byte, error)
func ApplyReaderAt ¶
func ApplyReaderAt(ctx context.Context, source io.ReaderAt, sourceSize int64, patch io.ReaderAt, patchSize int64, output io.WriterAt, opts ApplyOptions) (int64, error)
ApplyReaderAt applies a patch from random-access inputs to a random-access output. Source and output data remain file-backed unless temporary header or checksum transformations require the compatibility memory path. Formats that must read already-produced output also require output to implement ReaderAt; *os.File satisfies both interfaces. The patch itself is parsed in memory. The returned size is the exact output length.
func ApplyWithOptions ¶
func ApplyWithOptions(source, patchData []byte, opts ApplyOptions) ([]byte, error)
func CreateFile ¶
func CreateFile(originalPath, modifiedPath, outputPath string, format Format, opts *CreateOptions) error
func DefaultPatchedPath ¶
func ExtractZIP ¶
ExtractZIP writes one explicitly selected or unambiguous entry without buffering it in memory.
func FixROMChecksum ¶
func ReadZIPBytes ¶
func WriteFileAtomic ¶
WriteFileAtomic writes data to a temporary file in the destination directory, flushes it, and atomically publishes it. Existing destinations are never clobbered.
Types ¶
type APSGBAPatch ¶
type APSGBAPatch struct {
SourceSize, TargetSize uint32
Records []apsGBARecord
// contains filtered or unexported fields
}
func (*APSGBAPatch) Apply ¶
func (p *APSGBAPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (APSGBAPatch) Description ¶
func (APSGBAPatch) Description() string
func (*APSGBAPatch) Format ¶
func (*APSGBAPatch) Format() Format
func (*APSGBAPatch) MarshalBinary ¶
func (p *APSGBAPatch) MarshalBinary() ([]byte, error)
func (*APSGBAPatch) ValidateSource ¶
func (p *APSGBAPatch) ValidateSource(source []byte) bool
func (*APSGBAPatch) ValidationInfo ¶
func (p *APSGBAPatch) ValidationInfo() *ValidationInfo
type APSN64Patch ¶
type APSN64Patch struct {
HeaderType, Encoding byte
PatchDescription string
OriginalFormat byte
CartID string
CartCRC [8]byte
Pad [5]byte
TargetSize uint32
Records []apsRecord
}
func (*APSN64Patch) Apply ¶
func (p *APSN64Patch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (*APSN64Patch) Description ¶
func (p *APSN64Patch) Description() string
func (*APSN64Patch) Format ¶
func (*APSN64Patch) Format() Format
func (*APSN64Patch) MarshalBinary ¶
func (p *APSN64Patch) MarshalBinary() ([]byte, error)
func (*APSN64Patch) ValidateSource ¶
func (p *APSN64Patch) ValidateSource(source []byte) bool
func (*APSN64Patch) ValidationInfo ¶
func (p *APSN64Patch) ValidationInfo() *ValidationInfo
type ApplyOptions ¶
type ApplyOptions struct {
Validate, RemoveHeader, AddHeader, FixChecksum bool
SourceName string
// Context cancels long-running patch operations. Nil means context.Background.
Context context.Context
// Progress receives coarse, monotonic progress updates. Callbacks must return
// quickly; they run synchronously with patching.
Progress func(Progress)
// MaxOutputSize caps allocations from untrusted patches. Zero chooses a
// source-relative default (64 MiB plus twice the source size).
MaxOutputSize uint64
}
type ArchiveEntry ¶
type ArchiveEntry struct {
Name string `json:"name"`
Size uint64 `json:"size"`
CompressedSize uint64 `json:"compressedSize"`
PatchCandidate bool `json:"patchCandidate"`
SourceCandidate bool `json:"sourceCandidate"`
}
func ListZIP ¶
func ListZIP(path string) ([]ArchiveEntry, error)
func ListZIPBytes ¶
func ListZIPBytes(data []byte) ([]ArchiveEntry, error)
type ArtifactInfo ¶
type BDFPatch ¶
type BDFPatch struct {
TargetSize uint64
Records []bdfRecord
// contains filtered or unexported fields
}
func (*BDFPatch) Apply ¶
func (p *BDFPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (BDFPatch) Description ¶
func (BDFPatch) Description() string
func (*BDFPatch) MarshalBinary ¶
func (BDFPatch) ValidateSource ¶
func (BDFPatch) ValidationInfo ¶
func (BDFPatch) ValidationInfo() *ValidationInfo
type BPSPatch ¶
type BPSPatch struct {
SourceSize, TargetSize uint64
Metadata string
Actions []bpsAction
SourceCRC, TargetCRC, PatchCRC uint32
}
func (*BPSPatch) Apply ¶
func (p *BPSPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (*BPSPatch) Description ¶
func (*BPSPatch) MarshalBinary ¶
func (*BPSPatch) ValidateSource ¶
func (*BPSPatch) ValidationInfo ¶
func (p *BPSPatch) ValidationInfo() *ValidationInfo
type ChainResult ¶
func ApplyChain ¶
func ApplyChain(source []byte, patches [][]byte, opts ApplyOptions) (ChainResult, error)
ApplyChain applies patches in order. Each patch receives the exact output of the previous patch, so validation catches an incorrectly ordered chain.
type ChainStep ¶
type ChainStep struct {
Index int `json:"index"`
Inspection Inspection `json:"inspection"`
Output ArtifactInfo `json:"output"`
}
type CreateOptions ¶
type DryRunResult ¶
type DryRunResult struct {
Inspection Inspection `json:"inspection"`
SourceValid *bool `json:"sourceValid,omitempty"`
Output ArtifactInfo `json:"output"`
}
func DryRun ¶
func DryRun(source, patchData []byte, opts ApplyOptions) (DryRunResult, error)
type Format ¶
type Format string
const ( FormatIPS Format = "ips" FormatIPS32 Format = "ips32" FormatEBP Format = "ebp" FormatUPS Format = "ups" FormatAPSN64 Format = "aps" FormatAPSGBA Format = "aps-gba" FormatBPS Format = "bps" FormatRUP Format = "rup" FormatPPF Format = "ppf" FormatBDF Format = "bdf" FormatPMSR Format = "mod" FormatVCDIFF Format = "vcdiff" )
type HashInfo ¶
type HeaderInfo ¶
func CanAddHeader ¶
func CanAddHeader(data []byte, name string) *HeaderInfo
func DetectHeader ¶
func DetectHeader(data []byte, name string) *HeaderInfo
func RemoveHeader ¶
func RemoveHeader(data []byte, name string) (header, rom []byte, info *HeaderInfo)
type IPS32Patch ¶
type IPS32Patch struct {
Records []ipsRecord
Truncate uint32
HasTruncate bool
// contains filtered or unexported fields
}
IPS32Patch is the 32-bit-offset extension of IPS. It uses an IPS32 header, EEOF terminator, and an optional four-byte truncate size.
func (*IPS32Patch) Apply ¶
func (p *IPS32Patch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (IPS32Patch) Description ¶
func (IPS32Patch) Description() string
func (*IPS32Patch) Format ¶
func (*IPS32Patch) Format() Format
func (*IPS32Patch) MarshalBinary ¶
func (p *IPS32Patch) MarshalBinary() ([]byte, error)
func (IPS32Patch) ValidateSource ¶
func (IPS32Patch) ValidationInfo ¶
func (IPS32Patch) ValidationInfo() *ValidationInfo
type IPSPatch ¶
type IPSPatch struct {
Records []ipsRecord
Truncate int
HasTruncate bool
Metadata map[string]string
// contains filtered or unexported fields
}
func (*IPSPatch) Apply ¶
func (p *IPSPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (*IPSPatch) Description ¶
func (*IPSPatch) MarshalBinary ¶
func (IPSPatch) ValidateSource ¶
func (IPSPatch) ValidationInfo ¶
func (IPSPatch) ValidationInfo() *ValidationInfo
type Inspection ¶
type Inspection struct {
Format Format `json:"format"`
Description string `json:"description,omitempty"`
Source ArtifactInfo `json:"source,omitempty"`
Target ArtifactInfo `json:"target,omitempty"`
Validation *ValidationInfo `json:"validation,omitempty"`
Reversible bool `json:"reversible"`
CanCreate bool `json:"canCreate"`
RecordCount int `json:"recordCount,omitempty"`
// RecordCountKnown distinguishes a valid empty patch from a lazily decoded
// format whose record count is unavailable without applying it.
RecordCountKnown bool `json:"recordCountKnown"`
Metadata map[string]string `json:"metadata,omitempty"`
Limitations []string `json:"limitations,omitempty"`
}
func Inspect ¶
func Inspect(data []byte) (Inspection, error)
func InspectParsed ¶
func InspectParsed(p Patch) Inspection
type PMSRPatch ¶
type PMSRPatch struct {
TargetSize int
Records []pmsrRecord
// contains filtered or unexported fields
}
func (*PMSRPatch) Apply ¶
func (p *PMSRPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (PMSRPatch) Description ¶
func (PMSRPatch) Description() string
func (*PMSRPatch) MarshalBinary ¶
func (*PMSRPatch) ValidateSource ¶
func (*PMSRPatch) ValidationInfo ¶
func (*PMSRPatch) ValidationInfo() *ValidationInfo
type PPFPatch ¶
type PPFPatch struct {
Version int
PatchDescription string
ImageType byte
BlockCheck []byte
Undo bool
InputSize uint32
Records []ppfRecord
FileID string
}
func (*PPFPatch) Apply ¶
func (p *PPFPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (*PPFPatch) Description ¶
func (*PPFPatch) MarshalBinary ¶
func (*PPFPatch) ValidateSource ¶
func (*PPFPatch) ValidationInfo ¶
func (p *PPFPatch) ValidationInfo() *ValidationInfo
type Patch ¶
type Patch interface {
Format() Format
Apply(source []byte, options ApplyOptions) ([]byte, error)
ValidateSource(source []byte) bool
ValidationInfo() *ValidationInfo
Description() string
MarshalBinary() ([]byte, error)
}
type RUPPatch ¶
type RUPPatch struct {
TextEncoding byte
Author, Version, Title, Genre, Language, Date, Web, PatchDescription string
Files []rupFile
}
func (*RUPPatch) Apply ¶
func (p *RUPPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (*RUPPatch) Description ¶
func (*RUPPatch) MarshalBinary ¶
func (*RUPPatch) ValidateSource ¶
func (*RUPPatch) ValidationInfo ¶
func (p *RUPPatch) ValidationInfo() *ValidationInfo
type UPSPatch ¶
type UPSPatch struct {
SourceSize, TargetSize uint64
SourceCRC, TargetCRC uint32
Records []upsRecord
// contains filtered or unexported fields
}
func (*UPSPatch) Apply ¶
func (p *UPSPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (UPSPatch) Description ¶
func (UPSPatch) Description() string
func (*UPSPatch) MarshalBinary ¶
func (*UPSPatch) ValidateSource ¶
func (*UPSPatch) ValidationInfo ¶
func (p *UPSPatch) ValidationInfo() *ValidationInfo
type VCDIFFPatch ¶
type VCDIFFPatch struct {
// contains filtered or unexported fields
}
func (*VCDIFFPatch) Apply ¶
func (p *VCDIFFPatch) Apply(source []byte, options ApplyOptions) ([]byte, error)
func (VCDIFFPatch) Description ¶
func (VCDIFFPatch) Description() string
func (*VCDIFFPatch) Format ¶
func (*VCDIFFPatch) Format() Format
func (*VCDIFFPatch) MarshalBinary ¶
func (*VCDIFFPatch) MarshalBinary() ([]byte, error)
func (VCDIFFPatch) ValidateSource ¶
func (VCDIFFPatch) ValidationInfo ¶
func (VCDIFFPatch) ValidationInfo() *ValidationInfo
type ValidationInfo ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
releasepack
command
Command releasepack creates deterministic release archives, SHA-256 checksums, and an SPDX 2.3 SBOM for one binary.
|
Command releasepack creates deterministic release archives, SHA-256 checksums, and an SPDX 2.3 SBOM for one binary. |
|
rompatcher
command
|