cfb

package
v0.0.0-...-9c1b276 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

package cfb implement a (MicroSoft) Compound File Binary File reader. Note that the focus is on access to data in CFBs so stuff concerning writing CFBs is omitted. This package rely on the document from https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/SupportTech/WindowsCompoundBinaryFileFormatSpecification.pdf Naming will be matched as closely as possible, though hungarian notation (default MS) is omitted.

Index

Constants

View Source
const (
	// REGSECT 0x00000000 - 0xFFFFFFF9 Regular sector number.
	MAXREGSECT    uint32 = 0xFFFFFFFA // Maximum regular sector number.
	NotApplicable        = 0xFFFFFFFB // Reserved for future use.
	DIFSECT              = 0xFFFFFFFC // Specifies a DIFAT sector in the FAT.
	FATSECT              = 0xFFFFFFFD // Specifies a FAT sector in the FAT.
	ENDOFCHAIN           = 0xFFFFFFFE // End of a linked chain of sectors.
	FREESECT             = 0xFFFFFFFF // Specifies an unallocated sector in the FAT, Mini FAT, or DIFAT.
)
View Source
const (
	STGTY_INVALID   byte = 0 // empty directory entry
	STGTY_STORAGE        = 1 // element is a storage object
	STGTY_STREAM         = 2 // element is a stream object
	STGTY_LOCKBYTES      = 3 // element is an ILockBytes object
	STGTY_PROPERTY       = 4 // element is an IPropertyStorage object
	STGTY_ROOT           = 5 // element is a root storage
)

Object types in storage (from AAF specifications)

View Source
const (
	DE_RED   byte = 0
	DE_BLACK      = 1
)
View Source
const (
	MAXREGSID uint32 = 0xFFFFFFFA // (-6) maximum directory entry ID
	NOSTREAM  uint32 = 0xFFFFFFFF // (-1) unallocated directory entry
)

Directory Entry IDs (from AAF specifications)

Variables

View Source
var (
	ErrDoNotUse         = errors.New("Do not use")
	ErrSignature        = errors.New("Bad signature")
	ErrCLSID            = errors.New("Bad header CLSID")
	ErrVersion          = errors.New("Bad version")
	ErrSectorShift      = errors.New("Invalid sector shift, expected 9 or 12")
	ErrMiniSectorShift  = errors.New("Invalid mini sector shift, expected 6")
	ErrMiniSectorCutoff = errors.New("Incorrect MiniStreamCutoffSize")
	ErrStorageType      = errors.New("Unknown storage type")
	ErrStorageSize      = errors.New("Unknown storage size")
	ErrNameLength       = errors.New("Invalid name property length")
	ErrSeekIndex        = errors.New("Bad seek index")
	ErrSectorSize       = errors.New("Bad sector read")
	ErrRootSibling      = errors.New("Root directory has illegal siblings")
	ErrNotStream        = errors.New("Entry is not a stream")
)
View Source
var Signature = [8]byte{0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1}

Functions

func FilePos

func FilePos(r io.Reader) (pos int64)

func SortDirectories

func SortDirectories(dir []*DirectoryEntry)

func UTF16String

func UTF16String(b []uint16) (d string)

Types

type Directory

type Directory struct {
	NameUTF16    [32]uint16
	NameLength   uint16
	Type         byte
	Flags        byte // DECOLOR (Red/Black-tree color, red=0)
	LeftSibling  uint32
	RightSibling uint32
	Child        uint32
	CLSID        GUID   // If Type=STGTY_STORAGE
	UserFlags    uint32 // If Type=STGTY_STORAGE
	Time         [2]FILETIME
	Start        uint32
	Size         uint32
	PropType     uint16
}

Directory is an OLE directory entry header. Names are not really kept here as they are not clearly descibing the field.

func (*Directory) Name

func (d *Directory) Name() (name string)

func (*Directory) Validate

func (d *Directory) Validate() (err error)

type DirectoryEntry

type DirectoryEntry struct {
	Directory
	// contains filtered or unexported fields
}

func NewDirectoryEntry

func NewDirectoryEntry(d *Document, s *Stream) (dir *DirectoryEntry, err error)

func (*DirectoryEntry) Children

func (d *DirectoryEntry) Children() []*DirectoryEntry

func (*DirectoryEntry) FullName

func (d *DirectoryEntry) FullName() string

func (*DirectoryEntry) ID

func (d *DirectoryEntry) ID() uint32

func (*DirectoryEntry) Level

func (d *DirectoryEntry) Level() uint32

func (*DirectoryEntry) Parent

func (d *DirectoryEntry) Parent() *DirectoryEntry

func (*DirectoryEntry) Stream

func (d *DirectoryEntry) Stream() (s *Stream, err error)

func (*DirectoryEntry) Walk

func (d *DirectoryEntry) Walk(f func(d *DirectoryEntry))

type Document

type Document struct {
	Header
	// contains filtered or unexported fields
}

func New

func New() (d *Document, err error)

func NewFromFile

func NewFromFile(filename string) (d *Document, err error)

func (*Document) ReadFrom

func (d *Document) ReadFrom(r io.Reader) (n int64, err error)

func (*Document) Root

func (d *Document) Root() (root *DirectoryEntry, err error)

func (*Document) Walk

func (d *Document) Walk(f func(d *DirectoryEntry))

type FILETIME

type FILETIME struct {
	LowDateTime  uint32 // Windows FILETIME structure
	HighDateTime uint32 // Windows FILETIME structure
}

type Fat

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

func (*Fat) Close

func (f *Fat) Close() (err error)

func (*Fat) Len

func (f *Fat) Len() uint32

func (*Fat) Sectors

func (f *Fat) Sectors() uint32

func (*Fat) Seek

func (f *Fat) Seek(offset int64, whence int) (n int64, err error)

type GUID

type GUID struct {
	DataA uint32
	DataB uint16
	DataC uint16
	DataD [8]byte
}
var CLSID_NULL GUID

func (GUID) String

func (g GUID) String() string
type Header struct {
	Signature       [8]byte
	CLSID           GUID
	MinorVersion    uint16
	MajorVersion    uint16
	ByteOrder       uint16
	SectorShift     uint16
	MiniSectorShift uint16

	SectFAT      uint32
	SectDirStart uint32

	MiniSectorCutoff uint32
	MiniFatStart     uint32
	MiniFat          uint32
	DifStart         uint32
	Dif              uint32
	Fat              [109]uint32 // Double Indexed Fat
	// contains filtered or unexported fields
}

Header the OLE file header.

type Sector

type Sector []byte

func (Sector) Reader

func (s Sector) Reader() (r io.Reader)

type Stream

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

func NewStream

func NewStream(sectorSize, streamSize uint32) (s *Stream)

func (*Stream) AsUnicode

func (s *Stream) AsUnicode() (r io.Reader)

func (*Stream) Close

func (s *Stream) Close() (err error)

func (*Stream) Len

func (s *Stream) Len() uint32

func (*Stream) Read

func (s *Stream) Read(dst []byte) (n int, err error)

func (*Stream) ReadString

func (s *Stream) ReadString() (v string, err error)

func (*Stream) ReadUint16

func (s *Stream) ReadUint16() (v uint16, err error)

func (*Stream) ReadUint32

func (s *Stream) ReadUint32() (v uint32, err error)

func (*Stream) ReadUint64

func (s *Stream) ReadUint64() (v uint64, err error)

func (*Stream) ReadUint8

func (s *Stream) ReadUint8() (v uint8, err error)

func (*Stream) ReadUnicode

func (s *Stream) ReadUnicode() (v string, err error)

func (*Stream) Sectors

func (s *Stream) Sectors() uint32

func (*Stream) Seek

func (s *Stream) Seek(offset int64, whence int) (n int64, err error)

Jump to

Keyboard shortcuts

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