seven-zip 1.4.2 → 1.7.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (887) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +49 -0
  3. data/.github/workflows/release.yml +21 -0
  4. data/README.md +13 -2
  5. data/Rakefile +2 -0
  6. data/ext/p7zip/C/7zBuf.h +4 -8
  7. data/ext/p7zip/C/7zBuf2.c +9 -3
  8. data/ext/p7zip/C/7zCrc.c +84 -32
  9. data/ext/p7zip/C/7zCrc.h +2 -2
  10. data/ext/p7zip/C/7zCrcOpt.c +89 -8
  11. data/ext/p7zip/C/7zStream.c +4 -2
  12. data/ext/p7zip/C/{Types.h → 7zTypes.h} +8 -6
  13. data/ext/p7zip/C/7zVersion.h +21 -6
  14. data/ext/p7zip/C/Aes.c +28 -15
  15. data/ext/p7zip/C/Aes.h +2 -2
  16. data/ext/p7zip/C/Alloc.c +60 -12
  17. data/ext/p7zip/C/Alloc.h +6 -7
  18. data/ext/p7zip/C/Bcj2.c +256 -0
  19. data/ext/p7zip/C/Bcj2.h +146 -0
  20. data/ext/p7zip/C/Bcj2Enc.c +312 -0
  21. data/ext/p7zip/C/Blake2.h +48 -0
  22. data/ext/p7zip/C/Blake2s.c +244 -0
  23. data/ext/p7zip/C/Bra.c +2 -0
  24. data/ext/p7zip/C/Bra.h +4 -8
  25. data/ext/p7zip/C/Bra86.c +48 -51
  26. data/ext/p7zip/C/BraIA64.c +3 -1
  27. data/ext/p7zip/C/BwtSort.c +3 -4
  28. data/ext/p7zip/C/BwtSort.h +4 -8
  29. data/ext/p7zip/C/Compiler.h +32 -0
  30. data/ext/p7zip/C/CpuArch.c +50 -7
  31. data/ext/p7zip/C/CpuArch.h +112 -41
  32. data/ext/p7zip/C/Delta.c +2 -0
  33. data/ext/p7zip/C/Delta.h +4 -8
  34. data/ext/p7zip/C/HuffEnc.c +8 -6
  35. data/ext/p7zip/C/HuffEnc.h +4 -8
  36. data/ext/p7zip/C/LzFind.c +391 -108
  37. data/ext/p7zip/C/LzFind.h +20 -18
  38. data/ext/p7zip/C/LzFindMt.c +100 -90
  39. data/ext/p7zip/C/LzFindMt.h +4 -8
  40. data/ext/p7zip/C/LzHash.h +23 -20
  41. data/ext/p7zip/C/Lzma2Dec.c +48 -26
  42. data/ext/p7zip/C/Lzma2Dec.h +4 -8
  43. data/ext/p7zip/C/Lzma2Enc.c +58 -15
  44. data/ext/p7zip/C/Lzma2Enc.h +3 -7
  45. data/ext/p7zip/C/{LzmaUtil/Lzma86Enc.h → Lzma86.h} +47 -14
  46. data/ext/p7zip/C/{LzmaUtil/Lzma86Dec.c → Lzma86Dec.c} +6 -13
  47. data/ext/p7zip/C/{LzmaUtil/Lzma86Enc.c → Lzma86Enc.c} +8 -15
  48. data/ext/p7zip/C/LzmaDec.c +180 -79
  49. data/ext/p7zip/C/LzmaDec.h +4 -8
  50. data/ext/p7zip/C/LzmaEnc.c +230 -147
  51. data/ext/p7zip/C/LzmaEnc.h +6 -8
  52. data/ext/p7zip/C/MtCoder.c +3 -3
  53. data/ext/p7zip/C/Ppmd.h +5 -5
  54. data/ext/p7zip/C/Ppmd7.c +9 -7
  55. data/ext/p7zip/C/Ppmd7.h +3 -3
  56. data/ext/p7zip/C/Ppmd7Dec.c +2 -0
  57. data/ext/p7zip/C/Ppmd7Enc.c +4 -2
  58. data/ext/p7zip/C/Ppmd8.c +34 -31
  59. data/ext/p7zip/C/Ppmd8.h +5 -1
  60. data/ext/p7zip/C/Ppmd8Dec.c +2 -0
  61. data/ext/p7zip/C/Ppmd8Enc.c +2 -0
  62. data/ext/p7zip/C/Precomp.h +10 -0
  63. data/ext/p7zip/C/RotateDefs.h +11 -1
  64. data/ext/p7zip/C/Sha1.c +340 -0
  65. data/ext/p7zip/C/Sha1.h +38 -0
  66. data/ext/p7zip/C/Sha256.c +107 -63
  67. data/ext/p7zip/C/Sha256.h +2 -2
  68. data/ext/p7zip/C/Sort.c +59 -11
  69. data/ext/p7zip/C/Sort.h +8 -10
  70. data/ext/p7zip/C/Threads.h +1 -1
  71. data/ext/p7zip/C/Xz.c +7 -5
  72. data/ext/p7zip/C/Xz.h +40 -17
  73. data/ext/p7zip/C/XzCrc64.c +69 -16
  74. data/ext/p7zip/C/XzCrc64.h +2 -2
  75. data/ext/p7zip/C/XzCrc64Opt.c +69 -0
  76. data/ext/p7zip/C/XzDec.c +93 -55
  77. data/ext/p7zip/C/XzEnc.c +206 -165
  78. data/ext/p7zip/C/XzEnc.h +23 -9
  79. data/ext/p7zip/C/XzIn.c +50 -43
  80. data/ext/p7zip/CPP/7zip/Archive/7z/7zCompressionMode.h +37 -13
  81. data/ext/p7zip/CPP/7zip/Archive/7z/7zDecode.cpp +392 -181
  82. data/ext/p7zip/CPP/7zip/Archive/7z/7zDecode.h +29 -29
  83. data/ext/p7zip/CPP/7zip/Archive/7z/7zEncode.cpp +424 -212
  84. data/ext/p7zip/CPP/7zip/Archive/7z/7zEncode.h +53 -16
  85. data/ext/p7zip/CPP/7zip/Archive/7z/7zExtract.cpp +312 -174
  86. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderInStream.cpp +74 -61
  87. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderInStream.h +22 -19
  88. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandler.cpp +505 -232
  89. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandler.h +70 -16
  90. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandlerOut.cpp +602 -172
  91. data/ext/p7zip/CPP/7zip/Archive/7z/7zHeader.cpp +5 -0
  92. data/ext/p7zip/CPP/7zip/Archive/7z/7zHeader.h +54 -3
  93. data/ext/p7zip/CPP/7zip/Archive/7z/7zIn.cpp +981 -616
  94. data/ext/p7zip/CPP/7zip/Archive/7z/7zIn.h +275 -89
  95. data/ext/p7zip/CPP/7zip/Archive/7z/7zItem.h +77 -162
  96. data/ext/p7zip/CPP/7zip/Archive/7z/7zOut.cpp +288 -238
  97. data/ext/p7zip/CPP/7zip/Archive/7z/7zOut.h +189 -20
  98. data/ext/p7zip/CPP/7zip/Archive/7z/7zProperties.cpp +59 -49
  99. data/ext/p7zip/CPP/7zip/Archive/7z/7zRegister.cpp +12 -9
  100. data/ext/p7zip/CPP/7zip/Archive/7z/7zSpecStream.cpp +4 -6
  101. data/ext/p7zip/CPP/7zip/Archive/7z/7zSpecStream.h +5 -5
  102. data/ext/p7zip/CPP/7zip/Archive/7z/7zUpdate.cpp +1743 -447
  103. data/ext/p7zip/CPP/7zip/Archive/7z/7zUpdate.h +61 -10
  104. data/ext/p7zip/CPP/7zip/Archive/ApmHandler.cpp +84 -120
  105. data/ext/p7zip/CPP/7zip/Archive/ArHandler.cpp +854 -0
  106. data/ext/p7zip/CPP/7zip/Archive/ArchiveExports.cpp +48 -32
  107. data/ext/p7zip/CPP/7zip/Archive/ArjHandler.cpp +519 -340
  108. data/ext/p7zip/CPP/7zip/Archive/Bz2Handler.cpp +223 -203
  109. data/ext/p7zip/CPP/7zip/Archive/Cab/CabBlockInStream.cpp +50 -139
  110. data/ext/p7zip/CPP/7zip/Archive/Cab/CabBlockInStream.h +17 -18
  111. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHandler.cpp +566 -234
  112. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHandler.h +10 -1
  113. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHeader.cpp +2 -2
  114. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHeader.h +12 -15
  115. data/ext/p7zip/CPP/7zip/Archive/Cab/CabIn.cpp +341 -122
  116. data/ext/p7zip/CPP/7zip/Archive/Cab/CabIn.h +81 -66
  117. data/ext/p7zip/CPP/7zip/Archive/Cab/CabItem.h +17 -14
  118. data/ext/p7zip/CPP/7zip/Archive/Cab/CabRegister.cpp +10 -4
  119. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHandler.cpp +190 -83
  120. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHandler.h +7 -1
  121. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmIn.cpp +292 -174
  122. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmIn.h +73 -47
  123. data/ext/p7zip/CPP/7zip/Archive/ComHandler.cpp +886 -0
  124. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2.cpp +994 -71
  125. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2.h +364 -101
  126. data/ext/p7zip/CPP/7zip/Archive/Common/DummyOutStream.cpp +7 -12
  127. data/ext/p7zip/CPP/7zip/Archive/Common/DummyOutStream.h +4 -3
  128. data/ext/p7zip/CPP/7zip/Archive/Common/FindSignature.cpp +6 -6
  129. data/ext/p7zip/CPP/7zip/Archive/Common/FindSignature.h +2 -2
  130. data/ext/p7zip/CPP/7zip/Archive/Common/HandlerOut.cpp +77 -543
  131. data/ext/p7zip/CPP/7zip/Archive/Common/HandlerOut.h +31 -51
  132. data/ext/p7zip/CPP/7zip/Archive/Common/InStreamWithCRC.cpp +18 -14
  133. data/ext/p7zip/CPP/7zip/Archive/Common/ItemNameUtils.cpp +34 -7
  134. data/ext/p7zip/CPP/7zip/Archive/Common/ItemNameUtils.h +5 -2
  135. data/ext/p7zip/CPP/7zip/Archive/Common/MultiStream.cpp +25 -24
  136. data/ext/p7zip/CPP/7zip/Archive/Common/MultiStream.h +8 -3
  137. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.h +1 -0
  138. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithSha1.cpp +2 -2
  139. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithSha1.h +5 -5
  140. data/ext/p7zip/CPP/7zip/Archive/Common/ParseProperties.cpp +0 -174
  141. data/ext/p7zip/CPP/7zip/Archive/Common/ParseProperties.h +2 -14
  142. data/ext/p7zip/CPP/7zip/Archive/CpioHandler.cpp +506 -335
  143. data/ext/p7zip/CPP/7zip/Archive/CramfsHandler.cpp +227 -84
  144. data/ext/p7zip/CPP/7zip/Archive/DeflateProps.cpp +0 -115
  145. data/ext/p7zip/CPP/7zip/Archive/DeflateProps.h +0 -29
  146. data/ext/p7zip/CPP/7zip/Archive/DllExports2.cpp +63 -17
  147. data/ext/p7zip/CPP/7zip/Archive/DmgHandler.cpp +1007 -339
  148. data/ext/p7zip/CPP/7zip/Archive/ElfHandler.cpp +618 -177
  149. data/ext/p7zip/CPP/7zip/Archive/ExtHandler.cpp +2867 -0
  150. data/ext/p7zip/CPP/7zip/Archive/FatHandler.cpp +136 -76
  151. data/ext/p7zip/CPP/7zip/Archive/FlvHandler.cpp +132 -150
  152. data/ext/p7zip/CPP/7zip/Archive/GptHandler.cpp +405 -0
  153. data/ext/p7zip/CPP/7zip/Archive/GzHandler.cpp +560 -214
  154. data/ext/p7zip/CPP/7zip/Archive/HandlerCont.cpp +288 -0
  155. data/ext/p7zip/CPP/7zip/Archive/HandlerCont.h +116 -0
  156. data/ext/p7zip/CPP/7zip/Archive/HfsHandler.cpp +1880 -0
  157. data/ext/p7zip/CPP/7zip/Archive/IArchive.h +415 -51
  158. data/ext/p7zip/CPP/7zip/Archive/IhexHandler.cpp +497 -0
  159. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHandler.cpp +158 -71
  160. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHandler.h +2 -1
  161. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHeader.cpp +0 -9
  162. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHeader.h +8 -5
  163. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoIn.cpp +311 -91
  164. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoIn.h +101 -83
  165. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoItem.h +48 -39
  166. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoRegister.cpp +12 -4
  167. data/ext/p7zip/CPP/7zip/Archive/LzhHandler.cpp +127 -114
  168. data/ext/p7zip/CPP/7zip/Archive/LzmaHandler.cpp +264 -121
  169. data/ext/p7zip/CPP/7zip/Archive/MachoHandler.cpp +402 -242
  170. data/ext/p7zip/CPP/7zip/Archive/MbrHandler.cpp +56 -114
  171. data/ext/p7zip/CPP/7zip/Archive/MslzHandler.cpp +230 -90
  172. data/ext/p7zip/CPP/7zip/Archive/MubHandler.cpp +129 -153
  173. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisDecode.cpp +179 -58
  174. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisDecode.h +36 -7
  175. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisHandler.cpp +407 -237
  176. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisHandler.h +9 -16
  177. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisIn.cpp +5535 -1098
  178. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisIn.h +345 -81
  179. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisRegister.cpp +11 -4
  180. data/ext/p7zip/CPP/7zip/Archive/NtfsHandler.cpp +1424 -434
  181. data/ext/p7zip/CPP/7zip/Archive/PeHandler.cpp +1831 -521
  182. data/ext/p7zip/CPP/7zip/Archive/PpmdHandler.cpp +50 -35
  183. data/ext/p7zip/CPP/7zip/Archive/QcowHandler.cpp +615 -0
  184. data/ext/p7zip/CPP/7zip/Archive/Rar/Rar5Handler.cpp +2746 -0
  185. data/ext/p7zip/CPP/7zip/Archive/Rar/Rar5Handler.h +411 -0
  186. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHandler.cpp +1241 -355
  187. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHandler.h +70 -20
  188. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHeader.h +38 -34
  189. data/ext/p7zip/CPP/7zip/Archive/Rar/RarItem.h +34 -16
  190. data/ext/p7zip/CPP/7zip/Archive/Rar/RarVol.h +129 -0
  191. data/ext/p7zip/CPP/7zip/Archive/RpmHandler.cpp +641 -194
  192. data/ext/p7zip/CPP/7zip/Archive/SplitHandler.cpp +174 -181
  193. data/ext/p7zip/CPP/7zip/Archive/SquashfsHandler.cpp +237 -174
  194. data/ext/p7zip/CPP/7zip/Archive/SwfHandler.cpp +471 -192
  195. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandler.cpp +350 -59
  196. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandler.h +24 -7
  197. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandlerOut.cpp +79 -27
  198. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHeader.cpp +5 -7
  199. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHeader.h +20 -44
  200. data/ext/p7zip/CPP/7zip/Archive/Tar/TarIn.cpp +279 -64
  201. data/ext/p7zip/CPP/7zip/Archive/Tar/TarIn.h +10 -1
  202. data/ext/p7zip/CPP/7zip/Archive/Tar/TarItem.h +34 -8
  203. data/ext/p7zip/CPP/7zip/Archive/Tar/TarOut.cpp +145 -87
  204. data/ext/p7zip/CPP/7zip/Archive/Tar/TarOut.h +13 -5
  205. data/ext/p7zip/CPP/7zip/Archive/Tar/TarRegister.cpp +14 -9
  206. data/ext/p7zip/CPP/7zip/Archive/Tar/TarUpdate.cpp +154 -27
  207. data/ext/p7zip/CPP/7zip/Archive/Tar/TarUpdate.h +10 -6
  208. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfHandler.cpp +53 -128
  209. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfHandler.h +6 -5
  210. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfIn.cpp +384 -119
  211. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfIn.h +40 -21
  212. data/ext/p7zip/CPP/7zip/Archive/UefiHandler.cpp +1618 -0
  213. data/ext/p7zip/CPP/7zip/Archive/VdiHandler.cpp +362 -0
  214. data/ext/p7zip/CPP/7zip/Archive/VhdHandler.cpp +438 -247
  215. data/ext/p7zip/CPP/7zip/Archive/VmdkHandler.cpp +1518 -0
  216. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandler.cpp +837 -249
  217. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandler.h +73 -47
  218. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandlerOut.cpp +1614 -351
  219. data/ext/p7zip/CPP/7zip/Archive/Wim/WimIn.cpp +1519 -513
  220. data/ext/p7zip/CPP/7zip/Archive/Wim/WimIn.h +498 -139
  221. data/ext/p7zip/CPP/7zip/Archive/Wim/WimRegister.cpp +13 -9
  222. data/ext/p7zip/CPP/7zip/Archive/XarHandler.cpp +272 -128
  223. data/ext/p7zip/CPP/7zip/Archive/XzHandler.cpp +502 -253
  224. data/ext/p7zip/CPP/7zip/Archive/XzHandler.h +65 -0
  225. data/ext/p7zip/CPP/7zip/Archive/ZHandler.cpp +114 -39
  226. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipAddCommon.cpp +118 -134
  227. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipAddCommon.h +6 -0
  228. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipCompressionMode.h +40 -20
  229. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandler.cpp +541 -274
  230. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandler.h +13 -40
  231. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp +165 -254
  232. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHeader.h +70 -178
  233. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipIn.cpp +1934 -550
  234. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipIn.h +294 -63
  235. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItem.cpp +160 -86
  236. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItem.h +139 -110
  237. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipOut.cpp +177 -154
  238. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipOut.h +50 -18
  239. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipRegister.cpp +18 -9
  240. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipUpdate.cpp +367 -201
  241. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipUpdate.h +11 -10
  242. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile +2 -319
  243. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile.depend +0 -4962
  244. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile.list +1004 -259
  245. data/ext/p7zip/CPP/7zip/Common/CWrappers.cpp +26 -22
  246. data/ext/p7zip/CPP/7zip/Common/CWrappers.h +19 -14
  247. data/ext/p7zip/CPP/7zip/Common/CreateCoder.cpp +298 -130
  248. data/ext/p7zip/CPP/7zip/Common/CreateCoder.h +118 -34
  249. data/ext/p7zip/CPP/7zip/Common/FilePathAutoRename.cpp +24 -28
  250. data/ext/p7zip/CPP/7zip/Common/FilePathAutoRename.h +5 -5
  251. data/ext/p7zip/CPP/7zip/Common/FileStreams.cpp +268 -65
  252. data/ext/p7zip/CPP/7zip/Common/FileStreams.h +70 -33
  253. data/ext/p7zip/CPP/7zip/Common/FilterCoder.cpp +302 -131
  254. data/ext/p7zip/CPP/7zip/Common/FilterCoder.h +141 -43
  255. data/ext/p7zip/CPP/7zip/Common/InBuffer.cpp +87 -35
  256. data/ext/p7zip/CPP/7zip/Common/InBuffer.h +54 -45
  257. data/ext/p7zip/CPP/7zip/Common/InOutTempBuffer.cpp +22 -17
  258. data/ext/p7zip/CPP/7zip/Common/InOutTempBuffer.h +5 -5
  259. data/ext/p7zip/CPP/7zip/Common/LimitedStreams.cpp +256 -43
  260. data/ext/p7zip/CPP/7zip/Common/LimitedStreams.h +135 -8
  261. data/ext/p7zip/CPP/7zip/Common/MemBlocks.cpp +5 -5
  262. data/ext/p7zip/CPP/7zip/Common/MemBlocks.h +3 -3
  263. data/ext/p7zip/CPP/7zip/Common/MethodId.cpp +0 -24
  264. data/ext/p7zip/CPP/7zip/Common/MethodId.h +1 -1
  265. data/ext/p7zip/CPP/7zip/Common/MethodProps.cpp +430 -71
  266. data/ext/p7zip/CPP/7zip/Common/MethodProps.h +170 -17
  267. data/ext/p7zip/CPP/7zip/Common/OffsetStream.cpp +8 -4
  268. data/ext/p7zip/CPP/7zip/Common/OffsetStream.h +4 -3
  269. data/ext/p7zip/CPP/7zip/Common/OutBuffer.cpp +26 -31
  270. data/ext/p7zip/CPP/7zip/Common/OutBuffer.h +17 -18
  271. data/ext/p7zip/CPP/7zip/Common/OutMemStream.cpp +5 -5
  272. data/ext/p7zip/CPP/7zip/Common/OutMemStream.h +5 -4
  273. data/ext/p7zip/CPP/7zip/Common/ProgressUtils.cpp +22 -13
  274. data/ext/p7zip/CPP/7zip/Common/ProgressUtils.h +4 -3
  275. data/ext/p7zip/CPP/7zip/Common/PropId.cpp +108 -0
  276. data/ext/p7zip/CPP/7zip/Common/RegisterArc.h +63 -17
  277. data/ext/p7zip/CPP/7zip/Common/RegisterCodec.h +79 -6
  278. data/ext/p7zip/CPP/7zip/Common/StreamBinder.cpp +95 -90
  279. data/ext/p7zip/CPP/7zip/Common/StreamBinder.h +46 -23
  280. data/ext/p7zip/CPP/7zip/Common/StreamObjects.cpp +88 -24
  281. data/ext/p7zip/CPP/7zip/Common/StreamObjects.h +36 -14
  282. data/ext/p7zip/CPP/7zip/Common/StreamUtils.cpp +4 -4
  283. data/ext/p7zip/CPP/7zip/Common/StreamUtils.h +6 -6
  284. data/ext/p7zip/CPP/7zip/Common/UniqBlocks.cpp +57 -0
  285. data/ext/p7zip/CPP/7zip/Common/UniqBlocks.h +26 -0
  286. data/ext/p7zip/CPP/7zip/Common/VirtThread.cpp +8 -6
  287. data/ext/p7zip/CPP/7zip/Common/VirtThread.h +6 -5
  288. data/ext/p7zip/CPP/7zip/Compress/BZip2Const.h +13 -12
  289. data/ext/p7zip/CPP/7zip/Compress/BZip2Crc.h +1 -1
  290. data/ext/p7zip/CPP/7zip/Compress/BZip2Decoder.cpp +198 -147
  291. data/ext/p7zip/CPP/7zip/Compress/BZip2Decoder.h +60 -27
  292. data/ext/p7zip/CPP/7zip/Compress/BZip2Encoder.cpp +111 -116
  293. data/ext/p7zip/CPP/7zip/Compress/BZip2Encoder.h +53 -59
  294. data/ext/p7zip/CPP/7zip/Compress/BZip2Register.cpp +12 -7
  295. data/ext/p7zip/CPP/7zip/Compress/Bcj2Coder.cpp +554 -282
  296. data/ext/p7zip/CPP/7zip/Compress/Bcj2Coder.h +73 -71
  297. data/ext/p7zip/CPP/7zip/Compress/Bcj2Register.cpp +10 -5
  298. data/ext/p7zip/CPP/7zip/Compress/BcjCoder.cpp +13 -4
  299. data/ext/p7zip/CPP/7zip/Compress/BcjCoder.h +17 -5
  300. data/ext/p7zip/CPP/7zip/Compress/BcjRegister.cpp +7 -9
  301. data/ext/p7zip/CPP/7zip/Compress/BitlDecoder.cpp +2 -2
  302. data/ext/p7zip/CPP/7zip/Compress/BitlDecoder.h +58 -61
  303. data/ext/p7zip/CPP/7zip/Compress/BitlEncoder.h +24 -25
  304. data/ext/p7zip/CPP/7zip/Compress/BitmDecoder.h +46 -17
  305. data/ext/p7zip/CPP/7zip/Compress/BitmEncoder.h +18 -19
  306. data/ext/p7zip/CPP/7zip/Compress/BranchMisc.cpp +14 -28
  307. data/ext/p7zip/CPP/7zip/Compress/BranchMisc.h +27 -6
  308. data/ext/p7zip/CPP/7zip/Compress/BranchRegister.cpp +26 -15
  309. data/ext/p7zip/CPP/7zip/Compress/ByteSwap.cpp +45 -26
  310. data/ext/p7zip/CPP/7zip/Compress/CodecExports.cpp +254 -70
  311. data/ext/p7zip/CPP/7zip/Compress/CopyCoder.cpp +65 -17
  312. data/ext/p7zip/CPP/7zip/Compress/CopyCoder.h +15 -3
  313. data/ext/p7zip/CPP/7zip/Compress/CopyRegister.cpp +5 -4
  314. data/ext/p7zip/CPP/7zip/Compress/Deflate64Register.cpp +12 -6
  315. data/ext/p7zip/CPP/7zip/Compress/DeflateConst.h +43 -46
  316. data/ext/p7zip/CPP/7zip/Compress/DeflateDecoder.cpp +145 -81
  317. data/ext/p7zip/CPP/7zip/Compress/DeflateDecoder.h +31 -33
  318. data/ext/p7zip/CPP/7zip/Compress/DeflateEncoder.cpp +179 -162
  319. data/ext/p7zip/CPP/7zip/Compress/DeflateEncoder.h +35 -30
  320. data/ext/p7zip/CPP/7zip/Compress/DeflateRegister.cpp +11 -7
  321. data/ext/p7zip/CPP/7zip/Compress/DeltaFilter.cpp +55 -39
  322. data/ext/p7zip/CPP/7zip/Compress/{DllExports2.cpp → DllExports2Compress.cpp} +8 -8
  323. data/ext/p7zip/CPP/7zip/Compress/DllExportsCompress.cpp +48 -0
  324. data/ext/p7zip/CPP/7zip/Compress/HuffmanDecoder.h +220 -49
  325. data/ext/p7zip/CPP/7zip/Compress/ImplodeDecoder.cpp +14 -9
  326. data/ext/p7zip/CPP/7zip/Compress/ImplodeDecoder.h +2 -3
  327. data/ext/p7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp +7 -7
  328. data/ext/p7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.h +1 -1
  329. data/ext/p7zip/CPP/7zip/Compress/LzOutWindow.cpp +1 -1
  330. data/ext/p7zip/CPP/7zip/Compress/LzOutWindow.h +21 -18
  331. data/ext/p7zip/CPP/7zip/Compress/LzhDecoder.cpp +171 -141
  332. data/ext/p7zip/CPP/7zip/Compress/LzhDecoder.h +32 -64
  333. data/ext/p7zip/CPP/7zip/Compress/Lzham/LICENSE +22 -0
  334. data/ext/p7zip/CPP/7zip/Compress/Lzham/LzhamRegister.cpp +783 -0
  335. data/ext/p7zip/CPP/7zip/Compress/Lzham/README.md +211 -0
  336. data/ext/p7zip/CPP/7zip/Compress/Lzham/include/lzham.h +803 -0
  337. data/ext/p7zip/CPP/7zip/Compress/Lzham/include/lzham_dynamic_lib.h +156 -0
  338. data/ext/p7zip/CPP/7zip/Compress/Lzham/include/lzham_exports.inc +31 -0
  339. data/ext/p7zip/CPP/7zip/Compress/Lzham/include/lzham_static_lib.h +59 -0
  340. data/ext/p7zip/CPP/7zip/Compress/Lzham/include/zlib.h +2 -0
  341. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/CMakeLists.txt +69 -0
  342. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_comp.h +38 -0
  343. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzbase.cpp +244 -0
  344. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzbase.h +46 -0
  345. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzcomp.cpp +750 -0
  346. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzcomp_internal.cpp +2240 -0
  347. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzcomp_internal.h +503 -0
  348. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzcomp_state.cpp +1684 -0
  349. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_match_accel.cpp +947 -0
  350. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_match_accel.h +164 -0
  351. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_null_threading.h +98 -0
  352. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_pthreads_threading.cpp +214 -0
  353. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_pthreads_threading.h +535 -0
  354. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_threading.h +12 -0
  355. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_win32_threading.cpp +232 -0
  356. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_win32_threading.h +387 -0
  357. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzhamcomp.vcxproj +208 -0
  358. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/CMakeLists.txt +86 -0
  359. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_assert.cpp +80 -0
  360. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_assert.h +58 -0
  361. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_checksum.cpp +73 -0
  362. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_checksum.h +13 -0
  363. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_config.h +25 -0
  364. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_core.h +303 -0
  365. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_decomp.h +37 -0
  366. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_helpers.h +54 -0
  367. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_huffman_codes.cpp +286 -0
  368. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_huffman_codes.h +32 -0
  369. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_lzdecomp.cpp +1586 -0
  370. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_lzdecompbase.cpp +131 -0
  371. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_lzdecompbase.h +89 -0
  372. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_math.h +142 -0
  373. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_mem.cpp +463 -0
  374. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_mem.h +115 -0
  375. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_platform.cpp +159 -0
  376. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_platform.h +284 -0
  377. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_prefix_coding.cpp +431 -0
  378. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_prefix_coding.h +157 -0
  379. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_symbol_codec.cpp +1527 -0
  380. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_symbol_codec.h +494 -0
  381. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_timer.cpp +147 -0
  382. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_timer.h +99 -0
  383. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_traits.h +141 -0
  384. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_types.h +72 -0
  385. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_utils.h +58 -0
  386. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_vector.cpp +83 -0
  387. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_vector.h +628 -0
  388. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzhamdecomp.vcxproj +224 -0
  389. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamlib/lzham_lib.cpp +179 -0
  390. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamlib/lzhamlib.vcxproj +187 -0
  391. data/ext/p7zip/CPP/7zip/Compress/Lzham/makefile +10 -0
  392. data/ext/p7zip/CPP/7zip/Compress/Lzham/makefile.depend +0 -0
  393. data/ext/p7zip/CPP/7zip/Compress/Lzham/makefile.list +129 -0
  394. data/ext/p7zip/CPP/7zip/Compress/Lzma2Decoder.cpp +123 -46
  395. data/ext/p7zip/CPP/7zip/Compress/Lzma2Decoder.h +29 -14
  396. data/ext/p7zip/CPP/7zip/Compress/Lzma2Encoder.cpp +14 -9
  397. data/ext/p7zip/CPP/7zip/Compress/Lzma2Encoder.h +1 -1
  398. data/ext/p7zip/CPP/7zip/Compress/Lzma2Register.cpp +9 -7
  399. data/ext/p7zip/CPP/7zip/Compress/LzmaDecoder.cpp +24 -8
  400. data/ext/p7zip/CPP/7zip/Compress/LzmaDecoder.h +8 -1
  401. data/ext/p7zip/CPP/7zip/Compress/LzmaEncoder.cpp +30 -27
  402. data/ext/p7zip/CPP/7zip/Compress/LzmaEncoder.h +3 -1
  403. data/ext/p7zip/CPP/7zip/Compress/LzmaRegister.cpp +9 -7
  404. data/ext/p7zip/CPP/7zip/Compress/LzmsDecoder.cpp +576 -0
  405. data/ext/p7zip/CPP/7zip/Compress/LzmsDecoder.h +271 -0
  406. data/ext/p7zip/CPP/7zip/Compress/Lzx.h +32 -36
  407. data/ext/p7zip/CPP/7zip/Compress/LzxDecoder.cpp +380 -238
  408. data/ext/p7zip/CPP/7zip/Compress/LzxDecoder.h +170 -83
  409. data/ext/p7zip/CPP/7zip/Compress/Mtf8.h +7 -9
  410. data/ext/p7zip/CPP/7zip/Compress/PpmdDecoder.cpp +1 -5
  411. data/ext/p7zip/CPP/7zip/Compress/PpmdEncoder.cpp +51 -18
  412. data/ext/p7zip/CPP/7zip/Compress/PpmdEncoder.h +18 -8
  413. data/ext/p7zip/CPP/7zip/Compress/PpmdRegister.cpp +9 -8
  414. data/ext/p7zip/CPP/7zip/Compress/PpmdZip.cpp +61 -25
  415. data/ext/p7zip/CPP/7zip/Compress/PpmdZip.h +21 -6
  416. data/ext/p7zip/CPP/7zip/Compress/QuantumDecoder.cpp +122 -102
  417. data/ext/p7zip/CPP/7zip/Compress/QuantumDecoder.h +68 -157
  418. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile +33 -18
  419. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile.depend +0 -158
  420. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile.list +105 -56
  421. data/ext/p7zip/CPP/7zip/Compress/Rar1Decoder.cpp +34 -21
  422. data/ext/p7zip/CPP/7zip/Compress/Rar1Decoder.h +2 -0
  423. data/ext/p7zip/CPP/7zip/Compress/Rar2Decoder.cpp +77 -67
  424. data/ext/p7zip/CPP/7zip/Compress/Rar2Decoder.h +12 -10
  425. data/ext/p7zip/CPP/7zip/Compress/Rar3Decoder.cpp +139 -118
  426. data/ext/p7zip/CPP/7zip/Compress/Rar3Decoder.h +48 -33
  427. data/ext/p7zip/CPP/7zip/Compress/Rar3Vm.cpp +148 -113
  428. data/ext/p7zip/CPP/7zip/Compress/Rar3Vm.h +35 -19
  429. data/ext/p7zip/CPP/7zip/Compress/Rar5Decoder.cpp +961 -0
  430. data/ext/p7zip/CPP/7zip/Compress/Rar5Decoder.h +335 -0
  431. data/ext/p7zip/CPP/7zip/Compress/RarCodecsRegister.cpp +13 -6
  432. data/ext/p7zip/CPP/7zip/Compress/ShrinkDecoder.cpp +91 -71
  433. data/ext/p7zip/CPP/7zip/Compress/ShrinkDecoder.h +2 -4
  434. data/ext/p7zip/CPP/7zip/Compress/XpressDecoder.cpp +129 -0
  435. data/ext/p7zip/CPP/7zip/Compress/XpressDecoder.h +13 -0
  436. data/ext/p7zip/CPP/7zip/Compress/ZDecoder.cpp +98 -20
  437. data/ext/p7zip/CPP/7zip/Compress/ZDecoder.h +19 -7
  438. data/ext/p7zip/CPP/7zip/Compress/ZlibDecoder.cpp +14 -11
  439. data/ext/p7zip/CPP/7zip/Compress/ZlibDecoder.h +32 -1
  440. data/ext/p7zip/CPP/7zip/Crypto/7zAes.cpp +137 -101
  441. data/ext/p7zip/CPP/7zip/Crypto/7zAes.h +31 -30
  442. data/ext/p7zip/CPP/7zip/Crypto/7zAesRegister.cpp +8 -9
  443. data/ext/p7zip/CPP/7zip/Crypto/HmacSha1.cpp +39 -28
  444. data/ext/p7zip/CPP/7zip/Crypto/HmacSha1.h +3 -3
  445. data/ext/p7zip/CPP/7zip/Crypto/HmacSha256.cpp +62 -0
  446. data/ext/p7zip/CPP/7zip/Crypto/HmacSha256.h +27 -0
  447. data/ext/p7zip/CPP/7zip/Crypto/MyAes.cpp +73 -7
  448. data/ext/p7zip/CPP/7zip/Crypto/MyAes.h +25 -8
  449. data/ext/p7zip/CPP/7zip/Crypto/MyAesReg.cpp +16 -0
  450. data/ext/p7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp +29 -15
  451. data/ext/p7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.h +2 -1
  452. data/ext/p7zip/CPP/7zip/Crypto/RandGen.cpp +49 -34
  453. data/ext/p7zip/CPP/7zip/Crypto/RandGen.h +2 -2
  454. data/ext/p7zip/CPP/7zip/Crypto/Rar20Crypto.cpp +36 -39
  455. data/ext/p7zip/CPP/7zip/Crypto/Rar20Crypto.h +15 -17
  456. data/ext/p7zip/CPP/7zip/Crypto/Rar5Aes.cpp +257 -0
  457. data/ext/p7zip/CPP/7zip/Crypto/Rar5Aes.h +84 -0
  458. data/ext/p7zip/CPP/7zip/Crypto/RarAes.cpp +70 -71
  459. data/ext/p7zip/CPP/7zip/Crypto/RarAes.h +24 -19
  460. data/ext/p7zip/CPP/7zip/Crypto/Sha1Cls.h +51 -0
  461. data/ext/p7zip/CPP/7zip/Crypto/WzAes.cpp +68 -54
  462. data/ext/p7zip/CPP/7zip/Crypto/WzAes.h +37 -27
  463. data/ext/p7zip/CPP/7zip/Crypto/ZipCrypto.cpp +60 -34
  464. data/ext/p7zip/CPP/7zip/Crypto/ZipCrypto.h +28 -11
  465. data/ext/p7zip/CPP/7zip/Crypto/ZipStrong.cpp +90 -28
  466. data/ext/p7zip/CPP/7zip/Crypto/ZipStrong.h +13 -2
  467. data/ext/p7zip/CPP/7zip/Guid.txt +57 -11
  468. data/ext/p7zip/CPP/7zip/ICoder.h +202 -17
  469. data/ext/p7zip/CPP/7zip/IDecl.h +16 -3
  470. data/ext/p7zip/CPP/7zip/IPassword.h +1 -2
  471. data/ext/p7zip/CPP/7zip/IProgress.h +2 -16
  472. data/ext/p7zip/CPP/7zip/IStream.h +82 -13
  473. data/ext/p7zip/CPP/7zip/MyVersion.h +2 -11
  474. data/ext/p7zip/CPP/7zip/PropID.h +60 -9
  475. data/ext/p7zip/CPP/Common/C_FileIO.cpp +5 -1
  476. data/ext/p7zip/CPP/Common/C_FileIO.h +7 -1
  477. data/ext/p7zip/CPP/Common/CommandLineParser.cpp +122 -148
  478. data/ext/p7zip/CPP/Common/CommandLineParser.h +20 -29
  479. data/ext/p7zip/CPP/Common/Common.h +13 -0
  480. data/ext/p7zip/CPP/Common/CrcReg.cpp +98 -0
  481. data/ext/p7zip/CPP/Common/Defs.h +5 -10
  482. data/ext/p7zip/CPP/Common/DynLimBuf.cpp +93 -0
  483. data/ext/p7zip/CPP/Common/DynLimBuf.h +40 -0
  484. data/ext/p7zip/CPP/Common/DynamicBuffer.h +45 -31
  485. data/ext/p7zip/CPP/Common/IntToString.cpp +109 -40
  486. data/ext/p7zip/CPP/Common/IntToString.h +14 -9
  487. data/ext/p7zip/CPP/Common/Lang.cpp +120 -87
  488. data/ext/p7zip/CPP/Common/Lang.h +10 -15
  489. data/ext/p7zip/CPP/Common/ListFileUtils.cpp +82 -40
  490. data/ext/p7zip/CPP/Common/ListFileUtils.h +7 -4
  491. data/ext/p7zip/CPP/Common/MyBuffer.h +244 -0
  492. data/ext/p7zip/CPP/Common/MyCom.h +65 -28
  493. data/ext/p7zip/CPP/Common/MyGuidDef.h +1 -1
  494. data/ext/p7zip/CPP/Common/MyInitGuid.h +23 -0
  495. data/ext/p7zip/CPP/Common/MyLinux.h +42 -0
  496. data/ext/p7zip/CPP/Common/MyMap.cpp +8 -8
  497. data/ext/p7zip/CPP/Common/MyMap.h +2 -2
  498. data/ext/p7zip/CPP/Common/MyString.cpp +1643 -117
  499. data/ext/p7zip/CPP/Common/MyString.h +677 -486
  500. data/ext/p7zip/CPP/Common/MyTypes.h +38 -0
  501. data/ext/p7zip/CPP/Common/MyUnknown.h +4 -0
  502. data/ext/p7zip/CPP/Common/MyVector.cpp +0 -84
  503. data/ext/p7zip/CPP/Common/MyVector.h +472 -112
  504. data/ext/p7zip/CPP/Common/MyWindows.cpp +18 -1
  505. data/ext/p7zip/CPP/Common/MyWindows.h +8 -0
  506. data/ext/p7zip/CPP/Common/MyXml.cpp +169 -118
  507. data/ext/p7zip/CPP/Common/MyXml.h +14 -11
  508. data/ext/p7zip/CPP/Common/NewHandler.cpp +39 -0
  509. data/ext/p7zip/CPP/Common/NewHandler.h +55 -2
  510. data/ext/p7zip/CPP/Common/Random.h +14 -0
  511. data/ext/p7zip/CPP/Common/Sha1Reg.cpp +40 -0
  512. data/ext/p7zip/CPP/Common/Sha256Reg.cpp +40 -0
  513. data/ext/p7zip/CPP/Common/StdInStream.cpp +46 -27
  514. data/ext/p7zip/CPP/Common/StdInStream.h +11 -10
  515. data/ext/p7zip/CPP/Common/StdOutStream.cpp +48 -35
  516. data/ext/p7zip/CPP/Common/StdOutStream.h +44 -17
  517. data/ext/p7zip/CPP/Common/StringConvert.cpp +56 -17
  518. data/ext/p7zip/CPP/Common/StringConvert.h +7 -3
  519. data/ext/p7zip/CPP/Common/StringToInt.cpp +102 -48
  520. data/ext/p7zip/CPP/Common/StringToInt.h +13 -10
  521. data/ext/p7zip/CPP/Common/TextConfig.cpp +33 -47
  522. data/ext/p7zip/CPP/Common/TextConfig.h +3 -6
  523. data/ext/p7zip/CPP/Common/UTFConvert.cpp +218 -75
  524. data/ext/p7zip/CPP/Common/UTFConvert.h +4 -3
  525. data/ext/p7zip/CPP/Common/Wildcard.cpp +345 -125
  526. data/ext/p7zip/CPP/Common/Wildcard.h +82 -13
  527. data/ext/p7zip/CPP/Common/XzCrc64Reg.cpp +42 -0
  528. data/ext/p7zip/CPP/Windows/FileDir.cpp +427 -475
  529. data/ext/p7zip/CPP/Windows/FileDir.h +94 -72
  530. data/ext/p7zip/CPP/Windows/FileFind.cpp +235 -244
  531. data/ext/p7zip/CPP/Windows/FileFind.h +63 -59
  532. data/ext/p7zip/CPP/Windows/FileIO.cpp +29 -46
  533. data/ext/p7zip/CPP/Windows/FileIO.h +40 -42
  534. data/ext/p7zip/CPP/Windows/FileName.cpp +696 -17
  535. data/ext/p7zip/CPP/Windows/FileName.h +11 -3
  536. data/ext/p7zip/CPP/Windows/NtCheck.h +2 -0
  537. data/ext/p7zip/CPP/Windows/PropVariant.cpp +134 -30
  538. data/ext/p7zip/CPP/Windows/PropVariant.h +80 -24
  539. data/ext/p7zip/CPP/Windows/PropVariantUtils.cpp +89 -18
  540. data/ext/p7zip/CPP/Windows/PropVariantUtils.h +12 -7
  541. data/ext/p7zip/CPP/Windows/System.cpp +20 -15
  542. data/ext/p7zip/CPP/Windows/System.h +3 -2
  543. data/ext/p7zip/CPP/Windows/TimeUtils.cpp +203 -0
  544. data/ext/p7zip/CPP/Windows/TimeUtils.h +24 -0
  545. data/ext/p7zip/CPP/include_windows/basetyps.h +4 -4
  546. data/ext/p7zip/CPP/include_windows/windows.h +17 -11
  547. data/ext/p7zip/CPP/myWindows/StdAfx.h +97 -5
  548. data/ext/p7zip/CPP/myWindows/config.h +20 -5
  549. data/ext/p7zip/CPP/myWindows/myPrivate.h +8 -0
  550. data/ext/p7zip/CPP/myWindows/wine_date_and_time.cpp +34 -0
  551. data/ext/p7zip/ChangeLog +283 -35
  552. data/ext/p7zip/{DOCS → DOC}/7zC.txt +6 -13
  553. data/ext/p7zip/{DOCS → DOC}/License.txt +3 -2
  554. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/add.htm +93 -87
  555. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/bench.htm +88 -79
  556. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/delete.htm +62 -59
  557. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/extract.htm +96 -91
  558. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/extract_full.htm +73 -68
  559. data/ext/p7zip/DOC/MANUAL/cmdline/commands/hash.htm +65 -0
  560. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/index.htm +36 -33
  561. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/list.htm +78 -77
  562. data/ext/p7zip/DOC/MANUAL/cmdline/commands/rename.htm +51 -0
  563. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/style.css +232 -232
  564. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/test.htm +47 -46
  565. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/update.htm +71 -66
  566. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/exit_codes.htm +27 -27
  567. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/index.htm +29 -29
  568. data/ext/p7zip/{DOCS/MANUAL/switches → DOC/MANUAL/cmdline}/style.css +232 -232
  569. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/ar_exclude.htm +56 -56
  570. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/ar_include.htm +80 -83
  571. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/ar_no.htm +52 -52
  572. data/ext/p7zip/DOC/MANUAL/cmdline/switches/bb.htm +61 -0
  573. data/ext/p7zip/DOC/MANUAL/cmdline/switches/bs.htm +67 -0
  574. data/ext/p7zip/DOC/MANUAL/cmdline/switches/charset.htm +61 -0
  575. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/exclude.htm +71 -60
  576. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/include.htm +89 -87
  577. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/index.htm +95 -64
  578. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/large_pages.htm +59 -50
  579. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/list_tech.htm +36 -36
  580. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/method.htm +738 -625
  581. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/output_dir.htm +53 -53
  582. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/overwrite.htm +56 -56
  583. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/password.htm +55 -54
  584. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/recurse.htm +85 -83
  585. data/ext/p7zip/DOC/MANUAL/cmdline/switches/sa.htm +58 -0
  586. data/ext/p7zip/DOC/MANUAL/cmdline/switches/scc.htm +42 -0
  587. data/ext/p7zip/DOC/MANUAL/cmdline/switches/scrc.htm +53 -0
  588. data/ext/p7zip/DOC/MANUAL/cmdline/switches/sdel.htm +39 -0
  589. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/sfx.htm +153 -156
  590. data/ext/p7zip/DOC/MANUAL/cmdline/switches/shared.htm +40 -0
  591. data/ext/p7zip/DOC/MANUAL/cmdline/switches/sni.htm +56 -0
  592. data/ext/p7zip/DOC/MANUAL/cmdline/switches/sns.htm +77 -0
  593. data/ext/p7zip/DOC/MANUAL/cmdline/switches/spf.htm +80 -0
  594. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/ssc.htm +50 -50
  595. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/stdin.htm +56 -55
  596. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/stdout.htm +54 -50
  597. data/ext/p7zip/DOC/MANUAL/cmdline/switches/stl.htm +39 -0
  598. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/stop_switch.htm +31 -31
  599. data/ext/p7zip/DOC/MANUAL/cmdline/switches/stx.htm +50 -0
  600. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline/switches}/style.css +232 -232
  601. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/type.htm +121 -83
  602. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/update.htm +177 -176
  603. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/volume.htm +49 -49
  604. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/working_dir.htm +56 -55
  605. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/yes.htm +48 -48
  606. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/syntax.htm +120 -120
  607. data/ext/p7zip/DOC/MANUAL/fm/about.htm +21 -0
  608. data/ext/p7zip/DOC/MANUAL/fm/benchmark.htm +56 -0
  609. data/ext/p7zip/DOC/MANUAL/fm/index.htm +54 -0
  610. data/ext/p7zip/DOC/MANUAL/fm/menu.htm +154 -0
  611. data/ext/p7zip/DOC/MANUAL/fm/options.htm +152 -0
  612. data/ext/p7zip/DOC/MANUAL/fm/plugins/7-zip/add.htm +311 -0
  613. data/ext/p7zip/DOC/MANUAL/fm/plugins/7-zip/extract.htm +78 -0
  614. data/ext/p7zip/DOC/MANUAL/fm/plugins/7-zip/index.htm +63 -0
  615. data/ext/p7zip/DOC/MANUAL/fm/plugins/7-zip/style.css +232 -0
  616. data/ext/p7zip/DOC/MANUAL/fm/plugins/index.htm +22 -0
  617. data/ext/p7zip/DOC/MANUAL/fm/plugins/style.css +232 -0
  618. data/ext/p7zip/DOC/MANUAL/fm/style.css +232 -0
  619. data/ext/p7zip/DOC/MANUAL/general/7z.htm +117 -0
  620. data/ext/p7zip/DOC/MANUAL/general/faq.htm +125 -0
  621. data/ext/p7zip/DOC/MANUAL/general/formats.htm +100 -0
  622. data/ext/p7zip/DOC/MANUAL/general/index.htm +27 -0
  623. data/ext/p7zip/DOC/MANUAL/general/license.htm +30 -0
  624. data/ext/p7zip/DOC/MANUAL/general/performance.htm +98 -0
  625. data/ext/p7zip/DOC/MANUAL/general/style.css +232 -0
  626. data/ext/p7zip/DOC/MANUAL/general/thanks.htm +43 -0
  627. data/ext/p7zip/DOC/MANUAL/start.htm +37 -0
  628. data/ext/p7zip/DOC/MANUAL/style.css +232 -0
  629. data/ext/p7zip/DOC/Methods.txt +158 -0
  630. data/ext/p7zip/{DOCS → DOC}/copying.txt +9 -11
  631. data/ext/p7zip/DOC/lzma.txt +328 -0
  632. data/ext/p7zip/{DOCS → DOC}/readme.txt +42 -65
  633. data/ext/p7zip/{DOCS/history.txt → DOC/src-history.txt} +88 -2
  634. data/ext/p7zip/README +117 -91
  635. data/ext/p7zip/TODO +0 -2
  636. data/ext/p7zip/install.sh +31 -29
  637. data/ext/p7zip/last_error +1 -0
  638. data/ext/p7zip/makefile +29 -125
  639. data/ext/p7zip/makefile.afl +23 -0
  640. data/ext/p7zip/makefile.aix_gcc +5 -4
  641. data/ext/p7zip/makefile.android_arm +49 -0
  642. data/ext/p7zip/makefile.beos +5 -4
  643. data/ext/p7zip/makefile.common +150 -0
  644. data/ext/p7zip/makefile.crc32 +3 -3
  645. data/ext/p7zip/makefile.cygwin +5 -4
  646. data/ext/p7zip/makefile.cygwin64 +21 -0
  647. data/ext/p7zip/makefile.cygwin64_asm +22 -0
  648. data/ext/p7zip/makefile.cygwin_asm +6 -4
  649. data/ext/p7zip/makefile.cygwin_clang +21 -0
  650. data/ext/p7zip/makefile.cygwin_clang_asm +23 -0
  651. data/ext/p7zip/{makefile.djgpp_old → makefile.djgpp} +5 -4
  652. data/ext/p7zip/makefile.djgpp_watt +7 -5
  653. data/ext/p7zip/makefile.freebsd5 +5 -4
  654. data/ext/p7zip/{makefile.freebsd6 → makefile.freebsd6+} +6 -5
  655. data/ext/p7zip/makefile.glb +27 -18
  656. data/ext/p7zip/makefile.gprof +3 -2
  657. data/ext/p7zip/makefile.haiku +19 -0
  658. data/ext/p7zip/makefile.hpux-acc +3 -2
  659. data/ext/p7zip/makefile.hpux-acc_64 +3 -2
  660. data/ext/p7zip/makefile.hpux-gcc +5 -4
  661. data/ext/p7zip/makefile.linux_amd64 +5 -4
  662. data/ext/p7zip/makefile.linux_amd64_asm +12 -5
  663. data/ext/p7zip/makefile.linux_amd64_asm_icc +5 -3
  664. data/ext/p7zip/makefile.linux_amd64_sanitizer +26 -0
  665. data/ext/p7zip/makefile.linux_any_cpu +5 -4
  666. data/ext/p7zip/makefile.linux_any_cpu_gcc_4.X +7 -4
  667. data/ext/p7zip/makefile.linux_clang_amd64_asm +25 -0
  668. data/ext/p7zip/makefile.linux_clang_amd64_asm_sanitize +27 -0
  669. data/ext/p7zip/makefile.linux_cross_aarch64 +25 -0
  670. data/ext/p7zip/makefile.linux_cross_arm +7 -4
  671. data/ext/p7zip/makefile.linux_cross_djgpp +27 -0
  672. data/ext/p7zip/makefile.linux_cross_m68k +26 -0
  673. data/ext/p7zip/makefile.linux_cross_mipsel +27 -0
  674. data/ext/p7zip/makefile.linux_cross_ppc +25 -0
  675. data/ext/p7zip/makefile.linux_cross_ppc64 +25 -0
  676. data/ext/p7zip/makefile.linux_cross_ppc64le +25 -0
  677. data/ext/p7zip/makefile.linux_cross_s390x +25 -0
  678. data/ext/p7zip/makefile.linux_cross_sparc64 +25 -0
  679. data/ext/p7zip/makefile.linux_gcc6_sanitize +23 -0
  680. data/ext/p7zip/makefile.linux_gcc_2.95_no_need_for_libstdc +6 -4
  681. data/ext/p7zip/makefile.linux_other +6 -5
  682. data/ext/p7zip/makefile.linux_s390x +5 -4
  683. data/ext/p7zip/{makefile.machine_base → makefile.linux_scan-build} +5 -4
  684. data/ext/p7zip/makefile.linux_valgrind +25 -0
  685. data/ext/p7zip/{makefile.linux_clang_amd64 → makefile.linux_x32} +6 -5
  686. data/ext/p7zip/makefile.linux_x86_asm_gcc_4.X +10 -5
  687. data/ext/p7zip/makefile.linux_x86_asm_gcc_4.X_fltk +8 -4
  688. data/ext/p7zip/makefile.linux_x86_asm_gcc_mudflap_4.X +4 -2
  689. data/ext/p7zip/makefile.linux_x86_asm_icc +4 -2
  690. data/ext/p7zip/makefile.linux_x86_icc +3 -2
  691. data/ext/p7zip/makefile.macosx_arm64 +17 -0
  692. data/ext/p7zip/{makefile.macosx_32bits → makefile.macosx_gcc_32bits} +3 -2
  693. data/ext/p7zip/{makefile.macosx_32bits_asm → makefile.macosx_gcc_32bits_asm} +5 -3
  694. data/ext/p7zip/{makefile.macosx_32bits_ppc → makefile.macosx_gcc_32bits_ppc} +3 -2
  695. data/ext/p7zip/{makefile.macosx_64bits → makefile.macosx_gcc_64bits} +3 -2
  696. data/ext/p7zip/makefile.macosx_llvm_64bits +9 -3
  697. data/ext/p7zip/makefile.netbsd +5 -4
  698. data/ext/p7zip/makefile.netware_asm_gcc_3.X +6 -4
  699. data/ext/p7zip/makefile.oldmake +41 -130
  700. data/ext/p7zip/makefile.openbsd +7 -3
  701. data/ext/p7zip/makefile.openbsd_no_port +9 -5
  702. data/ext/p7zip/makefile.qnx_shared.bin +5 -4
  703. data/ext/p7zip/makefile.qnx_static +5 -4
  704. data/ext/p7zip/makefile.solaris_sparc_CC_32 +5 -4
  705. data/ext/p7zip/makefile.solaris_sparc_CC_64 +6 -4
  706. data/ext/p7zip/makefile.solaris_sparc_gcc +7 -6
  707. data/ext/p7zip/makefile.solaris_x86 +5 -4
  708. data/ext/p7zip/makefile.tru64 +5 -4
  709. data/ext/seven_zip_ruby/extconf.rb +92 -6
  710. data/ext/seven_zip_ruby/seven_zip_archive.cpp +40 -17
  711. data/ext/seven_zip_ruby/seven_zip_archive.h +1 -1
  712. data/ext/seven_zip_ruby/utils.cpp +267 -124
  713. data/ext/seven_zip_ruby/utils.h +2 -0
  714. data/lib/seven_zip_ruby/7z.dll +0 -0
  715. data/lib/seven_zip_ruby/7z.sfx +0 -0
  716. data/lib/seven_zip_ruby/7z64.dll +0 -0
  717. data/lib/seven_zip_ruby/7zCon.sfx +0 -0
  718. data/lib/seven_zip_ruby/seven_zip_reader.rb +16 -1
  719. data/lib/seven_zip_ruby/version.rb +1 -1
  720. data/p7zip/.gitignore +7 -0
  721. data/p7zip/README.txt +29 -0
  722. data/p7zip/extract.sh +134 -0
  723. data/spec/seven_zip_ruby_spec.rb +22 -13
  724. data/test/res/The Flying Spaghetti Monster.txt +3 -0
  725. data/test/res/The Three Little Pigs.txt +5 -0
  726. data/test/res/UTF_content.txt +3 -0
  727. data/test/res/test_reader_data.7z +0 -0
  728. data/test/res/test_reader_filename_cp932.7z +0 -0
  729. data/test/res/test_reader_files.7z +0 -0
  730. data/test/test_seven_zip_reader.rb +187 -0
  731. data/test/test_seven_zip_writer.rb +184 -0
  732. metadata +267 -219
  733. data/.github/workflows/test-and-release.yml +0 -43
  734. data/ext/C/Types.h +0 -254
  735. data/ext/CPP/7zip/Archive/IArchive.h +0 -234
  736. data/ext/CPP/7zip/IDecl.h +0 -15
  737. data/ext/CPP/7zip/IPassword.h +0 -24
  738. data/ext/CPP/7zip/IProgress.h +0 -33
  739. data/ext/CPP/7zip/IStream.h +0 -58
  740. data/ext/CPP/7zip/PropID.h +0 -76
  741. data/ext/CPP/Common/MyCom.h +0 -225
  742. data/ext/CPP/Common/MyGuidDef.h +0 -54
  743. data/ext/CPP/Common/MyInitGuid.h +0 -22
  744. data/ext/CPP/Common/MyUnknown.h +0 -13
  745. data/ext/CPP/Common/MyWindows.h +0 -204
  746. data/ext/CPP/Common/Types.h +0 -11
  747. data/ext/CPP/Windows/PropVariant.h +0 -56
  748. data/ext/CPP/include_windows/basetyps.h +0 -19
  749. data/ext/CPP/include_windows/tchar.h +0 -89
  750. data/ext/CPP/include_windows/windows.h +0 -194
  751. data/ext/p7zip/Asm/x64/7zCrcT8U.asm +0 -103
  752. data/ext/p7zip/Asm/x86/7zCrcT8U.asm +0 -101
  753. data/ext/p7zip/C/7zCrcT8.c +0 -43
  754. data/ext/p7zip/C/Alloc.back3 +0 -238
  755. data/ext/p7zip/C/Alloc.c.back +0 -243
  756. data/ext/p7zip/C/Alloc.c.back2 +0 -222
  757. data/ext/p7zip/C/LzmaUtil/Lzma86Dec.h +0 -51
  758. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderOutStream.cpp +0 -149
  759. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderOutStream.h +0 -58
  760. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHeader.cpp +0 -24
  761. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHeader.h +0 -28
  762. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmRegister.cpp +0 -13
  763. data/ext/p7zip/CPP/7zip/Archive/Com/ComHandler.cpp +0 -239
  764. data/ext/p7zip/CPP/7zip/Archive/Com/ComHandler.h +0 -28
  765. data/ext/p7zip/CPP/7zip/Archive/Com/ComIn.cpp +0 -389
  766. data/ext/p7zip/CPP/7zip/Archive/Com/ComIn.h +0 -119
  767. data/ext/p7zip/CPP/7zip/Archive/Com/ComRegister.cpp +0 -13
  768. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2MT.cpp +0 -240
  769. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2MT.h +0 -80
  770. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2ST.cpp +0 -239
  771. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2ST.h +0 -88
  772. data/ext/p7zip/CPP/7zip/Archive/Common/CrossThreadProgress.cpp +0 -15
  773. data/ext/p7zip/CPP/7zip/Archive/Common/CrossThreadProgress.h +0 -37
  774. data/ext/p7zip/CPP/7zip/Archive/DebHandler.cpp +0 -413
  775. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsHandler.cpp +0 -243
  776. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsHandler.h +0 -26
  777. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsIn.cpp +0 -480
  778. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsIn.h +0 -154
  779. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsRegister.cpp +0 -13
  780. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHeader.cpp +0 -21
  781. data/ext/p7zip/CPP/7zip/Archive/Rar/RarIn.cpp +0 -478
  782. data/ext/p7zip/CPP/7zip/Archive/Rar/RarIn.h +0 -123
  783. data/ext/p7zip/CPP/7zip/Archive/Rar/RarItem.cpp +0 -55
  784. data/ext/p7zip/CPP/7zip/Archive/Rar/RarRegister.cpp +0 -13
  785. data/ext/p7zip/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp +0 -78
  786. data/ext/p7zip/CPP/7zip/Archive/Rar/RarVolumeInStream.h +0 -49
  787. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfRegister.cpp +0 -13
  788. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHeader.cpp +0 -36
  789. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItemEx.h +0 -34
  790. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7zFM.txt +0 -163
  791. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7zG.txt +0 -131
  792. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7za.txt +0 -253
  793. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_ALL.txt +0 -32
  794. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_Format7zFree.txt +0 -290
  795. data/ext/p7zip/CPP/7zip/CMAKE/generate.sh +0 -37
  796. data/ext/p7zip/CPP/7zip/CMAKE/generate_xcode.sh +0 -32
  797. data/ext/p7zip/CPP/7zip/Common/LockedStream.cpp +0 -23
  798. data/ext/p7zip/CPP/7zip/Common/LockedStream.h +0 -38
  799. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder1.cpp +0 -309
  800. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder1.h +0 -98
  801. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder2.cpp +0 -90
  802. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder2.h +0 -59
  803. data/ext/p7zip/CPP/7zip/Compress/BranchCoder.cpp +0 -19
  804. data/ext/p7zip/CPP/7zip/Compress/BranchCoder.h +0 -44
  805. data/ext/p7zip/CPP/7zip/Compress/DllExports.cpp +0 -39
  806. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp +0 -531
  807. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp +0 -1018
  808. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h +0 -48
  809. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp +0 -311
  810. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h +0 -20
  811. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/makefile +0 -173
  812. data/ext/p7zip/CPP/7zip/Compress/Lzx86Converter.cpp +0 -90
  813. data/ext/p7zip/CPP/7zip/Compress/Lzx86Converter.h +0 -46
  814. data/ext/p7zip/CPP/7zip/Compress/RangeCoder.h +0 -205
  815. data/ext/p7zip/CPP/7zip/Compress/RangeCoderBit.h +0 -114
  816. data/ext/p7zip/CPP/7zip/Crypto/Sha1.cpp +0 -229
  817. data/ext/p7zip/CPP/7zip/Crypto/Sha1.h +0 -68
  818. data/ext/p7zip/CPP/7zip/PREMAKE/generate.sh +0 -18
  819. data/ext/p7zip/CPP/7zip/PREMAKE/premake4.lua +0 -263
  820. data/ext/p7zip/CPP/7zip/QMAKE/7ZA/7ZA.pro +0 -228
  821. data/ext/p7zip/CPP/7zip/QMAKE/7ZA/7ZA_osx.pro +0 -228
  822. data/ext/p7zip/CPP/7zip/QMAKE/test_emul/test_emul.pro +0 -26
  823. data/ext/p7zip/CPP/7zip/TEST/TestUI/TestUI.cpp +0 -560
  824. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile +0 -33
  825. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile.depend +0 -577
  826. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile.list +0 -16
  827. data/ext/p7zip/CPP/Common/Buffer.h +0 -77
  828. data/ext/p7zip/CPP/Common/Types.h +0 -11
  829. data/ext/p7zip/CPP/Windows/COM.cpp +0 -37
  830. data/ext/p7zip/CPP/Windows/COM.h +0 -69
  831. data/ext/p7zip/CPP/Windows/Clipboard.cpp +0 -160
  832. data/ext/p7zip/CPP/Windows/Clipboard.h +0 -28
  833. data/ext/p7zip/CPP/Windows/CommonDialog.h +0 -19
  834. data/ext/p7zip/CPP/Windows/Control/ComboBox.h +0 -82
  835. data/ext/p7zip/CPP/Windows/Control/Controls.cpp +0 -515
  836. data/ext/p7zip/CPP/Windows/Control/Dialog.cpp +0 -560
  837. data/ext/p7zip/CPP/Windows/Control/Dialog.h +0 -179
  838. data/ext/p7zip/CPP/Windows/Control/DialogImpl.h +0 -73
  839. data/ext/p7zip/CPP/Windows/Control/Edit.h +0 -24
  840. data/ext/p7zip/CPP/Windows/Control/ListView.h +0 -164
  841. data/ext/p7zip/CPP/Windows/Control/ProgressBar.h +0 -34
  842. data/ext/p7zip/CPP/Windows/Control/Static.h +0 -23
  843. data/ext/p7zip/CPP/Windows/Control/StatusBar.h +0 -56
  844. data/ext/p7zip/CPP/Windows/Control/Window2.cpp +0 -211
  845. data/ext/p7zip/CPP/Windows/Control/Window2.h +0 -111
  846. data/ext/p7zip/CPP/Windows/DLL.cpp +0 -193
  847. data/ext/p7zip/CPP/Windows/DLL.h +0 -48
  848. data/ext/p7zip/CPP/Windows/Error.cpp +0 -58
  849. data/ext/p7zip/CPP/Windows/Error.h +0 -33
  850. data/ext/p7zip/CPP/Windows/Menu.h +0 -4
  851. data/ext/p7zip/CPP/Windows/PropVariantConversions.cpp +0 -142
  852. data/ext/p7zip/CPP/Windows/PropVariantConversions.h +0 -14
  853. data/ext/p7zip/CPP/Windows/Registry.cpp +0 -313
  854. data/ext/p7zip/CPP/Windows/Registry.h +0 -113
  855. data/ext/p7zip/CPP/Windows/ResourceString.h +0 -22
  856. data/ext/p7zip/CPP/Windows/Shell.h +0 -21
  857. data/ext/p7zip/CPP/Windows/Time.cpp +0 -88
  858. data/ext/p7zip/CPP/Windows/Time.h +0 -21
  859. data/ext/p7zip/CPP/Windows/Window.cpp +0 -101
  860. data/ext/p7zip/CPP/Windows/Window.h +0 -43
  861. data/ext/p7zip/CPP/myWindows/initguid.h +0 -4
  862. data/ext/p7zip/CPP/myWindows/makefile +0 -21
  863. data/ext/p7zip/CPP/myWindows/makefile.depend +0 -32
  864. data/ext/p7zip/CPP/myWindows/makefile.list +0 -28
  865. data/ext/p7zip/CPP/myWindows/myAddExeFlag.cpp +0 -20
  866. data/ext/p7zip/CPP/myWindows/myGetTickCount.cpp +0 -8
  867. data/ext/p7zip/CPP/myWindows/mySplitCommandLine.cpp +0 -82
  868. data/ext/p7zip/CPP/myWindows/test_emul.cpp +0 -745
  869. data/ext/p7zip/CPP/myWindows/wine_GetXXXDefaultLangID.cpp +0 -741
  870. data/ext/p7zip/DOCS/MANUAL/switches/charset.htm +0 -49
  871. data/ext/p7zip/DOCS/Methods.txt +0 -152
  872. data/ext/p7zip/DOCS/lzma.txt +0 -598
  873. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/ChangeLog +0 -41
  874. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/readme +0 -21
  875. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/readme.u7z +0 -30
  876. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/u7z +0 -133
  877. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/README +0 -21
  878. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/check/check.sh +0 -117
  879. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/check/files.tar +0 -0
  880. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/man1/p7zip.1 +0 -33
  881. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/p7zip +0 -144
  882. data/ext/p7zip/contrib/qnx630sp3/qnx630sp3-shared +0 -14
  883. data/ext/p7zip/contrib/qnx630sp3/qnx630sp3-static +0 -10
  884. data/ext/p7zip/integration_context_menu.txt +0 -51
  885. data/ext/p7zip/makefile.rules +0 -661
  886. /data/ext/p7zip/{DOCS → DOC}/7zFormat.txt +0 -0
  887. /data/ext/p7zip/{DOCS → DOC}/unRarLicense.txt +0 -0
@@ -2,13 +2,26 @@
2
2
 
3
3
  #include "StdAfx.h"
4
4
 
5
+ // #define SHOW_DEBUG_INFO
6
+
7
+ #ifdef SHOW_DEBUG_INFO
8
+ #include <stdio.h>
9
+ #define PRF(x) x
10
+ #else
11
+ #define PRF(x)
12
+ #endif
13
+
5
14
  #include "../../../../C/CpuArch.h"
6
15
 
7
- #include "Common/IntToString.h"
16
+ #include "../../../Common/IntToString.h"
17
+ #include "../../../Common/StringToInt.h"
18
+ #include "../../../Common/UTFConvert.h"
8
19
 
9
- #include "../../Common/StreamUtils.h"
10
- #include "../../Common/StreamObjects.h"
11
20
  #include "../../Common/LimitedStreams.h"
21
+ #include "../../Common/StreamObjects.h"
22
+ #include "../../Common/StreamUtils.h"
23
+
24
+ #include "../../Compress/XpressDecoder.h"
12
25
 
13
26
  #include "../Common/OutStreamWithSha1.h"
14
27
 
@@ -21,589 +34,881 @@
21
34
  namespace NArchive {
22
35
  namespace NWim {
23
36
 
24
- namespace NXpress {
37
+ static int inline GetLog(UInt32 num)
38
+ {
39
+ for (int i = 0; i < 32; i++)
40
+ if (((UInt32)1 << i) == num)
41
+ return i;
42
+ return -1;
43
+ }
44
+
25
45
 
26
- class CDecoderFlusher
46
+ CUnpacker::~CUnpacker()
27
47
  {
28
- CDecoder *m_Decoder;
29
- public:
30
- bool NeedFlush;
31
- CDecoderFlusher(CDecoder *decoder): m_Decoder(decoder), NeedFlush(true) {}
32
- ~CDecoderFlusher()
33
- {
34
- if (NeedFlush)
35
- m_Decoder->Flush();
36
- m_Decoder->ReleaseStreams();
37
- }
38
- };
48
+ if (lzmsDecoder)
49
+ delete lzmsDecoder;
50
+ }
39
51
 
40
- HRESULT CDecoder::CodeSpec(UInt32 outSize)
52
+
53
+ HRESULT CUnpacker::UnpackChunk(
54
+ ISequentialInStream *inStream,
55
+ unsigned method, unsigned chunkSizeBits,
56
+ size_t inSize, size_t outSize,
57
+ ISequentialOutStream *outStream)
41
58
  {
59
+ if (inSize == outSize)
60
+ {
61
+ }
62
+ else if (method == NMethod::kXPRESS)
63
+ {
64
+ }
65
+ else if (method == NMethod::kLZX)
42
66
  {
43
- Byte levels[kMainTableSize];
44
- for (unsigned i = 0; i < kMainTableSize; i += 2)
67
+ if (!lzxDecoder)
45
68
  {
46
- Byte b = m_InBitStream.DirectReadByte();
47
- levels[i] = b & 0xF;
48
- levels[i + 1] = b >> 4;
69
+ lzxDecoderSpec = new NCompress::NLzx::CDecoder(true);
70
+ lzxDecoder = lzxDecoderSpec;
49
71
  }
50
- if (!m_MainDecoder.SetCodeLengths(levels))
51
- return S_FALSE;
52
72
  }
73
+ else if (method == NMethod::kLZMS)
74
+ {
75
+ if (!lzmsDecoder)
76
+ lzmsDecoder = new NCompress::NLzms::CDecoder();
77
+ }
78
+ else
79
+ return E_NOTIMPL;
53
80
 
54
- while (outSize > 0)
81
+ const size_t chunkSize = (size_t)1 << chunkSizeBits;
82
+
83
+ unpackBuf.EnsureCapacity(chunkSize);
84
+ if (!unpackBuf.Data)
85
+ return E_OUTOFMEMORY;
86
+
87
+ HRESULT res = S_FALSE;
88
+ size_t unpackedSize = 0;
89
+
90
+ if (inSize == outSize)
91
+ {
92
+ unpackedSize = outSize;
93
+ res = ReadStream(inStream, unpackBuf.Data, &unpackedSize);
94
+ TotalPacked += unpackedSize;
95
+ }
96
+ else if (inSize < chunkSize)
55
97
  {
56
- UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
57
- if (number < 256)
98
+ packBuf.EnsureCapacity(chunkSize);
99
+ if (!packBuf.Data)
100
+ return E_OUTOFMEMORY;
101
+
102
+ RINOK(ReadStream_FALSE(inStream, packBuf.Data, inSize));
103
+
104
+ TotalPacked += inSize;
105
+
106
+ if (method == NMethod::kXPRESS)
58
107
  {
59
- m_OutWindowStream.PutByte((Byte)number);
60
- outSize--;
108
+ res = NCompress::NXpress::Decode(packBuf.Data, inSize, unpackBuf.Data, outSize);
109
+ if (res == S_OK)
110
+ unpackedSize = outSize;
111
+ }
112
+ else if (method == NMethod::kLZX)
113
+ {
114
+ lzxDecoderSpec->SetExternalWindow(unpackBuf.Data, chunkSizeBits);
115
+ lzxDecoderSpec->KeepHistoryForNext = false;
116
+ lzxDecoderSpec->SetKeepHistory(false);
117
+ res = lzxDecoderSpec->Code(packBuf.Data, inSize, (UInt32)outSize);
118
+ unpackedSize = lzxDecoderSpec->GetUnpackSize();
119
+ if (res == S_OK && !lzxDecoderSpec->WasBlockFinished())
120
+ res = S_FALSE;
61
121
  }
62
122
  else
63
123
  {
64
- if (number >= kMainTableSize)
65
- return S_FALSE;
66
- UInt32 posLenSlot = number - 256;
67
- UInt32 posSlot = posLenSlot / kNumLenSlots;
68
- UInt32 len = posLenSlot % kNumLenSlots;
69
- UInt32 distance = (1 << posSlot) - 1 + m_InBitStream.ReadBits(posSlot);
70
-
71
- if (len == kNumLenSlots - 1)
72
- {
73
- len = m_InBitStream.DirectReadByte();
74
- if (len == 0xFF)
75
- {
76
- len = m_InBitStream.DirectReadByte();
77
- len |= (UInt32)m_InBitStream.DirectReadByte() << 8;
78
- }
79
- else
80
- len += kNumLenSlots - 1;
81
- }
82
-
83
- len += kMatchMinLen;
84
- UInt32 locLen = (len <= outSize ? len : outSize);
85
-
86
- if (!m_OutWindowStream.CopyBlock(distance, locLen))
87
- return S_FALSE;
88
-
89
- len -= locLen;
90
- outSize -= locLen;
91
- if (len != 0)
92
- return S_FALSE;
124
+ res = lzmsDecoder->Code(packBuf.Data, inSize, unpackBuf.Data, outSize);
125
+ unpackedSize = lzmsDecoder->GetUnpackSize();;
93
126
  }
94
127
  }
95
- return S_OK;
128
+
129
+ if (unpackedSize != outSize)
130
+ {
131
+ if (res == S_OK)
132
+ res = S_FALSE;
133
+
134
+ if (unpackedSize > outSize)
135
+ res = S_FALSE;
136
+ else
137
+ memset(unpackBuf.Data + unpackedSize, 0, outSize - unpackedSize);
138
+ }
139
+
140
+ if (outStream)
141
+ {
142
+ RINOK(WriteStream(outStream, unpackBuf.Data, outSize));
143
+ }
144
+
145
+ return res;
96
146
  }
97
147
 
98
- const UInt32 kDictSize = (1 << kNumPosSlots);
99
148
 
100
- HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, UInt32 outSize)
149
+ HRESULT CUnpacker::Unpack2(
150
+ IInStream *inStream,
151
+ const CResource &resource,
152
+ const CHeader &header,
153
+ const CDatabase *db,
154
+ ISequentialOutStream *outStream,
155
+ ICompressProgressInfo *progress)
101
156
  {
102
- if (!m_OutWindowStream.Create(kDictSize) || !m_InBitStream.Create(1 << 16))
103
- return E_OUTOFMEMORY;
104
-
105
- CDecoderFlusher flusher(this);
106
-
107
- m_InBitStream.SetStream(inStream);
108
- m_OutWindowStream.SetStream(outStream);
109
- m_InBitStream.Init();
110
- m_OutWindowStream.Init(false);
157
+ if (!resource.IsCompressed() && !resource.IsSolid())
158
+ {
159
+ if (!copyCoder)
160
+ {
161
+ copyCoderSpec = new NCompress::CCopyCoder;
162
+ copyCoder = copyCoderSpec;
163
+ }
111
164
 
112
- RINOK(CodeSpec(outSize));
165
+ CLimitedSequentialInStream *limitedStreamSpec = new CLimitedSequentialInStream();
166
+ CMyComPtr<ISequentialInStream> limitedStream = limitedStreamSpec;
167
+ limitedStreamSpec->SetStream(inStream);
168
+
169
+ RINOK(inStream->Seek(resource.Offset, STREAM_SEEK_SET, NULL));
170
+ if (resource.PackSize != resource.UnpackSize)
171
+ return S_FALSE;
113
172
 
114
- flusher.NeedFlush = false;
115
- return Flush();
116
- }
173
+ limitedStreamSpec->Init(resource.PackSize);
174
+ TotalPacked += resource.PackSize;
175
+
176
+ HRESULT res = copyCoder->Code(limitedStream, outStream, NULL, NULL, progress);
177
+
178
+ if (res == S_OK && copyCoderSpec->TotalSize != resource.UnpackSize)
179
+ res = S_FALSE;
180
+ return res;
181
+ }
182
+
183
+ if (resource.IsSolid())
184
+ {
185
+ if (!db || resource.SolidIndex < 0)
186
+ return E_NOTIMPL;
187
+ if (resource.IsCompressed())
188
+ return E_NOTIMPL;
117
189
 
118
- HRESULT CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream, UInt32 outSize)
119
- {
120
- try { return CodeReal(inStream, outStream, outSize); }
121
- catch(const CInBufferException &e) { return e.ErrorCode; } \
122
- catch(const CLzOutWindowException &e) { return e.ErrorCode; }
123
- catch(...) { return S_FALSE; }
124
- }
190
+ const CSolid &ss = db->Solids[resource.SolidIndex];
191
+
192
+ const unsigned chunkSizeBits = ss.ChunkSizeBits;
193
+ const size_t chunkSize = (size_t)1 << chunkSizeBits;
194
+
195
+ size_t chunkIndex = 0;
196
+ UInt64 rem = ss.UnpackSize;
197
+ size_t offsetInChunk = 0;
198
+
199
+ if (resource.IsSolidSmall())
200
+ {
201
+ UInt64 offs = resource.Offset;
202
+ if (offs < ss.SolidOffset)
203
+ return E_NOTIMPL;
204
+ offs -= ss.SolidOffset;
205
+ if (offs > ss.UnpackSize)
206
+ return E_NOTIMPL;
207
+ rem = resource.PackSize;
208
+ if (rem > ss.UnpackSize - offs)
209
+ return E_NOTIMPL;
210
+ chunkIndex = (size_t)(offs >> chunkSizeBits);
211
+ offsetInChunk = (size_t)offs & (chunkSize - 1);
212
+ }
213
+
214
+ UInt64 packProcessed = 0;
215
+ UInt64 outProcessed = 0;
216
+
217
+ if (_solidIndex == resource.SolidIndex && _unpackedChunkIndex == chunkIndex)
218
+ {
219
+ size_t cur = chunkSize - offsetInChunk;
220
+ if (cur > rem)
221
+ cur = (size_t)rem;
222
+ RINOK(WriteStream(outStream, unpackBuf.Data + offsetInChunk, cur));
223
+ outProcessed += cur;
224
+ rem -= cur;
225
+ offsetInChunk = 0;
226
+ chunkIndex++;
227
+ }
228
+
229
+ for (;;)
230
+ {
231
+ if (rem == 0)
232
+ return S_OK;
233
+
234
+ UInt64 offset = ss.Chunks[chunkIndex];
235
+ UInt64 packSize = ss.GetChunkPackSize(chunkIndex);
236
+ const CResource &rs = db->DataStreams[ss.StreamIndex].Resource;
237
+ RINOK(inStream->Seek(rs.Offset + ss.HeadersSize + offset, STREAM_SEEK_SET, NULL));
238
+
239
+ size_t cur = chunkSize;
240
+ UInt64 unpackRem = ss.UnpackSize - ((UInt64)chunkIndex << chunkSizeBits);
241
+ if (cur > unpackRem)
242
+ cur = (size_t)unpackRem;
243
+
244
+ _solidIndex = -1;
245
+ _unpackedChunkIndex = 0;
246
+
247
+ HRESULT res = UnpackChunk(inStream, ss.Method, chunkSizeBits, (size_t)packSize, cur, NULL);
248
+
249
+ if (res != S_OK)
250
+ {
251
+ // We ignore data errors in solid stream. SHA will show what files are bad.
252
+ if (res != S_FALSE)
253
+ return res;
254
+ }
255
+
256
+ _solidIndex = resource.SolidIndex;
257
+ _unpackedChunkIndex = chunkIndex;
125
258
 
126
- }
259
+ if (cur < offsetInChunk)
260
+ return E_FAIL;
261
+
262
+ cur -= offsetInChunk;
263
+
264
+ if (cur > rem)
265
+ cur = (size_t)rem;
266
+
267
+ RINOK(WriteStream(outStream, unpackBuf.Data + offsetInChunk, cur));
268
+
269
+ if (progress)
270
+ {
271
+ RINOK(progress->SetRatioInfo(&packProcessed, &outProcessed));
272
+ packProcessed += packSize;
273
+ outProcessed += cur;
274
+ }
275
+
276
+ rem -= cur;
277
+ offsetInChunk = 0;
278
+ chunkIndex++;
279
+ }
280
+ }
127
281
 
128
- HRESULT CUnpacker::Unpack(IInStream *inStream, const CResource &resource, bool lzxMode,
129
- ISequentialOutStream *outStream, ICompressProgressInfo *progress)
130
- {
131
- RINOK(inStream->Seek(resource.Offset, STREAM_SEEK_SET, NULL));
132
282
 
133
- CLimitedSequentialInStream *limitedStreamSpec = new CLimitedSequentialInStream();
134
- CMyComPtr<ISequentialInStream> limitedStream = limitedStreamSpec;
135
- limitedStreamSpec->SetStream(inStream);
283
+ // ---------- NON Solid ----------
136
284
 
137
- if (!copyCoder)
285
+ const UInt64 unpackSize = resource.UnpackSize;
286
+ if (unpackSize == 0)
138
287
  {
139
- copyCoderSpec = new NCompress::CCopyCoder;
140
- copyCoder = copyCoderSpec;
288
+ if (resource.PackSize == 0)
289
+ return S_OK;
290
+ return S_FALSE;
141
291
  }
142
- if (!resource.IsCompressed())
292
+
293
+ if (unpackSize > ((UInt64)1 << 63))
294
+ return E_NOTIMPL;
295
+
296
+ const unsigned chunkSizeBits = header.ChunkSizeBits;
297
+ const unsigned entrySizeShifts = (resource.UnpackSize < ((UInt64)1 << 32) ? 2 : 3);
298
+
299
+ UInt64 baseOffset = resource.Offset;
300
+ UInt64 packDataSize;
301
+ size_t numChunks;
143
302
  {
144
- if (resource.PackSize != resource.UnpackSize)
303
+ UInt64 numChunks64 = (unpackSize + (((UInt32)1 << chunkSizeBits) - 1)) >> chunkSizeBits;
304
+ UInt64 sizesBufSize64 = (numChunks64 - 1) << entrySizeShifts;
305
+ if (sizesBufSize64 > resource.PackSize)
145
306
  return S_FALSE;
146
- limitedStreamSpec->Init(resource.PackSize);
147
- return copyCoder->Code(limitedStreamSpec, outStream, NULL, NULL, progress);
148
- }
149
- if (resource.UnpackSize == 0)
150
- return S_OK;
151
- UInt64 numChunks = (resource.UnpackSize + kChunkSize - 1) >> kChunkSizeBits;
152
- unsigned entrySize = ((resource.UnpackSize > (UInt64)1 << 32) ? 8 : 4);
153
- UInt64 sizesBufSize64 = entrySize * (numChunks - 1);
154
- size_t sizesBufSize = (size_t)sizesBufSize64;
155
- if (sizesBufSize != sizesBufSize64)
156
- return E_OUTOFMEMORY;
157
- if (sizesBufSize > sizesBuf.GetCapacity())
158
- {
159
- sizesBuf.Free();
160
- sizesBuf.SetCapacity(sizesBufSize);
161
- }
162
- RINOK(ReadStream_FALSE(inStream, (Byte *)sizesBuf, sizesBufSize));
163
- const Byte *p = (const Byte *)sizesBuf;
164
-
165
- if (lzxMode && !lzxDecoder)
166
- {
167
- lzxDecoderSpec = new NCompress::NLzx::CDecoder(true);
168
- lzxDecoder = lzxDecoderSpec;
169
- RINOK(lzxDecoderSpec->SetParams(kChunkSizeBits));
307
+ packDataSize = resource.PackSize - sizesBufSize64;
308
+ size_t sizesBufSize = (size_t)sizesBufSize64;
309
+ if (sizesBufSize != sizesBufSize64)
310
+ return E_OUTOFMEMORY;
311
+ sizesBuf.AllocAtLeast(sizesBufSize);
312
+ RINOK(inStream->Seek(baseOffset, STREAM_SEEK_SET, NULL));
313
+ RINOK(ReadStream_FALSE(inStream, sizesBuf, sizesBufSize));
314
+ baseOffset += sizesBufSize64;
315
+ numChunks = (size_t)numChunks64;
170
316
  }
171
-
172
- UInt64 baseOffset = resource.Offset + sizesBufSize64;
317
+
318
+ _solidIndex = -1;
319
+ _unpackedChunkIndex = 0;
320
+
173
321
  UInt64 outProcessed = 0;
174
- for (UInt32 i = 0; i < (UInt32)numChunks; i++)
322
+ UInt64 offset = 0;
323
+
324
+ for (size_t i = 0; i < numChunks; i++)
175
325
  {
176
- UInt64 offset = 0;
177
- if (i > 0)
326
+ UInt64 nextOffset = packDataSize;
327
+
328
+ if (i + 1 < numChunks)
178
329
  {
179
- offset = (entrySize == 4) ? Get32(p): Get64(p);
180
- p += entrySize;
330
+ const Byte *p = (const Byte *)sizesBuf + (i << entrySizeShifts);
331
+ nextOffset = (entrySizeShifts == 2) ? Get32(p): Get64(p);
181
332
  }
182
- UInt64 nextOffset = resource.PackSize - sizesBufSize64;
183
- if (i + 1 < (UInt32)numChunks)
184
- nextOffset = (entrySize == 4) ? Get32(p): Get64(p);
333
+
185
334
  if (nextOffset < offset)
186
335
  return S_FALSE;
187
336
 
337
+ UInt64 inSize64 = nextOffset - offset;
338
+ size_t inSize = (size_t)inSize64;
339
+ if (inSize != inSize64)
340
+ return S_FALSE;
341
+
188
342
  RINOK(inStream->Seek(baseOffset + offset, STREAM_SEEK_SET, NULL));
189
- UInt64 inSize = nextOffset - offset;
190
- limitedStreamSpec->Init(inSize);
191
343
 
192
344
  if (progress)
193
345
  {
194
346
  RINOK(progress->SetRatioInfo(&offset, &outProcessed));
195
347
  }
196
348
 
197
- UInt32 outSize = kChunkSize;
198
- if (outProcessed + outSize > resource.UnpackSize)
199
- outSize = (UInt32)(resource.UnpackSize - outProcessed);
200
- UInt64 outSize64 = outSize;
201
- if (inSize == outSize)
202
- {
203
- RINOK(copyCoder->Code(limitedStreamSpec, outStream, NULL, &outSize64, NULL));
204
- }
205
- else
206
- {
207
- if (lzxMode)
208
- {
209
- lzxDecoderSpec->SetKeepHistory(false);
210
- RINOK(lzxDecoder->Code(limitedStreamSpec, outStream, NULL, &outSize64, NULL));
211
- }
212
- else
213
- {
214
- RINOK(xpressDecoder.Code(limitedStreamSpec, outStream, outSize));
215
- }
216
- }
349
+ size_t outSize = (size_t)1 << chunkSizeBits;
350
+ const UInt64 rem = unpackSize - outProcessed;
351
+ if (outSize > rem)
352
+ outSize = (size_t)rem;
353
+
354
+ RINOK(UnpackChunk(inStream, header.GetMethod(), chunkSizeBits, inSize, outSize, outStream));
355
+
217
356
  outProcessed += outSize;
357
+ offset = nextOffset;
218
358
  }
359
+
219
360
  return S_OK;
220
361
  }
221
362
 
222
- HRESULT CUnpacker::Unpack(IInStream *inStream, const CResource &resource, bool lzxMode,
363
+
364
+ HRESULT CUnpacker::Unpack(IInStream *inStream, const CResource &resource, const CHeader &header, const CDatabase *db,
223
365
  ISequentialOutStream *outStream, ICompressProgressInfo *progress, Byte *digest)
224
366
  {
225
- COutStreamWithSha1 *shaStreamSpec = new COutStreamWithSha1();
226
- CMyComPtr<ISequentialOutStream> shaStream = shaStreamSpec;
227
- shaStreamSpec->SetStream(outStream);
228
- shaStreamSpec->Init(digest != NULL);
229
- HRESULT result = Unpack(inStream, resource, lzxMode, shaStream, progress);
367
+ COutStreamWithSha1 *shaStreamSpec = NULL;
368
+ CMyComPtr<ISequentialOutStream> shaStream;
369
+
370
+ // outStream can be NULL, so we use COutStreamWithSha1 even if sha1 is not required
371
+ // if (digest)
372
+ {
373
+ shaStreamSpec = new COutStreamWithSha1();
374
+ shaStream = shaStreamSpec;
375
+ shaStreamSpec->SetStream(outStream);
376
+ shaStreamSpec->Init(digest != NULL);
377
+ outStream = shaStream;
378
+ }
379
+
380
+ HRESULT res = Unpack2(inStream, resource, header, db, outStream, progress);
381
+
230
382
  if (digest)
231
383
  shaStreamSpec->Final(digest);
232
- return result;
384
+
385
+ return res;
233
386
  }
234
387
 
235
- static HRESULT UnpackData(IInStream *inStream, const CResource &resource, bool lzxMode, CByteBuffer &buf, Byte *digest)
388
+
389
+ HRESULT CUnpacker::UnpackData(IInStream *inStream,
390
+ const CResource &resource, const CHeader &header,
391
+ const CDatabase *db,
392
+ CByteBuffer &buf, Byte *digest)
236
393
  {
237
- size_t size = (size_t)resource.UnpackSize;
238
- if (size != resource.UnpackSize)
394
+ // if (resource.IsSolid()) return E_NOTIMPL;
395
+
396
+ UInt64 unpackSize64 = resource.UnpackSize;
397
+ if (db)
398
+ unpackSize64 = db->Get_UnpackSize_of_Resource(resource);
399
+
400
+ size_t size = (size_t)unpackSize64;
401
+ if (size != unpackSize64)
239
402
  return E_OUTOFMEMORY;
240
- buf.Free();
241
- buf.SetCapacity(size);
403
+
404
+ buf.Alloc(size);
242
405
 
243
406
  CBufPtrSeqOutStream *outStreamSpec = new CBufPtrSeqOutStream();
244
407
  CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
245
408
  outStreamSpec->Init((Byte *)buf, size);
246
409
 
247
- CUnpacker unpacker;
248
- return unpacker.Unpack(inStream, resource, lzxMode, outStream, NULL, digest);
410
+ return Unpack(inStream, resource, header, db, outStream, NULL, digest);
249
411
  }
250
412
 
413
+
251
414
  void CResource::Parse(const Byte *p)
252
415
  {
253
416
  Flags = p[7];
254
417
  PackSize = Get64(p) & (((UInt64)1 << 56) - 1);
255
418
  Offset = Get64(p + 8);
256
419
  UnpackSize = Get64(p + 16);
420
+ KeepSolid = false;
421
+ SolidIndex = -1;
257
422
  }
258
423
 
259
- #define GetResource(p, res) res.Parse(p)
424
+ #define GET_RESOURCE(_p_, res) res.ParseAndUpdatePhySize(_p_, phySize)
260
425
 
261
- static void GetStream(bool oldVersion, const Byte *p, CStreamInfo &s)
426
+ static inline void ParseStream(bool oldVersion, const Byte *p, CStreamInfo &s)
262
427
  {
263
428
  s.Resource.Parse(p);
264
429
  if (oldVersion)
265
430
  {
266
431
  s.PartNumber = 1;
267
432
  s.Id = Get32(p + 24);
268
- s.RefCount = Get32(p + 28);
269
- memcpy(s.Hash, p + 32, kHashSize);
433
+ p += 28;
270
434
  }
271
435
  else
272
436
  {
273
437
  s.PartNumber = Get16(p + 24);
274
- s.RefCount = Get32(p + 26);
275
- memcpy(s.Hash, p + 30, kHashSize);
438
+ p += 26;
439
+ }
440
+ s.RefCount = Get32(p);
441
+ memcpy(s.Hash, p + 4, kHashSize);
442
+ }
443
+
444
+
445
+ static const char *kLongPath = "[LongPath]";
446
+
447
+ void CDatabase::GetShortName(unsigned index, NWindows::NCOM::CPropVariant &name) const
448
+ {
449
+ const CItem &item = Items[index];
450
+ const CImage &image = Images[item.ImageIndex];
451
+ if (item.Parent < 0 && image.NumEmptyRootItems != 0)
452
+ {
453
+ name.Clear();
454
+ return;
455
+ }
456
+ const Byte *meta = image.Meta + item.Offset +
457
+ (IsOldVersion ? kDirRecordSizeOld : kDirRecordSize);
458
+ UInt32 fileNameLen = Get16(meta - 2);
459
+ UInt32 shortLen = Get16(meta - 4) / 2;
460
+ wchar_t *s = name.AllocBstr(shortLen);
461
+ if (fileNameLen != 0)
462
+ meta += fileNameLen + 2;
463
+ for (UInt32 i = 0; i < shortLen; i++)
464
+ s[i] = Get16(meta + i * 2);
465
+ s[shortLen] = 0;
466
+ // empty shortName has no ZERO at the end ?
467
+ }
468
+
469
+
470
+ void CDatabase::GetItemName(unsigned index, NWindows::NCOM::CPropVariant &name) const
471
+ {
472
+ const CItem &item = Items[index];
473
+ const CImage &image = Images[item.ImageIndex];
474
+ if (item.Parent < 0 && image.NumEmptyRootItems != 0)
475
+ {
476
+ name = image.RootName;
477
+ return;
276
478
  }
479
+ const Byte *meta = image.Meta + item.Offset +
480
+ (item.IsAltStream ?
481
+ (IsOldVersion ? 0x10 : 0x24) :
482
+ (IsOldVersion ? kDirRecordSizeOld - 2 : kDirRecordSize - 2));
483
+ UInt32 len = Get16(meta) / 2;
484
+ wchar_t *s = name.AllocBstr(len);
485
+ meta += 2;
486
+ len++;
487
+ for (UInt32 i = 0; i < len; i++)
488
+ s[i] = Get16(meta + i * 2);
277
489
  }
278
490
 
279
- static const wchar_t *kLongPath = L"[LongPath]";
280
491
 
281
- UString CDatabase::GetItemPath(const int index1) const
492
+ void CDatabase::GetItemPath(unsigned index1, bool showImageNumber, NWindows::NCOM::CPropVariant &path) const
282
493
  {
283
- int size = 0;
494
+ unsigned size = 0;
284
495
  int index = index1;
285
- int newLevel;
286
- for (newLevel = 0;; newLevel = 1)
496
+ int imageIndex = Items[index].ImageIndex;
497
+ const CImage &image = Images[imageIndex];
498
+
499
+ unsigned newLevel = 0;
500
+ bool needColon = false;
501
+
502
+ for (;;)
287
503
  {
288
504
  const CItem &item = Items[index];
289
505
  index = item.Parent;
290
- if (index >= 0 || !SkipRoot)
291
- size += item.Name.Length() + newLevel;
506
+ if (index >= 0 || image.NumEmptyRootItems == 0)
507
+ {
508
+ const Byte *meta = image.Meta + item.Offset;
509
+ meta += item.IsAltStream ?
510
+ (IsOldVersion ? 0x10 : 0x24) :
511
+ (IsOldVersion ? kDirRecordSizeOld - 2 : kDirRecordSize - 2);
512
+ needColon = item.IsAltStream;
513
+ size += Get16(meta) / 2;
514
+ size += newLevel;
515
+ newLevel = 1;
516
+ if (size >= ((UInt32)1 << 15))
517
+ {
518
+ path = kLongPath;
519
+ return;
520
+ }
521
+ }
292
522
  if (index < 0)
293
523
  break;
294
- if ((UInt32)size >= ((UInt32)1 << 16))
295
- return kLongPath;
296
524
  }
297
525
 
298
- wchar_t temp[16];
299
- int imageLen = 0;
300
- if (ShowImageNumber)
526
+ if (showImageNumber)
301
527
  {
302
- ConvertUInt32ToString(-1 - index, temp);
303
- imageLen = MyStringLen(temp);
304
- size += imageLen + 1;
528
+ size += image.RootName.Len();
529
+ size += newLevel;
305
530
  }
306
- if ((UInt32)size >= ((UInt32)1 << 16))
307
- return kLongPath;
308
-
309
- UString path;
310
- wchar_t *s = path.GetBuffer(size);
531
+ else if (needColon)
532
+ size++;
533
+
534
+ wchar_t *s = path.AllocBstr(size);
311
535
  s[size] = 0;
312
- if (ShowImageNumber)
536
+
537
+ if (showImageNumber)
313
538
  {
314
- memcpy(s, temp, imageLen * sizeof(wchar_t));
315
- s[imageLen] = WCHAR_PATH_SEPARATOR;
539
+ MyStringCopy(s, (const wchar_t *)image.RootName);
540
+ if (newLevel)
541
+ s[image.RootName.Len()] = (wchar_t)(needColon ? L':' : WCHAR_PATH_SEPARATOR);
316
542
  }
543
+ else if (needColon)
544
+ s[0] = L':';
317
545
 
318
546
  index = index1;
547
+ wchar_t separator = 0;
319
548
 
320
- for (newLevel = 0;; newLevel = 1)
549
+ for (;;)
321
550
  {
322
551
  const CItem &item = Items[index];
323
552
  index = item.Parent;
324
- if (index >= 0 || !SkipRoot)
553
+ if (index >= 0 || image.NumEmptyRootItems == 0)
325
554
  {
326
- if (newLevel)
327
- s[--size] = WCHAR_PATH_SEPARATOR;
328
- size -= item.Name.Length();
329
- memcpy(s + size, item.Name, sizeof(wchar_t) * item.Name.Length());
555
+ if (separator != 0)
556
+ s[--size] = separator;
557
+ const Byte *meta = image.Meta + item.Offset;
558
+ meta += (item.IsAltStream) ?
559
+ (IsOldVersion ? 0x10: 0x24) :
560
+ (IsOldVersion ? kDirRecordSizeOld - 2 : kDirRecordSize - 2);
561
+ unsigned len = Get16(meta) / 2;
562
+ size -= len;
563
+ wchar_t *dest = s + size;
564
+ meta += 2;
565
+ for (unsigned i = 0; i < len; i++)
566
+ dest[i] = Get16(meta + i * 2);
330
567
  }
331
568
  if (index < 0)
332
- {
333
- path.ReleaseBuffer();
334
- return path;
335
- }
569
+ return;
570
+ separator = item.IsAltStream ? L':' : WCHAR_PATH_SEPARATOR;
336
571
  }
337
572
  }
338
573
 
339
- static void GetFileTimeFromMem(const Byte *p, FILETIME *ft)
340
- {
341
- ft->dwLowDateTime = Get32(p);
342
- ft->dwHighDateTime = Get32(p + 4);
343
- }
344
574
 
345
- static HRESULT ReadName(const Byte *p, int size, UString &dest)
346
- {
347
- if (size == 0)
348
- return S_OK;
349
- if (Get16(p + size) != 0)
350
- return S_FALSE;
351
- wchar_t *s = dest.GetBuffer(size / 2);
352
- for (int i = 0; i <= size; i += 2)
353
- *s++ = Get16(p + i);
354
- dest.ReleaseBuffer();
355
- return S_OK;
356
- }
575
+ // if (ver <= 1.10), root folder contains real items.
576
+ // if (ver >= 1.12), root folder contains only one folder with empty name.
357
577
 
358
578
  HRESULT CDatabase::ParseDirItem(size_t pos, int parent)
359
579
  {
360
- if ((pos & 7) != 0)
580
+ const unsigned align = GetDirAlignMask();
581
+ if ((pos & align) != 0)
361
582
  return S_FALSE;
362
-
363
- int prevIndex = -1;
364
- for (int numItems = 0;; numItems++)
583
+
584
+ for (unsigned numItems = 0;; numItems++)
365
585
  {
366
- if (OpenCallback)
586
+ if (OpenCallback && (Items.Size() & 0xFFFF) == 0)
367
587
  {
368
588
  UInt64 numFiles = Items.Size();
369
- if ((numFiles & 0x3FF) == 0)
370
- {
371
- RINOK(OpenCallback->SetCompleted(&numFiles, NULL));
372
- }
589
+ RINOK(OpenCallback->SetCompleted(&numFiles, NULL));
373
590
  }
374
- size_t rem = DirSize - pos;
591
+
592
+ const size_t rem = DirSize - pos;
375
593
  if (pos < DirStartOffset || pos > DirSize || rem < 8)
376
594
  return S_FALSE;
595
+
377
596
  const Byte *p = DirData + pos;
597
+
378
598
  UInt64 len = Get64(p);
379
599
  if (len == 0)
380
600
  {
381
- if (parent < 0 && numItems != 1)
382
- SkipRoot = false;
383
601
  DirProcessed += 8;
384
602
  return S_OK;
385
603
  }
386
- if ((len & 7) != 0 || rem < len)
604
+
605
+ if ((len & align) != 0 || rem < len)
387
606
  return S_FALSE;
388
- if (!IsOldVersion)
389
- if (len < 0x28)
390
- return S_FALSE;
607
+
391
608
  DirProcessed += (size_t)len;
392
609
  if (DirProcessed > DirSize)
393
610
  return S_FALSE;
394
- int extraOffset = 0;
395
- if (IsOldVersion)
396
- {
397
- if (len < 0x40 || (/* Get32(p + 12) == 0 && */ Get32(p + 0x14) != 0))
398
- {
399
- extraOffset = 0x10;
400
- }
401
- }
402
- else if (Get64(p + 8) == 0)
403
- extraOffset = 0x24;
404
- if (extraOffset)
405
- {
406
- if (prevIndex == -1)
407
- return S_FALSE;
408
- UInt32 fileNameLen = Get16(p + extraOffset);
409
- if ((fileNameLen & 1) != 0)
410
- return S_FALSE;
411
- /* Probably different versions of ImageX can use different number of
412
- additional ZEROs. So we don't use exact check. */
413
- UInt32 fileNameLen2 = (fileNameLen == 0 ? fileNameLen : fileNameLen + 2);
414
- if (((extraOffset + 2 + fileNameLen2 + 6) & ~7) > len)
415
- return S_FALSE;
416
-
417
- UString name;
418
- RINOK(ReadName(p + extraOffset + 2, fileNameLen, name));
419
-
420
- CItem &prevItem = Items[prevIndex];
421
- if (name.IsEmpty() && !prevItem.HasStream())
422
- {
423
- if (IsOldVersion)
424
- prevItem.Id = Get32(p + 8);
425
- else
426
- memcpy(prevItem.Hash, p + 0x10, kHashSize);
427
- }
428
- else
429
- {
430
- CItem item;
431
- item.Name = prevItem.Name + L':' + name;
432
- item.CTime = prevItem.CTime;
433
- item.ATime = prevItem.ATime;
434
- item.MTime = prevItem.MTime;
435
- if (IsOldVersion)
436
- {
437
- item.Id = Get32(p + 8);
438
- memset(item.Hash, 0, kHashSize);
439
- }
440
- else
441
- memcpy(item.Hash, p + 0x10, kHashSize);
442
- item.Attrib = 0;
443
- item.Order = Order++;
444
- item.Parent = parent;
445
- Items.Add(item);
446
- }
447
- pos += (size_t)len;
448
- continue;
449
- }
450
611
 
451
- UInt32 dirRecordSize = IsOldVersion ? kDirRecordSizeOld : kDirRecordSize;
612
+ const unsigned dirRecordSize = IsOldVersion ? kDirRecordSizeOld : kDirRecordSize;
452
613
  if (len < dirRecordSize)
453
614
  return S_FALSE;
454
615
 
455
616
  CItem item;
456
- item.Attrib = Get32(p + 8);
457
- // item.SecurityId = Get32(p + 0xC);
617
+ UInt32 attrib = Get32(p + 8);
618
+ item.IsDir = ((attrib & 0x10) != 0);
458
619
  UInt64 subdirOffset = Get64(p + 0x10);
459
- UInt32 timeOffset = IsOldVersion ? 0x18: 0x28;
460
- GetFileTimeFromMem(p + timeOffset, &item.CTime);
461
- GetFileTimeFromMem(p + timeOffset + 8, &item.ATime);
462
- GetFileTimeFromMem(p + timeOffset + 16, &item.MTime);
463
- if (IsOldVersion)
464
- {
465
- item.Id = Get32(p + 0x10);
466
- memset(item.Hash, 0, kHashSize);
467
- }
468
- else
469
- {
470
- memcpy(item.Hash, p + 0x40, kHashSize);
471
- }
472
- // UInt32 numStreams = Get16(p + dirRecordSize - 6);
473
- UInt32 shortNameLen = Get16(p + dirRecordSize - 4);
474
- UInt32 fileNameLen = Get16(p + dirRecordSize - 2);
475
620
 
621
+ const UInt32 numAltStreams = Get16(p + dirRecordSize - 6);
622
+ const UInt32 shortNameLen = Get16(p + dirRecordSize - 4);
623
+ const UInt32 fileNameLen = Get16(p + dirRecordSize - 2);
476
624
  if ((shortNameLen & 1) != 0 || (fileNameLen & 1) != 0)
477
625
  return S_FALSE;
478
-
479
- UInt32 shortNameLen2 = (shortNameLen == 0 ? shortNameLen : shortNameLen + 2);
480
- UInt32 fileNameLen2 = (fileNameLen == 0 ? fileNameLen : fileNameLen + 2);
481
-
482
- if (((dirRecordSize + fileNameLen2 + shortNameLen2 + 6) & ~7) > len)
626
+ const UInt32 shortNameLen2 = (shortNameLen == 0 ? shortNameLen : shortNameLen + 2);
627
+ const UInt32 fileNameLen2 = (fileNameLen == 0 ? fileNameLen : fileNameLen + 2);
628
+ if (((dirRecordSize + fileNameLen2 + shortNameLen2 + align) & ~align) > len)
483
629
  return S_FALSE;
630
+
484
631
  p += dirRecordSize;
485
632
 
486
- RINOK(ReadName(p, fileNameLen, item.Name));
487
- RINOK(ReadName(p + fileNameLen2, shortNameLen, item.ShortName));
488
-
489
- if (parent < 0 && (shortNameLen || fileNameLen || !item.IsDir()))
490
- SkipRoot = false;
491
-
492
- /*
493
- // there are some extra data for some files.
494
- p -= dirRecordSize;
495
- p += ((dirRecordSize + fileNameLen2 + shortNameLen2 + 6) & ~7);
496
- if (((dirRecordSize + fileNameLen2 + shortNameLen2 + 6) & ~7) != len)
497
- p = p;
498
- */
499
-
500
- /*
501
- if (parent >= 0)
502
633
  {
503
- UString s = GetItemPath(parent) + L"\\" + item.Name;
504
- printf("\n%s %8x %S", item.IsDir() ? "D" : " ", (int)subdirOffset, (const wchar_t *)s);
634
+ if (*(const UInt16 *)(p + fileNameLen) != 0)
635
+ return S_FALSE;
636
+ for (UInt32 j = 0; j < fileNameLen; j += 2)
637
+ if (*(const UInt16 *)(p + j) == 0)
638
+ return S_FALSE;
505
639
  }
506
- */
507
640
 
508
- if (fileNameLen == 0 && item.IsDir() && !item.HasStream())
509
- item.Attrib = 0x10; // some swm archives have system/hidden attributes for root
641
+ // PRF(printf("\n%S", p));
510
642
 
511
- item.Parent = parent;
512
- prevIndex = Items.Add(item);
513
- if (item.IsDir() && subdirOffset != 0)
643
+ if (shortNameLen != 0)
514
644
  {
515
- RINOK(ParseDirItem((size_t)subdirOffset, prevIndex));
645
+ // empty shortName has no ZERO at the end ?
646
+ const Byte *p2 = p + fileNameLen2;
647
+ if (*(const UInt16 *)(p2 + shortNameLen) != 0)
648
+ return S_FALSE;
649
+ for (UInt32 j = 0; j < shortNameLen; j += 2)
650
+ if (*(const UInt16 *)(p2 + j) == 0)
651
+ return S_FALSE;
516
652
  }
517
- Items[prevIndex].Order = Order++;
518
- pos += (size_t)len;
519
- }
520
- }
653
+
654
+ item.Offset = pos;
655
+ item.Parent = parent;
656
+ item.ImageIndex = Images.Size() - 1;
657
+
658
+ const unsigned prevIndex = Items.Add(item);
521
659
 
522
- HRESULT CDatabase::ParseImageDirs(const CByteBuffer &buf, int parent)
523
- {
524
- DirData = buf;
525
- DirSize = buf.GetCapacity();
660
+ pos += (size_t)len;
526
661
 
527
- size_t pos = 0;
528
- if (DirSize < 8)
529
- return S_FALSE;
530
- const Byte *p = DirData;
531
- UInt32 totalLength = Get32(p);
532
- if (IsOldVersion)
533
- {
534
- for (pos = 4;; pos += 8)
662
+ for (UInt32 i = 0; i < numAltStreams; i++)
535
663
  {
536
- if (pos + 4 > DirSize)
664
+ const size_t rem2 = DirSize - pos;
665
+ if (pos < DirStartOffset || pos > DirSize || rem2 < 8)
537
666
  return S_FALSE;
538
- UInt32 n = Get32(p + pos);
539
- if (n == 0)
540
- break;
541
- if (pos + 8 > DirSize)
667
+ const Byte *p2 = DirData + pos;
668
+ const UInt64 len2 = Get64(p2);
669
+ if ((len2 & align) != 0 || rem2 < len2 || len2 < (IsOldVersion ? 0x18 : 0x28))
542
670
  return S_FALSE;
543
- totalLength += Get32(p + pos + 4);
544
- if (totalLength > DirSize)
671
+
672
+ DirProcessed += (size_t)len2;
673
+ if (DirProcessed > DirSize)
545
674
  return S_FALSE;
546
- }
547
- pos += totalLength + 4;
548
- pos = (pos + 7) & ~(size_t)7;
549
- if (pos > DirSize)
550
- return S_FALSE;
551
- }
552
- else
553
- {
554
675
 
555
- // UInt32 numEntries = Get32(p + 4);
556
- pos += 8;
557
- {
558
- /*
559
- CRecordVector<UInt64> entryLens;
560
- UInt64 sum = 0;
561
- for (UInt32 i = 0; i < numEntries; i++)
562
- {
563
- if (pos + 8 > DirSize)
676
+ unsigned extraOffset = 0;
677
+
678
+ if (IsOldVersion)
679
+ extraOffset = 0x10;
680
+ else
681
+ {
682
+ if (Get64(p2 + 8) != 0)
683
+ return S_FALSE;
684
+ extraOffset = 0x24;
685
+ }
686
+
687
+ const UInt32 fileNameLen111 = Get16(p2 + extraOffset);
688
+ if ((fileNameLen111 & 1) != 0)
564
689
  return S_FALSE;
565
- UInt64 len = Get64(p + pos);
566
- entryLens.Add(len);
567
- sum += len;
568
- pos += 8;
690
+ /* Probably different versions of ImageX can use different number of
691
+ additional ZEROs. So we don't use exact check. */
692
+ const UInt32 fileNameLen222 = (fileNameLen111 == 0 ? fileNameLen111 : fileNameLen111 + 2);
693
+ if (((extraOffset + 2 + fileNameLen222 + align) & ~align) > len2)
694
+ return S_FALSE;
695
+
696
+ {
697
+ const Byte *p3 = p2 + extraOffset + 2;
698
+ if (*(const UInt16 *)(p3 + fileNameLen111) != 0)
699
+ return S_FALSE;
700
+ for (UInt32 j = 0; j < fileNameLen111; j += 2)
701
+ if (*(const UInt16 *)(p3 + j) == 0)
702
+ return S_FALSE;
703
+
704
+ // PRF(printf("\n %S", p3));
705
+ }
706
+
707
+
708
+ /* wim uses alt sreams list, if there is at least one alt stream.
709
+ And alt stream without name is main stream. */
710
+
711
+ // Why wimlib writes two alt streams for REPARSE_POINT, with empty second alt stream?
712
+
713
+ Byte *prevMeta = DirData + item.Offset;
714
+
715
+ if (fileNameLen111 == 0 &&
716
+ ((attrib & FILE_ATTRIBUTE_REPARSE_POINT) || !item.IsDir)
717
+ && (IsOldVersion || IsEmptySha(prevMeta + 0x40)))
718
+ {
719
+ if (IsOldVersion)
720
+ memcpy(prevMeta + 0x10, p2 + 8, 4); // It's 32-bit Id
721
+ else if (!IsEmptySha(p2 + 0x10))
722
+ {
723
+ // if (IsEmptySha(prevMeta + 0x40))
724
+ memcpy(prevMeta + 0x40, p2 + 0x10, kHashSize);
725
+ // else HeadersError = true;
726
+ }
727
+ }
728
+ else
729
+ {
730
+ ThereAreAltStreams = true;
731
+ CItem item2;
732
+ item2.Offset = pos;
733
+ item2.IsAltStream = true;
734
+ item2.Parent = prevIndex;
735
+ item2.ImageIndex = Images.Size() - 1;
736
+ Items.Add(item2);
737
+ }
738
+
739
+ pos += (size_t)len2;
569
740
  }
570
- pos += (size_t)sum; // skip security descriptors
571
- while ((pos & 7) != 0)
572
- pos++;
573
- if (pos != totalLength)
741
+
742
+ if (parent < 0 && numItems == 0 && shortNameLen == 0 && fileNameLen == 0 && item.IsDir)
743
+ {
744
+ const Byte *p2 = DirData + pos;
745
+ if (DirSize - pos >= 8 && Get64(p2) == 0)
746
+ {
747
+ CImage &image = Images.Back();
748
+ image.NumEmptyRootItems = 1;
749
+
750
+ if (subdirOffset != 0
751
+ && DirSize - pos >= 16
752
+ && Get64(p2 + 8) != 0
753
+ && pos + 8 < subdirOffset)
754
+ {
755
+ // Longhorn.4093 contains hidden files after empty root folder and before items of next folder. Why?
756
+ // That code shows them. If we want to ignore them, we need to update DirProcessed.
757
+ // DirProcessed += (size_t)(subdirOffset - (pos + 8));
758
+ // printf("\ndirOffset = %5d hiddenOffset = %5d\n", (int)subdirOffset, (int)pos + 8);
759
+ subdirOffset = pos + 8;
760
+ // return S_FALSE;
761
+ }
762
+ }
763
+ }
764
+
765
+ if (item.IsDir && subdirOffset != 0)
766
+ {
767
+ RINOK(ParseDirItem((size_t)subdirOffset, prevIndex));
768
+ }
769
+ }
770
+ }
771
+
772
+
773
+ HRESULT CDatabase::ParseImageDirs(CByteBuffer &buf, int parent)
774
+ {
775
+ DirData = buf;
776
+ DirSize = buf.Size();
777
+ if (DirSize < 8)
778
+ return S_FALSE;
779
+ const Byte *p = DirData;
780
+ size_t pos = 0;
781
+ CImage &image = Images.Back();
782
+
783
+ if (IsOldVersion)
784
+ {
785
+ UInt32 numEntries = Get32(p + 4);
786
+
787
+ if (numEntries > (1 << 28) ||
788
+ numEntries > (DirSize >> 3))
574
789
  return S_FALSE;
575
- */
576
- if (totalLength == 0)
790
+
791
+ UInt32 sum = 8;
792
+ if (numEntries != 0)
793
+ sum = numEntries * 8;
794
+
795
+ image.SecurOffsets.ClearAndReserve(numEntries + 1);
796
+ image.SecurOffsets.AddInReserved(sum);
797
+
798
+ for (UInt32 i = 0; i < numEntries; i++)
799
+ {
800
+ const Byte *pp = p + (size_t)i * 8;
801
+ UInt32 len = Get32(pp);
802
+ if (i != 0 && Get32(pp + 4) != 0)
803
+ return S_FALSE;
804
+ if (len > DirSize - sum)
805
+ return S_FALSE;
806
+ sum += len;
807
+ if (sum < len)
808
+ return S_FALSE;
809
+ image.SecurOffsets.AddInReserved(sum);
810
+ }
811
+
812
+ pos = sum;
813
+
814
+ const size_t align = GetDirAlignMask();
815
+ pos = (pos + align) & ~(size_t)align;
816
+ }
817
+ else
818
+ {
819
+ UInt32 totalLen = Get32(p);
820
+ if (totalLen == 0)
577
821
  pos = 8;
578
- else if (totalLength < 8)
579
- return S_FALSE;
580
822
  else
581
- pos = totalLength;
582
- }
823
+ {
824
+ if (totalLen < 8)
825
+ return S_FALSE;
826
+ UInt32 numEntries = Get32(p + 4);
827
+ pos = 8;
828
+ if (totalLen > DirSize || numEntries > ((totalLen - 8) >> 3))
829
+ return S_FALSE;
830
+ UInt32 sum = (UInt32)pos + numEntries * 8;
831
+ image.SecurOffsets.ClearAndReserve(numEntries + 1);
832
+ image.SecurOffsets.AddInReserved(sum);
833
+
834
+ for (UInt32 i = 0; i < numEntries; i++, pos += 8)
835
+ {
836
+ UInt64 len = Get64(p + pos);
837
+ if (len > totalLen - sum)
838
+ return S_FALSE;
839
+ sum += (UInt32)len;
840
+ image.SecurOffsets.AddInReserved(sum);
841
+ }
842
+
843
+ pos = sum;
844
+ pos = (pos + 7) & ~(size_t)7;
845
+ if (pos != (((size_t)totalLen + 7) & ~(size_t)7))
846
+ return S_FALSE;
847
+ }
583
848
  }
849
+
850
+ if (pos > DirSize)
851
+ return S_FALSE;
852
+
584
853
  DirStartOffset = DirProcessed = pos;
854
+ image.StartItem = Items.Size();
855
+
585
856
  RINOK(ParseDirItem(pos, parent));
857
+
858
+ image.NumItems = Items.Size() - image.StartItem;
586
859
  if (DirProcessed == DirSize)
587
860
  return S_OK;
588
- /* Original program writes additional 8 bytes (END_OF_ROOT_FOLDER), but
589
- reference to that folder is empty */
590
- if (DirProcessed == DirSize - 8 && DirProcessed - DirStartOffset == 112 &&
591
- Get64(p + DirSize - 8) == 0)
861
+
862
+ /* Original program writes additional 8 bytes (END_OF_ROOT_FOLDER),
863
+ but the reference to that folder is empty */
864
+
865
+ // we can't use DirProcessed - DirStartOffset == 112 check if there is alt stream in root
866
+ if (DirProcessed == DirSize - 8 && Get64(p + DirSize - 8) != 0)
592
867
  return S_OK;
868
+
593
869
  return S_FALSE;
594
870
  }
595
871
 
596
- HRESULT CHeader::Parse(const Byte *p)
872
+
873
+ HRESULT CHeader::Parse(const Byte *p, UInt64 &phySize)
597
874
  {
598
875
  UInt32 headerSize = Get32(p + 8);
876
+ phySize = headerSize;
599
877
  Version = Get32(p + 0x0C);
600
878
  Flags = Get32(p + 0x10);
601
879
  if (!IsSupported())
602
880
  return S_FALSE;
603
- ChunkSize = Get32(p + 0x14);
604
- if (ChunkSize != kChunkSize && ChunkSize != 0)
605
- return S_FALSE;
606
- int offset;
881
+
882
+ {
883
+ ChunkSize = Get32(p + 0x14);
884
+ ChunkSizeBits = kChunkSizeBits;
885
+ if (ChunkSize != 0)
886
+ {
887
+ int log = GetLog(ChunkSize);
888
+ if (log < 12)
889
+ return S_FALSE;
890
+ ChunkSizeBits = log;
891
+ }
892
+ }
893
+
894
+ _IsOldVersion = false;
895
+ _IsNewVersion = false;
896
+
897
+ if (IsSolidVersion())
898
+ _IsNewVersion = true;
899
+ else
900
+ {
901
+ if (Version < 0x010900)
902
+ return S_FALSE;
903
+ _IsOldVersion = (Version <= 0x010A00);
904
+ // We don't know details about 1.11 version. So we use headerSize to guess exact features.
905
+ if (Version == 0x010B00 && headerSize == 0x60)
906
+ _IsOldVersion = true;
907
+ _IsNewVersion = (Version >= 0x010D00);
908
+ }
909
+
910
+ unsigned offset;
911
+
607
912
  if (IsOldVersion())
608
913
  {
609
914
  if (headerSize != 0x60)
@@ -620,131 +925,260 @@ HRESULT CHeader::Parse(const Byte *p)
620
925
  memcpy(Guid, p + 0x18, 16);
621
926
  PartNumber = Get16(p + 0x28);
622
927
  NumParts = Get16(p + 0x2A);
928
+ if (PartNumber == 0 || PartNumber > NumParts)
929
+ return S_FALSE;
623
930
  offset = 0x2C;
624
931
  if (IsNewVersion())
625
932
  {
933
+ // if (headerSize < 0xD0)
934
+ if (headerSize != 0xD0)
935
+ return S_FALSE;
626
936
  NumImages = Get32(p + offset);
627
937
  offset += 4;
628
938
  }
629
939
  }
630
- GetResource(p + offset, OffsetResource);
631
- GetResource(p + offset + 0x18, XmlResource);
632
- GetResource(p + offset + 0x30, MetadataResource);
940
+
941
+ GET_RESOURCE(p + offset , OffsetResource);
942
+ GET_RESOURCE(p + offset + 0x18, XmlResource);
943
+ GET_RESOURCE(p + offset + 0x30, MetadataResource);
944
+ BootIndex = 0;
945
+
633
946
  if (IsNewVersion())
634
947
  {
635
- if (headerSize < 0xD0)
636
- return S_FALSE;
637
- BootIndex = Get32(p + 0x48);
638
- IntegrityResource.Parse(p + offset + 0x4C);
948
+ BootIndex = Get32(p + offset + 0x48);
949
+ GET_RESOURCE(p + offset + 0x4C, IntegrityResource);
639
950
  }
951
+
640
952
  return S_OK;
641
953
  }
642
954
 
955
+
643
956
  const Byte kSignature[kSignatureSize] = { 'M', 'S', 'W', 'I', 'M', 0, 0, 0 };
644
957
 
645
- HRESULT ReadHeader(IInStream *inStream, CHeader &h)
958
+ HRESULT ReadHeader(IInStream *inStream, CHeader &h, UInt64 &phySize)
646
959
  {
647
960
  Byte p[kHeaderSizeMax];
648
961
  RINOK(ReadStream_FALSE(inStream, p, kHeaderSizeMax));
649
962
  if (memcmp(p, kSignature, kSignatureSize) != 0)
650
963
  return S_FALSE;
651
- return h.Parse(p);
964
+ return h.Parse(p, phySize);
652
965
  }
653
966
 
654
- static HRESULT ReadStreams(bool oldVersion, IInStream *inStream, const CHeader &h, CDatabase &db)
967
+
968
+ static HRESULT ReadStreams(IInStream *inStream, const CHeader &h, CDatabase &db)
655
969
  {
656
970
  CByteBuffer offsetBuf;
657
- RINOK(UnpackData(inStream, h.OffsetResource, h.IsLzxMode(), offsetBuf, NULL));
658
- size_t i;
659
- size_t streamInfoSize = oldVersion ? kStreamInfoSize + 2 : kStreamInfoSize;
660
- for (i = 0; offsetBuf.GetCapacity() - i >= streamInfoSize; i += streamInfoSize)
971
+
972
+ CUnpacker unpacker;
973
+ RINOK(unpacker.UnpackData(inStream, h.OffsetResource, h, NULL, offsetBuf, NULL));
974
+
975
+ const size_t streamInfoSize = h.IsOldVersion() ? kStreamInfoSize + 2 : kStreamInfoSize;
976
+ {
977
+ const unsigned numItems = (unsigned)(offsetBuf.Size() / streamInfoSize);
978
+ if ((size_t)numItems * streamInfoSize != offsetBuf.Size())
979
+ return S_FALSE;
980
+ const unsigned numItems2 = db.DataStreams.Size() + numItems;
981
+ if (numItems2 < numItems)
982
+ return S_FALSE;
983
+ db.DataStreams.Reserve(numItems2);
984
+ }
985
+
986
+ bool keepSolid = false;
987
+
988
+ for (size_t i = 0; i < offsetBuf.Size(); i += streamInfoSize)
661
989
  {
662
990
  CStreamInfo s;
663
- GetStream(oldVersion, (const Byte *)offsetBuf + i, s);
664
- if (s.PartNumber == h.PartNumber)
665
- db.Streams.Add(s);
991
+ ParseStream(h.IsOldVersion(), (const Byte *)offsetBuf + i, s);
992
+
993
+ PRF(printf("\n"));
994
+ PRF(printf(s.Resource.IsMetadata() ? "### META" : " DATA"));
995
+ PRF(printf(" %2X", s.Resource.Flags));
996
+ PRF(printf(" %9I64X", s.Resource.Offset));
997
+ PRF(printf(" %9I64X", s.Resource.PackSize));
998
+ PRF(printf(" %9I64X", s.Resource.UnpackSize));
999
+ PRF(printf(" %d", s.RefCount));
1000
+
1001
+ if (s.PartNumber != h.PartNumber)
1002
+ continue;
1003
+
1004
+ if (s.Resource.IsSolid())
1005
+ {
1006
+ s.Resource.KeepSolid = keepSolid;
1007
+ keepSolid = true;
1008
+ }
1009
+ else
1010
+ {
1011
+ s.Resource.KeepSolid = false;
1012
+ keepSolid = false;
1013
+ }
1014
+
1015
+ if (!s.Resource.IsMetadata())
1016
+ db.DataStreams.AddInReserved(s);
1017
+ else
1018
+ {
1019
+ if (s.Resource.IsSolid())
1020
+ return E_NOTIMPL;
1021
+ if (s.RefCount == 0)
1022
+ {
1023
+ // some wims have such (deleted?) metadata stream.
1024
+ // examples: boot.wim in VistaBeta2, WinPE.wim from WAIK.
1025
+ // db.DataStreams.Add(s);
1026
+ // we can show these delete images, if we comment "continue" command;
1027
+ continue;
1028
+ }
1029
+
1030
+ if (s.RefCount > 1)
1031
+ {
1032
+ return S_FALSE;
1033
+ // s.RefCount--;
1034
+ // db.DataStreams.Add(s);
1035
+ }
1036
+
1037
+ db.MetaStreams.Add(s);
1038
+ }
666
1039
  }
667
- return (i == offsetBuf.GetCapacity()) ? S_OK : S_FALSE;
1040
+
1041
+ PRF(printf("\n"));
1042
+
1043
+ return S_OK;
1044
+ }
1045
+
1046
+
1047
+ HRESULT CDatabase::OpenXml(IInStream *inStream, const CHeader &h, CByteBuffer &xml)
1048
+ {
1049
+ CUnpacker unpacker;
1050
+ return unpacker.UnpackData(inStream, h.XmlResource, h, this, xml, NULL);
668
1051
  }
669
1052
 
670
- static bool IsEmptySha(const Byte *data)
1053
+ static void SetRootNames(CImage &image, unsigned value)
671
1054
  {
672
- for (int i = 0; i < kHashSize; i++)
673
- if (data[i] != 0)
674
- return false;
675
- return true;
1055
+ wchar_t temp[16];
1056
+ ConvertUInt32ToString(value, temp);
1057
+ image.RootName = temp;
1058
+ image.RootNameBuf.Alloc(image.RootName.Len() * 2 + 2);
1059
+ Byte *p = image.RootNameBuf;
1060
+ unsigned len = image.RootName.Len() + 1;
1061
+ for (unsigned k = 0; k < len; k++)
1062
+ {
1063
+ p[k * 2] = (Byte)temp[k];
1064
+ p[k * 2 + 1] = 0;
1065
+ }
676
1066
  }
677
1067
 
678
- HRESULT CDatabase::Open(IInStream *inStream, const CHeader &h, CByteBuffer &xml, IArchiveOpenCallback *openCallback)
1068
+
1069
+ HRESULT CDatabase::Open(IInStream *inStream, const CHeader &h, unsigned numItemsReserve, IArchiveOpenCallback *openCallback)
679
1070
  {
680
1071
  OpenCallback = openCallback;
681
1072
  IsOldVersion = h.IsOldVersion();
682
- RINOK(UnpackData(inStream, h.XmlResource, h.IsLzxMode(), xml, NULL));
683
- RINOK(ReadStreams(h.IsOldVersion(), inStream, h, *this));
1073
+ IsOldVersion9 = (h.Version == 0x10900);
1074
+
1075
+ RINOK(ReadStreams(inStream, h, *this));
1076
+
684
1077
  bool needBootMetadata = !h.MetadataResource.IsEmpty();
685
- Order = 0;
686
- if (h.PartNumber == 1)
1078
+ unsigned numNonDeletedImages = 0;
1079
+
1080
+ CUnpacker unpacker;
1081
+
1082
+ FOR_VECTOR (i, MetaStreams)
687
1083
  {
688
- int imageIndex = 1;
689
- for (int i = 0; i < Streams.Size(); i++)
1084
+ const CStreamInfo &si = MetaStreams[i];
1085
+
1086
+ if (h.PartNumber != 1 || si.PartNumber != h.PartNumber)
1087
+ continue;
1088
+
1089
+ const int userImage = Images.Size() + GetStartImageIndex();
1090
+ CImage &image = Images.AddNew();
1091
+ SetRootNames(image, userImage);
1092
+
1093
+ CByteBuffer &metadata = image.Meta;
1094
+ Byte hash[kHashSize];
1095
+
1096
+ RINOK(unpacker.UnpackData(inStream, si.Resource, h, this, metadata, hash));
1097
+
1098
+ if (memcmp(hash, si.Hash, kHashSize) != 0 &&
1099
+ !(h.IsOldVersion() && IsEmptySha(si.Hash)))
1100
+ return S_FALSE;
1101
+
1102
+ image.NumEmptyRootItems = 0;
1103
+
1104
+ if (Items.IsEmpty())
1105
+ Items.ClearAndReserve(numItemsReserve);
1106
+
1107
+ RINOK(ParseImageDirs(metadata, -1));
1108
+
1109
+ if (needBootMetadata)
690
1110
  {
691
- // if (imageIndex > 1) break;
692
- const CStreamInfo &si = Streams[i];
693
- if (!si.Resource.IsMetadata() || si.PartNumber != h.PartNumber)
694
- continue;
695
- Byte hash[kHashSize];
696
- CByteBuffer metadata;
697
- RINOK(UnpackData(inStream, si.Resource, h.IsLzxMode(), metadata, hash));
698
- if (memcmp(hash, si.Hash, kHashSize) != 0 &&
699
- !(h.IsOldVersion() && IsEmptySha(si.Hash)))
700
- return S_FALSE;
701
- NumImages++;
702
- RINOK(ParseImageDirs(metadata, -(int)(++imageIndex)));
703
- if (needBootMetadata)
704
- if (h.MetadataResource.Offset == si.Resource.Offset)
705
- needBootMetadata = false;
1111
+ bool sameRes = (h.MetadataResource.Offset == si.Resource.Offset);
1112
+ if (sameRes)
1113
+ needBootMetadata = false;
1114
+ if (h.IsNewVersion())
1115
+ {
1116
+ if (si.RefCount == 1)
1117
+ {
1118
+ numNonDeletedImages++;
1119
+ bool isBootIndex = (h.BootIndex == numNonDeletedImages);
1120
+ if (sameRes && !isBootIndex)
1121
+ return S_FALSE;
1122
+ if (isBootIndex && !sameRes)
1123
+ return S_FALSE;
1124
+ }
1125
+ }
706
1126
  }
707
1127
  }
708
1128
 
709
1129
  if (needBootMetadata)
1130
+ return S_FALSE;
1131
+ return S_OK;
1132
+ }
1133
+
1134
+
1135
+ bool CDatabase::ItemHasStream(const CItem &item) const
1136
+ {
1137
+ if (item.ImageIndex < 0)
1138
+ return true;
1139
+ const Byte *meta = Images[item.ImageIndex].Meta + item.Offset;
1140
+ if (IsOldVersion)
710
1141
  {
711
- CByteBuffer metadata;
712
- RINOK(UnpackData(inStream, h.MetadataResource, h.IsLzxMode(), metadata, NULL));
713
- RINOK(ParseImageDirs(metadata, -1));
714
- NumImages++;
1142
+ // old wim use same field for file_id and dir_offset;
1143
+ if (item.IsDir)
1144
+ return false;
1145
+ meta += (item.IsAltStream ? 0x8 : 0x10);
1146
+ UInt32 id = GetUi32(meta);
1147
+ return id != 0;
715
1148
  }
716
- return S_OK;
1149
+ meta += (item.IsAltStream ? 0x10 : 0x40);
1150
+ return !IsEmptySha(meta);
717
1151
  }
718
1152
 
719
1153
 
1154
+ #define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
1155
+
720
1156
  static int CompareStreamsByPos(const CStreamInfo *p1, const CStreamInfo *p2, void * /* param */)
721
1157
  {
722
- int res = MyCompare(p1->PartNumber, p2->PartNumber);
723
- if (res != 0)
724
- return res;
725
- return MyCompare(p1->Resource.Offset, p2->Resource.Offset);
1158
+ RINOZ(MyCompare(p1->PartNumber, p2->PartNumber));
1159
+ RINOZ(MyCompare(p1->Resource.Offset, p2->Resource.Offset));
1160
+ return MyCompare(p1->Resource.PackSize, p2->Resource.PackSize);
726
1161
  }
727
1162
 
728
- static int CompareIDs(const int *p1, const int *p2, void *param)
1163
+ static int CompareIDs(const unsigned *p1, const unsigned *p2, void *param)
729
1164
  {
730
- const CRecordVector<CStreamInfo> &streams = *(const CRecordVector<CStreamInfo> *)param;
1165
+ const CStreamInfo *streams = (const CStreamInfo *)param;
731
1166
  return MyCompare(streams[*p1].Id, streams[*p2].Id);
732
1167
  }
733
1168
 
734
- static int CompareHashRefs(const int *p1, const int *p2, void *param)
1169
+ static int CompareHashRefs(const unsigned *p1, const unsigned *p2, void *param)
735
1170
  {
736
- const CRecordVector<CStreamInfo> &streams = *(const CRecordVector<CStreamInfo> *)param;
1171
+ const CStreamInfo *streams = (const CStreamInfo *)param;
737
1172
  return memcmp(streams[*p1].Hash, streams[*p2].Hash, kHashSize);
738
1173
  }
739
1174
 
740
- static int FindId(const CRecordVector<CStreamInfo> &streams,
741
- const CIntVector &sortedByHash, UInt32 id)
1175
+ static int FindId(const CStreamInfo *streams, const CUIntVector &sorted, UInt32 id)
742
1176
  {
743
- int left = 0, right = streams.Size();
1177
+ unsigned left = 0, right = sorted.Size();
744
1178
  while (left != right)
745
1179
  {
746
- int mid = (left + right) / 2;
747
- int streamIndex = sortedByHash[mid];
1180
+ unsigned mid = (left + right) / 2;
1181
+ unsigned streamIndex = sorted[mid];
748
1182
  UInt32 id2 = streams[streamIndex].Id;
749
1183
  if (id == id2)
750
1184
  return streamIndex;
@@ -756,16 +1190,15 @@ static int FindId(const CRecordVector<CStreamInfo> &streams,
756
1190
  return -1;
757
1191
  }
758
1192
 
759
- static int FindHash(const CRecordVector<CStreamInfo> &streams,
760
- const CIntVector &sortedByHash, const Byte *hash)
1193
+ static int FindHash(const CStreamInfo *streams, const CUIntVector &sorted, const Byte *hash)
761
1194
  {
762
- int left = 0, right = streams.Size();
1195
+ unsigned left = 0, right = sorted.Size();
763
1196
  while (left != right)
764
1197
  {
765
- int mid = (left + right) / 2;
766
- int streamIndex = sortedByHash[mid];
767
- UInt32 i;
1198
+ unsigned mid = (left + right) / 2;
1199
+ unsigned streamIndex = sorted[mid];
768
1200
  const Byte *hash2 = streams[streamIndex].Hash;
1201
+ unsigned i;
769
1202
  for (i = 0; i < kHashSize; i++)
770
1203
  if (hash[i] != hash2[i])
771
1204
  break;
@@ -779,77 +1212,650 @@ static int FindHash(const CRecordVector<CStreamInfo> &streams,
779
1212
  return -1;
780
1213
  }
781
1214
 
782
- static int CompareItems(const int *a1, const int *a2, void *param)
1215
+ static int CompareItems(const unsigned *a1, const unsigned *a2, void *param)
783
1216
  {
784
- const CObjectVector<CItem> &items = ((CDatabase *)param)->Items;
1217
+ const CRecordVector<CItem> &items = ((CDatabase *)param)->Items;
785
1218
  const CItem &i1 = items[*a1];
786
1219
  const CItem &i2 = items[*a2];
787
1220
 
788
- if (i1.IsDir() != i2.IsDir())
789
- return i1.IsDir() ? 1 : -1;
790
- int res = MyCompare(i1.StreamIndex, i2.StreamIndex);
791
- if (res != 0)
792
- return res;
793
- return MyCompare(i1.Order, i2.Order);
1221
+ if (i1.IsDir != i2.IsDir)
1222
+ return i1.IsDir ? -1 : 1;
1223
+ if (i1.IsAltStream != i2.IsAltStream)
1224
+ return i1.IsAltStream ? 1 : -1;
1225
+ RINOZ(MyCompare(i1.StreamIndex, i2.StreamIndex));
1226
+ RINOZ(MyCompare(i1.ImageIndex, i2.ImageIndex));
1227
+ return MyCompare(i1.Offset, i2.Offset);
794
1228
  }
795
1229
 
796
- HRESULT CDatabase::Sort(bool skipRootDir)
1230
+
1231
+ HRESULT CDatabase::FillAndCheck(const CObjectVector<CVolume> &volumes)
797
1232
  {
798
- Streams.Sort(CompareStreamsByPos, NULL);
1233
+ CUIntVector sortedByHash;
1234
+ sortedByHash.Reserve(DataStreams.Size());
1235
+ {
1236
+ CByteBuffer sizesBuf;
1237
+
1238
+ for (unsigned iii = 0; iii < DataStreams.Size();)
1239
+ {
1240
+ {
1241
+ const CResource &r = DataStreams[iii].Resource;
1242
+ if (!r.IsSolid())
1243
+ {
1244
+ sortedByHash.AddInReserved(iii++);
1245
+ continue;
1246
+ }
1247
+ }
1248
+
1249
+ UInt64 solidRunOffset = 0;
1250
+ unsigned k;
1251
+ unsigned numSolidsStart = Solids.Size();
1252
+
1253
+ for (k = iii; k < DataStreams.Size(); k++)
1254
+ {
1255
+ CStreamInfo &si = DataStreams[k];
1256
+ CResource &r = si.Resource;
1257
+
1258
+ if (!r.IsSolid())
1259
+ break;
1260
+ if (!r.KeepSolid && k != iii)
1261
+ break;
799
1262
 
1263
+ if (r.Flags != NResourceFlags::kSolid)
1264
+ return S_FALSE;
1265
+
1266
+ if (!r.IsSolidBig())
1267
+ continue;
1268
+
1269
+ if (!si.IsEmptyHash())
1270
+ return S_FALSE;
1271
+ if (si.RefCount != 1)
1272
+ return S_FALSE;
1273
+
1274
+ r.SolidIndex = Solids.Size();
1275
+
1276
+ CSolid &ss = Solids.AddNew();
1277
+ ss.StreamIndex = k;
1278
+ ss.SolidOffset = solidRunOffset;
1279
+ {
1280
+ const size_t kSolidHeaderSize = 8 + 4 + 4;
1281
+ Byte header[kSolidHeaderSize];
1282
+
1283
+ if (si.PartNumber >= volumes.Size())
1284
+ return S_FALSE;
1285
+
1286
+ const CVolume &vol = volumes[si.PartNumber];
1287
+ IInStream *inStream = vol.Stream;
1288
+ RINOK(inStream->Seek(r.Offset, STREAM_SEEK_SET, NULL));
1289
+ RINOK(ReadStream_FALSE(inStream, (Byte *)header, kSolidHeaderSize));
1290
+
1291
+ ss.UnpackSize = GetUi64(header);
1292
+
1293
+ if (ss.UnpackSize > ((UInt64)1 << 63))
1294
+ return S_FALSE;
1295
+
1296
+ solidRunOffset += ss.UnpackSize;
1297
+ if (solidRunOffset < ss.UnpackSize)
1298
+ return S_FALSE;
1299
+
1300
+ const UInt32 solidChunkSize = GetUi32(header + 8);
1301
+ int log = GetLog(solidChunkSize);
1302
+ if (log < 8 || log > 31)
1303
+ return S_FALSE;
1304
+ ss.ChunkSizeBits = log;
1305
+ ss.Method = GetUi32(header + 12);
1306
+
1307
+ UInt64 numChunks64 = (ss.UnpackSize + (((UInt32)1 << ss.ChunkSizeBits) - 1)) >> ss.ChunkSizeBits;
1308
+ UInt64 sizesBufSize64 = 4 * numChunks64;
1309
+ ss.HeadersSize = kSolidHeaderSize + sizesBufSize64;
1310
+ size_t sizesBufSize = (size_t)sizesBufSize64;
1311
+ if (sizesBufSize != sizesBufSize64)
1312
+ return E_OUTOFMEMORY;
1313
+ sizesBuf.AllocAtLeast(sizesBufSize);
1314
+
1315
+ RINOK(ReadStream_FALSE(inStream, sizesBuf, sizesBufSize));
1316
+
1317
+ size_t numChunks = (size_t)numChunks64;
1318
+ ss.Chunks.Alloc(numChunks + 1);
1319
+
1320
+ UInt64 offset = 0;
1321
+
1322
+ size_t c;
1323
+ for (c = 0; c < numChunks; c++)
1324
+ {
1325
+ ss.Chunks[c] = offset;
1326
+ UInt32 packSize = GetUi32((const Byte *)sizesBuf + c * 4);
1327
+ offset += packSize;
1328
+ if (offset < packSize)
1329
+ return S_FALSE;
1330
+ }
1331
+ ss.Chunks[c] = offset;
1332
+
1333
+ if (ss.Chunks[0] != 0)
1334
+ return S_FALSE;
1335
+ if (ss.HeadersSize + offset != r.PackSize)
1336
+ return S_FALSE;
1337
+ }
1338
+ }
1339
+
1340
+ unsigned solidLim = k;
1341
+
1342
+ for (k = iii; k < solidLim; k++)
1343
+ {
1344
+ CStreamInfo &si = DataStreams[k];
1345
+ CResource &r = si.Resource;
1346
+
1347
+ if (!r.IsSolidSmall())
1348
+ continue;
1349
+
1350
+ if (si.IsEmptyHash())
1351
+ return S_FALSE;
1352
+
1353
+ unsigned solidIndex;
1354
+ {
1355
+ UInt64 offset = r.Offset;
1356
+ for (solidIndex = numSolidsStart;; solidIndex++)
1357
+ {
1358
+ if (solidIndex == Solids.Size())
1359
+ return S_FALSE;
1360
+ UInt64 unpackSize = Solids[solidIndex].UnpackSize;
1361
+ if (offset < unpackSize)
1362
+ break;
1363
+ offset -= unpackSize;
1364
+ }
1365
+ }
1366
+ CSolid &ss = Solids[solidIndex];
1367
+ if (r.Offset < ss.SolidOffset)
1368
+ return S_FALSE;
1369
+ UInt64 relat = r.Offset - ss.SolidOffset;
1370
+ if (relat > ss.UnpackSize)
1371
+ return S_FALSE;
1372
+ if (r.PackSize > ss.UnpackSize - relat)
1373
+ return S_FALSE;
1374
+ r.SolidIndex = solidIndex;
1375
+ if (ss.FirstSmallStream < 0)
1376
+ ss.FirstSmallStream = k;
1377
+
1378
+ sortedByHash.AddInReserved(k);
1379
+ // ss.NumRefs++;
1380
+ }
1381
+
1382
+ iii = solidLim;
1383
+ }
1384
+ }
1385
+
1386
+ if (Solids.IsEmpty())
800
1387
  {
801
- CIntVector sortedByHash;
1388
+ /* We want to check that streams layout is OK.
1389
+ So we need resources sorted by offset.
1390
+ Another code can work with non-sorted streams.
1391
+ NOTE: all WIM programs probably create wim archives with
1392
+ sorted data streams. So it doesn't call Sort() here. */
1393
+
802
1394
  {
803
- for (int i = 0; i < Streams.Size(); i++)
804
- sortedByHash.Add(i);
1395
+ unsigned i;
1396
+ for (i = 1; i < DataStreams.Size(); i++)
1397
+ {
1398
+ const CStreamInfo &s0 = DataStreams[i - 1];
1399
+ const CStreamInfo &s1 = DataStreams[i];
1400
+ if (s0.PartNumber < s1.PartNumber) continue;
1401
+ if (s0.PartNumber > s1.PartNumber) break;
1402
+ if (s0.Resource.Offset < s1.Resource.Offset) continue;
1403
+ if (s0.Resource.Offset > s1.Resource.Offset) break;
1404
+ if (s0.Resource.PackSize > s1.Resource.PackSize) break;
1405
+ }
1406
+
1407
+ if (i < DataStreams.Size())
1408
+ {
1409
+ // return E_FAIL;
1410
+ DataStreams.Sort(CompareStreamsByPos, NULL);
1411
+ }
1412
+ }
1413
+
1414
+ for (unsigned i = 1; i < DataStreams.Size(); i++)
1415
+ {
1416
+ const CStreamInfo &s0 = DataStreams[i - 1];
1417
+ const CStreamInfo &s1 = DataStreams[i];
1418
+ if (s0.PartNumber == s1.PartNumber)
1419
+ if (s0.Resource.GetEndLimit() > s1.Resource.Offset)
1420
+ return S_FALSE;
1421
+ }
1422
+ }
1423
+
1424
+ {
1425
+ {
1426
+ const CStreamInfo *streams = &DataStreams.Front();
1427
+
805
1428
  if (IsOldVersion)
806
- sortedByHash.Sort(CompareIDs, &Streams);
1429
+ {
1430
+ sortedByHash.Sort(CompareIDs, (void *)streams);
1431
+
1432
+ for (unsigned i = 1; i < sortedByHash.Size(); i++)
1433
+ if (streams[sortedByHash[i - 1]].Id >=
1434
+ streams[sortedByHash[i]].Id)
1435
+ return S_FALSE;
1436
+ }
807
1437
  else
808
- sortedByHash.Sort(CompareHashRefs, &Streams);
1438
+ {
1439
+ sortedByHash.Sort(CompareHashRefs, (void *)streams);
1440
+
1441
+ if (!sortedByHash.IsEmpty())
1442
+ {
1443
+ if (IsEmptySha(streams[sortedByHash[0]].Hash))
1444
+ HeadersError = true;
1445
+
1446
+ for (unsigned i = 1; i < sortedByHash.Size(); i++)
1447
+ if (memcmp(
1448
+ streams[sortedByHash[i - 1]].Hash,
1449
+ streams[sortedByHash[i]].Hash,
1450
+ kHashSize) >= 0)
1451
+ return S_FALSE;
1452
+ }
1453
+ }
809
1454
  }
810
1455
 
811
- for (int i = 0; i < Items.Size(); i++)
1456
+ FOR_VECTOR (i, Items)
812
1457
  {
813
1458
  CItem &item = Items[i];
814
1459
  item.StreamIndex = -1;
815
- if (item.HasStream())
816
- if (IsOldVersion)
817
- item.StreamIndex = FindId(Streams, sortedByHash, item.Id);
818
- else
819
- item.StreamIndex = FindHash(Streams, sortedByHash, item.Hash);
1460
+ const Byte *hash = Images[item.ImageIndex].Meta + item.Offset;
1461
+ if (IsOldVersion)
1462
+ {
1463
+ if (!item.IsDir)
1464
+ {
1465
+ hash += (item.IsAltStream ? 0x8 : 0x10);
1466
+ UInt32 id = GetUi32(hash);
1467
+ if (id != 0)
1468
+ item.StreamIndex = FindId(&DataStreams.Front(), sortedByHash, id);
1469
+ }
1470
+ }
1471
+ /*
1472
+ else if (item.IsDir)
1473
+ {
1474
+ // reparse points can have dirs some dir
1475
+ }
1476
+ */
1477
+ else
1478
+ {
1479
+ hash += (item.IsAltStream ? 0x10 : 0x40);
1480
+ if (!IsEmptySha(hash))
1481
+ {
1482
+ item.StreamIndex = FindHash(&DataStreams.Front(), sortedByHash, hash);
1483
+ }
1484
+ }
820
1485
  }
821
1486
  }
822
-
823
1487
  {
824
- CRecordVector<bool> used;
825
- int i;
826
- for (i = 0; i < Streams.Size(); i++)
1488
+ CUIntVector refCounts;
1489
+ refCounts.ClearAndSetSize(DataStreams.Size());
1490
+ unsigned i;
1491
+
1492
+ for (i = 0; i < DataStreams.Size(); i++)
827
1493
  {
828
- const CStreamInfo &s = Streams[i];
829
- used.Add(s.Resource.IsMetadata() && s.PartNumber == 1);
830
- // used.Add(false);
1494
+ UInt32 startVal = 0;
1495
+ // const CStreamInfo &s = DataStreams[i];
1496
+ /*
1497
+ if (s.Resource.IsMetadata() && s.PartNumber == 1)
1498
+ startVal = 1;
1499
+ */
1500
+ refCounts[i] = startVal;
831
1501
  }
1502
+
832
1503
  for (i = 0; i < Items.Size(); i++)
833
1504
  {
834
- CItem &item = Items[i];
835
- if (item.StreamIndex >= 0)
836
- used[item.StreamIndex] = true;
1505
+ int streamIndex = Items[i].StreamIndex;
1506
+ if (streamIndex >= 0)
1507
+ refCounts[streamIndex]++;
837
1508
  }
838
- for (i = 0; i < Streams.Size(); i++)
839
- if (!used[i])
1509
+
1510
+ for (i = 0; i < DataStreams.Size(); i++)
1511
+ {
1512
+ const CStreamInfo &s = DataStreams[i];
1513
+ if (s.RefCount != refCounts[i]
1514
+ && !s.Resource.IsSolidBig())
1515
+ {
1516
+ /*
1517
+ printf("\ni=%5d si.Ref=%2d realRefs=%2d size=%8d offset=%8x id=%4d ",
1518
+ i, s.RefCount, refCounts[i], (unsigned)s.Resource.UnpackSize, (unsigned)s.Resource.Offset, s.Id);
1519
+ */
1520
+ RefCountError = true;
1521
+ }
1522
+
1523
+ if (refCounts[i] == 0)
840
1524
  {
841
- CItem item;
842
- item.StreamIndex = i;
843
- item.HasMetadata = false;
844
- Items.Add(item);
1525
+ const CResource &r = DataStreams[i].Resource;
1526
+ if (!r.IsSolidBig() || Solids[r.SolidIndex].FirstSmallStream < 0)
1527
+ {
1528
+ CItem item;
1529
+ item.Offset = 0;
1530
+ item.StreamIndex = i;
1531
+ item.ImageIndex = -1;
1532
+ Items.Add(item);
1533
+ ThereAreDeletedStreams = true;
1534
+ }
845
1535
  }
1536
+ }
846
1537
  }
847
1538
 
848
- SortedItems.Reserve(Items.Size());
849
- for (int i = (skipRootDir ? 1 : 0); i < Items.Size(); i++)
850
- SortedItems.Add(i);
1539
+ return S_OK;
1540
+ }
1541
+
1542
+
1543
+ HRESULT CDatabase::GenerateSortedItems(int imageIndex, bool showImageNumber)
1544
+ {
1545
+ SortedItems.Clear();
1546
+ VirtualRoots.Clear();
1547
+ IndexOfUserImage = imageIndex;
1548
+ NumExcludededItems = 0;
1549
+ ExludedItem = -1;
1550
+
1551
+ if (Images.Size() != 1 && imageIndex < 0)
1552
+ showImageNumber = true;
1553
+
1554
+ unsigned startItem = 0;
1555
+ unsigned endItem = 0;
1556
+
1557
+ if (imageIndex < 0)
1558
+ {
1559
+ endItem = Items.Size();
1560
+ if (Images.Size() == 1)
1561
+ {
1562
+ IndexOfUserImage = 0;
1563
+ const CImage &image = Images[0];
1564
+ if (!showImageNumber)
1565
+ NumExcludededItems = image.NumEmptyRootItems;
1566
+ }
1567
+ }
1568
+ else if ((unsigned)imageIndex < Images.Size())
1569
+ {
1570
+ const CImage &image = Images[imageIndex];
1571
+ startItem = image.StartItem;
1572
+ endItem = startItem + image.NumItems;
1573
+ if (!showImageNumber)
1574
+ NumExcludededItems = image.NumEmptyRootItems;
1575
+ }
1576
+
1577
+ if (NumExcludededItems != 0)
1578
+ {
1579
+ ExludedItem = startItem;
1580
+ startItem += NumExcludededItems;
1581
+ }
1582
+
1583
+ unsigned num = endItem - startItem;
1584
+ SortedItems.ClearAndSetSize(num);
1585
+ unsigned i;
1586
+ for (i = 0; i < num; i++)
1587
+ SortedItems[i] = startItem + i;
1588
+
851
1589
  SortedItems.Sort(CompareItems, this);
1590
+ for (i = 0; i < SortedItems.Size(); i++)
1591
+ Items[SortedItems[i]].IndexInSorted = i;
1592
+
1593
+ if (showImageNumber)
1594
+ for (i = 0; i < Images.Size(); i++)
1595
+ {
1596
+ CImage &image = Images[i];
1597
+ if (image.NumEmptyRootItems != 0)
1598
+ continue;
1599
+ image.VirtualRootIndex = VirtualRoots.Size();
1600
+ VirtualRoots.Add(i);
1601
+ }
1602
+
1603
+ return S_OK;
1604
+ }
1605
+
1606
+
1607
+ static void IntVector_SetMinusOne_IfNeed(CIntVector &v, unsigned size)
1608
+ {
1609
+ if (v.Size() == size)
1610
+ return;
1611
+ v.ClearAndSetSize(size);
1612
+ int *vals = &v[0];
1613
+ for (unsigned i = 0; i < size; i++)
1614
+ vals[i] = -1;
1615
+ }
1616
+
1617
+
1618
+ HRESULT CDatabase::ExtractReparseStreams(const CObjectVector<CVolume> &volumes, IArchiveOpenCallback *openCallback)
1619
+ {
1620
+ ItemToReparse.Clear();
1621
+ ReparseItems.Clear();
1622
+
1623
+ // we don't know about Reparse field for OLD WIM format
1624
+ if (IsOldVersion)
1625
+ return S_OK;
1626
+
1627
+ CIntVector streamToReparse;
1628
+ CUnpacker unpacker;
1629
+ UInt64 totalPackedPrev = 0;
1630
+
1631
+ FOR_VECTOR(indexInSorted, SortedItems)
1632
+ {
1633
+ // we use sorted items for faster access
1634
+ unsigned itemIndex = SortedItems[indexInSorted];
1635
+ const CItem &item = Items[itemIndex];
1636
+
1637
+ if (!item.HasMetadata() || item.IsAltStream)
1638
+ continue;
1639
+
1640
+ if (item.ImageIndex < 0)
1641
+ continue;
1642
+
1643
+ const Byte *metadata = Images[item.ImageIndex].Meta + item.Offset;
1644
+
1645
+ const UInt32 attrib = Get32(metadata + 8);
1646
+ if ((attrib & FILE_ATTRIBUTE_REPARSE_POINT) == 0)
1647
+ continue;
1648
+
1649
+ if (item.StreamIndex < 0)
1650
+ continue; // it's ERROR
1651
+
1652
+ const CStreamInfo &si = DataStreams[item.StreamIndex];
1653
+ if (si.Resource.UnpackSize >= (1 << 16))
1654
+ continue; // reparse data can not be larger than 64 KB
1655
+
1656
+ IntVector_SetMinusOne_IfNeed(streamToReparse, DataStreams.Size());
1657
+ IntVector_SetMinusOne_IfNeed(ItemToReparse, Items.Size());
1658
+
1659
+ const unsigned offset = 0x58; // we don't know about Reparse field for OLD WIM format
1660
+ UInt32 tag = Get32(metadata + offset);
1661
+ int reparseIndex = streamToReparse[item.StreamIndex];
1662
+ CByteBuffer buf;
1663
+
1664
+ if (openCallback)
1665
+ {
1666
+ if ((unpacker.TotalPacked - totalPackedPrev) >= ((UInt32)1 << 16))
1667
+ {
1668
+ UInt64 numFiles = Items.Size();
1669
+ RINOK(openCallback->SetCompleted(&numFiles, &unpacker.TotalPacked));
1670
+ totalPackedPrev = unpacker.TotalPacked;
1671
+ }
1672
+ }
1673
+
1674
+ if (reparseIndex >= 0)
1675
+ {
1676
+ const CByteBuffer &reparse = ReparseItems[reparseIndex];
1677
+ if (tag == Get32(reparse))
1678
+ {
1679
+ ItemToReparse[itemIndex] = reparseIndex;
1680
+ continue;
1681
+ }
1682
+ buf = reparse;
1683
+ // we support that strange and unusual situation with different tags and same reparse data.
1684
+ }
1685
+ else
1686
+ {
1687
+ /*
1688
+ if (si.PartNumber >= volumes.Size())
1689
+ continue;
1690
+ */
1691
+ const CVolume &vol = volumes[si.PartNumber];
1692
+ /*
1693
+ if (!vol.Stream)
1694
+ continue;
1695
+ */
1696
+
1697
+ Byte digest[kHashSize];
1698
+ HRESULT res = unpacker.UnpackData(vol.Stream, si.Resource, vol.Header, this, buf, digest);
1699
+
1700
+ if (res == S_FALSE)
1701
+ continue;
1702
+
1703
+ RINOK(res);
1704
+
1705
+ if (memcmp(digest, si.Hash, kHashSize) != 0
1706
+ // && !(h.IsOldVersion() && IsEmptySha(si.Hash))
1707
+ )
1708
+ {
1709
+ // setErrorStatus;
1710
+ continue;
1711
+ }
1712
+ }
1713
+
1714
+ CByteBuffer &reparse = ReparseItems.AddNew();
1715
+ reparse.Alloc(8 + buf.Size());
1716
+ Byte *dest = (Byte *)reparse;
1717
+ SetUi32(dest, tag);
1718
+ SetUi32(dest + 4, (UInt32)buf.Size());
1719
+ if (buf.Size() != 0)
1720
+ memcpy(dest + 8, buf, buf.Size());
1721
+ ItemToReparse[itemIndex] = ReparseItems.Size() - 1;
1722
+ }
1723
+
852
1724
  return S_OK;
853
1725
  }
854
1726
 
1727
+
1728
+
1729
+ static bool ParseNumber64(const AString &s, UInt64 &res)
1730
+ {
1731
+ const char *end;
1732
+ if (s.IsPrefixedBy("0x"))
1733
+ {
1734
+ if (s.Len() == 2)
1735
+ return false;
1736
+ res = ConvertHexStringToUInt64(s.Ptr(2), &end);
1737
+ }
1738
+ else
1739
+ {
1740
+ if (s.IsEmpty())
1741
+ return false;
1742
+ res = ConvertStringToUInt64(s, &end);
1743
+ }
1744
+ return *end == 0;
1745
+ }
1746
+
1747
+
1748
+ static bool ParseNumber32(const AString &s, UInt32 &res)
1749
+ {
1750
+ UInt64 res64;
1751
+ if (!ParseNumber64(s, res64) || res64 >= ((UInt64)1 << 32))
1752
+ return false;
1753
+ res = (UInt32)res64;
1754
+ return true;
1755
+ }
1756
+
1757
+
1758
+ static bool ParseTime(const CXmlItem &item, FILETIME &ft, const char *tag)
1759
+ {
1760
+ int index = item.FindSubTag(tag);
1761
+ if (index >= 0)
1762
+ {
1763
+ const CXmlItem &timeItem = item.SubItems[index];
1764
+ UInt32 low = 0, high = 0;
1765
+ if (ParseNumber32(timeItem.GetSubStringForTag("LOWPART"), low) &&
1766
+ ParseNumber32(timeItem.GetSubStringForTag("HIGHPART"), high))
1767
+ {
1768
+ ft.dwLowDateTime = low;
1769
+ ft.dwHighDateTime = high;
1770
+ return true;
1771
+ }
1772
+ }
1773
+ return false;
1774
+ }
1775
+
1776
+
1777
+ void CImageInfo::Parse(const CXmlItem &item)
1778
+ {
1779
+ CTimeDefined = ParseTime(item, CTime, "CREATIONTIME");
1780
+ MTimeDefined = ParseTime(item, MTime, "LASTMODIFICATIONTIME");
1781
+ NameDefined = ConvertUTF8ToUnicode(item.GetSubStringForTag("NAME"), Name);
1782
+
1783
+ ParseNumber64(item.GetSubStringForTag("DIRCOUNT"), DirCount);
1784
+ ParseNumber64(item.GetSubStringForTag("FILECOUNT"), FileCount);
1785
+ IndexDefined = ParseNumber32(item.GetPropVal("INDEX"), Index);
1786
+ }
1787
+
1788
+ void CWimXml::ToUnicode(UString &s)
1789
+ {
1790
+ size_t size = Data.Size();
1791
+ if (size < 2 || (size & 1) != 0 || size > (1 << 24))
1792
+ return;
1793
+ const Byte *p = Data;
1794
+ if (Get16(p) != 0xFEFF)
1795
+ return;
1796
+ wchar_t *chars = s.GetBuf((unsigned)(size / 2));
1797
+ for (size_t i = 2; i < size; i += 2)
1798
+ {
1799
+ wchar_t c = Get16(p + i);
1800
+ if (c == 0)
1801
+ break;
1802
+ *chars++ = c;
1803
+ }
1804
+ *chars = 0;
1805
+ s.ReleaseBuf_SetLen((unsigned)(chars - (const wchar_t *)s));
1806
+ }
1807
+
1808
+
1809
+ bool CWimXml::Parse()
1810
+ {
1811
+ IsEncrypted = false;
1812
+ AString utf;
1813
+ {
1814
+ UString s;
1815
+ ToUnicode(s);
1816
+ // if (!ConvertUnicodeToUTF8(s, utf)) return false;
1817
+ ConvertUnicodeToUTF8(s, utf);
1818
+ }
1819
+
1820
+ if (!Xml.Parse(utf))
1821
+ return false;
1822
+ if (Xml.Root.Name != "WIM")
1823
+ return false;
1824
+
1825
+ FOR_VECTOR (i, Xml.Root.SubItems)
1826
+ {
1827
+ const CXmlItem &item = Xml.Root.SubItems[i];
1828
+
1829
+ if (item.IsTagged("IMAGE"))
1830
+ {
1831
+ CImageInfo imageInfo;
1832
+ imageInfo.Parse(item);
1833
+ if (!imageInfo.IndexDefined)
1834
+ return false;
1835
+
1836
+ if (imageInfo.Index != (UInt32)Images.Size() + 1)
1837
+ {
1838
+ // old wim (1.09) uses zero based image index
1839
+ if (imageInfo.Index != (UInt32)Images.Size())
1840
+ return false;
1841
+ }
1842
+
1843
+ imageInfo.ItemIndexInXml = i;
1844
+ Images.Add(imageInfo);
1845
+ }
1846
+
1847
+ if (item.IsTagged("ESD"))
1848
+ {
1849
+ FOR_VECTOR (k, item.SubItems)
1850
+ {
1851
+ const CXmlItem &item2 = item.SubItems[k];
1852
+ if (item2.IsTagged("ENCRYPTED"))
1853
+ IsEncrypted = true;
1854
+ }
1855
+ }
1856
+ }
1857
+
1858
+ return true;
1859
+ }
1860
+
855
1861
  }}