seven_zip_ruby 1.0.0

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 (732) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +39 -0
  6. data/README.md +176 -0
  7. data/Rakefile +47 -0
  8. data/ext/C/Types.h +254 -0
  9. data/ext/CPP/7zip/Archive/IArchive.h +234 -0
  10. data/ext/CPP/7zip/IDecl.h +15 -0
  11. data/ext/CPP/7zip/IPassword.h +24 -0
  12. data/ext/CPP/7zip/IProgress.h +33 -0
  13. data/ext/CPP/7zip/IStream.h +58 -0
  14. data/ext/CPP/7zip/PropID.h +76 -0
  15. data/ext/CPP/Common/MyCom.h +225 -0
  16. data/ext/CPP/Common/MyGuidDef.h +54 -0
  17. data/ext/CPP/Common/MyInitGuid.h +22 -0
  18. data/ext/CPP/Common/MyUnknown.h +13 -0
  19. data/ext/CPP/Common/MyWindows.h +204 -0
  20. data/ext/CPP/Common/Types.h +11 -0
  21. data/ext/CPP/Windows/PropVariant.h +56 -0
  22. data/ext/CPP/include_windows/basetyps.h +19 -0
  23. data/ext/CPP/include_windows/tchar.h +89 -0
  24. data/ext/CPP/include_windows/windows.h +194 -0
  25. data/ext/p7zip/Asm/x64/7zCrcT8U.asm +103 -0
  26. data/ext/p7zip/Asm/x86/7zCrcT8U.asm +101 -0
  27. data/ext/p7zip/C/7zBuf.h +39 -0
  28. data/ext/p7zip/C/7zBuf2.c +45 -0
  29. data/ext/p7zip/C/7zCrc.c +76 -0
  30. data/ext/p7zip/C/7zCrc.h +25 -0
  31. data/ext/p7zip/C/7zCrcOpt.c +34 -0
  32. data/ext/p7zip/C/7zCrcT8.c +43 -0
  33. data/ext/p7zip/C/7zStream.c +169 -0
  34. data/ext/p7zip/C/7zVersion.h +7 -0
  35. data/ext/p7zip/C/Aes.c +284 -0
  36. data/ext/p7zip/C/Aes.h +38 -0
  37. data/ext/p7zip/C/Alloc.back3 +238 -0
  38. data/ext/p7zip/C/Alloc.c +280 -0
  39. data/ext/p7zip/C/Alloc.c.back +243 -0
  40. data/ext/p7zip/C/Alloc.c.back2 +222 -0
  41. data/ext/p7zip/C/Alloc.h +27 -0
  42. data/ext/p7zip/C/Bra.c +133 -0
  43. data/ext/p7zip/C/Bra.h +68 -0
  44. data/ext/p7zip/C/Bra86.c +85 -0
  45. data/ext/p7zip/C/BraIA64.c +67 -0
  46. data/ext/p7zip/C/BwtSort.c +516 -0
  47. data/ext/p7zip/C/BwtSort.h +30 -0
  48. data/ext/p7zip/C/CpuArch.c +168 -0
  49. data/ext/p7zip/C/CpuArch.h +155 -0
  50. data/ext/p7zip/C/Delta.c +62 -0
  51. data/ext/p7zip/C/Delta.h +23 -0
  52. data/ext/p7zip/C/HuffEnc.c +146 -0
  53. data/ext/p7zip/C/HuffEnc.h +27 -0
  54. data/ext/p7zip/C/LzFind.c +761 -0
  55. data/ext/p7zip/C/LzFind.h +115 -0
  56. data/ext/p7zip/C/LzFindMt.c +793 -0
  57. data/ext/p7zip/C/LzFindMt.h +105 -0
  58. data/ext/p7zip/C/LzHash.h +54 -0
  59. data/ext/p7zip/C/Lzma2Dec.c +356 -0
  60. data/ext/p7zip/C/Lzma2Dec.h +84 -0
  61. data/ext/p7zip/C/Lzma2Enc.c +477 -0
  62. data/ext/p7zip/C/Lzma2Enc.h +66 -0
  63. data/ext/p7zip/C/LzmaDec.c +999 -0
  64. data/ext/p7zip/C/LzmaDec.h +231 -0
  65. data/ext/p7zip/C/LzmaEnc.c +2268 -0
  66. data/ext/p7zip/C/LzmaEnc.h +80 -0
  67. data/ext/p7zip/C/LzmaUtil/Lzma86Dec.c +61 -0
  68. data/ext/p7zip/C/LzmaUtil/Lzma86Dec.h +51 -0
  69. data/ext/p7zip/C/LzmaUtil/Lzma86Enc.c +113 -0
  70. data/ext/p7zip/C/LzmaUtil/Lzma86Enc.h +78 -0
  71. data/ext/p7zip/C/MtCoder.c +327 -0
  72. data/ext/p7zip/C/MtCoder.h +98 -0
  73. data/ext/p7zip/C/Ppmd.h +85 -0
  74. data/ext/p7zip/C/Ppmd7.c +708 -0
  75. data/ext/p7zip/C/Ppmd7.h +140 -0
  76. data/ext/p7zip/C/Ppmd7Dec.c +187 -0
  77. data/ext/p7zip/C/Ppmd7Enc.c +185 -0
  78. data/ext/p7zip/C/Ppmd8.c +1120 -0
  79. data/ext/p7zip/C/Ppmd8.h +133 -0
  80. data/ext/p7zip/C/Ppmd8Dec.c +155 -0
  81. data/ext/p7zip/C/Ppmd8Enc.c +161 -0
  82. data/ext/p7zip/C/RotateDefs.h +20 -0
  83. data/ext/p7zip/C/Sha256.c +204 -0
  84. data/ext/p7zip/C/Sha256.h +26 -0
  85. data/ext/p7zip/C/Sort.c +93 -0
  86. data/ext/p7zip/C/Sort.h +20 -0
  87. data/ext/p7zip/C/Threads.c +582 -0
  88. data/ext/p7zip/C/Threads.h +123 -0
  89. data/ext/p7zip/C/Types.h +254 -0
  90. data/ext/p7zip/C/Xz.c +88 -0
  91. data/ext/p7zip/C/Xz.h +252 -0
  92. data/ext/p7zip/C/XzCrc64.c +33 -0
  93. data/ext/p7zip/C/XzCrc64.h +26 -0
  94. data/ext/p7zip/C/XzDec.c +875 -0
  95. data/ext/p7zip/C/XzEnc.c +497 -0
  96. data/ext/p7zip/C/XzEnc.h +25 -0
  97. data/ext/p7zip/C/XzIn.c +306 -0
  98. data/ext/p7zip/CPP/7zip/Archive/7z/7zCompressionMode.cpp +3 -0
  99. data/ext/p7zip/CPP/7zip/Archive/7z/7zCompressionMode.h +50 -0
  100. data/ext/p7zip/CPP/7zip/Archive/7z/7zDecode.cpp +332 -0
  101. data/ext/p7zip/CPP/7zip/Archive/7z/7zDecode.h +68 -0
  102. data/ext/p7zip/CPP/7zip/Archive/7z/7zEncode.cpp +444 -0
  103. data/ext/p7zip/CPP/7zip/Archive/7z/7zEncode.h +55 -0
  104. data/ext/p7zip/CPP/7zip/Archive/7z/7zExtract.cpp +270 -0
  105. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderInStream.cpp +123 -0
  106. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderInStream.h +58 -0
  107. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderOutStream.cpp +149 -0
  108. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderOutStream.h +58 -0
  109. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandler.cpp +482 -0
  110. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandler.h +119 -0
  111. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandlerOut.cpp +483 -0
  112. data/ext/p7zip/CPP/7zip/Archive/7z/7zHeader.cpp +14 -0
  113. data/ext/p7zip/CPP/7zip/Archive/7z/7zHeader.h +97 -0
  114. data/ext/p7zip/CPP/7zip/Archive/7z/7zIn.cpp +1276 -0
  115. data/ext/p7zip/CPP/7zip/Archive/7z/7zIn.h +245 -0
  116. data/ext/p7zip/CPP/7zip/Archive/7z/7zItem.h +268 -0
  117. data/ext/p7zip/CPP/7zip/Archive/7z/7zOut.cpp +866 -0
  118. data/ext/p7zip/CPP/7zip/Archive/7z/7zOut.h +152 -0
  119. data/ext/p7zip/CPP/7zip/Archive/7z/7zProperties.cpp +164 -0
  120. data/ext/p7zip/CPP/7zip/Archive/7z/7zProperties.h +22 -0
  121. data/ext/p7zip/CPP/7zip/Archive/7z/7zRegister.cpp +18 -0
  122. data/ext/p7zip/CPP/7zip/Archive/7z/7zSpecStream.cpp +24 -0
  123. data/ext/p7zip/CPP/7zip/Archive/7z/7zSpecStream.h +35 -0
  124. data/ext/p7zip/CPP/7zip/Archive/7z/7zUpdate.cpp +1216 -0
  125. data/ext/p7zip/CPP/7zip/Archive/7z/7zUpdate.h +88 -0
  126. data/ext/p7zip/CPP/7zip/Archive/ApmHandler.cpp +356 -0
  127. data/ext/p7zip/CPP/7zip/Archive/ArchiveExports.cpp +135 -0
  128. data/ext/p7zip/CPP/7zip/Archive/ArjHandler.cpp +798 -0
  129. data/ext/p7zip/CPP/7zip/Archive/Bz2Handler.cpp +423 -0
  130. data/ext/p7zip/CPP/7zip/Archive/Cab/CabBlockInStream.cpp +189 -0
  131. data/ext/p7zip/CPP/7zip/Archive/Cab/CabBlockInStream.h +44 -0
  132. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHandler.cpp +929 -0
  133. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHandler.h +28 -0
  134. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHeader.cpp +15 -0
  135. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHeader.h +44 -0
  136. data/ext/p7zip/CPP/7zip/Archive/Cab/CabIn.cpp +272 -0
  137. data/ext/p7zip/CPP/7zip/Archive/Cab/CabIn.h +161 -0
  138. data/ext/p7zip/CPP/7zip/Archive/Cab/CabItem.h +63 -0
  139. data/ext/p7zip/CPP/7zip/Archive/Cab/CabRegister.cpp +13 -0
  140. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHandler.cpp +721 -0
  141. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHandler.h +29 -0
  142. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHeader.cpp +24 -0
  143. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHeader.h +28 -0
  144. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmIn.cpp +937 -0
  145. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmIn.h +244 -0
  146. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmRegister.cpp +13 -0
  147. data/ext/p7zip/CPP/7zip/Archive/Com/ComHandler.cpp +239 -0
  148. data/ext/p7zip/CPP/7zip/Archive/Com/ComHandler.h +28 -0
  149. data/ext/p7zip/CPP/7zip/Archive/Com/ComIn.cpp +389 -0
  150. data/ext/p7zip/CPP/7zip/Archive/Com/ComIn.h +119 -0
  151. data/ext/p7zip/CPP/7zip/Archive/Com/ComRegister.cpp +13 -0
  152. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2.cpp +121 -0
  153. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2.h +174 -0
  154. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2MT.cpp +240 -0
  155. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2MT.h +80 -0
  156. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2ST.cpp +239 -0
  157. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2ST.h +88 -0
  158. data/ext/p7zip/CPP/7zip/Archive/Common/CrossThreadProgress.cpp +15 -0
  159. data/ext/p7zip/CPP/7zip/Archive/Common/CrossThreadProgress.h +37 -0
  160. data/ext/p7zip/CPP/7zip/Archive/Common/DummyOutStream.cpp +22 -0
  161. data/ext/p7zip/CPP/7zip/Archive/Common/DummyOutStream.h +24 -0
  162. data/ext/p7zip/CPP/7zip/Archive/Common/FindSignature.cpp +62 -0
  163. data/ext/p7zip/CPP/7zip/Archive/Common/FindSignature.h +12 -0
  164. data/ext/p7zip/CPP/7zip/Archive/Common/HandlerOut.cpp +623 -0
  165. data/ext/p7zip/CPP/7zip/Archive/Common/HandlerOut.h +87 -0
  166. data/ext/p7zip/CPP/7zip/Archive/Common/InStreamWithCRC.cpp +42 -0
  167. data/ext/p7zip/CPP/7zip/Archive/Common/InStreamWithCRC.h +67 -0
  168. data/ext/p7zip/CPP/7zip/Archive/Common/ItemNameUtils.cpp +61 -0
  169. data/ext/p7zip/CPP/7zip/Archive/Common/ItemNameUtils.h +24 -0
  170. data/ext/p7zip/CPP/7zip/Archive/Common/MultiStream.cpp +190 -0
  171. data/ext/p7zip/CPP/7zip/Archive/Common/MultiStream.h +84 -0
  172. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp +18 -0
  173. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.h +36 -0
  174. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithSha1.cpp +18 -0
  175. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithSha1.h +36 -0
  176. data/ext/p7zip/CPP/7zip/Archive/Common/ParseProperties.cpp +177 -0
  177. data/ext/p7zip/CPP/7zip/Archive/Common/ParseProperties.h +18 -0
  178. data/ext/p7zip/CPP/7zip/Archive/CpioHandler.cpp +624 -0
  179. data/ext/p7zip/CPP/7zip/Archive/CramfsHandler.cpp +644 -0
  180. data/ext/p7zip/CPP/7zip/Archive/DebHandler.cpp +413 -0
  181. data/ext/p7zip/CPP/7zip/Archive/DeflateProps.cpp +118 -0
  182. data/ext/p7zip/CPP/7zip/Archive/DeflateProps.h +35 -0
  183. data/ext/p7zip/CPP/7zip/Archive/DllExports2.cpp +76 -0
  184. data/ext/p7zip/CPP/7zip/Archive/DmgHandler.cpp +918 -0
  185. data/ext/p7zip/CPP/7zip/Archive/ElfHandler.cpp +534 -0
  186. data/ext/p7zip/CPP/7zip/Archive/FatHandler.cpp +996 -0
  187. data/ext/p7zip/CPP/7zip/Archive/FlvHandler.cpp +544 -0
  188. data/ext/p7zip/CPP/7zip/Archive/GzHandler.cpp +698 -0
  189. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsHandler.cpp +243 -0
  190. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsHandler.h +26 -0
  191. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsIn.cpp +480 -0
  192. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsIn.h +154 -0
  193. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsRegister.cpp +13 -0
  194. data/ext/p7zip/CPP/7zip/Archive/IArchive.h +234 -0
  195. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHandler.cpp +326 -0
  196. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHandler.h +30 -0
  197. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHeader.cpp +21 -0
  198. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHeader.h +61 -0
  199. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoIn.cpp +453 -0
  200. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoIn.h +315 -0
  201. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoItem.h +141 -0
  202. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoRegister.cpp +13 -0
  203. data/ext/p7zip/CPP/7zip/Archive/LzhHandler.cpp +775 -0
  204. data/ext/p7zip/CPP/7zip/Archive/LzmaHandler.cpp +430 -0
  205. data/ext/p7zip/CPP/7zip/Archive/MachoHandler.cpp +500 -0
  206. data/ext/p7zip/CPP/7zip/Archive/MbrHandler.cpp +507 -0
  207. data/ext/p7zip/CPP/7zip/Archive/MslzHandler.cpp +257 -0
  208. data/ext/p7zip/CPP/7zip/Archive/MubHandler.cpp +266 -0
  209. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisDecode.cpp +130 -0
  210. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisDecode.h +47 -0
  211. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisHandler.cpp +510 -0
  212. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisHandler.h +43 -0
  213. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisIn.cpp +1461 -0
  214. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisIn.h +181 -0
  215. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisRegister.cpp +13 -0
  216. data/ext/p7zip/CPP/7zip/Archive/NtfsHandler.cpp +1764 -0
  217. data/ext/p7zip/CPP/7zip/Archive/PeHandler.cpp +1752 -0
  218. data/ext/p7zip/CPP/7zip/Archive/PpmdHandler.cpp +456 -0
  219. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHandler.cpp +869 -0
  220. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHandler.h +66 -0
  221. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHeader.cpp +21 -0
  222. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHeader.h +205 -0
  223. data/ext/p7zip/CPP/7zip/Archive/Rar/RarIn.cpp +478 -0
  224. data/ext/p7zip/CPP/7zip/Archive/Rar/RarIn.h +123 -0
  225. data/ext/p7zip/CPP/7zip/Archive/Rar/RarItem.cpp +55 -0
  226. data/ext/p7zip/CPP/7zip/Archive/Rar/RarItem.h +79 -0
  227. data/ext/p7zip/CPP/7zip/Archive/Rar/RarRegister.cpp +13 -0
  228. data/ext/p7zip/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp +78 -0
  229. data/ext/p7zip/CPP/7zip/Archive/Rar/RarVolumeInStream.h +49 -0
  230. data/ext/p7zip/CPP/7zip/Archive/RpmHandler.cpp +292 -0
  231. data/ext/p7zip/CPP/7zip/Archive/SplitHandler.cpp +366 -0
  232. data/ext/p7zip/CPP/7zip/Archive/SquashfsHandler.cpp +2155 -0
  233. data/ext/p7zip/CPP/7zip/Archive/SwfHandler.cpp +706 -0
  234. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandler.cpp +386 -0
  235. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandler.h +61 -0
  236. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandlerOut.cpp +122 -0
  237. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHeader.cpp +25 -0
  238. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHeader.h +108 -0
  239. data/ext/p7zip/CPP/7zip/Archive/Tar/TarIn.cpp +207 -0
  240. data/ext/p7zip/CPP/7zip/Archive/Tar/TarIn.h +17 -0
  241. data/ext/p7zip/CPP/7zip/Archive/Tar/TarItem.h +72 -0
  242. data/ext/p7zip/CPP/7zip/Archive/Tar/TarOut.cpp +187 -0
  243. data/ext/p7zip/CPP/7zip/Archive/Tar/TarOut.h +28 -0
  244. data/ext/p7zip/CPP/7zip/Archive/Tar/TarRegister.cpp +18 -0
  245. data/ext/p7zip/CPP/7zip/Archive/Tar/TarUpdate.cpp +139 -0
  246. data/ext/p7zip/CPP/7zip/Archive/Tar/TarUpdate.h +34 -0
  247. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfHandler.cpp +451 -0
  248. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfHandler.h +37 -0
  249. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfIn.cpp +876 -0
  250. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfIn.h +375 -0
  251. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfRegister.cpp +13 -0
  252. data/ext/p7zip/CPP/7zip/Archive/VhdHandler.cpp +734 -0
  253. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandler.cpp +660 -0
  254. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandler.h +77 -0
  255. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandlerOut.cpp +639 -0
  256. data/ext/p7zip/CPP/7zip/Archive/Wim/WimIn.cpp +855 -0
  257. data/ext/p7zip/CPP/7zip/Archive/Wim/WimIn.h +297 -0
  258. data/ext/p7zip/CPP/7zip/Archive/Wim/WimRegister.cpp +18 -0
  259. data/ext/p7zip/CPP/7zip/Archive/XarHandler.cpp +588 -0
  260. data/ext/p7zip/CPP/7zip/Archive/XzHandler.cpp +707 -0
  261. data/ext/p7zip/CPP/7zip/Archive/ZHandler.cpp +161 -0
  262. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipAddCommon.cpp +379 -0
  263. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipAddCommon.h +56 -0
  264. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipCompressionMode.h +42 -0
  265. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandler.cpp +822 -0
  266. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandler.h +101 -0
  267. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp +537 -0
  268. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHeader.cpp +36 -0
  269. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHeader.h +284 -0
  270. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipIn.cpp +893 -0
  271. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipIn.h +125 -0
  272. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItem.cpp +181 -0
  273. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItem.h +281 -0
  274. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItemEx.h +34 -0
  275. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipOut.cpp +289 -0
  276. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipOut.h +56 -0
  277. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipRegister.cpp +18 -0
  278. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipUpdate.cpp +1076 -0
  279. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipUpdate.h +58 -0
  280. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile +328 -0
  281. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile.depend +4962 -0
  282. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile.list +265 -0
  283. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7zFM.txt +163 -0
  284. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7zG.txt +131 -0
  285. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7za.txt +253 -0
  286. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_ALL.txt +32 -0
  287. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_Format7zFree.txt +290 -0
  288. data/ext/p7zip/CPP/7zip/CMAKE/generate.sh +37 -0
  289. data/ext/p7zip/CPP/7zip/CMAKE/generate_xcode.sh +32 -0
  290. data/ext/p7zip/CPP/7zip/Common/CWrappers.cpp +226 -0
  291. data/ext/p7zip/CPP/7zip/Common/CWrappers.h +109 -0
  292. data/ext/p7zip/CPP/7zip/Common/CreateCoder.cpp +293 -0
  293. data/ext/p7zip/CPP/7zip/Common/CreateCoder.h +98 -0
  294. data/ext/p7zip/CPP/7zip/Common/FilePathAutoRename.cpp +55 -0
  295. data/ext/p7zip/CPP/7zip/Common/FilePathAutoRename.h +10 -0
  296. data/ext/p7zip/CPP/7zip/Common/FileStreams.cpp +273 -0
  297. data/ext/p7zip/CPP/7zip/Common/FileStreams.h +134 -0
  298. data/ext/p7zip/CPP/7zip/Common/FilterCoder.cpp +247 -0
  299. data/ext/p7zip/CPP/7zip/Common/FilterCoder.h +128 -0
  300. data/ext/p7zip/CPP/7zip/Common/InBuffer.cpp +83 -0
  301. data/ext/p7zip/CPP/7zip/Common/InBuffer.h +81 -0
  302. data/ext/p7zip/CPP/7zip/Common/InOutTempBuffer.cpp +122 -0
  303. data/ext/p7zip/CPP/7zip/Common/InOutTempBuffer.h +48 -0
  304. data/ext/p7zip/CPP/7zip/Common/LimitedStreams.cpp +154 -0
  305. data/ext/p7zip/CPP/7zip/Common/LimitedStreams.h +125 -0
  306. data/ext/p7zip/CPP/7zip/Common/LockedStream.cpp +23 -0
  307. data/ext/p7zip/CPP/7zip/Common/LockedStream.h +38 -0
  308. data/ext/p7zip/CPP/7zip/Common/MemBlocks.cpp +183 -0
  309. data/ext/p7zip/CPP/7zip/Common/MemBlocks.h +71 -0
  310. data/ext/p7zip/CPP/7zip/Common/MethodId.cpp +27 -0
  311. data/ext/p7zip/CPP/7zip/Common/MethodId.h +10 -0
  312. data/ext/p7zip/CPP/7zip/Common/MethodProps.cpp +99 -0
  313. data/ext/p7zip/CPP/7zip/Common/MethodProps.h +41 -0
  314. data/ext/p7zip/CPP/7zip/Common/OffsetStream.cpp +35 -0
  315. data/ext/p7zip/CPP/7zip/Common/OffsetStream.h +25 -0
  316. data/ext/p7zip/CPP/7zip/Common/OutBuffer.cpp +116 -0
  317. data/ext/p7zip/CPP/7zip/Common/OutBuffer.h +64 -0
  318. data/ext/p7zip/CPP/7zip/Common/OutMemStream.cpp +142 -0
  319. data/ext/p7zip/CPP/7zip/Common/OutMemStream.h +96 -0
  320. data/ext/p7zip/CPP/7zip/Common/ProgressMt.cpp +53 -0
  321. data/ext/p7zip/CPP/7zip/Common/ProgressMt.h +46 -0
  322. data/ext/p7zip/CPP/7zip/Common/ProgressUtils.cpp +42 -0
  323. data/ext/p7zip/CPP/7zip/Common/ProgressUtils.h +34 -0
  324. data/ext/p7zip/CPP/7zip/Common/RegisterArc.h +32 -0
  325. data/ext/p7zip/CPP/7zip/Common/RegisterCodec.h +33 -0
  326. data/ext/p7zip/CPP/7zip/Common/StreamBinder.cpp +152 -0
  327. data/ext/p7zip/CPP/7zip/Common/StreamBinder.h +38 -0
  328. data/ext/p7zip/CPP/7zip/Common/StreamObjects.cpp +221 -0
  329. data/ext/p7zip/CPP/7zip/Common/StreamObjects.h +135 -0
  330. data/ext/p7zip/CPP/7zip/Common/StreamUtils.cpp +56 -0
  331. data/ext/p7zip/CPP/7zip/Common/StreamUtils.h +13 -0
  332. data/ext/p7zip/CPP/7zip/Common/VirtThread.cpp +46 -0
  333. data/ext/p7zip/CPP/7zip/Common/VirtThread.h +23 -0
  334. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder1.cpp +309 -0
  335. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder1.h +98 -0
  336. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder2.cpp +90 -0
  337. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder2.h +59 -0
  338. data/ext/p7zip/CPP/7zip/Compress/BZip2Const.h +54 -0
  339. data/ext/p7zip/CPP/7zip/Compress/BZip2Crc.cpp +26 -0
  340. data/ext/p7zip/CPP/7zip/Compress/BZip2Crc.h +31 -0
  341. data/ext/p7zip/CPP/7zip/Compress/BZip2Decoder.cpp +943 -0
  342. data/ext/p7zip/CPP/7zip/Compress/BZip2Decoder.h +205 -0
  343. data/ext/p7zip/CPP/7zip/Compress/BZip2Encoder.cpp +895 -0
  344. data/ext/p7zip/CPP/7zip/Compress/BZip2Encoder.h +245 -0
  345. data/ext/p7zip/CPP/7zip/Compress/BZip2Register.cpp +20 -0
  346. data/ext/p7zip/CPP/7zip/Compress/Bcj2Coder.cpp +386 -0
  347. data/ext/p7zip/CPP/7zip/Compress/Bcj2Coder.h +115 -0
  348. data/ext/p7zip/CPP/7zip/Compress/Bcj2Register.cpp +19 -0
  349. data/ext/p7zip/CPP/7zip/Compress/BcjCoder.cpp +15 -0
  350. data/ext/p7zip/CPP/7zip/Compress/BcjCoder.h +19 -0
  351. data/ext/p7zip/CPP/7zip/Compress/BcjRegister.cpp +19 -0
  352. data/ext/p7zip/CPP/7zip/Compress/BitlDecoder.cpp +24 -0
  353. data/ext/p7zip/CPP/7zip/Compress/BitlDecoder.h +141 -0
  354. data/ext/p7zip/CPP/7zip/Compress/BitlEncoder.h +57 -0
  355. data/ext/p7zip/CPP/7zip/Compress/BitmDecoder.h +66 -0
  356. data/ext/p7zip/CPP/7zip/Compress/BitmEncoder.h +50 -0
  357. data/ext/p7zip/CPP/7zip/Compress/BranchCoder.cpp +19 -0
  358. data/ext/p7zip/CPP/7zip/Compress/BranchCoder.h +44 -0
  359. data/ext/p7zip/CPP/7zip/Compress/BranchMisc.cpp +37 -0
  360. data/ext/p7zip/CPP/7zip/Compress/BranchMisc.h +14 -0
  361. data/ext/p7zip/CPP/7zip/Compress/BranchRegister.cpp +30 -0
  362. data/ext/p7zip/CPP/7zip/Compress/ByteSwap.cpp +73 -0
  363. data/ext/p7zip/CPP/7zip/Compress/CodecExports.cpp +160 -0
  364. data/ext/p7zip/CPP/7zip/Compress/CopyCoder.cpp +67 -0
  365. data/ext/p7zip/CPP/7zip/Compress/CopyCoder.h +34 -0
  366. data/ext/p7zip/CPP/7zip/Compress/CopyRegister.cpp +14 -0
  367. data/ext/p7zip/CPP/7zip/Compress/Deflate64Register.cpp +20 -0
  368. data/ext/p7zip/CPP/7zip/Compress/DeflateConst.h +134 -0
  369. data/ext/p7zip/CPP/7zip/Compress/DeflateDecoder.cpp +353 -0
  370. data/ext/p7zip/CPP/7zip/Compress/DeflateDecoder.h +157 -0
  371. data/ext/p7zip/CPP/7zip/Compress/DeflateEncoder.cpp +986 -0
  372. data/ext/p7zip/CPP/7zip/Compress/DeflateEncoder.h +211 -0
  373. data/ext/p7zip/CPP/7zip/Compress/DeflateRegister.cpp +21 -0
  374. data/ext/p7zip/CPP/7zip/Compress/DeltaFilter.cpp +112 -0
  375. data/ext/p7zip/CPP/7zip/Compress/DllExports.cpp +39 -0
  376. data/ext/p7zip/CPP/7zip/Compress/DllExports2.cpp +28 -0
  377. data/ext/p7zip/CPP/7zip/Compress/HuffmanDecoder.h +89 -0
  378. data/ext/p7zip/CPP/7zip/Compress/ImplodeDecoder.cpp +219 -0
  379. data/ext/p7zip/CPP/7zip/Compress/ImplodeDecoder.h +57 -0
  380. data/ext/p7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp +89 -0
  381. data/ext/p7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.h +34 -0
  382. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp +531 -0
  383. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp +1018 -0
  384. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h +48 -0
  385. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp +311 -0
  386. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h +20 -0
  387. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/makefile +173 -0
  388. data/ext/p7zip/CPP/7zip/Compress/LzOutWindow.cpp +14 -0
  389. data/ext/p7zip/CPP/7zip/Compress/LzOutWindow.h +66 -0
  390. data/ext/p7zip/CPP/7zip/Compress/LzhDecoder.cpp +220 -0
  391. data/ext/p7zip/CPP/7zip/Compress/LzhDecoder.h +106 -0
  392. data/ext/p7zip/CPP/7zip/Compress/Lzma2Decoder.cpp +189 -0
  393. data/ext/p7zip/CPP/7zip/Compress/Lzma2Decoder.h +73 -0
  394. data/ext/p7zip/CPP/7zip/Compress/Lzma2Encoder.cpp +94 -0
  395. data/ext/p7zip/CPP/7zip/Compress/Lzma2Encoder.h +36 -0
  396. data/ext/p7zip/CPP/7zip/Compress/Lzma2Register.cpp +20 -0
  397. data/ext/p7zip/CPP/7zip/Compress/LzmaDecoder.cpp +252 -0
  398. data/ext/p7zip/CPP/7zip/Compress/LzmaDecoder.h +84 -0
  399. data/ext/p7zip/CPP/7zip/Compress/LzmaEncoder.cpp +149 -0
  400. data/ext/p7zip/CPP/7zip/Compress/LzmaEncoder.h +36 -0
  401. data/ext/p7zip/CPP/7zip/Compress/LzmaRegister.cpp +20 -0
  402. data/ext/p7zip/CPP/7zip/Compress/Lzx.h +61 -0
  403. data/ext/p7zip/CPP/7zip/Compress/Lzx86Converter.cpp +90 -0
  404. data/ext/p7zip/CPP/7zip/Compress/Lzx86Converter.h +46 -0
  405. data/ext/p7zip/CPP/7zip/Compress/LzxDecoder.cpp +387 -0
  406. data/ext/p7zip/CPP/7zip/Compress/LzxDecoder.h +159 -0
  407. data/ext/p7zip/CPP/7zip/Compress/Mtf8.h +193 -0
  408. data/ext/p7zip/CPP/7zip/Compress/PpmdDecoder.cpp +167 -0
  409. data/ext/p7zip/CPP/7zip/Compress/PpmdDecoder.h +78 -0
  410. data/ext/p7zip/CPP/7zip/Compress/PpmdEncoder.cpp +119 -0
  411. data/ext/p7zip/CPP/7zip/Compress/PpmdEncoder.h +48 -0
  412. data/ext/p7zip/CPP/7zip/Compress/PpmdRegister.cpp +21 -0
  413. data/ext/p7zip/CPP/7zip/Compress/PpmdZip.cpp +223 -0
  414. data/ext/p7zip/CPP/7zip/Compress/PpmdZip.h +72 -0
  415. data/ext/p7zip/CPP/7zip/Compress/QuantumDecoder.cpp +175 -0
  416. data/ext/p7zip/CPP/7zip/Compress/QuantumDecoder.h +264 -0
  417. data/ext/p7zip/CPP/7zip/Compress/RangeCoder.h +205 -0
  418. data/ext/p7zip/CPP/7zip/Compress/RangeCoderBit.h +114 -0
  419. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile +34 -0
  420. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile.depend +158 -0
  421. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile.list +64 -0
  422. data/ext/p7zip/CPP/7zip/Compress/Rar1Decoder.cpp +480 -0
  423. data/ext/p7zip/CPP/7zip/Compress/Rar1Decoder.h +88 -0
  424. data/ext/p7zip/CPP/7zip/Compress/Rar2Decoder.cpp +391 -0
  425. data/ext/p7zip/CPP/7zip/Compress/Rar2Decoder.h +174 -0
  426. data/ext/p7zip/CPP/7zip/Compress/Rar3Decoder.cpp +897 -0
  427. data/ext/p7zip/CPP/7zip/Compress/Rar3Decoder.h +267 -0
  428. data/ext/p7zip/CPP/7zip/Compress/Rar3Vm.cpp +1091 -0
  429. data/ext/p7zip/CPP/7zip/Compress/Rar3Vm.h +179 -0
  430. data/ext/p7zip/CPP/7zip/Compress/RarCodecsRegister.cpp +26 -0
  431. data/ext/p7zip/CPP/7zip/Compress/ShrinkDecoder.cpp +145 -0
  432. data/ext/p7zip/CPP/7zip/Compress/ShrinkDecoder.h +38 -0
  433. data/ext/p7zip/CPP/7zip/Compress/ZDecoder.cpp +159 -0
  434. data/ext/p7zip/CPP/7zip/Compress/ZDecoder.h +42 -0
  435. data/ext/p7zip/CPP/7zip/Compress/ZlibDecoder.cpp +89 -0
  436. data/ext/p7zip/CPP/7zip/Compress/ZlibDecoder.h +48 -0
  437. data/ext/p7zip/CPP/7zip/Compress/ZlibEncoder.cpp +61 -0
  438. data/ext/p7zip/CPP/7zip/Compress/ZlibEncoder.h +48 -0
  439. data/ext/p7zip/CPP/7zip/Crypto/7zAes.cpp +244 -0
  440. data/ext/p7zip/CPP/7zip/Crypto/7zAes.h +117 -0
  441. data/ext/p7zip/CPP/7zip/Crypto/7zAesRegister.cpp +18 -0
  442. data/ext/p7zip/CPP/7zip/Crypto/HmacSha1.cpp +109 -0
  443. data/ext/p7zip/CPP/7zip/Crypto/HmacSha1.h +39 -0
  444. data/ext/p7zip/CPP/7zip/Crypto/MyAes.cpp +48 -0
  445. data/ext/p7zip/CPP/7zip/Crypto/MyAes.h +38 -0
  446. data/ext/p7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp +83 -0
  447. data/ext/p7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.h +21 -0
  448. data/ext/p7zip/CPP/7zip/Crypto/RandGen.cpp +107 -0
  449. data/ext/p7zip/CPP/7zip/Crypto/RandGen.h +21 -0
  450. data/ext/p7zip/CPP/7zip/Crypto/Rar20Crypto.cpp +133 -0
  451. data/ext/p7zip/CPP/7zip/Crypto/Rar20Crypto.h +50 -0
  452. data/ext/p7zip/CPP/7zip/Crypto/RarAes.cpp +134 -0
  453. data/ext/p7zip/CPP/7zip/Crypto/RarAes.h +47 -0
  454. data/ext/p7zip/CPP/7zip/Crypto/Sha1.cpp +229 -0
  455. data/ext/p7zip/CPP/7zip/Crypto/Sha1.h +68 -0
  456. data/ext/p7zip/CPP/7zip/Crypto/WzAes.cpp +221 -0
  457. data/ext/p7zip/CPP/7zip/Crypto/WzAes.h +125 -0
  458. data/ext/p7zip/CPP/7zip/Crypto/ZipCrypto.cpp +88 -0
  459. data/ext/p7zip/CPP/7zip/Crypto/ZipCrypto.h +56 -0
  460. data/ext/p7zip/CPP/7zip/Crypto/ZipStrong.cpp +164 -0
  461. data/ext/p7zip/CPP/7zip/Crypto/ZipStrong.h +47 -0
  462. data/ext/p7zip/CPP/7zip/Guid.txt +170 -0
  463. data/ext/p7zip/CPP/7zip/ICoder.h +186 -0
  464. data/ext/p7zip/CPP/7zip/IDecl.h +15 -0
  465. data/ext/p7zip/CPP/7zip/IPassword.h +24 -0
  466. data/ext/p7zip/CPP/7zip/IProgress.h +33 -0
  467. data/ext/p7zip/CPP/7zip/IStream.h +58 -0
  468. data/ext/p7zip/CPP/7zip/MyVersion.h +11 -0
  469. data/ext/p7zip/CPP/7zip/PREMAKE/generate.sh +18 -0
  470. data/ext/p7zip/CPP/7zip/PREMAKE/premake4.lua +263 -0
  471. data/ext/p7zip/CPP/7zip/PropID.h +76 -0
  472. data/ext/p7zip/CPP/7zip/QMAKE/7ZA/7ZA.pro +228 -0
  473. data/ext/p7zip/CPP/7zip/QMAKE/7ZA/7ZA_osx.pro +228 -0
  474. data/ext/p7zip/CPP/7zip/QMAKE/test_emul/test_emul.pro +26 -0
  475. data/ext/p7zip/CPP/7zip/TEST/TestUI/TestUI.cpp +560 -0
  476. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile +33 -0
  477. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile.depend +577 -0
  478. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile.list +16 -0
  479. data/ext/p7zip/CPP/Common/AutoPtr.h +35 -0
  480. data/ext/p7zip/CPP/Common/Buffer.h +77 -0
  481. data/ext/p7zip/CPP/Common/CRC.cpp +7 -0
  482. data/ext/p7zip/CPP/Common/C_FileIO.cpp +88 -0
  483. data/ext/p7zip/CPP/Common/C_FileIO.h +47 -0
  484. data/ext/p7zip/CPP/Common/ComTry.h +18 -0
  485. data/ext/p7zip/CPP/Common/CommandLineParser.cpp +230 -0
  486. data/ext/p7zip/CPP/Common/CommandLineParser.h +72 -0
  487. data/ext/p7zip/CPP/Common/Defs.h +20 -0
  488. data/ext/p7zip/CPP/Common/DynamicBuffer.h +50 -0
  489. data/ext/p7zip/CPP/Common/IntToString.cpp +77 -0
  490. data/ext/p7zip/CPP/Common/IntToString.h +19 -0
  491. data/ext/p7zip/CPP/Common/Lang.cpp +130 -0
  492. data/ext/p7zip/CPP/Common/Lang.h +28 -0
  493. data/ext/p7zip/CPP/Common/ListFileUtils.cpp +75 -0
  494. data/ext/p7zip/CPP/Common/ListFileUtils.h +11 -0
  495. data/ext/p7zip/CPP/Common/MyCom.h +225 -0
  496. data/ext/p7zip/CPP/Common/MyException.h +14 -0
  497. data/ext/p7zip/CPP/Common/MyGuidDef.h +54 -0
  498. data/ext/p7zip/CPP/Common/MyInitGuid.h +22 -0
  499. data/ext/p7zip/CPP/Common/MyMap.cpp +140 -0
  500. data/ext/p7zip/CPP/Common/MyMap.h +28 -0
  501. data/ext/p7zip/CPP/Common/MyString.cpp +206 -0
  502. data/ext/p7zip/CPP/Common/MyString.h +601 -0
  503. data/ext/p7zip/CPP/Common/MyUnknown.h +13 -0
  504. data/ext/p7zip/CPP/Common/MyVector.cpp +87 -0
  505. data/ext/p7zip/CPP/Common/MyVector.h +266 -0
  506. data/ext/p7zip/CPP/Common/MyWindows.cpp +111 -0
  507. data/ext/p7zip/CPP/Common/MyWindows.h +218 -0
  508. data/ext/p7zip/CPP/Common/MyXml.cpp +209 -0
  509. data/ext/p7zip/CPP/Common/MyXml.h +40 -0
  510. data/ext/p7zip/CPP/Common/NewHandler.h +16 -0
  511. data/ext/p7zip/CPP/Common/StdInStream.cpp +100 -0
  512. data/ext/p7zip/CPP/Common/StdInStream.h +32 -0
  513. data/ext/p7zip/CPP/Common/StdOutStream.cpp +93 -0
  514. data/ext/p7zip/CPP/Common/StdOutStream.h +35 -0
  515. data/ext/p7zip/CPP/Common/StringConvert.cpp +181 -0
  516. data/ext/p7zip/CPP/Common/StringConvert.h +73 -0
  517. data/ext/p7zip/CPP/Common/StringToInt.cpp +90 -0
  518. data/ext/p7zip/CPP/Common/StringToInt.h +18 -0
  519. data/ext/p7zip/CPP/Common/TextConfig.cpp +138 -0
  520. data/ext/p7zip/CPP/Common/TextConfig.h +22 -0
  521. data/ext/p7zip/CPP/Common/Types.h +11 -0
  522. data/ext/p7zip/CPP/Common/UTFConvert.cpp +145 -0
  523. data/ext/p7zip/CPP/Common/UTFConvert.h +11 -0
  524. data/ext/p7zip/CPP/Common/Wildcard.cpp +462 -0
  525. data/ext/p7zip/CPP/Common/Wildcard.h +80 -0
  526. data/ext/p7zip/CPP/Windows/COM.cpp +37 -0
  527. data/ext/p7zip/CPP/Windows/COM.h +69 -0
  528. data/ext/p7zip/CPP/Windows/Clipboard.cpp +160 -0
  529. data/ext/p7zip/CPP/Windows/Clipboard.h +28 -0
  530. data/ext/p7zip/CPP/Windows/CommonDialog.h +19 -0
  531. data/ext/p7zip/CPP/Windows/Control/ComboBox.h +82 -0
  532. data/ext/p7zip/CPP/Windows/Control/Controls.cpp +515 -0
  533. data/ext/p7zip/CPP/Windows/Control/Dialog.cpp +560 -0
  534. data/ext/p7zip/CPP/Windows/Control/Dialog.h +179 -0
  535. data/ext/p7zip/CPP/Windows/Control/DialogImpl.h +73 -0
  536. data/ext/p7zip/CPP/Windows/Control/Edit.h +24 -0
  537. data/ext/p7zip/CPP/Windows/Control/ListView.h +164 -0
  538. data/ext/p7zip/CPP/Windows/Control/ProgressBar.h +34 -0
  539. data/ext/p7zip/CPP/Windows/Control/Static.h +23 -0
  540. data/ext/p7zip/CPP/Windows/Control/StatusBar.h +56 -0
  541. data/ext/p7zip/CPP/Windows/Control/Window2.cpp +211 -0
  542. data/ext/p7zip/CPP/Windows/Control/Window2.h +111 -0
  543. data/ext/p7zip/CPP/Windows/DLL.cpp +193 -0
  544. data/ext/p7zip/CPP/Windows/DLL.h +48 -0
  545. data/ext/p7zip/CPP/Windows/Defs.h +17 -0
  546. data/ext/p7zip/CPP/Windows/Error.cpp +58 -0
  547. data/ext/p7zip/CPP/Windows/Error.h +33 -0
  548. data/ext/p7zip/CPP/Windows/FileDir.cpp +927 -0
  549. data/ext/p7zip/CPP/Windows/FileDir.h +115 -0
  550. data/ext/p7zip/CPP/Windows/FileFind.cpp +604 -0
  551. data/ext/p7zip/CPP/Windows/FileFind.h +126 -0
  552. data/ext/p7zip/CPP/Windows/FileIO.cpp +475 -0
  553. data/ext/p7zip/CPP/Windows/FileIO.h +110 -0
  554. data/ext/p7zip/CPP/Windows/FileName.cpp +50 -0
  555. data/ext/p7zip/CPP/Windows/FileName.h +27 -0
  556. data/ext/p7zip/CPP/Windows/Menu.h +4 -0
  557. data/ext/p7zip/CPP/Windows/NtCheck.h +44 -0
  558. data/ext/p7zip/CPP/Windows/PropVariant.cpp +243 -0
  559. data/ext/p7zip/CPP/Windows/PropVariant.h +56 -0
  560. data/ext/p7zip/CPP/Windows/PropVariantConversions.cpp +142 -0
  561. data/ext/p7zip/CPP/Windows/PropVariantConversions.h +14 -0
  562. data/ext/p7zip/CPP/Windows/PropVariantUtils.cpp +78 -0
  563. data/ext/p7zip/CPP/Windows/PropVariantUtils.h +28 -0
  564. data/ext/p7zip/CPP/Windows/Registry.cpp +313 -0
  565. data/ext/p7zip/CPP/Windows/Registry.h +113 -0
  566. data/ext/p7zip/CPP/Windows/ResourceString.h +22 -0
  567. data/ext/p7zip/CPP/Windows/Shell.h +21 -0
  568. data/ext/p7zip/CPP/Windows/Synchronization.cpp +157 -0
  569. data/ext/p7zip/CPP/Windows/Synchronization.h +187 -0
  570. data/ext/p7zip/CPP/Windows/Synchronization2.h +218 -0
  571. data/ext/p7zip/CPP/Windows/System.cpp +166 -0
  572. data/ext/p7zip/CPP/Windows/System.h +16 -0
  573. data/ext/p7zip/CPP/Windows/Thread.h +41 -0
  574. data/ext/p7zip/CPP/Windows/Time.cpp +88 -0
  575. data/ext/p7zip/CPP/Windows/Time.h +21 -0
  576. data/ext/p7zip/CPP/Windows/Window.cpp +101 -0
  577. data/ext/p7zip/CPP/Windows/Window.h +43 -0
  578. data/ext/p7zip/CPP/include_windows/basetyps.h +19 -0
  579. data/ext/p7zip/CPP/include_windows/tchar.h +89 -0
  580. data/ext/p7zip/CPP/include_windows/windows.h +194 -0
  581. data/ext/p7zip/CPP/myWindows/StdAfx.h +124 -0
  582. data/ext/p7zip/CPP/myWindows/config.h +67 -0
  583. data/ext/p7zip/CPP/myWindows/initguid.h +4 -0
  584. data/ext/p7zip/CPP/myWindows/makefile +21 -0
  585. data/ext/p7zip/CPP/myWindows/makefile.depend +32 -0
  586. data/ext/p7zip/CPP/myWindows/makefile.list +28 -0
  587. data/ext/p7zip/CPP/myWindows/myAddExeFlag.cpp +20 -0
  588. data/ext/p7zip/CPP/myWindows/myGetTickCount.cpp +8 -0
  589. data/ext/p7zip/CPP/myWindows/myPrivate.h +17 -0
  590. data/ext/p7zip/CPP/myWindows/mySplitCommandLine.cpp +82 -0
  591. data/ext/p7zip/CPP/myWindows/test_emul.cpp +745 -0
  592. data/ext/p7zip/CPP/myWindows/wine_GetXXXDefaultLangID.cpp +741 -0
  593. data/ext/p7zip/CPP/myWindows/wine_date_and_time.cpp +434 -0
  594. data/ext/p7zip/ChangeLog +914 -0
  595. data/ext/p7zip/DOCS/7zC.txt +194 -0
  596. data/ext/p7zip/DOCS/7zFormat.txt +469 -0
  597. data/ext/p7zip/DOCS/License.txt +52 -0
  598. data/ext/p7zip/DOCS/MANUAL/commands/add.htm +87 -0
  599. data/ext/p7zip/DOCS/MANUAL/commands/bench.htm +79 -0
  600. data/ext/p7zip/DOCS/MANUAL/commands/delete.htm +59 -0
  601. data/ext/p7zip/DOCS/MANUAL/commands/extract.htm +91 -0
  602. data/ext/p7zip/DOCS/MANUAL/commands/extract_full.htm +68 -0
  603. data/ext/p7zip/DOCS/MANUAL/commands/index.htm +33 -0
  604. data/ext/p7zip/DOCS/MANUAL/commands/list.htm +77 -0
  605. data/ext/p7zip/DOCS/MANUAL/commands/style.css +232 -0
  606. data/ext/p7zip/DOCS/MANUAL/commands/test.htm +46 -0
  607. data/ext/p7zip/DOCS/MANUAL/commands/update.htm +66 -0
  608. data/ext/p7zip/DOCS/MANUAL/exit_codes.htm +27 -0
  609. data/ext/p7zip/DOCS/MANUAL/index.htm +29 -0
  610. data/ext/p7zip/DOCS/MANUAL/style.css +232 -0
  611. data/ext/p7zip/DOCS/MANUAL/switches/ar_exclude.htm +56 -0
  612. data/ext/p7zip/DOCS/MANUAL/switches/ar_include.htm +83 -0
  613. data/ext/p7zip/DOCS/MANUAL/switches/ar_no.htm +52 -0
  614. data/ext/p7zip/DOCS/MANUAL/switches/charset.htm +49 -0
  615. data/ext/p7zip/DOCS/MANUAL/switches/exclude.htm +60 -0
  616. data/ext/p7zip/DOCS/MANUAL/switches/include.htm +87 -0
  617. data/ext/p7zip/DOCS/MANUAL/switches/index.htm +64 -0
  618. data/ext/p7zip/DOCS/MANUAL/switches/large_pages.htm +50 -0
  619. data/ext/p7zip/DOCS/MANUAL/switches/list_tech.htm +36 -0
  620. data/ext/p7zip/DOCS/MANUAL/switches/method.htm +625 -0
  621. data/ext/p7zip/DOCS/MANUAL/switches/output_dir.htm +53 -0
  622. data/ext/p7zip/DOCS/MANUAL/switches/overwrite.htm +56 -0
  623. data/ext/p7zip/DOCS/MANUAL/switches/password.htm +54 -0
  624. data/ext/p7zip/DOCS/MANUAL/switches/recurse.htm +83 -0
  625. data/ext/p7zip/DOCS/MANUAL/switches/sfx.htm +156 -0
  626. data/ext/p7zip/DOCS/MANUAL/switches/ssc.htm +50 -0
  627. data/ext/p7zip/DOCS/MANUAL/switches/stdin.htm +55 -0
  628. data/ext/p7zip/DOCS/MANUAL/switches/stdout.htm +50 -0
  629. data/ext/p7zip/DOCS/MANUAL/switches/stop_switch.htm +31 -0
  630. data/ext/p7zip/DOCS/MANUAL/switches/style.css +232 -0
  631. data/ext/p7zip/DOCS/MANUAL/switches/type.htm +83 -0
  632. data/ext/p7zip/DOCS/MANUAL/switches/update.htm +176 -0
  633. data/ext/p7zip/DOCS/MANUAL/switches/volume.htm +49 -0
  634. data/ext/p7zip/DOCS/MANUAL/switches/working_dir.htm +55 -0
  635. data/ext/p7zip/DOCS/MANUAL/switches/yes.htm +48 -0
  636. data/ext/p7zip/DOCS/MANUAL/syntax.htm +120 -0
  637. data/ext/p7zip/DOCS/Methods.txt +152 -0
  638. data/ext/p7zip/DOCS/copying.txt +504 -0
  639. data/ext/p7zip/DOCS/history.txt +456 -0
  640. data/ext/p7zip/DOCS/lzma.txt +598 -0
  641. data/ext/p7zip/DOCS/readme.txt +181 -0
  642. data/ext/p7zip/DOCS/unRarLicense.txt +41 -0
  643. data/ext/p7zip/README +358 -0
  644. data/ext/p7zip/TODO +39 -0
  645. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/ChangeLog +41 -0
  646. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/readme +21 -0
  647. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/readme.u7z +30 -0
  648. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/u7z +133 -0
  649. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/README +21 -0
  650. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/check/check.sh +117 -0
  651. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/check/files.tar +0 -0
  652. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/man1/p7zip.1 +33 -0
  653. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/p7zip +144 -0
  654. data/ext/p7zip/contrib/qnx630sp3/qnx630sp3-shared +14 -0
  655. data/ext/p7zip/contrib/qnx630sp3/qnx630sp3-static +10 -0
  656. data/ext/p7zip/install.sh +206 -0
  657. data/ext/p7zip/install_local_context_menu.sh +18 -0
  658. data/ext/p7zip/integration_context_menu.txt +51 -0
  659. data/ext/p7zip/makefile +181 -0
  660. data/ext/p7zip/makefile.aix_gcc +22 -0
  661. data/ext/p7zip/makefile.beos +18 -0
  662. data/ext/p7zip/makefile.crc32 +8 -0
  663. data/ext/p7zip/makefile.cygwin +20 -0
  664. data/ext/p7zip/makefile.cygwin_asm +21 -0
  665. data/ext/p7zip/makefile.djgpp_old +21 -0
  666. data/ext/p7zip/makefile.djgpp_watt +47 -0
  667. data/ext/p7zip/makefile.freebsd5 +20 -0
  668. data/ext/p7zip/makefile.freebsd6 +20 -0
  669. data/ext/p7zip/makefile.glb +39 -0
  670. data/ext/p7zip/makefile.gprof +18 -0
  671. data/ext/p7zip/makefile.hpux-acc +17 -0
  672. data/ext/p7zip/makefile.hpux-acc_64 +19 -0
  673. data/ext/p7zip/makefile.hpux-gcc +21 -0
  674. data/ext/p7zip/makefile.linux_amd64 +22 -0
  675. data/ext/p7zip/makefile.linux_amd64_asm +24 -0
  676. data/ext/p7zip/makefile.linux_amd64_asm_icc +27 -0
  677. data/ext/p7zip/makefile.linux_any_cpu +22 -0
  678. data/ext/p7zip/makefile.linux_any_cpu_gcc_4.X +24 -0
  679. data/ext/p7zip/makefile.linux_clang_amd64 +22 -0
  680. data/ext/p7zip/makefile.linux_cross_arm +22 -0
  681. data/ext/p7zip/makefile.linux_gcc_2.95_no_need_for_libstdc +20 -0
  682. data/ext/p7zip/makefile.linux_other +23 -0
  683. data/ext/p7zip/makefile.linux_s390x +23 -0
  684. data/ext/p7zip/makefile.linux_x86_asm_gcc_4.X +26 -0
  685. data/ext/p7zip/makefile.linux_x86_asm_gcc_4.X_fltk +26 -0
  686. data/ext/p7zip/makefile.linux_x86_asm_gcc_mudflap_4.X +26 -0
  687. data/ext/p7zip/makefile.linux_x86_asm_icc +25 -0
  688. data/ext/p7zip/makefile.linux_x86_icc +24 -0
  689. data/ext/p7zip/makefile.machine_base +22 -0
  690. data/ext/p7zip/makefile.macosx_32bits +20 -0
  691. data/ext/p7zip/makefile.macosx_32bits_asm +23 -0
  692. data/ext/p7zip/makefile.macosx_32bits_ppc +21 -0
  693. data/ext/p7zip/makefile.macosx_64bits +20 -0
  694. data/ext/p7zip/makefile.macosx_llvm_64bits +20 -0
  695. data/ext/p7zip/makefile.netbsd +21 -0
  696. data/ext/p7zip/makefile.netware_asm_gcc_3.X +41 -0
  697. data/ext/p7zip/makefile.oldmake +174 -0
  698. data/ext/p7zip/makefile.openbsd +20 -0
  699. data/ext/p7zip/makefile.openbsd_no_port +20 -0
  700. data/ext/p7zip/makefile.qnx_shared.bin +21 -0
  701. data/ext/p7zip/makefile.qnx_static +21 -0
  702. data/ext/p7zip/makefile.rules +661 -0
  703. data/ext/p7zip/makefile.solaris_sparc_CC_32 +21 -0
  704. data/ext/p7zip/makefile.solaris_sparc_CC_64 +23 -0
  705. data/ext/p7zip/makefile.solaris_sparc_gcc +21 -0
  706. data/ext/p7zip/makefile.solaris_x86 +19 -0
  707. data/ext/p7zip/makefile.tru64 +22 -0
  708. data/ext/seven_zip_ruby/depend +5 -0
  709. data/ext/seven_zip_ruby/extconf.rb +131 -0
  710. data/ext/seven_zip_ruby/guid_defs.h +29 -0
  711. data/ext/seven_zip_ruby/mutex.h +10 -0
  712. data/ext/seven_zip_ruby/posix/mutex.h +94 -0
  713. data/ext/seven_zip_ruby/seven_zip_archive.cpp +1614 -0
  714. data/ext/seven_zip_ruby/seven_zip_archive.h +515 -0
  715. data/ext/seven_zip_ruby/util_common.h +444 -0
  716. data/ext/seven_zip_ruby/utils.cpp +576 -0
  717. data/ext/seven_zip_ruby/utils.h +25 -0
  718. data/ext/seven_zip_ruby/win32/mutex.h +130 -0
  719. data/lib/seven_zip_ruby.rb +16 -0
  720. data/lib/seven_zip_ruby/7z.dll +0 -0
  721. data/lib/seven_zip_ruby/7z64.dll +0 -0
  722. data/lib/seven_zip_ruby/archive_info.rb +21 -0
  723. data/lib/seven_zip_ruby/entry_info.rb +45 -0
  724. data/lib/seven_zip_ruby/exception.rb +7 -0
  725. data/lib/seven_zip_ruby/seven_zip_reader.rb +180 -0
  726. data/lib/seven_zip_ruby/seven_zip_writer.rb +143 -0
  727. data/lib/seven_zip_ruby/update_info.rb +116 -0
  728. data/lib/seven_zip_ruby/version.rb +3 -0
  729. data/seven_zip_ruby.gemspec +26 -0
  730. data/spec/seven_zip_ruby_spec.rb +490 -0
  731. data/spec/seven_zip_ruby_spec_helper.rb +122 -0
  732. metadata +820 -0
@@ -0,0 +1,366 @@
1
+ // SplitHandler.cpp
2
+
3
+ #include "StdAfx.h"
4
+
5
+ #include "Common/ComTry.h"
6
+ #include "Common/MyString.h"
7
+
8
+ #include "Windows/PropVariant.h"
9
+
10
+ #include "../Common/ProgressUtils.h"
11
+ #include "../Common/RegisterArc.h"
12
+
13
+ #include "../Compress/CopyCoder.h"
14
+
15
+ #include "Common/MultiStream.h"
16
+
17
+ using namespace NWindows;
18
+
19
+ namespace NArchive {
20
+ namespace NSplit {
21
+
22
+ STATPROPSTG kProps[] =
23
+ {
24
+ { NULL, kpidPath, VT_BSTR},
25
+ { NULL, kpidSize, VT_UI8}
26
+ };
27
+
28
+ STATPROPSTG kArcProps[] =
29
+ {
30
+ { NULL, kpidNumVolumes, VT_UI4}
31
+ };
32
+
33
+ class CHandler:
34
+ public IInArchive,
35
+ public IInArchiveGetStream,
36
+ public CMyUnknownImp
37
+ {
38
+ UString _subName;
39
+ CObjectVector<CMyComPtr<IInStream> > _streams;
40
+ CRecordVector<UInt64> _sizes;
41
+ UInt64 _totalSize;
42
+ public:
43
+ MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
44
+ INTERFACE_IInArchive(;)
45
+ STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
46
+ };
47
+
48
+ IMP_IInArchive_Props
49
+ IMP_IInArchive_ArcProps
50
+
51
+ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
52
+ {
53
+ NCOM::CPropVariant prop;
54
+ switch(propID)
55
+ {
56
+ case kpidMainSubfile: prop = (UInt32)0; break;
57
+ case kpidNumVolumes: prop = (UInt32)_streams.Size(); break;
58
+ }
59
+ prop.Detach(value);
60
+ return S_OK;
61
+ }
62
+
63
+ struct CSeqName
64
+ {
65
+ UString _unchangedPart;
66
+ UString _changedPart;
67
+ bool _splitStyle;
68
+
69
+ UString GetNextName()
70
+ {
71
+ UString newName;
72
+ if (_splitStyle)
73
+ {
74
+ int i;
75
+ int numLetters = _changedPart.Length();
76
+ for (i = numLetters - 1; i >= 0; i--)
77
+ {
78
+ wchar_t c = _changedPart[i];
79
+ if (c == 'z')
80
+ {
81
+ c = 'a';
82
+ newName = c + newName;
83
+ continue;
84
+ }
85
+ else if (c == 'Z')
86
+ {
87
+ c = 'A';
88
+ newName = c + newName;
89
+ continue;
90
+ }
91
+ c++;
92
+ if ((c == 'z' || c == 'Z') && i == 0)
93
+ {
94
+ _unchangedPart += c;
95
+ wchar_t newChar = (c == 'z') ? L'a' : L'A';
96
+ newName.Empty();
97
+ numLetters++;
98
+ for (int k = 0; k < numLetters; k++)
99
+ newName += newChar;
100
+ break;
101
+ }
102
+ newName = c + newName;
103
+ i--;
104
+ for (; i >= 0; i--)
105
+ newName = _changedPart[i] + newName;
106
+ break;
107
+ }
108
+ }
109
+ else
110
+ {
111
+ int i;
112
+ int numLetters = _changedPart.Length();
113
+ for (i = numLetters - 1; i >= 0; i--)
114
+ {
115
+ wchar_t c = _changedPart[i];
116
+ if (c == L'9')
117
+ {
118
+ c = L'0';
119
+ newName = c + newName;
120
+ if (i == 0)
121
+ newName = UString(L'1') + newName;
122
+ continue;
123
+ }
124
+ c++;
125
+ newName = c + newName;
126
+ i--;
127
+ for (; i >= 0; i--)
128
+ newName = _changedPart[i] + newName;
129
+ break;
130
+ }
131
+ }
132
+ _changedPart = newName;
133
+ return _unchangedPart + _changedPart;
134
+ }
135
+ };
136
+
137
+ STDMETHODIMP CHandler::Open(IInStream *stream,
138
+ const UInt64 * /* maxCheckStartPosition */,
139
+ IArchiveOpenCallback *openArchiveCallback)
140
+ {
141
+ COM_TRY_BEGIN
142
+ Close();
143
+ if (openArchiveCallback == 0)
144
+ return S_FALSE;
145
+ // try
146
+ {
147
+ CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
148
+ CMyComPtr<IArchiveOpenCallback> openArchiveCallbackWrap = openArchiveCallback;
149
+ if (openArchiveCallbackWrap.QueryInterface(IID_IArchiveOpenVolumeCallback,
150
+ &openVolumeCallback) != S_OK)
151
+ return S_FALSE;
152
+
153
+ UString name;
154
+ {
155
+ NCOM::CPropVariant prop;
156
+ RINOK(openVolumeCallback->GetProperty(kpidName, &prop));
157
+ if (prop.vt != VT_BSTR)
158
+ return S_FALSE;
159
+ name = prop.bstrVal;
160
+ }
161
+
162
+ int dotPos = name.ReverseFind('.');
163
+ UString prefix, ext;
164
+ if (dotPos >= 0)
165
+ {
166
+ prefix = name.Left(dotPos + 1);
167
+ ext = name.Mid(dotPos + 1);
168
+ }
169
+ else
170
+ ext = name;
171
+ UString extBig = ext;
172
+ extBig.MakeUpper();
173
+
174
+ CSeqName seqName;
175
+
176
+ int numLetters = 2;
177
+ bool splitStyle = false;
178
+ if (extBig.Right(2) == L"AA")
179
+ {
180
+ splitStyle = true;
181
+ while (numLetters < extBig.Length())
182
+ {
183
+ if (extBig[extBig.Length() - numLetters - 1] != 'A')
184
+ break;
185
+ numLetters++;
186
+ }
187
+ }
188
+ else if (ext.Right(2) == L"01")
189
+ {
190
+ while (numLetters < extBig.Length())
191
+ {
192
+ if (extBig[extBig.Length() - numLetters - 1] != '0')
193
+ break;
194
+ numLetters++;
195
+ }
196
+ if (numLetters != ext.Length())
197
+ return S_FALSE;
198
+ }
199
+ else
200
+ return S_FALSE;
201
+
202
+ _streams.Add(stream);
203
+
204
+ seqName._unchangedPart = prefix + ext.Left(extBig.Length() - numLetters);
205
+ seqName._changedPart = ext.Right(numLetters);
206
+ seqName._splitStyle = splitStyle;
207
+
208
+ if (prefix.Length() < 1)
209
+ _subName = L"file";
210
+ else
211
+ _subName = prefix.Left(prefix.Length() - 1);
212
+
213
+ _totalSize = 0;
214
+ UInt64 size;
215
+ {
216
+ NCOM::CPropVariant prop;
217
+ RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));
218
+ if (prop.vt != VT_UI8)
219
+ return E_INVALIDARG;
220
+ size = prop.uhVal.QuadPart;
221
+ }
222
+ _totalSize += size;
223
+ _sizes.Add(size);
224
+
225
+ if (openArchiveCallback != NULL)
226
+ {
227
+ UInt64 numFiles = _streams.Size();
228
+ RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));
229
+ }
230
+
231
+ for (;;)
232
+ {
233
+ UString fullName = seqName.GetNextName();
234
+ CMyComPtr<IInStream> nextStream;
235
+ HRESULT result = openVolumeCallback->GetStream(fullName, &nextStream);
236
+ if (result == S_FALSE)
237
+ break;
238
+ if (result != S_OK)
239
+ return result;
240
+ if (!stream)
241
+ break;
242
+ {
243
+ NCOM::CPropVariant prop;
244
+ RINOK(openVolumeCallback->GetProperty(kpidSize, &prop));
245
+ if (prop.vt != VT_UI8)
246
+ return E_INVALIDARG;
247
+ size = prop.uhVal.QuadPart;
248
+ }
249
+ _totalSize += size;
250
+ _sizes.Add(size);
251
+ _streams.Add(nextStream);
252
+ if (openArchiveCallback != NULL)
253
+ {
254
+ UInt64 numFiles = _streams.Size();
255
+ RINOK(openArchiveCallback->SetCompleted(&numFiles, NULL));
256
+ }
257
+ }
258
+ }
259
+ /*
260
+ catch(...)
261
+ {
262
+ return S_FALSE;
263
+ }
264
+ */
265
+ return S_OK;
266
+ COM_TRY_END
267
+ }
268
+
269
+ STDMETHODIMP CHandler::Close()
270
+ {
271
+ _sizes.Clear();
272
+ _streams.Clear();
273
+ return S_OK;
274
+ }
275
+
276
+ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
277
+ {
278
+ *numItems = _streams.IsEmpty() ? 0 : 1;
279
+ return S_OK;
280
+ }
281
+
282
+ STDMETHODIMP CHandler::GetProperty(UInt32 /* index */, PROPID propID, PROPVARIANT *value)
283
+ {
284
+ NWindows::NCOM::CPropVariant prop;
285
+ switch(propID)
286
+ {
287
+ case kpidPath: prop = _subName; break;
288
+ case kpidSize:
289
+ case kpidPackSize:
290
+ prop = _totalSize;
291
+ break;
292
+ }
293
+ prop.Detach(value);
294
+ return S_OK;
295
+ }
296
+
297
+ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
298
+ Int32 testMode, IArchiveExtractCallback *extractCallback)
299
+ {
300
+ COM_TRY_BEGIN
301
+ if (numItems == 0)
302
+ return S_OK;
303
+ if (numItems != (UInt32)-1 && (numItems != 1 || indices[0] != 0))
304
+ return E_INVALIDARG;
305
+
306
+ UInt64 currentTotalSize = 0;
307
+ RINOK(extractCallback->SetTotal(_totalSize));
308
+ CMyComPtr<ISequentialOutStream> outStream;
309
+ Int32 askMode = testMode ?
310
+ NExtract::NAskMode::kTest :
311
+ NExtract::NAskMode::kExtract;
312
+ RINOK(extractCallback->GetStream(0, &outStream, askMode));
313
+ if (!testMode && !outStream)
314
+ return S_OK;
315
+ RINOK(extractCallback->PrepareOperation(askMode));
316
+
317
+ NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
318
+ CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
319
+
320
+ CLocalProgress *lps = new CLocalProgress;
321
+ CMyComPtr<ICompressProgressInfo> progress = lps;
322
+ lps->Init(extractCallback, false);
323
+
324
+ for (int i = 0; i < _streams.Size(); i++)
325
+ {
326
+ lps->InSize = lps->OutSize = currentTotalSize;
327
+ RINOK(lps->SetCur());
328
+ IInStream *inStream = _streams[i];
329
+ RINOK(inStream->Seek(0, STREAM_SEEK_SET, NULL));
330
+ RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
331
+ currentTotalSize += copyCoderSpec->TotalSize;
332
+ }
333
+ outStream.Release();
334
+ return extractCallback->SetOperationResult(NExtract::NOperationResult::kOK);
335
+ COM_TRY_END
336
+ }
337
+
338
+ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
339
+ {
340
+ COM_TRY_BEGIN
341
+ if (index != 0)
342
+ return E_INVALIDARG;
343
+ *stream = 0;
344
+ CMultiStream *streamSpec = new CMultiStream;
345
+ CMyComPtr<ISequentialInStream> streamTemp = streamSpec;
346
+ for (int i = 0; i < _streams.Size(); i++)
347
+ {
348
+ CMultiStream::CSubStreamInfo subStreamInfo;
349
+ subStreamInfo.Stream = _streams[i];
350
+ subStreamInfo.Size = _sizes[i];
351
+ streamSpec->Streams.Add(subStreamInfo);
352
+ }
353
+ streamSpec->Init();
354
+ *stream = streamTemp.Detach();
355
+ return S_OK;
356
+ COM_TRY_END
357
+ }
358
+
359
+ static IInArchive *CreateArc() { return new CHandler; }
360
+
361
+ static CArcInfo g_ArcInfo =
362
+ { L"Split", L"001", 0, 0xEA, { 0 }, 0, false, CreateArc, 0 };
363
+
364
+ REGISTER_ARC(Split)
365
+
366
+ }}
@@ -0,0 +1,2155 @@
1
+ // SquashfsHandler.cpp
2
+
3
+ #include "StdAfx.h"
4
+
5
+ #include "../../../C/7zCrc.h"
6
+ #include "../../../C/Alloc.h"
7
+ #include "../../../C/CpuArch.h"
8
+
9
+ #include "Common/ComTry.h"
10
+ #include "Common/IntToString.h"
11
+ #include "Common/StringConvert.h"
12
+
13
+ #include "Windows/PropVariantUtils.h"
14
+ #include "Windows/Time.h"
15
+
16
+ #include "../Common/LimitedStreams.h"
17
+ #include "../Common/ProgressUtils.h"
18
+ #include "../Common/RegisterArc.h"
19
+ #include "../Common/StreamObjects.h"
20
+ #include "../Common/StreamUtils.h"
21
+
22
+ #include "../Compress/CopyCoder.h"
23
+ #include "../Compress/ZlibDecoder.h"
24
+ #include "../Compress/LzmaDecoder.h"
25
+
26
+ namespace NArchive {
27
+ namespace NSquashfs {
28
+
29
+ static const UInt32 kNumFilesMax = (1 << 28);
30
+ static const unsigned kNumDirLevelsMax = (1 << 10);
31
+
32
+ // Layout: Header, Data, inodes, Directories, Fragments, UIDs, GIDs
33
+
34
+ /*
35
+ #define Get16(p) (be ? GetBe16(p) : GetUi16(p))
36
+ #define Get32(p) (be ? GetBe32(p) : GetUi32(p))
37
+ #define Get64(p) (be ? GetBe64(p) : GetUi64(p))
38
+ */
39
+
40
+ UInt16 Get16b(const Byte *p, bool be) { return be ? GetBe16(p) : GetUi16(p); }
41
+ UInt32 Get32b(const Byte *p, bool be) { return be ? GetBe32(p) : GetUi32(p); }
42
+ UInt64 Get64b(const Byte *p, bool be) { return be ? GetBe64(p) : GetUi64(p); }
43
+
44
+ #define Get16(p) Get16b(p, be)
45
+ #define Get32(p) Get32b(p, be)
46
+ #define Get64(p) Get64b(p, be)
47
+
48
+ #define LE_16(offs, dest) dest = GetUi16(p + (offs));
49
+ #define LE_32(offs, dest) dest = GetUi32(p + (offs));
50
+ #define LE_64(offs, dest) dest = GetUi64(p + (offs));
51
+
52
+ #define GET_16(offs, dest) dest = Get16(p + (offs));
53
+ #define GET_32(offs, dest) dest = Get32(p + (offs));
54
+ #define GET_64(offs, dest) dest = Get64(p + (offs));
55
+
56
+ static const UInt32 kSignatureSize = 4;
57
+ #define SIGNATURE { 'h', 's', 'q', 's' }
58
+ static const UInt32 kSignature32_LE = 0x73717368;
59
+ static const UInt32 kSignature32_BE = 0x68737173;
60
+ static const UInt32 kSignature32_LZ = 0x71736873;
61
+
62
+ #define kMethod_ZLIB 1
63
+ #define kMethod_LZMA 2
64
+ #define kMethod_LZO 3
65
+
66
+ static const char *k_Methods[] =
67
+ {
68
+ "Unknown",
69
+ "ZLIB",
70
+ "LZMA",
71
+ "LZO"
72
+ };
73
+
74
+ static const UInt32 kMetadataBlockSizeLog = 13;
75
+ static const UInt32 kMetadataBlockSize = (1 << kMetadataBlockSizeLog);
76
+
77
+ #define MY_S_IFIFO 0x1000
78
+ #define MY_S_IFCHR 0x2000
79
+ #define MY_S_IFDIR 0x4000
80
+ #define MY_S_IFBLK 0x6000
81
+ #define MY_S_IFREG 0x8000
82
+ #define MY_S_IFLNK 0xA000
83
+ #define MY_S_IFSOCK 0xC000
84
+
85
+ enum
86
+ {
87
+ kType_IPC,
88
+ kType_DIR,
89
+ kType_FILE,
90
+ kType_LNK,
91
+ kType_BLK,
92
+ kType_CHR,
93
+ kType_FIFO,
94
+ kType_SOCK
95
+ };
96
+
97
+ static const UInt32 k_TypeToMode[] =
98
+ {
99
+ 0,
100
+ MY_S_IFDIR, MY_S_IFREG, MY_S_IFLNK, MY_S_IFBLK, MY_S_IFCHR, MY_S_IFIFO, MY_S_IFSOCK,
101
+ MY_S_IFDIR, MY_S_IFREG, MY_S_IFLNK, MY_S_IFBLK, MY_S_IFCHR, MY_S_IFIFO, MY_S_IFSOCK
102
+ };
103
+
104
+
105
+ enum
106
+ {
107
+ kFlag_UNC_INODES,
108
+ kFlag_UNC_DATA,
109
+ kFlag_CHECK,
110
+ kFlag_UNC_FRAGS,
111
+ kFlag_NO_FRAGS,
112
+ kFlag_ALWAYS_FRAG,
113
+ kFlag_DUPLICATE,
114
+ kFlag_EXPORT
115
+ };
116
+
117
+ static const CUInt32PCharPair k_Flags[] =
118
+ {
119
+ { kFlag_UNC_INODES, "UNCOMPRESSED_INODES" },
120
+ { kFlag_UNC_DATA, "UNCOMPRESSED_DATA" },
121
+ { kFlag_CHECK, "CHECK" },
122
+ { kFlag_UNC_FRAGS, "UNCOMPRESSED_FRAGMENTS" },
123
+ { kFlag_NO_FRAGS, "NO_FRAGMENTS" },
124
+ { kFlag_ALWAYS_FRAG, "ALWAYS_FRAGMENTS" },
125
+ { kFlag_DUPLICATE, "DUPLICATES_REMOVED" },
126
+ { kFlag_EXPORT, "EXPORTABLE" }
127
+ };
128
+
129
+ static const UInt32 kNotCompressedBit16 = (1 << 15);
130
+ static const UInt32 kNotCompressedBit32 = (1 << 24);
131
+
132
+ #define GET_COMPRESSED_BLOCK_SIZE(size) ((size) & ~kNotCompressedBit32)
133
+ #define IS_COMPRESSED_BLOCK(size) (((size) & kNotCompressedBit32) == 0)
134
+
135
+ static const UInt32 kHeaderSize1 = 0x33;
136
+ static const UInt32 kHeaderSize2 = 0x3F;
137
+ static const UInt32 kHeaderSize3 = 0x77;
138
+ static const UInt32 kHeaderSize4 = 0x60;
139
+
140
+ struct CHeader
141
+ {
142
+ bool be;
143
+ bool SeveralMethods;
144
+ Byte NumUids;
145
+ Byte NumGids;
146
+
147
+ UInt32 NumInodes;
148
+ UInt32 CTime;
149
+ UInt32 BlockSize;
150
+ UInt32 NumFrags;
151
+ UInt16 Method;
152
+ UInt16 BlockSizeLog;
153
+ UInt16 Flags;
154
+ UInt16 NumIDs;
155
+ UInt16 Major;
156
+ UInt16 Minor;
157
+ UInt64 RootInode;
158
+ UInt64 Size;
159
+ UInt64 UidTable;
160
+ UInt64 GidTable;
161
+ UInt64 XattrIdTable;
162
+ UInt64 InodeTable;
163
+ UInt64 DirTable;
164
+ UInt64 FragTable;
165
+ UInt64 LookupTable;
166
+
167
+ void Parse3(const Byte *p)
168
+ {
169
+ Method = kMethod_ZLIB;
170
+ GET_32 (0x08, Size);
171
+ GET_32 (0x0C, UidTable);
172
+ GET_32 (0x10, GidTable);
173
+ GET_32 (0x14, InodeTable);
174
+ GET_32 (0x18, DirTable);
175
+ GET_16 (0x20, BlockSize);
176
+ GET_16 (0x22, BlockSizeLog);
177
+ Flags = p[0x24];
178
+ NumUids = p[0x25];
179
+ NumGids = p[0x26];
180
+ GET_32 (0x27, CTime);
181
+ GET_64 (0x2B, RootInode);
182
+ NumFrags = 0;
183
+ FragTable = UidTable;
184
+
185
+ if (Major >= 2)
186
+ {
187
+ GET_32 (0x33, BlockSize);
188
+ GET_32 (0x37, NumFrags);
189
+ GET_32 (0x3B, FragTable);
190
+ if (Major == 3)
191
+ {
192
+ GET_64 (0x3F, Size);
193
+ GET_64 (0x47, UidTable);
194
+ GET_64 (0x4F, GidTable);
195
+ GET_64 (0x57, InodeTable);
196
+ GET_64 (0x5F, DirTable);
197
+ GET_64 (0x67, FragTable);
198
+ GET_64 (0x6F, LookupTable);
199
+ }
200
+ }
201
+ }
202
+
203
+ void Parse4(const Byte *p)
204
+ {
205
+ LE_32 (0x08, CTime);
206
+ LE_32 (0x0C, BlockSize);
207
+ LE_32 (0x10, NumFrags);
208
+ LE_16 (0x14, Method);
209
+ LE_16 (0x16, BlockSizeLog);
210
+ LE_16 (0x18, Flags);
211
+ LE_16 (0x1A, NumIDs);
212
+ LE_64 (0x20, RootInode);
213
+ LE_64 (0x28, Size);
214
+ LE_64 (0x30, UidTable);
215
+ LE_64 (0x38, XattrIdTable);
216
+ LE_64 (0x40, InodeTable);
217
+ LE_64 (0x48, DirTable);
218
+ LE_64 (0x50, FragTable);
219
+ LE_64 (0x58, LookupTable);
220
+ GidTable = 0;
221
+ }
222
+
223
+ bool Parse(const Byte *p)
224
+ {
225
+ be = false;
226
+ SeveralMethods = false;
227
+ switch (GetUi32(p))
228
+ {
229
+ case kSignature32_LE: break;
230
+ case kSignature32_BE: be = true; break;
231
+ case kSignature32_LZ: SeveralMethods = true; break;
232
+ default: return false;
233
+ }
234
+ GET_32 (4, NumInodes);
235
+ GET_16 (0x1C, Major);
236
+ GET_16 (0x1E, Minor);
237
+ if (Major <= 3)
238
+ Parse3(p);
239
+ else
240
+ {
241
+ if (be)
242
+ return false;
243
+ Parse4(p);
244
+ }
245
+ return
246
+ InodeTable < DirTable &&
247
+ DirTable <= FragTable &&
248
+ FragTable <= Size &&
249
+ UidTable <= Size &&
250
+ BlockSizeLog >= 12 &&
251
+ BlockSizeLog < 31 &&
252
+ BlockSize == ((UInt32)1 << BlockSizeLog);
253
+ }
254
+
255
+ bool IsSupported() const { return Major > 0 && Major <= 4 && BlockSizeLog <= 23; }
256
+ bool IsOldVersion() const { return Major < 4; }
257
+ bool NeedCheckData() const { return (Flags & (1 << kFlag_CHECK)) != 0; }
258
+ unsigned GetFileNameOffset() const { return Major <= 2 ? 3 : (Major == 3 ? 5 : 8); }
259
+ unsigned GetSymLinkOffset() const { return Major <= 1 ? 5: (Major <= 2 ? 6: (Major == 3 ? 18 : 24)); }
260
+ unsigned GetSpecGuidIndex() const { return Major <= 1 ? 0xF: 0xFF; }
261
+ };
262
+
263
+ static const UInt32 kFrag_Empty = (UInt32)(Int32)-1;
264
+ // static const UInt32 kXattr_Empty = (UInt32)(Int32)-1;
265
+
266
+ struct CNode
267
+ {
268
+ UInt16 Type;
269
+ UInt16 Mode;
270
+ UInt16 Uid;
271
+ UInt16 Gid;
272
+ UInt32 Frag;
273
+ UInt32 Offset;
274
+ // UInt32 MTime;
275
+ // UInt32 Number;
276
+ // UInt32 NumLinks;
277
+ // UInt32 RDev;
278
+ // UInt32 Xattr;
279
+ // UInt32 Parent;
280
+
281
+ UInt64 FileSize;
282
+ UInt64 StartBlock;
283
+ // UInt64 Sparse;
284
+
285
+ UInt32 Parse1(const Byte *p, UInt32 size, const CHeader &_h);
286
+ UInt32 Parse2(const Byte *p, UInt32 size, const CHeader &_h);
287
+ UInt32 Parse3(const Byte *p, UInt32 size, const CHeader &_h);
288
+ UInt32 Parse4(const Byte *p, UInt32 size, const CHeader &_h);
289
+
290
+ bool IsDir() const { return (Type == kType_DIR || Type == kType_DIR + 7); }
291
+ bool IsLink() const { return (Type == kType_LNK || Type == kType_LNK + 7); }
292
+ UInt64 GetSize() const { return IsDir() ? 0 : FileSize; }
293
+
294
+ bool ThereAreFrags() const { return Frag != kFrag_Empty; }
295
+ UInt64 GetNumBlocks(const CHeader &_h) const
296
+ {
297
+ return (FileSize >> _h.BlockSizeLog) +
298
+ (!ThereAreFrags() && (FileSize & (_h.BlockSize - 1)) != 0);
299
+ }
300
+ };
301
+
302
+ UInt32 CNode::Parse1(const Byte *p, UInt32 size, const CHeader &_h)
303
+ {
304
+ bool be = _h.be;
305
+ if (size < 4)
306
+ return 0;
307
+ UInt16 t = Get16(p);
308
+ if (be)
309
+ {
310
+ Type = t >> 12;
311
+ Mode = t & 0xFFF;
312
+ Uid = p[2] >> 4;
313
+ Gid = p[2] & 0xF;
314
+ }
315
+ else
316
+ {
317
+ Type = t & 0xF;
318
+ Mode = t >> 4;
319
+ Uid = p[2] & 0xF;
320
+ Gid = p[2] >> 4;
321
+ }
322
+
323
+ // Xattr = kXattr_Empty;
324
+ // MTime = 0;
325
+ FileSize = 0;
326
+ StartBlock = 0;
327
+ Frag = kFrag_Empty;
328
+
329
+ if (Type == 0)
330
+ {
331
+ Byte t = p[3];
332
+ if (be)
333
+ {
334
+ Type = t >> 4;
335
+ Offset = t & 0xF;
336
+ }
337
+ else
338
+ {
339
+ Type = t & 0xF;
340
+ Offset = t >> 4;
341
+ }
342
+ return (Type == kType_FIFO || Type == kType_SOCK) ? 4 : 0;
343
+ }
344
+
345
+ Type--;
346
+ Uid += (Type / 5) * 16;
347
+ Type = (Type % 5) + 1;
348
+
349
+ if (Type == kType_FILE)
350
+ {
351
+ if (size < 15)
352
+ return 0;
353
+ // GET_32 (3, MTime);
354
+ GET_32 (7, StartBlock);
355
+ UInt32 t;
356
+ GET_32 (11, t);
357
+ FileSize = t;
358
+ UInt32 numBlocks = t >> _h.BlockSizeLog;
359
+ if ((t & (_h.BlockSize - 1)) != 0)
360
+ numBlocks++;
361
+ UInt32 pos = numBlocks * 2 + 15;
362
+ return (pos <= size) ? pos : 0;
363
+ }
364
+
365
+ if (Type == kType_DIR)
366
+ {
367
+ if (size < 14)
368
+ return 0;
369
+ UInt32 t = Get32(p + 3);
370
+ if (be)
371
+ {
372
+ FileSize = t >> 13;
373
+ Offset = t & 0x1FFF;
374
+ }
375
+ else
376
+ {
377
+ FileSize = t & 0x7FFFF;
378
+ Offset = t >> 19;
379
+ }
380
+ // GET_32 (7, MTime);
381
+ GET_32 (10, StartBlock);
382
+ if (be)
383
+ StartBlock &= 0xFFFFFF;
384
+ else
385
+ StartBlock >>= 8;
386
+ return 14;
387
+ }
388
+
389
+ if (size < 5)
390
+ return 0;
391
+
392
+ if (Type == kType_LNK)
393
+ {
394
+ UInt32 len;
395
+ GET_16 (3, len);
396
+ FileSize = len;
397
+ len += 5;
398
+ return (len <= size) ? len : 0;
399
+ }
400
+
401
+ // GET_32 (3, RDev);
402
+ return 5;
403
+ }
404
+
405
+ UInt32 CNode::Parse2(const Byte *p, UInt32 size, const CHeader &_h)
406
+ {
407
+ bool be = _h.be;
408
+ if (size < 4)
409
+ return 0;
410
+ UInt16 t = Get16(p);
411
+ if (be)
412
+ {
413
+ Type = t >> 12;
414
+ Mode = t & 0xFFF;
415
+ }
416
+ else
417
+ {
418
+ Type = t & 0xF;
419
+ Mode = t >> 4;
420
+ }
421
+ Uid = p[2];
422
+ Gid = p[3];
423
+
424
+ // Xattr = kXattr_Empty;
425
+
426
+ if (Type == kType_FILE)
427
+ {
428
+ if (size < 24)
429
+ return 0;
430
+ // GET_32 (4, MTime);
431
+ GET_32 (8, StartBlock);
432
+ GET_32 (12, Frag);
433
+ GET_32 (16, Offset);
434
+ UInt32 t;
435
+ GET_32 (20, t);
436
+ FileSize = t;
437
+ UInt32 numBlocks = t >> _h.BlockSizeLog;
438
+ if (!ThereAreFrags() && (t & (_h.BlockSize - 1)) != 0)
439
+ numBlocks++;
440
+ UInt32 pos = numBlocks * 4 + 24;
441
+ return (pos <= size) ? (UInt32)pos : 0;
442
+ }
443
+
444
+ FileSize = 0;
445
+ // MTime = 0;
446
+ StartBlock = 0;
447
+ Frag = kFrag_Empty;
448
+
449
+ if (Type == kType_DIR)
450
+ {
451
+ if (size < 15)
452
+ return 0;
453
+ UInt32 t = Get32(p + 4);
454
+ if (be)
455
+ {
456
+ FileSize = t >> 13;
457
+ Offset = t & 0x1FFF;
458
+ }
459
+ else
460
+ {
461
+ FileSize = t & 0x7FFFF;
462
+ Offset = t >> 19;
463
+ }
464
+ // GET_32 (8, MTime);
465
+ GET_32 (11, StartBlock);
466
+ if (be)
467
+ StartBlock &= 0xFFFFFF;
468
+ else
469
+ StartBlock >>= 8;
470
+ return 15;
471
+ }
472
+
473
+ if (Type == kType_DIR + 7)
474
+ {
475
+ if (size < 18)
476
+ return 0;
477
+ UInt32 t = Get32(p + 4);
478
+ UInt32 t2 = Get16(p + 7);
479
+ if (be)
480
+ {
481
+ FileSize = t >> 5;
482
+ Offset = t2 & 0x1FFF;
483
+ }
484
+ else
485
+ {
486
+ FileSize = t & 0x7FFFFFF;
487
+ Offset = t2 >> 3;
488
+ }
489
+ // GET_32 (9, MTime);
490
+ GET_32 (12, StartBlock);
491
+ if (be)
492
+ StartBlock &= 0xFFFFFF;
493
+ else
494
+ StartBlock >>= 8;
495
+ UInt32 iCount;
496
+ GET_16 (16, iCount);
497
+ UInt32 pos = 18;
498
+ for (UInt32 i = 0; i < iCount; i++)
499
+ {
500
+ // 27 bits: index
501
+ // 29 bits: startBlock
502
+ if (pos + 8 > size)
503
+ return 0;
504
+ pos += 8 + (UInt32)p[pos + 7] + 1; // nameSize
505
+ if (pos > size)
506
+ return 0;
507
+ }
508
+ return pos;
509
+ }
510
+
511
+ if (Type == kType_FIFO || Type == kType_SOCK)
512
+ return 4;
513
+
514
+ if (size < 6)
515
+ return 0;
516
+
517
+ if (Type == kType_LNK)
518
+ {
519
+ UInt32 len;
520
+ GET_16 (4, len);
521
+ FileSize = len;
522
+ len += 6;
523
+ return (len <= size) ? len : 0;
524
+ }
525
+
526
+ if (Type == kType_BLK || Type == kType_CHR)
527
+ {
528
+ // GET_16 (4, RDev);
529
+ return 6;
530
+ }
531
+
532
+ return 0;
533
+ }
534
+
535
+ UInt32 CNode::Parse3(const Byte *p, UInt32 size, const CHeader &_h)
536
+ {
537
+ bool be = _h.be;
538
+ if (size < 12)
539
+ return 0;
540
+ UInt16 t = Get16(p);
541
+ if (be)
542
+ {
543
+ Type = t >> 12;
544
+ Mode = t & 0xFFF;
545
+ }
546
+ else
547
+ {
548
+ Type = t & 0xF;
549
+ Mode = t >> 4;
550
+ }
551
+ Uid = p[2];
552
+ Gid = p[3];
553
+ // GET_32 (4, MTime);
554
+ // GET_32 (8, Number);
555
+ // Xattr = kXattr_Empty;
556
+ FileSize = 0;
557
+ StartBlock = 0;
558
+
559
+ if (Type == kType_FILE || Type == kType_FILE + 7)
560
+ {
561
+ UInt32 offset;
562
+ if (Type == kType_FILE)
563
+ {
564
+ if (size < 32)
565
+ return 0;
566
+ GET_64 (12, StartBlock);
567
+ GET_32 (20, Frag);
568
+ GET_32 (24, Offset);
569
+ GET_32 (28, FileSize);
570
+ offset = 32;
571
+ }
572
+ else
573
+ {
574
+ if (size < 40)
575
+ return 0;
576
+ // GET_32 (12, NumLinks);
577
+ GET_64 (16, StartBlock);
578
+ GET_32 (24, Frag);
579
+ GET_32 (28, Offset);
580
+ GET_64 (32, FileSize);
581
+ offset = 40;
582
+ }
583
+ UInt64 pos = GetNumBlocks(_h) * 4 + offset;
584
+ return (pos <= size) ? (UInt32)pos : 0;
585
+ }
586
+
587
+ if (size < 16)
588
+ return 0;
589
+ // GET_32 (12, NumLinks);
590
+
591
+ if (Type == kType_DIR)
592
+ {
593
+ if (size < 28)
594
+ return 0;
595
+ UInt32 t = Get32(p + 16);
596
+ if (be)
597
+ {
598
+ FileSize = t >> 13;
599
+ Offset = t & 0x1FFF;
600
+ }
601
+ else
602
+ {
603
+ FileSize = t & 0x7FFFF;
604
+ Offset = t >> 19;
605
+ }
606
+ GET_32 (20, StartBlock);
607
+ // GET_32 (24, Parent);
608
+ return 28;
609
+ }
610
+
611
+ if (Type == kType_DIR + 7)
612
+ {
613
+ if (size < 31)
614
+ return 0;
615
+ UInt32 t = Get32(p + 16);
616
+ UInt32 t2 = Get16(p + 19);
617
+ if (be)
618
+ {
619
+ FileSize = t >> 5;
620
+ Offset = t2 & 0x1FFF;
621
+ }
622
+ else
623
+ {
624
+ FileSize = t & 0x7FFFFFF;
625
+ Offset = t2 >> 3;
626
+ }
627
+ GET_32 (21, StartBlock);
628
+ UInt32 iCount;
629
+ GET_16 (25, iCount);
630
+ // GET_32 (27, Parent);
631
+ UInt32 pos = 31;
632
+ for (UInt32 i = 0; i < iCount; i++)
633
+ {
634
+ // UInt32 index
635
+ // UInt32 startBlock
636
+ if (pos + 9 > size)
637
+ return 0;
638
+ pos += 9 + (unsigned)p[pos + 8] + 1; // nameSize
639
+ if (pos > size)
640
+ return 0;
641
+ }
642
+ return pos;
643
+ }
644
+
645
+ if (Type == kType_FIFO || Type == kType_SOCK)
646
+ return 16;
647
+
648
+ if (size < 18)
649
+ return 0;
650
+ if (Type == kType_LNK)
651
+ {
652
+ UInt32 len;
653
+ GET_16 (16, len);
654
+ FileSize = len;
655
+ len += 18;
656
+ return (len <= size) ? len : 0;
657
+ }
658
+
659
+ if (Type == kType_BLK || Type == kType_CHR)
660
+ {
661
+ // GET_16 (16, RDev);
662
+ return 18;
663
+ }
664
+
665
+ return 0;
666
+ }
667
+
668
+ UInt32 CNode::Parse4(const Byte *p, UInt32 size, const CHeader &_h)
669
+ {
670
+ if (size < 20)
671
+ return 0;
672
+ LE_16 (0, Type);
673
+ LE_16 (2, Mode);
674
+ LE_16 (4, Uid);
675
+ LE_16 (6, Gid);
676
+ // LE_32 (8, MTime);
677
+ // LE_32 (12, Number);
678
+
679
+ // Xattr = kXattr_Empty;
680
+ FileSize = 0;
681
+ StartBlock = 0;
682
+
683
+ if (Type == kType_FILE || Type == kType_FILE + 7)
684
+ {
685
+ UInt32 offset;
686
+ if (Type == kType_FILE)
687
+ {
688
+ if (size < 32)
689
+ return 0;
690
+ LE_32 (16, StartBlock);
691
+ LE_32 (20, Frag);
692
+ LE_32 (24, Offset);
693
+ LE_32 (28, FileSize);
694
+ offset = 32;
695
+ }
696
+ else
697
+ {
698
+ if (size < 56)
699
+ return 0;
700
+ LE_64 (16, StartBlock);
701
+ LE_64 (24, FileSize);
702
+ // LE_64 (32, Sparse);
703
+ // LE_32 (40, NumLinks);
704
+ LE_32 (44, Frag);
705
+ LE_32 (48, Offset);
706
+ // LE_32 (52, Xattr);
707
+ offset = 56;
708
+ }
709
+ UInt64 pos = GetNumBlocks(_h) * 4 + offset;
710
+ return (pos <= size) ? (UInt32)pos : 0;
711
+ }
712
+
713
+ if (Type == kType_DIR)
714
+ {
715
+ if (size < 32)
716
+ return 0;
717
+ LE_32 (16, StartBlock);
718
+ // LE_32 (20, NumLinks);
719
+ LE_16 (24, FileSize);
720
+ LE_16 (26, Offset);
721
+ // LE_32 (28, Parent);
722
+ return 32;
723
+ }
724
+
725
+ // LE_32 (16, NumLinks);
726
+
727
+ if (Type == kType_DIR + 7)
728
+ {
729
+ if (size < 40)
730
+ return 0;
731
+ LE_32 (20, FileSize);
732
+ LE_32 (24, StartBlock);
733
+ // LE_32 (28, Parent);
734
+ UInt32 iCount;
735
+ LE_16 (32, iCount);
736
+ LE_16 (34, Offset);
737
+ // LE_32 (36, Xattr);
738
+
739
+ UInt32 pos = 40;
740
+ for (UInt32 i = 0; i < iCount; i++)
741
+ {
742
+ // UInt32 index
743
+ // UInt32 startBlock
744
+ if (pos + 12 > size)
745
+ return 0;
746
+ UInt32 nameLen = GetUi32(p + pos + 8);
747
+ pos += 12 + nameLen + 1;
748
+ if (pos > size || nameLen > (1 << 10))
749
+ return 0;
750
+ }
751
+ return pos;
752
+ }
753
+
754
+ unsigned offset = 20;
755
+ switch(Type)
756
+ {
757
+ case kType_FIFO: case kType_FIFO + 7:
758
+ case kType_SOCK: case kType_SOCK + 7:
759
+ break;
760
+ case kType_LNK: case kType_LNK + 7:
761
+ {
762
+ if (size < 24)
763
+ return 0;
764
+ UInt32 len;
765
+ LE_32 (20, len);
766
+ FileSize = len;
767
+ offset = len + 24;
768
+ if (size < offset || len > (1 << 30))
769
+ return 0;
770
+ break;
771
+ }
772
+ case kType_BLK: case kType_BLK + 7:
773
+ case kType_CHR: case kType_CHR + 7:
774
+ if (size < 24)
775
+ return 0;
776
+ // LE_32 (20, RDev);
777
+ offset = 24;
778
+ break;
779
+ default:
780
+ return 0;
781
+ }
782
+
783
+ if (Type >= 8)
784
+ {
785
+ if (size < offset + 4)
786
+ return 0;
787
+ // LE_32 (offset, Xattr);
788
+ offset += 4;
789
+ }
790
+ return offset;
791
+ }
792
+
793
+ struct CItem
794
+ {
795
+ int Node;
796
+ int Parent;
797
+ UInt32 Ptr;
798
+ };
799
+
800
+ struct CData
801
+ {
802
+ CByteBuffer Data;
803
+ CRecordVector<UInt32> PackPos;
804
+ CRecordVector<UInt32> UnpackPos; // additional item at the end contains TotalUnpackSize
805
+
806
+ UInt32 GetNumBlocks() const { return PackPos.Size(); }
807
+ void Clear()
808
+ {
809
+ Data.Free();
810
+ PackPos.Clear();
811
+ UnpackPos.Clear();
812
+ }
813
+ };
814
+
815
+ struct CFrag
816
+ {
817
+ UInt64 StartBlock;
818
+ UInt32 Size;
819
+ };
820
+
821
+ class CHandler:
822
+ public IInArchive,
823
+ public IInArchiveGetStream,
824
+ public CMyUnknownImp
825
+ {
826
+ CRecordVector<CItem> _items;
827
+ CRecordVector<CNode> _nodes;
828
+ CRecordVector<UInt32> _nodesPos;
829
+ CRecordVector<UInt32> _blockToNode;
830
+ CData _inodesData;
831
+ CData _dirs;
832
+ CRecordVector<CFrag> _frags;
833
+ // CByteBuffer _uids;
834
+ // CByteBuffer _gids;
835
+ CHeader _h;
836
+
837
+ CMyComPtr<IInStream> _stream;
838
+ UInt64 _sizeCalculated;
839
+
840
+ IArchiveOpenCallback *_openCallback;
841
+
842
+ int _nodeIndex;
843
+ CRecordVector<bool> _blockCompressed;
844
+ CRecordVector<UInt64> _blockOffsets;
845
+
846
+ CByteBuffer _cachedBlock;
847
+ UInt64 _cachedBlockStartPos;
848
+ UInt32 _cachedPackBlockSize;
849
+ UInt32 _cachedUnpackBlockSize;
850
+
851
+ CLimitedSequentialInStream *_limitedInStreamSpec;
852
+ CMyComPtr<ISequentialInStream> _limitedInStream;
853
+
854
+ CBufPtrSeqOutStream *_outStreamSpec;
855
+ CMyComPtr<ISequentialOutStream> _outStream;
856
+
857
+ NCompress::NLzma::CDecoder *_lzmaDecoderSpec;
858
+ CMyComPtr<ICompressCoder> _lzmaDecoder;
859
+
860
+ NCompress::NZlib::CDecoder *_zlibDecoderSpec;
861
+ CMyComPtr<ICompressCoder> _zlibDecoder;
862
+
863
+ CByteBuffer _inputBuffer;
864
+
865
+ CDynBufSeqOutStream *_dynOutStreamSpec;
866
+ CMyComPtr<ISequentialOutStream> _dynOutStream;
867
+
868
+ void ClearCache()
869
+ {
870
+ _cachedBlockStartPos = 0;
871
+ _cachedPackBlockSize = 0;
872
+ _cachedUnpackBlockSize = 0;
873
+ }
874
+
875
+ HRESULT Decompress(ISequentialOutStream *outStream, Byte *outBuf, bool *outBufWasWritten, UInt32 *outBufWasWrittenSize,
876
+ UInt32 inSize, UInt32 outSizeMax);
877
+ HRESULT ReadMetadataBlock(UInt32 &packSize);
878
+ HRESULT ReadData(CData &data, UInt64 start, UInt64 end);
879
+
880
+ HRESULT OpenDir(int parent, UInt32 startBlock, UInt32 offset, unsigned level, int &nodeIndex);
881
+ HRESULT ScanInodes(UInt64 ptr);
882
+ // HRESULT ReadUids(UInt64 start, UInt32 num, CByteBuffer &ids);
883
+ HRESULT Open2(IInStream *inStream);
884
+ AString GetPath(int index) const;
885
+ bool GetPackSize(int index, UInt64 &res, bool fillOffsets);
886
+
887
+ public:
888
+ CHandler();
889
+ MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
890
+ INTERFACE_IInArchive(;)
891
+ STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
892
+
893
+ HRESULT ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize);
894
+ };
895
+
896
+ CHandler::CHandler()
897
+ {
898
+ _limitedInStreamSpec = new CLimitedSequentialInStream;
899
+ _limitedInStream = _limitedInStreamSpec;
900
+
901
+ _outStreamSpec = new CBufPtrSeqOutStream();
902
+ _outStream = _outStreamSpec;
903
+
904
+ _dynOutStreamSpec = new CDynBufSeqOutStream;
905
+ _dynOutStream = _dynOutStreamSpec;
906
+ }
907
+
908
+ static const STATPROPSTG kProps[] =
909
+ {
910
+ { NULL, kpidPath, VT_BSTR},
911
+ { NULL, kpidIsDir, VT_BOOL},
912
+ { NULL, kpidSize, VT_UI8},
913
+ { NULL, kpidPackSize, VT_UI8},
914
+ { NULL, kpidMTime, VT_FILETIME},
915
+ { NULL, kpidPosixAttrib, VT_UI4}
916
+ // { NULL, kpidUser, VT_BSTR},
917
+ // { NULL, kpidGroup, VT_BSTR},
918
+ // { NULL, kpidLinks, VT_UI4},
919
+ // { NULL, kpidOffset, VT_UI4}
920
+ };
921
+
922
+ static const STATPROPSTG kArcProps[] =
923
+ {
924
+ { NULL, kpidFileSystem, VT_BSTR},
925
+ { NULL, kpidMethod, VT_BSTR},
926
+ { NULL, kpidBlock, VT_UI4},
927
+ { NULL, kpidPhySize, VT_UI8},
928
+ { NULL, kpidHeadersSize, VT_UI8},
929
+ { NULL, kpidBigEndian, VT_BOOL},
930
+ { NULL, kpidCTime, VT_FILETIME},
931
+ { NULL, kpidCharacts, VT_BSTR}
932
+ // { NULL, kpidNumBlocks, VT_UI4}
933
+ };
934
+
935
+ IMP_IInArchive_Props
936
+ IMP_IInArchive_ArcProps
937
+
938
+ static HRESULT LzoDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen)
939
+ {
940
+ SizeT destRem = *destLen;
941
+ SizeT srcRem = *srcLen;
942
+ *destLen = 0;
943
+ *srcLen = 0;
944
+ const Byte *destStart = dest;
945
+ const Byte *srcStart = src;
946
+ unsigned mode = 2;
947
+
948
+ {
949
+ if (srcRem == 0)
950
+ return S_FALSE;
951
+ UInt32 b = *src;
952
+ if (b > 17)
953
+ {
954
+ src++;
955
+ srcRem--;
956
+ b -= 17;
957
+ mode = (b < 4 ? 0 : 1);
958
+ if (b > srcRem || b > destRem)
959
+ return S_FALSE;
960
+ srcRem -= b;
961
+ destRem -= b;
962
+ do
963
+ *dest++ = *src++;
964
+ while (--b);
965
+ }
966
+ }
967
+
968
+ for (;;)
969
+ {
970
+ if (srcRem < 3)
971
+ return S_FALSE;
972
+ UInt32 b = *src++;
973
+ srcRem--;
974
+ UInt32 len, back;
975
+ if (b >= 64)
976
+ {
977
+ srcRem--;
978
+ back = ((b >> 2) & 7) + ((UInt32)*src++ << 3);
979
+ len = (b >> 5) + 1;
980
+ }
981
+ else if (b < 16)
982
+ {
983
+ if (mode == 2)
984
+ {
985
+ if (b == 0)
986
+ {
987
+ for (b = 15;; b += 255)
988
+ {
989
+ if (srcRem == 0)
990
+ return S_FALSE;
991
+ UInt32 b2 = *src++;
992
+ srcRem--;
993
+ if (b2 != 0)
994
+ {
995
+ b += b2;
996
+ break;
997
+ }
998
+ }
999
+ }
1000
+ b += 3;
1001
+ if (b > srcRem || b > destRem)
1002
+ return S_FALSE;
1003
+ srcRem -= b;
1004
+ destRem -= b;
1005
+ mode = 1;
1006
+ do
1007
+ *dest++ = *src++;
1008
+ while (--b);
1009
+ continue;
1010
+ }
1011
+ srcRem--;
1012
+ back = (b >> 2) + (*src++ << 2);
1013
+ len = 2;
1014
+ if (mode == 1)
1015
+ {
1016
+ back += (1 << 11);
1017
+ len = 3;
1018
+ }
1019
+ }
1020
+ else
1021
+ {
1022
+ UInt32 bOld = b;
1023
+ b = (b < 32 ? 7 : 31);
1024
+ len = bOld & b;
1025
+ if (len == 0)
1026
+ {
1027
+ for (len = b;; len += 255)
1028
+ {
1029
+ if (srcRem == 0)
1030
+ return S_FALSE;
1031
+ UInt32 b2 = *src++;
1032
+ srcRem--;
1033
+ if (b2 != 0)
1034
+ {
1035
+ len += b2;
1036
+ break;
1037
+ }
1038
+ }
1039
+ }
1040
+ len += 2;
1041
+ if (srcRem < 2)
1042
+ return S_FALSE;
1043
+ b = *src;
1044
+ back = (b >> 2) + ((UInt32)src[1] << 6);
1045
+ src += 2;
1046
+ srcRem -= 2;
1047
+ if (bOld < 32)
1048
+ {
1049
+ if (back == 0)
1050
+ {
1051
+ *destLen = dest - destStart;
1052
+ *srcLen = src - srcStart;
1053
+ return S_OK;
1054
+ }
1055
+ back += ((bOld & 8) << 11) + (1 << 14) - 1;
1056
+ }
1057
+ }
1058
+ back++;
1059
+ if (len > destRem || (size_t)(dest - destStart) < back)
1060
+ return S_FALSE;
1061
+ destRem -= len;
1062
+ Byte *destTemp = dest - back;
1063
+ dest += len;
1064
+ do
1065
+ {
1066
+ *(destTemp + back) = *destTemp;
1067
+ destTemp++;
1068
+ }
1069
+ while (--len);
1070
+ b &= 3;
1071
+ if (b == 0)
1072
+ {
1073
+ mode = 2;
1074
+ continue;
1075
+ }
1076
+ if (b > srcRem || b > destRem)
1077
+ return S_FALSE;
1078
+ srcRem -= b;
1079
+ destRem -= b;
1080
+ mode = 0;
1081
+ *dest++ = *src++;
1082
+ if (b > 1)
1083
+ {
1084
+ *dest++ = *src++;
1085
+ if (b > 2)
1086
+ *dest++ = *src++;
1087
+ }
1088
+ }
1089
+ }
1090
+
1091
+ HRESULT CHandler::Decompress(ISequentialOutStream *outStream, Byte *outBuf, bool *outBufWasWritten, UInt32 *outBufWasWrittenSize, UInt32 inSize, UInt32 outSizeMax)
1092
+ {
1093
+ if (outBuf)
1094
+ {
1095
+ *outBufWasWritten = false;
1096
+ *outBufWasWrittenSize = 0;
1097
+ }
1098
+ UInt32 method = _h.Method;
1099
+ if (_h.SeveralMethods)
1100
+ {
1101
+ Byte props[1];
1102
+ RINOK(ReadStream_FALSE(_stream, props, 1));
1103
+ method = (props[0] == 0x5D ? kMethod_LZMA : kMethod_ZLIB);
1104
+ RINOK(_stream->Seek(-1, STREAM_SEEK_CUR, NULL));
1105
+ }
1106
+
1107
+ if (method == kMethod_LZO)
1108
+ {
1109
+ if (_inputBuffer.GetCapacity() < inSize)
1110
+ {
1111
+ _inputBuffer.Free();
1112
+ _inputBuffer.SetCapacity(inSize);
1113
+ }
1114
+ RINOK(ReadStream_FALSE(_stream, _inputBuffer, inSize));
1115
+
1116
+ Byte *dest = outBuf;
1117
+ if (!outBuf)
1118
+ {
1119
+ dest = _dynOutStreamSpec->GetBufPtrForWriting(outSizeMax);
1120
+ if (!dest)
1121
+ return E_OUTOFMEMORY;
1122
+ }
1123
+ SizeT destLen = outSizeMax, srcLen = inSize;
1124
+ RINOK(LzoDecode(dest, &destLen, _inputBuffer, &srcLen));
1125
+ if (inSize != srcLen)
1126
+ return S_FALSE;
1127
+ if (outBuf)
1128
+ {
1129
+ *outBufWasWritten = true;
1130
+ *outBufWasWrittenSize = (UInt32)destLen;
1131
+ }
1132
+ else
1133
+ _dynOutStreamSpec->UpdateSize(destLen);
1134
+ }
1135
+ else if (method == kMethod_LZMA)
1136
+ {
1137
+ if (!_lzmaDecoder)
1138
+ {
1139
+ _lzmaDecoderSpec = new NCompress::NLzma::CDecoder();
1140
+ _lzmaDecoderSpec->FinishStream = true;
1141
+ _lzmaDecoder = _lzmaDecoderSpec;
1142
+ }
1143
+ const UInt32 kPropsSize = 5 + 8;
1144
+ Byte props[kPropsSize];
1145
+ ReadStream_FALSE(_limitedInStream, props, kPropsSize);
1146
+ RINOK(_lzmaDecoderSpec->SetDecoderProperties2(props, 5));
1147
+ UInt64 outSize = GetUi64(props + 5);
1148
+ if (outSize > outSizeMax)
1149
+ return S_FALSE;
1150
+ RINOK(_lzmaDecoder->Code(_limitedInStream, outStream, NULL, &outSize, NULL));
1151
+ if (inSize != kPropsSize + _lzmaDecoderSpec->GetInputProcessedSize())
1152
+ return S_FALSE;
1153
+ }
1154
+ else
1155
+ {
1156
+ if (!_zlibDecoder)
1157
+ {
1158
+ _zlibDecoderSpec = new NCompress::NZlib::CDecoder();
1159
+ _zlibDecoder = _zlibDecoderSpec;
1160
+ }
1161
+ RINOK(_zlibDecoder->Code(_limitedInStream, outStream, NULL, NULL, NULL));
1162
+ if (inSize != _zlibDecoderSpec->GetInputProcessedSize())
1163
+ return S_FALSE;
1164
+ }
1165
+ return S_OK;
1166
+ }
1167
+
1168
+ HRESULT CHandler::ReadMetadataBlock(UInt32 &packSize)
1169
+ {
1170
+ Byte temp[3];
1171
+ unsigned offset = _h.NeedCheckData() ? 3 : 2;
1172
+ if (offset > packSize)
1173
+ return S_FALSE;
1174
+ RINOK(ReadStream_FALSE(_stream, temp, offset));
1175
+ // if (NeedCheckData && Major < 4) checkByte must be = 0xFF
1176
+ bool be = _h.be;
1177
+ UInt32 size = Get16(temp);
1178
+ bool isCompressed = ((size & kNotCompressedBit16) == 0);
1179
+ if (size != kNotCompressedBit16)
1180
+ size &= ~kNotCompressedBit16;
1181
+
1182
+ if (size > kMetadataBlockSize || offset + size > packSize)
1183
+ return S_FALSE;
1184
+ packSize = offset + size;
1185
+ if (isCompressed)
1186
+ {
1187
+ _limitedInStreamSpec->Init(size);
1188
+ RINOK(Decompress(_dynOutStream, NULL, NULL, NULL, size, kMetadataBlockSize));
1189
+ }
1190
+ else
1191
+ {
1192
+ // size != 0 here
1193
+ Byte *buf = _dynOutStreamSpec->GetBufPtrForWriting(size);
1194
+ if (!buf)
1195
+ return E_OUTOFMEMORY;
1196
+ RINOK(ReadStream_FALSE(_stream, buf, size));
1197
+ _dynOutStreamSpec->UpdateSize(size);
1198
+ }
1199
+ return S_OK;
1200
+ }
1201
+
1202
+ HRESULT CHandler::ReadData(CData &data, UInt64 start, UInt64 end)
1203
+ {
1204
+ if (end < start || end - start >= ((UInt64)1 << 32))
1205
+ return S_FALSE;
1206
+ UInt32 size = (UInt32)(end - start);
1207
+ RINOK(_stream->Seek(start, STREAM_SEEK_SET, NULL));
1208
+ _dynOutStreamSpec->Init();
1209
+ UInt32 packPos = 0;
1210
+ while (packPos != size)
1211
+ {
1212
+ data.PackPos.Add(packPos);
1213
+ data.UnpackPos.Add((UInt32)_dynOutStreamSpec->GetSize());
1214
+ if (packPos > size)
1215
+ return S_FALSE;
1216
+ UInt32 packSize = size - packPos;
1217
+ RINOK(ReadMetadataBlock(packSize));
1218
+ if (_dynOutStreamSpec->GetSize() >= ((UInt64)1 << 32))
1219
+ return S_FALSE;
1220
+ packPos += packSize;
1221
+ }
1222
+ data.UnpackPos.Add((UInt32)_dynOutStreamSpec->GetSize());
1223
+ _dynOutStreamSpec->CopyToBuffer(data.Data);
1224
+ return S_OK;
1225
+ }
1226
+
1227
+ struct CTempItem
1228
+ {
1229
+ UInt32 StartBlock;
1230
+ // UInt32 iNodeNumber1;
1231
+ UInt32 Offset;
1232
+ // UInt16 iNodeNumber2;
1233
+ UInt16 Type;
1234
+ };
1235
+
1236
+ HRESULT CHandler::OpenDir(int parent, UInt32 startBlock, UInt32 offset, unsigned level, int &nodeIndex)
1237
+ {
1238
+ if (level > kNumDirLevelsMax)
1239
+ return S_FALSE;
1240
+
1241
+ int blockIndex = _inodesData.PackPos.FindInSorted(startBlock);
1242
+ if (blockIndex < 0)
1243
+ return S_FALSE;
1244
+ UInt32 unpackPos = _inodesData.UnpackPos[blockIndex] + offset;
1245
+ if (unpackPos < offset)
1246
+ return S_FALSE;
1247
+
1248
+ nodeIndex = _nodesPos.FindInSorted(unpackPos, _blockToNode[blockIndex], _blockToNode[blockIndex + 1]);
1249
+ // nodeIndex = _nodesPos.FindInSorted(unpackPos);
1250
+ if (nodeIndex < 0)
1251
+ return S_FALSE;
1252
+
1253
+ const CNode &n = _nodes[nodeIndex];
1254
+ if (!n.IsDir())
1255
+ return S_OK;
1256
+ blockIndex = _dirs.PackPos.FindInSorted((UInt32)n.StartBlock);
1257
+ if (blockIndex < 0)
1258
+ return S_FALSE;
1259
+ unpackPos = _dirs.UnpackPos[blockIndex] + n.Offset;
1260
+ if (unpackPos < n.Offset || unpackPos > _dirs.Data.GetCapacity())
1261
+ return S_FALSE;
1262
+
1263
+ UInt32 rem = (UInt32)_dirs.Data.GetCapacity() - unpackPos;
1264
+ const Byte *p = _dirs.Data + unpackPos;
1265
+ UInt32 fileSize = (UInt32)n.FileSize;
1266
+
1267
+ if (fileSize > rem)
1268
+ return S_FALSE;
1269
+ rem = fileSize;
1270
+ if (_h.Major >= 3)
1271
+ {
1272
+ if (rem < 3)
1273
+ return S_FALSE;
1274
+ rem -= 3;
1275
+ }
1276
+
1277
+ CRecordVector<CTempItem> tempItems;
1278
+ while (rem != 0)
1279
+ {
1280
+ bool be = _h.be;
1281
+ UInt32 count;
1282
+ CTempItem tempItem;
1283
+ if (_h.Major <= 2)
1284
+ {
1285
+ if (rem < 4)
1286
+ return S_FALSE;
1287
+ count = p[0];
1288
+ tempItem.StartBlock = Get32(p);
1289
+ if (be)
1290
+ tempItem.StartBlock &= 0xFFFFFF;
1291
+ else
1292
+ tempItem.StartBlock >>= 8;
1293
+ p += 4;
1294
+ rem -= 4;
1295
+ }
1296
+ else
1297
+ {
1298
+ if (_h.Major == 3)
1299
+ {
1300
+ if (rem < 9)
1301
+ return S_FALSE;
1302
+ count = p[0];
1303
+ p += 1;
1304
+ rem -= 1;
1305
+ }
1306
+ else
1307
+ {
1308
+ if (rem < 12)
1309
+ return S_FALSE;
1310
+ count = GetUi32(p);
1311
+ p += 4;
1312
+ rem -= 4;
1313
+ }
1314
+ GET_32 (0, tempItem.StartBlock);
1315
+ // GET_32 (4, tempItem.iNodeNumber1);
1316
+ p += 8;
1317
+ rem -= 8;
1318
+ }
1319
+ count++;
1320
+
1321
+ for (UInt32 i = 0; i < count; i++)
1322
+ {
1323
+ if (rem == 0)
1324
+ return S_FALSE;
1325
+
1326
+ UInt32 nameOffset = _h.GetFileNameOffset();
1327
+ if (rem < nameOffset)
1328
+ return S_FALSE;
1329
+
1330
+ if ((UInt32)_items.Size() >= kNumFilesMax)
1331
+ return S_FALSE;
1332
+ if (_openCallback)
1333
+ {
1334
+ UInt64 numFiles = _items.Size();
1335
+ if ((numFiles & 0xFFFF) == 0)
1336
+ {
1337
+ RINOK(_openCallback->SetCompleted(&numFiles, NULL));
1338
+ }
1339
+ }
1340
+
1341
+ CItem item;
1342
+ item.Ptr = (UInt32)(p - _dirs.Data);
1343
+
1344
+ UInt32 size;
1345
+ if (_h.IsOldVersion())
1346
+ {
1347
+ UInt32 t = Get16(p);
1348
+ if (be)
1349
+ {
1350
+ tempItem.Offset = t >> 3;
1351
+ tempItem.Type = (UInt16)(t & 0x7);
1352
+ }
1353
+ else
1354
+ {
1355
+ tempItem.Offset = t & 0x1FFF;
1356
+ tempItem.Type = (UInt16)(t >> 13);
1357
+ }
1358
+ size = (UInt32)p[2];
1359
+ /*
1360
+ if (_h.Major > 2)
1361
+ tempItem.iNodeNumber2 = Get16(p + 3);
1362
+ */
1363
+ }
1364
+ else
1365
+ {
1366
+ GET_16 (0, tempItem.Offset);
1367
+ // GET_16 (2, tempItem.iNodeNumber2);
1368
+ GET_16 (4, tempItem.Type);
1369
+ GET_16 (6, size);
1370
+ }
1371
+ p += nameOffset;
1372
+ rem -= nameOffset;
1373
+ size++;
1374
+ if (rem < size)
1375
+ return S_FALSE;
1376
+ p += size;
1377
+ rem -= size;
1378
+ item.Parent = parent;
1379
+ _items.Add(item);
1380
+ tempItems.Add(tempItem);
1381
+ }
1382
+ }
1383
+
1384
+ int startItemIndex = _items.Size() - tempItems.Size();
1385
+ for (int i = 0; i < tempItems.Size(); i++)
1386
+ {
1387
+ const CTempItem &tempItem = tempItems[i];
1388
+ int index = startItemIndex + i;
1389
+ CItem &item = _items[index];
1390
+ RINOK(OpenDir(index, tempItem.StartBlock, tempItem.Offset, level + 1, item.Node));
1391
+ }
1392
+
1393
+ return S_OK;
1394
+ }
1395
+
1396
+ /*
1397
+ HRESULT CHandler::ReadUids(UInt64 start, UInt32 num, CByteBuffer &ids)
1398
+ {
1399
+ size_t size = num * 4;
1400
+ ids.SetCapacity(size);
1401
+ RINOK(_stream->Seek(start, STREAM_SEEK_SET, NULL));
1402
+ return ReadStream_FALSE(_stream, ids, size);
1403
+ }
1404
+ */
1405
+
1406
+ HRESULT CHandler::Open2(IInStream *inStream)
1407
+ {
1408
+ {
1409
+ Byte buf[kHeaderSize3];
1410
+ RINOK(ReadStream_FALSE(inStream, buf, kHeaderSize3));
1411
+ if (!_h.Parse(buf))
1412
+ return S_FALSE;
1413
+ if (!_h.IsSupported())
1414
+ return E_NOTIMPL;
1415
+
1416
+ switch (_h.Method)
1417
+ {
1418
+ case kMethod_ZLIB:
1419
+ case kMethod_LZMA:
1420
+ case kMethod_LZO:
1421
+ break;
1422
+ default:
1423
+ return E_NOTIMPL;
1424
+ }
1425
+ }
1426
+
1427
+ _stream = inStream;
1428
+
1429
+ if (_h.NumFrags != 0)
1430
+ {
1431
+ if (_h.NumFrags > kNumFilesMax)
1432
+ return S_FALSE;
1433
+ _frags.Reserve(_h.NumFrags);
1434
+ CByteBuffer data;
1435
+ unsigned bigFrag = (_h.Major > 2);
1436
+
1437
+ unsigned fragPtrsInBlockLog = kMetadataBlockSizeLog - (3 + bigFrag);
1438
+ UInt32 numBlocks = (_h.NumFrags + (1 << fragPtrsInBlockLog) - 1) >> fragPtrsInBlockLog;
1439
+ size_t numBlocksBytes = (size_t)numBlocks << (2 + bigFrag);
1440
+ data.SetCapacity(numBlocksBytes);
1441
+ RINOK(inStream->Seek(_h.FragTable, STREAM_SEEK_SET, NULL));
1442
+ RINOK(ReadStream_FALSE(inStream, data, numBlocksBytes));
1443
+ bool be = _h.be;
1444
+
1445
+ for (UInt32 i = 0; i < numBlocks; i++)
1446
+ {
1447
+ UInt64 offset = bigFrag ? Get64(data + i * 8) : Get32(data + i * 4);
1448
+ RINOK(_stream->Seek(offset, STREAM_SEEK_SET, NULL));
1449
+ _dynOutStreamSpec->Init();
1450
+ UInt32 packSize = kMetadataBlockSize + 3;
1451
+ RINOK(ReadMetadataBlock(packSize));
1452
+ UInt32 unpackSize = (UInt32)_dynOutStreamSpec->GetSize();
1453
+ if (unpackSize != kMetadataBlockSize)
1454
+ if (i != numBlocks - 1 || unpackSize != ((_h.NumFrags << (3 + bigFrag)) & (kMetadataBlockSize - 1)))
1455
+ return S_FALSE;
1456
+ const Byte *buf = _dynOutStreamSpec->GetBuffer();
1457
+ for (UInt32 j = 0; j < kMetadataBlockSize && j < unpackSize;)
1458
+ {
1459
+ CFrag frag;
1460
+ if (bigFrag)
1461
+ {
1462
+ frag.StartBlock = Get64(buf + j);
1463
+ frag.Size = Get32(buf + j + 8);
1464
+ // some archives contain nonzero in unused (buf + j + 12)
1465
+ j += 16;
1466
+ }
1467
+ else
1468
+ {
1469
+ frag.StartBlock = Get32(buf + j);
1470
+ frag.Size = Get32(buf + j + 4);
1471
+ j += 8;
1472
+ }
1473
+ _frags.Add(frag);
1474
+ }
1475
+ }
1476
+ if ((UInt32)_frags.Size() != _h.NumFrags)
1477
+ return S_FALSE;
1478
+ }
1479
+
1480
+ // RINOK(inStream->Seek(_h.InodeTable, STREAM_SEEK_SET, NULL));
1481
+
1482
+ RINOK(ReadData(_inodesData, _h.InodeTable, _h.DirTable));
1483
+ RINOK(ReadData(_dirs, _h.DirTable, _h.FragTable));
1484
+
1485
+ UInt64 absOffset = _h.RootInode >> 16;
1486
+ if (absOffset >= ((UInt64)1 << 32))
1487
+ return S_FALSE;
1488
+ {
1489
+ UInt32 pos = 0;
1490
+ UInt32 totalSize = (UInt32)_inodesData.Data.GetCapacity();
1491
+ _nodesPos.Reserve(_h.NumInodes);
1492
+ _nodes.Reserve(_h.NumInodes);
1493
+ // we use _blockToNode for binary search seed optimizations
1494
+ _blockToNode.Reserve(_inodesData.GetNumBlocks() + 1);
1495
+ int curBlock = 0;
1496
+ for (UInt32 i = 0; i < _h.NumInodes; i++)
1497
+ {
1498
+ CNode n;
1499
+ const Byte *p = _inodesData.Data + pos;
1500
+ UInt32 size = totalSize - pos;
1501
+
1502
+ switch(_h.Major)
1503
+ {
1504
+ case 1: size = n.Parse1(p, size, _h); break;
1505
+ case 2: size = n.Parse2(p, size, _h); break;
1506
+ case 3: size = n.Parse3(p, size, _h); break;
1507
+ default: size = n.Parse4(p, size, _h); break;
1508
+ }
1509
+ if (size == 0)
1510
+ return S_FALSE;
1511
+ while (pos >= _inodesData.UnpackPos[curBlock])
1512
+ {
1513
+ _blockToNode.Add(_nodesPos.Size());
1514
+ curBlock++;
1515
+ }
1516
+ _nodesPos.Add(pos);
1517
+ _nodes.Add(n);
1518
+ pos += size;
1519
+ }
1520
+ _blockToNode.Add(_nodesPos.Size());
1521
+ if (pos != totalSize)
1522
+ return S_FALSE;
1523
+ }
1524
+ int rootNodeIndex;
1525
+ RINOK(OpenDir(-1, (UInt32)absOffset, (UInt32)_h.RootInode & 0xFFFF, 0, rootNodeIndex));
1526
+
1527
+ /*
1528
+ if (_h.Major < 4)
1529
+ {
1530
+ RINOK(ReadUids(_h.UidTable, _h.NumUids, _uids));
1531
+ RINOK(ReadUids(_h.GidTable, _h.NumGids, _gids));
1532
+ }
1533
+ else
1534
+ {
1535
+ UInt32 size = _h.NumIDs * 4;
1536
+ _uids.SetCapacity(size);
1537
+
1538
+ UInt32 numBlocks = (size + kMetadataBlockSize - 1) / kMetadataBlockSize;
1539
+ UInt32 numBlocksBytes = numBlocks << 3;
1540
+ CByteBuffer data;
1541
+ data.SetCapacity(numBlocksBytes);
1542
+ RINOK(inStream->Seek(_h.UidTable, STREAM_SEEK_SET, NULL));
1543
+ RINOK(ReadStream_FALSE(inStream, data, numBlocksBytes));
1544
+
1545
+ for (UInt32 i = 0; i < numBlocks; i++)
1546
+ {
1547
+ UInt64 offset = GetUi64(data + i * 8);
1548
+ UInt32 unpackSize, packSize;
1549
+ RINOK(_stream->Seek(offset, STREAM_SEEK_SET, NULL));
1550
+ RINOK(ReadMetadataBlock(NULL, _uids + kMetadataBlockSize * i, packSize, unpackSize));
1551
+ if (unpackSize != kMetadataBlockSize)
1552
+ if (i != numBlocks - 1 || unpackSize != (size & (kMetadataBlockSize - 1)))
1553
+ return S_FALSE;
1554
+ }
1555
+ }
1556
+ */
1557
+
1558
+ {
1559
+ const UInt32 alignSize = 1 << 12;
1560
+ Byte buf[alignSize];
1561
+ RINOK(inStream->Seek(_h.Size, STREAM_SEEK_SET, NULL));
1562
+ UInt32 rem = (UInt32)(0 - _h.Size) & (alignSize - 1);
1563
+ _sizeCalculated = _h.Size;
1564
+ if (rem != 0)
1565
+ {
1566
+ if (ReadStream_FALSE(_stream, buf, rem) == S_OK)
1567
+ {
1568
+ size_t i;
1569
+ for (i = 0; i < rem && buf[i] == 0; i++);
1570
+ if (i == rem)
1571
+ _sizeCalculated = _h.Size + rem;
1572
+ }
1573
+ }
1574
+ }
1575
+ return S_OK;
1576
+ }
1577
+
1578
+ AString CHandler::GetPath(int index) const
1579
+ {
1580
+ unsigned len = 0;
1581
+ int indexMem = index;
1582
+ bool be = _h.be;
1583
+ do
1584
+ {
1585
+ const CItem &item = _items[index];
1586
+ index = item.Parent;
1587
+ const Byte *p = _dirs.Data + item.Ptr;
1588
+ unsigned size = (_h.IsOldVersion() ? (unsigned)p[2] : (unsigned)Get16(p + 6)) + 1;
1589
+ p += _h.GetFileNameOffset();
1590
+ unsigned i;
1591
+ for (i = 0; i < size && p[i]; i++);
1592
+ len += i + 1;
1593
+ }
1594
+ while (index >= 0);
1595
+ len--;
1596
+
1597
+ AString path;
1598
+ char *dest = path.GetBuffer(len) + len;
1599
+ index = indexMem;
1600
+ for (;;)
1601
+ {
1602
+ const CItem &item = _items[index];
1603
+ index = item.Parent;
1604
+
1605
+ const Byte *p = _dirs.Data + item.Ptr;
1606
+ unsigned size = (_h.IsOldVersion() ? (unsigned)p[2] : (unsigned)Get16(p + 6)) + 1;
1607
+ p += _h.GetFileNameOffset();
1608
+ unsigned i;
1609
+ for (i = 0; i < size && p[i]; i++);
1610
+ dest -= i;
1611
+ memcpy(dest, p, i);
1612
+ if (index < 0)
1613
+ break;
1614
+ *(--dest) = CHAR_PATH_SEPARATOR;
1615
+ }
1616
+ path.ReleaseBuffer(len);
1617
+ return path;
1618
+ }
1619
+
1620
+ STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *callback)
1621
+ {
1622
+ COM_TRY_BEGIN
1623
+ {
1624
+ Close();
1625
+ _limitedInStreamSpec->SetStream(stream);
1626
+ HRESULT res;
1627
+ try
1628
+ {
1629
+ RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
1630
+ _openCallback = callback;
1631
+ res = Open2(stream);
1632
+ }
1633
+ catch(...)
1634
+ {
1635
+ Close();
1636
+ throw;
1637
+ }
1638
+ if (res != S_OK)
1639
+ {
1640
+ Close();
1641
+ return res;
1642
+ }
1643
+ _stream = stream;
1644
+ }
1645
+ return S_OK;
1646
+ COM_TRY_END
1647
+ }
1648
+
1649
+ STDMETHODIMP CHandler::Close()
1650
+ {
1651
+ _limitedInStreamSpec->ReleaseStream();
1652
+ _stream.Release();
1653
+
1654
+ _items.Clear();
1655
+ _nodes.Clear();
1656
+ _nodesPos.Clear();
1657
+ _blockToNode.Clear();
1658
+ _frags.Clear();
1659
+ _inodesData.Clear();
1660
+ _dirs.Clear();
1661
+
1662
+ // _uids.Free();
1663
+ // _gids.Free();;
1664
+
1665
+ _cachedBlock.Free();
1666
+ ClearCache();
1667
+
1668
+ return S_OK;
1669
+ }
1670
+
1671
+ bool CHandler::GetPackSize(int index, UInt64 &totalPack, bool fillOffsets)
1672
+ {
1673
+ totalPack = 0;
1674
+ const CItem &item = _items[index];
1675
+ const CNode &node = _nodes[item.Node];
1676
+ UInt32 ptr = _nodesPos[item.Node];
1677
+ const Byte *p = _inodesData.Data + ptr;
1678
+ bool be = _h.be;
1679
+
1680
+ UInt32 type = node.Type;
1681
+ UInt32 offset;
1682
+ if (node.IsLink() || node.FileSize == 0)
1683
+ {
1684
+ totalPack = node.FileSize;
1685
+ return true;
1686
+ }
1687
+
1688
+ UInt32 numBlocks = (UInt32)node.GetNumBlocks(_h);
1689
+
1690
+ if (fillOffsets)
1691
+ {
1692
+ _blockOffsets.Clear();
1693
+ _blockCompressed.Clear();
1694
+ _blockOffsets.Add(totalPack);
1695
+ }
1696
+
1697
+ if (_h.Major <= 1)
1698
+ {
1699
+ offset = 15;
1700
+ p += offset;
1701
+
1702
+ for (UInt32 i = 0; i < numBlocks; i++)
1703
+ {
1704
+ UInt32 t = Get16(p + i * 2);
1705
+ if (fillOffsets)
1706
+ _blockCompressed.Add((t & kNotCompressedBit16) == 0);
1707
+ if (t != kNotCompressedBit16)
1708
+ t &= ~kNotCompressedBit16;
1709
+ totalPack += t;
1710
+ if (fillOffsets)
1711
+ _blockOffsets.Add(totalPack);
1712
+ }
1713
+ }
1714
+ else
1715
+ {
1716
+ if (_h.Major <= 2)
1717
+ offset = 24;
1718
+ else if (type == kType_FILE)
1719
+ offset = 32;
1720
+ else if (type == kType_FILE + 7)
1721
+ offset = (_h.Major <= 3 ? 40 : 56);
1722
+ else
1723
+ return false;
1724
+
1725
+ p += offset;
1726
+
1727
+ for (UInt64 i = 0; i < numBlocks; i++)
1728
+ {
1729
+ UInt32 t = Get32(p + i * 4);
1730
+ if (fillOffsets)
1731
+ _blockCompressed.Add(IS_COMPRESSED_BLOCK(t));
1732
+ UInt32 size = GET_COMPRESSED_BLOCK_SIZE(t);
1733
+ if (size > _h.BlockSize)
1734
+ return false;
1735
+ totalPack += size;
1736
+ if (fillOffsets)
1737
+ _blockOffsets.Add(totalPack);
1738
+ }
1739
+
1740
+ if (node.ThereAreFrags())
1741
+ {
1742
+ if (node.Frag >= (UInt32)_frags.Size())
1743
+ return false;
1744
+ const CFrag &frag = _frags[node.Frag];
1745
+ if (node.Offset == 0)
1746
+ {
1747
+ UInt32 size = GET_COMPRESSED_BLOCK_SIZE(frag.Size);
1748
+ if (size > _h.BlockSize)
1749
+ return false;
1750
+ totalPack += size;
1751
+ }
1752
+ }
1753
+ }
1754
+ return true;
1755
+ }
1756
+
1757
+
1758
+ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
1759
+ {
1760
+ *numItems = _items.Size();
1761
+ return S_OK;
1762
+ }
1763
+
1764
+ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
1765
+ {
1766
+ COM_TRY_BEGIN
1767
+ NWindows::NCOM::CPropVariant prop;
1768
+ switch(propID)
1769
+ {
1770
+ case kpidMethod:
1771
+ {
1772
+ const char *s;
1773
+ if (_h.SeveralMethods)
1774
+ s = "LZMA ZLIB";
1775
+ else
1776
+ {
1777
+ s = k_Methods[0];
1778
+ if (_h.Method < sizeof(k_Methods) / sizeof(k_Methods[0]))
1779
+ s = k_Methods[_h.Method];
1780
+ }
1781
+ prop = s;
1782
+ break;
1783
+ }
1784
+ case kpidFileSystem:
1785
+ {
1786
+ AString res = "SquashFS";
1787
+ if (_h.SeveralMethods)
1788
+ res += "-LZMA";
1789
+ res += ' ';
1790
+ char s[16];
1791
+ ConvertUInt32ToString(_h.Major, s);
1792
+ res += s;
1793
+ res += '.';
1794
+ ConvertUInt32ToString(_h.Minor, s);
1795
+ res += s;
1796
+ prop = res;
1797
+ break;
1798
+ }
1799
+ case kpidBlock: prop = _h.BlockSize; break;
1800
+ case kpidBigEndian: prop = _h.be; break;
1801
+ case kpidCTime:
1802
+ if (_h.CTime != 0)
1803
+ {
1804
+ FILETIME ft;
1805
+ NWindows::NTime::UnixTimeToFileTime(_h.CTime, ft);
1806
+ prop = ft;
1807
+ }
1808
+ break;
1809
+ case kpidCharacts: FLAGS_TO_PROP(k_Flags, _h.Flags, prop); break;
1810
+ // case kpidNumBlocks: prop = _h.NumFrags; break;
1811
+ case kpidPhySize: prop = _sizeCalculated; break;
1812
+ case kpidHeadersSize:
1813
+ if (_sizeCalculated >= _h.InodeTable)
1814
+ prop = _sizeCalculated - _h.InodeTable;
1815
+ break;
1816
+ }
1817
+ prop.Detach(value);
1818
+ return S_OK;
1819
+ COM_TRY_END
1820
+ }
1821
+
1822
+ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
1823
+ {
1824
+ COM_TRY_BEGIN
1825
+ NWindows::NCOM::CPropVariant prop;
1826
+ const CItem &item = _items[index];
1827
+ const CNode &node = _nodes[item.Node];
1828
+ bool isDir = node.IsDir();
1829
+ bool be = _h.be;
1830
+
1831
+ switch(propID)
1832
+ {
1833
+ case kpidPath: prop = MultiByteToUnicodeString(GetPath(index), CP_OEMCP); break;
1834
+ case kpidIsDir: prop = isDir; break;
1835
+ // case kpidOffset: if (!node.IsLink()) prop = (UInt64)node.StartBlock; break;
1836
+ case kpidSize: if (!isDir) prop = node.GetSize(); break;
1837
+ case kpidPackSize:
1838
+ if (!isDir)
1839
+ {
1840
+ UInt64 size;
1841
+ if (GetPackSize(index, size, false))
1842
+ prop = size;
1843
+ }
1844
+ break;
1845
+ case kpidMTime:
1846
+ {
1847
+ UInt32 offset = 0;
1848
+ switch(_h.Major)
1849
+ {
1850
+ case 1:
1851
+ if (node.Type == kType_FILE)
1852
+ offset = 3;
1853
+ else if (node.Type == kType_DIR)
1854
+ offset = 7;
1855
+ break;
1856
+ case 2:
1857
+ if (node.Type == kType_FILE)
1858
+ offset = 4;
1859
+ else if (node.Type == kType_DIR)
1860
+ offset = 8;
1861
+ else if (node.Type == kType_DIR + 7)
1862
+ offset = 9;
1863
+ break;
1864
+ case 3: offset = 4; break;
1865
+ case 4: offset = 8; break;
1866
+ }
1867
+ if (offset != 0)
1868
+ {
1869
+ const Byte *p = _inodesData.Data + _nodesPos[item.Node] + offset;
1870
+ FILETIME ft;
1871
+ NWindows::NTime::UnixTimeToFileTime(Get32(p), ft);
1872
+ prop = ft;
1873
+ }
1874
+ break;
1875
+ }
1876
+ case kpidPosixAttrib:
1877
+ {
1878
+ if (node.Type != 0 && node.Type < sizeof(k_TypeToMode) / sizeof(k_TypeToMode[0]))
1879
+ prop = (UInt32)(node.Mode & 0xFFF) | k_TypeToMode[node.Type];
1880
+ break;
1881
+ }
1882
+ /*
1883
+ case kpidUser:
1884
+ {
1885
+ UInt32 offset = node.Uid * 4;
1886
+ if (offset < _uids.GetCapacity())
1887
+ prop = (UInt32)Get32(_uids + offset);
1888
+ break;
1889
+ }
1890
+ case kpidGroup:
1891
+ {
1892
+ if (_h.Major == 4 || node.Gid == _h.GetSpecGuidIndex())
1893
+ {
1894
+ UInt32 offset = node.Uid * 4;
1895
+ if (offset < _uids.GetCapacity())
1896
+ prop = (UInt32)Get32(_uids + offset);
1897
+ }
1898
+ else
1899
+ {
1900
+ UInt32 offset = node.Gid * 4;
1901
+ if (offset < _gids.GetCapacity())
1902
+ prop = (UInt32)Get32(_gids + offset);
1903
+ }
1904
+ break;
1905
+ }
1906
+ */
1907
+ /*
1908
+ case kpidLinks:
1909
+ if (_h.Major >= 3 && node.Type != kType_FILE)
1910
+ prop = node.NumLinks;
1911
+ break;
1912
+ */
1913
+ }
1914
+ prop.Detach(value);
1915
+ return S_OK;
1916
+ COM_TRY_END
1917
+ }
1918
+
1919
+ class CSquashfsInStream: public CCachedInStream
1920
+ {
1921
+ HRESULT ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize);
1922
+ public:
1923
+ CHandler *Handler;
1924
+ };
1925
+
1926
+ HRESULT CSquashfsInStream::ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize)
1927
+ {
1928
+ return Handler->ReadBlock(blockIndex, dest, blockSize);
1929
+ }
1930
+
1931
+ HRESULT CHandler::ReadBlock(UInt64 blockIndex, Byte *dest, size_t blockSize)
1932
+ {
1933
+ const CNode &node = _nodes[_nodeIndex];
1934
+ UInt64 blockOffset;
1935
+ UInt32 packBlockSize;
1936
+ UInt32 offsetInBlock = 0;
1937
+ bool compressed;
1938
+ if (blockIndex < _blockCompressed.Size())
1939
+ {
1940
+ compressed = _blockCompressed[(int)blockIndex];
1941
+ blockOffset = _blockOffsets[(int)blockIndex];
1942
+ packBlockSize = (UInt32)(_blockOffsets[(int)blockIndex + 1] - blockOffset);
1943
+ blockOffset += node.StartBlock;
1944
+ }
1945
+ else
1946
+ {
1947
+ if (!node.ThereAreFrags())
1948
+ return S_FALSE;
1949
+ const CFrag &frag = _frags[node.Frag];
1950
+ offsetInBlock = node.Offset;
1951
+ blockOffset = frag.StartBlock;
1952
+ packBlockSize = GET_COMPRESSED_BLOCK_SIZE(frag.Size);
1953
+ compressed = IS_COMPRESSED_BLOCK(frag.Size);
1954
+ }
1955
+
1956
+ if (packBlockSize == 0)
1957
+ {
1958
+ // sparse file ???
1959
+ memset(dest, 0, blockSize);
1960
+ return S_OK;
1961
+ }
1962
+
1963
+ if (blockOffset != _cachedBlockStartPos ||
1964
+ packBlockSize != _cachedPackBlockSize)
1965
+ {
1966
+ ClearCache();
1967
+ RINOK(_stream->Seek(blockOffset, STREAM_SEEK_SET, NULL));
1968
+ _limitedInStreamSpec->Init(packBlockSize);
1969
+
1970
+ if (compressed)
1971
+ {
1972
+ _outStreamSpec->Init((Byte *)_cachedBlock, _h.BlockSize);
1973
+ bool outBufWasWritten;
1974
+ UInt32 outBufWasWrittenSize;
1975
+ HRESULT res = Decompress(_outStream, _cachedBlock, &outBufWasWritten, &outBufWasWrittenSize, packBlockSize, _h.BlockSize);
1976
+ if (outBufWasWritten)
1977
+ _cachedUnpackBlockSize = outBufWasWrittenSize;
1978
+ else
1979
+ _cachedUnpackBlockSize = (UInt32)_outStreamSpec->GetPos();
1980
+ RINOK(res);
1981
+ }
1982
+ else
1983
+ {
1984
+ RINOK(ReadStream_FALSE(_limitedInStream, _cachedBlock, packBlockSize));
1985
+ _cachedUnpackBlockSize = packBlockSize;
1986
+ }
1987
+ _cachedBlockStartPos = blockOffset;
1988
+ _cachedPackBlockSize = packBlockSize;
1989
+ }
1990
+ if (offsetInBlock + blockSize > _cachedUnpackBlockSize)
1991
+ return S_FALSE;
1992
+ memcpy(dest, _cachedBlock + offsetInBlock, blockSize);
1993
+ return S_OK;
1994
+ }
1995
+
1996
+ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1997
+ Int32 testMode, IArchiveExtractCallback *extractCallback)
1998
+ {
1999
+ COM_TRY_BEGIN
2000
+ bool allFilesMode = (numItems == (UInt32)-1);
2001
+ if (allFilesMode)
2002
+ numItems = _items.Size();
2003
+ if (numItems == 0)
2004
+ return S_OK;
2005
+ UInt64 totalSize = 0;
2006
+ UInt32 i;
2007
+ for (i = 0; i < numItems; i++)
2008
+ {
2009
+ const CItem &item = _items[allFilesMode ? i : indices[i]];
2010
+ const CNode &node = _nodes[item.Node];
2011
+ totalSize += node.GetSize();
2012
+ }
2013
+ extractCallback->SetTotal(totalSize);
2014
+
2015
+ UInt64 totalPackSize;
2016
+ totalSize = totalPackSize = 0;
2017
+
2018
+ NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
2019
+ CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
2020
+
2021
+ CLocalProgress *lps = new CLocalProgress;
2022
+ CMyComPtr<ICompressProgressInfo> progress = lps;
2023
+ lps->Init(extractCallback, false);
2024
+
2025
+ for (i = 0; i < numItems; i++)
2026
+ {
2027
+ lps->InSize = totalPackSize;
2028
+ lps->OutSize = totalSize;
2029
+ RINOK(lps->SetCur());
2030
+ CMyComPtr<ISequentialOutStream> outStream;
2031
+ Int32 askMode = testMode ?
2032
+ NExtract::NAskMode::kTest :
2033
+ NExtract::NAskMode::kExtract;
2034
+ UInt32 index = allFilesMode ? i : indices[i];
2035
+ const CItem &item = _items[index];
2036
+ const CNode &node = _nodes[item.Node];
2037
+ RINOK(extractCallback->GetStream(index, &outStream, askMode));
2038
+ // const Byte *p = _data + item.Offset;
2039
+
2040
+ if (node.IsDir())
2041
+ {
2042
+ RINOK(extractCallback->PrepareOperation(askMode));
2043
+ RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
2044
+ continue;
2045
+ }
2046
+ UInt64 unpackSize = node.GetSize();
2047
+ totalSize += unpackSize;
2048
+ UInt64 packSize;
2049
+ if (GetPackSize(index, packSize, false))
2050
+ totalPackSize += packSize;
2051
+
2052
+ if (!testMode && !outStream)
2053
+ continue;
2054
+ RINOK(extractCallback->PrepareOperation(askMode));
2055
+
2056
+ int res = NExtract::NOperationResult::kDataError;
2057
+ {
2058
+ CMyComPtr<ISequentialInStream> inSeqStream;
2059
+ CMyComPtr<IInStream> inStream;
2060
+ HRESULT hres = GetStream(index, &inSeqStream);
2061
+ if (inSeqStream)
2062
+ inSeqStream.QueryInterface(IID_IInStream, &inStream);
2063
+ if (hres == S_FALSE || !inStream)
2064
+ {
2065
+ if (hres == E_OUTOFMEMORY)
2066
+ return hres;
2067
+ res = NExtract::NOperationResult::kUnSupportedMethod;
2068
+ }
2069
+ else
2070
+ {
2071
+ RINOK(hres);
2072
+ if (inStream)
2073
+ {
2074
+ HRESULT hres = copyCoder->Code(inStream, outStream, NULL, NULL, progress);
2075
+ if (hres != S_OK && hres != S_FALSE)
2076
+ {
2077
+ RINOK(hres);
2078
+ }
2079
+ if (copyCoderSpec->TotalSize == unpackSize && hres == S_OK)
2080
+ res = NExtract::NOperationResult::kOK;
2081
+ else
2082
+ {
2083
+ res = res;
2084
+ }
2085
+ }
2086
+ }
2087
+ }
2088
+ RINOK(extractCallback->SetOperationResult(res));
2089
+ }
2090
+ return S_OK;
2091
+ COM_TRY_END
2092
+ }
2093
+
2094
+
2095
+ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
2096
+ {
2097
+ COM_TRY_BEGIN
2098
+
2099
+ const CItem &item = _items[index];
2100
+ const CNode &node = _nodes[item.Node];
2101
+
2102
+ if (node.IsDir())
2103
+ return E_FAIL;
2104
+
2105
+ const Byte *p = _inodesData.Data + _nodesPos[item.Node];
2106
+
2107
+ if (node.FileSize == 0 || node.IsLink())
2108
+ {
2109
+ CBufInStream *streamSpec = new CBufInStream;
2110
+ CMyComPtr<IInStream> streamTemp = streamSpec;
2111
+ if (node.IsLink())
2112
+ streamSpec->Init(p + _h.GetSymLinkOffset(), (size_t)node.FileSize);
2113
+ else
2114
+ streamSpec->Init(NULL, 0);
2115
+ *stream = streamTemp.Detach();
2116
+ return S_OK;
2117
+ }
2118
+
2119
+ UInt64 packSize;
2120
+ if (!GetPackSize(index, packSize, true))
2121
+ return S_FALSE;
2122
+
2123
+ _nodeIndex = item.Node;
2124
+
2125
+ size_t cacheSize = _h.BlockSize;
2126
+ if (_cachedBlock.GetCapacity() != cacheSize)
2127
+ {
2128
+ ClearCache();
2129
+ _cachedBlock.SetCapacity(cacheSize);
2130
+ }
2131
+
2132
+ CSquashfsInStream *streamSpec = new CSquashfsInStream;
2133
+ CMyComPtr<IInStream> streamTemp = streamSpec;
2134
+ streamSpec->Handler = this;
2135
+ unsigned cacheSizeLog = 22;
2136
+ if (cacheSizeLog <= _h.BlockSizeLog)
2137
+ cacheSizeLog = _h.BlockSizeLog + 1;
2138
+ if (!streamSpec->Alloc(_h.BlockSizeLog, cacheSizeLog - _h.BlockSizeLog))
2139
+ return E_OUTOFMEMORY;
2140
+ streamSpec->Init(node.FileSize);
2141
+ *stream = streamTemp.Detach();
2142
+
2143
+ return S_OK;
2144
+
2145
+ COM_TRY_END
2146
+ }
2147
+
2148
+ static IInArchive *CreateArc() { return new NArchive::NSquashfs::CHandler; }
2149
+
2150
+ static CArcInfo g_ArcInfo =
2151
+ { L"SquashFS", L"squashfs", 0, 0xD2, SIGNATURE, kSignatureSize, false, CreateArc, 0 };
2152
+
2153
+ REGISTER_ARC(Cramfs)
2154
+
2155
+ }}