Introduction
An import library tells the linker which functions a DLL exports. Older tools wrote full COFF objects with the import tables already built. Newer ones write a short form instead: a library member with a 20-byte header and two strings, from which the linker builds the rest.
Structure
0import header20 bytes20symbol name, zero-terminatedvaries…DLL name, zero-terminatedvaries
The header, IMPORT_OBJECT_HEADER:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 2 | Sig1 | 0: IMAGE_FILE_MACHINE_UNKNOWN |
| 2 | 2 | Sig2 | 0xFFFF |
| 4 | 2 | Version | The structure version, 0 |
| 6 | 2 | Machine | The processor the DLL is for |
| 8 | 4 | TimeDateStamp | When the file was made |
| 12 | 4 | SizeOfData | The size of the strings after the header |
| 16 | 2 | OrdinalOrHint | The ordinal when the name type says so; otherwise a hint for looking up the name |
| 18 | 2 | Flags | Bits 0 and 1: the import type. Bits 2 to 4: the name type. The rest is reserved. |
Import type
| Value | Constant | Meaning |
|---|---|---|
| 0 | IMPORT_OBJECT_CODE | Executable code |
| 1 | IMPORT_OBJECT_DATA | Data |
| 2 | IMPORT_OBJECT_CONST | Specified as CONST in the .def file |
Name type
| Value | Constant | Meaning |
|---|---|---|
| 0 | IMPORT_OBJECT_ORDINAL | Import by ordinal: OrdinalOrHint is the ordinal |
| 1 | IMPORT_OBJECT_NAME | The import name is the symbol name exactly |
| 2 | IMPORT_OBJECT_NAME_NOPREFIX | The symbol name without its leading ?, @ or (on x86) _ |
| 3 | IMPORT_OBJECT_NAME_UNDECORATE | As above, and cut at the first @ |
| 4 | IMPORT_OBJECT_NAME_EXPORTAS | The exported name is a third string after the DLL’s name |
Strings
The symbol’s public name comes first and the DLL’s name second, each ending in a zero byte. SizeOfData counts both. With name type 4 a third string gives the name to import.
Variants
- Windows COFF library – a Windows static or import library in the ar archive format
- Short import object – one member of an import library: a header and two strings
- OMF library – a library of OMF object modules from 16-bit compilers
Links
Reference
- PE Format – Microsoft’s specification, in its section on the import library format