7zFormat.txt 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. 7z Format description (2.30 Beta 25)
  2. -----------------------------------
  3. This file contains description of 7z archive format.
  4. 7z archive can contain files compressed with any method.
  5. See "Methods.txt" for description for defined compressing methods.
  6. Format structure Overview
  7. -------------------------
  8. Some fields can be optional.
  9. Archive structure
  10. ~~~~~~~~~~~~~~~~~
  11. SignatureHeader
  12. [PackedStreams]
  13. [PackedStreamsForHeaders]
  14. [
  15. Header
  16. or
  17. {
  18. Packed Header
  19. HeaderInfo
  20. }
  21. ]
  22. Header structure
  23. ~~~~~~~~~~~~~~~~
  24. {
  25. ArchiveProperties
  26. AdditionalStreams
  27. {
  28. PackInfo
  29. {
  30. PackPos
  31. NumPackStreams
  32. Sizes[NumPackStreams]
  33. CRCs[NumPackStreams]
  34. }
  35. CodersInfo
  36. {
  37. NumFolders
  38. Folders[NumFolders]
  39. {
  40. NumCoders
  41. CodersInfo[NumCoders]
  42. {
  43. ID
  44. NumInStreams;
  45. NumOutStreams;
  46. PropertiesSize
  47. Properties[PropertiesSize]
  48. }
  49. NumBindPairs
  50. BindPairsInfo[NumBindPairs]
  51. {
  52. InIndex;
  53. OutIndex;
  54. }
  55. PackedIndices
  56. }
  57. UnPackSize[Folders][Folders.NumOutstreams]
  58. CRCs[NumFolders]
  59. }
  60. SubStreamsInfo
  61. {
  62. NumUnPackStreamsInFolders[NumFolders];
  63. UnPackSizes[]
  64. CRCs[]
  65. }
  66. }
  67. MainStreamsInfo
  68. {
  69. (Same as in AdditionalStreams)
  70. }
  71. FilesInfo
  72. {
  73. NumFiles
  74. Properties[]
  75. {
  76. ID
  77. Size
  78. Data
  79. }
  80. }
  81. }
  82. HeaderInfo structure
  83. ~~~~~~~~~~~~~~~~~~~~
  84. {
  85. (Same as in AdditionalStreams)
  86. }
  87. Notes about Notation and encoding
  88. ---------------------------------
  89. 7z uses little endian encoding.
  90. 7z archive format has optional headers that are marked as
  91. []
  92. Header
  93. []
  94. REAL_UINT64 means real UINT64.
  95. UINT64 means real UINT64 encoded with the following scheme:
  96. Size of encoding sequence depends from first byte:
  97. First_Byte Extra_Bytes Value
  98. (binary)
  99. 0xxxxxxx : ( xxxxxxx )
  100. 10xxxxxx BYTE y[1] : ( xxxxxx << (8 * 1)) + y
  101. 110xxxxx BYTE y[2] : ( xxxxx << (8 * 2)) + y
  102. ...
  103. 1111110x BYTE y[6] : ( x << (8 * 6)) + y
  104. 11111110 BYTE y[7] : y
  105. 11111111 BYTE y[8] : y
  106. Property IDs
  107. ------------
  108. 0x00 = kEnd,
  109. 0x01 = kHeader,
  110. 0x02 = kArchiveProperties,
  111. 0x03 = kAdditionalStreamsInfo,
  112. 0x04 = kMainStreamsInfo,
  113. 0x05 = kFilesInfo,
  114. 0x06 = kPackInfo,
  115. 0x07 = kUnPackInfo,
  116. 0x08 = kSubStreamsInfo,
  117. 0x09 = kSize,
  118. 0x0A = kCRC,
  119. 0x0B = kFolder,
  120. 0x0C = kCodersUnPackSize,
  121. 0x0D = kNumUnPackStream,
  122. 0x0E = kEmptyStream,
  123. 0x0F = kEmptyFile,
  124. 0x10 = kAnti,
  125. 0x11 = kName,
  126. 0x12 = kCreationTime,
  127. 0x13 = kLastAccessTime,
  128. 0x14 = kLastWriteTime,
  129. 0x15 = kWinAttributes,
  130. 0x16 = kComment,
  131. 0x17 = kEncodedHeader,
  132. 7z format headers
  133. -----------------
  134. SignatureHeader
  135. ~~~~~~~~~~~~~~~
  136. BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
  137. ArchiveVersion
  138. {
  139. BYTE Major; // now = 0
  140. BYTE Minor; // now = 2
  141. };
  142. UINT32 StartHeaderCRC;
  143. StartHeader
  144. {
  145. REAL_UINT64 NextHeaderOffset
  146. REAL_UINT64 NextHeaderSize
  147. UINT32 NextHeaderCRC
  148. }
  149. ...........................
  150. ArchiveProperties
  151. ~~~~~~~~~~~~~~~~~
  152. BYTE NID::kArchiveProperties (0x02)
  153. for (;;)
  154. {
  155. BYTE PropertyType;
  156. if (aType == 0)
  157. break;
  158. UINT64 PropertySize;
  159. BYTE PropertyData[PropertySize];
  160. }
  161. Digests (NumStreams)
  162. ~~~~~~~~~~~~~~~~~~~~~
  163. BYTE AllAreDefined
  164. if (AllAreDefined == 0)
  165. {
  166. for(NumStreams)
  167. BIT Defined
  168. }
  169. UINT32 CRCs[NumDefined]
  170. PackInfo
  171. ~~~~~~~~~~~~
  172. BYTE NID::kPackInfo (0x06)
  173. UINT64 PackPos
  174. UINT64 NumPackStreams
  175. []
  176. BYTE NID::kSize (0x09)
  177. UINT64 PackSizes[NumPackStreams]
  178. []
  179. []
  180. BYTE NID::kCRC (0x0A)
  181. PackStreamDigests[NumPackStreams]
  182. []
  183. BYTE NID::kEnd
  184. Folder
  185. ~~~~~~
  186. UINT64 NumCoders;
  187. for (NumCoders)
  188. {
  189. BYTE
  190. {
  191. 0:3 DecompressionMethod.IDSize
  192. 4:
  193. 0 - IsSimple
  194. 1 - Is not simple
  195. 5:
  196. 0 - No Attributes
  197. 1 - There Are Attributes
  198. 7:
  199. 0 - Last Method in Alternative_Method_List
  200. 1 - There are more alternative methods
  201. }
  202. BYTE DecompressionMethod.ID[DecompressionMethod.IDSize]
  203. if (!IsSimple)
  204. {
  205. UINT64 NumInStreams;
  206. UINT64 NumOutStreams;
  207. }
  208. if (DecompressionMethod[0] != 0)
  209. {
  210. UINT64 PropertiesSize
  211. BYTE Properties[PropertiesSize]
  212. }
  213. }
  214. NumBindPairs = NumOutStreamsTotal - 1;
  215. for (NumBindPairs)
  216. {
  217. UINT64 InIndex;
  218. UINT64 OutIndex;
  219. }
  220. NumPackedStreams = NumInStreamsTotal - NumBindPairs;
  221. if (NumPackedStreams > 1)
  222. for(NumPackedStreams)
  223. {
  224. UINT64 Index;
  225. };
  226. Coders Info
  227. ~~~~~~~~~~~
  228. BYTE NID::kUnPackInfo (0x07)
  229. BYTE NID::kFolder (0x0B)
  230. UINT64 NumFolders
  231. BYTE External
  232. switch(External)
  233. {
  234. case 0:
  235. Folders[NumFolders]
  236. case 1:
  237. UINT64 DataStreamIndex
  238. }
  239. BYTE ID::kCodersUnPackSize (0x0C)
  240. for(Folders)
  241. for(Folder.NumOutStreams)
  242. UINT64 UnPackSize;
  243. []
  244. BYTE NID::kCRC (0x0A)
  245. UnPackDigests[NumFolders]
  246. []
  247. BYTE NID::kEnd
  248. SubStreams Info
  249. ~~~~~~~~~~~~~~
  250. BYTE NID::kSubStreamsInfo; (0x08)
  251. []
  252. BYTE NID::kNumUnPackStream; (0x0D)
  253. UINT64 NumUnPackStreamsInFolders[NumFolders];
  254. []
  255. []
  256. BYTE NID::kSize (0x09)
  257. UINT64 UnPackSizes[]
  258. []
  259. []
  260. BYTE NID::kCRC (0x0A)
  261. Digests[Number of streams with unknown CRC]
  262. []
  263. BYTE NID::kEnd
  264. Streams Info
  265. ~~~~~~~~~~~~
  266. []
  267. PackInfo
  268. []
  269. []
  270. CodersInfo
  271. []
  272. []
  273. SubStreamsInfo
  274. []
  275. BYTE NID::kEnd
  276. FilesInfo
  277. ~~~~~~~~~
  278. BYTE NID::kFilesInfo; (0x05)
  279. UINT64 NumFiles
  280. for (;;)
  281. {
  282. BYTE PropertyType;
  283. if (aType == 0)
  284. break;
  285. UINT64 Size;
  286. switch(PropertyType)
  287. {
  288. kEmptyStream: (0x0E)
  289. for(NumFiles)
  290. BIT IsEmptyStream
  291. kEmptyFile: (0x0F)
  292. for(EmptyStreams)
  293. BIT IsEmptyFile
  294. kAnti: (0x10)
  295. for(EmptyStreams)
  296. BIT IsAntiFile
  297. case kCreationTime: (0x12)
  298. case kLastAccessTime: (0x13)
  299. case kLastWriteTime: (0x14)
  300. BYTE AllAreDefined
  301. if (AllAreDefined == 0)
  302. {
  303. for(NumFiles)
  304. BIT TimeDefined
  305. }
  306. BYTE External;
  307. if(External != 0)
  308. UINT64 DataIndex
  309. []
  310. for(Definded Items)
  311. UINT32 Time
  312. []
  313. kNames: (0x11)
  314. BYTE External;
  315. if(External != 0)
  316. UINT64 DataIndex
  317. []
  318. for(Files)
  319. {
  320. wchar_t Names[NameSize];
  321. wchar_t 0;
  322. }
  323. []
  324. kAttributes: (0x15)
  325. BYTE AllAreDefined
  326. if (AllAreDefined == 0)
  327. {
  328. for(NumFiles)
  329. BIT AttributesAreDefined
  330. }
  331. BYTE External;
  332. if(External != 0)
  333. UINT64 DataIndex
  334. []
  335. for(Definded Attributes)
  336. UINT32 Attributes
  337. []
  338. }
  339. }
  340. Header
  341. ~~~~~~
  342. BYTE NID::kHeader (0x01)
  343. []
  344. ArchiveProperties
  345. []
  346. []
  347. BYTE NID::kAdditionalStreamsInfo; (0x03)
  348. StreamsInfo
  349. []
  350. []
  351. BYTE NID::kMainStreamsInfo; (0x04)
  352. StreamsInfo
  353. []
  354. []
  355. FilesInfo
  356. []
  357. BYTE NID::kEnd
  358. HeaderInfo
  359. ~~~~~~~~~~
  360. []
  361. BYTE NID::kEncodedHeader; (0x17)
  362. StreamsInfo for Encoded Header
  363. []
  364. ---
  365. End of document