mscfb

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 9 Imported by: 1

README

go-mscfb

Go Go Report Card

A Go library for reading Microsoft Compound File Binary files. Also known as the Object Linking and Embedding (OLE) or Component Object Model (COM) format.

Install

go get -u github.com/asalih/go-mscfb

Documentation

Index

Constants

View Source
const (
	HEADER_LEN                  int = 512 // length of CFB file header, in bytes
	DIR_ENTRY_LEN               int = 128 // length of directory entry, in bytes
	NUM_DIFAT_ENTRIES_IN_HEADER int = 109
)
View Source
const (
	MINOR_VERSION      int    = 0x3e
	BYTE_ORDER_MARK    uint16 = 0xfffe
	MINI_SECTOR_SHIFT  uint16 = 6 // 64-byte mini sectors
	MINI_SECTOR_LEN    int    = 1 << (MINI_SECTOR_SHIFT)
	MINI_STREAM_CUTOFF uint32 = 4096
)
View Source
const (
	MAX_REGULAR_SECTOR uint32 = 0xfffffffa
	INVALID_SECTOR     uint32 = 0xfffffffb
	DIFAT_SECTOR       uint32 = 0xfffffffc
	FAT_SECTOR         uint32 = 0xfffffffd
	END_OF_CHAIN       uint32 = 0xfffffffe
	FREE_SECTOR        uint32 = 0xffffffff
)

Constants for FAT entries:

View Source
const (
	ROOT_DIR_NAME                = "Root Entry"
	OBJ_TYPE_UNALLOCATED  uint8  = 0
	OBJ_TYPE_STORAGE      uint8  = 1
	OBJ_TYPE_STREAM       uint8  = 2
	OBJ_TYPE_ROOT         uint8  = 5
	COLOR_RED             uint8  = 0
	COLOR_BLACK           uint8  = 1
	ROOT_STREAM_ID        uint32 = 0
	MAX_REGULAR_STREAM_ID uint32 = 0xfffffffa
	NO_STREAM             uint32 = 0xffffffff
)

Constants for directory entries:

View Source
const MAX_NAME_LEN int = 31

Variables

View Source
var (
	ErrorInvalidCFB = errors.New("invalid cfb file")
)
View Source
var MAGIC_NUMBER = []byte{0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1}

Constants for CFB file header values:

Functions

func ValidateName

func ValidateName(name string, nameUtf16 []uint16) error

Types

type Allocator

type Allocator struct {
	Sector         *Sector
	DifatSectorIds []uint32
	Difat          []uint32
	Fat            []uint32
	Validation     Validation
}

func NewAllocator

func NewAllocator(sector *Sector, difatSectorIds []uint32, difat []uint32, fat []uint32, validation Validation) (*Allocator, error)

func (*Allocator) Next

func (a *Allocator) Next(index uint32) (uint32, error)

func (*Allocator) SeekToSector

func (a *Allocator) SeekToSector(sectorId uint32) (int64, error)

func (*Allocator) SeekWithinSector

func (a *Allocator) SeekWithinSector(sectorId uint32, offset int64) (int64, error)

func (*Allocator) Validate

func (a *Allocator) Validate() error

type Chain

type Chain struct {
	Allocator       *Allocator
	SectorInit      SectorInit
	SectorIds       []uint32
	OffsetFromStart uint64
}

func NewChain

func NewChain(allocator *Allocator, startingSectorId uint32, init SectorInit) (*Chain, error)

func (*Chain) Len

func (c *Chain) Len() uint64

func (*Chain) NumSectors

func (c *Chain) NumSectors() uint32

func (*Chain) Read

func (c *Chain) Read(p []byte) (int, error)

type Color

type Color int
const (
	Red Color = iota
	Black
)

func ColorFromByte

func ColorFromByte(b byte) Color

func (Color) AsByte

func (c Color) AsByte() byte

type CompoundFile

type CompoundFile struct {
	Header    *Header
	Directory *Directory
	MiniAlloc *MiniAlloc
	// contains filtered or unexported fields
}

func Open

func Open(reader io.ReadSeeker, validation Validation) (*CompoundFile, error)

type DirEntry

type DirEntry struct {
	Name           string
	ObjType        ObjectType
	Color          Color
	LeftSibling    uint32
	RightSibling   uint32
	Child          uint32
	CLSID          [16]byte
	StateBits      uint32
	CreationTime   uint64
	ModifiedTime   uint64
	StartingSector uint32
	StreamSize     uint64
}

func NewDirEntry

func NewDirEntry(name string, objType ObjectType, timestamp uint64) *DirEntry

func ReadDirEntry

func ReadDirEntry(reader io.ReadSeeker, version Version, validation Validation) (*DirEntry, error)

type Directory

type Directory struct {
	Allocator      *Allocator
	DirEntries     []*DirEntry
	DirStartSector uint32
}

func NewDirectory

func NewDirectory(allocator *Allocator, dirEntries []*DirEntry, dirStartSector uint32) (*Directory, error)

func (*Directory) RootDirEntry

func (d *Directory) RootDirEntry() *DirEntry

func (*Directory) Validate

func (d *Directory) Validate() error
type Header struct {
	Version            Version
	NumDirSectors      uint32
	NumFatSectors      uint32
	FirstDirSector     uint32
	FirstMinifatSector uint32
	NumMinifatSector   uint32
	FirstDifatSector   uint32
	NumDifatSectors    uint32

	InitialDifatEntries []uint32
}

type MiniAlloc

type MiniAlloc struct {
	Directory          *Directory
	Minifat            []uint32
	MinifatStartSector uint32
}

func NewMiniAlloc

func NewMiniAlloc(d *Directory, minifat []uint32, minifatStartSector uint32) (*MiniAlloc, error)

func (*MiniAlloc) Validate

func (a *MiniAlloc) Validate() error

type ObjectType

type ObjectType int
const (
	Unallocated ObjectType = iota
	Storage
	Stream
	Root
)

func ObjectFromByte

func ObjectFromByte(b byte) ObjectType

func (ObjectType) AsByte

func (o ObjectType) AsByte() byte

type Ordering

type Ordering int
const (
	OrderLess Ordering = iota
	OrderEqual
	OrderGreater
)

func CompareNames

func CompareNames(nameLeft, nameRight string) Ordering

type Sector

type Sector struct {
	Version    Version
	NumSectors uint32
	// contains filtered or unexported fields
}

func NewSector

func NewSector(v Version, bufferLength int64, reader io.ReadSeeker) *Sector

func (*Sector) SectorLen

func (s *Sector) SectorLen() int

func (*Sector) SeekToSector

func (s *Sector) SeekToSector(sectorId uint32) (int64, error)

func (*Sector) SeekWithinSector

func (s *Sector) SeekWithinSector(sectorId uint32, offset int64) (int64, error)

type SectorInit

type SectorInit int
const (
	SectorInitZero SectorInit = iota
	SectorInitFat
	SectorInitDifat
	SectorInitDir
)

func (SectorInit) Initialize

func (s SectorInit) Initialize(sector *Sector)

type Validation

type Validation int
const (
	ValidationPermissive Validation = iota
	ValidationStrict     Validation = iota
)

func (Validation) IsStrict

func (v Validation) IsStrict() bool

type Version

type Version int
const (
	V3 Version = 3
	V4 Version = 4
)

func VersionNumber

func VersionNumber(v uint16) (Version, error)

func (Version) DirEntriesPerSector

func (v Version) DirEntriesPerSector() int

Returns the number of directory entries per sector in this version.

func (Version) SectorLen

func (v Version) SectorLen() int

Returns the length of sectors used in this version.

func (Version) SectorLenMask

func (v Version) SectorLenMask() uint64

Returns the bitmask used for reading stream lengths in this version.

func (Version) SectorShift

func (v Version) SectorShift() uint16

Returns the sector shift used in this version.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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