Skip to main content

Crate msft_typelib

Crate msft_typelib 

Source
Expand description

Allocation-free parser for MSFT-format type library (.tlb) files.

MSFT is the binary format used by Microsoft COM type libraries since the late 1990s. A type library describes the interfaces, coclasses, enumerations, and constants exposed by a COM component so that tools and languages can use them at compile time or runtime.

Record types borrow directly from the input &[u8] and carry a lifetime that ties them to the original buffer. Parsing requires no heap allocations beyond what the caller performs to load the file; individual accessor methods return small scalar values by copy.

§Quick start

let data = std::fs::read("library.tlb").unwrap();
let lib = msft_typelib::TypeLib::parse(&data)?;
println!("TypeLib: {} ({} typeinfos)",
    lib.lib_name().unwrap_or("?"), lib.typeinfo_count());

§Binary format overview

An MSFT file begins with a 0x54-byte header (magic "MSFT", version, GUID offset, LCID, flags, etc.), followed by:

  1. Offset table – one i32 per TypeInfo, giving its byte offset inside the TypeInfo segment.
  2. Extra field (4 bytes) – help-string-DLL offset when the HELPDLLFLAG is set; empirically always present.
  3. Segment directory – 15 entries of 16 bytes each (offset: i32, length: i32, res08, res0c), pointing to the data segments that follow.

The 15 segments are:

IndexContents
0TypeInfo table – fixed-size (0x64 byte) entries
1Import-info table – 12-byte entries referencing external typelibs
2Import-files table – variable-length entries with library name, GUID, version
3Reference table – 16-byte linked-list entries for coclass impl-types
4GUID hash table – bucket array for fast GUID lookup
5GUID table – 24-byte entries (16-byte GUID + hreftype + hash chain)
6Name hash table – bucket array for fast name lookup
7Name table – variable-length entries (12-byte header + name bytes)
8String table – variable-length entries (2-byte length + string bytes)
9Type-descriptor table – 8-byte entries encoding TYPEDESC trees
10Array-descriptor table – variable-length ARRAYDESC entries
11Custom-data table – variant-tagged values (2-byte VT + payload)
12Custom-data GUID directory – 12-byte linked-list entries mapping GUIDs to custom data
13–14Reserved (always empty)

Each TypeInfo has a func/var data block at an absolute file offset. The block starts with a 4-byte size, followed by variable-length function and variable records, then auxiliary arrays containing MEMBERIDs and name-table offsets for each member.

§Public types

TypeDescription
TypeLibMain entry point and all lookup / iteration methods
TypeInfoEntryOne type description (enum, struct, interface, …)
FuncRecordOne function or property accessor
VarRecordOne variable or constant
ParameterInfoOne function parameter
GuidEntryOne GUID-table entry
RefRecordOne coclass-implements reference
ImpInfoOne imported-typelib reference
ImpFileOne imported-library file entry (name, version, GUID)
ArrayDesc, SafeArrayBoundArray descriptor with per-dimension bounds
CustDataEntryOne entry in the custom data GUID directory
ResolvedHreftypeResult of resolving an hreftype (internal or external)
TypeKind, ConstValue, vt_nameShared enumerations and helpers
Guid16-byte GUID display wrapper
NameEntryA decoded entry from the name table
ErrorParse error type

Structs§

ArrayDesc
Zero-copy view of a VT_CARRAY array descriptor.
CustDataEntry
One entry in the CDGuids directory (12 bytes).
CustDataIter
Iterator that walks a custom data chain in the CDGuids directory (segment 12).
FuncIter
Iterator over FuncRecord values within a TypeInfo’s func/var data block.
FuncRecord
Zero-copy view of a variable-length MSFT_FuncRecord.
Guid
Zero-copy view of a 16-byte COM GUID.
GuidEntry
Zero-copy view of an MSFT_GuidEntry (24 bytes) in the GUID table.
GuidEntryIter
Iterator over GuidEntry values in the GUID table segment.
ImpFile
Zero-copy view of a variable-length import-file entry.
ImpFileIter
Iterator over ImpFile entries in the import-files segment (segment 2).
ImpInfo
Zero-copy view of an MSFT_ImpInfo import record (12 bytes).
ImpInfoIter
Iterator over ImpInfo entries in the import-info segment.
ImplTypeIter
Iterator over implemented interfaces for a coclass (via pRefTab chain).
NameEntry
A decoded name table entry yielded by NameIter.
NameIter
Iterator over entries in the name table segment.
ParamIter
Iterator over ParameterInfo entries within a FuncRecord.
ParameterInfo
Zero-copy view of an MSFT_ParameterInfo (12 bytes).
RefRecord
Zero-copy view of a reference table entry (16 bytes).
SafeArrayBound
One dimension of a SAFEARRAY descriptor.
TypeInfoEntry
Zero-copy view of an MSFT_TypeInfoBase structure (0x64 bytes).
TypeInfoIter
Iterator over TypeInfoEntry values in a type library.
TypeLib
Zero-copy view over an MSFT-format type library file.
VarIter
Iterator over VarRecord values within a TypeInfo’s func/var data block.
VarRecord
Zero-copy view of a variable-length MSFT_VarRecord.

Enums§

ConstValue
A decoded constant value from a VAR_CONST variable record or custom data.
Error
Errors that can occur when parsing an MSFT type library.
ResolvedHreftype
The result of resolving an hreftype via TypeLib::resolve_hreftype_full.
TypeKind
The kind of a TypeInfo entry (low 4 bits of the typekind field).

Functions§

vt_name
Returns a human-readable VB-style name for a VARTYPE code.