parse

package
v0.0.0-...-5a59a6e Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Crlf = 1 + iota // windows
	Cr              // old mac os
	Lf              // linux + modern mac os
)

line endings

Variables

This section is empty.

Functions

func HasSignatureInHeader

func HasSignatureInHeader(hdr []byte, pos int64, sig []byte) bool

HasSignatureInHeader returns true if `sig` is found in `hdr`

func ReadBytesFrom

func ReadBytesFrom(file *os.File, pos int64, size int64) []byte

ReadBytesFrom reads `size` bytes from `file`

func ReadBytesUntilNewline

func ReadBytesUntilNewline(file *os.File, pos int64) ([]byte, int64, error)

ReadBytesUntilNewline is used to process text

func ReadToMap

func ReadToMap(file *os.File, dataType DataType, pos int64, i interface{}) (string, error)

ReadToMap maps a bit value to a []string map

func ReadUint16be

func ReadUint16be(file *os.File, pos int64) (uint16, error)

ReadUint16be reads big endian Uint16 from `file`

func ReadUint16le

func ReadUint16le(file *os.File, pos int64) (uint16, error)

ReadUint16le reads little endian Uint16 from `file`

func ReadUint32be

func ReadUint32be(file *os.File, pos int64) (uint32, error)

ReadUint32be reads big endian Uint32 from `file`

func ReadUint32le

func ReadUint32le(file *os.File, pos int64) (uint32, error)

ReadUint32le reads little endian Uint32 from `file`

func ReadUint64be

func ReadUint64be(file *os.File, pos int64) (uint64, error)

ReadUint64be reads big endian Uint64 from `file`

func ReadUint8

func ReadUint8(file *os.File, pos int64) (uint8, error)

ReadUint8 reads Uint8 from `file`

func ReadUnsignedInt

func ReadUnsignedInt(file *os.File, field *Layout) uint32

ReadUnsignedInt reads field value, as an uint32

func ReadZeroTerminatedASCIIUntil

func ReadZeroTerminatedASCIIUntil(file *os.File, pos int64, maxLen int64) (string, int64, error)

ReadZeroTerminatedASCIIUntil returns ascii-string, bytes read, error

Types

type BrowseMode

type BrowseMode int

BrowseMode ...

const (
	ByGroup BrowseMode = 1 + iota
	ByFieldInGroup
)

browse modes

type ByLayout

type ByLayout []Layout

ByLayout ...

func (ByLayout) Len

func (slice ByLayout) Len() int

func (ByLayout) Less

func (slice ByLayout) Less(i, j int) bool

func (ByLayout) Swap

func (slice ByLayout) Swap(i, j int)

type Checker

type Checker struct {
	Header       []byte
	File         *os.File
	ParsedLayout ParsedLayout
}

Checker (parse checker)

type DataType

type DataType int

DataType ...

const (
	Group DataType = 1 + iota // container

	// single bytes
	Int8
	Uint8

	// little endian
	Int16le
	Int32le
	Uint16le
	Uint24le
	Uint32le
	Uint64le

	// big endian
	Uint16be
	Uint32be
	Uint64be

	// version
	MajorMinor8     // high nibble = major, low = minor
	MinorMajor8Five // high 5 bits = minor, low 3 = major
	MajorMinor16le  // first byte = major, last = minor
	MajorMinor16be  // first byte = major, last = minor
	MajorMinor32le  // first word = major, last = minor
	MinorMajor16le  // first byte = minor, last = major

	// timestamps
	DOSDateTime // 4 bytes
	ArjDateTime // 4 bytes

	// positions
	DOSOffsetSegment // ip:cs, 4 bytes

	// groups of bytes
	Bytes
	ASCII
	ASCIIC
	ASCIIZ
	RGB
)

...

func (DataType) String

func (dt DataType) String() string

type FileKind

type FileKind int

FileKind ...

const (
	Image FileKind = 1 + iota
	Archive
	AudioVideo
	Binary
	Executable
	Document
	Font
	WindowsResource
	MacOSResource
)

kinds of files

func (FileKind) String

func (i FileKind) String() string

type HexFormatting

type HexFormatting struct {
	BetweenSymbols string
	GroupSize      byte
}

HexFormatting ...

type HexViewState

type HexViewState struct {
	BrowseMode   BrowseMode
	StartingRow  int64
	VisibleRows  int
	RowWidth     int
	CurrentGroup int
	CurrentField int
}

HexViewState ...

func (*HexViewState) CurrentFieldInfo

func (state *HexViewState) CurrentFieldInfo(f *os.File, pl ParsedLayout) string

CurrentFieldInfo renders info of current field

func (*HexViewState) NextFieldInGroup

func (f *HexViewState) NextFieldInGroup(layout []Layout)

NextFieldInGroup moves to the next field in current group

func (*HexViewState) NextGroup

func (f *HexViewState) NextGroup(layout []Layout)

NextGroup moves focus to the next group

func (*HexViewState) PrevFieldInGroup

func (f *HexViewState) PrevFieldInGroup()

PrevFieldInGroup moves to the previous field in current group

func (*HexViewState) PrevGroup

func (f *HexViewState) PrevGroup()

PrevGroup moves focus to the previous group

type Layout

type Layout struct {
	Offset int64
	Length int64
	Type   DataType
	Info   string // user friendly field name
	Spec   string // field name according to specs
	Childs []Layout
	Masks  []Mask
}

Layout represents a parsed file structure

func (*Layout) CalcLength

func (l *Layout) CalcLength()

CalcLength calculates the .Length property from childs

func (*Layout) GetBitSize

func (l *Layout) GetBitSize() int

GetBitSize returns the bit size of the data type for the layout

type LineEnding

type LineEnding int

LineEnding ...

type Mask

type Mask struct {
	Low    int
	Length int
	Info   string // user friendly field name
	Spec   string // field name according to specs
}

Mask represents how to decode a bit field

type ParsedLayout

type ParsedLayout struct {
	FormatName   string
	FileName     string
	FileSize     int64
	FileKind     FileKind
	MimeType     string
	TextEncoding TextEncoding
	Layout       []Layout
}

ParsedLayout ...

func RAW

func RAW(c *Checker) (*ParsedLayout, error)

RAW is used for unrecognized files

func Text

func Text(c *Checker) (*ParsedLayout, error)

Text parses various text formats

func (*ParsedLayout) DecodeBitfieldFromInfo

func (pl *ParsedLayout) DecodeBitfieldFromInfo(file *os.File, info string) uint32

DecodeBitfieldFromInfo decodes a bitfield value

func (*ParsedLayout) FullListing

func (pl *ParsedLayout) FullListing() string

FullListing lists the parsed layout

func (*ParsedLayout) GetASCII

func (pl *ParsedLayout) GetASCII(file *os.File, hexView HexViewState) (string, error)

GetASCII returns the ASCII values of the currently visible area of the parsed layout

func (*ParsedLayout) GetHex

func (pl *ParsedLayout) GetHex(file *os.File, hexView HexViewState) (string, error)

GetHex dumps a row of hex

func (*ParsedLayout) PercentMapped

func (pl *ParsedLayout) PercentMapped(totalSize int64) float64

PercentMapped returns the % of total file size mapped to known structures

func (*ParsedLayout) PercentUnmapped

func (pl *ParsedLayout) PercentUnmapped(totalSize int64) float64

PercentUnmapped returns the % of total file size not mapped to known structures

func (*ParsedLayout) PrettyASCIIView

func (pl *ParsedLayout) PrettyASCIIView(file *os.File, hexView HexViewState) string

PrettyASCIIView returns pretty ASCII of the currently visible area of the parsed layout

func (*ParsedLayout) PrettyHexView

func (pl *ParsedLayout) PrettyHexView(file *os.File, hexView HexViewState) string

PrettyHexView returns the hex values of the currently visible area of the parsed layout

func (*ParsedLayout) PrettyOffsetView

func (pl *ParsedLayout) PrettyOffsetView(file *os.File, hexView HexViewState) string

PrettyOffsetView returns the offsets of the currently visible area of the parsed layout

func (*ParsedLayout) PrettyPrint

func (pl *ParsedLayout) PrettyPrint() string

PrettyPrint returns the output for cmd/prober

func (*ParsedLayout) ReadUint32leFromInfo

func (pl *ParsedLayout) ReadUint32leFromInfo(file *os.File, info string) (uint32, error)

ReadUint32leFromInfo returns a little-endian 32-bit value

func (*ParsedLayout) ShortPrint

func (pl *ParsedLayout) ShortPrint() string

ShortPrint returns the output for cmd/prober --short

func (*ParsedLayout) Sort

func (pl *ParsedLayout) Sort()

Sort sorts the parsed layout

func (*ParsedLayout) TypeSummary

func (pl *ParsedLayout) TypeSummary() string

TypeSummary returns a summary of the parsed layout

type TextEncoding

type TextEncoding int

TextEncoding ...

const (
	None TextEncoding = iota
	ASCIIUS
	UTF8
	UTF16le
	UTF16be
	UTF32le
	UTF32be
)

text encodings

func (TextEncoding) String

func (e TextEncoding) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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