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:
- Offset table – one
i32per TypeInfo, giving its byte offset inside the TypeInfo segment. - Extra field (4 bytes) – help-string-DLL offset when the
HELPDLLFLAGis set; empirically always present. - 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:
| Index | Contents |
|---|---|
| 0 | TypeInfo table – fixed-size (0x64 byte) entries |
| 1 | Import-info table – 12-byte entries referencing external typelibs |
| 2 | Import-files table – variable-length entries with library name, GUID, version |
| 3 | Reference table – 16-byte linked-list entries for coclass impl-types |
| 4 | GUID hash table – bucket array for fast GUID lookup |
| 5 | GUID table – 24-byte entries (16-byte GUID + hreftype + hash chain) |
| 6 | Name hash table – bucket array for fast name lookup |
| 7 | Name table – variable-length entries (12-byte header + name bytes) |
| 8 | String table – variable-length entries (2-byte length + string bytes) |
| 9 | Type-descriptor table – 8-byte entries encoding TYPEDESC trees |
| 10 | Array-descriptor table – variable-length ARRAYDESC entries |
| 11 | Custom-data table – variant-tagged values (2-byte VT + payload) |
| 12 | Custom-data GUID directory – 12-byte linked-list entries mapping GUIDs to custom data |
| 13–14 | Reserved (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
| Type | Description |
|---|---|
TypeLib | Main entry point and all lookup / iteration methods |
TypeInfoEntry | One type description (enum, struct, interface, …) |
FuncRecord | One function or property accessor |
VarRecord | One variable or constant |
ParameterInfo | One function parameter |
GuidEntry | One GUID-table entry |
RefRecord | One coclass-implements reference |
ImpInfo | One imported-typelib reference |
ImpFile | One imported-library file entry (name, version, GUID) |
ArrayDesc, SafeArrayBound | Array descriptor with per-dimension bounds |
CustDataEntry | One entry in the custom data GUID directory |
ResolvedHreftype | Result of resolving an hreftype (internal or external) |
TypeKind, ConstValue, vt_name | Shared enumerations and helpers |
Guid | 16-byte GUID display wrapper |
NameEntry | A decoded entry from the name table |
Error | Parse error type |
Structs§
- Array
Desc - Zero-copy view of a
VT_CARRAYarray descriptor. - Cust
Data Entry - One entry in the CDGuids directory (12 bytes).
- Cust
Data Iter - Iterator that walks a custom data chain in the CDGuids directory (segment 12).
- Func
Iter - Iterator over
FuncRecordvalues within a TypeInfo’s func/var data block. - Func
Record - Zero-copy view of a variable-length
MSFT_FuncRecord. - Guid
- Zero-copy view of a 16-byte COM GUID.
- Guid
Entry - Zero-copy view of an
MSFT_GuidEntry(24 bytes) in the GUID table. - Guid
Entry Iter - Iterator over
GuidEntryvalues in the GUID table segment. - ImpFile
- Zero-copy view of a variable-length import-file entry.
- ImpFile
Iter - Iterator over
ImpFileentries in the import-files segment (segment 2). - ImpInfo
- Zero-copy view of an
MSFT_ImpInfoimport record (12 bytes). - ImpInfo
Iter - Iterator over
ImpInfoentries in the import-info segment. - Impl
Type Iter - Iterator over implemented interfaces for a coclass (via
pRefTabchain). - Name
Entry - A decoded name table entry yielded by
NameIter. - Name
Iter - Iterator over entries in the name table segment.
- Param
Iter - Iterator over
ParameterInfoentries within aFuncRecord. - Parameter
Info - Zero-copy view of an
MSFT_ParameterInfo(12 bytes). - RefRecord
- Zero-copy view of a reference table entry (16 bytes).
- Safe
Array Bound - One dimension of a SAFEARRAY descriptor.
- Type
Info Entry - Zero-copy view of an
MSFT_TypeInfoBasestructure (0x64 bytes). - Type
Info Iter - Iterator over
TypeInfoEntryvalues in a type library. - TypeLib
- Zero-copy view over an MSFT-format type library file.
- VarIter
- Iterator over
VarRecordvalues within a TypeInfo’s func/var data block. - VarRecord
- Zero-copy view of a variable-length
MSFT_VarRecord.
Enums§
- Const
Value - A decoded constant value from a
VAR_CONSTvariable record or custom data. - Error
- Errors that can occur when parsing an MSFT type library.
- Resolved
Hreftype - The result of resolving an
hreftypeviaTypeLib::resolve_hreftype_full. - Type
Kind - The kind of a TypeInfo entry (low 4 bits of the
typekindfield).
Functions§
- vt_name
- Returns a human-readable VB-style name for a
VARTYPEcode.