parser

package
v0.0.0-...-341aec2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2025 License: GPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateFS4HeaderGap

func GenerateFS4HeaderGap() []byte

GenerateHeaderGap generates the standard header gap for FS4 firmware

func ReconstructFS4Header

func ReconstructFS4Header(magicOffset uint32) []byte

ReconstructHeader reconstructs the standard firmware header

Types

type CRCCalculator

type CRCCalculator struct {
	// contains filtered or unexported fields
}

CRCCalculator provides CRC calculation methods

func NewCRCCalculator

func NewCRCCalculator() *CRCCalculator

NewCRCCalculator creates a new CRC calculator

func (*CRCCalculator) Calculate

func (c *CRCCalculator) Calculate(data []byte) uint32

Calculate implements the CRCCalculator interface

func (*CRCCalculator) CalculateHardwareCRC

func (c *CRCCalculator) CalculateHardwareCRC(data []byte) uint16

CalculateHardwareCRC calculates hardware CRC using the special table This matches mstflint's calc_hw_crc implementation

func (*CRCCalculator) CalculateImageCRC

func (c *CRCCalculator) CalculateImageCRC(data []byte, sizeInDwords int) uint16

CalculateImageCRC calculates CRC16 on image data (matches mstflint's CalcImageCRC) data: byte array containing the data sizeInDwords: number of 32-bit words to process

func (*CRCCalculator) CalculateSoftwareCRC16

func (c *CRCCalculator) CalculateSoftwareCRC16(data []byte) uint16

CalculateSoftwareCRC16 calculates software CRC16 using polynomial 0x100b This matches mstflint's implementation for FS4 sections

func (*CRCCalculator) CalculateWithParams

func (c *CRCCalculator) CalculateWithParams(data []byte, polynomial, initial, xorOut uint32) uint32

CalculateWithParams implements the CRCCalculator interface

func (*CRCCalculator) GetType

func (c *CRCCalculator) GetType() types.CRCType

GetType implements the CRCCalculator interface

func (*CRCCalculator) VerifyCRC

func (c *CRCCalculator) VerifyCRC(data []byte, expectedCRC uint16, useHardwareCRC bool) bool

VerifyCRC verifies CRC for a data buffer

type FileInfo

type FileInfo struct {
	Size   int64
	SHA256 string
}

FileInfo represents firmware file information

type FirmwareReader

type FirmwareReader struct {
	// contains filtered or unexported fields
}

FirmwareReader provides low-level firmware file reading operations

func NewFirmwareReader

func NewFirmwareReader(filePath string, logger *zap.Logger) (*FirmwareReader, error)

NewFirmwareReader creates a new firmware reader

func (*FirmwareReader) Close

func (r *FirmwareReader) Close() error

Close closes the firmware file

func (*FirmwareReader) FindMagicPattern

func (r *FirmwareReader) FindMagicPattern() (uint32, error)

FindMagicPattern searches for the firmware magic pattern at standard offsets

func (*FirmwareReader) GetFileInfo

func (r *FirmwareReader) GetFileInfo() (*FileInfo, error)

GetFileInfo returns information about the firmware file

func (*FirmwareReader) ReadAt

func (r *FirmwareReader) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements io.ReaderAt interface

func (*FirmwareReader) ReadSection

func (r *FirmwareReader) ReadSection(offset int64, size uint32) ([]byte, error)

ReadSection reads a section of data from the firmware

func (*FirmwareReader) Size

func (r *FirmwareReader) Size() int64

Size returns the size of the firmware file

type GapHandler

type GapHandler struct {
	// Minimum gap size to consider (smaller gaps are ignored)
	MinGapSize uint64
	// Whether to skip gaps that are entirely 0xFF
	SkipEmptyGaps bool
}

GapHandler handles gaps between sections in firmware

func NewGapHandler

func NewGapHandler() *GapHandler

NewGapHandler creates a new gap handler with default settings

func (*GapHandler) AnalyzeGap

func (h *GapHandler) AnalyzeGap(data []byte, start, end uint64) *GapInfo

AnalyzeGap analyzes a gap in the firmware data

func (*GapHandler) ShouldExtractGap

func (h *GapHandler) ShouldExtractGap(gap *GapInfo) bool

ShouldExtractGap determines if a gap should be extracted

type GapInfo

type GapInfo struct {
	Start    uint64
	End      uint64
	Size     uint64
	IsEmpty  bool // True if gap contains only 0xFF bytes
	IsHeader bool // True if this is the header gap (before first section)
}

GapInfo contains information about a gap

type TOCReader

type TOCReader struct {
	// contains filtered or unexported fields
}

TOCReader provides generic TOC reading functionality

func NewTOCReader

func NewTOCReader(logger *zap.Logger) *TOCReader

NewTOCReader creates a new TOC reader

func NewTOCReaderWithFactory

func NewTOCReaderWithFactory(logger *zap.Logger, factory interfaces.SectionFactory) *TOCReader

NewTOCReaderWithFactory creates a new TOC reader with a section factory

func (*TOCReader) GetCRCType

func (r *TOCReader) GetCRCType(entry *types.ITOCEntry) types.CRCType

GetCRCType determines the CRC type from ITOC entry

func (*TOCReader) GetCRCTypeLegacy

func (r *TOCReader) GetCRCTypeLegacy(entry *types.ITOCEntry) types.CRCType

GetCRCTypeLegacy determines the CRC type from legacy ITOC entry flags

func (*TOCReader) ReadTOCEntries

func (r *TOCReader) ReadTOCEntries(data []byte, tocAddr uint32) ([]*types.ITOCEntry, error)

ReadTOCEntries reads all TOC entries until end marker

func (*TOCReader) ReadTOCHeader

func (r *TOCReader) ReadTOCHeader(data []byte, tocAddr uint32, isDTOC bool) (*types.ITOCHeader, error)

ReadTOCHeader reads and validates a TOC header

func (*TOCReader) ReadTOCRawEntries

func (r *TOCReader) ReadTOCRawEntries(data []byte, tocAddr uint32, isDTOC bool) ([]*types.ITOCEntry, error)

ReadTOCRawEntries reads raw TOC entries without converting to sections This is useful for the replacer which needs the raw entries

func (*TOCReader) ReadTOCSections

func (r *TOCReader) ReadTOCSections(data []byte, tocAddr uint32, isDTOC bool) ([]*interfaces.Section, error)

ReadTOCSections reads all sections from a TOC

func (*TOCReader) ReadTOCSectionsNew

func (r *TOCReader) ReadTOCSectionsNew(data []byte, tocAddr uint32, isDTOC bool) ([]interfaces.CompleteSectionInterface, error)

ReadTOCSectionsNew reads TOC sections and returns section interfaces

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL