seven-zip 1.4.2 → 1.7.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (887) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +49 -0
  3. data/.github/workflows/release.yml +21 -0
  4. data/README.md +13 -2
  5. data/Rakefile +2 -0
  6. data/ext/p7zip/C/7zBuf.h +4 -8
  7. data/ext/p7zip/C/7zBuf2.c +9 -3
  8. data/ext/p7zip/C/7zCrc.c +84 -32
  9. data/ext/p7zip/C/7zCrc.h +2 -2
  10. data/ext/p7zip/C/7zCrcOpt.c +89 -8
  11. data/ext/p7zip/C/7zStream.c +4 -2
  12. data/ext/p7zip/C/{Types.h → 7zTypes.h} +8 -6
  13. data/ext/p7zip/C/7zVersion.h +21 -6
  14. data/ext/p7zip/C/Aes.c +28 -15
  15. data/ext/p7zip/C/Aes.h +2 -2
  16. data/ext/p7zip/C/Alloc.c +60 -12
  17. data/ext/p7zip/C/Alloc.h +6 -7
  18. data/ext/p7zip/C/Bcj2.c +256 -0
  19. data/ext/p7zip/C/Bcj2.h +146 -0
  20. data/ext/p7zip/C/Bcj2Enc.c +312 -0
  21. data/ext/p7zip/C/Blake2.h +48 -0
  22. data/ext/p7zip/C/Blake2s.c +244 -0
  23. data/ext/p7zip/C/Bra.c +2 -0
  24. data/ext/p7zip/C/Bra.h +4 -8
  25. data/ext/p7zip/C/Bra86.c +48 -51
  26. data/ext/p7zip/C/BraIA64.c +3 -1
  27. data/ext/p7zip/C/BwtSort.c +3 -4
  28. data/ext/p7zip/C/BwtSort.h +4 -8
  29. data/ext/p7zip/C/Compiler.h +32 -0
  30. data/ext/p7zip/C/CpuArch.c +50 -7
  31. data/ext/p7zip/C/CpuArch.h +112 -41
  32. data/ext/p7zip/C/Delta.c +2 -0
  33. data/ext/p7zip/C/Delta.h +4 -8
  34. data/ext/p7zip/C/HuffEnc.c +8 -6
  35. data/ext/p7zip/C/HuffEnc.h +4 -8
  36. data/ext/p7zip/C/LzFind.c +391 -108
  37. data/ext/p7zip/C/LzFind.h +20 -18
  38. data/ext/p7zip/C/LzFindMt.c +100 -90
  39. data/ext/p7zip/C/LzFindMt.h +4 -8
  40. data/ext/p7zip/C/LzHash.h +23 -20
  41. data/ext/p7zip/C/Lzma2Dec.c +48 -26
  42. data/ext/p7zip/C/Lzma2Dec.h +4 -8
  43. data/ext/p7zip/C/Lzma2Enc.c +58 -15
  44. data/ext/p7zip/C/Lzma2Enc.h +3 -7
  45. data/ext/p7zip/C/{LzmaUtil/Lzma86Enc.h → Lzma86.h} +47 -14
  46. data/ext/p7zip/C/{LzmaUtil/Lzma86Dec.c → Lzma86Dec.c} +6 -13
  47. data/ext/p7zip/C/{LzmaUtil/Lzma86Enc.c → Lzma86Enc.c} +8 -15
  48. data/ext/p7zip/C/LzmaDec.c +180 -79
  49. data/ext/p7zip/C/LzmaDec.h +4 -8
  50. data/ext/p7zip/C/LzmaEnc.c +230 -147
  51. data/ext/p7zip/C/LzmaEnc.h +6 -8
  52. data/ext/p7zip/C/MtCoder.c +3 -3
  53. data/ext/p7zip/C/Ppmd.h +5 -5
  54. data/ext/p7zip/C/Ppmd7.c +9 -7
  55. data/ext/p7zip/C/Ppmd7.h +3 -3
  56. data/ext/p7zip/C/Ppmd7Dec.c +2 -0
  57. data/ext/p7zip/C/Ppmd7Enc.c +4 -2
  58. data/ext/p7zip/C/Ppmd8.c +34 -31
  59. data/ext/p7zip/C/Ppmd8.h +5 -1
  60. data/ext/p7zip/C/Ppmd8Dec.c +2 -0
  61. data/ext/p7zip/C/Ppmd8Enc.c +2 -0
  62. data/ext/p7zip/C/Precomp.h +10 -0
  63. data/ext/p7zip/C/RotateDefs.h +11 -1
  64. data/ext/p7zip/C/Sha1.c +340 -0
  65. data/ext/p7zip/C/Sha1.h +38 -0
  66. data/ext/p7zip/C/Sha256.c +107 -63
  67. data/ext/p7zip/C/Sha256.h +2 -2
  68. data/ext/p7zip/C/Sort.c +59 -11
  69. data/ext/p7zip/C/Sort.h +8 -10
  70. data/ext/p7zip/C/Threads.h +1 -1
  71. data/ext/p7zip/C/Xz.c +7 -5
  72. data/ext/p7zip/C/Xz.h +40 -17
  73. data/ext/p7zip/C/XzCrc64.c +69 -16
  74. data/ext/p7zip/C/XzCrc64.h +2 -2
  75. data/ext/p7zip/C/XzCrc64Opt.c +69 -0
  76. data/ext/p7zip/C/XzDec.c +93 -55
  77. data/ext/p7zip/C/XzEnc.c +206 -165
  78. data/ext/p7zip/C/XzEnc.h +23 -9
  79. data/ext/p7zip/C/XzIn.c +50 -43
  80. data/ext/p7zip/CPP/7zip/Archive/7z/7zCompressionMode.h +37 -13
  81. data/ext/p7zip/CPP/7zip/Archive/7z/7zDecode.cpp +392 -181
  82. data/ext/p7zip/CPP/7zip/Archive/7z/7zDecode.h +29 -29
  83. data/ext/p7zip/CPP/7zip/Archive/7z/7zEncode.cpp +424 -212
  84. data/ext/p7zip/CPP/7zip/Archive/7z/7zEncode.h +53 -16
  85. data/ext/p7zip/CPP/7zip/Archive/7z/7zExtract.cpp +312 -174
  86. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderInStream.cpp +74 -61
  87. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderInStream.h +22 -19
  88. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandler.cpp +505 -232
  89. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandler.h +70 -16
  90. data/ext/p7zip/CPP/7zip/Archive/7z/7zHandlerOut.cpp +602 -172
  91. data/ext/p7zip/CPP/7zip/Archive/7z/7zHeader.cpp +5 -0
  92. data/ext/p7zip/CPP/7zip/Archive/7z/7zHeader.h +54 -3
  93. data/ext/p7zip/CPP/7zip/Archive/7z/7zIn.cpp +981 -616
  94. data/ext/p7zip/CPP/7zip/Archive/7z/7zIn.h +275 -89
  95. data/ext/p7zip/CPP/7zip/Archive/7z/7zItem.h +77 -162
  96. data/ext/p7zip/CPP/7zip/Archive/7z/7zOut.cpp +288 -238
  97. data/ext/p7zip/CPP/7zip/Archive/7z/7zOut.h +189 -20
  98. data/ext/p7zip/CPP/7zip/Archive/7z/7zProperties.cpp +59 -49
  99. data/ext/p7zip/CPP/7zip/Archive/7z/7zRegister.cpp +12 -9
  100. data/ext/p7zip/CPP/7zip/Archive/7z/7zSpecStream.cpp +4 -6
  101. data/ext/p7zip/CPP/7zip/Archive/7z/7zSpecStream.h +5 -5
  102. data/ext/p7zip/CPP/7zip/Archive/7z/7zUpdate.cpp +1743 -447
  103. data/ext/p7zip/CPP/7zip/Archive/7z/7zUpdate.h +61 -10
  104. data/ext/p7zip/CPP/7zip/Archive/ApmHandler.cpp +84 -120
  105. data/ext/p7zip/CPP/7zip/Archive/ArHandler.cpp +854 -0
  106. data/ext/p7zip/CPP/7zip/Archive/ArchiveExports.cpp +48 -32
  107. data/ext/p7zip/CPP/7zip/Archive/ArjHandler.cpp +519 -340
  108. data/ext/p7zip/CPP/7zip/Archive/Bz2Handler.cpp +223 -203
  109. data/ext/p7zip/CPP/7zip/Archive/Cab/CabBlockInStream.cpp +50 -139
  110. data/ext/p7zip/CPP/7zip/Archive/Cab/CabBlockInStream.h +17 -18
  111. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHandler.cpp +566 -234
  112. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHandler.h +10 -1
  113. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHeader.cpp +2 -2
  114. data/ext/p7zip/CPP/7zip/Archive/Cab/CabHeader.h +12 -15
  115. data/ext/p7zip/CPP/7zip/Archive/Cab/CabIn.cpp +341 -122
  116. data/ext/p7zip/CPP/7zip/Archive/Cab/CabIn.h +81 -66
  117. data/ext/p7zip/CPP/7zip/Archive/Cab/CabItem.h +17 -14
  118. data/ext/p7zip/CPP/7zip/Archive/Cab/CabRegister.cpp +10 -4
  119. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHandler.cpp +190 -83
  120. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHandler.h +7 -1
  121. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmIn.cpp +292 -174
  122. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmIn.h +73 -47
  123. data/ext/p7zip/CPP/7zip/Archive/ComHandler.cpp +886 -0
  124. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2.cpp +994 -71
  125. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2.h +364 -101
  126. data/ext/p7zip/CPP/7zip/Archive/Common/DummyOutStream.cpp +7 -12
  127. data/ext/p7zip/CPP/7zip/Archive/Common/DummyOutStream.h +4 -3
  128. data/ext/p7zip/CPP/7zip/Archive/Common/FindSignature.cpp +6 -6
  129. data/ext/p7zip/CPP/7zip/Archive/Common/FindSignature.h +2 -2
  130. data/ext/p7zip/CPP/7zip/Archive/Common/HandlerOut.cpp +77 -543
  131. data/ext/p7zip/CPP/7zip/Archive/Common/HandlerOut.h +31 -51
  132. data/ext/p7zip/CPP/7zip/Archive/Common/InStreamWithCRC.cpp +18 -14
  133. data/ext/p7zip/CPP/7zip/Archive/Common/ItemNameUtils.cpp +34 -7
  134. data/ext/p7zip/CPP/7zip/Archive/Common/ItemNameUtils.h +5 -2
  135. data/ext/p7zip/CPP/7zip/Archive/Common/MultiStream.cpp +25 -24
  136. data/ext/p7zip/CPP/7zip/Archive/Common/MultiStream.h +8 -3
  137. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithCRC.h +1 -0
  138. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithSha1.cpp +2 -2
  139. data/ext/p7zip/CPP/7zip/Archive/Common/OutStreamWithSha1.h +5 -5
  140. data/ext/p7zip/CPP/7zip/Archive/Common/ParseProperties.cpp +0 -174
  141. data/ext/p7zip/CPP/7zip/Archive/Common/ParseProperties.h +2 -14
  142. data/ext/p7zip/CPP/7zip/Archive/CpioHandler.cpp +506 -335
  143. data/ext/p7zip/CPP/7zip/Archive/CramfsHandler.cpp +227 -84
  144. data/ext/p7zip/CPP/7zip/Archive/DeflateProps.cpp +0 -115
  145. data/ext/p7zip/CPP/7zip/Archive/DeflateProps.h +0 -29
  146. data/ext/p7zip/CPP/7zip/Archive/DllExports2.cpp +63 -17
  147. data/ext/p7zip/CPP/7zip/Archive/DmgHandler.cpp +1007 -339
  148. data/ext/p7zip/CPP/7zip/Archive/ElfHandler.cpp +618 -177
  149. data/ext/p7zip/CPP/7zip/Archive/ExtHandler.cpp +2867 -0
  150. data/ext/p7zip/CPP/7zip/Archive/FatHandler.cpp +136 -76
  151. data/ext/p7zip/CPP/7zip/Archive/FlvHandler.cpp +132 -150
  152. data/ext/p7zip/CPP/7zip/Archive/GptHandler.cpp +405 -0
  153. data/ext/p7zip/CPP/7zip/Archive/GzHandler.cpp +560 -214
  154. data/ext/p7zip/CPP/7zip/Archive/HandlerCont.cpp +288 -0
  155. data/ext/p7zip/CPP/7zip/Archive/HandlerCont.h +116 -0
  156. data/ext/p7zip/CPP/7zip/Archive/HfsHandler.cpp +1880 -0
  157. data/ext/p7zip/CPP/7zip/Archive/IArchive.h +415 -51
  158. data/ext/p7zip/CPP/7zip/Archive/IhexHandler.cpp +497 -0
  159. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHandler.cpp +158 -71
  160. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHandler.h +2 -1
  161. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHeader.cpp +0 -9
  162. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoHeader.h +8 -5
  163. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoIn.cpp +311 -91
  164. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoIn.h +101 -83
  165. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoItem.h +48 -39
  166. data/ext/p7zip/CPP/7zip/Archive/Iso/IsoRegister.cpp +12 -4
  167. data/ext/p7zip/CPP/7zip/Archive/LzhHandler.cpp +127 -114
  168. data/ext/p7zip/CPP/7zip/Archive/LzmaHandler.cpp +264 -121
  169. data/ext/p7zip/CPP/7zip/Archive/MachoHandler.cpp +402 -242
  170. data/ext/p7zip/CPP/7zip/Archive/MbrHandler.cpp +56 -114
  171. data/ext/p7zip/CPP/7zip/Archive/MslzHandler.cpp +230 -90
  172. data/ext/p7zip/CPP/7zip/Archive/MubHandler.cpp +129 -153
  173. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisDecode.cpp +179 -58
  174. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisDecode.h +36 -7
  175. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisHandler.cpp +407 -237
  176. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisHandler.h +9 -16
  177. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisIn.cpp +5535 -1098
  178. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisIn.h +345 -81
  179. data/ext/p7zip/CPP/7zip/Archive/Nsis/NsisRegister.cpp +11 -4
  180. data/ext/p7zip/CPP/7zip/Archive/NtfsHandler.cpp +1424 -434
  181. data/ext/p7zip/CPP/7zip/Archive/PeHandler.cpp +1831 -521
  182. data/ext/p7zip/CPP/7zip/Archive/PpmdHandler.cpp +50 -35
  183. data/ext/p7zip/CPP/7zip/Archive/QcowHandler.cpp +615 -0
  184. data/ext/p7zip/CPP/7zip/Archive/Rar/Rar5Handler.cpp +2746 -0
  185. data/ext/p7zip/CPP/7zip/Archive/Rar/Rar5Handler.h +411 -0
  186. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHandler.cpp +1241 -355
  187. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHandler.h +70 -20
  188. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHeader.h +38 -34
  189. data/ext/p7zip/CPP/7zip/Archive/Rar/RarItem.h +34 -16
  190. data/ext/p7zip/CPP/7zip/Archive/Rar/RarVol.h +129 -0
  191. data/ext/p7zip/CPP/7zip/Archive/RpmHandler.cpp +641 -194
  192. data/ext/p7zip/CPP/7zip/Archive/SplitHandler.cpp +174 -181
  193. data/ext/p7zip/CPP/7zip/Archive/SquashfsHandler.cpp +237 -174
  194. data/ext/p7zip/CPP/7zip/Archive/SwfHandler.cpp +471 -192
  195. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandler.cpp +350 -59
  196. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandler.h +24 -7
  197. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHandlerOut.cpp +79 -27
  198. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHeader.cpp +5 -7
  199. data/ext/p7zip/CPP/7zip/Archive/Tar/TarHeader.h +20 -44
  200. data/ext/p7zip/CPP/7zip/Archive/Tar/TarIn.cpp +279 -64
  201. data/ext/p7zip/CPP/7zip/Archive/Tar/TarIn.h +10 -1
  202. data/ext/p7zip/CPP/7zip/Archive/Tar/TarItem.h +34 -8
  203. data/ext/p7zip/CPP/7zip/Archive/Tar/TarOut.cpp +145 -87
  204. data/ext/p7zip/CPP/7zip/Archive/Tar/TarOut.h +13 -5
  205. data/ext/p7zip/CPP/7zip/Archive/Tar/TarRegister.cpp +14 -9
  206. data/ext/p7zip/CPP/7zip/Archive/Tar/TarUpdate.cpp +154 -27
  207. data/ext/p7zip/CPP/7zip/Archive/Tar/TarUpdate.h +10 -6
  208. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfHandler.cpp +53 -128
  209. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfHandler.h +6 -5
  210. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfIn.cpp +384 -119
  211. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfIn.h +40 -21
  212. data/ext/p7zip/CPP/7zip/Archive/UefiHandler.cpp +1618 -0
  213. data/ext/p7zip/CPP/7zip/Archive/VdiHandler.cpp +362 -0
  214. data/ext/p7zip/CPP/7zip/Archive/VhdHandler.cpp +438 -247
  215. data/ext/p7zip/CPP/7zip/Archive/VmdkHandler.cpp +1518 -0
  216. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandler.cpp +837 -249
  217. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandler.h +73 -47
  218. data/ext/p7zip/CPP/7zip/Archive/Wim/WimHandlerOut.cpp +1614 -351
  219. data/ext/p7zip/CPP/7zip/Archive/Wim/WimIn.cpp +1519 -513
  220. data/ext/p7zip/CPP/7zip/Archive/Wim/WimIn.h +498 -139
  221. data/ext/p7zip/CPP/7zip/Archive/Wim/WimRegister.cpp +13 -9
  222. data/ext/p7zip/CPP/7zip/Archive/XarHandler.cpp +272 -128
  223. data/ext/p7zip/CPP/7zip/Archive/XzHandler.cpp +502 -253
  224. data/ext/p7zip/CPP/7zip/Archive/XzHandler.h +65 -0
  225. data/ext/p7zip/CPP/7zip/Archive/ZHandler.cpp +114 -39
  226. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipAddCommon.cpp +118 -134
  227. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipAddCommon.h +6 -0
  228. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipCompressionMode.h +40 -20
  229. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandler.cpp +541 -274
  230. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandler.h +13 -40
  231. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp +165 -254
  232. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHeader.h +70 -178
  233. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipIn.cpp +1934 -550
  234. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipIn.h +294 -63
  235. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItem.cpp +160 -86
  236. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItem.h +139 -110
  237. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipOut.cpp +177 -154
  238. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipOut.h +50 -18
  239. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipRegister.cpp +18 -9
  240. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipUpdate.cpp +367 -201
  241. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipUpdate.h +11 -10
  242. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile +2 -319
  243. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile.depend +0 -4962
  244. data/ext/p7zip/CPP/7zip/Bundles/Format7zFree/makefile.list +1004 -259
  245. data/ext/p7zip/CPP/7zip/Common/CWrappers.cpp +26 -22
  246. data/ext/p7zip/CPP/7zip/Common/CWrappers.h +19 -14
  247. data/ext/p7zip/CPP/7zip/Common/CreateCoder.cpp +298 -130
  248. data/ext/p7zip/CPP/7zip/Common/CreateCoder.h +118 -34
  249. data/ext/p7zip/CPP/7zip/Common/FilePathAutoRename.cpp +24 -28
  250. data/ext/p7zip/CPP/7zip/Common/FilePathAutoRename.h +5 -5
  251. data/ext/p7zip/CPP/7zip/Common/FileStreams.cpp +268 -65
  252. data/ext/p7zip/CPP/7zip/Common/FileStreams.h +70 -33
  253. data/ext/p7zip/CPP/7zip/Common/FilterCoder.cpp +302 -131
  254. data/ext/p7zip/CPP/7zip/Common/FilterCoder.h +141 -43
  255. data/ext/p7zip/CPP/7zip/Common/InBuffer.cpp +87 -35
  256. data/ext/p7zip/CPP/7zip/Common/InBuffer.h +54 -45
  257. data/ext/p7zip/CPP/7zip/Common/InOutTempBuffer.cpp +22 -17
  258. data/ext/p7zip/CPP/7zip/Common/InOutTempBuffer.h +5 -5
  259. data/ext/p7zip/CPP/7zip/Common/LimitedStreams.cpp +256 -43
  260. data/ext/p7zip/CPP/7zip/Common/LimitedStreams.h +135 -8
  261. data/ext/p7zip/CPP/7zip/Common/MemBlocks.cpp +5 -5
  262. data/ext/p7zip/CPP/7zip/Common/MemBlocks.h +3 -3
  263. data/ext/p7zip/CPP/7zip/Common/MethodId.cpp +0 -24
  264. data/ext/p7zip/CPP/7zip/Common/MethodId.h +1 -1
  265. data/ext/p7zip/CPP/7zip/Common/MethodProps.cpp +430 -71
  266. data/ext/p7zip/CPP/7zip/Common/MethodProps.h +170 -17
  267. data/ext/p7zip/CPP/7zip/Common/OffsetStream.cpp +8 -4
  268. data/ext/p7zip/CPP/7zip/Common/OffsetStream.h +4 -3
  269. data/ext/p7zip/CPP/7zip/Common/OutBuffer.cpp +26 -31
  270. data/ext/p7zip/CPP/7zip/Common/OutBuffer.h +17 -18
  271. data/ext/p7zip/CPP/7zip/Common/OutMemStream.cpp +5 -5
  272. data/ext/p7zip/CPP/7zip/Common/OutMemStream.h +5 -4
  273. data/ext/p7zip/CPP/7zip/Common/ProgressUtils.cpp +22 -13
  274. data/ext/p7zip/CPP/7zip/Common/ProgressUtils.h +4 -3
  275. data/ext/p7zip/CPP/7zip/Common/PropId.cpp +108 -0
  276. data/ext/p7zip/CPP/7zip/Common/RegisterArc.h +63 -17
  277. data/ext/p7zip/CPP/7zip/Common/RegisterCodec.h +79 -6
  278. data/ext/p7zip/CPP/7zip/Common/StreamBinder.cpp +95 -90
  279. data/ext/p7zip/CPP/7zip/Common/StreamBinder.h +46 -23
  280. data/ext/p7zip/CPP/7zip/Common/StreamObjects.cpp +88 -24
  281. data/ext/p7zip/CPP/7zip/Common/StreamObjects.h +36 -14
  282. data/ext/p7zip/CPP/7zip/Common/StreamUtils.cpp +4 -4
  283. data/ext/p7zip/CPP/7zip/Common/StreamUtils.h +6 -6
  284. data/ext/p7zip/CPP/7zip/Common/UniqBlocks.cpp +57 -0
  285. data/ext/p7zip/CPP/7zip/Common/UniqBlocks.h +26 -0
  286. data/ext/p7zip/CPP/7zip/Common/VirtThread.cpp +8 -6
  287. data/ext/p7zip/CPP/7zip/Common/VirtThread.h +6 -5
  288. data/ext/p7zip/CPP/7zip/Compress/BZip2Const.h +13 -12
  289. data/ext/p7zip/CPP/7zip/Compress/BZip2Crc.h +1 -1
  290. data/ext/p7zip/CPP/7zip/Compress/BZip2Decoder.cpp +198 -147
  291. data/ext/p7zip/CPP/7zip/Compress/BZip2Decoder.h +60 -27
  292. data/ext/p7zip/CPP/7zip/Compress/BZip2Encoder.cpp +111 -116
  293. data/ext/p7zip/CPP/7zip/Compress/BZip2Encoder.h +53 -59
  294. data/ext/p7zip/CPP/7zip/Compress/BZip2Register.cpp +12 -7
  295. data/ext/p7zip/CPP/7zip/Compress/Bcj2Coder.cpp +554 -282
  296. data/ext/p7zip/CPP/7zip/Compress/Bcj2Coder.h +73 -71
  297. data/ext/p7zip/CPP/7zip/Compress/Bcj2Register.cpp +10 -5
  298. data/ext/p7zip/CPP/7zip/Compress/BcjCoder.cpp +13 -4
  299. data/ext/p7zip/CPP/7zip/Compress/BcjCoder.h +17 -5
  300. data/ext/p7zip/CPP/7zip/Compress/BcjRegister.cpp +7 -9
  301. data/ext/p7zip/CPP/7zip/Compress/BitlDecoder.cpp +2 -2
  302. data/ext/p7zip/CPP/7zip/Compress/BitlDecoder.h +58 -61
  303. data/ext/p7zip/CPP/7zip/Compress/BitlEncoder.h +24 -25
  304. data/ext/p7zip/CPP/7zip/Compress/BitmDecoder.h +46 -17
  305. data/ext/p7zip/CPP/7zip/Compress/BitmEncoder.h +18 -19
  306. data/ext/p7zip/CPP/7zip/Compress/BranchMisc.cpp +14 -28
  307. data/ext/p7zip/CPP/7zip/Compress/BranchMisc.h +27 -6
  308. data/ext/p7zip/CPP/7zip/Compress/BranchRegister.cpp +26 -15
  309. data/ext/p7zip/CPP/7zip/Compress/ByteSwap.cpp +45 -26
  310. data/ext/p7zip/CPP/7zip/Compress/CodecExports.cpp +254 -70
  311. data/ext/p7zip/CPP/7zip/Compress/CopyCoder.cpp +65 -17
  312. data/ext/p7zip/CPP/7zip/Compress/CopyCoder.h +15 -3
  313. data/ext/p7zip/CPP/7zip/Compress/CopyRegister.cpp +5 -4
  314. data/ext/p7zip/CPP/7zip/Compress/Deflate64Register.cpp +12 -6
  315. data/ext/p7zip/CPP/7zip/Compress/DeflateConst.h +43 -46
  316. data/ext/p7zip/CPP/7zip/Compress/DeflateDecoder.cpp +145 -81
  317. data/ext/p7zip/CPP/7zip/Compress/DeflateDecoder.h +31 -33
  318. data/ext/p7zip/CPP/7zip/Compress/DeflateEncoder.cpp +179 -162
  319. data/ext/p7zip/CPP/7zip/Compress/DeflateEncoder.h +35 -30
  320. data/ext/p7zip/CPP/7zip/Compress/DeflateRegister.cpp +11 -7
  321. data/ext/p7zip/CPP/7zip/Compress/DeltaFilter.cpp +55 -39
  322. data/ext/p7zip/CPP/7zip/Compress/{DllExports2.cpp → DllExports2Compress.cpp} +8 -8
  323. data/ext/p7zip/CPP/7zip/Compress/DllExportsCompress.cpp +48 -0
  324. data/ext/p7zip/CPP/7zip/Compress/HuffmanDecoder.h +220 -49
  325. data/ext/p7zip/CPP/7zip/Compress/ImplodeDecoder.cpp +14 -9
  326. data/ext/p7zip/CPP/7zip/Compress/ImplodeDecoder.h +2 -3
  327. data/ext/p7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp +7 -7
  328. data/ext/p7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.h +1 -1
  329. data/ext/p7zip/CPP/7zip/Compress/LzOutWindow.cpp +1 -1
  330. data/ext/p7zip/CPP/7zip/Compress/LzOutWindow.h +21 -18
  331. data/ext/p7zip/CPP/7zip/Compress/LzhDecoder.cpp +171 -141
  332. data/ext/p7zip/CPP/7zip/Compress/LzhDecoder.h +32 -64
  333. data/ext/p7zip/CPP/7zip/Compress/Lzham/LICENSE +22 -0
  334. data/ext/p7zip/CPP/7zip/Compress/Lzham/LzhamRegister.cpp +783 -0
  335. data/ext/p7zip/CPP/7zip/Compress/Lzham/README.md +211 -0
  336. data/ext/p7zip/CPP/7zip/Compress/Lzham/include/lzham.h +803 -0
  337. data/ext/p7zip/CPP/7zip/Compress/Lzham/include/lzham_dynamic_lib.h +156 -0
  338. data/ext/p7zip/CPP/7zip/Compress/Lzham/include/lzham_exports.inc +31 -0
  339. data/ext/p7zip/CPP/7zip/Compress/Lzham/include/lzham_static_lib.h +59 -0
  340. data/ext/p7zip/CPP/7zip/Compress/Lzham/include/zlib.h +2 -0
  341. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/CMakeLists.txt +69 -0
  342. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_comp.h +38 -0
  343. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzbase.cpp +244 -0
  344. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzbase.h +46 -0
  345. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzcomp.cpp +750 -0
  346. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzcomp_internal.cpp +2240 -0
  347. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzcomp_internal.h +503 -0
  348. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_lzcomp_state.cpp +1684 -0
  349. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_match_accel.cpp +947 -0
  350. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_match_accel.h +164 -0
  351. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_null_threading.h +98 -0
  352. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_pthreads_threading.cpp +214 -0
  353. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_pthreads_threading.h +535 -0
  354. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_threading.h +12 -0
  355. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_win32_threading.cpp +232 -0
  356. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzham_win32_threading.h +387 -0
  357. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamcomp/lzhamcomp.vcxproj +208 -0
  358. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/CMakeLists.txt +86 -0
  359. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_assert.cpp +80 -0
  360. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_assert.h +58 -0
  361. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_checksum.cpp +73 -0
  362. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_checksum.h +13 -0
  363. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_config.h +25 -0
  364. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_core.h +303 -0
  365. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_decomp.h +37 -0
  366. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_helpers.h +54 -0
  367. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_huffman_codes.cpp +286 -0
  368. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_huffman_codes.h +32 -0
  369. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_lzdecomp.cpp +1586 -0
  370. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_lzdecompbase.cpp +131 -0
  371. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_lzdecompbase.h +89 -0
  372. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_math.h +142 -0
  373. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_mem.cpp +463 -0
  374. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_mem.h +115 -0
  375. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_platform.cpp +159 -0
  376. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_platform.h +284 -0
  377. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_prefix_coding.cpp +431 -0
  378. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_prefix_coding.h +157 -0
  379. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_symbol_codec.cpp +1527 -0
  380. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_symbol_codec.h +494 -0
  381. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_timer.cpp +147 -0
  382. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_timer.h +99 -0
  383. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_traits.h +141 -0
  384. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_types.h +72 -0
  385. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_utils.h +58 -0
  386. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_vector.cpp +83 -0
  387. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzham_vector.h +628 -0
  388. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamdecomp/lzhamdecomp.vcxproj +224 -0
  389. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamlib/lzham_lib.cpp +179 -0
  390. data/ext/p7zip/CPP/7zip/Compress/Lzham/lzhamlib/lzhamlib.vcxproj +187 -0
  391. data/ext/p7zip/CPP/7zip/Compress/Lzham/makefile +10 -0
  392. data/ext/p7zip/CPP/7zip/Compress/Lzham/makefile.depend +0 -0
  393. data/ext/p7zip/CPP/7zip/Compress/Lzham/makefile.list +129 -0
  394. data/ext/p7zip/CPP/7zip/Compress/Lzma2Decoder.cpp +123 -46
  395. data/ext/p7zip/CPP/7zip/Compress/Lzma2Decoder.h +29 -14
  396. data/ext/p7zip/CPP/7zip/Compress/Lzma2Encoder.cpp +14 -9
  397. data/ext/p7zip/CPP/7zip/Compress/Lzma2Encoder.h +1 -1
  398. data/ext/p7zip/CPP/7zip/Compress/Lzma2Register.cpp +9 -7
  399. data/ext/p7zip/CPP/7zip/Compress/LzmaDecoder.cpp +24 -8
  400. data/ext/p7zip/CPP/7zip/Compress/LzmaDecoder.h +8 -1
  401. data/ext/p7zip/CPP/7zip/Compress/LzmaEncoder.cpp +30 -27
  402. data/ext/p7zip/CPP/7zip/Compress/LzmaEncoder.h +3 -1
  403. data/ext/p7zip/CPP/7zip/Compress/LzmaRegister.cpp +9 -7
  404. data/ext/p7zip/CPP/7zip/Compress/LzmsDecoder.cpp +576 -0
  405. data/ext/p7zip/CPP/7zip/Compress/LzmsDecoder.h +271 -0
  406. data/ext/p7zip/CPP/7zip/Compress/Lzx.h +32 -36
  407. data/ext/p7zip/CPP/7zip/Compress/LzxDecoder.cpp +380 -238
  408. data/ext/p7zip/CPP/7zip/Compress/LzxDecoder.h +170 -83
  409. data/ext/p7zip/CPP/7zip/Compress/Mtf8.h +7 -9
  410. data/ext/p7zip/CPP/7zip/Compress/PpmdDecoder.cpp +1 -5
  411. data/ext/p7zip/CPP/7zip/Compress/PpmdEncoder.cpp +51 -18
  412. data/ext/p7zip/CPP/7zip/Compress/PpmdEncoder.h +18 -8
  413. data/ext/p7zip/CPP/7zip/Compress/PpmdRegister.cpp +9 -8
  414. data/ext/p7zip/CPP/7zip/Compress/PpmdZip.cpp +61 -25
  415. data/ext/p7zip/CPP/7zip/Compress/PpmdZip.h +21 -6
  416. data/ext/p7zip/CPP/7zip/Compress/QuantumDecoder.cpp +122 -102
  417. data/ext/p7zip/CPP/7zip/Compress/QuantumDecoder.h +68 -157
  418. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile +33 -18
  419. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile.depend +0 -158
  420. data/ext/p7zip/CPP/7zip/Compress/Rar/makefile.list +105 -56
  421. data/ext/p7zip/CPP/7zip/Compress/Rar1Decoder.cpp +34 -21
  422. data/ext/p7zip/CPP/7zip/Compress/Rar1Decoder.h +2 -0
  423. data/ext/p7zip/CPP/7zip/Compress/Rar2Decoder.cpp +77 -67
  424. data/ext/p7zip/CPP/7zip/Compress/Rar2Decoder.h +12 -10
  425. data/ext/p7zip/CPP/7zip/Compress/Rar3Decoder.cpp +139 -118
  426. data/ext/p7zip/CPP/7zip/Compress/Rar3Decoder.h +48 -33
  427. data/ext/p7zip/CPP/7zip/Compress/Rar3Vm.cpp +148 -113
  428. data/ext/p7zip/CPP/7zip/Compress/Rar3Vm.h +35 -19
  429. data/ext/p7zip/CPP/7zip/Compress/Rar5Decoder.cpp +961 -0
  430. data/ext/p7zip/CPP/7zip/Compress/Rar5Decoder.h +335 -0
  431. data/ext/p7zip/CPP/7zip/Compress/RarCodecsRegister.cpp +13 -6
  432. data/ext/p7zip/CPP/7zip/Compress/ShrinkDecoder.cpp +91 -71
  433. data/ext/p7zip/CPP/7zip/Compress/ShrinkDecoder.h +2 -4
  434. data/ext/p7zip/CPP/7zip/Compress/XpressDecoder.cpp +129 -0
  435. data/ext/p7zip/CPP/7zip/Compress/XpressDecoder.h +13 -0
  436. data/ext/p7zip/CPP/7zip/Compress/ZDecoder.cpp +98 -20
  437. data/ext/p7zip/CPP/7zip/Compress/ZDecoder.h +19 -7
  438. data/ext/p7zip/CPP/7zip/Compress/ZlibDecoder.cpp +14 -11
  439. data/ext/p7zip/CPP/7zip/Compress/ZlibDecoder.h +32 -1
  440. data/ext/p7zip/CPP/7zip/Crypto/7zAes.cpp +137 -101
  441. data/ext/p7zip/CPP/7zip/Crypto/7zAes.h +31 -30
  442. data/ext/p7zip/CPP/7zip/Crypto/7zAesRegister.cpp +8 -9
  443. data/ext/p7zip/CPP/7zip/Crypto/HmacSha1.cpp +39 -28
  444. data/ext/p7zip/CPP/7zip/Crypto/HmacSha1.h +3 -3
  445. data/ext/p7zip/CPP/7zip/Crypto/HmacSha256.cpp +62 -0
  446. data/ext/p7zip/CPP/7zip/Crypto/HmacSha256.h +27 -0
  447. data/ext/p7zip/CPP/7zip/Crypto/MyAes.cpp +73 -7
  448. data/ext/p7zip/CPP/7zip/Crypto/MyAes.h +25 -8
  449. data/ext/p7zip/CPP/7zip/Crypto/MyAesReg.cpp +16 -0
  450. data/ext/p7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp +29 -15
  451. data/ext/p7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.h +2 -1
  452. data/ext/p7zip/CPP/7zip/Crypto/RandGen.cpp +49 -34
  453. data/ext/p7zip/CPP/7zip/Crypto/RandGen.h +2 -2
  454. data/ext/p7zip/CPP/7zip/Crypto/Rar20Crypto.cpp +36 -39
  455. data/ext/p7zip/CPP/7zip/Crypto/Rar20Crypto.h +15 -17
  456. data/ext/p7zip/CPP/7zip/Crypto/Rar5Aes.cpp +257 -0
  457. data/ext/p7zip/CPP/7zip/Crypto/Rar5Aes.h +84 -0
  458. data/ext/p7zip/CPP/7zip/Crypto/RarAes.cpp +70 -71
  459. data/ext/p7zip/CPP/7zip/Crypto/RarAes.h +24 -19
  460. data/ext/p7zip/CPP/7zip/Crypto/Sha1Cls.h +51 -0
  461. data/ext/p7zip/CPP/7zip/Crypto/WzAes.cpp +68 -54
  462. data/ext/p7zip/CPP/7zip/Crypto/WzAes.h +37 -27
  463. data/ext/p7zip/CPP/7zip/Crypto/ZipCrypto.cpp +60 -34
  464. data/ext/p7zip/CPP/7zip/Crypto/ZipCrypto.h +28 -11
  465. data/ext/p7zip/CPP/7zip/Crypto/ZipStrong.cpp +90 -28
  466. data/ext/p7zip/CPP/7zip/Crypto/ZipStrong.h +13 -2
  467. data/ext/p7zip/CPP/7zip/Guid.txt +57 -11
  468. data/ext/p7zip/CPP/7zip/ICoder.h +202 -17
  469. data/ext/p7zip/CPP/7zip/IDecl.h +16 -3
  470. data/ext/p7zip/CPP/7zip/IPassword.h +1 -2
  471. data/ext/p7zip/CPP/7zip/IProgress.h +2 -16
  472. data/ext/p7zip/CPP/7zip/IStream.h +82 -13
  473. data/ext/p7zip/CPP/7zip/MyVersion.h +2 -11
  474. data/ext/p7zip/CPP/7zip/PropID.h +60 -9
  475. data/ext/p7zip/CPP/Common/C_FileIO.cpp +5 -1
  476. data/ext/p7zip/CPP/Common/C_FileIO.h +7 -1
  477. data/ext/p7zip/CPP/Common/CommandLineParser.cpp +122 -148
  478. data/ext/p7zip/CPP/Common/CommandLineParser.h +20 -29
  479. data/ext/p7zip/CPP/Common/Common.h +13 -0
  480. data/ext/p7zip/CPP/Common/CrcReg.cpp +98 -0
  481. data/ext/p7zip/CPP/Common/Defs.h +5 -10
  482. data/ext/p7zip/CPP/Common/DynLimBuf.cpp +93 -0
  483. data/ext/p7zip/CPP/Common/DynLimBuf.h +40 -0
  484. data/ext/p7zip/CPP/Common/DynamicBuffer.h +45 -31
  485. data/ext/p7zip/CPP/Common/IntToString.cpp +109 -40
  486. data/ext/p7zip/CPP/Common/IntToString.h +14 -9
  487. data/ext/p7zip/CPP/Common/Lang.cpp +120 -87
  488. data/ext/p7zip/CPP/Common/Lang.h +10 -15
  489. data/ext/p7zip/CPP/Common/ListFileUtils.cpp +82 -40
  490. data/ext/p7zip/CPP/Common/ListFileUtils.h +7 -4
  491. data/ext/p7zip/CPP/Common/MyBuffer.h +244 -0
  492. data/ext/p7zip/CPP/Common/MyCom.h +65 -28
  493. data/ext/p7zip/CPP/Common/MyGuidDef.h +1 -1
  494. data/ext/p7zip/CPP/Common/MyInitGuid.h +23 -0
  495. data/ext/p7zip/CPP/Common/MyLinux.h +42 -0
  496. data/ext/p7zip/CPP/Common/MyMap.cpp +8 -8
  497. data/ext/p7zip/CPP/Common/MyMap.h +2 -2
  498. data/ext/p7zip/CPP/Common/MyString.cpp +1643 -117
  499. data/ext/p7zip/CPP/Common/MyString.h +677 -486
  500. data/ext/p7zip/CPP/Common/MyTypes.h +38 -0
  501. data/ext/p7zip/CPP/Common/MyUnknown.h +4 -0
  502. data/ext/p7zip/CPP/Common/MyVector.cpp +0 -84
  503. data/ext/p7zip/CPP/Common/MyVector.h +472 -112
  504. data/ext/p7zip/CPP/Common/MyWindows.cpp +18 -1
  505. data/ext/p7zip/CPP/Common/MyWindows.h +8 -0
  506. data/ext/p7zip/CPP/Common/MyXml.cpp +169 -118
  507. data/ext/p7zip/CPP/Common/MyXml.h +14 -11
  508. data/ext/p7zip/CPP/Common/NewHandler.cpp +39 -0
  509. data/ext/p7zip/CPP/Common/NewHandler.h +55 -2
  510. data/ext/p7zip/CPP/Common/Random.h +14 -0
  511. data/ext/p7zip/CPP/Common/Sha1Reg.cpp +40 -0
  512. data/ext/p7zip/CPP/Common/Sha256Reg.cpp +40 -0
  513. data/ext/p7zip/CPP/Common/StdInStream.cpp +46 -27
  514. data/ext/p7zip/CPP/Common/StdInStream.h +11 -10
  515. data/ext/p7zip/CPP/Common/StdOutStream.cpp +48 -35
  516. data/ext/p7zip/CPP/Common/StdOutStream.h +44 -17
  517. data/ext/p7zip/CPP/Common/StringConvert.cpp +56 -17
  518. data/ext/p7zip/CPP/Common/StringConvert.h +7 -3
  519. data/ext/p7zip/CPP/Common/StringToInt.cpp +102 -48
  520. data/ext/p7zip/CPP/Common/StringToInt.h +13 -10
  521. data/ext/p7zip/CPP/Common/TextConfig.cpp +33 -47
  522. data/ext/p7zip/CPP/Common/TextConfig.h +3 -6
  523. data/ext/p7zip/CPP/Common/UTFConvert.cpp +218 -75
  524. data/ext/p7zip/CPP/Common/UTFConvert.h +4 -3
  525. data/ext/p7zip/CPP/Common/Wildcard.cpp +345 -125
  526. data/ext/p7zip/CPP/Common/Wildcard.h +82 -13
  527. data/ext/p7zip/CPP/Common/XzCrc64Reg.cpp +42 -0
  528. data/ext/p7zip/CPP/Windows/FileDir.cpp +427 -475
  529. data/ext/p7zip/CPP/Windows/FileDir.h +94 -72
  530. data/ext/p7zip/CPP/Windows/FileFind.cpp +235 -244
  531. data/ext/p7zip/CPP/Windows/FileFind.h +63 -59
  532. data/ext/p7zip/CPP/Windows/FileIO.cpp +29 -46
  533. data/ext/p7zip/CPP/Windows/FileIO.h +40 -42
  534. data/ext/p7zip/CPP/Windows/FileName.cpp +696 -17
  535. data/ext/p7zip/CPP/Windows/FileName.h +11 -3
  536. data/ext/p7zip/CPP/Windows/NtCheck.h +2 -0
  537. data/ext/p7zip/CPP/Windows/PropVariant.cpp +134 -30
  538. data/ext/p7zip/CPP/Windows/PropVariant.h +80 -24
  539. data/ext/p7zip/CPP/Windows/PropVariantUtils.cpp +89 -18
  540. data/ext/p7zip/CPP/Windows/PropVariantUtils.h +12 -7
  541. data/ext/p7zip/CPP/Windows/System.cpp +20 -15
  542. data/ext/p7zip/CPP/Windows/System.h +3 -2
  543. data/ext/p7zip/CPP/Windows/TimeUtils.cpp +203 -0
  544. data/ext/p7zip/CPP/Windows/TimeUtils.h +24 -0
  545. data/ext/p7zip/CPP/include_windows/basetyps.h +4 -4
  546. data/ext/p7zip/CPP/include_windows/windows.h +17 -11
  547. data/ext/p7zip/CPP/myWindows/StdAfx.h +97 -5
  548. data/ext/p7zip/CPP/myWindows/config.h +20 -5
  549. data/ext/p7zip/CPP/myWindows/myPrivate.h +8 -0
  550. data/ext/p7zip/CPP/myWindows/wine_date_and_time.cpp +34 -0
  551. data/ext/p7zip/ChangeLog +283 -35
  552. data/ext/p7zip/{DOCS → DOC}/7zC.txt +6 -13
  553. data/ext/p7zip/{DOCS → DOC}/License.txt +3 -2
  554. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/add.htm +93 -87
  555. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/bench.htm +88 -79
  556. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/delete.htm +62 -59
  557. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/extract.htm +96 -91
  558. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/extract_full.htm +73 -68
  559. data/ext/p7zip/DOC/MANUAL/cmdline/commands/hash.htm +65 -0
  560. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/index.htm +36 -33
  561. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/list.htm +78 -77
  562. data/ext/p7zip/DOC/MANUAL/cmdline/commands/rename.htm +51 -0
  563. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/style.css +232 -232
  564. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/test.htm +47 -46
  565. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/commands/update.htm +71 -66
  566. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/exit_codes.htm +27 -27
  567. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/index.htm +29 -29
  568. data/ext/p7zip/{DOCS/MANUAL/switches → DOC/MANUAL/cmdline}/style.css +232 -232
  569. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/ar_exclude.htm +56 -56
  570. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/ar_include.htm +80 -83
  571. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/ar_no.htm +52 -52
  572. data/ext/p7zip/DOC/MANUAL/cmdline/switches/bb.htm +61 -0
  573. data/ext/p7zip/DOC/MANUAL/cmdline/switches/bs.htm +67 -0
  574. data/ext/p7zip/DOC/MANUAL/cmdline/switches/charset.htm +61 -0
  575. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/exclude.htm +71 -60
  576. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/include.htm +89 -87
  577. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/index.htm +95 -64
  578. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/large_pages.htm +59 -50
  579. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/list_tech.htm +36 -36
  580. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/method.htm +738 -625
  581. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/output_dir.htm +53 -53
  582. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/overwrite.htm +56 -56
  583. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/password.htm +55 -54
  584. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/recurse.htm +85 -83
  585. data/ext/p7zip/DOC/MANUAL/cmdline/switches/sa.htm +58 -0
  586. data/ext/p7zip/DOC/MANUAL/cmdline/switches/scc.htm +42 -0
  587. data/ext/p7zip/DOC/MANUAL/cmdline/switches/scrc.htm +53 -0
  588. data/ext/p7zip/DOC/MANUAL/cmdline/switches/sdel.htm +39 -0
  589. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/sfx.htm +153 -156
  590. data/ext/p7zip/DOC/MANUAL/cmdline/switches/shared.htm +40 -0
  591. data/ext/p7zip/DOC/MANUAL/cmdline/switches/sni.htm +56 -0
  592. data/ext/p7zip/DOC/MANUAL/cmdline/switches/sns.htm +77 -0
  593. data/ext/p7zip/DOC/MANUAL/cmdline/switches/spf.htm +80 -0
  594. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/ssc.htm +50 -50
  595. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/stdin.htm +56 -55
  596. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/stdout.htm +54 -50
  597. data/ext/p7zip/DOC/MANUAL/cmdline/switches/stl.htm +39 -0
  598. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/stop_switch.htm +31 -31
  599. data/ext/p7zip/DOC/MANUAL/cmdline/switches/stx.htm +50 -0
  600. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline/switches}/style.css +232 -232
  601. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/type.htm +121 -83
  602. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/update.htm +177 -176
  603. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/volume.htm +49 -49
  604. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/working_dir.htm +56 -55
  605. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/switches/yes.htm +48 -48
  606. data/ext/p7zip/{DOCS/MANUAL → DOC/MANUAL/cmdline}/syntax.htm +120 -120
  607. data/ext/p7zip/DOC/MANUAL/fm/about.htm +21 -0
  608. data/ext/p7zip/DOC/MANUAL/fm/benchmark.htm +56 -0
  609. data/ext/p7zip/DOC/MANUAL/fm/index.htm +54 -0
  610. data/ext/p7zip/DOC/MANUAL/fm/menu.htm +154 -0
  611. data/ext/p7zip/DOC/MANUAL/fm/options.htm +152 -0
  612. data/ext/p7zip/DOC/MANUAL/fm/plugins/7-zip/add.htm +311 -0
  613. data/ext/p7zip/DOC/MANUAL/fm/plugins/7-zip/extract.htm +78 -0
  614. data/ext/p7zip/DOC/MANUAL/fm/plugins/7-zip/index.htm +63 -0
  615. data/ext/p7zip/DOC/MANUAL/fm/plugins/7-zip/style.css +232 -0
  616. data/ext/p7zip/DOC/MANUAL/fm/plugins/index.htm +22 -0
  617. data/ext/p7zip/DOC/MANUAL/fm/plugins/style.css +232 -0
  618. data/ext/p7zip/DOC/MANUAL/fm/style.css +232 -0
  619. data/ext/p7zip/DOC/MANUAL/general/7z.htm +117 -0
  620. data/ext/p7zip/DOC/MANUAL/general/faq.htm +125 -0
  621. data/ext/p7zip/DOC/MANUAL/general/formats.htm +100 -0
  622. data/ext/p7zip/DOC/MANUAL/general/index.htm +27 -0
  623. data/ext/p7zip/DOC/MANUAL/general/license.htm +30 -0
  624. data/ext/p7zip/DOC/MANUAL/general/performance.htm +98 -0
  625. data/ext/p7zip/DOC/MANUAL/general/style.css +232 -0
  626. data/ext/p7zip/DOC/MANUAL/general/thanks.htm +43 -0
  627. data/ext/p7zip/DOC/MANUAL/start.htm +37 -0
  628. data/ext/p7zip/DOC/MANUAL/style.css +232 -0
  629. data/ext/p7zip/DOC/Methods.txt +158 -0
  630. data/ext/p7zip/{DOCS → DOC}/copying.txt +9 -11
  631. data/ext/p7zip/DOC/lzma.txt +328 -0
  632. data/ext/p7zip/{DOCS → DOC}/readme.txt +42 -65
  633. data/ext/p7zip/{DOCS/history.txt → DOC/src-history.txt} +88 -2
  634. data/ext/p7zip/README +117 -91
  635. data/ext/p7zip/TODO +0 -2
  636. data/ext/p7zip/install.sh +31 -29
  637. data/ext/p7zip/last_error +1 -0
  638. data/ext/p7zip/makefile +29 -125
  639. data/ext/p7zip/makefile.afl +23 -0
  640. data/ext/p7zip/makefile.aix_gcc +5 -4
  641. data/ext/p7zip/makefile.android_arm +49 -0
  642. data/ext/p7zip/makefile.beos +5 -4
  643. data/ext/p7zip/makefile.common +150 -0
  644. data/ext/p7zip/makefile.crc32 +3 -3
  645. data/ext/p7zip/makefile.cygwin +5 -4
  646. data/ext/p7zip/makefile.cygwin64 +21 -0
  647. data/ext/p7zip/makefile.cygwin64_asm +22 -0
  648. data/ext/p7zip/makefile.cygwin_asm +6 -4
  649. data/ext/p7zip/makefile.cygwin_clang +21 -0
  650. data/ext/p7zip/makefile.cygwin_clang_asm +23 -0
  651. data/ext/p7zip/{makefile.djgpp_old → makefile.djgpp} +5 -4
  652. data/ext/p7zip/makefile.djgpp_watt +7 -5
  653. data/ext/p7zip/makefile.freebsd5 +5 -4
  654. data/ext/p7zip/{makefile.freebsd6 → makefile.freebsd6+} +6 -5
  655. data/ext/p7zip/makefile.glb +27 -18
  656. data/ext/p7zip/makefile.gprof +3 -2
  657. data/ext/p7zip/makefile.haiku +19 -0
  658. data/ext/p7zip/makefile.hpux-acc +3 -2
  659. data/ext/p7zip/makefile.hpux-acc_64 +3 -2
  660. data/ext/p7zip/makefile.hpux-gcc +5 -4
  661. data/ext/p7zip/makefile.linux_amd64 +5 -4
  662. data/ext/p7zip/makefile.linux_amd64_asm +12 -5
  663. data/ext/p7zip/makefile.linux_amd64_asm_icc +5 -3
  664. data/ext/p7zip/makefile.linux_amd64_sanitizer +26 -0
  665. data/ext/p7zip/makefile.linux_any_cpu +5 -4
  666. data/ext/p7zip/makefile.linux_any_cpu_gcc_4.X +7 -4
  667. data/ext/p7zip/makefile.linux_clang_amd64_asm +25 -0
  668. data/ext/p7zip/makefile.linux_clang_amd64_asm_sanitize +27 -0
  669. data/ext/p7zip/makefile.linux_cross_aarch64 +25 -0
  670. data/ext/p7zip/makefile.linux_cross_arm +7 -4
  671. data/ext/p7zip/makefile.linux_cross_djgpp +27 -0
  672. data/ext/p7zip/makefile.linux_cross_m68k +26 -0
  673. data/ext/p7zip/makefile.linux_cross_mipsel +27 -0
  674. data/ext/p7zip/makefile.linux_cross_ppc +25 -0
  675. data/ext/p7zip/makefile.linux_cross_ppc64 +25 -0
  676. data/ext/p7zip/makefile.linux_cross_ppc64le +25 -0
  677. data/ext/p7zip/makefile.linux_cross_s390x +25 -0
  678. data/ext/p7zip/makefile.linux_cross_sparc64 +25 -0
  679. data/ext/p7zip/makefile.linux_gcc6_sanitize +23 -0
  680. data/ext/p7zip/makefile.linux_gcc_2.95_no_need_for_libstdc +6 -4
  681. data/ext/p7zip/makefile.linux_other +6 -5
  682. data/ext/p7zip/makefile.linux_s390x +5 -4
  683. data/ext/p7zip/{makefile.machine_base → makefile.linux_scan-build} +5 -4
  684. data/ext/p7zip/makefile.linux_valgrind +25 -0
  685. data/ext/p7zip/{makefile.linux_clang_amd64 → makefile.linux_x32} +6 -5
  686. data/ext/p7zip/makefile.linux_x86_asm_gcc_4.X +10 -5
  687. data/ext/p7zip/makefile.linux_x86_asm_gcc_4.X_fltk +8 -4
  688. data/ext/p7zip/makefile.linux_x86_asm_gcc_mudflap_4.X +4 -2
  689. data/ext/p7zip/makefile.linux_x86_asm_icc +4 -2
  690. data/ext/p7zip/makefile.linux_x86_icc +3 -2
  691. data/ext/p7zip/makefile.macosx_arm64 +17 -0
  692. data/ext/p7zip/{makefile.macosx_32bits → makefile.macosx_gcc_32bits} +3 -2
  693. data/ext/p7zip/{makefile.macosx_32bits_asm → makefile.macosx_gcc_32bits_asm} +5 -3
  694. data/ext/p7zip/{makefile.macosx_32bits_ppc → makefile.macosx_gcc_32bits_ppc} +3 -2
  695. data/ext/p7zip/{makefile.macosx_64bits → makefile.macosx_gcc_64bits} +3 -2
  696. data/ext/p7zip/makefile.macosx_llvm_64bits +9 -3
  697. data/ext/p7zip/makefile.netbsd +5 -4
  698. data/ext/p7zip/makefile.netware_asm_gcc_3.X +6 -4
  699. data/ext/p7zip/makefile.oldmake +41 -130
  700. data/ext/p7zip/makefile.openbsd +7 -3
  701. data/ext/p7zip/makefile.openbsd_no_port +9 -5
  702. data/ext/p7zip/makefile.qnx_shared.bin +5 -4
  703. data/ext/p7zip/makefile.qnx_static +5 -4
  704. data/ext/p7zip/makefile.solaris_sparc_CC_32 +5 -4
  705. data/ext/p7zip/makefile.solaris_sparc_CC_64 +6 -4
  706. data/ext/p7zip/makefile.solaris_sparc_gcc +7 -6
  707. data/ext/p7zip/makefile.solaris_x86 +5 -4
  708. data/ext/p7zip/makefile.tru64 +5 -4
  709. data/ext/seven_zip_ruby/extconf.rb +92 -6
  710. data/ext/seven_zip_ruby/seven_zip_archive.cpp +40 -17
  711. data/ext/seven_zip_ruby/seven_zip_archive.h +1 -1
  712. data/ext/seven_zip_ruby/utils.cpp +267 -124
  713. data/ext/seven_zip_ruby/utils.h +2 -0
  714. data/lib/seven_zip_ruby/7z.dll +0 -0
  715. data/lib/seven_zip_ruby/7z.sfx +0 -0
  716. data/lib/seven_zip_ruby/7z64.dll +0 -0
  717. data/lib/seven_zip_ruby/7zCon.sfx +0 -0
  718. data/lib/seven_zip_ruby/seven_zip_reader.rb +16 -1
  719. data/lib/seven_zip_ruby/version.rb +1 -1
  720. data/p7zip/.gitignore +7 -0
  721. data/p7zip/README.txt +29 -0
  722. data/p7zip/extract.sh +134 -0
  723. data/spec/seven_zip_ruby_spec.rb +22 -13
  724. data/test/res/The Flying Spaghetti Monster.txt +3 -0
  725. data/test/res/The Three Little Pigs.txt +5 -0
  726. data/test/res/UTF_content.txt +3 -0
  727. data/test/res/test_reader_data.7z +0 -0
  728. data/test/res/test_reader_filename_cp932.7z +0 -0
  729. data/test/res/test_reader_files.7z +0 -0
  730. data/test/test_seven_zip_reader.rb +187 -0
  731. data/test/test_seven_zip_writer.rb +184 -0
  732. metadata +267 -219
  733. data/.github/workflows/test-and-release.yml +0 -43
  734. data/ext/C/Types.h +0 -254
  735. data/ext/CPP/7zip/Archive/IArchive.h +0 -234
  736. data/ext/CPP/7zip/IDecl.h +0 -15
  737. data/ext/CPP/7zip/IPassword.h +0 -24
  738. data/ext/CPP/7zip/IProgress.h +0 -33
  739. data/ext/CPP/7zip/IStream.h +0 -58
  740. data/ext/CPP/7zip/PropID.h +0 -76
  741. data/ext/CPP/Common/MyCom.h +0 -225
  742. data/ext/CPP/Common/MyGuidDef.h +0 -54
  743. data/ext/CPP/Common/MyInitGuid.h +0 -22
  744. data/ext/CPP/Common/MyUnknown.h +0 -13
  745. data/ext/CPP/Common/MyWindows.h +0 -204
  746. data/ext/CPP/Common/Types.h +0 -11
  747. data/ext/CPP/Windows/PropVariant.h +0 -56
  748. data/ext/CPP/include_windows/basetyps.h +0 -19
  749. data/ext/CPP/include_windows/tchar.h +0 -89
  750. data/ext/CPP/include_windows/windows.h +0 -194
  751. data/ext/p7zip/Asm/x64/7zCrcT8U.asm +0 -103
  752. data/ext/p7zip/Asm/x86/7zCrcT8U.asm +0 -101
  753. data/ext/p7zip/C/7zCrcT8.c +0 -43
  754. data/ext/p7zip/C/Alloc.back3 +0 -238
  755. data/ext/p7zip/C/Alloc.c.back +0 -243
  756. data/ext/p7zip/C/Alloc.c.back2 +0 -222
  757. data/ext/p7zip/C/LzmaUtil/Lzma86Dec.h +0 -51
  758. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderOutStream.cpp +0 -149
  759. data/ext/p7zip/CPP/7zip/Archive/7z/7zFolderOutStream.h +0 -58
  760. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHeader.cpp +0 -24
  761. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmHeader.h +0 -28
  762. data/ext/p7zip/CPP/7zip/Archive/Chm/ChmRegister.cpp +0 -13
  763. data/ext/p7zip/CPP/7zip/Archive/Com/ComHandler.cpp +0 -239
  764. data/ext/p7zip/CPP/7zip/Archive/Com/ComHandler.h +0 -28
  765. data/ext/p7zip/CPP/7zip/Archive/Com/ComIn.cpp +0 -389
  766. data/ext/p7zip/CPP/7zip/Archive/Com/ComIn.h +0 -119
  767. data/ext/p7zip/CPP/7zip/Archive/Com/ComRegister.cpp +0 -13
  768. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2MT.cpp +0 -240
  769. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2MT.h +0 -80
  770. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2ST.cpp +0 -239
  771. data/ext/p7zip/CPP/7zip/Archive/Common/CoderMixer2ST.h +0 -88
  772. data/ext/p7zip/CPP/7zip/Archive/Common/CrossThreadProgress.cpp +0 -15
  773. data/ext/p7zip/CPP/7zip/Archive/Common/CrossThreadProgress.h +0 -37
  774. data/ext/p7zip/CPP/7zip/Archive/DebHandler.cpp +0 -413
  775. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsHandler.cpp +0 -243
  776. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsHandler.h +0 -26
  777. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsIn.cpp +0 -480
  778. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsIn.h +0 -154
  779. data/ext/p7zip/CPP/7zip/Archive/Hfs/HfsRegister.cpp +0 -13
  780. data/ext/p7zip/CPP/7zip/Archive/Rar/RarHeader.cpp +0 -21
  781. data/ext/p7zip/CPP/7zip/Archive/Rar/RarIn.cpp +0 -478
  782. data/ext/p7zip/CPP/7zip/Archive/Rar/RarIn.h +0 -123
  783. data/ext/p7zip/CPP/7zip/Archive/Rar/RarItem.cpp +0 -55
  784. data/ext/p7zip/CPP/7zip/Archive/Rar/RarRegister.cpp +0 -13
  785. data/ext/p7zip/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp +0 -78
  786. data/ext/p7zip/CPP/7zip/Archive/Rar/RarVolumeInStream.h +0 -49
  787. data/ext/p7zip/CPP/7zip/Archive/Udf/UdfRegister.cpp +0 -13
  788. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipHeader.cpp +0 -36
  789. data/ext/p7zip/CPP/7zip/Archive/Zip/ZipItemEx.h +0 -34
  790. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7zFM.txt +0 -163
  791. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7zG.txt +0 -131
  792. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_7za.txt +0 -253
  793. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_ALL.txt +0 -32
  794. data/ext/p7zip/CPP/7zip/CMAKE/CMakeLists_Format7zFree.txt +0 -290
  795. data/ext/p7zip/CPP/7zip/CMAKE/generate.sh +0 -37
  796. data/ext/p7zip/CPP/7zip/CMAKE/generate_xcode.sh +0 -32
  797. data/ext/p7zip/CPP/7zip/Common/LockedStream.cpp +0 -23
  798. data/ext/p7zip/CPP/7zip/Common/LockedStream.h +0 -38
  799. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder1.cpp +0 -309
  800. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder1.h +0 -98
  801. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder2.cpp +0 -90
  802. data/ext/p7zip/CPP/7zip/Compress/ArjDecoder2.h +0 -59
  803. data/ext/p7zip/CPP/7zip/Compress/BranchCoder.cpp +0 -19
  804. data/ext/p7zip/CPP/7zip/Compress/BranchCoder.h +0 -44
  805. data/ext/p7zip/CPP/7zip/Compress/DllExports.cpp +0 -39
  806. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp +0 -531
  807. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp +0 -1018
  808. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h +0 -48
  809. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp +0 -311
  810. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h +0 -20
  811. data/ext/p7zip/CPP/7zip/Compress/LZMA_Alone/makefile +0 -173
  812. data/ext/p7zip/CPP/7zip/Compress/Lzx86Converter.cpp +0 -90
  813. data/ext/p7zip/CPP/7zip/Compress/Lzx86Converter.h +0 -46
  814. data/ext/p7zip/CPP/7zip/Compress/RangeCoder.h +0 -205
  815. data/ext/p7zip/CPP/7zip/Compress/RangeCoderBit.h +0 -114
  816. data/ext/p7zip/CPP/7zip/Crypto/Sha1.cpp +0 -229
  817. data/ext/p7zip/CPP/7zip/Crypto/Sha1.h +0 -68
  818. data/ext/p7zip/CPP/7zip/PREMAKE/generate.sh +0 -18
  819. data/ext/p7zip/CPP/7zip/PREMAKE/premake4.lua +0 -263
  820. data/ext/p7zip/CPP/7zip/QMAKE/7ZA/7ZA.pro +0 -228
  821. data/ext/p7zip/CPP/7zip/QMAKE/7ZA/7ZA_osx.pro +0 -228
  822. data/ext/p7zip/CPP/7zip/QMAKE/test_emul/test_emul.pro +0 -26
  823. data/ext/p7zip/CPP/7zip/TEST/TestUI/TestUI.cpp +0 -560
  824. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile +0 -33
  825. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile.depend +0 -577
  826. data/ext/p7zip/CPP/7zip/TEST/TestUI/makefile.list +0 -16
  827. data/ext/p7zip/CPP/Common/Buffer.h +0 -77
  828. data/ext/p7zip/CPP/Common/Types.h +0 -11
  829. data/ext/p7zip/CPP/Windows/COM.cpp +0 -37
  830. data/ext/p7zip/CPP/Windows/COM.h +0 -69
  831. data/ext/p7zip/CPP/Windows/Clipboard.cpp +0 -160
  832. data/ext/p7zip/CPP/Windows/Clipboard.h +0 -28
  833. data/ext/p7zip/CPP/Windows/CommonDialog.h +0 -19
  834. data/ext/p7zip/CPP/Windows/Control/ComboBox.h +0 -82
  835. data/ext/p7zip/CPP/Windows/Control/Controls.cpp +0 -515
  836. data/ext/p7zip/CPP/Windows/Control/Dialog.cpp +0 -560
  837. data/ext/p7zip/CPP/Windows/Control/Dialog.h +0 -179
  838. data/ext/p7zip/CPP/Windows/Control/DialogImpl.h +0 -73
  839. data/ext/p7zip/CPP/Windows/Control/Edit.h +0 -24
  840. data/ext/p7zip/CPP/Windows/Control/ListView.h +0 -164
  841. data/ext/p7zip/CPP/Windows/Control/ProgressBar.h +0 -34
  842. data/ext/p7zip/CPP/Windows/Control/Static.h +0 -23
  843. data/ext/p7zip/CPP/Windows/Control/StatusBar.h +0 -56
  844. data/ext/p7zip/CPP/Windows/Control/Window2.cpp +0 -211
  845. data/ext/p7zip/CPP/Windows/Control/Window2.h +0 -111
  846. data/ext/p7zip/CPP/Windows/DLL.cpp +0 -193
  847. data/ext/p7zip/CPP/Windows/DLL.h +0 -48
  848. data/ext/p7zip/CPP/Windows/Error.cpp +0 -58
  849. data/ext/p7zip/CPP/Windows/Error.h +0 -33
  850. data/ext/p7zip/CPP/Windows/Menu.h +0 -4
  851. data/ext/p7zip/CPP/Windows/PropVariantConversions.cpp +0 -142
  852. data/ext/p7zip/CPP/Windows/PropVariantConversions.h +0 -14
  853. data/ext/p7zip/CPP/Windows/Registry.cpp +0 -313
  854. data/ext/p7zip/CPP/Windows/Registry.h +0 -113
  855. data/ext/p7zip/CPP/Windows/ResourceString.h +0 -22
  856. data/ext/p7zip/CPP/Windows/Shell.h +0 -21
  857. data/ext/p7zip/CPP/Windows/Time.cpp +0 -88
  858. data/ext/p7zip/CPP/Windows/Time.h +0 -21
  859. data/ext/p7zip/CPP/Windows/Window.cpp +0 -101
  860. data/ext/p7zip/CPP/Windows/Window.h +0 -43
  861. data/ext/p7zip/CPP/myWindows/initguid.h +0 -4
  862. data/ext/p7zip/CPP/myWindows/makefile +0 -21
  863. data/ext/p7zip/CPP/myWindows/makefile.depend +0 -32
  864. data/ext/p7zip/CPP/myWindows/makefile.list +0 -28
  865. data/ext/p7zip/CPP/myWindows/myAddExeFlag.cpp +0 -20
  866. data/ext/p7zip/CPP/myWindows/myGetTickCount.cpp +0 -8
  867. data/ext/p7zip/CPP/myWindows/mySplitCommandLine.cpp +0 -82
  868. data/ext/p7zip/CPP/myWindows/test_emul.cpp +0 -745
  869. data/ext/p7zip/CPP/myWindows/wine_GetXXXDefaultLangID.cpp +0 -741
  870. data/ext/p7zip/DOCS/MANUAL/switches/charset.htm +0 -49
  871. data/ext/p7zip/DOCS/Methods.txt +0 -152
  872. data/ext/p7zip/DOCS/lzma.txt +0 -598
  873. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/ChangeLog +0 -41
  874. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/readme +0 -21
  875. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/readme.u7z +0 -30
  876. data/ext/p7zip/contrib/VirtualFileSystemForMidnightCommander/u7z +0 -133
  877. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/README +0 -21
  878. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/check/check.sh +0 -117
  879. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/check/files.tar +0 -0
  880. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/man1/p7zip.1 +0 -33
  881. data/ext/p7zip/contrib/gzip-like_CLI_wrapper_for_7z/p7zip +0 -144
  882. data/ext/p7zip/contrib/qnx630sp3/qnx630sp3-shared +0 -14
  883. data/ext/p7zip/contrib/qnx630sp3/qnx630sp3-static +0 -10
  884. data/ext/p7zip/integration_context_menu.txt +0 -51
  885. data/ext/p7zip/makefile.rules +0 -661
  886. /data/ext/p7zip/{DOCS → DOC}/7zFormat.txt +0 -0
  887. /data/ext/p7zip/{DOCS → DOC}/unRarLicense.txt +0 -0
@@ -2,15 +2,17 @@
2
2
 
3
3
  #include "StdAfx.h"
4
4
 
5
+ // #include <stdio.h>
6
+
5
7
  #include "../../../C/CpuArch.h"
6
8
 
7
- #include "Common/DynamicBuffer.h"
8
- #include "Common/ComTry.h"
9
- #include "Common/IntToString.h"
10
- #include "Common/StringConvert.h"
9
+ #include "../../Common/DynamicBuffer.h"
10
+ #include "../../Common/ComTry.h"
11
+ #include "../../Common/IntToString.h"
12
+ #include "../../Common/StringConvert.h"
11
13
 
12
- #include "Windows/PropVariantUtils.h"
13
- #include "Windows/Time.h"
14
+ #include "../../Windows/PropVariantUtils.h"
15
+ #include "../../Windows/TimeUtils.h"
14
16
 
15
17
  #include "../Common/LimitedStreams.h"
16
18
  #include "../Common/ProgressUtils.h"
@@ -24,21 +26,69 @@
24
26
  #define Get32(p) GetUi32(p)
25
27
  #define Get64(p) GetUi64(p)
26
28
 
29
+ #define G16(offs, v) v = Get16(p + (offs))
30
+ #define G32(offs, v) v = Get32(p + (offs))
31
+ #define G64(offs, v) v = Get64(p + (offs))
32
+
33
+ #define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
34
+
27
35
  using namespace NWindows;
28
36
 
29
37
  namespace NArchive {
30
38
  namespace NPe {
31
39
 
32
- #define NUM_SCAN_SECTIONS_MAX (1 << 6)
40
+ static const UInt32 k_Signature32 = 0x00004550;
41
+
42
+ static HRESULT CalcCheckSum(ISequentialInStream *stream, UInt32 size, UInt32 excludePos, UInt32 &res)
43
+ {
44
+ const UInt32 kBufSizeMax = (UInt32)1 << 16;
45
+ UInt32 bufSize = MyMin(kBufSizeMax, size);
46
+ bufSize += (bufSize & 1);
47
+ CByteBuffer buffer(bufSize);
48
+ Byte *buf = buffer;
49
+ UInt32 sum = 0;
50
+ UInt32 pos = 0;
51
+ for (;;)
52
+ {
53
+ UInt32 rem = size - pos;
54
+ if (rem > bufSize)
55
+ rem = bufSize;
56
+ if (rem == 0)
57
+ break;
58
+ size_t processed = rem;
59
+ RINOK(ReadStream(stream, buf, &processed));
60
+
61
+ if ((processed & 1) != 0)
62
+ buf[processed] = 0;
63
+
64
+ for (unsigned j = 0; j < 4; j++)
65
+ {
66
+ UInt32 e = excludePos + j;
67
+ if (pos <= e)
68
+ {
69
+ e -= pos;
70
+ if (e < processed)
71
+ buf[e] = 0;
72
+ }
73
+ }
33
74
 
34
- #define PE_SIG 0x00004550
35
- #define PE_OptHeader_Magic_32 0x10B
36
- #define PE_OptHeader_Magic_64 0x20B
75
+ for (size_t i = 0; i < processed; i += 2)
76
+ {
77
+ sum += Get16(buf + i);
78
+ sum = (sum + (sum >> 16)) & 0xFFFF;
79
+ }
80
+ pos += (UInt32)processed;
81
+ if (rem != processed)
82
+ break;
83
+ }
84
+ res = sum + pos;
85
+ return S_OK;
86
+ }
37
87
 
38
88
  static AString GetDecString(UInt32 v)
39
89
  {
40
- char sz[32];
41
- ConvertUInt64ToString(v, sz);
90
+ char sz[16];
91
+ ConvertUInt32ToString(v, sz);
42
92
  return sz;
43
93
  }
44
94
 
@@ -47,65 +97,80 @@ struct CVersion
47
97
  UInt16 Major;
48
98
  UInt16 Minor;
49
99
 
50
- void Parse(const Byte *buf);
51
- AString GetString() const { return GetDecString(Major) + '.' + GetDecString(Minor); }
100
+ void Parse(const Byte *p)
101
+ {
102
+ G16(0, Major);
103
+ G16(2, Minor);
104
+ }
105
+ void ToProp(NCOM::CPropVariant &prop);
52
106
  };
53
107
 
54
- void CVersion::Parse(const Byte *p)
108
+ void CVersion::ToProp(NCOM::CPropVariant &prop)
55
109
  {
56
- Major = Get16(p);
57
- Minor = Get16(p + 2);
110
+ char sz[32];
111
+ ConvertUInt32ToString(Major, sz);
112
+ unsigned len = MyStringLen(sz);
113
+ sz[len] = '.';
114
+ ConvertUInt32ToString(Minor, sz + len + 1);
115
+ prop = sz;
58
116
  }
59
117
 
60
- static const UInt32 kHeaderSize = 4 + 20;
118
+ static const unsigned kHeaderSize = 4 + 20;
119
+ static const unsigned k_OptHeader32_Size_MIN = 96;
120
+ static const unsigned k_OptHeader64_Size_MIN = 112;
121
+
122
+ static const UInt32 PE_IMAGE_FILE_DLL = (1 << 13);
61
123
 
62
124
  struct CHeader
63
125
  {
126
+ UInt16 Machine;
64
127
  UInt16 NumSections;
65
128
  UInt32 Time;
66
129
  UInt32 PointerToSymbolTable;
67
130
  UInt32 NumSymbols;
68
131
  UInt16 OptHeaderSize;
69
132
  UInt16 Flags;
70
- UInt16 Machine;
71
133
 
72
- bool Parse(const Byte *buf);
134
+ bool Parse(const Byte *p);
135
+ bool IsDll() const { return (Flags & PE_IMAGE_FILE_DLL) != 0; }
73
136
  };
74
137
 
75
138
  bool CHeader::Parse(const Byte *p)
76
139
  {
77
- if (Get32(p) != PE_SIG)
140
+ if (Get32(p) != k_Signature32)
78
141
  return false;
79
142
  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;
143
+ G16( 0, Machine);
144
+ G16( 2, NumSections);
145
+ G32( 4, Time);
146
+ G32( 8, PointerToSymbolTable);
147
+ G32(12, NumSymbols);
148
+ G16(16, OptHeaderSize);
149
+ G16(18, Flags);
150
+ return OptHeaderSize >= k_OptHeader32_Size_MIN;
88
151
  }
89
152
 
90
153
  struct CDirLink
91
154
  {
92
155
  UInt32 Va;
93
156
  UInt32 Size;
94
- void Parse(const Byte *p);
157
+
158
+ CDirLink(): Va(0), Size(0) {}
159
+ void Parse(const Byte *p)
160
+ {
161
+ G32(0, Va);
162
+ G32(4, Size);
163
+ }
95
164
  };
96
165
 
97
- void CDirLink::Parse(const Byte *p)
98
- {
99
- Va = Get32(p);
100
- Size = Get32(p + 4);
101
- }
102
-
103
166
  enum
104
167
  {
105
168
  kDirLink_Certificate = 4,
106
169
  kDirLink_Debug = 6
107
170
  };
108
171
 
172
+ static const UInt32 kNumDirItemsMax = 16;
173
+
109
174
  struct CDebugEntry
110
175
  {
111
176
  UInt32 Flags;
@@ -116,21 +181,25 @@ struct CDebugEntry
116
181
  UInt32 Va;
117
182
  UInt32 Pa;
118
183
 
119
- void Parse(const Byte *p);
184
+ void Parse(const Byte *p)
185
+ {
186
+ G32(0, Flags);
187
+ G32(4, Time);
188
+ Ver.Parse(p + 8);
189
+ G32(12, Type);
190
+ G32(16, Size);
191
+ G32(20, Va);
192
+ G32(24, Pa);
193
+ }
120
194
  };
121
195
 
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
- }
196
+ static const UInt32 k_CheckSum_Field_Offset = 64;
132
197
 
133
- static const UInt32 kNumDirItemsMax = 16;
198
+ static const UInt32 PE_OptHeader_Magic_32 = 0x10B;
199
+ static const UInt32 PE_OptHeader_Magic_64 = 0x20B;
200
+
201
+ static const UInt32 k_SubSystems_EFI_First = 10;
202
+ static const UInt32 k_SubSystems_EFI_Last = 13;
134
203
 
135
204
  struct COptHeader
136
205
  {
@@ -173,15 +242,24 @@ struct COptHeader
173
242
 
174
243
  int GetNumFileAlignBits() const
175
244
  {
176
- for (int i = 9; i <= 16; i++)
245
+ for (unsigned i = 0; i <= 31; i++)
177
246
  if (((UInt32)1 << i) == FileAlign)
178
247
  return i;
179
248
  return -1;
180
249
  }
250
+
251
+ bool IsSybSystem_EFI() const
252
+ {
253
+ return
254
+ SubSystem >= k_SubSystems_EFI_First &&
255
+ SubSystem <= k_SubSystems_EFI_Last;
256
+ }
181
257
  };
182
258
 
183
259
  bool COptHeader::Parse(const Byte *p, UInt32 size)
184
260
  {
261
+ if (size < k_OptHeader32_Size_MIN)
262
+ return false;
185
263
  Magic = Get16(p);
186
264
  switch (Magic)
187
265
  {
@@ -194,19 +272,14 @@ bool COptHeader::Parse(const Byte *p, UInt32 size)
194
272
  LinkerVerMajor = p[2];
195
273
  LinkerVerMinor = p[3];
196
274
 
197
- bool hdr64 = Is64Bit();
275
+ G32( 4, CodeSize);
276
+ G32( 8, InitDataSize);
277
+ G32(12, UninitDataSize);
278
+ // G32(16, AddressOfEntryPoint);
279
+ // G32(20, BaseOfCode);
198
280
 
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);
281
+ G32(32, SectAlign);
282
+ G32(36, FileAlign);
210
283
 
211
284
  OsVer.Parse(p + 40);
212
285
  ImageVer.Parse(p + 44);
@@ -214,28 +287,39 @@ bool COptHeader::Parse(const Byte *p, UInt32 size)
214
287
 
215
288
  // reserved = Get32(p + 52);
216
289
 
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);
290
+ G32(56, ImageSize);
291
+ G32(60, HeadersSize);
292
+ G32(64, CheckSum);
293
+ G16(68, SubSystem);
294
+ G16(70, DllCharacts);
222
295
 
223
- if (hdr64)
296
+ UInt32 pos;
297
+ if (Is64Bit())
224
298
  {
225
- StackReserve = Get64(p + 72);
226
- StackCommit = Get64(p + 80);
227
- HeapReserve = Get64(p + 88);
228
- HeapCommit = Get64(p + 96);
299
+ if (size < k_OptHeader64_Size_MIN)
300
+ return false;
301
+ // BaseOfData32 = 0;
302
+ G64(24, ImageBase);
303
+ G64(72, StackReserve);
304
+ G64(80, StackCommit);
305
+ G64(88, HeapReserve);
306
+ G64(96, HeapCommit);
307
+ pos = 108;
229
308
  }
230
309
  else
231
310
  {
232
- StackReserve = Get32(p + 72);
233
- StackCommit = Get32(p + 76);
234
- HeapReserve = Get32(p + 80);
235
- HeapCommit = Get32(p + 84);
311
+ // G32(24, BaseOfData32);
312
+ G32(28, ImageBase);
313
+ G32(72, StackReserve);
314
+ G32(76, StackCommit);
315
+ G32(80, HeapReserve);
316
+ G32(84, HeapCommit);
317
+ pos = 92;
236
318
  }
237
- UInt32 pos = (hdr64 ? 108 : 92);
238
- NumDirItems = Get32(p + pos);
319
+
320
+ G32(pos, NumDirItems);
321
+ if (NumDirItems > (1 << 16))
322
+ return false;
239
323
  pos += 4;
240
324
  if (pos + 8 * NumDirItems != size)
241
325
  return false;
@@ -257,45 +341,49 @@ struct CSection
257
341
  UInt32 Flags;
258
342
  UInt32 Time;
259
343
  // UInt16 NumRelocs;
260
- bool IsDebug;
261
344
  bool IsRealSect;
345
+ bool IsDebug;
262
346
  bool IsAdditionalSection;
263
347
 
264
348
  CSection(): IsRealSect(false), IsDebug(false), IsAdditionalSection(false) {}
265
- UInt64 GetPackSize() const { return PSize; }
266
349
 
267
- void UpdateTotalSize(UInt32 &totalSize)
350
+ const UInt32 GetSizeExtract() const { return PSize; }
351
+ const UInt32 GetSizeMin() const { return MyMin(PSize, VSize); }
352
+
353
+ void UpdateTotalSize(UInt32 &totalSize) const
268
354
  {
269
355
  UInt32 t = Pa + PSize;
270
- if (t > totalSize)
356
+ if (totalSize < t)
271
357
  totalSize = t;
272
358
  }
359
+
273
360
  void Parse(const Byte *p);
361
+
362
+ int Compare(const CSection &s) const
363
+ {
364
+ RINOZ(MyCompare(Pa, s.Pa));
365
+ UInt32 size1 = GetSizeExtract();
366
+ UInt32 size2 = s.GetSizeExtract();
367
+ return MyCompare(size1, size2);
368
+ }
274
369
  };
275
370
 
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); }
371
+ static const unsigned kNameSize = 8;
278
372
 
279
- static AString GetName(const Byte *name)
373
+ static void GetName(const Byte *name, AString &res)
280
374
  {
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;
375
+ res.SetFrom_CalcLen((const char *)name, kNameSize);
288
376
  }
289
377
 
290
378
  void CSection::Parse(const Byte *p)
291
379
  {
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);
380
+ GetName(p, Name);
381
+ G32( 8, VSize);
382
+ G32(12, Va);
383
+ G32(16, PSize);
384
+ G32(20, Pa);
385
+ // G16(32, NumRelocs);
386
+ G32(36, Flags);
299
387
  }
300
388
 
301
389
  static const CUInt32PCharPair g_HeaderCharacts[] =
@@ -352,6 +440,7 @@ static const CUInt32PCharPair g_SectFlags[] =
352
440
  static const CUInt32PCharPair g_MachinePairs[] =
353
441
  {
354
442
  { 0x014C, "x86" },
443
+ { 0x014D, "I860" },
355
444
  { 0x0162, "MIPS-R3000" },
356
445
  { 0x0166, "MIPS-R4000" },
357
446
  { 0x0168, "MIPS-R10000" },
@@ -364,24 +453,31 @@ static const CUInt32PCharPair g_MachinePairs[] =
364
453
  { 0x01A8, "SH5" },
365
454
  { 0x01C0, "ARM" },
366
455
  { 0x01C2, "ARM-Thumb" },
456
+ { 0x01C4, "ARM-NT" },
457
+ { 0x01D3, "AM33" },
367
458
  { 0x01F0, "PPC" },
368
459
  { 0x01F1, "PPC-FP" },
369
460
  { 0x0200, "IA-64" },
461
+ { 0x0266, "MIPS-16" },
370
462
  { 0x0284, "Alpha-64" },
371
- { 0x0200, "IA-64" },
372
- { 0x0366, "MIPSFPU" },
463
+ { 0x0366, "MIPS-FPU" },
464
+ { 0x0466, "MIPS-FPU16" },
465
+ { 0x0520, "TriCore" },
466
+ { 0x0CEF, "CEF" },
467
+ { 0x0EBC, "EFI" },
373
468
  { 0x8664, "x64" },
374
- { 0x0EBC, "EFI" }
469
+ { 0x9041, "M32R" },
470
+ { 0xC0EE, "CEE" }
375
471
  };
376
472
 
377
473
  static const CUInt32PCharPair g_SubSystems[] =
378
474
  {
379
- { 0, "Unknown" },
380
- { 1, "Native" },
381
- { 2, "Windows GUI" },
382
- { 3, "Windows CUI" },
383
- { 7, "Posix" },
384
- { 9, "Windows CE" },
475
+ { 0, "Unknown" },
476
+ { 1, "Native" },
477
+ { 2, "Windows GUI" },
478
+ { 3, "Windows CUI" },
479
+ { 7, "Posix" },
480
+ { 9, "Windows CE" },
385
481
  { 10, "EFI" },
386
482
  { 11, "EFI Boot" },
387
483
  { 12, "EFI Runtime" },
@@ -389,37 +485,37 @@ static const CUInt32PCharPair g_SubSystems[] =
389
485
  { 14, "XBOX" }
390
486
  };
391
487
 
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"
488
+ static const char * const g_ResTypes[] =
489
+ {
490
+ NULL
491
+ , "CURSOR"
492
+ , "BITMAP"
493
+ , "ICON"
494
+ , "MENU"
495
+ , "DIALOG"
496
+ , "STRING"
497
+ , "FONTDIR"
498
+ , "FONT"
499
+ , "ACCELERATOR"
500
+ , "RCDATA"
501
+ , "MESSAGETABLE"
502
+ , "GROUP_CURSOR"
503
+ , NULL
504
+ , "GROUP_ICON"
505
+ , NULL
506
+ , "VERSION"
507
+ , "DLGINCLUDE"
508
+ , NULL
509
+ , "PLUGPLAY"
510
+ , "VXD"
511
+ , "ANICURSOR"
512
+ , "ANIICON"
513
+ , "HTML"
514
+ , "MANIFEST"
419
515
  };
420
516
 
421
- const UInt32 kFlag = (UInt32)1 << 31;
422
- const UInt32 kMask = ~kFlag;
517
+ static const UInt32 kFlag = (UInt32)1 << 31;
518
+ static const UInt32 kMask = ~kFlag;
423
519
 
424
520
  struct CTableItem
425
521
  {
@@ -428,8 +524,8 @@ struct CTableItem
428
524
  };
429
525
 
430
526
 
431
- const UInt32 kBmpHeaderSize = 14;
432
- const UInt32 kIconHeaderSize = 22;
527
+ static const UInt32 kBmpHeaderSize = 14;
528
+ static const UInt32 kIconHeaderSize = 22;
433
529
 
434
530
  struct CResItem
435
531
  {
@@ -450,45 +546,107 @@ struct CResItem
450
546
  bool IsIcon() const { return Type == 3; }
451
547
  bool IsString() const { return Type == 6; }
452
548
  bool IsRcData() const { return Type == 10; }
549
+ bool IsVersion() const { return Type == 16; }
453
550
  bool IsRcDataOrUnknown() const { return IsRcData() || Type > 64; }
454
551
  };
455
552
 
456
- struct CStringItem
553
+ struct CTextFile
457
554
  {
458
- UInt32 Lang;
459
- UInt32 Size;
460
555
  CByteDynamicBuffer Buf;
461
556
 
557
+ size_t FinalSize() const { return Buf.GetPos(); }
558
+
462
559
  void AddChar(Byte c);
463
560
  void AddWChar(UInt16 c);
561
+ void AddWChar_Smart(UInt16 c);
562
+ void NewLine();
563
+ void AddString(const char *s);
564
+ void AddSpaces(int num);
565
+ void AddBytes(const Byte *p, size_t size)
566
+ {
567
+ Buf.AddData(p, size);
568
+ }
569
+
570
+ void OpenBlock(int num)
571
+ {
572
+ AddSpaces(num);
573
+ AddChar('{');
574
+ NewLine();
575
+ }
576
+ void CloseBlock(int num)
577
+ {
578
+ AddSpaces(num);
579
+ AddChar('}');
580
+ NewLine();
581
+ }
464
582
  };
465
583
 
466
- void CStringItem::AddChar(Byte c)
584
+ void CTextFile::AddChar(Byte c)
467
585
  {
468
- Buf.EnsureCapacity(Size + 2);
469
- Buf[Size++] = c;
470
- Buf[Size++] = 0;
586
+ Byte *p = Buf.GetCurPtrAndGrow(2);
587
+ p[0] = c;
588
+ p[1] = 0;
471
589
  }
472
590
 
473
- void CStringItem::AddWChar(UInt16 c)
591
+ void CTextFile::AddWChar(UInt16 c)
592
+ {
593
+ Byte *p = Buf.GetCurPtrAndGrow(2);
594
+ SetUi16(p, c);
595
+ }
596
+
597
+ void CTextFile::AddWChar_Smart(UInt16 c)
474
598
  {
475
599
  if (c == '\n')
476
600
  {
477
601
  AddChar('\\');
478
602
  c = 'n';
479
603
  }
480
- Buf.EnsureCapacity(Size + 2);
481
- SetUi16(Buf + Size, c);
482
- Size += 2;
604
+ AddWChar(c);
605
+ }
606
+
607
+ void CTextFile::NewLine()
608
+ {
609
+ AddChar(0x0D);
610
+ AddChar(0x0A);
611
+ }
612
+
613
+ void CTextFile::AddString(const char *s)
614
+ {
615
+ for (;; s++)
616
+ {
617
+ char c = *s;
618
+ if (c == 0)
619
+ return;
620
+ AddChar(c);
621
+ }
483
622
  }
484
623
 
624
+ void CTextFile::AddSpaces(int num)
625
+ {
626
+ for (int i = 0; i < num; i++)
627
+ AddChar(' ');
628
+ }
629
+
630
+ struct CStringItem: public CTextFile
631
+ {
632
+ UInt32 Lang;
633
+ };
634
+
635
+ struct CByteBuffer_WithLang: public CByteBuffer
636
+ {
637
+ UInt32 Lang;
638
+ };
639
+
640
+
485
641
  struct CMixItem
486
642
  {
487
643
  int SectionIndex;
488
644
  int ResourceIndex;
489
645
  int StringIndex;
646
+ int VersionIndex;
490
647
 
491
- bool IsSectionItem() const { return ResourceIndex < 0 && StringIndex < 0; };
648
+ CMixItem(): SectionIndex(-1), ResourceIndex(-1), StringIndex(-1), VersionIndex(-1) {}
649
+ bool IsSectionItem() const { return ResourceIndex < 0 && StringIndex < 0 && VersionIndex < 0; }
492
650
  };
493
651
 
494
652
  struct CUsedBitmap
@@ -498,113 +656,95 @@ public:
498
656
  void Alloc(size_t size)
499
657
  {
500
658
  size = (size + 7) / 8;
501
- Buf.SetCapacity(size);
659
+ Buf.Alloc(size);
502
660
  memset(Buf, 0, size);
503
661
  }
662
+
504
663
  void Free()
505
664
  {
506
- Buf.SetCapacity(0);
665
+ Buf.Free();
507
666
  }
508
- bool SetRange(size_t from, int size)
667
+
668
+ bool SetRange(size_t from, unsigned size)
509
669
  {
510
- for (int i = 0; i < size; i++)
670
+ for (unsigned i = 0; i < size; i++)
511
671
  {
512
672
  size_t pos = (from + i) >> 3;
513
673
  Byte mask = (Byte)(1 << ((from + i) & 7));
514
674
  Byte b = Buf[pos];
515
675
  if ((b & mask) != 0)
516
676
  return false;
517
- Buf[pos] = b | mask;
677
+ Buf[pos] = (Byte)(b | mask);
518
678
  }
519
679
  return true;
520
680
  }
521
681
  };
522
682
 
683
+ struct CStringKeyValue
684
+ {
685
+ UString Key;
686
+ UString Value;
687
+ };
523
688
 
524
689
  class CHandler:
525
690
  public IInArchive,
526
691
  public IInArchiveGetStream,
692
+ public IArchiveAllowTail,
527
693
  public CMyUnknownImp
528
694
  {
529
695
  CMyComPtr<IInStream> _stream;
530
696
  CObjectVector<CSection> _sections;
531
697
  UInt32 _peOffset;
532
698
  CHeader _header;
533
- COptHeader _optHeader;
534
699
  UInt32 _totalSize;
535
- UInt32 _totalSizeLimited;
536
700
  Int32 _mainSubfile;
537
701
 
702
+ CRecordVector<CMixItem> _mixItems;
538
703
  CRecordVector<CResItem> _items;
539
704
  CObjectVector<CStringItem> _strings;
705
+ CObjectVector<CByteBuffer_WithLang> _versionFiles;
706
+ UString _versionFullString;
707
+ UString _versionShortString;
708
+ UString _originalFilename;
709
+ CObjectVector<CStringKeyValue> _versionKeys;
540
710
 
541
711
  CByteBuffer _buf;
542
712
  bool _oneLang;
543
- UString _resourceFileName;
713
+ UString _resourcesPrefix;
544
714
  CUsedBitmap _usedRes;
545
715
  bool _parseResources;
716
+ bool _checksumError;
546
717
 
547
- CRecordVector<CMixItem> _mixItems;
718
+ COptHeader _optHeader;
719
+
720
+ bool _allowTail;
548
721
 
549
722
  HRESULT LoadDebugSections(IInStream *stream, bool &thereIsSection);
550
723
  HRESULT Open2(IInStream *stream, IArchiveOpenCallback *callback);
551
- bool Parse(const Byte *buf, UInt32 size);
552
724
 
553
725
  void AddResNameToString(UString &s, UInt32 id) const;
554
- UString GetLangPrefix(UInt32 lang);
726
+ void AddLangPrefix(UString &s, UInt32 lang) const;
555
727
  HRESULT ReadString(UInt32 offset, UString &dest) const;
556
728
  HRESULT ReadTable(UInt32 offset, CRecordVector<CTableItem> &items);
557
729
  bool ParseStringRes(UInt32 id, UInt32 lang, const Byte *src, UInt32 size);
558
- HRESULT OpenResources(int sectIndex, IInStream *stream, IArchiveOpenCallback *callback);
730
+ HRESULT OpenResources(unsigned sectIndex, IInStream *stream, IArchiveOpenCallback *callback);
559
731
  void CloseResources();
560
732
 
561
733
 
562
734
  bool CheckItem(const CSection &sect, const CResItem &item, size_t offset) const
563
735
  {
564
- return item.Offset >= sect.Va && offset <= _buf.GetCapacity() && _buf.GetCapacity() - offset >= item.Size;
736
+ return item.Offset >= sect.Va && offset <= _buf.Size() && _buf.Size() - offset >= item.Size;
565
737
  }
566
738
 
567
739
  public:
568
- MY_UNKNOWN_IMP2(IInArchive, IInArchiveGetStream)
740
+ CHandler(): _allowTail(false) {}
741
+
742
+ MY_UNKNOWN_IMP3(IInArchive, IInArchiveGetStream, IArchiveAllowTail)
569
743
  INTERFACE_IInArchive(;)
570
744
  STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
745
+ STDMETHOD(AllowTail)(Int32 allowTail);
571
746
  };
572
747
 
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
748
 
609
749
  enum
610
750
  {
@@ -631,56 +771,56 @@ enum
631
771
  // kpidBaseOfData32,
632
772
  };
633
773
 
634
- STATPROPSTG kArcProps[] =
774
+ static const CStatProp kArcProps[] =
635
775
  {
776
+ // { NULL, kpidWarning, VT_BSTR},
636
777
  { NULL, kpidCpu, VT_BSTR},
637
778
  { NULL, kpidBit64, VT_BOOL},
638
779
  { NULL, kpidCharacts, VT_BSTR},
639
780
  { NULL, kpidCTime, VT_FILETIME},
640
- { NULL, kpidPhySize, VT_UI4},
641
781
  { NULL, kpidHeadersSize, VT_UI4},
642
782
  { 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},
783
+ { NULL, kpidName, VT_BSTR},
784
+
785
+ { "Image Size", kpidImageSize, VT_UI4},
786
+ { "Section Alignment", kpidSectAlign, VT_UI4},
787
+ { "File Alignment", kpidFileAlign, VT_UI4},
788
+ { "Code Size", kpidCodeSize, VT_UI4},
789
+ { "Initialized Data Size", kpidInitDataSize, VT_UI4},
790
+ { "Uninitialized Data Size", kpidUnInitDataSize, VT_UI4},
791
+ { "Linker Version", kpidLinkerVer, VT_BSTR},
792
+ { "OS Version", kpidOsVer, VT_BSTR},
793
+ { "Image Version", kpidImageVer, VT_BSTR},
794
+ { "Subsystem Version", kpidSubsysVer, VT_BSTR},
795
+ { "Subsystem", kpidSubSystem, VT_BSTR},
796
+ { "DLL Characteristics", kpidDllCharacts, VT_BSTR},
797
+ { "Stack Reserve", kpidStackReserve, VT_UI8},
798
+ { "Stack Commit", kpidStackCommit, VT_UI8},
799
+ { "Heap Reserve", kpidHeapReserve, VT_UI8},
800
+ { "Heap Commit", kpidHeapCommit, VT_UI8},
801
+ { "Image Base", kpidImageBase, VT_UI8},
802
+ { NULL, kpidComment, VT_BSTR},
803
+
804
+ // { "Address Of Entry Point", kpidAddressOfEntryPoint, VT_UI8},
805
+ // { "Base Of Code", kpidBaseOfCode, VT_UI8},
806
+ // { "Base Of Data", kpidBaseOfData32, VT_UI8},
663
807
  };
664
808
 
665
- STATPROPSTG kProps[] =
809
+ static const Byte kProps[] =
666
810
  {
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}
811
+ kpidPath,
812
+ kpidSize,
813
+ kpidPackSize,
814
+ kpidVirtualSize,
815
+ kpidCharacts,
816
+ kpidOffset,
817
+ kpidVa,
673
818
  };
674
819
 
675
820
  IMP_IInArchive_Props
676
821
  IMP_IInArchive_ArcProps_WITH_NAME
677
822
 
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)
823
+ static void TimeToProp(UInt32 unixTime, NCOM::CPropVariant &prop)
684
824
  {
685
825
  if (unixTime != 0)
686
826
  {
@@ -694,20 +834,20 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
694
834
  {
695
835
  COM_TRY_BEGIN
696
836
  NCOM::CPropVariant prop;
697
- switch(propID)
837
+ switch (propID)
698
838
  {
699
839
  case kpidSectAlign: prop = _optHeader.SectAlign; break;
700
840
  case kpidFileAlign: prop = _optHeader.FileAlign; break;
701
841
  case kpidLinkerVer:
702
842
  {
703
843
  CVersion v = { _optHeader.LinkerVerMajor, _optHeader.LinkerVerMinor };
704
- VerToProp(v, prop);
844
+ v.ToProp(prop);
705
845
  break;
706
846
  }
707
847
 
708
- case kpidOsVer: VerToProp(_optHeader.OsVer, prop); break;
709
- case kpidImageVer: VerToProp(_optHeader.ImageVer, prop); break;
710
- case kpidSubsysVer: VerToProp(_optHeader.SubsysVer, prop); break;
848
+ case kpidOsVer: _optHeader.OsVer.ToProp(prop); break;
849
+ case kpidImageVer: _optHeader.ImageVer.ToProp(prop); break;
850
+ case kpidSubsysVer: _optHeader.SubsysVer.ToProp(prop); break;
711
851
  case kpidCodeSize: prop = _optHeader.CodeSize; break;
712
852
  case kpidInitDataSize: prop = _optHeader.InitDataSize; break;
713
853
  case kpidUnInitDataSize: prop = _optHeader.UninitDataSize; break;
@@ -715,7 +855,27 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
715
855
  case kpidPhySize: prop = _totalSize; break;
716
856
  case kpidHeadersSize: prop = _optHeader.HeadersSize; break;
717
857
  case kpidChecksum: prop = _optHeader.CheckSum; break;
858
+ case kpidComment: if (!_versionFullString.IsEmpty()) prop = _versionFullString; break;
859
+ case kpidShortComment:
860
+ if (!_versionShortString.IsEmpty())
861
+ prop = _versionShortString;
862
+ else
863
+ {
864
+ PAIR_TO_PROP(g_MachinePairs, _header.Machine, prop);
865
+ }
866
+ break;
867
+
868
+ case kpidName: if (!_originalFilename.IsEmpty()) prop = _originalFilename; break;
869
+ case kpidExtension:
870
+ if (_header.IsDll())
871
+ prop = _optHeader.IsSybSystem_EFI() ? "efi" : "dll";
872
+ break;
718
873
 
874
+ // case kpidIsSelfExe: prop = !_header.IsDll(); break;
875
+
876
+ // case kpidError:
877
+ case kpidWarning: if (_checksumError) prop = "Checksum error"; break;
878
+
719
879
  case kpidCpu: PAIR_TO_PROP(g_MachinePairs, _header.Machine, prop); break;
720
880
  case kpidBit64: if (_optHeader.Is64Bit()) prop = true; break;
721
881
  case kpidSubSystem: PAIR_TO_PROP(g_SubSystems, _optHeader.SubSystem, prop); break;
@@ -741,6 +901,33 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
741
901
  COM_TRY_END
742
902
  }
743
903
 
904
+ HRESULT CHandler::ReadString(UInt32 offset, UString &dest) const
905
+ {
906
+ if ((offset & 1) != 0 || offset >= _buf.Size())
907
+ return S_FALSE;
908
+ size_t rem = _buf.Size() - offset;
909
+ if (rem < 2)
910
+ return S_FALSE;
911
+ unsigned len = Get16(_buf + offset);
912
+ if ((rem - 2) / 2 < len)
913
+ return S_FALSE;
914
+ dest.Empty();
915
+ wchar_t *destBuf = dest.GetBuf(len);
916
+ offset += 2;
917
+ const Byte *src = _buf + offset;
918
+ unsigned i;
919
+ for (i = 0; i < len; i++)
920
+ {
921
+ wchar_t c = (wchar_t)Get16(src + i * 2);
922
+ if (c == 0)
923
+ break;
924
+ destBuf[i] = c;
925
+ }
926
+ destBuf[i] = 0;
927
+ dest.ReleaseBuf_SetLen(i);
928
+ return S_OK;
929
+ }
930
+
744
931
  void CHandler::AddResNameToString(UString &s, UInt32 id) const
745
932
  {
746
933
  if ((id & kFlag) != 0)
@@ -748,32 +935,33 @@ void CHandler::AddResNameToString(UString &s, UInt32 id) const
748
935
  UString name;
749
936
  if (ReadString(id & kMask, name) == S_OK)
750
937
  {
751
- if (name.IsEmpty())
752
- s += L"[]";
753
- else
938
+ const wchar_t *str = L"[]";
939
+ if (name.Len() > 1 && name[0] == '"' && name.Back() == '"')
754
940
  {
755
- if (name.Length() > 1 && name[0] == '"' && name.Back() == '"')
756
- name = name.Mid(1, name.Length() - 2);
757
- s += name;
941
+ if (name.Len() != 2)
942
+ {
943
+ name.DeleteBack();
944
+ str = name.Ptr(1);
945
+ }
758
946
  }
947
+ else if (!name.IsEmpty())
948
+ str = name;
949
+ s += str;
759
950
  return;
760
951
  }
761
952
  }
762
- wchar_t sz[32];
953
+ wchar_t sz[16];
763
954
  ConvertUInt32ToString(id, sz);
764
955
  s += sz;
765
956
  }
766
957
 
767
- UString CHandler::GetLangPrefix(UInt32 lang)
958
+ void CHandler::AddLangPrefix(UString &s, UInt32 lang) const
768
959
  {
769
- UString s = _resourceFileName;
770
- s += WCHAR_PATH_SEPARATOR;
771
960
  if (!_oneLang)
772
961
  {
773
962
  AddResNameToString(s, lang);
774
- s += WCHAR_PATH_SEPARATOR;
963
+ s.Add_PathSepar();
775
964
  }
776
- return s;
777
965
  }
778
966
 
779
967
  STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
@@ -784,55 +972,65 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
784
972
  if (mixItem.StringIndex >= 0)
785
973
  {
786
974
  const CStringItem &item = _strings[mixItem.StringIndex];
787
- switch(propID)
975
+ switch (propID)
788
976
  {
789
- case kpidPath: prop = GetLangPrefix(item.Lang) + L"string.txt"; break;
977
+ case kpidPath:
978
+ {
979
+ UString s = _resourcesPrefix;
980
+ AddLangPrefix(s, item.Lang);
981
+ s.AddAscii("string.txt");
982
+ prop = s;
983
+ break;
984
+ }
790
985
  case kpidSize:
791
986
  case kpidPackSize:
792
- prop = (UInt64)item.Size; break;
987
+ prop = (UInt64)item.FinalSize(); break;
793
988
  }
794
989
  }
795
- else if (mixItem.ResourceIndex < 0)
990
+ else if (mixItem.VersionIndex >= 0)
796
991
  {
797
- const CSection &item = _sections[mixItem.SectionIndex];
798
- switch(propID)
992
+ const CByteBuffer_WithLang &item = _versionFiles[mixItem.VersionIndex];
993
+ switch (propID)
799
994
  {
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;
995
+ case kpidPath:
996
+ {
997
+ UString s = _resourcesPrefix;
998
+ AddLangPrefix(s, item.Lang);
999
+ s.AddAscii("version.txt");
1000
+ prop = s;
1001
+ break;
1002
+ }
1003
+ case kpidSize:
1004
+ case kpidPackSize:
1005
+ prop = (UInt64)item.Size(); break;
809
1006
  }
810
1007
  }
811
- else
1008
+ else if (mixItem.ResourceIndex >= 0)
812
1009
  {
813
1010
  const CResItem &item = _items[mixItem.ResourceIndex];
814
- switch(propID)
1011
+ switch (propID)
815
1012
  {
816
1013
  case kpidPath:
817
1014
  {
818
- UString s = GetLangPrefix(item.Lang);
1015
+ UString s = _resourcesPrefix;
1016
+ AddLangPrefix(s, item.Lang);
819
1017
  {
820
- const wchar_t *p = NULL;
821
- if (item.Type < sizeof(g_ResTypes) / sizeof(g_ResTypes[0]))
1018
+ const char *p = NULL;
1019
+ if (item.Type < ARRAY_SIZE(g_ResTypes))
822
1020
  p = g_ResTypes[item.Type];
823
- if (p != 0)
824
- s += p;
1021
+ if (p)
1022
+ s.AddAscii(p);
825
1023
  else
826
1024
  AddResNameToString(s, item.Type);
827
1025
  }
828
- s += WCHAR_PATH_SEPARATOR;
1026
+ s.Add_PathSepar();
829
1027
  AddResNameToString(s, item.ID);
830
1028
  if (item.HeaderSize != 0)
831
1029
  {
832
1030
  if (item.IsBmp())
833
- s += L".bmp";
1031
+ s.AddAscii(".bmp");
834
1032
  else if (item.IsIcon())
835
- s += L".ico";
1033
+ s.AddAscii(".ico");
836
1034
  }
837
1035
  prop = s;
838
1036
  break;
@@ -841,6 +1039,24 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
841
1039
  case kpidPackSize: prop = (UInt64)item.Size; break;
842
1040
  }
843
1041
  }
1042
+ else
1043
+ {
1044
+ const CSection &item = _sections[mixItem.SectionIndex];
1045
+ switch (propID)
1046
+ {
1047
+ case kpidPath: prop = MultiByteToUnicodeString(item.Name); break;
1048
+ case kpidSize: prop = (UInt64)item.PSize; break;
1049
+ case kpidPackSize: prop = (UInt64)item.PSize; break;
1050
+ case kpidVirtualSize: prop = (UInt64)item.VSize; break;
1051
+ case kpidOffset: prop = item.Pa; break;
1052
+ case kpidVa: if (item.IsRealSect) prop = item.Va; break;
1053
+ case kpidMTime:
1054
+ case kpidCTime:
1055
+ TimeToProp(item.IsDebug ? item.Time : _header.Time, prop); break;
1056
+ case kpidCharacts: if (item.IsRealSect) FLAGS_TO_PROP(g_SectFlags, item.Flags, prop); break;
1057
+ case kpidZerosTailIsAllowed: if (!item.IsRealSect) prop = true; break;
1058
+ }
1059
+ }
844
1060
  prop.Detach(value);
845
1061
  return S_OK;
846
1062
  COM_TRY_END
@@ -858,11 +1074,11 @@ HRESULT CHandler::LoadDebugSections(IInStream *stream, bool &thereIsSection)
858
1074
  return S_FALSE;
859
1075
 
860
1076
  UInt64 pa = 0;
861
- int i;
1077
+ unsigned i;
862
1078
  for (i = 0; i < _sections.Size(); i++)
863
1079
  {
864
1080
  const CSection &sect = _sections[i];
865
- if (sect.Va < debugLink.Va && debugLink.Va + debugLink.Size <= sect.Va + sect.PSize)
1081
+ if (sect.Va <= debugLink.Va && debugLink.Va + debugLink.Size <= sect.Va + sect.PSize)
866
1082
  {
867
1083
  pa = sect.Pa + (debugLink.Va - sect.Va);
868
1084
  break;
@@ -870,19 +1086,18 @@ HRESULT CHandler::LoadDebugSections(IInStream *stream, bool &thereIsSection)
870
1086
  }
871
1087
  if (i == _sections.Size())
872
1088
  {
873
- return S_OK;
874
1089
  // Exe for ARM requires S_OK
875
1090
  // return S_FALSE;
1091
+ return S_OK;
876
1092
  }
877
1093
 
878
- CByteBuffer buffer;
879
- buffer.SetCapacity(debugLink.Size);
1094
+ CByteBuffer buffer(debugLink.Size);
880
1095
  Byte *buf = buffer;
881
1096
 
882
1097
  RINOK(stream->Seek(pa, STREAM_SEEK_SET, NULL));
883
1098
  RINOK(ReadStream_FALSE(stream, buf, debugLink.Size));
884
1099
 
885
- for (i = 0; i < (int)numItems; i++)
1100
+ for (i = 0; i < numItems; i++)
886
1101
  {
887
1102
  CDebugEntry de;
888
1103
  de.Parse(buf);
@@ -890,20 +1105,19 @@ HRESULT CHandler::LoadDebugSections(IInStream *stream, bool &thereIsSection)
890
1105
  if (de.Size == 0)
891
1106
  continue;
892
1107
 
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;
1108
+ UInt32 totalSize = de.Pa + de.Size;
902
1109
  if (totalSize > _totalSize)
903
1110
  {
904
1111
  _totalSize = totalSize;
905
- _sections.Add(sect);
906
1112
  thereIsSection = true;
1113
+
1114
+ CSection &sect = _sections.AddNew();
1115
+ sect.Name = ".debug" + GetDecString(i);
1116
+ sect.IsDebug = true;
1117
+ sect.Time = de.Time;
1118
+ sect.Va = de.Va;
1119
+ sect.Pa = de.Pa;
1120
+ sect.PSize = sect.VSize = de.Size;
907
1121
  }
908
1122
  buf += kEntrySize;
909
1123
  }
@@ -911,31 +1125,13 @@ HRESULT CHandler::LoadDebugSections(IInStream *stream, bool &thereIsSection)
911
1125
  return S_OK;
912
1126
  }
913
1127
 
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
1128
  HRESULT CHandler::ReadTable(UInt32 offset, CRecordVector<CTableItem> &items)
932
1129
  {
933
- if ((offset & 3) != 0 || offset >= _buf.GetCapacity())
1130
+ if ((offset & 3) != 0 || offset >= _buf.Size())
934
1131
  return S_FALSE;
935
- size_t rem = _buf.GetCapacity() - offset;
1132
+ size_t rem = _buf.Size() - offset;
936
1133
  if (rem < 16)
937
1134
  return S_FALSE;
938
- items.Clear();
939
1135
  unsigned numNameItems = Get16(_buf + offset + 12);
940
1136
  unsigned numIdItems = Get16(_buf + offset + 14);
941
1137
  unsigned numItems = numNameItems + numIdItems;
@@ -944,25 +1140,23 @@ HRESULT CHandler::ReadTable(UInt32 offset, CRecordVector<CTableItem> &items)
944
1140
  if (!_usedRes.SetRange(offset, 16 + numItems * 8))
945
1141
  return S_FALSE;
946
1142
  offset += 16;
947
- _oneLang = true;
948
- unsigned i;
949
- for (i = 0; i < numItems; i++)
1143
+ items.ClearAndReserve(numItems);
1144
+ for (unsigned i = 0; i < numItems; i++, offset += 8)
950
1145
  {
951
- CTableItem item;
952
1146
  const Byte *buf = _buf + offset;
953
- offset += 8;
1147
+ CTableItem item;
954
1148
  item.ID = Get32(buf + 0);
955
- if (((item.ID & kFlag) != 0) != (i < numNameItems))
1149
+ if ((bool)((item.ID & kFlag) != 0) != (bool)(i < numNameItems))
956
1150
  return S_FALSE;
957
1151
  item.Offset = Get32(buf + 4);
958
- items.Add(item);
1152
+ items.AddInReserved(item);
959
1153
  }
960
1154
  return S_OK;
961
1155
  }
962
1156
 
963
- static const UInt32 kFileSizeMax = (UInt32)1 << 30;
964
- static const int kNumResItemsMax = (UInt32)1 << 23;
965
- static const int kNumStringLangsMax = 128;
1157
+ static const UInt32 kFileSizeMax = (UInt32)1 << 31;
1158
+ static const unsigned kNumResItemsMax = (unsigned)1 << 23;
1159
+ static const unsigned kNumStringLangsMax = 256;
966
1160
 
967
1161
  // BITMAPINFOHEADER
968
1162
  struct CBitmapInfoHeader
@@ -984,12 +1178,12 @@ bool CBitmapInfoHeader::Parse(const Byte *p, size_t size)
984
1178
  {
985
1179
  if (size < kBitmapInfoHeader_Size || Get32(p) != kBitmapInfoHeader_Size)
986
1180
  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);
1181
+ G32( 4, XSize);
1182
+ G32( 8, YSize);
1183
+ G16(12, Planes);
1184
+ G16(14, BitCount);
1185
+ G32(16, Compression);
1186
+ G32(20, SizeImage);
993
1187
  return true;
994
1188
  }
995
1189
 
@@ -1005,11 +1199,14 @@ static UInt32 SetBitmapHeader(Byte *dest, const Byte *src, UInt32 size)
1005
1199
  return 0;
1006
1200
  if (h.YSize < 0)
1007
1201
  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
1202
+ if (h.XSize > (1 << 26) || h.YSize > (1 << 26) || h.Planes != 1 || h.BitCount > 32)
1010
1203
  return 0;
1011
1204
  if (h.SizeImage == 0)
1205
+ {
1206
+ if (h.Compression != 0) // BI_RGB
1207
+ return 0;
1012
1208
  h.SizeImage = GetImageSize(h.XSize, h.YSize, h.BitCount);
1209
+ }
1013
1210
  UInt32 totalSize = kBmpHeaderSize + size;
1014
1211
  UInt32 offBits = totalSize - h.SizeImage;
1015
1212
  // BITMAPFILEHEADER
@@ -1089,7 +1286,7 @@ bool CHandler::ParseStringRes(UInt32 id, UInt32 lang, const Byte *src, UInt32 si
1089
1286
  if ((size & 1) != 0)
1090
1287
  return false;
1091
1288
 
1092
- int i;
1289
+ unsigned i;
1093
1290
  for (i = 0; i < _strings.Size(); i++)
1094
1291
  if (_strings[i].Lang == lang)
1095
1292
  break;
@@ -1097,10 +1294,8 @@ bool CHandler::ParseStringRes(UInt32 id, UInt32 lang, const Byte *src, UInt32 si
1097
1294
  {
1098
1295
  if (_strings.Size() >= kNumStringLangsMax)
1099
1296
  return false;
1100
- CStringItem item;
1101
- item.Size = 0;
1297
+ CStringItem &item = _strings.AddNew();
1102
1298
  item.Lang = lang;
1103
- i = _strings.Add(item);
1104
1299
  }
1105
1300
 
1106
1301
  CStringItem &item = _strings[i];
@@ -1117,52 +1312,658 @@ bool CHandler::ParseStringRes(UInt32 id, UInt32 lang, const Byte *src, UInt32 si
1117
1312
  if (size - pos < len * 2)
1118
1313
  return false;
1119
1314
  char temp[32];
1120
- ConvertUInt32ToString(id + i, temp);
1315
+ ConvertUInt32ToString(id + i, temp);
1121
1316
  size_t tempLen = strlen(temp);
1122
1317
  size_t j;
1123
1318
  for (j = 0; j < tempLen; j++)
1124
1319
  item.AddChar(temp[j]);
1125
1320
  item.AddChar('\t');
1126
1321
  for (j = 0; j < len; j++, pos += 2)
1127
- item.AddWChar(Get16(src + pos));
1128
- item.AddChar(0x0D);
1129
- item.AddChar(0x0A);
1322
+ item.AddWChar_Smart(Get16(src + pos));
1323
+ item.NewLine();
1130
1324
  }
1131
1325
  }
1132
- return (size == pos);
1326
+ if (size == pos)
1327
+ return true;
1328
+
1329
+ // Some rare case files have additional ZERO.
1330
+ if (size == pos + 2 && Get16(src + pos) == 0)
1331
+ return true;
1332
+
1333
+ return false;
1133
1334
  }
1134
1335
 
1135
- HRESULT CHandler::OpenResources(int sectionIndex, IInStream *stream, IArchiveOpenCallback *callback)
1336
+
1337
+ // ---------- VERSION ----------
1338
+
1339
+ static const UInt32 kMy_VS_FFI_SIGNATURE = 0xFEEF04BD;
1340
+
1341
+ struct CMy_VS_FIXEDFILEINFO
1136
1342
  {
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));
1343
+ // UInt32 Signature;
1344
+ // UInt32 StrucVersion;
1345
+ UInt32 VersionMS;
1346
+ UInt32 VersionLS;
1347
+ UInt32 ProductVersionMS;
1348
+ UInt32 ProductVersionLS;
1349
+ UInt32 FlagsMask;
1350
+ UInt32 Flags;
1351
+ UInt32 OS;
1352
+ UInt32 Type;
1353
+ UInt32 Subtype;
1354
+ UInt32 DateMS;
1355
+ UInt32 DateLS;
1161
1356
 
1162
- _oneLang = true;
1357
+ bool Parse(const Byte *p);
1358
+ void PrintToTextFile(CTextFile &f, CObjectVector<CStringKeyValue> &keys);
1359
+ };
1360
+
1361
+ bool CMy_VS_FIXEDFILEINFO::Parse(const Byte *p)
1362
+ {
1363
+ if (Get32(p) != kMy_VS_FFI_SIGNATURE) // signature;
1364
+ return false;
1365
+ // G32(0x04, StrucVersion);
1366
+ G32(0x08, VersionMS);
1367
+ G32(0x0C, VersionLS);
1368
+ G32(0x10, ProductVersionMS);
1369
+ G32(0x14, ProductVersionLS);
1370
+ G32(0x18, FlagsMask);
1371
+ G32(0x1C, Flags);
1372
+ G32(0x20, OS);
1373
+ G32(0x24, Type);
1374
+ G32(0x28, Subtype);
1375
+ G32(0x2C, DateMS);
1376
+ G32(0x40, DateLS);
1377
+ return true;
1378
+ }
1379
+
1380
+ static void PrintUInt32(CTextFile &f, UInt32 v)
1381
+ {
1382
+ char s[16];
1383
+ ConvertUInt32ToString(v, s);
1384
+ f.AddString(s);
1385
+ }
1386
+
1387
+ static void PrintUInt32(UString &dest, UInt32 v)
1388
+ {
1389
+ wchar_t s[16];
1390
+ ConvertUInt32ToString(v, s);
1391
+ dest += s;
1392
+ }
1393
+
1394
+ static void PrintHex(CTextFile &f, UInt32 val)
1395
+ {
1396
+ char temp[16];
1397
+ temp[0] = '0';
1398
+ temp[1] = 'x';
1399
+ ConvertUInt32ToHex(val, temp + 2);
1400
+ f.AddString(temp);
1401
+ }
1402
+
1403
+ static void PrintVersion(CTextFile &f, UInt32 ms, UInt32 ls)
1404
+ {
1405
+ PrintUInt32(f, HIWORD(ms)); f.AddChar(',');
1406
+ PrintUInt32(f, LOWORD(ms)); f.AddChar(',');
1407
+ PrintUInt32(f, HIWORD(ls)); f.AddChar(',');
1408
+ PrintUInt32(f, LOWORD(ls));
1409
+ }
1410
+
1411
+ static void PrintVersion(UString &s, UInt32 ms, UInt32 ls)
1412
+ {
1413
+ PrintUInt32(s, HIWORD(ms)); s += L'.';
1414
+ PrintUInt32(s, LOWORD(ms)); s += L'.';
1415
+ PrintUInt32(s, HIWORD(ls)); s += L'.';
1416
+ PrintUInt32(s, LOWORD(ls));
1417
+ }
1418
+
1419
+ static const char * const k_VS_FileFlags[] =
1420
+ {
1421
+ "DEBUG"
1422
+ , "PRERELEASE"
1423
+ , "PATCHED"
1424
+ , "PRIVATEBUILD"
1425
+ , "INFOINFERRED"
1426
+ , "SPECIALBUILD"
1427
+ };
1428
+
1429
+ static const CUInt32PCharPair k_VS_FileOS[] =
1430
+ {
1431
+ { 0x10001, "VOS_DOS_WINDOWS16" },
1432
+ { 0x10004, "VOS_DOS_WINDOWS32" },
1433
+ { 0x20002, "VOS_OS216_PM16" },
1434
+ { 0x30003, "VOS_OS232_PM32" },
1435
+ { 0x40004, "VOS_NT_WINDOWS32" }
1436
+ };
1437
+
1438
+ static const char * const k_VS_FileOS_High[] =
1439
+ {
1440
+ "VOS_UNKNOWN"
1441
+ , "VOS_DOS"
1442
+ , "VOS_OS216"
1443
+ , "VOS_OS232"
1444
+ , "VOS_NT"
1445
+ , "VOS_WINCE"
1446
+ };
1447
+
1448
+ static const UInt32 kMY_VFT_DRV = 3;
1449
+ static const UInt32 kMY_VFT_FONT = 4;
1450
+
1451
+ static const char * const k_VS_FileOS_Low[] =
1452
+ {
1453
+ "VOS__BASE"
1454
+ , "VOS__WINDOWS16"
1455
+ , "VOS__PM16"
1456
+ , "VOS__PM32"
1457
+ , "VOS__WINDOWS32"
1458
+ };
1459
+
1460
+ static const char * const k_VS_FileType[] =
1461
+ {
1462
+ "VFT_UNKNOWN"
1463
+ , "VFT_APP"
1464
+ , "VFT_DLL"
1465
+ , "VFT_DRV"
1466
+ , "VFT_FONT"
1467
+ , "VFT_VXD"
1468
+ , "0x6"
1469
+ , "VFT_STATIC_LIB"
1470
+ };
1471
+
1472
+ // Subtype for VFT_DRV Type
1473
+ static const char * const k_VS_FileSubType_DRV[] =
1474
+ {
1475
+ "0"
1476
+ , "PRINTER"
1477
+ , "KEYBOARD"
1478
+ , "LANGUAGE"
1479
+ , "DISPLAY"
1480
+ , "MOUSE"
1481
+ , "NETWORK"
1482
+ , "SYSTEM"
1483
+ , "INSTALLABLE"
1484
+ , "SOUND"
1485
+ , "COMM"
1486
+ , "INPUTMETHOD"
1487
+ , "VERSIONED_PRINTER"
1488
+ };
1489
+
1490
+ // Subtype for VFT_FONT Type
1491
+ static const char * const k_VS_FileSubType_FONT[] =
1492
+ {
1493
+ "0"
1494
+ , "VFT2_FONT_RASTER"
1495
+ , "VFT2_FONT_VECTOR"
1496
+ , "VFT2_FONT_TRUETYPE"
1497
+ };
1498
+
1499
+ static int FindKey(CObjectVector<CStringKeyValue> &v, const char *key)
1500
+ {
1501
+ FOR_VECTOR (i, v)
1502
+ if (v[i].Key.IsEqualTo(key))
1503
+ return i;
1504
+ return -1;
1505
+ }
1506
+
1507
+ static void AddToUniqueUStringVector(CObjectVector<CStringKeyValue> &v, const UString &key, const UString &value)
1508
+ {
1509
+ bool needInsert = false;
1510
+ unsigned i;
1511
+ for (i = 0; i < v.Size(); i++)
1512
+ {
1513
+ if (v[i].Key == key)
1514
+ {
1515
+ if (v[i].Value == value)
1516
+ return;
1517
+ needInsert = true;
1518
+ }
1519
+ else if (needInsert)
1520
+ break;
1521
+ }
1522
+ CStringKeyValue &pair = v.InsertNew(i);
1523
+ pair.Key = key;
1524
+ pair.Value = value;
1525
+ }
1526
+
1527
+ void CMy_VS_FIXEDFILEINFO::PrintToTextFile(CTextFile &f, CObjectVector<CStringKeyValue> &keys)
1528
+ {
1529
+ f.AddString("FILEVERSION ");
1530
+ PrintVersion(f, VersionMS, VersionLS);
1531
+ f.NewLine();
1532
+
1533
+ f.AddString("PRODUCTVERSION ");
1534
+ PrintVersion(f, ProductVersionMS, ProductVersionLS);
1535
+ f.NewLine();
1536
+
1537
+ {
1538
+ UString s;
1539
+ PrintVersion(s, VersionMS, VersionLS);
1540
+ AddToUniqueUStringVector(keys, L"FileVersion", s);
1541
+ }
1542
+ {
1543
+ UString s;
1544
+ PrintVersion(s, ProductVersionMS, ProductVersionLS);
1545
+ AddToUniqueUStringVector(keys, L"ProductVersion", s);
1546
+ }
1547
+
1548
+ f.AddString("FILEFLAGSMASK ");
1549
+ PrintHex(f, FlagsMask);
1550
+ f.NewLine();
1551
+
1552
+ f.AddString("FILEFLAGS ");
1553
+ {
1554
+ bool wasPrinted = false;
1555
+ for (unsigned i = 0; i < ARRAY_SIZE(k_VS_FileFlags); i++)
1556
+ {
1557
+ if ((Flags & ((UInt32)1 << i)) != 0)
1558
+ {
1559
+ if (wasPrinted)
1560
+ f.AddString(" | ");
1561
+ f.AddString("VS_FF_");
1562
+ f.AddString(k_VS_FileFlags[i]);
1563
+ wasPrinted = true;
1564
+ }
1565
+ }
1566
+ UInt32 v = Flags & ~(((UInt32)1 << ARRAY_SIZE(k_VS_FileFlags)) - 1);
1567
+ if (v != 0 || !wasPrinted)
1568
+ {
1569
+ if (wasPrinted)
1570
+ f.AddString(" | ");
1571
+ PrintHex(f, v);
1572
+ }
1573
+ }
1574
+ f.NewLine();
1575
+
1576
+ // OS = 0x111230;
1577
+ f.AddString("FILEOS ");
1578
+ unsigned i;
1579
+ for (i = 0; i < ARRAY_SIZE(k_VS_FileOS); i++)
1580
+ {
1581
+ const CUInt32PCharPair &pair = k_VS_FileOS[i];
1582
+ if (OS == pair.Value)
1583
+ {
1584
+ // continue;
1585
+ // f.AddString("VOS_");
1586
+ f.AddString(pair.Name);
1587
+ break;
1588
+ }
1589
+ }
1590
+ if (i == ARRAY_SIZE(k_VS_FileOS))
1591
+ {
1592
+ UInt32 high = OS >> 16;
1593
+ if (high < ARRAY_SIZE(k_VS_FileOS_High))
1594
+ f.AddString(k_VS_FileOS_High[high]);
1595
+ else
1596
+ PrintHex(f, high << 16);
1597
+ UInt32 low = OS & 0xFFFF;
1598
+ if (low != 0)
1599
+ {
1600
+ f.AddString(" | ");
1601
+ if (low < ARRAY_SIZE(k_VS_FileOS_Low))
1602
+ f.AddString(k_VS_FileOS_Low[low]);
1603
+ else
1604
+ PrintHex(f, low);
1605
+ }
1606
+ }
1607
+ f.NewLine();
1608
+
1609
+ f.AddString("FILETYPE ");
1610
+ if (Type < ARRAY_SIZE(k_VS_FileType))
1611
+ f.AddString(k_VS_FileType[Type]);
1612
+ else
1613
+ PrintHex(f, Type);
1614
+ f.NewLine();
1615
+
1616
+ f.AddString("FILESUBTYPE ");
1617
+ bool needPrintSubType = true;
1618
+ if (Type == kMY_VFT_DRV)
1619
+ {
1620
+ if (Subtype != 0 && Subtype < ARRAY_SIZE(k_VS_FileSubType_DRV))
1621
+ {
1622
+ f.AddString("VFT2_DRV_");
1623
+ f.AddString(k_VS_FileSubType_DRV[Subtype]);
1624
+ needPrintSubType = false;
1625
+ }
1626
+ }
1627
+ else if (Type == kMY_VFT_FONT)
1628
+ {
1629
+ if (Subtype != 0 && Subtype < ARRAY_SIZE(k_VS_FileSubType_FONT))
1630
+ {
1631
+ f.AddString(k_VS_FileSubType_FONT[Subtype]);
1632
+ needPrintSubType = false;
1633
+ }
1634
+ }
1635
+ if (needPrintSubType)
1636
+ PrintHex(f, Subtype);
1637
+ f.NewLine();
1638
+ }
1639
+
1640
+ static void CopyToUString(const Byte *p, UString &s)
1641
+ {
1642
+ for (;;)
1643
+ {
1644
+ wchar_t c = (wchar_t)Get16(p);
1645
+ p += 2;
1646
+ if (c == 0)
1647
+ return;
1648
+ s += c;
1649
+ }
1650
+ }
1651
+
1652
+ static bool CompareWStrStrings(const Byte *p, const char *s)
1653
+ {
1654
+ unsigned pos = 0;
1655
+ for (;;)
1656
+ {
1657
+ Byte c = *s++;
1658
+ if (Get16(p + pos) != c)
1659
+ return false;
1660
+ pos += 2;
1661
+ if (c == 0)
1662
+ return true;
1663
+ }
1664
+ }
1665
+
1666
+ struct CVersionBlock
1667
+ {
1668
+ UInt32 TotalLen;
1669
+ UInt32 ValueLen;
1670
+ bool IsTextValue;
1671
+ unsigned StrSize;
1672
+
1673
+ bool Parse(const Byte *p, UInt32 size);
1674
+ };
1675
+
1676
+ static int Get_Utf16Str_Len_InBytes(const Byte *p, size_t size)
1677
+ {
1678
+ unsigned pos = 0;
1679
+ for (;;)
1680
+ {
1681
+ if (pos + 1 >= size)
1682
+ return -1;
1683
+ if (Get16(p + pos) == 0)
1684
+ return pos;
1685
+ pos += 2;
1686
+ }
1687
+ }
1688
+
1689
+ static const unsigned k_ResoureBlockHeader_Size = 6;
1690
+
1691
+ bool CVersionBlock::Parse(const Byte *p, UInt32 size)
1692
+ {
1693
+ if (size < k_ResoureBlockHeader_Size)
1694
+ return false;
1695
+ TotalLen = Get16(p);
1696
+ ValueLen = Get16(p + 2);
1697
+ if (TotalLen == 0 || TotalLen > size)
1698
+ return false;
1699
+ switch (Get16(p + 4))
1700
+ {
1701
+ case 0: IsTextValue = false; break;
1702
+ case 1: IsTextValue = true; break;
1703
+ default: return false;
1704
+ }
1705
+ StrSize = 0;
1706
+ int t = Get_Utf16Str_Len_InBytes(p + k_ResoureBlockHeader_Size, TotalLen - k_ResoureBlockHeader_Size);
1707
+ if (t < 0)
1708
+ return false;
1709
+ StrSize = t;
1710
+ return true;
1711
+ }
1712
+
1713
+ static void AddParamString(CTextFile &f, const Byte *p, size_t sLen)
1714
+ {
1715
+ f.AddChar(' ');
1716
+ f.AddChar('\"');
1717
+ f.AddBytes(p, sLen);
1718
+ f.AddChar('\"');
1719
+ }
1720
+
1721
+ static bool ParseVersion(const Byte *p, UInt32 size, CTextFile &f, CObjectVector<CStringKeyValue> &keys)
1722
+ {
1723
+ UInt32 pos;
1724
+ {
1725
+ const unsigned k_sizeof_VS_FIXEDFILEINFO = 13 * 4;
1726
+
1727
+ CVersionBlock vb;
1728
+ if (!vb.Parse(p, size))
1729
+ return false;
1730
+ if (vb.ValueLen != k_sizeof_VS_FIXEDFILEINFO) // maybe 0 is allowed here?
1731
+ return false;
1732
+ if (vb.IsTextValue)
1733
+ return false;
1734
+ pos = k_ResoureBlockHeader_Size;
1735
+ if (!CompareWStrStrings(p + pos, "VS_VERSION_INFO"))
1736
+ return false;
1737
+ pos += vb.StrSize + 2;
1738
+ pos += (4 - pos) & 3;
1739
+ if (pos + vb.ValueLen > vb.TotalLen)
1740
+ return false;
1741
+ /* sometimes resource contains zeros in remainder.
1742
+ So we don't check that size != vb.TotalLen
1743
+ // if (size != vb.TotalLen) return false;
1744
+ */
1745
+ if (size > vb.TotalLen)
1746
+ size = vb.TotalLen;
1747
+ CMy_VS_FIXEDFILEINFO FixedFileInfo;
1748
+ if (!FixedFileInfo.Parse(p + pos))
1749
+ return false;
1750
+ FixedFileInfo.PrintToTextFile(f, keys);
1751
+ pos += vb.ValueLen;
1752
+ }
1753
+
1754
+ f.OpenBlock(0);
1755
+
1756
+ for (;;)
1757
+ {
1758
+ pos += (4 - pos) & 3;
1759
+ if (pos >= size)
1760
+ break;
1761
+
1762
+ CVersionBlock vb;
1763
+ if (!vb.Parse(p + pos, size - pos))
1764
+ return false;
1765
+ if (vb.ValueLen != 0)
1766
+ return false;
1767
+ UInt32 endPos = pos + vb.TotalLen;
1768
+ pos += k_ResoureBlockHeader_Size;
1769
+
1770
+ f.AddSpaces(2);
1771
+ f.AddString("BLOCK");
1772
+ AddParamString(f, p + pos, vb.StrSize);
1773
+
1774
+ f.NewLine();
1775
+ f.OpenBlock(2);
1776
+
1777
+ if (CompareWStrStrings(p + pos, "VarFileInfo"))
1778
+ {
1779
+ pos += vb.StrSize + 2;
1780
+ for (;;)
1781
+ {
1782
+ pos += (4 - pos) & 3;
1783
+ if (pos >= endPos)
1784
+ break;
1785
+ CVersionBlock vb2;
1786
+ if (!vb2.Parse(p + pos, endPos - pos))
1787
+ return false;
1788
+ UInt32 endPos2 = pos + vb2.TotalLen;
1789
+ if (vb2.IsTextValue)
1790
+ return false;
1791
+ pos += k_ResoureBlockHeader_Size;
1792
+ f.AddSpaces(4);
1793
+ f.AddString("VALUE");
1794
+ AddParamString(f, p + pos, vb2.StrSize);
1795
+ if (!CompareWStrStrings(p + pos, "Translation"))
1796
+ return false;
1797
+ pos += vb2.StrSize + 2;
1798
+ pos += (4 - pos) & 3;
1799
+ if (pos + vb2.ValueLen != endPos2)
1800
+ return false;
1801
+ if ((vb2.ValueLen & 3) != 0)
1802
+ return false;
1803
+ UInt32 num = (vb2.ValueLen >> 2);
1804
+ for (; num != 0; num--, pos += 4)
1805
+ {
1806
+ UInt32 dw = Get32(p + pos);
1807
+ UInt32 lang = LOWORD(dw);
1808
+ UInt32 codePage = HIWORD(dw);
1809
+
1810
+ f.AddString(", ");
1811
+ PrintHex(f, lang);
1812
+ f.AddString(", ");
1813
+ PrintUInt32(f, codePage);
1814
+ }
1815
+ f.NewLine();
1816
+ }
1817
+ }
1818
+ else
1819
+ {
1820
+ if (!CompareWStrStrings(p + pos, "StringFileInfo"))
1821
+ return false;
1822
+ pos += vb.StrSize + 2;
1823
+
1824
+ for (;;)
1825
+ {
1826
+ pos += (4 - pos) & 3;
1827
+ if (pos >= endPos)
1828
+ break;
1829
+ CVersionBlock vb2;
1830
+ if (!vb2.Parse(p + pos, endPos - pos))
1831
+ return false;
1832
+ UInt32 endPos2 = pos + vb2.TotalLen;
1833
+ if (vb2.ValueLen != 0)
1834
+ return false;
1835
+ pos += k_ResoureBlockHeader_Size;
1836
+
1837
+ f.AddSpaces(4);
1838
+ f.AddString("BLOCK");
1839
+ AddParamString(f, p + pos, vb2.StrSize);
1840
+ pos += vb2.StrSize + 2;
1841
+
1842
+ f.NewLine();
1843
+ f.OpenBlock(4);
1844
+
1845
+ for (;;)
1846
+ {
1847
+ pos += (4 - pos) & 3;
1848
+ if (pos >= endPos2)
1849
+ break;
1850
+
1851
+ CVersionBlock vb3;
1852
+ if (!vb3.Parse(p + pos, endPos2 - pos))
1853
+ return false;
1854
+ // ValueLen sometimes is a number of characters (not bytes)?
1855
+ // So we don't use it.
1856
+ UInt32 endPos3 = pos + vb3.TotalLen;
1857
+ pos += k_ResoureBlockHeader_Size;
1858
+
1859
+ // we don't write string if it's not text
1860
+ if (vb3.IsTextValue)
1861
+ {
1862
+ f.AddSpaces(6);
1863
+ f.AddString("VALUE");
1864
+ AddParamString(f, p + pos, vb3.StrSize);
1865
+ UString key;
1866
+ UString value;
1867
+ CopyToUString(p + pos, key);
1868
+ pos += vb3.StrSize + 2;
1869
+
1870
+ pos += (4 - pos) & 3;
1871
+ if (vb3.ValueLen > 0 && pos + 2 <= endPos3)
1872
+ {
1873
+ f.AddChar(',');
1874
+ f.AddSpaces((34 - (int)vb3.StrSize) / 2);
1875
+ int sLen = Get_Utf16Str_Len_InBytes(p + pos, endPos3 - pos);
1876
+ if (sLen < 0)
1877
+ return false;
1878
+ AddParamString(f, p + pos, (unsigned)sLen);
1879
+ CopyToUString(p + pos, value);
1880
+ pos += sLen + 2;
1881
+ }
1882
+ AddToUniqueUStringVector(keys, key, value);
1883
+ }
1884
+ pos = endPos3;
1885
+ f.NewLine();
1886
+ }
1887
+ f.CloseBlock(4);
1888
+ }
1889
+ }
1890
+ f.CloseBlock(2);
1891
+ }
1892
+
1893
+ f.CloseBlock(0);
1894
+ return true;
1895
+ }
1896
+
1897
+
1898
+ HRESULT CHandler::OpenResources(unsigned sectionIndex, IInStream *stream, IArchiveOpenCallback *callback)
1899
+ {
1900
+ const CSection &sect = _sections[sectionIndex];
1901
+ size_t fileSize = sect.PSize;
1902
+ {
1903
+ size_t fileSizeMin = sect.PSize;
1904
+
1905
+ if (sect.VSize < sect.PSize)
1906
+ {
1907
+ fileSize = fileSizeMin = sect.VSize;
1908
+ const int numBits = _optHeader.GetNumFileAlignBits();
1909
+ if (numBits > 0)
1910
+ {
1911
+ const UInt32 mask = ((UInt32)1 << numBits) - 1;
1912
+ const size_t end = (size_t)((sect.VSize + mask) & (UInt32)~mask);
1913
+ if (end > sect.VSize)
1914
+ if (end <= sect.PSize)
1915
+ fileSize = end;
1916
+ else
1917
+ fileSize = sect.PSize;
1918
+ }
1919
+ }
1920
+
1921
+ if (fileSize > kFileSizeMax)
1922
+ return S_FALSE;
1923
+
1924
+ {
1925
+ const UInt64 fileSize64 = fileSize;
1926
+ if (callback)
1927
+ RINOK(callback->SetTotal(NULL, &fileSize64));
1928
+ }
1929
+
1930
+ RINOK(stream->Seek(sect.Pa, STREAM_SEEK_SET, NULL));
1931
+
1932
+ _buf.Alloc(fileSize);
1933
+
1934
+ size_t pos;
1935
+
1936
+ for (pos = 0; pos < fileSize;)
1937
+ {
1938
+ {
1939
+ const UInt64 offset64 = pos;
1940
+ if (callback)
1941
+ RINOK(callback->SetCompleted(NULL, &offset64))
1942
+ }
1943
+ size_t rem = MyMin(fileSize - pos, (size_t)(1 << 22));
1944
+ RINOK(ReadStream(stream, _buf + pos, &rem));
1945
+ if (rem == 0)
1946
+ {
1947
+ if (pos < fileSizeMin)
1948
+ return S_FALSE;
1949
+ break;
1950
+ }
1951
+ pos += rem;
1952
+ }
1953
+
1954
+ if (pos < fileSize)
1955
+ memset(_buf + pos, 0, fileSize - pos);
1956
+ }
1957
+
1958
+ _usedRes.Alloc(fileSize);
1959
+ CRecordVector<CTableItem> specItems;
1960
+ RINOK(ReadTable(0, specItems));
1961
+
1962
+ _oneLang = true;
1163
1963
  bool stringsOk = true;
1164
1964
  size_t maxOffset = 0;
1165
- for (int i = 0; i < specItems.Size(); i++)
1965
+
1966
+ FOR_VECTOR (i, specItems)
1166
1967
  {
1167
1968
  const CTableItem &item1 = specItems[i];
1168
1969
  if ((item1.Offset & kFlag) == 0)
@@ -1171,7 +1972,7 @@ HRESULT CHandler::OpenResources(int sectionIndex, IInStream *stream, IArchiveOpe
1171
1972
  CRecordVector<CTableItem> specItems2;
1172
1973
  RINOK(ReadTable(item1.Offset & kMask, specItems2));
1173
1974
 
1174
- for (int j = 0; j < specItems2.Size(); j++)
1975
+ FOR_VECTOR (j, specItems2)
1175
1976
  {
1176
1977
  const CTableItem &item2 = specItems2[j];
1177
1978
  if ((item2.Offset & kFlag) == 0)
@@ -1184,14 +1985,14 @@ HRESULT CHandler::OpenResources(int sectionIndex, IInStream *stream, IArchiveOpe
1184
1985
  item.Type = item1.ID;
1185
1986
  item.ID = item2.ID;
1186
1987
 
1187
- for (int k = 0; k < specItems3.Size(); k++)
1988
+ FOR_VECTOR (k, specItems3)
1188
1989
  {
1189
1990
  if (_items.Size() >= kNumResItemsMax)
1190
1991
  return S_FALSE;
1191
1992
  const CTableItem &item3 = specItems3[k];
1192
1993
  if ((item3.Offset & kFlag) != 0)
1193
1994
  return S_FALSE;
1194
- if (item3.Offset >= _buf.GetCapacity() || _buf.GetCapacity() - item3.Offset < 16)
1995
+ if (item3.Offset >= _buf.Size() || _buf.Size() - item3.Offset < 16)
1195
1996
  return S_FALSE;
1196
1997
  const Byte *buf = _buf + item3.Offset;
1197
1998
  item.Lang = item3.ID;
@@ -1225,6 +2026,25 @@ HRESULT CHandler::OpenResources(int sectionIndex, IInStream *stream, IArchiveOpe
1225
2026
  }
1226
2027
  }
1227
2028
 
2029
+ if (item.IsVersion())
2030
+ {
2031
+ if (offset > _buf.Size() || _buf.Size() - offset < item.Size)
2032
+ continue;
2033
+ CTextFile f;
2034
+ if (ParseVersion((const Byte *)_buf + offset, item.Size, f, _versionKeys))
2035
+ {
2036
+ CMixItem mixItem;
2037
+ mixItem.VersionIndex = _versionFiles.Size();
2038
+ mixItem.SectionIndex = sectionIndex; // check it !!!!
2039
+ CByteBuffer_WithLang &vf = _versionFiles.AddNew();
2040
+ vf.Lang = item.Lang;
2041
+ vf.CopyFrom(f.Buf, f.Buf.GetPos());
2042
+ _mixItems.Add(mixItem);
2043
+ continue;
2044
+ }
2045
+ // PrintError("ver.Parse error");
2046
+ }
2047
+
1228
2048
  item.Enabled = true;
1229
2049
  _items.Add(item);
1230
2050
  }
@@ -1233,7 +2053,7 @@ HRESULT CHandler::OpenResources(int sectionIndex, IInStream *stream, IArchiveOpe
1233
2053
 
1234
2054
  if (stringsOk && !_strings.IsEmpty())
1235
2055
  {
1236
- int i;
2056
+ unsigned i;
1237
2057
  for (i = 0; i < _items.Size(); i++)
1238
2058
  {
1239
2059
  CResItem &item = _items[i];
@@ -1242,10 +2062,9 @@ HRESULT CHandler::OpenResources(int sectionIndex, IInStream *stream, IArchiveOpe
1242
2062
  }
1243
2063
  for (i = 0; i < _strings.Size(); i++)
1244
2064
  {
1245
- if (_strings[i].Size == 0)
2065
+ if (_strings[i].FinalSize() == 0)
1246
2066
  continue;
1247
2067
  CMixItem mixItem;
1248
- mixItem.ResourceIndex = -1;
1249
2068
  mixItem.StringIndex = i;
1250
2069
  mixItem.SectionIndex = sectionIndex;
1251
2070
  _mixItems.Add(mixItem);
@@ -1254,15 +2073,13 @@ HRESULT CHandler::OpenResources(int sectionIndex, IInStream *stream, IArchiveOpe
1254
2073
 
1255
2074
  _usedRes.Free();
1256
2075
 
1257
- int numBits = _optHeader.GetNumFileAlignBits();
1258
- if (numBits >= 0)
1259
2076
  {
1260
- UInt32 mask = (1 << numBits) - 1;
1261
- size_t end = ((maxOffset + mask) & ~mask);
1262
- if (end < sect.VSize && end <= sect.PSize)
2077
+ // PSize can be much larger than VSize in some exe installers.
2078
+ // it contains archive data after PE resources.
2079
+ // So we need to use PSize here!
2080
+ if (maxOffset < sect.PSize)
1263
2081
  {
1264
- CSection sect2;
1265
- sect2.Flags = 0;
2082
+ size_t end = fileSize;
1266
2083
 
1267
2084
  // we skip Zeros to start of aligned block
1268
2085
  size_t i;
@@ -1272,78 +2089,168 @@ HRESULT CHandler::OpenResources(int sectionIndex, IInStream *stream, IArchiveOpe
1272
2089
  if (i == end)
1273
2090
  maxOffset = end;
1274
2091
 
2092
+ CSection sect2;
2093
+ sect2.Flags = 0;
1275
2094
  sect2.Pa = sect.Pa + (UInt32)maxOffset;
1276
2095
  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);
2096
+
2097
+ // 9.29: we use sect.PSize instead of sect.VSize to support some CAB-SFX
2098
+ // the code for .rsrc_2 is commented.
2099
+ sect2.PSize = sect.PSize - (UInt32)maxOffset;
2100
+
2101
+ if (sect2.PSize != 0)
2102
+ {
2103
+ sect2.VSize = sect2.PSize;
2104
+ sect2.Name = ".rsrc_1";
2105
+ sect2.Time = 0;
2106
+ sect2.IsAdditionalSection = true;
2107
+ _sections.Add(sect2);
2108
+ }
1283
2109
  }
1284
2110
  }
1285
2111
 
1286
2112
  return S_OK;
1287
2113
  }
1288
2114
 
1289
- HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
2115
+ static inline bool CheckPeOffset(UInt32 pe)
1290
2116
  {
1291
- const UInt32 kBufSize = 1 << 18;
1292
- const UInt32 kSigSize = 2;
1293
-
1294
- _mainSubfile = -1;
2117
+ return (pe >= 0x40 && pe <= 0x1000 && (pe & 7) == 0);
2118
+ }
1295
2119
 
1296
- CByteBuffer buffer;
1297
- buffer.SetCapacity(kBufSize);
1298
- Byte *buf = buffer;
2120
+ static const unsigned kStartSize = 0x40;
1299
2121
 
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));
2122
+ API_FUNC_static_IsArc IsArc_Pe(const Byte *p, size_t size)
2123
+ {
2124
+ if (size < 2)
2125
+ return k_IsArc_Res_NEED_MORE;
2126
+ if (p[0] != 'M' || p[1] != 'Z')
2127
+ return k_IsArc_Res_NO;
2128
+ if (size < kStartSize)
2129
+ return k_IsArc_Res_NEED_MORE;
2130
+ UInt32 pe = Get32(p + 0x3C);
2131
+ if (!CheckPeOffset(pe))
2132
+ return k_IsArc_Res_NO;
2133
+ if (pe + kHeaderSize > size)
2134
+ return k_IsArc_Res_NEED_MORE;
2135
+ CHeader header;
2136
+ if (!header.Parse(p + pe))
2137
+ return k_IsArc_Res_NO;
2138
+ return k_IsArc_Res_YES;
2139
+ }
2140
+ }
1311
2141
 
1312
- const CDirLink &certLink = _optHeader.DirItems[kDirLink_Certificate];
1313
- if (certLink.Size != 0)
2142
+ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
2143
+ {
1314
2144
  {
1315
- CSection sect;
2145
+ Byte h[kStartSize];
2146
+ _mainSubfile = -1;
2147
+ RINOK(ReadStream_FALSE(stream, h, kStartSize));
2148
+ if (h[0] != 'M' || h[1] != 'Z')
2149
+ return S_FALSE;
2150
+ /* most of PE files contain 0x0090 at offset 2.
2151
+ But some rare PE files contain another values. So we don't use that check.
2152
+ if (Get16(h + 2) != 0x90) return false; */
2153
+ _peOffset = Get32(h + 0x3C);
2154
+ if (!CheckPeOffset(_peOffset))
2155
+ return S_FALSE;
2156
+ }
2157
+ {
2158
+ Byte h[kHeaderSize];
2159
+ RINOK(stream->Seek(_peOffset, STREAM_SEEK_SET, NULL));
2160
+ RINOK(ReadStream_FALSE(stream, h, kHeaderSize));
2161
+ if (!_header.Parse(h))
2162
+ return S_FALSE;
2163
+ }
2164
+
2165
+ UInt32 bufSize = _header.OptHeaderSize + (UInt32)_header.NumSections * kSectionSize;
2166
+ _totalSize = _peOffset + kHeaderSize + bufSize;
2167
+ CByteBuffer buffer(bufSize);
2168
+
2169
+ RINOK(ReadStream_FALSE(stream, buffer, bufSize));
2170
+ if (!_optHeader.Parse(buffer, _header.OptHeaderSize))
2171
+ return S_FALSE;
2172
+
2173
+ UInt32 pos = _header.OptHeaderSize;
2174
+ unsigned i;
2175
+ for (i = 0; i < _header.NumSections; i++, pos += kSectionSize)
2176
+ {
2177
+ CSection &sect = _sections.AddNew();
2178
+ sect.Parse(buffer + pos);
2179
+ sect.IsRealSect = true;
2180
+
2181
+ /* PE pre-file in .hxs file has errors:
2182
+ PSize of resource is larger tnan real size.
2183
+ So it overlaps next ".its" section.
2184
+ We correct it. */
2185
+
2186
+ if (i > 0)
2187
+ {
2188
+ CSection &prev = _sections[i - 1];
2189
+ if (prev.Pa < sect.Pa &&
2190
+ prev.Pa + prev.PSize > sect.Pa &&
2191
+ sect.PSize > 0)
2192
+ {
2193
+ // printf("\n !!!! Section correction: %s\n ", prev.Name);
2194
+ // fflush(stdout);
2195
+ prev.PSize = sect.Pa - prev.Pa;
2196
+ }
2197
+ }
2198
+ /* last ".its" section in hxs file has incorrect sect.PSize.
2199
+ So we reduce it to real sect.VSize */
2200
+ if (sect.VSize == 24 && sect.PSize == 512 && i == (unsigned)_header.NumSections - 1)
2201
+ sect.PSize = sect.VSize;
2202
+ }
2203
+
2204
+ for (i = 0; i < _sections.Size(); i++)
2205
+ _sections[i].UpdateTotalSize(_totalSize);
2206
+
2207
+ bool thereISDebug;
2208
+ RINOK(LoadDebugSections(stream, thereISDebug));
2209
+
2210
+ const CDirLink &certLink = _optHeader.DirItems[kDirLink_Certificate];
2211
+ if (certLink.Size != 0)
2212
+ {
2213
+ CSection &sect = _sections.AddNew();
1316
2214
  sect.Name = "CERTIFICATE";
1317
2215
  sect.Va = 0;
1318
2216
  sect.Pa = certLink.Va;
1319
2217
  sect.PSize = sect.VSize = certLink.Size;
1320
2218
  sect.UpdateTotalSize(_totalSize);
1321
- _sections.Add(sect);
1322
2219
  }
1323
2220
 
1324
2221
  if (thereISDebug)
1325
2222
  {
2223
+ /* sometime there is some data after debug section.
2224
+ We don't see any reference in exe file to that data.
2225
+ But we suppose that it's part of EXE file */
2226
+
1326
2227
  const UInt32 kAlign = 1 << 12;
1327
2228
  UInt32 alignPos = _totalSize & (kAlign - 1);
1328
2229
  if (alignPos != 0)
1329
2230
  {
1330
2231
  UInt32 size = kAlign - alignPos;
1331
2232
  RINOK(stream->Seek(_totalSize, STREAM_SEEK_SET, NULL));
1332
- buffer.Free();
1333
- buffer.SetCapacity(kAlign);
2233
+ buffer.Alloc(kAlign);
1334
2234
  Byte *buf = buffer;
1335
2235
  size_t processed = size;
1336
2236
  RINOK(ReadStream(stream, buf, &processed));
1337
- size_t i;
1338
- for (i = 0; i < processed; i++)
2237
+
2238
+ /*
2239
+ if (processed != 0)
1339
2240
  {
1340
- if (buf[i] != 0)
1341
- break;
2241
+ printf("\ndata after debug %d, %d \n", (int)size, (int)processed);
2242
+ fflush(stdout);
1342
2243
  }
2244
+ */
2245
+
2246
+ size_t k;
2247
+ for (k = 0; k < processed; k++)
2248
+ if (buf[k] != 0)
2249
+ break;
1343
2250
  if (processed < size && processed < 100)
1344
2251
  _totalSize += (UInt32)processed;
1345
- else if (((_totalSize + i) & 0x1FF) == 0 || processed < size)
1346
- _totalSize += (UInt32)i;
2252
+ else if (((_totalSize + k) & 0x1FF) == 0 || processed < size)
2253
+ _totalSize += (UInt32)k;
1347
2254
  }
1348
2255
  }
1349
2256
 
@@ -1351,8 +2258,6 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
1351
2258
  {
1352
2259
  if (_header.NumSymbols >= (1 << 24))
1353
2260
  return S_FALSE;
1354
- CSection sect;
1355
- sect.Name = "COFF_SYMBOLS";
1356
2261
  UInt32 size = _header.NumSymbols * 18;
1357
2262
  RINOK(stream->Seek((UInt64)_header.PointerToSymbolTable + size, STREAM_SEEK_SET, NULL));
1358
2263
  Byte buf[4];
@@ -1362,38 +2267,31 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
1362
2267
  return S_FALSE;
1363
2268
  size += size2;
1364
2269
 
2270
+ CSection &sect = _sections.AddNew();
2271
+ sect.Name = "COFF_SYMBOLS";
1365
2272
  sect.Va = 0;
1366
2273
  sect.Pa = _header.PointerToSymbolTable;
1367
2274
  sect.PSize = sect.VSize = size;
1368
2275
  sect.UpdateTotalSize(_totalSize);
1369
- _sections.Add(sect);
1370
2276
  }
1371
2277
 
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
2278
  {
1379
2279
  CObjectVector<CSection> sections = _sections;
1380
2280
  sections.Sort();
1381
2281
  UInt32 limit = (1 << 12);
1382
- int num = 0;
1383
- int numSections = sections.Size();
1384
- for (int i = 0; i < numSections; i++)
2282
+ unsigned num = 0;
2283
+ FOR_VECTOR (k, sections)
1385
2284
  {
1386
- const CSection &s = sections[i];
2285
+ const CSection &s = sections[k];
1387
2286
  if (s.Pa > limit)
1388
2287
  {
1389
- CSection s2;
2288
+ CSection &s2 = _sections.AddNew();
1390
2289
  s2.Pa = s2.Va = limit;
1391
2290
  s2.PSize = s2.VSize = s.Pa - limit;
1392
2291
  s2.IsAdditionalSection = true;
1393
2292
  s2.Name = '[';
1394
2293
  s2.Name += GetDecString(num++);
1395
2294
  s2.Name += ']';
1396
- _sections.Add(s2);
1397
2295
  limit = s.Pa;
1398
2296
  }
1399
2297
  UInt32 next = s.Pa + s.PSize;
@@ -1404,10 +2302,29 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
1404
2302
  }
1405
2303
  }
1406
2304
 
2305
+
2306
+ if (_optHeader.CheckSum != 0)
2307
+ {
2308
+ RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
2309
+ UInt32 checkSum = 0;
2310
+ RINOK(CalcCheckSum(stream, _totalSize, _peOffset + kHeaderSize + k_CheckSum_Field_Offset, checkSum));
2311
+ _checksumError = (checkSum != _optHeader.CheckSum);
2312
+ }
2313
+
2314
+
2315
+ if (!_allowTail)
2316
+ {
2317
+ UInt64 fileSize;
2318
+ RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
2319
+ if (fileSize > _totalSize)
2320
+ return S_FALSE;
2321
+ }
2322
+
1407
2323
  _parseResources = true;
2324
+ // _parseResources = false;
1408
2325
 
1409
2326
  UInt64 mainSize = 0, mainSize2 = 0;
1410
- int i;
2327
+
1411
2328
  for (i = 0; i < _sections.Size(); i++)
1412
2329
  {
1413
2330
  const CSection &sect = _sections[i];
@@ -1418,14 +2335,14 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
1418
2335
  HRESULT res = OpenResources(i, stream, callback);
1419
2336
  if (res == S_OK)
1420
2337
  {
1421
- _resourceFileName = GetUnicodeString(sect.Name);
1422
- for (int j = 0; j < _items.Size(); j++)
2338
+ _resourcesPrefix.SetFromAscii(sect.Name);
2339
+ _resourcesPrefix.Add_PathSepar();
2340
+ FOR_VECTOR (j, _items)
1423
2341
  {
1424
2342
  const CResItem &item = _items[j];
1425
2343
  if (item.Enabled)
1426
2344
  {
1427
2345
  mixItem.ResourceIndex = j;
1428
- mixItem.StringIndex = -1;
1429
2346
  if (item.IsRcDataOrUnknown())
1430
2347
  {
1431
2348
  if (item.Size >= mainSize)
@@ -1440,6 +2357,9 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
1440
2357
  _mixItems.Add(mixItem);
1441
2358
  }
1442
2359
  }
2360
+ // 9.29: .rsrc_2 code was commented.
2361
+ // .rsrc_1 now must include that .rsrc_2 block.
2362
+ /*
1443
2363
  if (sect.PSize > sect.VSize)
1444
2364
  {
1445
2365
  int numBits = _optHeader.GetNumFileAlignBits();
@@ -1450,7 +2370,7 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
1450
2370
 
1451
2371
  if (sect.PSize > end)
1452
2372
  {
1453
- CSection sect2;
2373
+ CSection &sect2 = _sections.AddNew();
1454
2374
  sect2.Flags = 0;
1455
2375
  sect2.Pa = sect.Pa + end;
1456
2376
  sect2.Va = sect.Va + end;
@@ -1459,18 +2379,16 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
1459
2379
  sect2.Name = ".rsrc_2";
1460
2380
  sect2.Time = 0;
1461
2381
  sect2.IsAdditionalSection = true;
1462
- _sections.Add(sect2);
1463
2382
  }
1464
2383
  }
1465
2384
  }
2385
+ */
1466
2386
  continue;
1467
2387
  }
1468
2388
  if (res != S_FALSE)
1469
2389
  return res;
1470
2390
  CloseResources();
1471
2391
  }
1472
- mixItem.StringIndex = -1;
1473
- mixItem.ResourceIndex = -1;
1474
2392
  if (sect.IsAdditionalSection)
1475
2393
  {
1476
2394
  if (sect.PSize >= mainSize)
@@ -1479,7 +2397,7 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
1479
2397
  mainSize = sect.PSize;
1480
2398
  _mainSubfile = _mixItems.Size();
1481
2399
  }
1482
- else
2400
+ else if (sect.PSize >= mainSize2)
1483
2401
  mainSize2 = sect.PSize;
1484
2402
  }
1485
2403
  _mixItems.Add(mixItem);
@@ -1498,55 +2416,35 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
1498
2416
  }
1499
2417
  }
1500
2418
 
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 (;;)
2419
+ for (i = 0; i < _versionKeys.Size(); i++)
1515
2420
  {
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
- }
2421
+ if (i != 0)
2422
+ _versionFullString.Add_LF();
2423
+ const CStringKeyValue &k = _versionKeys[i];
2424
+ _versionFullString += k.Key;
2425
+ _versionFullString += L": ";
2426
+ _versionFullString += k.Value;
2427
+ }
1538
2428
 
1539
- for (size_t i = 0; i < processed; i += 2)
2429
+ {
2430
+ int keyIndex = FindKey(_versionKeys, "OriginalFilename");
2431
+ if (keyIndex >= 0)
2432
+ _originalFilename = _versionKeys[keyIndex].Value;
2433
+ }
2434
+ {
2435
+ int keyIndex = FindKey(_versionKeys, "FileDescription");
2436
+ if (keyIndex >= 0)
2437
+ _versionShortString = _versionKeys[keyIndex].Value;
2438
+ }
2439
+ {
2440
+ int keyIndex = FindKey(_versionKeys, "FileVersion");
2441
+ if (keyIndex >= 0)
1540
2442
  {
1541
- sum += Get16(buf + i);
1542
- sum = (sum + (sum >> 16)) & 0xFFFF;
2443
+ _versionShortString.Add_Space();
2444
+ _versionShortString += _versionKeys[keyIndex].Value;
1543
2445
  }
1544
- pos += (UInt32)processed;
1545
- if (rem != processed)
1546
- break;
1547
2446
  }
1548
- sum += pos;
1549
- res = sum;
2447
+
1550
2448
  return S_OK;
1551
2449
  }
1552
2450
 
@@ -1565,11 +2463,18 @@ void CHandler::CloseResources()
1565
2463
  _usedRes.Free();
1566
2464
  _items.Clear();
1567
2465
  _strings.Clear();
1568
- _buf.SetCapacity(0);
2466
+ _versionFiles.Clear();
2467
+ _buf.Free();
2468
+ _versionFullString.Empty();
2469
+ _versionShortString.Empty();
2470
+ _originalFilename.Empty();
2471
+ _versionKeys.Clear();
1569
2472
  }
1570
2473
 
1571
2474
  STDMETHODIMP CHandler::Close()
1572
2475
  {
2476
+ _totalSize = 0;
2477
+ _checksumError = false;
1573
2478
  _stream.Release();
1574
2479
  _sections.Clear();
1575
2480
  _mixItems.Clear();
@@ -1587,7 +2492,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1587
2492
  Int32 testMode, IArchiveExtractCallback *extractCallback)
1588
2493
  {
1589
2494
  COM_TRY_BEGIN
1590
- bool allFilesMode = (numItems == (UInt32)-1);
2495
+ bool allFilesMode = (numItems == (UInt32)(Int32)-1);
1591
2496
  if (allFilesMode)
1592
2497
  numItems = _mixItems.Size();
1593
2498
  if (numItems == 0)
@@ -1597,12 +2502,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1597
2502
  for (i = 0; i < numItems; i++)
1598
2503
  {
1599
2504
  const CMixItem &mixItem = _mixItems[allFilesMode ? i : indices[i]];
2505
+ UInt64 size;
1600
2506
  if (mixItem.StringIndex >= 0)
1601
- totalSize += _strings[mixItem.StringIndex].Size;
1602
- else if (mixItem.ResourceIndex < 0)
1603
- totalSize += _sections[mixItem.SectionIndex].GetPackSize();
2507
+ size = _strings[mixItem.StringIndex].FinalSize();
2508
+ else if (mixItem.VersionIndex >= 0)
2509
+ size = _versionFiles[mixItem.VersionIndex].Size();
2510
+ else if (mixItem.ResourceIndex >= 0)
2511
+ size = _items[mixItem.ResourceIndex].GetSize();
1604
2512
  else
1605
- totalSize += _items[mixItem.ResourceIndex].GetSize();
2513
+ size = _sections[mixItem.SectionIndex].GetSizeExtract();
2514
+ totalSize += size;
1606
2515
  }
1607
2516
  extractCallback->SetTotal(totalSize);
1608
2517
 
@@ -1616,15 +2525,6 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1616
2525
  CMyComPtr<ICompressProgressInfo> progress = lps;
1617
2526
  lps->Init(extractCallback, false);
1618
2527
 
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
2528
  CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
1629
2529
  CMyComPtr<ISequentialInStream> inStream(streamSpec);
1630
2530
  streamSpec->SetStream(_stream);
@@ -1647,27 +2547,26 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1647
2547
  if (mixItem.StringIndex >= 0)
1648
2548
  {
1649
2549
  const CStringItem &item = _strings[mixItem.StringIndex];
1650
- currentItemSize = item.Size;
2550
+ currentItemSize = item.FinalSize();
1651
2551
  if (!testMode && !outStream)
1652
2552
  continue;
1653
2553
 
1654
2554
  RINOK(extractCallback->PrepareOperation(askMode));
1655
2555
  if (outStream)
1656
- RINOK(WriteStream(outStream, item.Buf, item.Size));
2556
+ RINOK(WriteStream(outStream, item.Buf, item.FinalSize()));
1657
2557
  }
1658
- else if (mixItem.ResourceIndex < 0)
2558
+ else if (mixItem.VersionIndex >= 0)
1659
2559
  {
1660
- currentItemSize = sect.GetPackSize();
2560
+ const CByteBuffer &item = _versionFiles[mixItem.VersionIndex];
2561
+ currentItemSize = item.Size();
1661
2562
  if (!testMode && !outStream)
1662
2563
  continue;
1663
-
2564
+
1664
2565
  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);
2566
+ if (outStream)
2567
+ RINOK(WriteStream(outStream, item, item.Size()));
1669
2568
  }
1670
- else
2569
+ else if (mixItem.ResourceIndex >= 0)
1671
2570
  {
1672
2571
  const CResItem &item = _items[mixItem.ResourceIndex];
1673
2572
  currentItemSize = item.GetSize();
@@ -1685,12 +2584,22 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
1685
2584
  RINOK(WriteStream(outStream, _buf + offset, item.Size));
1686
2585
  }
1687
2586
  }
2587
+ else
2588
+ {
2589
+ currentItemSize = sect.GetSizeExtract();
2590
+ if (!testMode && !outStream)
2591
+ continue;
2592
+
2593
+ RINOK(extractCallback->PrepareOperation(askMode));
2594
+ RINOK(_stream->Seek(sect.Pa, STREAM_SEEK_SET, NULL));
2595
+ streamSpec->Init(currentItemSize);
2596
+ RINOK(copyCoder->Code(inStream, outStream, NULL, NULL, progress));
2597
+ isOk = (copyCoderSpec->TotalSize == currentItemSize);
2598
+ }
1688
2599
 
1689
2600
  outStream.Release();
1690
2601
  RINOK(extractCallback->SetOperationResult(isOk ?
1691
- checkSumOK ?
1692
- NExtract::NOperationResult::kOK:
1693
- NExtract::NOperationResult::kCRCError:
2602
+ NExtract::NOperationResult::kOK :
1694
2603
  NExtract::NOperationResult::kDataError));
1695
2604
  }
1696
2605
  return S_OK;
@@ -1714,8 +2623,12 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
1714
2623
  if (mixItem.StringIndex >= 0)
1715
2624
  {
1716
2625
  const CStringItem &item = _strings[mixItem.StringIndex];
1717
- referenceBuf->Buf.SetCapacity(item.Size);
1718
- memcpy(referenceBuf->Buf, item.Buf, item.Size);
2626
+ referenceBuf->Buf.CopyFrom(item.Buf, item.FinalSize());
2627
+ }
2628
+ else if (mixItem.VersionIndex >= 0)
2629
+ {
2630
+ const CByteBuffer &item = _versionFiles[mixItem.VersionIndex];
2631
+ referenceBuf->Buf.CopyFrom(item, item.Size());
1719
2632
  }
1720
2633
  else
1721
2634
  {
@@ -1731,9 +2644,10 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
1731
2644
  *stream = streamTemp2.Detach();
1732
2645
  return S_OK;
1733
2646
  }
1734
- referenceBuf->Buf.SetCapacity(item.HeaderSize + item.Size);
2647
+ referenceBuf->Buf.Alloc(item.HeaderSize + item.Size);
1735
2648
  memcpy(referenceBuf->Buf, item.Header, item.HeaderSize);
1736
- memcpy(referenceBuf->Buf + item.HeaderSize, _buf + offset, item.Size);
2649
+ if (item.Size != 0)
2650
+ memcpy(referenceBuf->Buf + item.HeaderSize, _buf + offset, item.Size);
1737
2651
  }
1738
2652
  inStreamSpec->Init(referenceBuf);
1739
2653
 
@@ -1742,11 +2656,407 @@ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
1742
2656
  COM_TRY_END
1743
2657
  }
1744
2658
 
1745
- static IInArchive *CreateArc() { return new CHandler; }
2659
+ STDMETHODIMP CHandler::AllowTail(Int32 allowTail)
2660
+ {
2661
+ _allowTail = IntToBool(allowTail);
2662
+ return S_OK;
2663
+ }
2664
+
2665
+ static const Byte k_Signature[] = { 'M', 'Z' };
2666
+
2667
+ REGISTER_ARC_I(
2668
+ "PE", "exe dll sys", 0, 0xDD,
2669
+ k_Signature,
2670
+ 0,
2671
+ NArcInfoFlags::kPreArc,
2672
+ IsArc_Pe)
2673
+
2674
+ }
2675
+
2676
+
2677
+
2678
+
2679
+ namespace NTe {
2680
+
2681
+ // Terse Executable (TE) image
2682
+
2683
+ struct CDataDir
2684
+ {
2685
+ UInt32 Va;
2686
+ UInt32 Size;
2687
+
2688
+ void Parse(const Byte *p)
2689
+ {
2690
+ G32(0, Va);
2691
+ G32(4, Size);
2692
+ }
2693
+ };
2694
+
2695
+ static const UInt32 kHeaderSize = 40;
2696
+
2697
+ static bool FindValue(const CUInt32PCharPair *pairs, unsigned num, UInt32 value)
2698
+ {
2699
+ for (unsigned i = 0; i < num; i++)
2700
+ if (pairs[i].Value == value)
2701
+ return true;
2702
+ return false;
2703
+ }
2704
+
2705
+ #define MY_FIND_VALUE(pairs, value) FindValue(pairs, ARRAY_SIZE(pairs), value)
2706
+
2707
+ static const UInt32 kNumSection_MAX = 32;
2708
+
2709
+ struct CHeader
2710
+ {
2711
+ UInt16 Machine;
2712
+ Byte NumSections;
2713
+ Byte SubSystem;
2714
+ UInt16 StrippedSize;
2715
+ /*
2716
+ UInt32 AddressOfEntryPoint;
2717
+ UInt32 BaseOfCode;
2718
+ UInt64 ImageBase;
2719
+ */
2720
+ CDataDir DataDir[2]; // base relocation and debug directory
2721
+
2722
+ bool ConvertPa(UInt32 &pa) const
2723
+ {
2724
+ if (pa < StrippedSize)
2725
+ return false;
2726
+ pa = pa - StrippedSize + kHeaderSize;
2727
+ return true;
2728
+ }
2729
+ bool Parse(const Byte *p);
2730
+ };
2731
+
2732
+ bool CHeader::Parse(const Byte *p)
2733
+ {
2734
+ NumSections = p[4];
2735
+ if (NumSections > kNumSection_MAX)
2736
+ return false;
2737
+ SubSystem = p[5];
2738
+ G16(2, Machine);
2739
+ G16(6, StrippedSize);
2740
+ /*
2741
+ G32(8, AddressOfEntryPoint);
2742
+ G32(12, BaseOfCode);
2743
+ G64(16, ImageBase);
2744
+ */
2745
+ for (int i = 0; i < 2; i++)
2746
+ {
2747
+ CDataDir &dd = DataDir[i];
2748
+ dd.Parse(p + 24 + i * 8);
2749
+ if (dd.Size >= ((UInt32)1 << 28))
2750
+ return false;
2751
+ }
2752
+ return
2753
+ MY_FIND_VALUE(NPe::g_MachinePairs, Machine) &&
2754
+ MY_FIND_VALUE(NPe::g_SubSystems, SubSystem);
2755
+ }
2756
+
2757
+ API_FUNC_static_IsArc IsArc_Te(const Byte *p, size_t size)
2758
+ {
2759
+ if (size < 2)
2760
+ return k_IsArc_Res_NEED_MORE;
2761
+ if (p[0] != 'V' || p[1] != 'Z')
2762
+ return k_IsArc_Res_NO;
2763
+ if (size < kHeaderSize)
2764
+ return k_IsArc_Res_NEED_MORE;
2765
+
2766
+ CHeader h;
2767
+ if (!h.Parse(p))
2768
+ return k_IsArc_Res_NO;
2769
+ return k_IsArc_Res_YES;
2770
+ }
2771
+ }
1746
2772
 
1747
- static CArcInfo g_ArcInfo =
1748
- { L"PE", L"exe dll sys", 0, 0xDD, { 'P', 'E', 0, 0 }, 4, false, CreateArc, 0 };
1749
2773
 
1750
- REGISTER_ARC(Pe)
2774
+ struct CSection
2775
+ {
2776
+ Byte Name[NPe::kNameSize];
1751
2777
 
1752
- }}
2778
+ UInt32 VSize;
2779
+ UInt32 Va;
2780
+ UInt32 PSize;
2781
+ UInt32 Pa;
2782
+ UInt32 Flags;
2783
+ // UInt16 NumRelocs;
2784
+
2785
+ void Parse(const Byte *p)
2786
+ {
2787
+ memcpy(Name, p, NPe::kNameSize);
2788
+ G32(8, VSize);
2789
+ G32(12, Va);
2790
+ G32(16, PSize);
2791
+ G32(20, Pa);
2792
+ // G32(p + 32, NumRelocs);
2793
+ G32(36, Flags);
2794
+ }
2795
+
2796
+ bool Check() const
2797
+ {
2798
+ return
2799
+ Pa <= ((UInt32)1 << 30) &&
2800
+ PSize <= ((UInt32)1 << 30);
2801
+ }
2802
+
2803
+ void UpdateTotalSize(UInt32 &totalSize)
2804
+ {
2805
+ UInt32 t = Pa + PSize;
2806
+ if (t > totalSize)
2807
+ totalSize = t;
2808
+ }
2809
+ };
2810
+
2811
+ class CHandler:
2812
+ public IInArchive,
2813
+ public IInArchiveGetStream,
2814
+ public IArchiveAllowTail,
2815
+ public CMyUnknownImp
2816
+ {
2817
+ CRecordVector<CSection> _items;
2818
+ CMyComPtr<IInStream> _stream;
2819
+ UInt32 _totalSize;
2820
+ bool _allowTail;
2821
+ CHeader _h;
2822
+
2823
+ HRESULT Open2(IInStream *stream);
2824
+ public:
2825
+ MY_UNKNOWN_IMP3(IInArchive, IInArchiveGetStream, IArchiveAllowTail)
2826
+ INTERFACE_IInArchive(;)
2827
+ STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
2828
+ STDMETHOD(AllowTail)(Int32 allowTail);
2829
+ CHandler(): _allowTail(false) {}
2830
+ };
2831
+
2832
+ static const Byte kProps[] =
2833
+ {
2834
+ kpidPath,
2835
+ kpidSize,
2836
+ kpidVirtualSize,
2837
+ kpidCharacts,
2838
+ kpidOffset,
2839
+ kpidVa
2840
+ };
2841
+
2842
+ enum
2843
+ {
2844
+ kpidSubSystem = kpidUserDefined,
2845
+ // , kpidImageBase
2846
+ };
2847
+
2848
+ static const CStatProp kArcProps[] =
2849
+ {
2850
+ // { NULL, kpidHeadersSize, VT_UI4 },
2851
+ { NULL, kpidCpu, VT_BSTR},
2852
+ { "Subsystem", kpidSubSystem, VT_BSTR },
2853
+ // { "Image Base", kpidImageBase, VT_UI8 }
2854
+ };
2855
+
2856
+ IMP_IInArchive_Props
2857
+ IMP_IInArchive_ArcProps_WITH_NAME
2858
+
2859
+ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
2860
+ {
2861
+ COM_TRY_BEGIN
2862
+ NCOM::CPropVariant prop;
2863
+ switch (propID)
2864
+ {
2865
+ case kpidPhySize: prop = _totalSize; break;
2866
+ case kpidCpu: PAIR_TO_PROP(NPe::g_MachinePairs, _h.Machine, prop); break;
2867
+ case kpidSubSystem: PAIR_TO_PROP(NPe::g_SubSystems, _h.SubSystem, prop); break;
2868
+ /*
2869
+ case kpidImageBase: prop = _h.ImageBase; break;
2870
+ case kpidAddressOfEntryPoint: prop = _h.AddressOfEntryPoint; break;
2871
+ case kpidBaseOfCode: prop = _h.BaseOfCode; break;
2872
+ */
2873
+ }
2874
+ prop.Detach(value);
2875
+ return S_OK;
2876
+ COM_TRY_END
2877
+ }
2878
+
2879
+ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
2880
+ {
2881
+ COM_TRY_BEGIN
2882
+ NCOM::CPropVariant prop;
2883
+ {
2884
+ const CSection &item = _items[index];
2885
+ switch (propID)
2886
+ {
2887
+ case kpidPath:
2888
+ {
2889
+ AString name;
2890
+ NPe::GetName(item.Name, name);
2891
+ prop = MultiByteToUnicodeString(name);
2892
+ break;
2893
+ }
2894
+ case kpidSize:
2895
+ case kpidPackSize: prop = (UInt64)item.PSize; break;
2896
+ case kpidVirtualSize: prop = (UInt64)item.VSize; break;
2897
+ case kpidOffset: prop = item.Pa; break;
2898
+ case kpidVa: prop = item.Va; break;
2899
+ case kpidCharacts: FLAGS_TO_PROP(NPe::g_SectFlags, item.Flags, prop); break;
2900
+ }
2901
+ }
2902
+ prop.Detach(value);
2903
+ return S_OK;
2904
+ COM_TRY_END
2905
+ }
2906
+
2907
+ HRESULT CHandler::Open2(IInStream *stream)
2908
+ {
2909
+ Byte h[kHeaderSize];
2910
+ RINOK(ReadStream_FALSE(stream, h, kHeaderSize));
2911
+ if (h[0] != 'V' || h[1] != 'Z')
2912
+ return S_FALSE;
2913
+ if (!_h.Parse(h))
2914
+ return S_FALSE;
2915
+
2916
+ UInt32 headerSize = NPe::kSectionSize * (UInt32)_h.NumSections;
2917
+ CByteArr buf(headerSize);
2918
+ RINOK(ReadStream_FALSE(stream, buf, headerSize));
2919
+ headerSize += kHeaderSize;
2920
+
2921
+ _totalSize = headerSize;
2922
+ _items.ClearAndReserve(_h.NumSections);
2923
+ for (UInt32 i = 0; i < _h.NumSections; i++)
2924
+ {
2925
+ CSection sect;
2926
+ sect.Parse(buf + i * NPe::kSectionSize);
2927
+ if (!_h.ConvertPa(sect.Pa))
2928
+ return S_FALSE;
2929
+ if (sect.Pa < headerSize)
2930
+ return S_FALSE;
2931
+ if (!sect.Check())
2932
+ return S_FALSE;
2933
+ _items.AddInReserved(sect);
2934
+ sect.UpdateTotalSize(_totalSize);
2935
+ }
2936
+
2937
+ if (!_allowTail)
2938
+ {
2939
+ UInt64 fileSize;
2940
+ RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
2941
+ if (fileSize > _totalSize)
2942
+ return S_FALSE;
2943
+ }
2944
+
2945
+ return S_OK;
2946
+ }
2947
+
2948
+ STDMETHODIMP CHandler::Open(IInStream *inStream,
2949
+ const UInt64 * /* maxCheckStartPosition */,
2950
+ IArchiveOpenCallback * /* openArchiveCallback */)
2951
+ {
2952
+ COM_TRY_BEGIN
2953
+ Close();
2954
+ try
2955
+ {
2956
+ if (Open2(inStream) != S_OK)
2957
+ return S_FALSE;
2958
+ _stream = inStream;
2959
+ }
2960
+ catch(...) { return S_FALSE; }
2961
+ return S_OK;
2962
+ COM_TRY_END
2963
+ }
2964
+
2965
+ STDMETHODIMP CHandler::Close()
2966
+ {
2967
+ _totalSize = 0;
2968
+ _stream.Release();
2969
+ _items.Clear();
2970
+ return S_OK;
2971
+ }
2972
+
2973
+ STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
2974
+ {
2975
+ *numItems = _items.Size();
2976
+ return S_OK;
2977
+ }
2978
+
2979
+ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
2980
+ Int32 testMode, IArchiveExtractCallback *extractCallback)
2981
+ {
2982
+ COM_TRY_BEGIN
2983
+ bool allFilesMode = (numItems == (UInt32)(Int32)-1);
2984
+ if (allFilesMode)
2985
+ numItems = _items.Size();
2986
+ if (numItems == 0)
2987
+ return S_OK;
2988
+ UInt64 totalSize = 0;
2989
+ UInt32 i;
2990
+ for (i = 0; i < numItems; i++)
2991
+ totalSize += _items[allFilesMode ? i : indices[i]].PSize;
2992
+ extractCallback->SetTotal(totalSize);
2993
+
2994
+ UInt64 currentTotalSize = 0;
2995
+
2996
+ NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder();
2997
+ CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
2998
+
2999
+ CLocalProgress *lps = new CLocalProgress;
3000
+ CMyComPtr<ICompressProgressInfo> progress = lps;
3001
+ lps->Init(extractCallback, false);
3002
+
3003
+ CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
3004
+ CMyComPtr<ISequentialInStream> inStream(streamSpec);
3005
+ streamSpec->SetStream(_stream);
3006
+
3007
+ for (i = 0; i < numItems; i++)
3008
+ {
3009
+ lps->InSize = lps->OutSize = currentTotalSize;
3010
+ RINOK(lps->SetCur());
3011
+ CMyComPtr<ISequentialOutStream> realOutStream;
3012
+ Int32 askMode = testMode ?
3013
+ NExtract::NAskMode::kTest :
3014
+ NExtract::NAskMode::kExtract;
3015
+ UInt32 index = allFilesMode ? i : indices[i];
3016
+ const CSection &item = _items[index];
3017
+ RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
3018
+ currentTotalSize += item.PSize;
3019
+
3020
+ if (!testMode && !realOutStream)
3021
+ continue;
3022
+ RINOK(extractCallback->PrepareOperation(askMode));
3023
+ int res = NExtract::NOperationResult::kDataError;
3024
+
3025
+ RINOK(_stream->Seek(item.Pa, STREAM_SEEK_SET, NULL));
3026
+ streamSpec->Init(item.PSize);
3027
+ RINOK(copyCoder->Code(inStream, realOutStream, NULL, NULL, progress));
3028
+ if (copyCoderSpec->TotalSize == item.PSize)
3029
+ res = NExtract::NOperationResult::kOK;
3030
+
3031
+ realOutStream.Release();
3032
+ RINOK(extractCallback->SetOperationResult(res));
3033
+ }
3034
+ return S_OK;
3035
+ COM_TRY_END
3036
+ }
3037
+
3038
+ STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
3039
+ {
3040
+ COM_TRY_BEGIN
3041
+ const CSection &item = _items[index];
3042
+ return CreateLimitedInStream(_stream, item.Pa, item.PSize, stream);
3043
+ COM_TRY_END
3044
+ }
3045
+
3046
+ STDMETHODIMP CHandler::AllowTail(Int32 allowTail)
3047
+ {
3048
+ _allowTail = IntToBool(allowTail);
3049
+ return S_OK;
3050
+ }
3051
+
3052
+ static const Byte k_Signature[] = { 'V', 'Z' };
3053
+
3054
+ REGISTER_ARC_I(
3055
+ "TE", "te", 0, 0xCF,
3056
+ k_Signature,
3057
+ 0,
3058
+ NArcInfoFlags::kPreArc,
3059
+ IsArc_Te)
3060
+
3061
+ }
3062
+ }