Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

469 lines
7.4 KiB

  1. 7z Format description (4.59)
  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 = kCTime
  127. 0x13 = kATime
  128. 0x14 = kMTime
  129. 0x15 = kWinAttributes
  130. 0x16 = kComment
  131. 0x17 = kEncodedHeader
  132. 0x18 = kStartPos
  133. 0x19 = kDummy
  134. 7z format headers
  135. -----------------
  136. SignatureHeader
  137. ~~~~~~~~~~~~~~~
  138. BYTE kSignature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
  139. ArchiveVersion
  140. {
  141. BYTE Major; // now = 0
  142. BYTE Minor; // now = 2
  143. };
  144. UINT32 StartHeaderCRC;
  145. StartHeader
  146. {
  147. REAL_UINT64 NextHeaderOffset
  148. REAL_UINT64 NextHeaderSize
  149. UINT32 NextHeaderCRC
  150. }
  151. ...........................
  152. ArchiveProperties
  153. ~~~~~~~~~~~~~~~~~
  154. BYTE NID::kArchiveProperties (0x02)
  155. for (;;)
  156. {
  157. BYTE PropertyType;
  158. if (aType == 0)
  159. break;
  160. UINT64 PropertySize;
  161. BYTE PropertyData[PropertySize];
  162. }
  163. Digests (NumStreams)
  164. ~~~~~~~~~~~~~~~~~~~~~
  165. BYTE AllAreDefined
  166. if (AllAreDefined == 0)
  167. {
  168. for(NumStreams)
  169. BIT Defined
  170. }
  171. UINT32 CRCs[NumDefined]
  172. PackInfo
  173. ~~~~~~~~~~~~
  174. BYTE NID::kPackInfo (0x06)
  175. UINT64 PackPos
  176. UINT64 NumPackStreams
  177. []
  178. BYTE NID::kSize (0x09)
  179. UINT64 PackSizes[NumPackStreams]
  180. []
  181. []
  182. BYTE NID::kCRC (0x0A)
  183. PackStreamDigests[NumPackStreams]
  184. []
  185. BYTE NID::kEnd
  186. Folder
  187. ~~~~~~
  188. UINT64 NumCoders;
  189. for (NumCoders)
  190. {
  191. BYTE
  192. {
  193. 0:3 CodecIdSize
  194. 4: Is Complex Coder
  195. 5: There Are Attributes
  196. 6: Reserved
  197. 7: There are more alternative methods. (Not used anymore, must be 0).
  198. }
  199. BYTE CodecId[CodecIdSize]
  200. if (Is Complex Coder)
  201. {
  202. UINT64 NumInStreams;
  203. UINT64 NumOutStreams;
  204. }
  205. if (There Are Attributes)
  206. {
  207. UINT64 PropertiesSize
  208. BYTE Properties[PropertiesSize]
  209. }
  210. }
  211. NumBindPairs = NumOutStreamsTotal - 1;
  212. for (NumBindPairs)
  213. {
  214. UINT64 InIndex;
  215. UINT64 OutIndex;
  216. }
  217. NumPackedStreams = NumInStreamsTotal - NumBindPairs;
  218. if (NumPackedStreams > 1)
  219. for(NumPackedStreams)
  220. {
  221. UINT64 Index;
  222. };
  223. Coders Info
  224. ~~~~~~~~~~~
  225. BYTE NID::kUnPackInfo (0x07)
  226. BYTE NID::kFolder (0x0B)
  227. UINT64 NumFolders
  228. BYTE External
  229. switch(External)
  230. {
  231. case 0:
  232. Folders[NumFolders]
  233. case 1:
  234. UINT64 DataStreamIndex
  235. }
  236. BYTE ID::kCodersUnPackSize (0x0C)
  237. for(Folders)
  238. for(Folder.NumOutStreams)
  239. UINT64 UnPackSize;
  240. []
  241. BYTE NID::kCRC (0x0A)
  242. UnPackDigests[NumFolders]
  243. []
  244. BYTE NID::kEnd
  245. SubStreams Info
  246. ~~~~~~~~~~~~~~
  247. BYTE NID::kSubStreamsInfo; (0x08)
  248. []
  249. BYTE NID::kNumUnPackStream; (0x0D)
  250. UINT64 NumUnPackStreamsInFolders[NumFolders];
  251. []
  252. []
  253. BYTE NID::kSize (0x09)
  254. UINT64 UnPackSizes[]
  255. []
  256. []
  257. BYTE NID::kCRC (0x0A)
  258. Digests[Number of streams with unknown CRC]
  259. []
  260. BYTE NID::kEnd
  261. Streams Info
  262. ~~~~~~~~~~~~
  263. []
  264. PackInfo
  265. []
  266. []
  267. CodersInfo
  268. []
  269. []
  270. SubStreamsInfo
  271. []
  272. BYTE NID::kEnd
  273. FilesInfo
  274. ~~~~~~~~~
  275. BYTE NID::kFilesInfo; (0x05)
  276. UINT64 NumFiles
  277. for (;;)
  278. {
  279. BYTE PropertyType;
  280. if (aType == 0)
  281. break;
  282. UINT64 Size;
  283. switch(PropertyType)
  284. {
  285. kEmptyStream: (0x0E)
  286. for(NumFiles)
  287. BIT IsEmptyStream
  288. kEmptyFile: (0x0F)
  289. for(EmptyStreams)
  290. BIT IsEmptyFile
  291. kAnti: (0x10)
  292. for(EmptyStreams)
  293. BIT IsAntiFile
  294. case kCTime: (0x12)
  295. case kATime: (0x13)
  296. case kMTime: (0x14)
  297. BYTE AllAreDefined
  298. if (AllAreDefined == 0)
  299. {
  300. for(NumFiles)
  301. BIT TimeDefined
  302. }
  303. BYTE External;
  304. if(External != 0)
  305. UINT64 DataIndex
  306. []
  307. for(Definded Items)
  308. UINT64 Time
  309. []
  310. kNames: (0x11)
  311. BYTE External;
  312. if(External != 0)
  313. UINT64 DataIndex
  314. []
  315. for(Files)
  316. {
  317. wchar_t Names[NameSize];
  318. wchar_t 0;
  319. }
  320. []
  321. kAttributes: (0x15)
  322. BYTE AllAreDefined
  323. if (AllAreDefined == 0)
  324. {
  325. for(NumFiles)
  326. BIT AttributesAreDefined
  327. }
  328. BYTE External;
  329. if(External != 0)
  330. UINT64 DataIndex
  331. []
  332. for(Definded Attributes)
  333. UINT32 Attributes
  334. []
  335. }
  336. }
  337. Header
  338. ~~~~~~
  339. BYTE NID::kHeader (0x01)
  340. []
  341. ArchiveProperties
  342. []
  343. []
  344. BYTE NID::kAdditionalStreamsInfo; (0x03)
  345. StreamsInfo
  346. []
  347. []
  348. BYTE NID::kMainStreamsInfo; (0x04)
  349. StreamsInfo
  350. []
  351. []
  352. FilesInfo
  353. []
  354. BYTE NID::kEnd
  355. HeaderInfo
  356. ~~~~~~~~~~
  357. []
  358. BYTE NID::kEncodedHeader; (0x17)
  359. StreamsInfo for Encoded Header
  360. []
  361. ---
  362. End of document