Besides the header variables, classes and objects, a DWG file has several smaller sections. In R13 to R2000 some sit at fixed places found through the file header; from R2004 each is a named data section reached through the section map. This page follows chapters 11 to 19 and 21 to 27 of the Open Design Alliance’s Open Design Specification for .dwg files, version 5.4.1. Unless stated, these sections are byte streams, not bit streams, and little-endian.
- Object map (AcDb:Handles)
- Second file header (R13 to R2000)
- Auxiliary header (AcDb:AuxHeader)
- Preview (AcDb:Preview)
- Summary info (AcDb:SummaryInfo)
- App info (AcDb:AppInfo)
- File dependencies (AcDb:FileDepList)
- VBA project (AcDb:VBAProject)
- Revision history (AcDb:RevHistory)
- Security (AcDb:Security)
- Template (AcDb:Template)
- Object free space (AcDb:ObjFreeSpace)
- Empty section, padding, unknown section
- Data storage (AcDb:AcDsPrototype_1b)
Object map (AcDb:Handles)
The object map gives the location of every object. It is a list of handle and location pairs, split into sections:
- Start with a last handle of 0 and a last location of 0.
- Read a section size as a 2-byte big-endian short. A size of 2 (an empty section holding only its CRC) ends the map.
- Until the section’s data runs out, read pairs of modular chars: the handle’s offset from the last handle, then the location’s offset from the last location. Location offsets can be negative; handle offsets are not.
- Read the section’s CRC, most significant byte first.
Each section is at most 2032 bytes. In R13 to R2000 the locations are absolute file addresses. From R2004 the section is compressed, has the usual page header, and the locations are offsets into the AcDb:AcDbObjects section, starting at 0.
Second file header (R13 to R2000)
Near the end of an R13 to R2000 file is a second header repeating the section addresses and the handles of the main control objects:
| Type | Meaning |
|---|---|
| SN | Beginning sentinel D4 7B 21 CE 28 93 9F BF 53 24 40 09 12 3C AA 01 |
| RL | Size of this section |
| L | Location of this header (the start of its sentinel) |
| RC × 6 | AC1012 or AC1014 for R13 or R14 |
| RC × 6 | Six zeros |
| B × 4 | Four zero bits |
| RC × 4 | 18 78 01 04 for R13, 18 78 01 05 for R14 |
| RC, L, L | 0, header address, header size |
| RC, L, L | 1, class address, class data size |
| RC, L, L | 2, object map address, object map size |
| RC, L, L | 3, address and size of the unknown section |
| S | 14, the number of handle records that follow |
| RC, RC, RC × size | Each record: the number of valid bytes, the record number, then the handle bytes |
| RS | CRC |
| RC × 8 | R14 only: 8 bytes of junk, counted in the size at the start |
| SN | Ending sentinel 2B 84 DE 31 D7 6C 60 40 AC DB BF F6 ED C3 55 FE |
| Record | Handle of |
|---|---|
| 0 | HANDSEED |
| 1 | Block control object |
| 2 | Layer control object |
| 3 | Shapefile (style) control object |
| 4 | Linetype control object |
| 5 | View control object |
| 6 | UCS control object |
| 7 | Vport control object |
| 8 | Registered application (APPID) control object |
| 9 | Dimstyle control object |
| 10 | Viewport entity header control object |
| 11 | Named objects dictionary |
| 12 | Default multi-line style |
| 13 | Group dictionary |
Auxiliary header (AcDb:AuxHeader)
Introduced with R2000 (R15), mostly redundant information:
| Type | Meaning |
|---|---|
| RC × 3 | FF 77 01 |
| RS | DWG version (codes below) |
| RS | Maintenance version |
| RL | Number of saves, from 1 |
| RL | −1 |
| RS | Number of saves part 1: number of saves − part 2 |
| RS | Number of saves part 2: number of saves − 0x7FFF if that is above 0x7FFF, otherwise 0 |
| RL | 0 |
| RS, RS | DWG version, maintenance version |
| RS, RS | DWG version, maintenance version |
| RS × 6 | 0x0005, 0x0893, 0x0005, 0x0893, 0x0000, 0x0001 |
| RL × 5 | 0 |
| TD | TDCREATE, creation date and time |
| TD | TDUPDATE, update date and time |
| RL | HANDSEED if below 0x7FFFFFFF, otherwise −1 |
| RL | Educational plot stamp (default 0) |
| RS | 0 |
| RS | Number of saves part 1 − number of saves part 2 |
| RL × 3 | 0 |
| RL | Number of saves |
| RL × 4 | 0 |
| RS × 3 | R2018+: 0 |
| Code | Version | Code | Version |
|---|---|---|---|
| 17 | AC1010 | 26 | AC1021 beta |
| 18 | AC1011 | 27 | AC1021 |
| 19 | AC1012 | 28 | AC1024 beta |
| 20 | AC1013 | 29 | AC1024 |
| 21 | AC1014 | 30 | AC1027 beta |
| 22 | AC1015 beta | 31 | AC1027 |
| 23 | AC1015 | 32 | AC1032 beta |
| 24 | AC1018 beta | 33 | AC1032 |
| 25 | AC1018 |
Preview (AcDb:Preview)
Before R13 C3 the preview image follows the classes; from R13 C3 it is at the end of the file, at the address in the file header. From R2004 it is the AcDb:Preview section (uncompressed; page size 0x400 when there is no image). It holds a BMP or, sometimes, WMF image:
| Type | Meaning |
|---|---|
| SN | Start sentinel 1F 25 6D 07 D4 36 28 28 9D 57 CA 3F 9D 44 10 2B |
| RL | Overall size of the image area |
| RC | Number of entries that follow |
| RC, RL, RL | Each entry: a code, a start address and a size. Code 1 header data, 2 BMP, 3 WMF |
| RC × size | BMP data, if present |
| RC × size | WMF data, if present |
| SN | End sentinel E0 DA 92 F8 2B C9 D7 D7 62 A8 35 C0 62 BB EF D4 |
Summary info (AcDb:SummaryInfo)
Uncompressed, page size 0x100, encrypted only when properties are. Strings are a 16-bit length followed by the characters, zero-terminated.
| Type | Size | Meaning |
|---|---|---|
| String | 2 + n | Title |
| String | 2 + n | Subject |
| String | 2 + n | Author |
| String | 2 + n | Keywords |
| String | 2 + n | Comments |
| String | 2 + n | Last saved by |
| String | 2 + n | Revision number |
| String | 2 + n | Hyperlink base |
| ? | 8 | Total editing time (the ODA writes two zero Int32s) |
| Julian date | 8 | Creation date and time |
| Julian date | 8 | Modification date and time |
| Int16 | 2 + pairs | Property count, then that many key and value string pairs |
| Int32 | 4 | Unknown (write 0) |
| Int32 | 4 | Unknown (write 0) |
App info (AcDb:AppInfo)
Optional; describes the application that wrote the file. Its layout depends on the application version in the file header, so an R2004 file may have an R2007 app info section.
R2004 layout
Strings are a 16-bit length and zero-terminated bytes.
| Type | Size | Meaning |
|---|---|---|
| String | 2 + n | App info name; the ODA writes AppInfoDataList |
| UInt32 | 4 | Unknown (the ODA writes 2) |
| String | 2 + n | Unknown (the ODA writes 4001) |
| String | 2 + n | Product XML element, e.g. <ProductInformation name ="Teigha" build_version="0.0" registry_version="3.3" install_id_string="ODA" registry_localeID="1033"/> |
| String | 2 + n | App info version, e.g. 2.7.2.0 |
R2007, R2010 and R2013 layout
Strings are a 16-bit length and UTF-16 characters with a zero terminator.
| Type | Size | Meaning |
|---|---|---|
| UInt32 | 4 | Unknown (the ODA writes 2) |
| String | 2 + 2n + 2 | App info name, AppInfoDataList |
| UInt32 | 4 | Unknown (the ODA writes 3) |
| Byte[16] | 16 | Version data (checksum; the ODA writes zeros) |
| String | 2 + 2n + 2 | Version |
| Byte[16] | 16 | Comment data (checksum) |
| String | 2 + 2n + 2 | Comment |
| Byte[16] | 16 | Product data (checksum) |
| String | 2 + 2n + 2 | Product |
| String | 2 + n | App info version |
File dependencies (AcDb:FileDepList)
Files the drawing depends on, such as images and fonts. Strings are a 32-bit length and the bytes, without a terminator.
| Type | Size | Meaning |
|---|---|---|
| Int32 | 4 | Feature count |
| String32 | 4 + n each | Feature names: Acad:XRef (block table record), Acad:Image (image definition), Acad:PlotConfig (plot setting), Acad:Text (text style) |
| Int32 | 4 | File count |
Then for each file (the feature name and full file name together identify it):
| Type | Size | Meaning |
|---|---|---|
| String32 | 4 + n | Full file name |
| String32 | 4 + n | Found path, where the file was found |
| String32 | 4 + n | Fingerprint GUID (xrefs only) |
| String32 | 4 + n | Version GUID (xrefs only) |
| Int32 | 4 | Index into the feature list |
| Int32 | 4 | Time stamp, seconds since 1 January 1980 |
| Int32 | 4 | File size |
| Int16 | 2 | Affects graphics: 1 true, 0 false |
| Int32 | 4 | Reference count |
VBA project (AcDb:VBAProject)
Optional and not understood; the ODA copies it as is. It holds 16 bytes
00 00 00 00 00 00 00 00 00 1C 00 00 19 00 00 00, the VBA project data
and a zero Int32.
Revision history (AcDb:RevHistory)
Compressed; contents unknown. The ODA writes three zero UInt32s in R2004, and UInt32s 0, 0, 1, 0 in R2007. More unknown bytes may follow.
Security (AcDb:Security)
Present only when the file was saved with a password (in R2004, when the security type at 0x18 of the file header is above 0). Strings are a 32-bit length and bytes without a terminator.
| Type | Size | Meaning |
|---|---|---|
| Int32 | 4 | Unknown (the ODA writes 0x0C) |
| Int32 | 4 | Unknown (the ODA writes 0) |
| Int32 | 4 | Unknown (the ODA writes 0xABCDABCD) |
| UInt32 | 4 | Cryptographic provider ID |
| String32 | 4 + n | Cryptographic provider name |
| UInt32 | 4 | Algorithm ID |
| UInt32 | 4 | Encryption key length |
| Int32 | 4 | Size of the buffer that follows |
| Byte[] | n | The encrypted test string |
The algorithm is RC4, in R2004 and R2007. The password, as 2-byte Unicode
characters, is hashed with MD5 and a session key is derived from the hash without
salt; the default key length is 40, and a sample provider is ID 0x0D, “Microsoft
Base DSS and Diffie-Hellman Cryptographic Provider”. The password is right if the
test buffer decrypts to SamirBajajSamirB.
Template (AcDb:Template)
Optional in R13 to R2000 (section locator 4), required from R2004. It holds only the MEASUREMENT variable:
| Type | Size | Meaning |
|---|---|---|
| Int16 | 2 | Length of the template description in bytes (the ODA writes 0) |
| Byte[] | n | Template description in the drawing’s code page |
| UInt16 | 2 | MEASUREMENT: 0 English, 1 metric |
Object free space (AcDb:ObjFreeSpace)
Not fully understood; the ODA can write a valid one.
| Type | Size | Meaning |
|---|---|---|
| Int32 | 4 | 0 |
| UInt32 | 4 | Approximate number of objects (handles) |
| Julian date | 8 | TDUPDATE |
| UInt32 | 4 | Offset of the objects section in the stream |
| UInt8 | 1 | Number of 64-bit values that follow (the ODA writes 4) |
| UInt32 × 8 | 32 | The ODA writes 0x32, 0, 0x64, 0, 0x200, 0, 0xFFFFFFFF, 0 |
Empty section, padding and unknown section
Empty section (R2004 and later): name “”, section ID always 0, compressed, page size 0x7400, no data.
Padding (R13 C3 and later): can be ignored; the ODA writes zeros. AutoCAD occasionally stores the MEASUREMENT value in its first 4 bytes. It let versions before R13 C3 read later files.
Unknown section (section locator 3, R13 C3
to R2000): 53 bytes, largely unknown. The ODA writes a zero long, then the number of
object map entries + 3 as a long, then 45 bytes of known-good data
(A7 62 25 00 F6 AF 25 02 3B 04 00 00 04 32 00 00 00 00 00 00 00 64 00 00 00
00 00 00 00 00 02 00 00 00 00 00 00 FF FF FF FF 00 00 00 00), then puts the
start address of the objects at offset 16.
Data storage (AcDb:AcDsPrototype_1b)
Added in R2013; in December 2012 it held ACIS data for regions and solids. It is a byte stream of segments, each padded with 0x70 bytes to a multiple of 0x40 (AutoCAD uses 0x80).
File header
| Type | Meaning |
|---|---|
| UInt32 | File signature |
| Int32 | File header size |
| Int32 | Unknown 1 (always 2?) |
| Int32 | Version (always 2?) |
| Int32 | Unknown 2 (always 0?) |
| Int32 | Data storage revision |
| Int32 | Segment index offset, from the start of the data store |
| Int32 | Segment index unknown |
| Int32 | Segment index entry count |
| Int32 | Schema index segment index |
| Int32 | Data index segment index |
| Int32 | Search segment index |
| Int32 | Previous save index |
| Int32 | File size |
Segment header
| Type | Meaning |
|---|---|
| Int16 | Signature (always 0xD5AC?) |
| byte[6] | Name: segidx segment index, datidx data index, _data_ data, schidx schema index, schdat schema data, search search, blob01 blob page |
| Int32 | Segment index |
| Int32 | Unknown 1 (0 or 1; 1 in blob01 segments) |
| Int32 | Segment size |
| Int32 | Unknown 2 (always 0?) |
| Int32 | Data storage revision |
| Int32 | Unknown 3 (always 0?) |
| Int32 | System data alignment offset (shift left 4 and add to the segment start; used by schema segments) |
| Int32 | Object data alignment offset (likewise; used by data segments) |
| byte[8] | Alignment bytes (always 0x55?) |
Segment types
| Segment | Contents |
|---|---|
segidx | For each segment: offset (UInt64, from the data store start) and size (UInt32) |
datidx | Entry count, an unknown Int32, then per entry: segment index (0 is a stub), local offset into that data segment, schema index (UInt32 each) |
_data_ | Record headers (entry size, unknown 1, handle UInt64, local offset), then the records: a UInt32 data size and the bytes, or, when the size is 0xBB106BB1, a blob reference (total size UInt64, page count, record size, page size, last page size, two unknowns, then a segment index and size per page). Records up to 0x40000 bytes are stored directly |
blob01 | One page of a blob: total size (UInt64), page start offset (UInt64), page index, page count (Int32), page data size (UInt64) and the data; at most 0xFFFB0 bytes per page |
schidx | Unknown property entries (index, segment index, local offset), an unknown Int64 0x0AF10C, then property entries (segment index, local offset, index) |
schdat | Unknown properties (data size, flags), schemas, and a list of zero-terminated property names |
search | Schema search data; may be ignored when reading, but AutoCAD ignores an entity whose search data is missing |
Each ACIS entity’s data record is its SAB stream, starting with
ACIS BinaryFile. When made from SAT, it ends with
End-of-ASM-data for ACIS version 21800 and later, otherwise
End-of-ACIS-data. A schema property has flags (UInt32: 1 unknown, 2 no
type, 8 unknown), a name index, a type 0 to 15 (0xE means a custom size follows;
otherwise the size is looked up in 0, 0, 2, 1, 2, 4, 8, 1, 2, 4, 8, 4, 8, 0, 0, 0),
a value count and the value. Section 24.3 of the specification shows the default
contents of an empty data store.
Not confirmed
- The VBA project, revision history and unknown section contents, and most of the object free space and data storage values, are unknown; the specification describes what the ODA writes.
- The padding size is 200 or 0x200 bytes; the specification gives both.
- The AcDb:Security layout is given for R2004 and said to be the same in R2007; it is not described for later versions.
- The TD (date) type of the auxiliary header and the “Julian date” of the summary info are not defined further.
Sources
- Open Design Specification for .dwg files, version 5.4.1 – Open Design Alliance; chapters 11 to 19 and 21 to 27