Documentation
¶
Index ¶
- Constants
- type BaseSection
- func (b *BaseSection) CRCType() types.CRCType
- func (b *BaseSection) CalculateCRC() (uint32, error)
- func (b *BaseSection) GetCRC() uint32
- func (b *BaseSection) GetCRCHandler() SectionCRCHandler
- func (b *BaseSection) GetEntry() *types.ITOCEntry
- func (b *BaseSection) GetITOCEntry() *types.ITOCEntry
- func (b *BaseSection) GetRawData() []byte
- func (b *BaseSection) HasCRC() bool
- func (b *BaseSection) IsDeviceData() bool
- func (b *BaseSection) IsEncrypted() bool
- func (b *BaseSection) IsFromHWPointer() bool
- func (b *BaseSection) Offset() uint64
- func (b *BaseSection) Parse(data []byte) error
- func (b *BaseSection) SetCRCHandler(handler SectionCRCHandler)
- func (b *BaseSection) SetRawData(data []byte)
- func (b *BaseSection) Size() uint32
- func (b *BaseSection) Type() uint16
- func (b *BaseSection) TypeName() string
- func (b *BaseSection) VerifyCRC() error
- func (b *BaseSection) Write(w io.Writer) error
- type CRCCalculator
- type CRCVerifier
- type CompleteSectionInterface
- type FirmwareInfo
- type FirmwareParser
- type RomInfo
- type Section
- type SectionAttributes
- type SectionCRCHandler
- type SectionCRCInfo
- type SectionCRCOperations
- type SectionData
- type SectionExtras
- type SectionFactory
- type SectionInfo
- type SectionInterface
- type SectionMetadata
- type SectionOption
- func WithCRC(crcType types.CRCType, crc uint32) SectionOption
- func WithCRCHandler(handler SectionCRCHandler) SectionOption
- func WithDeviceData() SectionOption
- func WithEncryption() SectionOption
- func WithFromHWPointer() SectionOption
- func WithITOCEntry(entry *types.ITOCEntry) SectionOption
- func WithNoCRC() SectionOption
- func WithRawData(data []byte) SectionOption
- type SectionParser
- type SectionReader
- type SectionVerifier
Constants ¶
const ( MinCRCSectionSize = 4 // Minimum size for embedded CRC CRCByteSize = 4 // Size of CRC field in bytes )
CRC-related constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseSection ¶
type BaseSection struct {
SectionType types.SectionType `json:"type" offset:"-"`
SectionOffset uint64 `json:"offset" offset:"-"`
SectionSize uint32 `json:"size" offset:"-"`
SectionCRCType types.CRCType `json:"crc_type" offset:"-"`
SectionCRC uint32 `json:"-" offset:"-"` // Internal use only
EncryptedFlag bool `json:"is_encrypted" offset:"-"`
DeviceDataFlag bool `json:"is_device_data" offset:"-"`
HasRawData bool `json:"has_raw_data" offset:"-"` // Set by sections based on parse status
FromHWPointerFlag bool `json:"is_from_hw_pointer" offset:"-"`
// contains filtered or unexported fields
}
BaseSection provides common implementation for all sections
func NewBaseSection ¶
func NewBaseSection(sectionType uint16, offset uint64, size uint32, crcType types.CRCType, crc uint32, isEncrypted, isDeviceData bool, entry *types.ITOCEntry, isFromHWPointer bool) *BaseSection
NewBaseSection creates a new base section with the given parameters Deprecated: Use NewBaseSectionWithOptions for new code
func NewBaseSectionWithOptions ¶
func NewBaseSectionWithOptions(sectionType uint16, offset uint64, size uint32, opts ...SectionOption) *BaseSection
NewBaseSectionWithOptions creates a new base section using functional options
func (*BaseSection) CRCType ¶
func (b *BaseSection) CRCType() types.CRCType
CRCType returns the CRC type for this section
func (*BaseSection) CalculateCRC ¶
func (b *BaseSection) CalculateCRC() (uint32, error)
CalculateCRC calculates the CRC for this section
func (*BaseSection) GetCRC ¶
func (b *BaseSection) GetCRC() uint32
GetCRC returns the expected CRC value for this section
func (*BaseSection) GetCRCHandler ¶
func (b *BaseSection) GetCRCHandler() SectionCRCHandler
GetCRCHandler returns the CRC handler for this section
func (*BaseSection) GetEntry ¶
func (b *BaseSection) GetEntry() *types.ITOCEntry
GetEntry returns the ITOC entry for this section
func (*BaseSection) GetITOCEntry ¶
func (b *BaseSection) GetITOCEntry() *types.ITOCEntry
GetITOCEntry returns the ITOC entry for this section (may be nil)
func (*BaseSection) GetRawData ¶
func (b *BaseSection) GetRawData() []byte
GetRawData returns the raw section data
func (*BaseSection) HasCRC ¶
func (b *BaseSection) HasCRC() bool
HasCRC returns whether this section has CRC verification enabled
func (*BaseSection) IsDeviceData ¶
func (b *BaseSection) IsDeviceData() bool
IsDeviceData returns whether this is device-specific data
func (*BaseSection) IsEncrypted ¶
func (b *BaseSection) IsEncrypted() bool
IsEncrypted returns whether the section is encrypted
func (*BaseSection) IsFromHWPointer ¶
func (b *BaseSection) IsFromHWPointer() bool
IsFromHWPointer returns whether section was discovered from HW pointer
func (*BaseSection) Offset ¶
func (b *BaseSection) Offset() uint64
Offset returns the section offset in the firmware
func (*BaseSection) Parse ¶
func (b *BaseSection) Parse(data []byte) error
Parse parses the raw data into section-specific structures
func (*BaseSection) SetCRCHandler ¶
func (b *BaseSection) SetCRCHandler(handler SectionCRCHandler)
SetCRCHandler sets the CRC handler for this section
func (*BaseSection) SetRawData ¶
func (b *BaseSection) SetRawData(data []byte)
SetRawData sets the raw section data
func (*BaseSection) TypeName ¶
func (b *BaseSection) TypeName() string
TypeName returns the human-readable name for this section type
func (*BaseSection) VerifyCRC ¶
func (b *BaseSection) VerifyCRC() error
VerifyCRC verifies the section's CRC
type CRCCalculator ¶
type CRCCalculator interface {
// Calculate calculates CRC for the given data
Calculate(data []byte) uint32
// CalculateWithParams calculates CRC with specific parameters
CalculateWithParams(data []byte, polynomial, initial, xorOut uint32) uint32
// CalculateImageCRC calculates CRC for firmware image data (handles endianness)
CalculateImageCRC(data []byte, sizeInDwords int) uint16
// GetType returns the CRC type
GetType() types.CRCType
}
CRCCalculator defines the interface for CRC calculation
type CRCVerifier ¶
type CRCVerifier interface {
// CalculateSoftwareCRC calculates software CRC16 for data
CalculateSoftwareCRC(data []byte) uint16
// CalculateHardwareCRC calculates hardware CRC for data
CalculateHardwareCRC(data []byte) uint16
// VerifyCRC verifies CRC for a data buffer
VerifyCRC(data []byte, expectedCRC uint32, useHardwareCRC bool) error
}
CRCVerifier provides CRC calculation and verification
type CompleteSectionInterface ¶
type CompleteSectionInterface interface {
SectionMetadata
SectionAttributes
SectionCRCInfo
SectionCRCOperations
SectionData
SectionExtras
}
CompleteSectionInterface combines all section interfaces This is equivalent to SectionInterface but built from smaller interfaces
type FirmwareInfo ¶
type FirmwareInfo struct {
// Basic information
Format string
FormatVersion int
// Version information
FWVersion string
FWReleaseDate string
MICVersion string
ProductVersion string
// Product information
PartNumber string
Description string
PSID string
OrigPSID string // Original PSID (shown when different from PSID)
PRSName string
// ROM information
RomInfo []RomInfo
// GUID/MAC information
BaseGUID uint64
BaseGUIDNum int
BaseMAC uint64
BaseMACNum int
// Additional GUID/MAC for dual format (encrypted firmware)
BaseGUID2 uint64
BaseGUID2Num int
BaseMAC2 uint64
BaseMAC2Num int
GUIDStep uint8
MACStep uint8
UseDualFormat bool // Whether to display GUID1/GUID2 format
// VSD information
ImageVSD string
DeviceVSD string
// Security information
SecurityAttrs string
SecurityVer int
IsEncrypted bool
// Activation method (device-mode; from MCQI)
ActivationMethod string
// Device information
DeviceID uint16
VendorID uint16
// Size information
ImageSize uint64
ChunkSize uint64
// Additional metadata
Sections []SectionInfo
}
FirmwareInfo represents the query output information
type FirmwareParser ¶
type FirmwareParser interface {
// Parse reads and parses the firmware from the provided reader
Parse(reader io.ReaderAt) error
// Query returns firmware information similar to mstflint query output
Query() (*FirmwareInfo, error)
// GetFormat returns the firmware format (FS4 or FS5)
GetFormat() int
// GetSections returns all parsed sections
GetSections() map[uint16]*Section
// GetSection returns a specific section by type
GetSection(sectionType uint16) (*Section, error)
}
FirmwareParser is the main interface for parsing firmware files
type Section ¶
type Section struct {
Type uint16
Offset uint64
Size uint32
Data []byte
CRCType types.CRCType
CRC uint32
IsEncrypted bool
IsDeviceData bool
Entry *types.ITOCEntry
IsFromHWPointer bool // True if section was discovered from HW pointer in encrypted firmware
}
Section represents a parsed firmware section
type SectionAttributes ¶
type SectionAttributes interface {
// IsEncrypted returns whether the section is encrypted
IsEncrypted() bool
// IsDeviceData returns whether this is device-specific data
IsDeviceData() bool
// IsFromHWPointer returns true if this section was referenced from HW pointers
IsFromHWPointer() bool
}
SectionAttributes provides access to section attributes
type SectionCRCHandler ¶
type SectionCRCHandler interface {
// CalculateCRC calculates the CRC for the section data
CalculateCRC(data []byte, crcType types.CRCType) (uint32, error)
// VerifyCRC verifies the CRC for the section
VerifyCRC(data []byte, expectedCRC uint32, crcType types.CRCType) error
// GetCRCOffset returns the offset of CRC within the section data (if CRC is embedded)
GetCRCOffset() int
// HasEmbeddedCRC returns true if CRC is stored within the section data
HasEmbeddedCRC() bool
}
SectionCRCHandler provides CRC handling for specific section types
type SectionCRCInfo ¶
type SectionCRCInfo interface {
// CRCType returns the CRC type for this section
CRCType() types.CRCType
// HasCRC returns whether this section has CRC verification enabled
HasCRC() bool
// GetCRC returns the expected CRC value for this section
GetCRC() uint32
}
SectionCRCInfo provides CRC-related information
type SectionCRCOperations ¶
type SectionCRCOperations interface {
// CalculateCRC calculates the CRC for this section
CalculateCRC() (uint32, error)
// VerifyCRC verifies the section's CRC
VerifyCRC() error
}
SectionCRCOperations provides CRC calculation and verification
type SectionData ¶
type SectionData interface {
// Parse parses the raw data into section-specific structures
Parse(data []byte) error
// GetRawData returns the raw section data
GetRawData() []byte
// Write writes the section data to the writer
Write(w io.Writer) error
}
SectionData provides access to section data
type SectionExtras ¶
type SectionExtras interface {
// GetITOCEntry returns the ITOC entry for this section (may be nil)
GetITOCEntry() *types.ITOCEntry
}
SectionExtras provides additional section information
type SectionFactory ¶
type SectionFactory interface {
// CreateSection creates a new section instance for the given type
CreateSection(sectionType uint16, offset uint64, size uint32, crcType types.CRCType,
crc uint32, isEncrypted, isDeviceData bool, entry *types.ITOCEntry, isFromHWPointer bool) (CompleteSectionInterface, error)
// CreateSectionFromData creates a section and parses its data
CreateSectionFromData(sectionType uint16, offset uint64, size uint32, crcType types.CRCType,
crc uint32, isEncrypted, isDeviceData bool, entry *types.ITOCEntry, isFromHWPointer bool, data []byte) (CompleteSectionInterface, error)
}
SectionFactory creates section instances based on type
type SectionInfo ¶
type SectionInfo struct {
Type uint16
TypeName string
Offset uint64
Size uint32
CRCType types.CRCType
IsEncrypted bool
IsDeviceData bool
}
SectionInfo represents information about a single section
type SectionInterface ¶
type SectionInterface interface {
// Type returns the section type
Type() uint16
// TypeName returns the human-readable name for this section type
TypeName() string
// Offset returns the section offset in the firmware
Offset() uint64
// Size returns the section size
Size() uint32
// CRCType returns the CRC type for this section
CRCType() types.CRCType
// HasCRC returns whether this section has CRC verification enabled
HasCRC() bool
// GetCRC returns the expected CRC value for this section
GetCRC() uint32
// CalculateCRC calculates the CRC for this section
CalculateCRC() (uint32, error)
// VerifyCRC verifies the section's CRC
VerifyCRC() error
// IsEncrypted returns whether the section is encrypted
IsEncrypted() bool
// IsDeviceData returns whether this is device-specific data
IsDeviceData() bool
// Parse parses the raw data into section-specific structures
Parse(data []byte) error
// GetRawData returns the raw section data
GetRawData() []byte
// Write writes the section data to the writer
Write(w io.Writer) error
// GetITOCEntry returns the ITOC entry for this section (may be nil)
GetITOCEntry() *types.ITOCEntry
// IsFromHWPointer returns true if this section was referenced from HW pointers
IsFromHWPointer() bool
}
SectionInterface defines the interface all section types must implement
type SectionMetadata ¶
type SectionMetadata interface {
// Type returns the section type
Type() uint16
// TypeName returns the human-readable name for this section type
TypeName() string
// Offset returns the section offset in the firmware
Offset() uint64
// Size returns the section size
Size() uint32
}
SectionMetadata provides basic metadata about a section
type SectionOption ¶
type SectionOption func(*BaseSection)
SectionOption is a functional option for configuring a BaseSection
func WithCRC ¶
func WithCRC(crcType types.CRCType, crc uint32) SectionOption
WithCRC sets the CRC type and value for the section
func WithCRCHandler ¶
func WithCRCHandler(handler SectionCRCHandler) SectionOption
WithCRCHandler sets a specific CRC handler for the section
func WithDeviceData ¶
func WithDeviceData() SectionOption
WithDeviceData sets whether the section contains device-specific data
func WithEncryption ¶
func WithEncryption() SectionOption
WithEncryption sets whether the section is encrypted
func WithFromHWPointer ¶
func WithFromHWPointer() SectionOption
WithFromHWPointer sets whether the section is from a hardware pointer
func WithITOCEntry ¶
func WithITOCEntry(entry *types.ITOCEntry) SectionOption
WithITOCEntry sets the ITOC entry for the section
func WithRawData ¶
func WithRawData(data []byte) SectionOption
WithRawData sets pre-loaded raw data for the section
type SectionParser ¶
type SectionParser interface {
SectionReader
SectionData
}
SectionParser combines interfaces for parsing sections
type SectionReader ¶
type SectionReader interface {
SectionMetadata
SectionAttributes
SectionCRCInfo
SectionExtras
}
SectionReader combines interfaces for reading section information
type SectionVerifier ¶
type SectionVerifier interface {
SectionReader
SectionCRCOperations
SectionData
}
SectionVerifier combines interfaces for verifying sections