複合二進制文件
外觀
複合二進制文檔(CFBF),簡稱複合文檔,[1]英文全名 Composite Document File V2 Document[2],是微軟開發、用於實現COM結構化存儲的文件格式,用於把多個對象內容存放在同一個硬盤文件。[3][4][5]
Microsoft已經開放了這個文件格式。廣泛用於Microsoft Word與Microsoft Access。也是Advanced Authoring Format的基礎。[6]
文件結構
[編輯]CFBF文件頭部是512字節,隨後跟着是保存數據的扇區。扇區的長度在文件頭部指定,通常是512字節或4096字節。
CFBF的扇區類型:
- FAT扇區
- MiniFAT扇區:用於Mini-Stream
- Double-Indirect FAT (DIFAT)扇區 - 包含FAT扇區索引的鍊表數據
- Directory扇區
- Stream扇區 - 包含數據內容
- Range Lock扇區 - 包含大文件的上鎖的字節範圍
CFBF文件頭
[編輯]CFBF頭是該文件的最前的512字節。對應於C語言數據結構為:
typedef unsigned long ULONG; // 4 Bytes
typedef unsigned short USHORT; // 2 Bytes
typedef short OFFSET; // 2 Bytes
typedef ULONG SECT; // 4 Bytes
typedef ULONG FSINDEX; // 4 Bytes
typedef USHORT FSOFFSET; // 2 Bytes
typedef USHORT WCHAR; // 2 Bytes
typedef ULONG DFSIGNATURE; // 4 Bytes
typedef unsigned char BYTE; // 1 Byte
typedef unsigned short WORD; // 2 Bytes
typedef unsigned long DWORD; // 4 Bytes
typedef ULONG SID; // 4 Bytes
typedef GUID CLSID; // 16 Bytes
struct StructuredStorageHeader { // [offset from start (bytes), length (bytes)]
BYTE _abSig[8]; // [00H,08] {0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1,
// 0x1a, 0xe1} for current version
CLSID _clsid; // [08H,16] reserved must be zero (WriteClassStg/
// GetClassFile uses root directory class id)
USHORT _uMinorVersion; // [18H,02] minor version of the format: 33 is
// written by reference implementation
USHORT _uDllVersion; // [1AH,02] major version of the dll/format: 3 for
// 512-byte sectors, 4 for 4 KB sectors
USHORT _uByteOrder; // [1CH,02] 0xFFFE: indicates Intel byte-ordering
USHORT _uSectorShift; // [1EH,02] size of sectors in power-of-two;
// typically 9 indicating 512-byte sectors
USHORT _uMiniSectorShift; // [20H,02] size of mini-sectors in power-of-two;
// typically 6 indicating 64-byte mini-sectors
USHORT _usReserved; // [22H,02] reserved, must be zero
ULONG _ulReserved1; // [24H,04] reserved, must be zero
FSINDEX _csectDir; // [28H,04] must be zero for 512-byte sectors,
// number of SECTs in directory chain for 4 KB
// sectors
FSINDEX _csectFat; // [2CH,04] number of SECTs in the FAT chain
SECT _sectDirStart; // [30H,04] first SECT in the directory chain
DFSIGNATURE _signature; // [34H,04] signature used for transactions; must
// be zero. The reference implementation
// does not support transactions
ULONG _ulMiniSectorCutoff; // [38H,04] maximum size for a mini stream;
// typically 4096 bytes
SECT _sectMiniFatStart; // [3CH,04] first SECT in the MiniFAT chain
FSINDEX _csectMiniFat; // [40H,04] number of SECTs in the MiniFAT chain
SECT _sectDifStart; // [44H,04] first SECT in the DIFAT chain
FSINDEX _csectDif; // [48H,04] number of SECTs in the DIFAT chain
SECT _sectFat[109]; // [4CH,436] the SECTs of first 109 FAT sectors
};
FAT扇區
[編輯]每個FAT條目長度4字節,包含下個FAT鍊表條目的扇區號,或下述特定值:
- FREESECT (0xFFFFFFFF) - 未用扇區
- ENDOFCHAIN (0xFFFFFFFE) - FAT鍊表最後一個扇區
- FATSECT (0xFFFFFFFD) - 用於FAT數據存儲
- DIFSECT (0xFFFFFFFC) - 用於DIFAT數據存儲
詞彙表
[編輯]- FAT - 文件分配表,也稱 SAT - 扇區分配表
- DIFAT - Double-Indirect File Allocation Table
- FAT Chain - 一群FAT條目指出分配給一個流的那些扇區
- Stream - 一個數據對象的內容
- Sector - 扇區,占據512或4096個字節
參見
[編輯]參考文獻
[編輯]- ^ Apache POI - POIFS. POI Project. [10 May 2011]. (原始內容存檔於2011-04-26).
- ^ How to convert documents between LibreOffice and Microsoft Office file formats on Linux. [25 Nov 2016]. (原始內容存檔於2019-09-21).
- ^ Compound Files (Windows). Microsoft Developers Network (MSDN) library – COM SDK. Microsoft Corporation. 20 November 2008 [23 September 2009]. (原始內容存檔於2016-03-07).
- ^ Containers: Compound Files. Microsoft Developers Network (MSDN) library – Visual Studio 2008 documentation. Microsoft Corporation. [23 September 2009]. (原始內容存檔於2012-10-18).
- ^ Understand Compound Files. Microsoft Developers Network (MSDN) library – ActiveDirectory Rights Management. 25 June 2009 [23 September 2009]. (原始內容存檔於2016-03-09).
- ^ AMW Association (formerly AAF Association) 網際網路檔案館的存檔,存檔日期15 August 2000.
外部連結
[編輯]- Microsoft Compound Document File Format (PDF). OpenOffice.org CFBF description. [2006-05-22]. (原始內容存檔 (PDF)於2011-10-12).
- Advanced Authoring Format Low-Level Container Specification (PDF). Microsoft Structured Storage version 3 specification (PDF). [2006-05-22]. (原始內容 (PDF)存檔於2011-08-09).