msi

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: MIT Imports: 13 Imported by: 1

README

go-msi

Go library for reading msi files

Documentation

Index

Constants

View Source
const (
	/// An unrestricted text string.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/text) for this
	/// data type.
	CategoryText = iota
	/// A text string containing no lowercase letters.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/uppercase) for
	/// this data type.
	CategoryUpperCase
	/// A text string containing no uppercase letters.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/lowercase) for
	/// this data type.
	CategoryLowerCase
	/// A signed 16-bit integer.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/integer) for
	/// this data type.
	CategoryInteger
	/// A signed 32-bit integer.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/doubleinteger)
	/// for this data type.
	CategoryDoubleInteger
	/// Stores a civil datetime, with a 2-second resolution.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/time-date) for
	/// this data type.
	CategoryTimeDate
	/// A string identifier (such as a table or column name).  May only contain
	/// alphanumerics, underscores, and periods, and must start with a letter
	/// or underscore.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/identifier)
	/// for this data type.
	CategoryIdentifier
	/// A string that is either an identifier (see above), or a reference to an
	/// environment variable (which consists of a `%` character followed by an
	/// identifier).
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/property) for
	/// this data type.
	CategoryProperty
	/// The name of a file or directory.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/filename) for
	/// this data type.
	CategoryFilename
	/// A filename that can contain shell glob wildcards.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/wildcardfilename)
	/// for this data type.
	CategoryWildCardFilename
	/// A string containing an absolute filepath.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/path) for this
	/// data type.
	CategoryPath
	/// A string containing a semicolon-separated list of absolute filepaths.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/paths) for
	/// this data type.
	CategoryPaths
	/// A string containing an absolute or relative filepath.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/anypath) for
	/// this data type.
	CategoryAnyPath
	/// A string containing either a filename or an identifier.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/defaultdir)
	/// for this data type.
	CategoryDefaultDir
	/// A string containing a registry path.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/regpath) for
	/// this data type.
	CategoryRegPath
	/// A string containing special formatting escapes, such as environment
	/// variables.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/formatted) for
	/// this data type.
	CategoryFormatted
	/// A security descriptor definition language (SDDL) text string written in
	/// valid [Security Descriptor String
	/// Format](https://docs.microsoft.com/en-us/windows/win32/secauthz/security-descriptor-string-format).
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/formattedsddltext)
	/// for this data type.
	CategoryFormattedSddlText
	/// Like `Formatted`, but allows additional escapes.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/template) for
	/// this data type.
	CategoryTemplate
	/// A string represeting a boolean predicate.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/condition) for
	/// this data type.
	CategoryCondition
	/// A hyphenated, uppercase GUID string, enclosed in curly braces.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/guid) for
	/// this data type.
	CategoryGuid
	/// A string containing a version number.  The string must consist of at
	/// most four period-separated numbers, with the value of each number being
	/// at most 65535.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/version) for
	/// this data type.
	CategoryVersion
	/// A string containing a comma-separated list of decimal language ID
	/// numbers.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/language) for
	/// this data type.
	CategoryLanguage
	/// A string that refers to a binary data stream.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/binary) for
	/// this data type.
	CategoryBinary
	/// A string that refers to a custom source.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/customsource)
	/// for this data type.
	CategoryCustomSource
	/// A string that refers to a cabinet.  If it starts with a `#` character,
	/// then the rest of the string is an identifier (see above) indicating a
	/// data stream in the package where the cabinet is stored.  Otherwise, the
	/// string is a short filename (at most eight characters, a period, and a
	/// three-character extension).
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/cabinet) for
	/// this data type.
	///
	/// # Examples
	///
	/// “`
	/// // Valid:
	/// assert!(msi::Category::Cabinet.validate("hello.txt"));
	/// assert!(msi::Category::Cabinet.validate("#HelloWorld"));
	/// // Invalid:
	/// assert!(!msi::Category::Cabinet.validate("longfilename.long"));
	/// assert!(!msi::Category::Cabinet.validate("#123.456"));
	/// “`
	CategoryCabinet
	/// A string that refers to a shortcut.
	///
	/// For more details, see the [MSI
	/// docs](https://docs.microsoft.com/en-us/windows/win32/msi/shortcut) for
	/// this data type.
	CategoryShortcut
)
View Source
const (
	COL_FIELD_SIZE_MASK int32 = 0xff
	COL_LOCALIZABLE_BIT int32 = 0x200
	COL_STRING_BIT      int32 = 0x800
	COL_NULLABLE_BIT    int32 = 0x1000
	COL_PRIMARY_KEY_BIT int32 = 0x2000

	COL_VALID_BIT     int32 = 0x100
	COL_NONBINARY_BIT int32 = 0x400
)
View Source
const (
	INSTALLER_PACKAGE_CLSID = "000C1084-0000-0000-C000-000000000046"
	PATCH_PACKAGE_CLSID     = "000C1086-0000-0000-C000-000000000046"
	TRANSFORM_PACKAGE_CLSID = "000C1082-0000-0000-C000-000000000046"

	COLUMNS_TABLE_NAME     = "_Columns"
	TABLES_TABLE_NAME      = "_Tables"
	VALIDATION_TABLE_NAME  = "_Validation"
	STRING_DATA_TABLE_NAME = "_StringData"
	STRING_POOL_TABLE_NAME = "_StringPool"

	MAX_NUM_TABLE_COLUMNS uint32 = 32
)
View Source
const (
	BYTE_ORDER_MARK   uint16 = 0xfffe
	PROPERTY_CODEPAGE uint32 = 1
)
View Source
const (
	DIGITAL_SIGNATURE_STREAM_NAME        = "\x05DigitalSignature"
	MSI_DIGITAL_SIGNATURE_EX_STREAM_NAME = "\x05MsiDigitalSignatureEx"
	SUMMARY_INFO_STREAM_NAME             = "\x05SummaryInformation"

	TABLE_PREFIX = "\xE4\xA1\x80"
)
View Source
const (
	LONG_STRING_REFS_BIT uint32 = 0x8000_0000
	MAX_STRING_REF       int32  = 0xff_ffff
)

Variables

Functions

func NameDecode

func NameDecode(name string) (string, bool)

func NameEncode

func NameEncode(name string, isTable bool) string

func NameIsValid

func NameIsValid(name string, isTable bool) bool

Types

type Category

type Category int

func CategoryFromString

func CategoryFromString(str string) Category

func (Category) String

func (c Category) String() string

type CodePage

type CodePage int
const (
	/// [Windows-932 (Japanese Shift JIS)](https://en.wikipedia.org/wiki/Code_page_932_(Microsoft_Windows))
	Windows932 CodePage = iota
	/// [Windows-936 (Chinese (simplified) GBK)](https://en.wikipedia.org/wiki/Code_page_936_(Microsoft_Windows))
	Windows936
	/// [Windows-949 (Korean Unified Hangul Code)](https://en.wikipedia.org/wiki/Unified_Hangul_Code)
	Windows949
	/// [Windows-950 (Chinese (traditional) Big5)](https://en.wikipedia.org/wiki/Code_page_950)
	Windows950
	/// [Windows-951 (Chinese (traditional) Big5-HKSCS)](https://en.wikipedia.org/wiki/Hong_Kong_Supplementary_Character_Set#Microsoft_Windows)
	Windows951
	/// [Windows-1250 (Latin 2)](https://en.wikipedia.org/wiki/Windows-1250)
	Windows1250
	/// [Windows-1251 (Cyrillic)](https://en.wikipedia.org/wiki/Windows-1251)
	Windows1251
	/// [Windows-1252 (Latin 1)](https://en.wikipedia.org/wiki/Windows-1252)
	Windows1252
	/// [Windows-1253 (Greek)](https://en.wikipedia.org/wiki/Windows-1253)
	Windows1253
	/// [Windows-1254 (Turkish)](https://en.wikipedia.org/wiki/Windows-1254)
	Windows1254
	/// [Windows-1255 (Hebrew)](https://en.wikipedia.org/wiki/Windows-1255)
	Windows1255
	/// [Windows-1256 (Arabic)](https://en.wikipedia.org/wiki/Windows-1256)
	Windows1256
	/// [Windows-1257 (Baltic)](https://en.wikipedia.org/wiki/Windows-1257)
	Windows1257
	/// [Windows-1258 (Vietnamese)](https://en.wikipedia.org/wiki/Windows-1258)
	Windows1258
	/// [Mac OS Roman](https://en.wikipedia.org/wiki/Mac_OS_Roman)
	MacintoshRoman
	/// [Macintosh
	/// Cyrillic](https://en.wikipedia.org/wiki/Macintosh_Cyrillic_encoding)
	MacintoshCyrillic
	/// [US-ASCII](https://en.wikipedia.org/wiki/ASCII)
	UsAscii
	/// [ISO-8859-1 (Latin 1)](https://en.wikipedia.org/wiki/ISO-8859-1)
	Iso88591
	/// [ISO-8859-2 (Latin 2)](https://en.wikipedia.org/wiki/ISO-8859-2)
	Iso88592
	/// [ISO-8859-3 (South European)](https://en.wikipedia.org/wiki/ISO-8859-3)
	Iso88593
	/// [ISO-8859-4 (North European)](https://en.wikipedia.org/wiki/ISO-8859-4)
	Iso88594
	/// [ISO-8859-5 (Cyrillic)](https://en.wikipedia.org/wiki/ISO-8859-5)
	Iso88595
	/// [ISO-8859-6 (Arabic)](https://en.wikipedia.org/wiki/ISO-8859-6)
	Iso88596
	/// [ISO-8859-7 (Greek)](https://en.wikipedia.org/wiki/ISO-8859-7)
	Iso88597
	/// [ISO-8859-8 (Hebrew)](https://en.wikipedia.org/wiki/ISO-8859-8)
	Iso88598
	/// [UTF-8](https://en.wikipedia.org/wiki/UTF-8)
	Utf8
)

func CodePageDefault

func CodePageDefault() CodePage

func CodePageFromID

func CodePageFromID(id int) CodePage

Returns the code page (if any) with the given ID number.

func (CodePage) Decode

func (c CodePage) Decode(data []byte) (string, error)

func (CodePage) Encoding

func (c CodePage) Encoding() encoding.Encoding

func (CodePage) ID

func (c CodePage) ID() int

Returns the ID number used within Windows to represent this code page.

type Column

type Column struct {
	Name             string
	ColumnType       ColumnType
	ColumnStringSize int
	IsLocalizable    bool
	IsNullable       bool
	IsPrimarykey     bool
	ValueRange       valueRange
	ForeignKey       foreignKey
	Category         Category
	EnumValues       []string
}

type ColumnBuilder

type ColumnBuilder struct {
	Name          string
	IsLocalizable bool
	IsNullable    bool
	IsPrimarykey  bool
	ValueRange    valueRange
	ForeignKey    foreignKey
	Category      Category
	EnumValues    []string
}

func NewColumnBuilder

func NewColumnBuilder(name string) *ColumnBuilder

func (*ColumnBuilder) Binary

func (b *ColumnBuilder) Binary() *Column

Builds a column that refers to a binary data stream.

func (*ColumnBuilder) FormattedString

func (b *ColumnBuilder) FormattedString(maxLen int) *Column

Builds a column that stores a formatted string.

func (*ColumnBuilder) IDString

func (b *ColumnBuilder) IDString(maxLen int) *Column

Builds a column that stores an identifier string.

func (*ColumnBuilder) Int16

func (b *ColumnBuilder) Int16() *Column

Makes the column only permit the given values.

func (*ColumnBuilder) Int32

func (b *ColumnBuilder) Int32() *Column

Makes the column only permit the given values.

func (*ColumnBuilder) SetCategory

func (b *ColumnBuilder) SetCategory(category Category) *ColumnBuilder

For string columns, makes the column use the specified data format.

func (*ColumnBuilder) SetEnumValues

func (b *ColumnBuilder) SetEnumValues(values ...string) *ColumnBuilder

Makes the column only permit the given values.

func (*ColumnBuilder) SetForeignKey

func (b *ColumnBuilder) SetForeignKey(tableName string, colIndex int32) *ColumnBuilder

Makes the column refer to a key column in another table.

func (*ColumnBuilder) SetLocalizable

func (b *ColumnBuilder) SetLocalizable() *ColumnBuilder

Makes the column be localizable.

func (*ColumnBuilder) SetNullable

func (b *ColumnBuilder) SetNullable() *ColumnBuilder

Makes the column allow null values.

func (*ColumnBuilder) SetPrimaryKey

func (b *ColumnBuilder) SetPrimaryKey() *ColumnBuilder

Makes the column be a primary key column.

func (*ColumnBuilder) SetRange

func (b *ColumnBuilder) SetRange(min, max int32) *ColumnBuilder

Makes the column only permit values in the given range.

func (*ColumnBuilder) String

func (b *ColumnBuilder) String(maxLen int) *Column

Builds a column that stores a string.

func (*ColumnBuilder) TextString

func (b *ColumnBuilder) TextString(maxLen int) *Column

Builds a column that stores a text string.

type ColumnType

type ColumnType int
const (
	ColumnTypeInt16 ColumnType = iota
	ColumnTypeInt32
	ColumnTypeStr
)

func ColumnTypeFromBitField

func ColumnTypeFromBitField(typeBits int32) (ColumnType, int, error)

func (ColumnType) ReadValue

func (c ColumnType) ReadValue(stream *mscfb.Stream, longStringRefs bool) (*ValueRef, error)

func (ColumnType) Width

func (c ColumnType) Width(longStringRefs bool) uint64

type MSIPackage

type MSIPackage struct {
	CompoundFile *mscfb.CompoundFile

	PackageType PackageType
	SummaryInfo *SummaryInfo
	StringPool  *StringPool
	Tables      map[string]*Table
}

func Open

func Open(rdr io.ReadSeeker) (*MSIPackage, error)

func (*MSIPackage) ReadStream

func (p *MSIPackage) ReadStream(streamName string) (io.ReadSeeker, error)

func (*MSIPackage) Streams

func (p *MSIPackage) Streams() *Streams

type OperatingSystem

type OperatingSystem int
const (
	Win16 OperatingSystem = iota
	Mac
	Win32
)

type PackageType

type PackageType int
const (
	// An installer package, which installs a new application.
	PackageTypeInstaller PackageType = iota
	// A patch package, which provides an update to an application.
	PackageTypePatch
	// A transform, which is a collection of changes applied to an installation.
	PackageTypeTransform
)

func PackageTypeFromCLSID

func PackageTypeFromCLSID(clsid uuid.UUID) PackageType

func (PackageType) CLSID

func (p PackageType) CLSID() uuid.UUID

func (PackageType) String

func (p PackageType) String() string

type PropertyFormatVersion

type PropertyFormatVersion uint16
const (
	PropertyFormatVersion0 PropertyFormatVersion = 0
	PropertyFormatVersion1 PropertyFormatVersion = 1
)

func (PropertyFormatVersion) VersionNumber

func (p PropertyFormatVersion) VersionNumber() int

type PropertySet

type PropertySet struct {
	OS        OperatingSystem
	OSVersion uint16
	CLSID     []byte
	FmtID     []byte
	CodePage  CodePage
	//todo: must be binary tree
	Properties map[uint32]*PropertyValue
}

func NewPropertySet

func NewPropertySet(os OperatingSystem, osVersion uint16, fmtId []byte) *PropertySet

func ReadPropertySet

func ReadPropertySet(reader *mscfb.Stream) (*PropertySet, error)

type PropertyValue

type PropertyValue struct {
	Empty    bool
	Null     bool
	I1       int8
	I2       int16
	I4       int32
	LpStr    string
	FileTime int64
}

func ReadPropValue

func ReadPropValue(rdr io.ReadSeeker, codePage CodePage) (*PropertyValue, error)

func (*PropertyValue) MinimumVersion

func (p *PropertyValue) MinimumVersion() PropertyFormatVersion

type Row

type Row struct {
	Table  *Table
	Values []Value
}

func NewRow

func NewRow(t *Table, values []Value) *Row

type Rows

type Rows struct {
	StringPool   *StringPool
	Table        *Table
	Rows         [][]*ValueRef
	NextRowIndex int
}

func NewRows

func NewRows(stringPool *StringPool, table *Table, rows [][]*ValueRef) *Rows

func (*Rows) Next

func (r *Rows) Next() *Row

type Streams

type Streams struct {
	Entries *mscfb.Entries
}

func NewStreams

func NewStreams(entries *mscfb.Entries) *Streams

func (*Streams) Next

func (s *Streams) Next() string

type StringPool

type StringPool struct {
	CodePage       CodePage
	Strings        []poolStrings
	LongStringRefs bool
	IsModified     bool
}

func (*StringPool) Get

func (s *StringPool) Get(ref StringRef) string

type StringPoolBuilder

type StringPoolBuilder struct {
	CodePage           CodePage
	LongStringRefs     bool
	LengthAndRefCounts []stringPoolLRC
}

func (*StringPoolBuilder) BuildFromData

func (pool *StringPoolBuilder) BuildFromData(stream *mscfb.Stream) (*StringPool, error)

func (*StringPoolBuilder) ReadFromPool

func (pool *StringPoolBuilder) ReadFromPool(stream *mscfb.Stream) error

type StringRef

type StringRef struct {
	Num int32
}

func (*StringRef) Index

func (s *StringRef) Index() int64

func (*StringRef) Read

func (s *StringRef) Read(reader *mscfb.Stream, longStringRefs bool) (StringRef, error)

type SummaryInfo

type SummaryInfo struct {
	Properties *PropertySet
}

func NewSummary

func NewSummary() *SummaryInfo

func (*SummaryInfo) ReadSummaryInfo

func (s *SummaryInfo) ReadSummaryInfo(reader *mscfb.Stream) (*SummaryInfo, error)

type Table

type Table struct {
	Name           string
	Columns        []*Column
	LongStringRefs bool
}

func NewTable

func NewTable(name string, columns []*Column, longStringRefs bool) *Table

func (*Table) ReadRows

func (t *Table) ReadRows(stream *mscfb.Stream) ([][]*ValueRef, error)

func (*Table) StreamName

func (t *Table) StreamName() string

type Value

type Value interface{}

type ValueRef

type ValueRef struct {
	IsNull bool
	IsInt  bool
	IsStr  bool

	Value interface{}
}

func (*ValueRef) ToValue

func (v *ValueRef) ToValue(pool *StringPool) Value

Directories

Path Synopsis
cmd
msi

Jump to

Keyboard shortcuts

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