seven-zip 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (739) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +31 -0
  3. data/.github/workflows/release.yml +30 -0
  4. data/.gitignore +27 -0
  5. data/.travis.yml +35 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +204 -0
  9. data/Rakefile +79 -0
  10. data/ext/C/Types.h +254 -0
  11. data/ext/CPP/7zip/Archive/IArchive.h +234 -0
  12. data/ext/CPP/7zip/IDecl.h +15 -0
  13. data/ext/CPP/7zip/IPassword.h +24 -0
  14. data/ext/CPP/7zip/IProgress.h +33 -0
  15. data/ext/CPP/7zip/IStream.h +58 -0
  16. data/ext/CPP/7zip/PropID.h +76 -0
  17. data/ext/CPP/Common/MyCom.h +225 -0
  18. data/ext/CPP/Common/MyGuidDef.h +54 -0
  19. data/ext/CPP/Common/MyInitGuid.h +22 -0
  20. data/ext/CPP/Common/MyUnknown.h +13 -0
  21. data/ext/CPP/Common/MyWindows.h +204 -0
  22. data/ext/CPP/Common/Types.h +11 -0
  23. data/ext/CPP/Windows/PropVariant.h +56 -0
  24. data/ext/CPP/include_windows/basetyps.h +19 -0
  25. data/ext/CPP/include_windows/tchar.h +89 -0
  26. data/ext/CPP/include_windows/windows.h +194 -0
  27. data/ext/p7zip/Asm/x64/7zCrcT8U.asm +103 -0
  28. data/ext/p7zip/Asm/x86/7zCrcT8U.asm +101 -0
  29. data/ext/p7zip/C/7zBuf.h +39 -0
  30. data/ext/p7zip/C/7zBuf2.c +45 -0
  31. data/ext/p7zip/C/7zCrc.c +76 -0
  32. data/ext/p7zip/C/7zCrc.h +25 -0
  33. data/ext/p7zip/C/7zCrcOpt.c +34 -0
  34. data/ext/p7zip/C/7zCrcT8.c +43 -0
  35. data/ext/p7zip/C/7zStream.c +169 -0
  36. data/ext/p7zip/C/7zVersion.h +7 -0
  37. data/ext/p7zip/C/Aes.c +284 -0
  38. data/ext/p7zip/C/Aes.h +38 -0
  39. data/ext/p7zip/C/Alloc.back3 +238 -0
  40. data/ext/p7zip/C/Alloc.c +280 -0
  41. data/ext/p7zip/C/Alloc.c.back +243 -0
  42. data/ext/p7zip/C/Alloc.c.back2 +222 -0
  43. data/ext/p7zip/C/Alloc.h +27 -0
  44. data/ext/p7zip/C/Bra.c +133 -0
  45. data/ext/p7zip/C/Bra.h +68 -0
  46. data/ext/p7zip/C/Bra86.c +85 -0
  47. data/ext/p7zip/C/BraIA64.c +67 -0
  48. data/ext/p7zip/C/BwtSort.c +516 -0
  49. data/ext/p7zip/C/BwtSort.h +30 -0
  50. data/ext/p7zip/C/CpuArch.c +168 -0
  51. data/ext/p7zip/C/CpuArch.h +155 -0
  52. data/ext/p7zip/C/Delta.c +62 -0
  53. data/ext/p7zip/C/Delta.h +23 -0
  54. data/ext/p7zip/C/HuffEnc.c +146 -0
  55. data/ext/p7zip/C/HuffEnc.h +27 -0
  56. data/ext/p7zip/C/LzFind.c +761 -0
  57. data/ext/p7zip/C/LzFind.h +115 -0
  58. data/ext/p7zip/C/LzFindMt.c +793 -0
  59. data/ext/p7zip/C/LzFindMt.h +105 -0
  60. data/ext/p7zip/C/LzHash.h +54 -0
  61. data/ext/p7zip/C/Lzma2Dec.c +356 -0
  62. data/ext/p7zip/C/Lzma2Dec.h +84 -0
  63. data/ext/p7zip/C/Lzma2Enc.c +477 -0
  64. data/ext/p7zip/C/Lzma2Enc.h +66 -0
  65. data/ext/p7zip/C/LzmaDec.c +999 -0
  66. data/ext/p7zip/C/LzmaDec.h +231 -0
  67. data/ext/p7zip/C/LzmaEnc.c +2268 -0
  68. data/ext/p7zip/C/LzmaEnc.h +80 -0
  69. data/ext/p7zip/C/LzmaUtil/Lzma86Dec.c +61 -0
  70. data/ext/p7zip/C/LzmaUtil/Lzma86Dec.h +51 -0
  71. data/ext/p7zip/C/LzmaUtil/Lzma86Enc.c +113 -0
  72. data/ext/p7zip/C/LzmaUtil/Lzma86Enc.h +78 -0
  73. data/ext/p7zip/C/MtCoder.c +327 -0
  74. data/ext/p7zip/C/MtCoder.h +98 -0
  75. data/ext/p7zip/C/Ppmd.h +85 -0
  76. data/ext/p7zip/C/Ppmd7.c +708 -0
  77. data/ext/p7zip/C/Ppmd7.h +140 -0
  78. data/ext/p7zip/C/Ppmd7Dec.c +187 -0
  79. data/ext/p7zip/C/Ppmd7Enc.c +185 -0
  80. data/ext/p7zip/C/Ppmd8.c +1120 -0
  81. data/ext/p7zip/C/Ppmd8.h +133 -0
  82. data/ext/p7zip/C/Ppmd8Dec.c +155 -0
  83. data/ext/p7zip/C/Ppmd8Enc.c +161 -0
  84. data/ext/p7zip/C/RotateDefs.h +20 -0
  85. data/ext/p7zip/C/Sha256.c +204 -0
  86. data/ext/p7zip/C/Sha256.h +26 -0
  87. data/ext/p7zip/C/Sort.c +93 -0
  88. data/ext/p7zip/C/Sort.h +20 -0
  89. data/ext/p7zip/C/Threads.c +582 -0
  90. data/ext/p7zip/C/Threads.h +123 -0
  91. data/ext/p7zip/C/Types.h +254 -0
  92. data/ext/p7zip/C/Xz.c +88 -0
  93. data/ext/p7zip/C/Xz.h +252 -0
  94. data/ext/p7zip/C/XzCrc64.c +33 -0
  95. data/ext/p7zip/C/XzCrc64.h +26 -0
  96. data/ext/p7zip/C/XzDec.c +875 -0
  97. data/ext/p7zip/C/XzEnc.c +497 -0
  98. data/ext/p7zip/C/XzEnc.h +25 -0
  99. data/ext/p7zip/C/XzIn.c +306 -0
  100. data/ext/p7zip/CPP/7zip/Archive/7z/7zCompressionMode.cpp +3 -0
  101. data/ext/p7zip/CPP/7zip/Archive/7z/7zCompressionMode.h +50 -0
  102. data/ext/p7zip/CPP/7zip/Archive/7z/7zDecode.cpp +332 -0
  103. data/ext/p7zip/CPP/7zip/Archive/7z/7zDecode.h +68 -0
  104. data/ext/p7zip/CPP/7zip/Archive/7z/7zEncode.cpp +444 -0
  105. data/ext/p7zip/CPP/7zip/Archive/7z/7zEncode.h +55 -0
  106. data/ext/p7zip/CPP/7zip/Archive/7z/7zExtract.cpp +270 -0
  107. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderInStream.cpp +123 -0
  108. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderInStream.h +58 -0
  109. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderOutStream.cpp +149 -0
  110. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderOutStream.h +58 -0
  111. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandler.cpp +482 -0
  112. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandler.h +119 -0
  113. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandlerOut.cpp +483 -0
  114. data/ext/p7zip/CPP/7zip/Archive/7z/7zHeader.cpp +14 -0
  115. data/ext/p7zip/CPP/7zip/Archive/7z/7zHeader.h +97 -0
  116. data/ext/p7zip/CPP/7zip/Archive/7z/7zIn.cpp +1276 -0
  117. data/ext/p7zip/CPP/7zip/Archive/7z/7zIn.h +245 -0
  118. data/ext/p7zip/CPP/7zip/Archive/7z/7zItem.h +268 -0
  119. data/ext/p7zip/CPP/7zip/Archive/7z/7zOut.cpp +866 -0
  120. data/ext/p7zip/CPP/7zip/Archive/7z/7zOut.h +152 -0
  121. data/ext/p7zip/CPP/7zip/Archive/7z/7zProperties.cpp +164 -0
  122. data/ext/p7zip/CPP/7zip/Archive/7z/7zProperties.h +22 -0
  123. data/ext/p7zip/CPP/7zip/Archive/7z/7zRegister.cpp +18 -0
  124. data/ext/p7zip/CPP/7zip/Archive/7z/7zSpecStream.cpp +24 -0
  125. data/ext/p7zip/CPP/7zip/Archive/7z/7zSpecStream.h +35 -0
  126. data/ext/p7zip/CPP/7zip/Archive/7z/7zUpdate.cpp +1216 -0
  127. data/ext/p7zip/CPP/7zip/Archive/7z/7zUpdate.h +88 -0
  128. data/ext/p7zip/CPP/7zip/Archive/ApmHandler.cpp +356 -0
  129. data/ext/p7zip/CPP/7zip/Archive/ArchiveExports.cpp +135 -0
  130. data/ext/p7zip/CPP/7zip/Archive/ArjHandler.cpp +798 -0
  131. data/ext/p7zip/CPP/7zip/Archive/Bz2Handler.cpp +423 -0
  132. data/ext/p7zip/CPP/7zip/Archive/Cab/CabBlockInStream.cpp +189 -0
  133. data/ext/p7zip/CPP/7zip/Archive/Cab/CabBlockInStream.h +44 -0
  134. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHandler.cpp +929 -0
  135. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHandler.h +28 -0
  136. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHeader.cpp +15 -0
  137. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHeader.h +44 -0
  138. data/ext/p7zip/CPP/7zip/Archive/Cab/CabIn.cpp +272 -0
  139. data/ext/p7zip/CPP/7zip/Archive/Cab/CabIn.h +161 -0
  140. data/ext/p7zip/CPP/7zip/Archive/Cab/CabItem.h +63 -0
  141. data/ext/p7zip/CPP/7zip/Archive/Cab/CabRegister.cpp +13 -0
  142. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHandler.cpp +721 -0
  143. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHandler.h +29 -0
  144. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHeader.cpp +24 -0
  145. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHeader.h +28 -0
  146. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmIn.cpp +937 -0
  147. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmIn.h +244 -0
  148. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmRegister.cpp +13 -0
  149. data/ext/p7zip/CPP/7zip/Archive/Com/ComHandler.cpp +239 -0
  150. data/ext/p7zip/CPP/7zip/Archive/Com/ComHandler.h +28 -0
  151. data/ext/p7zip/CPP/7zip/Archive/Com/ComIn.cpp +389 -0
  152. data/ext/p7zip/CPP/7zip/Archive/Com/ComIn.h +119 -0
  153. data/ext/p7zip/CPP/7zip/Archive/Com/ComRegister.cpp +13 -0
  154. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2.cpp +121 -0
  155. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2.h +174 -0
  156. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2MT.cpp +240 -0
  157. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2MT.h +80 -0
  158. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2ST.cpp +239 -0
  159. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2ST.h +88 -0
  160. data/ext/p7zip/CPP/7zip/Archive/Common/CrossThreadProgress.cpp +15 -0
  161. data/ext/p7zip/CPP/7zip/Archive/Common/CrossThreadProgress.h +37 -0
  162. data/ext/p7zip/CPP/7zip/Archive/Common/DummyOutStream.cpp +22 -0
  163. data/ext/p7zip/CPP/7zip/Archive/Common/DummyOutStream.h +24 -0
  164. data/ext/p7zip/CPP/7zip/Archive/Common/FindSignature.cpp +62 -0
  165. data/ext/p7zip/CPP/7zip/Archive/Common/FindSignature.h +12 -0
  166. data/ext/p7zip/CPP/7zip/Archive/Common/HandlerOut.cpp +623 -0
  167. data/ext/p7zip/CPP/7zip/Archive/Common/HandlerOut.h +87 -0
  168. data/ext/p7zip/CPP/7zip/Archive/Common/InStreamWithCRC.cpp +42 -0
  169. data/ext/p7zip/CPP/7zip/Archive/Common/InStreamWithCRC.h +67 -0
  170. data/ext/p7zip/CPP/7zip/Archive/Common/ItemNameUtils.cpp +61 -0
  171. data/ext/p7zip/CPP/7zip/Archive/Common/ItemNameUtils.h +24 -0
  172. data/ext/p7zip/CPP/7zip/Archive/Common/MultiStream.cpp +190 -0
  173. data/ext/p7zip/CPP/7zip/Archive/Common/MultiStream.h +84 -0
  174. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.cpp +18 -0
  175. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.h +36 -0
  176. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithSha1.cpp +18 -0
  177. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithSha1.h +36 -0
  178. data/ext/p7zip/CPP/7zip/Archive/Common/ParseProperties.cpp +177 -0
  179. data/ext/p7zip/CPP/7zip/Archive/Common/ParseProperties.h +18 -0
  180. data/ext/p7zip/CPP/7zip/Archive/CpioHandler.cpp +624 -0
  181. data/ext/p7zip/CPP/7zip/Archive/CramfsHandler.cpp +644 -0
  182. data/ext/p7zip/CPP/7zip/Archive/DebHandler.cpp +413 -0
  183. data/ext/p7zip/CPP/7zip/Archive/DeflateProps.cpp +118 -0
  184. data/ext/p7zip/CPP/7zip/Archive/DeflateProps.h +35 -0
  185. data/ext/p7zip/CPP/7zip/Archive/DllExports2.cpp +76 -0
  186. data/ext/p7zip/CPP/7zip/Archive/DmgHandler.cpp +918 -0
  187. data/ext/p7zip/CPP/7zip/Archive/ElfHandler.cpp +534 -0
  188. data/ext/p7zip/CPP/7zip/Archive/FatHandler.cpp +996 -0
  189. data/ext/p7zip/CPP/7zip/Archive/FlvHandler.cpp +544 -0
  190. data/ext/p7zip/CPP/7zip/Archive/GzHandler.cpp +698 -0
  191. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsHandler.cpp +243 -0
  192. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsHandler.h +26 -0
  193. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsIn.cpp +480 -0
  194. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsIn.h +154 -0
  195. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsRegister.cpp +13 -0
  196. data/ext/p7zip/CPP/7zip/Archive/IArchive.h +234 -0
  197. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHandler.cpp +326 -0
  198. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHandler.h +30 -0
  199. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHeader.cpp +21 -0
  200. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHeader.h +61 -0
  201. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoIn.cpp +453 -0
  202. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoIn.h +315 -0
  203. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoItem.h +141 -0
  204. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoRegister.cpp +13 -0
  205. data/ext/p7zip/CPP/7zip/Archive/LzhHandler.cpp +775 -0
  206. data/ext/p7zip/CPP/7zip/Archive/LzmaHandler.cpp +430 -0
  207. data/ext/p7zip/CPP/7zip/Archive/MachoHandler.cpp +500 -0
  208. data/ext/p7zip/CPP/7zip/Archive/MbrHandler.cpp +507 -0
  209. data/ext/p7zip/CPP/7zip/Archive/MslzHandler.cpp +257 -0
  210. data/ext/p7zip/CPP/7zip/Archive/MubHandler.cpp +266 -0
  211. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisDecode.cpp +130 -0
  212. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisDecode.h +47 -0
  213. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisHandler.cpp +510 -0
  214. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisHandler.h +43 -0
  215. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisIn.cpp +1461 -0
  216. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisIn.h +181 -0
  217. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisRegister.cpp +13 -0
  218. data/ext/p7zip/CPP/7zip/Archive/NtfsHandler.cpp +1764 -0
  219. data/ext/p7zip/CPP/7zip/Archive/PeHandler.cpp +1752 -0
  220. data/ext/p7zip/CPP/7zip/Archive/PpmdHandler.cpp +456 -0
  221. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHandler.cpp +869 -0
  222. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHandler.h +66 -0
  223. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHeader.cpp +21 -0
  224. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHeader.h +205 -0
  225. data/ext/p7zip/CPP/7zip/Archive/Rar/RarIn.cpp +478 -0
  226. data/ext/p7zip/CPP/7zip/Archive/Rar/RarIn.h +123 -0
  227. data/ext/p7zip/CPP/7zip/Archive/Rar/RarItem.cpp +55 -0
  228. data/ext/p7zip/CPP/7zip/Archive/Rar/RarItem.h +79 -0
  229. data/ext/p7zip/CPP/7zip/Archive/Rar/RarRegister.cpp +13 -0
  230. data/ext/p7zip/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp +78 -0
  231. data/ext/p7zip/CPP/7zip/Archive/Rar/RarVolumeInStream.h +49 -0
  232. data/ext/p7zip/CPP/7zip/Archive/RpmHandler.cpp +292 -0
  233. data/ext/p7zip/CPP/7zip/Archive/SplitHandler.cpp +366 -0
  234. data/ext/p7zip/CPP/7zip/Archive/SquashfsHandler.cpp +2155 -0
  235. data/ext/p7zip/CPP/7zip/Archive/SwfHandler.cpp +706 -0
  236. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandler.cpp +386 -0
  237. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandler.h +61 -0
  238. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandlerOut.cpp +122 -0
  239. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHeader.cpp +25 -0
  240. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHeader.h +108 -0
  241. data/ext/p7zip/CPP/7zip/Archive/Tar/TarIn.cpp +207 -0
  242. data/ext/p7zip/CPP/7zip/Archive/Tar/TarIn.h +17 -0
  243. data/ext/p7zip/CPP/7zip/Archive/Tar/TarItem.h +72 -0
  244. data/ext/p7zip/CPP/7zip/Archive/Tar/TarOut.cpp +187 -0
  245. data/ext/p7zip/CPP/7zip/Archive/Tar/TarOut.h +28 -0
  246. data/ext/p7zip/CPP/7zip/Archive/Tar/TarRegister.cpp +18 -0
  247. data/ext/p7zip/CPP/7zip/Archive/Tar/TarUpdate.cpp +139 -0
  248. data/ext/p7zip/CPP/7zip/Archive/Tar/TarUpdate.h +34 -0
  249. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfHandler.cpp +451 -0
  250. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfHandler.h +37 -0
  251. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfIn.cpp +876 -0
  252. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfIn.h +375 -0
  253. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfRegister.cpp +13 -0
  254. data/ext/p7zip/CPP/7zip/Archive/VhdHandler.cpp +734 -0
  255. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandler.cpp +660 -0
  256. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandler.h +77 -0
  257. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandlerOut.cpp +639 -0
  258. data/ext/p7zip/CPP/7zip/Archive/Wim/WimIn.cpp +855 -0
  259. data/ext/p7zip/CPP/7zip/Archive/Wim/WimIn.h +297 -0
  260. data/ext/p7zip/CPP/7zip/Archive/Wim/WimRegister.cpp +18 -0
  261. data/ext/p7zip/CPP/7zip/Archive/XarHandler.cpp +588 -0
  262. data/ext/p7zip/CPP/7zip/Archive/XzHandler.cpp +707 -0
  263. data/ext/p7zip/CPP/7zip/Archive/ZHandler.cpp +161 -0
  264. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipAddCommon.cpp +379 -0
  265. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipAddCommon.h +56 -0
  266. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipCompressionMode.h +42 -0
  267. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandler.cpp +822 -0
  268. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandler.h +101 -0
  269. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp +537 -0
  270. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHeader.cpp +36 -0
  271. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHeader.h +284 -0
  272. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipIn.cpp +893 -0
  273. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipIn.h +125 -0
  274. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItem.cpp +181 -0
  275. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItem.h +281 -0
  276. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItemEx.h +34 -0
  277. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipOut.cpp +289 -0
  278. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipOut.h +56 -0
  279. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipRegister.cpp +18 -0
  280. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipUpdate.cpp +1076 -0
  281. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipUpdate.h +58 -0
  282. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile +328 -0
  283. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile.depend +4962 -0
  284. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile.list +265 -0
  285. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7zFM.txt +163 -0
  286. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7zG.txt +131 -0
  287. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7za.txt +253 -0
  288. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_ALL.txt +32 -0
  289. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_Format7zFree.txt +290 -0
  290. data/ext/p7zip/CPP/7zip/CMAKE/generate.sh +37 -0
  291. data/ext/p7zip/CPP/7zip/CMAKE/generate_xcode.sh +32 -0
  292. data/ext/p7zip/CPP/7zip/Common/CWrappers.cpp +226 -0
  293. data/ext/p7zip/CPP/7zip/Common/CWrappers.h +109 -0
  294. data/ext/p7zip/CPP/7zip/Common/CreateCoder.cpp +293 -0
  295. data/ext/p7zip/CPP/7zip/Common/CreateCoder.h +98 -0
  296. data/ext/p7zip/CPP/7zip/Common/FilePathAutoRename.cpp +55 -0
  297. data/ext/p7zip/CPP/7zip/Common/FilePathAutoRename.h +10 -0
  298. data/ext/p7zip/CPP/7zip/Common/FileStreams.cpp +273 -0
  299. data/ext/p7zip/CPP/7zip/Common/FileStreams.h +134 -0
  300. data/ext/p7zip/CPP/7zip/Common/FilterCoder.cpp +247 -0
  301. data/ext/p7zip/CPP/7zip/Common/FilterCoder.h +128 -0
  302. data/ext/p7zip/CPP/7zip/Common/InBuffer.cpp +83 -0
  303. data/ext/p7zip/CPP/7zip/Common/InBuffer.h +81 -0
  304. data/ext/p7zip/CPP/7zip/Common/InOutTempBuffer.cpp +122 -0
  305. data/ext/p7zip/CPP/7zip/Common/InOutTempBuffer.h +48 -0
  306. data/ext/p7zip/CPP/7zip/Common/LimitedStreams.cpp +154 -0
  307. data/ext/p7zip/CPP/7zip/Common/LimitedStreams.h +125 -0
  308. data/ext/p7zip/CPP/7zip/Common/LockedStream.cpp +23 -0
  309. data/ext/p7zip/CPP/7zip/Common/LockedStream.h +38 -0
  310. data/ext/p7zip/CPP/7zip/Common/MemBlocks.cpp +183 -0
  311. data/ext/p7zip/CPP/7zip/Common/MemBlocks.h +71 -0
  312. data/ext/p7zip/CPP/7zip/Common/MethodId.cpp +27 -0
  313. data/ext/p7zip/CPP/7zip/Common/MethodId.h +10 -0
  314. data/ext/p7zip/CPP/7zip/Common/MethodProps.cpp +99 -0
  315. data/ext/p7zip/CPP/7zip/Common/MethodProps.h +41 -0
  316. data/ext/p7zip/CPP/7zip/Common/OffsetStream.cpp +35 -0
  317. data/ext/p7zip/CPP/7zip/Common/OffsetStream.h +25 -0
  318. data/ext/p7zip/CPP/7zip/Common/OutBuffer.cpp +116 -0
  319. data/ext/p7zip/CPP/7zip/Common/OutBuffer.h +64 -0
  320. data/ext/p7zip/CPP/7zip/Common/OutMemStream.cpp +142 -0
  321. data/ext/p7zip/CPP/7zip/Common/OutMemStream.h +96 -0
  322. data/ext/p7zip/CPP/7zip/Common/ProgressMt.cpp +53 -0
  323. data/ext/p7zip/CPP/7zip/Common/ProgressMt.h +46 -0
  324. data/ext/p7zip/CPP/7zip/Common/ProgressUtils.cpp +42 -0
  325. data/ext/p7zip/CPP/7zip/Common/ProgressUtils.h +34 -0
  326. data/ext/p7zip/CPP/7zip/Common/RegisterArc.h +32 -0
  327. data/ext/p7zip/CPP/7zip/Common/RegisterCodec.h +33 -0
  328. data/ext/p7zip/CPP/7zip/Common/StreamBinder.cpp +152 -0
  329. data/ext/p7zip/CPP/7zip/Common/StreamBinder.h +38 -0
  330. data/ext/p7zip/CPP/7zip/Common/StreamObjects.cpp +221 -0
  331. data/ext/p7zip/CPP/7zip/Common/StreamObjects.h +135 -0
  332. data/ext/p7zip/CPP/7zip/Common/StreamUtils.cpp +56 -0
  333. data/ext/p7zip/CPP/7zip/Common/StreamUtils.h +13 -0
  334. data/ext/p7zip/CPP/7zip/Common/VirtThread.cpp +46 -0
  335. data/ext/p7zip/CPP/7zip/Common/VirtThread.h +23 -0
  336. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder1.cpp +309 -0
  337. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder1.h +98 -0
  338. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder2.cpp +90 -0
  339. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder2.h +59 -0
  340. data/ext/p7zip/CPP/7zip/Compress/BZip2Const.h +54 -0
  341. data/ext/p7zip/CPP/7zip/Compress/BZip2Crc.cpp +26 -0
  342. data/ext/p7zip/CPP/7zip/Compress/BZip2Crc.h +31 -0
  343. data/ext/p7zip/CPP/7zip/Compress/BZip2Decoder.cpp +943 -0
  344. data/ext/p7zip/CPP/7zip/Compress/BZip2Decoder.h +205 -0
  345. data/ext/p7zip/CPP/7zip/Compress/BZip2Encoder.cpp +895 -0
  346. data/ext/p7zip/CPP/7zip/Compress/BZip2Encoder.h +245 -0
  347. data/ext/p7zip/CPP/7zip/Compress/BZip2Register.cpp +20 -0
  348. data/ext/p7zip/CPP/7zip/Compress/Bcj2Coder.cpp +386 -0
  349. data/ext/p7zip/CPP/7zip/Compress/Bcj2Coder.h +115 -0
  350. data/ext/p7zip/CPP/7zip/Compress/Bcj2Register.cpp +19 -0
  351. data/ext/p7zip/CPP/7zip/Compress/BcjCoder.cpp +15 -0
  352. data/ext/p7zip/CPP/7zip/Compress/BcjCoder.h +19 -0
  353. data/ext/p7zip/CPP/7zip/Compress/BcjRegister.cpp +19 -0
  354. data/ext/p7zip/CPP/7zip/Compress/BitlDecoder.cpp +24 -0
  355. data/ext/p7zip/CPP/7zip/Compress/BitlDecoder.h +141 -0
  356. data/ext/p7zip/CPP/7zip/Compress/BitlEncoder.h +57 -0
  357. data/ext/p7zip/CPP/7zip/Compress/BitmDecoder.h +66 -0
  358. data/ext/p7zip/CPP/7zip/Compress/BitmEncoder.h +50 -0
  359. data/ext/p7zip/CPP/7zip/Compress/BranchCoder.cpp +19 -0
  360. data/ext/p7zip/CPP/7zip/Compress/BranchCoder.h +44 -0
  361. data/ext/p7zip/CPP/7zip/Compress/BranchMisc.cpp +37 -0
  362. data/ext/p7zip/CPP/7zip/Compress/BranchMisc.h +14 -0
  363. data/ext/p7zip/CPP/7zip/Compress/BranchRegister.cpp +30 -0
  364. data/ext/p7zip/CPP/7zip/Compress/ByteSwap.cpp +73 -0
  365. data/ext/p7zip/CPP/7zip/Compress/CodecExports.cpp +160 -0
  366. data/ext/p7zip/CPP/7zip/Compress/CopyCoder.cpp +67 -0
  367. data/ext/p7zip/CPP/7zip/Compress/CopyCoder.h +34 -0
  368. data/ext/p7zip/CPP/7zip/Compress/CopyRegister.cpp +14 -0
  369. data/ext/p7zip/CPP/7zip/Compress/Deflate64Register.cpp +20 -0
  370. data/ext/p7zip/CPP/7zip/Compress/DeflateConst.h +134 -0
  371. data/ext/p7zip/CPP/7zip/Compress/DeflateDecoder.cpp +353 -0
  372. data/ext/p7zip/CPP/7zip/Compress/DeflateDecoder.h +157 -0
  373. data/ext/p7zip/CPP/7zip/Compress/DeflateEncoder.cpp +986 -0
  374. data/ext/p7zip/CPP/7zip/Compress/DeflateEncoder.h +211 -0
  375. data/ext/p7zip/CPP/7zip/Compress/DeflateRegister.cpp +21 -0
  376. data/ext/p7zip/CPP/7zip/Compress/DeltaFilter.cpp +112 -0
  377. data/ext/p7zip/CPP/7zip/Compress/DllExports.cpp +39 -0
  378. data/ext/p7zip/CPP/7zip/Compress/DllExports2.cpp +28 -0
  379. data/ext/p7zip/CPP/7zip/Compress/HuffmanDecoder.h +89 -0
  380. data/ext/p7zip/CPP/7zip/Compress/ImplodeDecoder.cpp +219 -0
  381. data/ext/p7zip/CPP/7zip/Compress/ImplodeDecoder.h +57 -0
  382. data/ext/p7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp +89 -0
  383. data/ext/p7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.h +34 -0
  384. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp +531 -0
  385. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp +1018 -0
  386. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h +48 -0
  387. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp +311 -0
  388. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h +20 -0
  389. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/makefile +173 -0
  390. data/ext/p7zip/CPP/7zip/Compress/LzOutWindow.cpp +14 -0
  391. data/ext/p7zip/CPP/7zip/Compress/LzOutWindow.h +66 -0
  392. data/ext/p7zip/CPP/7zip/Compress/LzhDecoder.cpp +220 -0
  393. data/ext/p7zip/CPP/7zip/Compress/LzhDecoder.h +106 -0
  394. data/ext/p7zip/CPP/7zip/Compress/Lzma2Decoder.cpp +189 -0
  395. data/ext/p7zip/CPP/7zip/Compress/Lzma2Decoder.h +73 -0
  396. data/ext/p7zip/CPP/7zip/Compress/Lzma2Encoder.cpp +94 -0
  397. data/ext/p7zip/CPP/7zip/Compress/Lzma2Encoder.h +36 -0
  398. data/ext/p7zip/CPP/7zip/Compress/Lzma2Register.cpp +20 -0
  399. data/ext/p7zip/CPP/7zip/Compress/LzmaDecoder.cpp +252 -0
  400. data/ext/p7zip/CPP/7zip/Compress/LzmaDecoder.h +84 -0
  401. data/ext/p7zip/CPP/7zip/Compress/LzmaEncoder.cpp +149 -0
  402. data/ext/p7zip/CPP/7zip/Compress/LzmaEncoder.h +36 -0
  403. data/ext/p7zip/CPP/7zip/Compress/LzmaRegister.cpp +20 -0
  404. data/ext/p7zip/CPP/7zip/Compress/Lzx.h +61 -0
  405. data/ext/p7zip/CPP/7zip/Compress/Lzx86Converter.cpp +90 -0
  406. data/ext/p7zip/CPP/7zip/Compress/Lzx86Converter.h +46 -0
  407. data/ext/p7zip/CPP/7zip/Compress/LzxDecoder.cpp +387 -0
  408. data/ext/p7zip/CPP/7zip/Compress/LzxDecoder.h +159 -0
  409. data/ext/p7zip/CPP/7zip/Compress/Mtf8.h +193 -0
  410. data/ext/p7zip/CPP/7zip/Compress/PpmdDecoder.cpp +167 -0
  411. data/ext/p7zip/CPP/7zip/Compress/PpmdDecoder.h +78 -0
  412. data/ext/p7zip/CPP/7zip/Compress/PpmdEncoder.cpp +119 -0
  413. data/ext/p7zip/CPP/7zip/Compress/PpmdEncoder.h +48 -0
  414. data/ext/p7zip/CPP/7zip/Compress/PpmdRegister.cpp +21 -0
  415. data/ext/p7zip/CPP/7zip/Compress/PpmdZip.cpp +223 -0
  416. data/ext/p7zip/CPP/7zip/Compress/PpmdZip.h +72 -0
  417. data/ext/p7zip/CPP/7zip/Compress/QuantumDecoder.cpp +175 -0
  418. data/ext/p7zip/CPP/7zip/Compress/QuantumDecoder.h +264 -0
  419. data/ext/p7zip/CPP/7zip/Compress/RangeCoder.h +205 -0
  420. data/ext/p7zip/CPP/7zip/Compress/RangeCoderBit.h +114 -0
  421. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile +34 -0
  422. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile.depend +158 -0
  423. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile.list +64 -0
  424. data/ext/p7zip/CPP/7zip/Compress/Rar1Decoder.cpp +480 -0
  425. data/ext/p7zip/CPP/7zip/Compress/Rar1Decoder.h +88 -0
  426. data/ext/p7zip/CPP/7zip/Compress/Rar2Decoder.cpp +391 -0
  427. data/ext/p7zip/CPP/7zip/Compress/Rar2Decoder.h +174 -0
  428. data/ext/p7zip/CPP/7zip/Compress/Rar3Decoder.cpp +897 -0
  429. data/ext/p7zip/CPP/7zip/Compress/Rar3Decoder.h +267 -0
  430. data/ext/p7zip/CPP/7zip/Compress/Rar3Vm.cpp +1091 -0
  431. data/ext/p7zip/CPP/7zip/Compress/Rar3Vm.h +179 -0
  432. data/ext/p7zip/CPP/7zip/Compress/RarCodecsRegister.cpp +26 -0
  433. data/ext/p7zip/CPP/7zip/Compress/ShrinkDecoder.cpp +145 -0
  434. data/ext/p7zip/CPP/7zip/Compress/ShrinkDecoder.h +38 -0
  435. data/ext/p7zip/CPP/7zip/Compress/ZDecoder.cpp +159 -0
  436. data/ext/p7zip/CPP/7zip/Compress/ZDecoder.h +42 -0
  437. data/ext/p7zip/CPP/7zip/Compress/ZlibDecoder.cpp +89 -0
  438. data/ext/p7zip/CPP/7zip/Compress/ZlibDecoder.h +48 -0
  439. data/ext/p7zip/CPP/7zip/Compress/ZlibEncoder.cpp +61 -0
  440. data/ext/p7zip/CPP/7zip/Compress/ZlibEncoder.h +48 -0
  441. data/ext/p7zip/CPP/7zip/Crypto/7zAes.cpp +244 -0
  442. data/ext/p7zip/CPP/7zip/Crypto/7zAes.h +117 -0
  443. data/ext/p7zip/CPP/7zip/Crypto/7zAesRegister.cpp +18 -0
  444. data/ext/p7zip/CPP/7zip/Crypto/HmacSha1.cpp +109 -0
  445. data/ext/p7zip/CPP/7zip/Crypto/HmacSha1.h +39 -0
  446. data/ext/p7zip/CPP/7zip/Crypto/MyAes.cpp +48 -0
  447. data/ext/p7zip/CPP/7zip/Crypto/MyAes.h +38 -0
  448. data/ext/p7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp +83 -0
  449. data/ext/p7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.h +21 -0
  450. data/ext/p7zip/CPP/7zip/Crypto/RandGen.cpp +107 -0
  451. data/ext/p7zip/CPP/7zip/Crypto/RandGen.h +21 -0
  452. data/ext/p7zip/CPP/7zip/Crypto/Rar20Crypto.cpp +133 -0
  453. data/ext/p7zip/CPP/7zip/Crypto/Rar20Crypto.h +50 -0
  454. data/ext/p7zip/CPP/7zip/Crypto/RarAes.cpp +134 -0
  455. data/ext/p7zip/CPP/7zip/Crypto/RarAes.h +47 -0
  456. data/ext/p7zip/CPP/7zip/Crypto/Sha1.cpp +229 -0
  457. data/ext/p7zip/CPP/7zip/Crypto/Sha1.h +68 -0
  458. data/ext/p7zip/CPP/7zip/Crypto/WzAes.cpp +221 -0
  459. data/ext/p7zip/CPP/7zip/Crypto/WzAes.h +125 -0
  460. data/ext/p7zip/CPP/7zip/Crypto/ZipCrypto.cpp +88 -0
  461. data/ext/p7zip/CPP/7zip/Crypto/ZipCrypto.h +56 -0
  462. data/ext/p7zip/CPP/7zip/Crypto/ZipStrong.cpp +164 -0
  463. data/ext/p7zip/CPP/7zip/Crypto/ZipStrong.h +47 -0
  464. data/ext/p7zip/CPP/7zip/Guid.txt +170 -0
  465. data/ext/p7zip/CPP/7zip/ICoder.h +186 -0
  466. data/ext/p7zip/CPP/7zip/IDecl.h +15 -0
  467. data/ext/p7zip/CPP/7zip/IPassword.h +24 -0
  468. data/ext/p7zip/CPP/7zip/IProgress.h +33 -0
  469. data/ext/p7zip/CPP/7zip/IStream.h +58 -0
  470. data/ext/p7zip/CPP/7zip/MyVersion.h +11 -0
  471. data/ext/p7zip/CPP/7zip/PREMAKE/generate.sh +18 -0
  472. data/ext/p7zip/CPP/7zip/PREMAKE/premake4.lua +263 -0
  473. data/ext/p7zip/CPP/7zip/PropID.h +76 -0
  474. data/ext/p7zip/CPP/7zip/QMAKE/7ZA/7ZA.pro +228 -0
  475. data/ext/p7zip/CPP/7zip/QMAKE/7ZA/7ZA_osx.pro +228 -0
  476. data/ext/p7zip/CPP/7zip/QMAKE/test_emul/test_emul.pro +26 -0
  477. data/ext/p7zip/CPP/7zip/TEST/TestUI/TestUI.cpp +560 -0
  478. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile +33 -0
  479. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile.depend +577 -0
  480. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile.list +16 -0
  481. data/ext/p7zip/CPP/Common/AutoPtr.h +35 -0
  482. data/ext/p7zip/CPP/Common/Buffer.h +77 -0
  483. data/ext/p7zip/CPP/Common/CRC.cpp +7 -0
  484. data/ext/p7zip/CPP/Common/C_FileIO.cpp +88 -0
  485. data/ext/p7zip/CPP/Common/C_FileIO.h +47 -0
  486. data/ext/p7zip/CPP/Common/ComTry.h +18 -0
  487. data/ext/p7zip/CPP/Common/CommandLineParser.cpp +230 -0
  488. data/ext/p7zip/CPP/Common/CommandLineParser.h +72 -0
  489. data/ext/p7zip/CPP/Common/Defs.h +20 -0
  490. data/ext/p7zip/CPP/Common/DynamicBuffer.h +50 -0
  491. data/ext/p7zip/CPP/Common/IntToString.cpp +77 -0
  492. data/ext/p7zip/CPP/Common/IntToString.h +19 -0
  493. data/ext/p7zip/CPP/Common/Lang.cpp +130 -0
  494. data/ext/p7zip/CPP/Common/Lang.h +28 -0
  495. data/ext/p7zip/CPP/Common/ListFileUtils.cpp +75 -0
  496. data/ext/p7zip/CPP/Common/ListFileUtils.h +11 -0
  497. data/ext/p7zip/CPP/Common/MyCom.h +225 -0
  498. data/ext/p7zip/CPP/Common/MyException.h +14 -0
  499. data/ext/p7zip/CPP/Common/MyGuidDef.h +54 -0
  500. data/ext/p7zip/CPP/Common/MyInitGuid.h +22 -0
  501. data/ext/p7zip/CPP/Common/MyMap.cpp +140 -0
  502. data/ext/p7zip/CPP/Common/MyMap.h +28 -0
  503. data/ext/p7zip/CPP/Common/MyString.cpp +206 -0
  504. data/ext/p7zip/CPP/Common/MyString.h +601 -0
  505. data/ext/p7zip/CPP/Common/MyUnknown.h +13 -0
  506. data/ext/p7zip/CPP/Common/MyVector.cpp +87 -0
  507. data/ext/p7zip/CPP/Common/MyVector.h +266 -0
  508. data/ext/p7zip/CPP/Common/MyWindows.cpp +111 -0
  509. data/ext/p7zip/CPP/Common/MyWindows.h +218 -0
  510. data/ext/p7zip/CPP/Common/MyXml.cpp +209 -0
  511. data/ext/p7zip/CPP/Common/MyXml.h +40 -0
  512. data/ext/p7zip/CPP/Common/NewHandler.h +16 -0
  513. data/ext/p7zip/CPP/Common/StdInStream.cpp +100 -0
  514. data/ext/p7zip/CPP/Common/StdInStream.h +32 -0
  515. data/ext/p7zip/CPP/Common/StdOutStream.cpp +93 -0
  516. data/ext/p7zip/CPP/Common/StdOutStream.h +35 -0
  517. data/ext/p7zip/CPP/Common/StringConvert.cpp +181 -0
  518. data/ext/p7zip/CPP/Common/StringConvert.h +73 -0
  519. data/ext/p7zip/CPP/Common/StringToInt.cpp +90 -0
  520. data/ext/p7zip/CPP/Common/StringToInt.h +18 -0
  521. data/ext/p7zip/CPP/Common/TextConfig.cpp +138 -0
  522. data/ext/p7zip/CPP/Common/TextConfig.h +22 -0
  523. data/ext/p7zip/CPP/Common/Types.h +11 -0
  524. data/ext/p7zip/CPP/Common/UTFConvert.cpp +145 -0
  525. data/ext/p7zip/CPP/Common/UTFConvert.h +11 -0
  526. data/ext/p7zip/CPP/Common/Wildcard.cpp +462 -0
  527. data/ext/p7zip/CPP/Common/Wildcard.h +80 -0
  528. data/ext/p7zip/CPP/Windows/COM.cpp +37 -0
  529. data/ext/p7zip/CPP/Windows/COM.h +69 -0
  530. data/ext/p7zip/CPP/Windows/Clipboard.cpp +160 -0
  531. data/ext/p7zip/CPP/Windows/Clipboard.h +28 -0
  532. data/ext/p7zip/CPP/Windows/CommonDialog.h +19 -0
  533. data/ext/p7zip/CPP/Windows/Control/ComboBox.h +82 -0
  534. data/ext/p7zip/CPP/Windows/Control/Controls.cpp +515 -0
  535. data/ext/p7zip/CPP/Windows/Control/Dialog.cpp +560 -0
  536. data/ext/p7zip/CPP/Windows/Control/Dialog.h +179 -0
  537. data/ext/p7zip/CPP/Windows/Control/DialogImpl.h +73 -0
  538. data/ext/p7zip/CPP/Windows/Control/Edit.h +24 -0
  539. data/ext/p7zip/CPP/Windows/Control/ListView.h +164 -0
  540. data/ext/p7zip/CPP/Windows/Control/ProgressBar.h +34 -0
  541. data/ext/p7zip/CPP/Windows/Control/Static.h +23 -0
  542. data/ext/p7zip/CPP/Windows/Control/StatusBar.h +56 -0
  543. data/ext/p7zip/CPP/Windows/Control/Window2.cpp +211 -0
  544. data/ext/p7zip/CPP/Windows/Control/Window2.h +111 -0
  545. data/ext/p7zip/CPP/Windows/DLL.cpp +193 -0
  546. data/ext/p7zip/CPP/Windows/DLL.h +48 -0
  547. data/ext/p7zip/CPP/Windows/Defs.h +17 -0
  548. data/ext/p7zip/CPP/Windows/Error.cpp +58 -0
  549. data/ext/p7zip/CPP/Windows/Error.h +33 -0
  550. data/ext/p7zip/CPP/Windows/FileDir.cpp +927 -0
  551. data/ext/p7zip/CPP/Windows/FileDir.h +115 -0
  552. data/ext/p7zip/CPP/Windows/FileFind.cpp +604 -0
  553. data/ext/p7zip/CPP/Windows/FileFind.h +126 -0
  554. data/ext/p7zip/CPP/Windows/FileIO.cpp +475 -0
  555. data/ext/p7zip/CPP/Windows/FileIO.h +110 -0
  556. data/ext/p7zip/CPP/Windows/FileName.cpp +50 -0
  557. data/ext/p7zip/CPP/Windows/FileName.h +27 -0
  558. data/ext/p7zip/CPP/Windows/Menu.h +4 -0
  559. data/ext/p7zip/CPP/Windows/NtCheck.h +44 -0
  560. data/ext/p7zip/CPP/Windows/PropVariant.cpp +243 -0
  561. data/ext/p7zip/CPP/Windows/PropVariant.h +56 -0
  562. data/ext/p7zip/CPP/Windows/PropVariantConversions.cpp +142 -0
  563. data/ext/p7zip/CPP/Windows/PropVariantConversions.h +14 -0
  564. data/ext/p7zip/CPP/Windows/PropVariantUtils.cpp +78 -0
  565. data/ext/p7zip/CPP/Windows/PropVariantUtils.h +28 -0
  566. data/ext/p7zip/CPP/Windows/Registry.cpp +313 -0
  567. data/ext/p7zip/CPP/Windows/Registry.h +113 -0
  568. data/ext/p7zip/CPP/Windows/ResourceString.h +22 -0
  569. data/ext/p7zip/CPP/Windows/Shell.h +21 -0
  570. data/ext/p7zip/CPP/Windows/Synchronization.cpp +157 -0
  571. data/ext/p7zip/CPP/Windows/Synchronization.h +187 -0
  572. data/ext/p7zip/CPP/Windows/Synchronization2.h +218 -0
  573. data/ext/p7zip/CPP/Windows/System.cpp +166 -0
  574. data/ext/p7zip/CPP/Windows/System.h +16 -0
  575. data/ext/p7zip/CPP/Windows/Thread.h +41 -0
  576. data/ext/p7zip/CPP/Windows/Time.cpp +88 -0
  577. data/ext/p7zip/CPP/Windows/Time.h +21 -0
  578. data/ext/p7zip/CPP/Windows/Window.cpp +101 -0
  579. data/ext/p7zip/CPP/Windows/Window.h +43 -0
  580. data/ext/p7zip/CPP/include_windows/basetyps.h +19 -0
  581. data/ext/p7zip/CPP/include_windows/tchar.h +89 -0
  582. data/ext/p7zip/CPP/include_windows/windows.h +194 -0
  583. data/ext/p7zip/CPP/myWindows/StdAfx.h +124 -0
  584. data/ext/p7zip/CPP/myWindows/config.h +67 -0
  585. data/ext/p7zip/CPP/myWindows/initguid.h +4 -0
  586. data/ext/p7zip/CPP/myWindows/makefile +21 -0
  587. data/ext/p7zip/CPP/myWindows/makefile.depend +32 -0
  588. data/ext/p7zip/CPP/myWindows/makefile.list +28 -0
  589. data/ext/p7zip/CPP/myWindows/myAddExeFlag.cpp +20 -0
  590. data/ext/p7zip/CPP/myWindows/myGetTickCount.cpp +8 -0
  591. data/ext/p7zip/CPP/myWindows/myPrivate.h +17 -0
  592. data/ext/p7zip/CPP/myWindows/mySplitCommandLine.cpp +82 -0
  593. data/ext/p7zip/CPP/myWindows/test_emul.cpp +745 -0
  594. data/ext/p7zip/CPP/myWindows/wine_GetXXXDefaultLangID.cpp +741 -0
  595. data/ext/p7zip/CPP/myWindows/wine_date_and_time.cpp +434 -0
  596. data/ext/p7zip/ChangeLog +914 -0
  597. data/ext/p7zip/DOCS/7zC.txt +194 -0
  598. data/ext/p7zip/DOCS/7zFormat.txt +469 -0
  599. data/ext/p7zip/DOCS/License.txt +52 -0
  600. data/ext/p7zip/DOCS/MANUAL/commands/add.htm +87 -0
  601. data/ext/p7zip/DOCS/MANUAL/commands/bench.htm +79 -0
  602. data/ext/p7zip/DOCS/MANUAL/commands/delete.htm +59 -0
  603. data/ext/p7zip/DOCS/MANUAL/commands/extract.htm +91 -0
  604. data/ext/p7zip/DOCS/MANUAL/commands/extract_full.htm +68 -0
  605. data/ext/p7zip/DOCS/MANUAL/commands/index.htm +33 -0
  606. data/ext/p7zip/DOCS/MANUAL/commands/list.htm +77 -0
  607. data/ext/p7zip/DOCS/MANUAL/commands/style.css +232 -0
  608. data/ext/p7zip/DOCS/MANUAL/commands/test.htm +46 -0
  609. data/ext/p7zip/DOCS/MANUAL/commands/update.htm +66 -0
  610. data/ext/p7zip/DOCS/MANUAL/exit_codes.htm +27 -0
  611. data/ext/p7zip/DOCS/MANUAL/index.htm +29 -0
  612. data/ext/p7zip/DOCS/MANUAL/style.css +232 -0
  613. data/ext/p7zip/DOCS/MANUAL/switches/ar_exclude.htm +56 -0
  614. data/ext/p7zip/DOCS/MANUAL/switches/ar_include.htm +83 -0
  615. data/ext/p7zip/DOCS/MANUAL/switches/ar_no.htm +52 -0
  616. data/ext/p7zip/DOCS/MANUAL/switches/charset.htm +49 -0
  617. data/ext/p7zip/DOCS/MANUAL/switches/exclude.htm +60 -0
  618. data/ext/p7zip/DOCS/MANUAL/switches/include.htm +87 -0
  619. data/ext/p7zip/DOCS/MANUAL/switches/index.htm +64 -0
  620. data/ext/p7zip/DOCS/MANUAL/switches/large_pages.htm +50 -0
  621. data/ext/p7zip/DOCS/MANUAL/switches/list_tech.htm +36 -0
  622. data/ext/p7zip/DOCS/MANUAL/switches/method.htm +625 -0
  623. data/ext/p7zip/DOCS/MANUAL/switches/output_dir.htm +53 -0
  624. data/ext/p7zip/DOCS/MANUAL/switches/overwrite.htm +56 -0
  625. data/ext/p7zip/DOCS/MANUAL/switches/password.htm +54 -0
  626. data/ext/p7zip/DOCS/MANUAL/switches/recurse.htm +83 -0
  627. data/ext/p7zip/DOCS/MANUAL/switches/sfx.htm +156 -0
  628. data/ext/p7zip/DOCS/MANUAL/switches/ssc.htm +50 -0
  629. data/ext/p7zip/DOCS/MANUAL/switches/stdin.htm +55 -0
  630. data/ext/p7zip/DOCS/MANUAL/switches/stdout.htm +50 -0
  631. data/ext/p7zip/DOCS/MANUAL/switches/stop_switch.htm +31 -0
  632. data/ext/p7zip/DOCS/MANUAL/switches/style.css +232 -0
  633. data/ext/p7zip/DOCS/MANUAL/switches/type.htm +83 -0
  634. data/ext/p7zip/DOCS/MANUAL/switches/update.htm +176 -0
  635. data/ext/p7zip/DOCS/MANUAL/switches/volume.htm +49 -0
  636. data/ext/p7zip/DOCS/MANUAL/switches/working_dir.htm +55 -0
  637. data/ext/p7zip/DOCS/MANUAL/switches/yes.htm +48 -0
  638. data/ext/p7zip/DOCS/MANUAL/syntax.htm +120 -0
  639. data/ext/p7zip/DOCS/Methods.txt +152 -0
  640. data/ext/p7zip/DOCS/copying.txt +504 -0
  641. data/ext/p7zip/DOCS/history.txt +456 -0
  642. data/ext/p7zip/DOCS/lzma.txt +598 -0
  643. data/ext/p7zip/DOCS/readme.txt +181 -0
  644. data/ext/p7zip/DOCS/unRarLicense.txt +41 -0
  645. data/ext/p7zip/README +358 -0
  646. data/ext/p7zip/TODO +39 -0
  647. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/ChangeLog +41 -0
  648. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/readme +21 -0
  649. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/readme.u7z +30 -0
  650. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/u7z +133 -0
  651. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/README +21 -0
  652. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/check/check.sh +117 -0
  653. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/check/files.tar +0 -0
  654. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/man1/p7zip.1 +33 -0
  655. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/p7zip +144 -0
  656. data/ext/p7zip/contrib/qnx630sp3/qnx630sp3-shared +14 -0
  657. data/ext/p7zip/contrib/qnx630sp3/qnx630sp3-static +10 -0
  658. data/ext/p7zip/extconf.rb +101 -0
  659. data/ext/p7zip/install.sh +206 -0
  660. data/ext/p7zip/install_local_context_menu.sh +18 -0
  661. data/ext/p7zip/integration_context_menu.txt +51 -0
  662. data/ext/p7zip/makefile +181 -0
  663. data/ext/p7zip/makefile.aix_gcc +22 -0
  664. data/ext/p7zip/makefile.beos +18 -0
  665. data/ext/p7zip/makefile.crc32 +8 -0
  666. data/ext/p7zip/makefile.cygwin +20 -0
  667. data/ext/p7zip/makefile.cygwin_asm +21 -0
  668. data/ext/p7zip/makefile.djgpp_old +21 -0
  669. data/ext/p7zip/makefile.djgpp_watt +47 -0
  670. data/ext/p7zip/makefile.freebsd5 +20 -0
  671. data/ext/p7zip/makefile.freebsd6 +20 -0
  672. data/ext/p7zip/makefile.glb +39 -0
  673. data/ext/p7zip/makefile.gprof +18 -0
  674. data/ext/p7zip/makefile.hpux-acc +17 -0
  675. data/ext/p7zip/makefile.hpux-acc_64 +19 -0
  676. data/ext/p7zip/makefile.hpux-gcc +21 -0
  677. data/ext/p7zip/makefile.linux_amd64 +22 -0
  678. data/ext/p7zip/makefile.linux_amd64_asm +24 -0
  679. data/ext/p7zip/makefile.linux_amd64_asm_icc +27 -0
  680. data/ext/p7zip/makefile.linux_any_cpu +22 -0
  681. data/ext/p7zip/makefile.linux_any_cpu_gcc_4.X +24 -0
  682. data/ext/p7zip/makefile.linux_clang_amd64 +22 -0
  683. data/ext/p7zip/makefile.linux_cross_arm +22 -0
  684. data/ext/p7zip/makefile.linux_gcc_2.95_no_need_for_libstdc +20 -0
  685. data/ext/p7zip/makefile.linux_other +23 -0
  686. data/ext/p7zip/makefile.linux_s390x +23 -0
  687. data/ext/p7zip/makefile.linux_x86_asm_gcc_4.X +26 -0
  688. data/ext/p7zip/makefile.linux_x86_asm_gcc_4.X_fltk +26 -0
  689. data/ext/p7zip/makefile.linux_x86_asm_gcc_mudflap_4.X +26 -0
  690. data/ext/p7zip/makefile.linux_x86_asm_icc +25 -0
  691. data/ext/p7zip/makefile.linux_x86_icc +24 -0
  692. data/ext/p7zip/makefile.machine_base +22 -0
  693. data/ext/p7zip/makefile.macosx_32bits +20 -0
  694. data/ext/p7zip/makefile.macosx_32bits_asm +23 -0
  695. data/ext/p7zip/makefile.macosx_32bits_ppc +21 -0
  696. data/ext/p7zip/makefile.macosx_64bits +20 -0
  697. data/ext/p7zip/makefile.macosx_llvm_64bits +20 -0
  698. data/ext/p7zip/makefile.netbsd +21 -0
  699. data/ext/p7zip/makefile.netware_asm_gcc_3.X +41 -0
  700. data/ext/p7zip/makefile.oldmake +174 -0
  701. data/ext/p7zip/makefile.openbsd +20 -0
  702. data/ext/p7zip/makefile.openbsd_no_port +20 -0
  703. data/ext/p7zip/makefile.qnx_shared.bin +21 -0
  704. data/ext/p7zip/makefile.qnx_static +21 -0
  705. data/ext/p7zip/makefile.rules +661 -0
  706. data/ext/p7zip/makefile.solaris_sparc_CC_32 +21 -0
  707. data/ext/p7zip/makefile.solaris_sparc_CC_64 +23 -0
  708. data/ext/p7zip/makefile.solaris_sparc_gcc +21 -0
  709. data/ext/p7zip/makefile.solaris_x86 +19 -0
  710. data/ext/p7zip/makefile.tru64 +22 -0
  711. data/ext/seven_zip_ruby/extconf.rb +127 -0
  712. data/ext/seven_zip_ruby/guid_defs.h +29 -0
  713. data/ext/seven_zip_ruby/mutex.h +10 -0
  714. data/ext/seven_zip_ruby/posix/mutex.h +94 -0
  715. data/ext/seven_zip_ruby/seven_zip_archive.cpp +1876 -0
  716. data/ext/seven_zip_ruby/seven_zip_archive.h +548 -0
  717. data/ext/seven_zip_ruby/util_common.cpp +28 -0
  718. data/ext/seven_zip_ruby/util_common.h +515 -0
  719. data/ext/seven_zip_ruby/utils.cpp +575 -0
  720. data/ext/seven_zip_ruby/utils.h +25 -0
  721. data/ext/seven_zip_ruby/win32/mutex.h +130 -0
  722. data/lib/seven_zip_ruby/7z.dll +0 -0
  723. data/lib/seven_zip_ruby/7z.sfx +0 -0
  724. data/lib/seven_zip_ruby/7z64.dll +0 -0
  725. data/lib/seven_zip_ruby/7zCon.sfx +0 -0
  726. data/lib/seven_zip_ruby/archive_info.rb +21 -0
  727. data/lib/seven_zip_ruby/entry_info.rb +46 -0
  728. data/lib/seven_zip_ruby/exception.rb +10 -0
  729. data/lib/seven_zip_ruby/seven_zip_reader.rb +537 -0
  730. data/lib/seven_zip_ruby/seven_zip_writer.rb +502 -0
  731. data/lib/seven_zip_ruby/update_info.rb +116 -0
  732. data/lib/seven_zip_ruby/version.rb +3 -0
  733. data/lib/seven_zip_ruby.rb +34 -0
  734. data/seven-zip.gemspec +35 -0
  735. data/spec/seven_zip.7z +0 -0
  736. data/spec/seven_zip_password.7z +0 -0
  737. data/spec/seven_zip_ruby_spec.rb +703 -0
  738. data/spec/seven_zip_ruby_spec_helper.rb +144 -0
  739. metadata +829 -0
@@ -0,0 +1,1752 @@
1
+ // PeHandler.cpp
2
+
3
+ #include "StdAfx.h"
4
+
5
+ #include "../../../C/CpuArch.h"
6
+
7
+ #include "Common/DynamicBuffer.h"
8
+ #include "Common/ComTry.h"
9
+ #include "Common/IntToString.h"
10
+ #include "Common/StringConvert.h"
11
+
12
+ #include "Windows/PropVariantUtils.h"
13
+ #include "Windows/Time.h"
14
+
15
+ #include "../Common/LimitedStreams.h"
16
+ #include "../Common/ProgressUtils.h"
17
+ #include "../Common/RegisterArc.h"
18
+ #include "../Common/StreamObjects.h"
19
+ #include "../Common/StreamUtils.h"
20
+
21
+ #include "../Compress/CopyCoder.h"
22
+
23
+ #define Get16(p) GetUi16(p)
24
+ #define Get32(p) GetUi32(p)
25
+ #define Get64(p) GetUi64(p)
26
+
27
+ using namespace NWindows;
28
+
29
+ namespace NArchive {
30
+ namespace NPe {
31
+
32
+ #define NUM_SCAN_SECTIONS_MAX (1 << 6)
33
+
34
+ #define PE_SIG 0x00004550
35
+ #define PE_OptHeader_Magic_32 0x10B
36
+ #define PE_OptHeader_Magic_64 0x20B
37
+
38
+ static AString GetDecString(UInt32 v)
39
+ {
40
+ char sz[32];
41
+ ConvertUInt64ToString(v, sz);
42
+ return sz;
43
+ }
44
+
45
+ struct CVersion
46
+ {
47
+ UInt16 Major;
48
+ UInt16 Minor;
49
+
50
+ void Parse(const Byte *buf);
51
+ AString GetString() const { return GetDecString(Major) + '.' + GetDecString(Minor); }
52
+ };
53
+
54
+ void CVersion::Parse(const Byte *p)
55
+ {
56
+ Major = Get16(p);
57
+ Minor = Get16(p + 2);
58
+ }
59
+
60
+ static const UInt32 kHeaderSize = 4 + 20;
61
+
62
+ struct CHeader
63
+ {
64
+ UInt16 NumSections;
65
+ UInt32 Time;
66
+ UInt32 PointerToSymbolTable;
67
+ UInt32 NumSymbols;
68
+ UInt16 OptHeaderSize;
69
+ UInt16 Flags;
70
+ UInt16 Machine;
71
+
72
+ bool Parse(const Byte *buf);
73
+ };
74
+
75
+ bool CHeader::Parse(const Byte *p)
76
+ {
77
+ if (Get32(p) != PE_SIG)
78
+ return false;
79
+ p += 4;
80
+ Machine = Get16(p + 0);
81
+ NumSections = Get16(p + 2);
82
+ Time = Get32(p + 4);
83
+ PointerToSymbolTable = Get32(p + 8);
84
+ NumSymbols = Get32(p + 12);
85
+ OptHeaderSize = Get16(p + 16);
86
+ Flags = Get16(p + 18);
87
+ return true;
88
+ }
89
+
90
+ struct CDirLink
91
+ {
92
+ UInt32 Va;
93
+ UInt32 Size;
94
+ void Parse(const Byte *p);
95
+ };
96
+
97
+ void CDirLink::Parse(const Byte *p)
98
+ {
99
+ Va = Get32(p);
100
+ Size = Get32(p + 4);
101
+ }
102
+
103
+ enum
104
+ {
105
+ kDirLink_Certificate = 4,
106
+ kDirLink_Debug = 6
107
+ };
108
+
109
+ struct CDebugEntry
110
+ {
111
+ UInt32 Flags;
112
+ UInt32 Time;
113
+ CVersion Ver;
114
+ UInt32 Type;
115
+ UInt32 Size;
116
+ UInt32 Va;
117
+ UInt32 Pa;
118
+
119
+ void Parse(const Byte *p);
120
+ };
121
+
122
+ void CDebugEntry::Parse(const Byte *p)
123
+ {
124
+ Flags = Get32(p);
125
+ Time = Get32(p + 4);
126
+ Ver.Parse(p + 8);
127
+ Type = Get32(p + 12);
128
+ Size = Get32(p + 16);
129
+ Va = Get32(p + 20);
130
+ Pa = Get32(p + 24);
131
+ }
132
+
133
+ static const UInt32 kNumDirItemsMax = 16;
134
+
135
+ struct COptHeader
136
+ {
137
+ UInt16 Magic;
138
+ Byte LinkerVerMajor;
139
+ Byte LinkerVerMinor;
140
+
141
+ UInt32 CodeSize;
142
+ UInt32 InitDataSize;
143
+ UInt32 UninitDataSize;
144
+
145
+ // UInt32 AddressOfEntryPoint;
146
+ // UInt32 BaseOfCode;
147
+ // UInt32 BaseOfData32;
148
+ UInt64 ImageBase;
149
+
150
+ UInt32 SectAlign;
151
+ UInt32 FileAlign;
152
+
153
+ CVersion OsVer;
154
+ CVersion ImageVer;
155
+ CVersion SubsysVer;
156
+
157
+ UInt32 ImageSize;
158
+ UInt32 HeadersSize;
159
+ UInt32 CheckSum;
160
+ UInt16 SubSystem;
161
+ UInt16 DllCharacts;
162
+
163
+ UInt64 StackReserve;
164
+ UInt64 StackCommit;
165
+ UInt64 HeapReserve;
166
+ UInt64 HeapCommit;
167
+
168
+ UInt32 NumDirItems;
169
+ CDirLink DirItems[kNumDirItemsMax];
170
+
171
+ bool Is64Bit() const { return Magic == PE_OptHeader_Magic_64; }
172
+ bool Parse(const Byte *p, UInt32 size);
173
+
174
+ int GetNumFileAlignBits() const
175
+ {
176
+ for (int i = 9; i <= 16; i++)
177
+ if (((UInt32)1 << i) == FileAlign)
178
+ return i;
179
+ return -1;
180
+ }
181
+ };
182
+
183
+ bool COptHeader::Parse(const Byte *p, UInt32 size)
184
+ {
185
+ Magic = Get16(p);
186
+ switch (Magic)
187
+ {
188
+ case PE_OptHeader_Magic_32:
189
+ case PE_OptHeader_Magic_64:
190
+ break;
191
+ default:
192
+ return false;
193
+ }
194
+ LinkerVerMajor = p[2];
195
+ LinkerVerMinor = p[3];
196
+
197
+ bool hdr64 = Is64Bit();
198
+
199
+ CodeSize = Get32(p + 4);
200
+ InitDataSize = Get32(p + 8);
201
+ UninitDataSize = Get32(p + 12);
202
+
203
+ // AddressOfEntryPoint = Get32(p + 16);
204
+ // BaseOfCode = Get32(p + 20);
205
+ // BaseOfData32 = hdr64 ? 0: Get32(p + 24);
206
+ ImageBase = hdr64 ? GetUi64(p + 24) : Get32(p + 28);
207
+
208
+ SectAlign = Get32(p + 32);
209
+ FileAlign = Get32(p + 36);
210
+
211
+ OsVer.Parse(p + 40);
212
+ ImageVer.Parse(p + 44);
213
+ SubsysVer.Parse(p + 48);
214
+
215
+ // reserved = Get32(p + 52);
216
+
217
+ ImageSize = Get32(p + 56);
218
+ HeadersSize = Get32(p + 60);
219
+ CheckSum = Get32(p + 64);
220
+ SubSystem = Get16(p + 68);
221
+ DllCharacts = Get16(p + 70);
222
+
223
+ if (hdr64)
224
+ {
225
+ StackReserve = Get64(p + 72);
226
+ StackCommit = Get64(p + 80);
227
+ HeapReserve = Get64(p + 88);
228
+ HeapCommit = Get64(p + 96);
229
+ }
230
+ else
231
+ {
232
+ StackReserve = Get32(p + 72);
233
+ StackCommit = Get32(p + 76);
234
+ HeapReserve = Get32(p + 80);
235
+ HeapCommit = Get32(p + 84);
236
+ }
237
+ UInt32 pos = (hdr64 ? 108 : 92);
238
+ NumDirItems = Get32(p + pos);
239
+ pos += 4;
240
+ if (pos + 8 * NumDirItems != size)
241
+ return false;
242
+ for (UInt32 i = 0; i < NumDirItems && i < kNumDirItemsMax; i++)
243
+ DirItems[i].Parse(p + pos + i * 8);
244
+ return true;
245
+ }
246
+
247
+ static const UInt32 kSectionSize = 40;
248
+
249
+ struct CSection
250
+ {
251
+ AString Name;
252
+
253
+ UInt32 VSize;
254
+ UInt32 Va;
255
+ UInt32 PSize;
256
+ UInt32 Pa;
257
+ UInt32 Flags;
258
+ UInt32 Time;
259
+ // UInt16 NumRelocs;
260
+ bool IsDebug;
261
+ bool IsRealSect;
262
+ bool IsAdditionalSection;
263
+
264
+ CSection(): IsRealSect(false), IsDebug(false), IsAdditionalSection(false) {}
265
+ UInt64 GetPackSize() const { return PSize; }
266
+
267
+ void UpdateTotalSize(UInt32 &totalSize)
268
+ {
269
+ UInt32 t = Pa + PSize;
270
+ if (t > totalSize)
271
+ totalSize = t;
272
+ }
273
+ void Parse(const Byte *p);
274
+ };
275
+
276
+ static bool operator <(const CSection &a1, const CSection &a2) { return (a1.Pa < a2.Pa) || ((a1.Pa == a2.Pa) && (a1.PSize < a2.PSize)) ; }
277
+ static bool operator ==(const CSection &a1, const CSection &a2) { return (a1.Pa == a2.Pa) && (a1.PSize == a2.PSize); }
278
+
279
+ static AString GetName(const Byte *name)
280
+ {
281
+ const int kNameSize = 8;
282
+ AString res;
283
+ char *p = res.GetBuffer(kNameSize);
284
+ memcpy(p, name, kNameSize);
285
+ p[kNameSize] = 0;
286
+ res.ReleaseBuffer();
287
+ return res;
288
+ }
289
+
290
+ void CSection::Parse(const Byte *p)
291
+ {
292
+ Name = GetName(p);
293
+ VSize = Get32(p + 8);
294
+ Va = Get32(p + 12);
295
+ PSize = Get32(p + 16);
296
+ Pa = Get32(p + 20);
297
+ // NumRelocs = Get16(p + 32);
298
+ Flags = Get32(p + 36);
299
+ }
300
+
301
+ static const CUInt32PCharPair g_HeaderCharacts[] =
302
+ {
303
+ { 1, "Executable" },
304
+ { 13, "DLL" },
305
+ { 8, "32-bit" },
306
+ { 5, "LargeAddress" },
307
+ { 0, "NoRelocs" },
308
+ { 2, "NoLineNums" },
309
+ { 3, "NoLocalSyms" },
310
+ { 4, "AggressiveWsTrim" },
311
+ { 9, "NoDebugInfo" },
312
+ { 10, "RemovableRun" },
313
+ { 11, "NetRun" },
314
+ { 12, "System" },
315
+ { 14, "UniCPU" },
316
+ { 7, "Little-Endian" },
317
+ { 15, "Big-Endian" }
318
+ };
319
+
320
+ static const CUInt32PCharPair g_DllCharacts[] =
321
+ {
322
+ { 6, "Relocated" },
323
+ { 7, "Integrity" },
324
+ { 8, "NX-Compatible" },
325
+ { 9, "NoIsolation" },
326
+ { 10, "NoSEH" },
327
+ { 11, "NoBind" },
328
+ { 13, "WDM" },
329
+ { 15, "TerminalServerAware" }
330
+ };
331
+
332
+ static const CUInt32PCharPair g_SectFlags[] =
333
+ {
334
+ { 3, "NoPad" },
335
+ { 5, "Code" },
336
+ { 6, "InitializedData" },
337
+ { 7, "UninitializedData" },
338
+ { 9, "Comments" },
339
+ { 11, "Remove" },
340
+ { 12, "COMDAT" },
341
+ { 15, "GP" },
342
+ { 24, "ExtendedRelocations" },
343
+ { 25, "Discardable" },
344
+ { 26, "NotCached" },
345
+ { 27, "NotPaged" },
346
+ { 28, "Shared" },
347
+ { 29, "Execute" },
348
+ { 30, "Read" },
349
+ { 31, "Write" }
350
+ };
351
+
352
+ static const CUInt32PCharPair g_MachinePairs[] =
353
+ {
354
+ { 0x014C, "x86" },
355
+ { 0x0162, "MIPS-R3000" },
356
+ { 0x0166, "MIPS-R4000" },
357
+ { 0x0168, "MIPS-R10000" },
358
+ { 0x0169, "MIPS-V2" },
359
+ { 0x0184, "Alpha" },
360
+ { 0x01A2, "SH3" },
361
+ { 0x01A3, "SH3-DSP" },
362
+ { 0x01A4, "SH3E" },
363
+ { 0x01A6, "SH4" },
364
+ { 0x01A8, "SH5" },
365
+ { 0x01C0, "ARM" },
366
+ { 0x01C2, "ARM-Thumb" },
367
+ { 0x01F0, "PPC" },
368
+ { 0x01F1, "PPC-FP" },
369
+ { 0x0200, "IA-64" },
370
+ { 0x0284, "Alpha-64" },
371
+ { 0x0200, "IA-64" },
372
+ { 0x0366, "MIPSFPU" },
373
+ { 0x8664, "x64" },
374
+ { 0x0EBC, "EFI" }
375
+ };
376
+
377
+ static const CUInt32PCharPair g_SubSystems[] =
378
+ {
379
+ { 0, "Unknown" },
380
+ { 1, "Native" },
381
+ { 2, "Windows GUI" },
382
+ { 3, "Windows CUI" },
383
+ { 7, "Posix" },
384
+ { 9, "Windows CE" },
385
+ { 10, "EFI" },
386
+ { 11, "EFI Boot" },
387
+ { 12, "EFI Runtime" },
388
+ { 13, "EFI ROM" },
389
+ { 14, "XBOX" }
390
+ };
391
+
392
+ static const wchar_t *g_ResTypes[] =
393
+ {
394
+ NULL,
395
+ L"CURSOR",
396
+ L"BITMAP",
397
+ L"ICON",
398
+ L"MENU",
399
+ L"DIALOG",
400
+ L"STRING",
401
+ L"FONTDIR",
402
+ L"FONT",
403
+ L"ACCELERATOR",
404
+ L"RCDATA",
405
+ L"MESSAGETABLE",
406
+ L"GROUP_CURSOR",
407
+ NULL,
408
+ L"GROUP_ICON",
409
+ NULL,
410
+ L"VERSION",
411
+ L"DLGINCLUDE",
412
+ NULL,
413
+ L"PLUGPLAY",
414
+ L"VXD",
415
+ L"ANICURSOR",
416
+ L"ANIICON",
417
+ L"HTML",
418
+ L"MANIFEST"
419
+ };
420
+
421
+ const UInt32 kFlag = (UInt32)1 << 31;
422
+ const UInt32 kMask = ~kFlag;
423
+
424
+ struct CTableItem
425
+ {
426
+ UInt32 Offset;
427
+ UInt32 ID;
428
+ };
429
+
430
+
431
+ const UInt32 kBmpHeaderSize = 14;
432
+ const UInt32 kIconHeaderSize = 22;
433
+
434
+ struct CResItem
435
+ {
436
+ UInt32 Type;
437
+ UInt32 ID;
438
+ UInt32 Lang;
439
+
440
+ UInt32 Size;
441
+ UInt32 Offset;
442
+
443
+ UInt32 HeaderSize;
444
+ Byte Header[kIconHeaderSize]; // it must be enough for max size header.
445
+ bool Enabled;
446
+
447
+ bool IsNameEqual(const CResItem &item) const { return Lang == item.Lang; }
448
+ UInt32 GetSize() const { return Size + HeaderSize; }
449
+ bool IsBmp() const { return Type == 2; }
450
+ bool IsIcon() const { return Type == 3; }
451
+ bool IsString() const { return Type == 6; }
452
+ bool IsRcData() const { return Type == 10; }
453
+ bool IsRcDataOrUnknown() const { return IsRcData() || Type > 64; }
454
+ };
455
+
456
+ struct CStringItem
457
+ {
458
+ UInt32 Lang;
459
+ UInt32 Size;
460
+ CByteDynamicBuffer Buf;
461
+
462
+ void AddChar(Byte c);
463
+ void AddWChar(UInt16 c);
464
+ };
465
+
466
+ void CStringItem::AddChar(Byte c)
467
+ {
468
+ Buf.EnsureCapacity(Size + 2);
469
+ Buf[Size++] = c;
470
+ Buf[Size++] = 0;
471
+ }
472
+
473
+ void CStringItem::AddWChar(UInt16 c)
474
+ {
475
+ if (c == '\n')
476
+ {
477
+ AddChar('\\');
478
+ c = 'n';
479
+ }
480
+ Buf.EnsureCapacity(Size + 2);
481
+ SetUi16(Buf + Size, c);
482
+ Size += 2;
483
+ }
484
+
485
+ struct CMixItem
486
+ {
487
+ int SectionIndex;
488
+ int ResourceIndex;
489
+ int StringIndex;
490
+
491
+ bool IsSectionItem() const { return ResourceIndex < 0 && StringIndex < 0; };
492
+ };
493
+
494
+ struct CUsedBitmap
495
+ {
496
+ CByteBuffer Buf;
497
+ public:
498
+ void Alloc(size_t size)
499
+ {
500
+ size = (size + 7) / 8;
501
+ Buf.SetCapacity(size);
502
+ memset(Buf, 0, size);
503
+ }
504
+ void Free()
505
+ {
506
+ Buf.SetCapacity(0);
507
+ }
508
+ bool SetRange(size_t from, int size)
509
+ {
510
+ for (int i = 0; i < size; i++)
511
+ {
512
+ size_t pos = (from + i) >> 3;
513
+ Byte mask = (Byte)(1 << ((from + i) & 7));
514
+ Byte b = Buf[pos];
515
+ if ((b & mask) != 0)
516
+ return false;
517
+ Buf[pos] = b | mask;
518
+ }
519
+ return true;
520
+ }
521
+ };
522
+
523
+
524
+ class CHandler:
525
+ public IInArchive,
526
+ public IInArchiveGetStream,
527
+ public CMyUnknownImp
528
+ {
529
+ CMyComPtr<IInStream> _stream;
530
+ CObjectVector<CSection> _sections;
531
+ UInt32 _peOffset;
532
+ CHeader _header;
533
+ COptHeader _optHeader;
534
+ UInt32 _totalSize;
535
+ UInt32 _totalSizeLimited;
536
+ Int32 _mainSubfile;
537
+
538
+ CRecordVector<CResItem> _items;
539
+ CObjectVector<CStringItem> _strings;
540
+
541
+ CByteBuffer _buf;
542
+ bool _oneLang;
543
+ UString _resourceFileName;
544
+ CUsedBitmap _usedRes;
545
+ bool _parseResources;
546
+
547
+ CRecordVector<CMixItem> _mixItems;
548
+
549
+ HRESULT LoadDebugSections(IInStream *stream, bool &thereIsSection);
550
+ HRESULT Open2(IInStream *stream, IArchiveOpenCallback *callback);
551
+ bool Parse(const Byte *buf, UInt32 size);
552
+
553
+ void AddResNameToString(UString &s, UInt32 id) const;
554
+ UString GetLangPrefix(UInt32 lang);
555
+ HRESULT ReadString(UInt32 offset, UString &dest) const;
556
+ HRESULT ReadTable(UInt32 offset, CRecordVector<CTableItem> &items);
557
+ bool ParseStringRes(UInt32 id, UInt32 lang, const Byte *src, UInt32 size);
558
+ HRESULT OpenResources(int sectIndex, IInStream *stream, IArchiveOpenCallback *callback);
559
+ void CloseResources();
560
+
561
+
562
+ bool CheckItem(const CSection &sect, const CResItem &item, size_t offset) const
563
+ {
564
+ return item.Offset >= sect.Va && offset <= _buf.GetCapacity() && _buf.GetCapacity() - offset >= item.Size;
565
+ }
566
+
567
+ public:
568
+ MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
569
+ INTERFACE_IInArchive(;)
570
+ STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
571
+ };
572
+
573
+ bool CHandler::Parse(const Byte *buf, UInt32 size)
574
+ {
575
+ UInt32 i;
576
+ if (size < 512)
577
+ return false;
578
+ _peOffset = Get32(buf + 0x3C);
579
+ if (_peOffset >= 0x1000 || _peOffset + 512 > size || (_peOffset & 7) != 0)
580
+ return false;
581
+
582
+ UInt32 pos = _peOffset;
583
+ if (!_header.Parse(buf + pos))
584
+ return false;
585
+ if (_header.OptHeaderSize > 512 || _header.NumSections > NUM_SCAN_SECTIONS_MAX)
586
+ return false;
587
+ pos += kHeaderSize;
588
+
589
+ if (!_optHeader.Parse(buf + pos, _header.OptHeaderSize))
590
+ return false;
591
+
592
+ pos += _header.OptHeaderSize;
593
+ _totalSize = pos;
594
+
595
+ for (i = 0; i < _header.NumSections; i++, pos += kSectionSize)
596
+ {
597
+ CSection sect;
598
+ if (pos + kSectionSize > size)
599
+ return false;
600
+ sect.Parse(buf + pos);
601
+ sect.IsRealSect = true;
602
+ sect.UpdateTotalSize(_totalSize);
603
+ _sections.Add(sect);
604
+ }
605
+
606
+ return true;
607
+ }
608
+
609
+ enum
610
+ {
611
+ kpidSectAlign = kpidUserDefined,
612
+ kpidFileAlign,
613
+ kpidLinkerVer,
614
+ kpidOsVer,
615
+ kpidImageVer,
616
+ kpidSubsysVer,
617
+ kpidCodeSize,
618
+ kpidImageSize,
619
+ kpidInitDataSize,
620
+ kpidUnInitDataSize,
621
+ kpidHeadersSizeUnInitDataSize,
622
+ kpidSubSystem,
623
+ kpidDllCharacts,
624
+ kpidStackReserve,
625
+ kpidStackCommit,
626
+ kpidHeapReserve,
627
+ kpidHeapCommit,
628
+ kpidImageBase
629
+ // kpidAddressOfEntryPoint,
630
+ // kpidBaseOfCode,
631
+ // kpidBaseOfData32,
632
+ };
633
+
634
+ STATPROPSTG kArcProps[] =
635
+ {
636
+ { NULL, kpidCpu, VT_BSTR},
637
+ { NULL, kpidBit64, VT_BOOL},
638
+ { NULL, kpidCharacts, VT_BSTR},
639
+ { NULL, kpidCTime, VT_FILETIME},
640
+ { NULL, kpidPhySize, VT_UI4},
641
+ { NULL, kpidHeadersSize, VT_UI4},
642
+ { NULL, kpidChecksum, VT_UI4},
643
+ { L"Image Size", kpidImageSize, VT_UI4},
644
+ { L"Section Alignment", kpidSectAlign, VT_UI4},
645
+ { L"File Alignment", kpidFileAlign, VT_UI4},
646
+ { L"Code Size", kpidCodeSize, VT_UI4},
647
+ { L"Initialized Data Size", kpidInitDataSize, VT_UI4},
648
+ { L"Uninitialized Data Size", kpidUnInitDataSize, VT_UI4},
649
+ { L"Linker Version", kpidLinkerVer, VT_BSTR},
650
+ { L"OS Version", kpidOsVer, VT_BSTR},
651
+ { L"Image Version", kpidImageVer, VT_BSTR},
652
+ { L"Subsystem Version", kpidSubsysVer, VT_BSTR},
653
+ { L"Subsystem", kpidSubSystem, VT_BSTR},
654
+ { L"DLL Characteristics", kpidDllCharacts, VT_BSTR},
655
+ { L"Stack Reserve", kpidStackReserve, VT_UI8},
656
+ { L"Stack Commit", kpidStackCommit, VT_UI8},
657
+ { L"Heap Reserve", kpidHeapReserve, VT_UI8},
658
+ { L"Heap Commit", kpidHeapCommit, VT_UI8},
659
+ { L"Image Base", kpidImageBase, VT_UI8}
660
+ // { L"Address Of Entry Point", kpidAddressOfEntryPoint, VT_UI8},
661
+ // { L"Base Of Code", kpidBaseOfCode, VT_UI8},
662
+ // { L"Base Of Data", kpidBaseOfData32, VT_UI8},
663
+ };
664
+
665
+ STATPROPSTG kProps[] =
666
+ {
667
+ { NULL, kpidPath, VT_BSTR},
668
+ { NULL, kpidSize, VT_UI8},
669
+ { NULL, kpidPackSize, VT_UI8},
670
+ { NULL, kpidCharacts, VT_BSTR},
671
+ { NULL, kpidOffset, VT_UI8},
672
+ { NULL, kpidVa, VT_UI8}
673
+ };
674
+
675
+ IMP_IInArchive_Props
676
+ IMP_IInArchive_ArcProps_WITH_NAME
677
+
678
+ static void VerToProp(const CVersion &v, NCOM::CPropVariant &prop)
679
+ {
680
+ StringToProp(v.GetString(), prop);
681
+ }
682
+
683
+ void TimeToProp(UInt32 unixTime, NCOM::CPropVariant &prop)
684
+ {
685
+ if (unixTime != 0)
686
+ {
687
+ FILETIME ft;
688
+ NTime::UnixTimeToFileTime(unixTime, ft);
689
+ prop = ft;
690
+ }
691
+ }
692
+
693
+ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
694
+ {
695
+ COM_TRY_BEGIN
696
+ NCOM::CPropVariant prop;
697
+ switch(propID)
698
+ {
699
+ case kpidSectAlign: prop = _optHeader.SectAlign; break;
700
+ case kpidFileAlign: prop = _optHeader.FileAlign; break;
701
+ case kpidLinkerVer:
702
+ {
703
+ CVersion v = { _optHeader.LinkerVerMajor, _optHeader.LinkerVerMinor };
704
+ VerToProp(v, prop);
705
+ break;
706
+ }
707
+
708
+ case kpidOsVer: VerToProp(_optHeader.OsVer, prop); break;
709
+ case kpidImageVer: VerToProp(_optHeader.ImageVer, prop); break;
710
+ case kpidSubsysVer: VerToProp(_optHeader.SubsysVer, prop); break;
711
+ case kpidCodeSize: prop = _optHeader.CodeSize; break;
712
+ case kpidInitDataSize: prop = _optHeader.InitDataSize; break;
713
+ case kpidUnInitDataSize: prop = _optHeader.UninitDataSize; break;
714
+ case kpidImageSize: prop = _optHeader.ImageSize; break;
715
+ case kpidPhySize: prop = _totalSize; break;
716
+ case kpidHeadersSize: prop = _optHeader.HeadersSize; break;
717
+ case kpidChecksum: prop = _optHeader.CheckSum; break;
718
+
719
+ case kpidCpu: PAIR_TO_PROP(g_MachinePairs, _header.Machine, prop); break;
720
+ case kpidBit64: if (_optHeader.Is64Bit()) prop = true; break;
721
+ case kpidSubSystem: PAIR_TO_PROP(g_SubSystems, _optHeader.SubSystem, prop); break;
722
+
723
+ case kpidMTime:
724
+ case kpidCTime: TimeToProp(_header.Time, prop); break;
725
+ case kpidCharacts: FLAGS_TO_PROP(g_HeaderCharacts, _header.Flags, prop); break;
726
+ case kpidDllCharacts: FLAGS_TO_PROP(g_DllCharacts, _optHeader.DllCharacts, prop); break;
727
+ case kpidStackReserve: prop = _optHeader.StackReserve; break;
728
+ case kpidStackCommit: prop = _optHeader.StackCommit; break;
729
+ case kpidHeapReserve: prop = _optHeader.HeapReserve; break;
730
+ case kpidHeapCommit: prop = _optHeader.HeapCommit; break;
731
+
732
+ case kpidImageBase: prop = _optHeader.ImageBase; break;
733
+ // case kpidAddressOfEntryPoint: prop = _optHeader.AddressOfEntryPoint; break;
734
+ // case kpidBaseOfCode: prop = _optHeader.BaseOfCode; break;
735
+ // case kpidBaseOfData32: if (!_optHeader.Is64Bit()) prop = _optHeader.BaseOfData32; break;
736
+
737
+ case kpidMainSubfile: if (_mainSubfile >= 0) prop = (UInt32)_mainSubfile; break;
738
+ }
739
+ prop.Detach(value);
740
+ return S_OK;
741
+ COM_TRY_END
742
+ }
743
+
744
+ void CHandler::AddResNameToString(UString &s, UInt32 id) const
745
+ {
746
+ if ((id & kFlag) != 0)
747
+ {
748
+ UString name;
749
+ if (ReadString(id & kMask, name) == S_OK)
750
+ {
751
+ if (name.IsEmpty())
752
+ s += L"[]";
753
+ else
754
+ {
755
+ if (name.Length() > 1 && name[0] == '"' && name.Back() == '"')
756
+ name = name.Mid(1, name.Length() - 2);
757
+ s += name;
758
+ }
759
+ return;
760
+ }
761
+ }
762
+ wchar_t sz[32];
763
+ ConvertUInt32ToString(id, sz);
764
+ s += sz;
765
+ }
766
+
767
+ UString CHandler::GetLangPrefix(UInt32 lang)
768
+ {
769
+ UString s = _resourceFileName;
770
+ s += WCHAR_PATH_SEPARATOR;
771
+ if (!_oneLang)
772
+ {
773
+ AddResNameToString(s, lang);
774
+ s += WCHAR_PATH_SEPARATOR;
775
+ }
776
+ return s;
777
+ }
778
+
779
+ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
780
+ {
781
+ COM_TRY_BEGIN
782
+ NCOM::CPropVariant prop;
783
+ const CMixItem &mixItem = _mixItems[index];
784
+ if (mixItem.StringIndex >= 0)
785
+ {
786
+ const CStringItem &item = _strings[mixItem.StringIndex];
787
+ switch(propID)
788
+ {
789
+ case kpidPath: prop = GetLangPrefix(item.Lang) + L"string.txt"; break;
790
+ case kpidSize:
791
+ case kpidPackSize:
792
+ prop = (UInt64)item.Size; break;
793
+ }
794
+ }
795
+ else if (mixItem.ResourceIndex < 0)
796
+ {
797
+ const CSection &item = _sections[mixItem.SectionIndex];
798
+ switch(propID)
799
+ {
800
+ case kpidPath: StringToProp(item.Name, prop); break;
801
+ case kpidSize: prop = (UInt64)item.VSize; break;
802
+ case kpidPackSize: prop = (UInt64)item.GetPackSize(); break;
803
+ case kpidOffset: prop = item.Pa; break;
804
+ case kpidVa: if (item.IsRealSect) prop = item.Va; break;
805
+ case kpidMTime:
806
+ case kpidCTime:
807
+ TimeToProp(item.IsDebug ? item.Time : _header.Time, prop); break;
808
+ case kpidCharacts: if (item.IsRealSect) FLAGS_TO_PROP(g_SectFlags, item.Flags, prop); break;
809
+ }
810
+ }
811
+ else
812
+ {
813
+ const CResItem &item = _items[mixItem.ResourceIndex];
814
+ switch(propID)
815
+ {
816
+ case kpidPath:
817
+ {
818
+ UString s = GetLangPrefix(item.Lang);
819
+ {
820
+ const wchar_t *p = NULL;
821
+ if (item.Type < sizeof(g_ResTypes) / sizeof(g_ResTypes[0]))
822
+ p = g_ResTypes[item.Type];
823
+ if (p != 0)
824
+ s += p;
825
+ else
826
+ AddResNameToString(s, item.Type);
827
+ }
828
+ s += WCHAR_PATH_SEPARATOR;
829
+ AddResNameToString(s, item.ID);
830
+ if (item.HeaderSize != 0)
831
+ {
832
+ if (item.IsBmp())
833
+ s += L".bmp";
834
+ else if (item.IsIcon())
835
+ s += L".ico";
836
+ }
837
+ prop = s;
838
+ break;
839
+ }
840
+ case kpidSize: prop = (UInt64)item.GetSize(); break;
841
+ case kpidPackSize: prop = (UInt64)item.Size; break;
842
+ }
843
+ }
844
+ prop.Detach(value);
845
+ return S_OK;
846
+ COM_TRY_END
847
+ }
848
+
849
+ HRESULT CHandler::LoadDebugSections(IInStream *stream, bool &thereIsSection)
850
+ {
851
+ thereIsSection = false;
852
+ const CDirLink &debugLink = _optHeader.DirItems[kDirLink_Debug];
853
+ if (debugLink.Size == 0)
854
+ return S_OK;
855
+ const unsigned kEntrySize = 28;
856
+ UInt32 numItems = debugLink.Size / kEntrySize;
857
+ if (numItems * kEntrySize != debugLink.Size || numItems > 16)
858
+ return S_FALSE;
859
+
860
+ UInt64 pa = 0;
861
+ int i;
862
+ for (i = 0; i < _sections.Size(); i++)
863
+ {
864
+ const CSection &sect = _sections[i];
865
+ if (sect.Va < debugLink.Va && debugLink.Va + debugLink.Size <= sect.Va + sect.PSize)
866
+ {
867
+ pa = sect.Pa + (debugLink.Va - sect.Va);
868
+ break;
869
+ }
870
+ }
871
+ if (i == _sections.Size())
872
+ {
873
+ return S_OK;
874
+ // Exe for ARM requires S_OK
875
+ // return S_FALSE;
876
+ }
877
+
878
+ CByteBuffer buffer;
879
+ buffer.SetCapacity(debugLink.Size);
880
+ Byte *buf = buffer;
881
+
882
+ RINOK(stream->Seek(pa, STREAM_SEEK_SET, NULL));
883
+ RINOK(ReadStream_FALSE(stream, buf, debugLink.Size));
884
+
885
+ for (i = 0; i < (int)numItems; i++)
886
+ {
887
+ CDebugEntry de;
888
+ de.Parse(buf);
889
+
890
+ if (de.Size == 0)
891
+ continue;
892
+
893
+ CSection sect;
894
+ sect.Name = ".debug" + GetDecString(i);
895
+
896
+ sect.IsDebug = true;
897
+ sect.Time = de.Time;
898
+ sect.Va = de.Va;
899
+ sect.Pa = de.Pa;
900
+ sect.PSize = sect.VSize = de.Size;
901
+ UInt32 totalSize = sect.Pa + sect.PSize;
902
+ if (totalSize > _totalSize)
903
+ {
904
+ _totalSize = totalSize;
905
+ _sections.Add(sect);
906
+ thereIsSection = true;
907
+ }
908
+ buf += kEntrySize;
909
+ }
910
+
911
+ return S_OK;
912
+ }
913
+
914
+ HRESULT CHandler::ReadString(UInt32 offset, UString &dest) const
915
+ {
916
+ if ((offset & 1) != 0 || offset >= _buf.GetCapacity())
917
+ return S_FALSE;
918
+ size_t rem = _buf.GetCapacity() - offset;
919
+ if (rem < 2)
920
+ return S_FALSE;
921
+ unsigned length = Get16(_buf + offset);
922
+ if ((rem - 2) / 2 < length)
923
+ return S_FALSE;
924
+ dest.Empty();
925
+ offset += 2;
926
+ for (unsigned i = 0; i < length; i++)
927
+ dest += (wchar_t)Get16(_buf + offset + i * 2);
928
+ return S_OK;
929
+ }
930
+
931
+ HRESULT CHandler::ReadTable(UInt32 offset, CRecordVector<CTableItem> &items)
932
+ {
933
+ if ((offset & 3) != 0 || offset >= _buf.GetCapacity())
934
+ return S_FALSE;
935
+ size_t rem = _buf.GetCapacity() - offset;
936
+ if (rem < 16)
937
+ return S_FALSE;
938
+ items.Clear();
939
+ unsigned numNameItems = Get16(_buf + offset + 12);
940
+ unsigned numIdItems = Get16(_buf + offset + 14);
941
+ unsigned numItems = numNameItems + numIdItems;
942
+ if ((rem - 16) / 8 < numItems)
943
+ return S_FALSE;
944
+ if (!_usedRes.SetRange(offset, 16 + numItems * 8))
945
+ return S_FALSE;
946
+ offset += 16;
947
+ _oneLang = true;
948
+ unsigned i;
949
+ for (i = 0; i < numItems; i++)
950
+ {
951
+ CTableItem item;
952
+ const Byte *buf = _buf + offset;
953
+ offset += 8;
954
+ item.ID = Get32(buf + 0);
955
+ if (((item.ID & kFlag) != 0) != (i < numNameItems))
956
+ return S_FALSE;
957
+ item.Offset = Get32(buf + 4);
958
+ items.Add(item);
959
+ }
960
+ return S_OK;
961
+ }
962
+
963
+ static const UInt32 kFileSizeMax = (UInt32)1 << 30;
964
+ static const int kNumResItemsMax = (UInt32)1 << 23;
965
+ static const int kNumStringLangsMax = 128;
966
+
967
+ // BITMAPINFOHEADER
968
+ struct CBitmapInfoHeader
969
+ {
970
+ // UInt32 HeaderSize;
971
+ UInt32 XSize;
972
+ Int32 YSize;
973
+ UInt16 Planes;
974
+ UInt16 BitCount;
975
+ UInt32 Compression;
976
+ UInt32 SizeImage;
977
+
978
+ bool Parse(const Byte *p, size_t size);
979
+ };
980
+
981
+ static const UInt32 kBitmapInfoHeader_Size = 0x28;
982
+
983
+ bool CBitmapInfoHeader::Parse(const Byte *p, size_t size)
984
+ {
985
+ if (size < kBitmapInfoHeader_Size || Get32(p) != kBitmapInfoHeader_Size)
986
+ return false;
987
+ XSize = Get32(p + 4);
988
+ YSize = (Int32)Get32(p + 8);
989
+ Planes = Get16(p + 12);
990
+ BitCount = Get16(p + 14);
991
+ Compression = Get32(p + 16);
992
+ SizeImage = Get32(p + 20);
993
+ return true;
994
+ }
995
+
996
+ static UInt32 GetImageSize(UInt32 xSize, UInt32 ySize, UInt32 bitCount)
997
+ {
998
+ return ((xSize * bitCount + 7) / 8 + 3) / 4 * 4 * ySize;
999
+ }
1000
+
1001
+ static UInt32 SetBitmapHeader(Byte *dest, const Byte *src, UInt32 size)
1002
+ {
1003
+ CBitmapInfoHeader h;
1004
+ if (!h.Parse(src, size))
1005
+ return 0;
1006
+ if (h.YSize < 0)
1007
+ h.YSize = -h.YSize;
1008
+ if (h.XSize > (1 << 26) || h.YSize > (1 << 26) || h.Planes != 1 || h.BitCount > 32 ||
1009
+ h.Compression != 0) // BI_RGB
1010
+ return 0;
1011
+ if (h.SizeImage == 0)
1012
+ h.SizeImage = GetImageSize(h.XSize, h.YSize, h.BitCount);
1013
+ UInt32 totalSize = kBmpHeaderSize + size;
1014
+ UInt32 offBits = totalSize - h.SizeImage;
1015
+ // BITMAPFILEHEADER
1016
+ SetUi16(dest, 0x4D42);
1017
+ SetUi32(dest + 2, totalSize);
1018
+ SetUi32(dest + 6, 0);
1019
+ SetUi32(dest + 10, offBits);
1020
+ return kBmpHeaderSize;
1021
+ }
1022
+
1023
+ static UInt32 SetIconHeader(Byte *dest, const Byte *src, UInt32 size)
1024
+ {
1025
+ CBitmapInfoHeader h;
1026
+ if (!h.Parse(src, size))
1027
+ return 0;
1028
+ if (h.YSize < 0)
1029
+ h.YSize = -h.YSize;
1030
+ if (h.XSize > (1 << 26) || h.YSize > (1 << 26) || h.Planes != 1 ||
1031
+ h.Compression != 0) // BI_RGB
1032
+ return 0;
1033
+
1034
+ UInt32 numBitCount = h.BitCount;
1035
+ if (numBitCount != 1 &&
1036
+ numBitCount != 4 &&
1037
+ numBitCount != 8 &&
1038
+ numBitCount != 24 &&
1039
+ numBitCount != 32)
1040
+ return 0;
1041
+
1042
+ if ((h.YSize & 1) != 0)
1043
+ return 0;
1044
+ h.YSize /= 2;
1045
+ if (h.XSize > 0x100 || h.YSize > 0x100)
1046
+ return 0;
1047
+
1048
+ UInt32 imageSize;
1049
+ // imageSize is not correct if AND mask array contains zeros
1050
+ // in this case it is equal image1Size
1051
+
1052
+ // UInt32 imageSize = h.SizeImage;
1053
+ // if (imageSize == 0)
1054
+ // {
1055
+ UInt32 image1Size = GetImageSize(h.XSize, h.YSize, h.BitCount);
1056
+ UInt32 image2Size = GetImageSize(h.XSize, h.YSize, 1);
1057
+ imageSize = image1Size + image2Size;
1058
+ // }
1059
+ UInt32 numColors = 0;
1060
+ if (numBitCount < 16)
1061
+ numColors = 1 << numBitCount;
1062
+
1063
+ SetUi16(dest, 0); // Reserved
1064
+ SetUi16(dest + 2, 1); // RES_ICON
1065
+ SetUi16(dest + 4, 1); // ResCount
1066
+
1067
+ dest[6] = (Byte)h.XSize; // Width
1068
+ dest[7] = (Byte)h.YSize; // Height
1069
+ dest[8] = (Byte)numColors; // ColorCount
1070
+ dest[9] = 0; // Reserved
1071
+
1072
+ SetUi32(dest + 10, 0); // Reserved1 / Reserved2
1073
+
1074
+ UInt32 numQuadsBytes = numColors * 4;
1075
+ UInt32 BytesInRes = kBitmapInfoHeader_Size + numQuadsBytes + imageSize;
1076
+ SetUi32(dest + 14, BytesInRes);
1077
+ SetUi32(dest + 18, kIconHeaderSize);
1078
+
1079
+ /*
1080
+ Description = DWORDToString(xSize) +
1081
+ kDelimiterChar + DWORDToString(ySize) +
1082
+ kDelimiterChar + DWORDToString(numBitCount);
1083
+ */
1084
+ return kIconHeaderSize;
1085
+ }
1086
+
1087
+ bool CHandler::ParseStringRes(UInt32 id, UInt32 lang, const Byte *src, UInt32 size)
1088
+ {
1089
+ if ((size & 1) != 0)
1090
+ return false;
1091
+
1092
+ int i;
1093
+ for (i = 0; i < _strings.Size(); i++)
1094
+ if (_strings[i].Lang == lang)
1095
+ break;
1096
+ if (i == _strings.Size())
1097
+ {
1098
+ if (_strings.Size() >= kNumStringLangsMax)
1099
+ return false;
1100
+ CStringItem item;
1101
+ item.Size = 0;
1102
+ item.Lang = lang;
1103
+ i = _strings.Add(item);
1104
+ }
1105
+
1106
+ CStringItem &item = _strings[i];
1107
+ id = (id - 1) << 4;
1108
+ UInt32 pos = 0;
1109
+ for (i = 0; i < 16; i++)
1110
+ {
1111
+ if (size - pos < 2)
1112
+ return false;
1113
+ UInt32 len = Get16(src + pos);
1114
+ pos += 2;
1115
+ if (len != 0)
1116
+ {
1117
+ if (size - pos < len * 2)
1118
+ return false;
1119
+ char temp[32];
1120
+ ConvertUInt32ToString(id + i, temp);
1121
+ size_t tempLen = strlen(temp);
1122
+ size_t j;
1123
+ for (j = 0; j < tempLen; j++)
1124
+ item.AddChar(temp[j]);
1125
+ item.AddChar('\t');
1126
+ for (j = 0; j < len; j++, pos += 2)
1127
+ item.AddWChar(Get16(src + pos));
1128
+ item.AddChar(0x0D);
1129
+ item.AddChar(0x0A);
1130
+ }
1131
+ }
1132
+ return (size == pos);
1133
+ }
1134
+
1135
+ HRESULT CHandler::OpenResources(int sectionIndex, IInStream *stream, IArchiveOpenCallback *callback)
1136
+ {
1137
+ const CSection &sect = _sections[sectionIndex];
1138
+ size_t fileSize = sect.PSize; // Maybe we need sect.VSize here !!!
1139
+ if (fileSize > kFileSizeMax)
1140
+ return S_FALSE;
1141
+ {
1142
+ UInt64 fileSize64 = fileSize;
1143
+ if (callback)
1144
+ RINOK(callback->SetTotal(NULL, &fileSize64));
1145
+ RINOK(stream->Seek(sect.Pa, STREAM_SEEK_SET, NULL));
1146
+ _buf.SetCapacity(fileSize);
1147
+ for (size_t pos = 0; pos < fileSize;)
1148
+ {
1149
+ UInt64 offset64 = pos;
1150
+ if (callback)
1151
+ RINOK(callback->SetCompleted(NULL, &offset64))
1152
+ size_t rem = MyMin(fileSize - pos, (size_t)(1 << 20));
1153
+ RINOK(ReadStream_FALSE(stream, _buf + pos, rem));
1154
+ pos += rem;
1155
+ }
1156
+ }
1157
+
1158
+ _usedRes.Alloc(fileSize);
1159
+ CRecordVector<CTableItem> specItems;
1160
+ RINOK(ReadTable(0, specItems));
1161
+
1162
+ _oneLang = true;
1163
+ bool stringsOk = true;
1164
+ size_t maxOffset = 0;
1165
+ for (int i = 0; i < specItems.Size(); i++)
1166
+ {
1167
+ const CTableItem &item1 = specItems[i];
1168
+ if ((item1.Offset & kFlag) == 0)
1169
+ return S_FALSE;
1170
+
1171
+ CRecordVector<CTableItem> specItems2;
1172
+ RINOK(ReadTable(item1.Offset & kMask, specItems2));
1173
+
1174
+ for (int j = 0; j < specItems2.Size(); j++)
1175
+ {
1176
+ const CTableItem &item2 = specItems2[j];
1177
+ if ((item2.Offset & kFlag) == 0)
1178
+ return S_FALSE;
1179
+
1180
+ CRecordVector<CTableItem> specItems3;
1181
+ RINOK(ReadTable(item2.Offset & kMask, specItems3));
1182
+
1183
+ CResItem item;
1184
+ item.Type = item1.ID;
1185
+ item.ID = item2.ID;
1186
+
1187
+ for (int k = 0; k < specItems3.Size(); k++)
1188
+ {
1189
+ if (_items.Size() >= kNumResItemsMax)
1190
+ return S_FALSE;
1191
+ const CTableItem &item3 = specItems3[k];
1192
+ if ((item3.Offset & kFlag) != 0)
1193
+ return S_FALSE;
1194
+ if (item3.Offset >= _buf.GetCapacity() || _buf.GetCapacity() - item3.Offset < 16)
1195
+ return S_FALSE;
1196
+ const Byte *buf = _buf + item3.Offset;
1197
+ item.Lang = item3.ID;
1198
+ item.Offset = Get32(buf + 0);
1199
+ item.Size = Get32(buf + 4);
1200
+ // UInt32 codePage = Get32(buf + 8);
1201
+ if (Get32(buf + 12) != 0)
1202
+ return S_FALSE;
1203
+ if (!_items.IsEmpty() && _oneLang && !item.IsNameEqual(_items.Back()))
1204
+ _oneLang = false;
1205
+
1206
+ item.HeaderSize = 0;
1207
+
1208
+ size_t offset = item.Offset - sect.Va;
1209
+ if (offset > maxOffset)
1210
+ maxOffset = offset;
1211
+ if (offset + item.Size > maxOffset)
1212
+ maxOffset = offset + item.Size;
1213
+
1214
+ if (CheckItem(sect, item, offset))
1215
+ {
1216
+ const Byte *data = _buf + offset;
1217
+ if (item.IsBmp())
1218
+ item.HeaderSize = SetBitmapHeader(item.Header, data, item.Size);
1219
+ else if (item.IsIcon())
1220
+ item.HeaderSize = SetIconHeader(item.Header, data, item.Size);
1221
+ else if (item.IsString())
1222
+ {
1223
+ if (stringsOk)
1224
+ stringsOk = ParseStringRes(item.ID, item.Lang, data, item.Size);
1225
+ }
1226
+ }
1227
+
1228
+ item.Enabled = true;
1229
+ _items.Add(item);
1230
+ }
1231
+ }
1232
+ }
1233
+
1234
+ if (stringsOk && !_strings.IsEmpty())
1235
+ {
1236
+ int i;
1237
+ for (i = 0; i < _items.Size(); i++)
1238
+ {
1239
+ CResItem &item = _items[i];
1240
+ if (item.IsString())
1241
+ item.Enabled = false;
1242
+ }
1243
+ for (i = 0; i < _strings.Size(); i++)
1244
+ {
1245
+ if (_strings[i].Size == 0)
1246
+ continue;
1247
+ CMixItem mixItem;
1248
+ mixItem.ResourceIndex = -1;
1249
+ mixItem.StringIndex = i;
1250
+ mixItem.SectionIndex = sectionIndex;
1251
+ _mixItems.Add(mixItem);
1252
+ }
1253
+ }
1254
+
1255
+ _usedRes.Free();
1256
+
1257
+ int numBits = _optHeader.GetNumFileAlignBits();
1258
+ if (numBits >= 0)
1259
+ {
1260
+ UInt32 mask = (1 << numBits) - 1;
1261
+ size_t end = ((maxOffset + mask) & ~mask);
1262
+ if (end < sect.VSize && end <= sect.PSize)
1263
+ {
1264
+ CSection sect2;
1265
+ sect2.Flags = 0;
1266
+
1267
+ // we skip Zeros to start of aligned block
1268
+ size_t i;
1269
+ for (i = maxOffset; i < end; i++)
1270
+ if (_buf[i] != 0)
1271
+ break;
1272
+ if (i == end)
1273
+ maxOffset = end;
1274
+
1275
+ sect2.Pa = sect.Pa + (UInt32)maxOffset;
1276
+ sect2.Va = sect.Va + (UInt32)maxOffset;
1277
+ sect2.PSize = sect.VSize - (UInt32)maxOffset;
1278
+ sect2.VSize = sect2.PSize;
1279
+ sect2.Name = ".rsrc_1";
1280
+ sect2.Time = 0;
1281
+ sect2.IsAdditionalSection = true;
1282
+ _sections.Add(sect2);
1283
+ }
1284
+ }
1285
+
1286
+ return S_OK;
1287
+ }
1288
+
1289
+ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
1290
+ {
1291
+ const UInt32 kBufSize = 1 << 18;
1292
+ const UInt32 kSigSize = 2;
1293
+
1294
+ _mainSubfile = -1;
1295
+
1296
+ CByteBuffer buffer;
1297
+ buffer.SetCapacity(kBufSize);
1298
+ Byte *buf = buffer;
1299
+
1300
+ size_t processed = kSigSize;
1301
+ RINOK(ReadStream_FALSE(stream, buf, processed));
1302
+ if (buf[0] != 'M' || buf[1] != 'Z')
1303
+ return S_FALSE;
1304
+ processed = kBufSize - kSigSize;
1305
+ RINOK(ReadStream(stream, buf + kSigSize, &processed));
1306
+ processed += kSigSize;
1307
+ if (!Parse(buf, (UInt32)processed))
1308
+ return S_FALSE;
1309
+ bool thereISDebug;
1310
+ RINOK(LoadDebugSections(stream, thereISDebug));
1311
+
1312
+ const CDirLink &certLink = _optHeader.DirItems[kDirLink_Certificate];
1313
+ if (certLink.Size != 0)
1314
+ {
1315
+ CSection sect;
1316
+ sect.Name = "CERTIFICATE";
1317
+ sect.Va = 0;
1318
+ sect.Pa = certLink.Va;
1319
+ sect.PSize = sect.VSize = certLink.Size;
1320
+ sect.UpdateTotalSize(_totalSize);
1321
+ _sections.Add(sect);
1322
+ }
1323
+
1324
+ if (thereISDebug)
1325
+ {
1326
+ const UInt32 kAlign = 1 << 12;
1327
+ UInt32 alignPos = _totalSize & (kAlign - 1);
1328
+ if (alignPos != 0)
1329
+ {
1330
+ UInt32 size = kAlign - alignPos;
1331
+ RINOK(stream->Seek(_totalSize, STREAM_SEEK_SET, NULL));
1332
+ buffer.Free();
1333
+ buffer.SetCapacity(kAlign);
1334
+ Byte *buf = buffer;
1335
+ size_t processed = size;
1336
+ RINOK(ReadStream(stream, buf, &processed));
1337
+ size_t i;
1338
+ for (i = 0; i < processed; i++)
1339
+ {
1340
+ if (buf[i] != 0)
1341
+ break;
1342
+ }
1343
+ if (processed < size && processed < 100)
1344
+ _totalSize += (UInt32)processed;
1345
+ else if (((_totalSize + i) & 0x1FF) == 0 || processed < size)
1346
+ _totalSize += (UInt32)i;
1347
+ }
1348
+ }
1349
+
1350
+ if (_header.NumSymbols > 0 && _header.PointerToSymbolTable >= 512)
1351
+ {
1352
+ if (_header.NumSymbols >= (1 << 24))
1353
+ return S_FALSE;
1354
+ CSection sect;
1355
+ sect.Name = "COFF_SYMBOLS";
1356
+ UInt32 size = _header.NumSymbols * 18;
1357
+ RINOK(stream->Seek((UInt64)_header.PointerToSymbolTable + size, STREAM_SEEK_SET, NULL));
1358
+ Byte buf[4];
1359
+ RINOK(ReadStream_FALSE(stream, buf, 4));
1360
+ UInt32 size2 = Get32(buf);
1361
+ if (size2 >= (1 << 28))
1362
+ return S_FALSE;
1363
+ size += size2;
1364
+
1365
+ sect.Va = 0;
1366
+ sect.Pa = _header.PointerToSymbolTable;
1367
+ sect.PSize = sect.VSize = size;
1368
+ sect.UpdateTotalSize(_totalSize);
1369
+ _sections.Add(sect);
1370
+ }
1371
+
1372
+ UInt64 fileSize;
1373
+ RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
1374
+ if (fileSize > _totalSize)
1375
+ return S_FALSE;
1376
+ _totalSizeLimited = (_totalSize < fileSize) ? _totalSize : (UInt32)fileSize;
1377
+
1378
+ {
1379
+ CObjectVector<CSection> sections = _sections;
1380
+ sections.Sort();
1381
+ UInt32 limit = (1 << 12);
1382
+ int num = 0;
1383
+ int numSections = sections.Size();
1384
+ for (int i = 0; i < numSections; i++)
1385
+ {
1386
+ const CSection &s = sections[i];
1387
+ if (s.Pa > limit)
1388
+ {
1389
+ CSection s2;
1390
+ s2.Pa = s2.Va = limit;
1391
+ s2.PSize = s2.VSize = s.Pa - limit;
1392
+ s2.IsAdditionalSection = true;
1393
+ s2.Name = '[';
1394
+ s2.Name += GetDecString(num++);
1395
+ s2.Name += ']';
1396
+ _sections.Add(s2);
1397
+ limit = s.Pa;
1398
+ }
1399
+ UInt32 next = s.Pa + s.PSize;
1400
+ if (next < s.Pa)
1401
+ break;
1402
+ if (next >= limit)
1403
+ limit = next;
1404
+ }
1405
+ }
1406
+
1407
+ _parseResources = true;
1408
+
1409
+ UInt64 mainSize = 0, mainSize2 = 0;
1410
+ int i;
1411
+ for (i = 0; i < _sections.Size(); i++)
1412
+ {
1413
+ const CSection &sect = _sections[i];
1414
+ CMixItem mixItem;
1415
+ mixItem.SectionIndex = i;
1416
+ if (_parseResources && sect.Name == ".rsrc" && _items.IsEmpty())
1417
+ {
1418
+ HRESULT res = OpenResources(i, stream, callback);
1419
+ if (res == S_OK)
1420
+ {
1421
+ _resourceFileName = GetUnicodeString(sect.Name);
1422
+ for (int j = 0; j < _items.Size(); j++)
1423
+ {
1424
+ const CResItem &item = _items[j];
1425
+ if (item.Enabled)
1426
+ {
1427
+ mixItem.ResourceIndex = j;
1428
+ mixItem.StringIndex = -1;
1429
+ if (item.IsRcDataOrUnknown())
1430
+ {
1431
+ if (item.Size >= mainSize)
1432
+ {
1433
+ mainSize2 = mainSize;
1434
+ mainSize = item.Size;
1435
+ _mainSubfile = _mixItems.Size();
1436
+ }
1437
+ else if (item.Size >= mainSize2)
1438
+ mainSize2 = item.Size;
1439
+ }
1440
+ _mixItems.Add(mixItem);
1441
+ }
1442
+ }
1443
+ if (sect.PSize > sect.VSize)
1444
+ {
1445
+ int numBits = _optHeader.GetNumFileAlignBits();
1446
+ if (numBits >= 0)
1447
+ {
1448
+ UInt32 mask = (1 << numBits) - 1;
1449
+ UInt32 end = ((sect.VSize + mask) & ~mask);
1450
+
1451
+ if (sect.PSize > end)
1452
+ {
1453
+ CSection sect2;
1454
+ sect2.Flags = 0;
1455
+ sect2.Pa = sect.Pa + end;
1456
+ sect2.Va = sect.Va + end;
1457
+ sect2.PSize = sect.PSize - end;
1458
+ sect2.VSize = sect2.PSize;
1459
+ sect2.Name = ".rsrc_2";
1460
+ sect2.Time = 0;
1461
+ sect2.IsAdditionalSection = true;
1462
+ _sections.Add(sect2);
1463
+ }
1464
+ }
1465
+ }
1466
+ continue;
1467
+ }
1468
+ if (res != S_FALSE)
1469
+ return res;
1470
+ CloseResources();
1471
+ }
1472
+ mixItem.StringIndex = -1;
1473
+ mixItem.ResourceIndex = -1;
1474
+ if (sect.IsAdditionalSection)
1475
+ {
1476
+ if (sect.PSize >= mainSize)
1477
+ {
1478
+ mainSize2 = mainSize;
1479
+ mainSize = sect.PSize;
1480
+ _mainSubfile = _mixItems.Size();
1481
+ }
1482
+ else
1483
+ mainSize2 = sect.PSize;
1484
+ }
1485
+ _mixItems.Add(mixItem);
1486
+ }
1487
+
1488
+ if (mainSize2 >= (1 << 20) && mainSize < mainSize2 * 2)
1489
+ _mainSubfile = -1;
1490
+
1491
+ for (i = 0; i < _mixItems.Size(); i++)
1492
+ {
1493
+ const CMixItem &mixItem = _mixItems[i];
1494
+ if (mixItem.StringIndex < 0 && mixItem.ResourceIndex < 0 && _sections[mixItem.SectionIndex].Name == "_winzip_")
1495
+ {
1496
+ _mainSubfile = i;
1497
+ break;
1498
+ }
1499
+ }
1500
+
1501
+ return S_OK;
1502
+ }
1503
+
1504
+ HRESULT CalcCheckSum(ISequentialInStream *stream, UInt32 size, UInt32 excludePos, UInt32 &res)
1505
+ {
1506
+ // size &= ~1;
1507
+ const UInt32 kBufSize = 1 << 23;
1508
+ CByteBuffer buffer;
1509
+ buffer.SetCapacity(kBufSize);
1510
+ Byte *buf = buffer;
1511
+
1512
+ UInt32 sum = 0;
1513
+ UInt32 pos = 0;
1514
+ for (;;)
1515
+ {
1516
+ UInt32 rem = size - pos;
1517
+ if (rem > kBufSize)
1518
+ rem = kBufSize;
1519
+ if (rem == 0)
1520
+ break;
1521
+ size_t processed = rem;
1522
+ RINOK(ReadStream(stream, buf, &processed));
1523
+
1524
+ /*
1525
+ for (; processed < rem; processed++)
1526
+ buf[processed] = 0;
1527
+ */
1528
+
1529
+ if ((processed & 1) != 0)
1530
+ buf[processed] = 0;
1531
+
1532
+ for (int j = 0; j < 4; j++)
1533
+ {
1534
+ UInt32 p = excludePos + j;
1535
+ if (pos <= p && p < pos + processed)
1536
+ buf[p - pos] = 0;
1537
+ }
1538
+
1539
+ for (size_t i = 0; i < processed; i += 2)
1540
+ {
1541
+ sum += Get16(buf + i);
1542
+ sum = (sum + (sum >> 16)) & 0xFFFF;
1543
+ }
1544
+ pos += (UInt32)processed;
1545
+ if (rem != processed)
1546
+ break;
1547
+ }
1548
+ sum += pos;
1549
+ res = sum;
1550
+ return S_OK;
1551
+ }
1552
+
1553
+ STDMETHODIMP CHandler::Open(IInStream *inStream, const UInt64 *, IArchiveOpenCallback *callback)
1554
+ {
1555
+ COM_TRY_BEGIN
1556
+ Close();
1557
+ RINOK(Open2(inStream, callback));
1558
+ _stream = inStream;
1559
+ return S_OK;
1560
+ COM_TRY_END
1561
+ }
1562
+
1563
+ void CHandler::CloseResources()
1564
+ {
1565
+ _usedRes.Free();
1566
+ _items.Clear();
1567
+ _strings.Clear();
1568
+ _buf.SetCapacity(0);
1569
+ }
1570
+
1571
+ STDMETHODIMP CHandler::Close()
1572
+ {
1573
+ _stream.Release();
1574
+ _sections.Clear();
1575
+ _mixItems.Clear();
1576
+ CloseResources();
1577
+ return S_OK;
1578
+ }
1579
+
1580
+ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
1581
+ {
1582
+ *numItems = _mixItems.Size();
1583
+ return S_OK;
1584
+ }
1585
+
1586
+ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1587
+ Int32 testMode, IArchiveExtractCallback *extractCallback)
1588
+ {
1589
+ COM_TRY_BEGIN
1590
+ bool allFilesMode = (numItems == (UInt32)-1);
1591
+ if (allFilesMode)
1592
+ numItems = _mixItems.Size();
1593
+ if (numItems == 0)
1594
+ return S_OK;
1595
+ UInt64 totalSize = 0;
1596
+ UInt32 i;
1597
+ for (i = 0; i < numItems; i++)
1598
+ {
1599
+ const CMixItem &mixItem = _mixItems[allFilesMode ? i : indices[i]];
1600
+ if (mixItem.StringIndex >= 0)
1601
+ totalSize += _strings[mixItem.StringIndex].Size;
1602
+ else if (mixItem.ResourceIndex < 0)
1603
+ totalSize += _sections[mixItem.SectionIndex].GetPackSize();
1604
+ else
1605
+ totalSize += _items[mixItem.ResourceIndex].GetSize();
1606
+ }
1607
+ extractCallback->SetTotal(totalSize);
1608
+
1609
+ UInt64 currentTotalSize = 0;
1610
+ UInt64 currentItemSize;
1611
+
1612
+ NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
1613
+ CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
1614
+
1615
+ CLocalProgress *lps = new CLocalProgress;
1616
+ CMyComPtr<ICompressProgressInfo> progress = lps;
1617
+ lps->Init(extractCallback, false);
1618
+
1619
+ bool checkSumOK = true;
1620
+ if (_optHeader.CheckSum != 0 && (int)numItems == _mixItems.Size())
1621
+ {
1622
+ UInt32 checkSum = 0;
1623
+ RINOK(_stream->Seek(0, STREAM_SEEK_SET, NULL));
1624
+ CalcCheckSum(_stream, _totalSizeLimited, _peOffset + kHeaderSize + 64, checkSum);
1625
+ checkSumOK = (checkSum == _optHeader.CheckSum);
1626
+ }
1627
+
1628
+ CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
1629
+ CMyComPtr<ISequentialInStream> inStream(streamSpec);
1630
+ streamSpec->SetStream(_stream);
1631
+
1632
+ for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
1633
+ {
1634
+ lps->InSize = lps->OutSize = currentTotalSize;
1635
+ RINOK(lps->SetCur());
1636
+ Int32 askMode = testMode ?
1637
+ NExtract::NAskMode::kTest :
1638
+ NExtract::NAskMode::kExtract;
1639
+ UInt32 index = allFilesMode ? i : indices[i];
1640
+
1641
+ CMyComPtr<ISequentialOutStream> outStream;
1642
+ RINOK(extractCallback->GetStream(index, &outStream, askMode));
1643
+ const CMixItem &mixItem = _mixItems[index];
1644
+
1645
+ const CSection &sect = _sections[mixItem.SectionIndex];
1646
+ bool isOk = true;
1647
+ if (mixItem.StringIndex >= 0)
1648
+ {
1649
+ const CStringItem &item = _strings[mixItem.StringIndex];
1650
+ currentItemSize = item.Size;
1651
+ if (!testMode && !outStream)
1652
+ continue;
1653
+
1654
+ RINOK(extractCallback->PrepareOperation(askMode));
1655
+ if (outStream)
1656
+ RINOK(WriteStream(outStream, item.Buf, item.Size));
1657
+ }
1658
+ else if (mixItem.ResourceIndex < 0)
1659
+ {
1660
+ currentItemSize = sect.GetPackSize();
1661
+ if (!testMode && !outStream)
1662
+ continue;
1663
+
1664
+ RINOK(extractCallback->PrepareOperation(askMode));
1665
+ RINOK(_stream->Seek(sect.Pa, STREAM_SEEK_SET, NULL));
1666
+ streamSpec->Init(currentItemSize);
1667
+ RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
1668
+ isOk = (copyCoderSpec->TotalSize == currentItemSize);
1669
+ }
1670
+ else
1671
+ {
1672
+ const CResItem &item = _items[mixItem.ResourceIndex];
1673
+ currentItemSize = item.GetSize();
1674
+ if (!testMode && !outStream)
1675
+ continue;
1676
+
1677
+ RINOK(extractCallback->PrepareOperation(askMode));
1678
+ size_t offset = item.Offset - sect.Va;
1679
+ if (!CheckItem(sect, item, offset))
1680
+ isOk = false;
1681
+ else if (outStream)
1682
+ {
1683
+ if (item.HeaderSize != 0)
1684
+ RINOK(WriteStream(outStream, item.Header, item.HeaderSize));
1685
+ RINOK(WriteStream(outStream, _buf + offset, item.Size));
1686
+ }
1687
+ }
1688
+
1689
+ outStream.Release();
1690
+ RINOK(extractCallback->SetOperationResult(isOk ?
1691
+ checkSumOK ?
1692
+ NExtract::NOperationResult::kOK:
1693
+ NExtract::NOperationResult::kCRCError:
1694
+ NExtract::NOperationResult::kDataError));
1695
+ }
1696
+ return S_OK;
1697
+ COM_TRY_END
1698
+ }
1699
+
1700
+ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
1701
+ {
1702
+ COM_TRY_BEGIN
1703
+ *stream = 0;
1704
+
1705
+ const CMixItem &mixItem = _mixItems[index];
1706
+ const CSection &sect = _sections[mixItem.SectionIndex];
1707
+ if (mixItem.IsSectionItem())
1708
+ return CreateLimitedInStream(_stream, sect.Pa, sect.PSize, stream);
1709
+
1710
+ CBufInStream *inStreamSpec = new CBufInStream;
1711
+ CMyComPtr<ISequentialInStream> streamTemp = inStreamSpec;
1712
+ CReferenceBuf *referenceBuf = new CReferenceBuf;
1713
+ CMyComPtr<IUnknown> ref = referenceBuf;
1714
+ if (mixItem.StringIndex >= 0)
1715
+ {
1716
+ const CStringItem &item = _strings[mixItem.StringIndex];
1717
+ referenceBuf->Buf.SetCapacity(item.Size);
1718
+ memcpy(referenceBuf->Buf, item.Buf, item.Size);
1719
+ }
1720
+ else
1721
+ {
1722
+ const CResItem &item = _items[mixItem.ResourceIndex];
1723
+ size_t offset = item.Offset - sect.Va;
1724
+ if (!CheckItem(sect, item, offset))
1725
+ return S_FALSE;
1726
+ if (item.HeaderSize == 0)
1727
+ {
1728
+ CBufInStream *streamSpec = new CBufInStream;
1729
+ CMyComPtr<IInStream> streamTemp2 = streamSpec;
1730
+ streamSpec->Init(_buf + offset, item.Size, (IInArchive *)this);
1731
+ *stream = streamTemp2.Detach();
1732
+ return S_OK;
1733
+ }
1734
+ referenceBuf->Buf.SetCapacity(item.HeaderSize + item.Size);
1735
+ memcpy(referenceBuf->Buf, item.Header, item.HeaderSize);
1736
+ memcpy(referenceBuf->Buf + item.HeaderSize, _buf + offset, item.Size);
1737
+ }
1738
+ inStreamSpec->Init(referenceBuf);
1739
+
1740
+ *stream = streamTemp.Detach();
1741
+ return S_OK;
1742
+ COM_TRY_END
1743
+ }
1744
+
1745
+ static IInArchive *CreateArc() { return new CHandler; }
1746
+
1747
+ static CArcInfo g_ArcInfo =
1748
+ { L"PE", L"exe dll sys", 0, 0xDD, { 'P', 'E', 0, 0 }, 4, false, CreateArc, 0 };
1749
+
1750
+ REGISTER_ARC(Pe)
1751
+
1752
+ }}