libwz 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +165 -0
  3. package/binding.gyp +149 -0
  4. package/deps/tiny-aes/.github/workflows/c-cpp.yml +27 -0
  5. package/deps/tiny-aes/CMakeLists.txt +17 -0
  6. package/deps/tiny-aes/Makefile +61 -0
  7. package/deps/tiny-aes/README.md +83 -0
  8. package/deps/tiny-aes/aes.c +572 -0
  9. package/deps/tiny-aes/aes.h +91 -0
  10. package/deps/tiny-aes/aes.hpp +12 -0
  11. package/deps/tiny-aes/conanfile.py +73 -0
  12. package/deps/tiny-aes/library.json +19 -0
  13. package/deps/tiny-aes/library.properties +11 -0
  14. package/deps/tiny-aes/test.c +316 -0
  15. package/deps/tiny-aes/test.cpp +2 -0
  16. package/deps/tiny-aes/test_package/CMakeLists.txt +11 -0
  17. package/deps/tiny-aes/test_package/conanfile.py +17 -0
  18. package/deps/tiny-aes/unlicense.txt +24 -0
  19. package/deps/zlib/.cmake-format.yaml +245 -0
  20. package/deps/zlib/.github/workflows/c-std.yml +268 -0
  21. package/deps/zlib/.github/workflows/cmake.yml +147 -0
  22. package/deps/zlib/.github/workflows/configure.yml +146 -0
  23. package/deps/zlib/.github/workflows/contribs.yml +64 -0
  24. package/deps/zlib/.github/workflows/fuzz.yml +25 -0
  25. package/deps/zlib/.github/workflows/msys-cygwin.yml +92 -0
  26. package/deps/zlib/.github/workflows/others.yml +153 -0
  27. package/deps/zlib/BUILD.bazel +134 -0
  28. package/deps/zlib/CMakeLists.txt +310 -0
  29. package/deps/zlib/ChangeLog +1669 -0
  30. package/deps/zlib/FAQ +371 -0
  31. package/deps/zlib/INDEX +67 -0
  32. package/deps/zlib/LICENSE +22 -0
  33. package/deps/zlib/MODULE.bazel +9 -0
  34. package/deps/zlib/Makefile.in +426 -0
  35. package/deps/zlib/README +115 -0
  36. package/deps/zlib/README-cmake.md +79 -0
  37. package/deps/zlib/adler32.c +164 -0
  38. package/deps/zlib/amiga/Makefile.pup +69 -0
  39. package/deps/zlib/amiga/Makefile.sas +68 -0
  40. package/deps/zlib/compress.c +99 -0
  41. package/deps/zlib/configure +1078 -0
  42. package/deps/zlib/contrib/CMakeLists.txt +61 -0
  43. package/deps/zlib/contrib/README.contrib +57 -0
  44. package/deps/zlib/contrib/ada/CMakeLists.txt +217 -0
  45. package/deps/zlib/contrib/ada/buffer_demo.adb +106 -0
  46. package/deps/zlib/contrib/ada/cmake/Modules/CMakeADACompiler.cmake.in +23 -0
  47. package/deps/zlib/contrib/ada/cmake/Modules/CMakeADAInformation.cmake +133 -0
  48. package/deps/zlib/contrib/ada/cmake/Modules/CMakeDetermineADACompiler.cmake +33 -0
  49. package/deps/zlib/contrib/ada/cmake/Modules/CMakeTestADACompiler.cmake +46 -0
  50. package/deps/zlib/contrib/ada/cmake/binder_helper.cmake +47 -0
  51. package/deps/zlib/contrib/ada/cmake/compile_helper.cmake +32 -0
  52. package/deps/zlib/contrib/ada/cmake/exe_link_helper.cmake +53 -0
  53. package/deps/zlib/contrib/ada/cmake/shared_link_helper.cmake +52 -0
  54. package/deps/zlib/contrib/ada/cmake/static_link_helper.cmake +25 -0
  55. package/deps/zlib/contrib/ada/mtest.adb +156 -0
  56. package/deps/zlib/contrib/ada/read.adb +156 -0
  57. package/deps/zlib/contrib/ada/readme.txt +65 -0
  58. package/deps/zlib/contrib/ada/test.adb +463 -0
  59. package/deps/zlib/contrib/ada/zlib-streams.adb +225 -0
  60. package/deps/zlib/contrib/ada/zlib-streams.ads +114 -0
  61. package/deps/zlib/contrib/ada/zlib-thin.adb +142 -0
  62. package/deps/zlib/contrib/ada/zlib-thin.ads +450 -0
  63. package/deps/zlib/contrib/ada/zlib.adb +701 -0
  64. package/deps/zlib/contrib/ada/zlib.ads +328 -0
  65. package/deps/zlib/contrib/ada/zlib.gpr +20 -0
  66. package/deps/zlib/contrib/blast/CMakeLists.txt +166 -0
  67. package/deps/zlib/contrib/blast/Makefile +14 -0
  68. package/deps/zlib/contrib/blast/README +4 -0
  69. package/deps/zlib/contrib/blast/blast-test.c +42 -0
  70. package/deps/zlib/contrib/blast/blast.c +422 -0
  71. package/deps/zlib/contrib/blast/blast.h +84 -0
  72. package/deps/zlib/contrib/blast/blastConfig.cmake.in +18 -0
  73. package/deps/zlib/contrib/blast/test/CMakeLists.txt +193 -0
  74. package/deps/zlib/contrib/blast/test/add_subdirectory_exclude_test.cmake.in +27 -0
  75. package/deps/zlib/contrib/blast/test/add_subdirectory_test.cmake.in +25 -0
  76. package/deps/zlib/contrib/blast/test/find_package_no_components_test.cmake.in +24 -0
  77. package/deps/zlib/contrib/blast/test/find_package_test.cmake.in +24 -0
  78. package/deps/zlib/contrib/blast/test/find_package_wrong_components_test.cmake.in +24 -0
  79. package/deps/zlib/contrib/blast/test.pk +0 -0
  80. package/deps/zlib/contrib/blast/test.txt +1 -0
  81. package/deps/zlib/contrib/blast/tester.cmake +28 -0
  82. package/deps/zlib/contrib/crc32vx/CMakeLists.txt +67 -0
  83. package/deps/zlib/contrib/crc32vx/README +9 -0
  84. package/deps/zlib/contrib/crc32vx/crc32_vx.c +254 -0
  85. package/deps/zlib/contrib/crc32vx/crc32_vx_hooks.h +9 -0
  86. package/deps/zlib/contrib/delphi/ZLib.pas +557 -0
  87. package/deps/zlib/contrib/delphi/ZLibConst.pas +11 -0
  88. package/deps/zlib/contrib/delphi/readme.txt +76 -0
  89. package/deps/zlib/contrib/delphi/zlibd32.mak +99 -0
  90. package/deps/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs +58 -0
  91. package/deps/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs +202 -0
  92. package/deps/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs +83 -0
  93. package/deps/zlib/contrib/dotzlib/DotZLib/CodecBase.cs +198 -0
  94. package/deps/zlib/contrib/dotzlib/DotZLib/Deflater.cs +106 -0
  95. package/deps/zlib/contrib/dotzlib/DotZLib/DotZLib.cs +288 -0
  96. package/deps/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj +141 -0
  97. package/deps/zlib/contrib/dotzlib/DotZLib/GZipStream.cs +301 -0
  98. package/deps/zlib/contrib/dotzlib/DotZLib/Inflater.cs +105 -0
  99. package/deps/zlib/contrib/dotzlib/DotZLib/UnitTests.cs +274 -0
  100. package/deps/zlib/contrib/dotzlib/DotZLib.build +33 -0
  101. package/deps/zlib/contrib/dotzlib/DotZLib.chm +0 -0
  102. package/deps/zlib/contrib/dotzlib/DotZLib.sln +21 -0
  103. package/deps/zlib/contrib/dotzlib/LICENSE_1_0.txt +23 -0
  104. package/deps/zlib/contrib/dotzlib/readme.txt +58 -0
  105. package/deps/zlib/contrib/gcc_gvmat64/CMakeLists.txt +19 -0
  106. package/deps/zlib/contrib/gcc_gvmat64/gvmat64.S +570 -0
  107. package/deps/zlib/contrib/infback9/CMakeLists.txt +19 -0
  108. package/deps/zlib/contrib/infback9/README +1 -0
  109. package/deps/zlib/contrib/infback9/infback9.c +603 -0
  110. package/deps/zlib/contrib/infback9/infback9.h +37 -0
  111. package/deps/zlib/contrib/infback9/inffix9.h +107 -0
  112. package/deps/zlib/contrib/infback9/inflate9.h +47 -0
  113. package/deps/zlib/contrib/infback9/inftree9.c +319 -0
  114. package/deps/zlib/contrib/infback9/inftree9.h +61 -0
  115. package/deps/zlib/contrib/iostream/test.cpp +24 -0
  116. package/deps/zlib/contrib/iostream/zfstream.cpp +329 -0
  117. package/deps/zlib/contrib/iostream/zfstream.h +128 -0
  118. package/deps/zlib/contrib/iostream2/zstream.h +306 -0
  119. package/deps/zlib/contrib/iostream2/zstream_test.cpp +25 -0
  120. package/deps/zlib/contrib/iostream3/CMakeLists.txt +200 -0
  121. package/deps/zlib/contrib/iostream3/README +35 -0
  122. package/deps/zlib/contrib/iostream3/TODO +17 -0
  123. package/deps/zlib/contrib/iostream3/iostream3Config.cmake.in +23 -0
  124. package/deps/zlib/contrib/iostream3/test/CMakeLists.txt +191 -0
  125. package/deps/zlib/contrib/iostream3/test/add_subdirectory_exclude_test.cmake.in +27 -0
  126. package/deps/zlib/contrib/iostream3/test/add_subdirectory_test.cmake.in +25 -0
  127. package/deps/zlib/contrib/iostream3/test/find_package_no_components_test.cmake.in +24 -0
  128. package/deps/zlib/contrib/iostream3/test/find_package_test.cmake.in +24 -0
  129. package/deps/zlib/contrib/iostream3/test/find_package_wrong_components_test.cmake.in +24 -0
  130. package/deps/zlib/contrib/iostream3/test.cc +50 -0
  131. package/deps/zlib/contrib/iostream3/zfstream.cc +479 -0
  132. package/deps/zlib/contrib/iostream3/zfstream.h +466 -0
  133. package/deps/zlib/contrib/minizip/CMakeLists.txt +387 -0
  134. package/deps/zlib/contrib/minizip/LICENSE.Info-Zip +58 -0
  135. package/deps/zlib/contrib/minizip/Makefile +33 -0
  136. package/deps/zlib/contrib/minizip/Makefile.am +45 -0
  137. package/deps/zlib/contrib/minizip/MiniZip64_Changes.txt +6 -0
  138. package/deps/zlib/contrib/minizip/MiniZip64_info.txt +69 -0
  139. package/deps/zlib/contrib/minizip/configure.ac +32 -0
  140. package/deps/zlib/contrib/minizip/crypt.h +125 -0
  141. package/deps/zlib/contrib/minizip/ints.h +57 -0
  142. package/deps/zlib/contrib/minizip/ioapi.c +231 -0
  143. package/deps/zlib/contrib/minizip/ioapi.h +183 -0
  144. package/deps/zlib/contrib/minizip/iowin32.c +447 -0
  145. package/deps/zlib/contrib/minizip/iowin32.h +27 -0
  146. package/deps/zlib/contrib/minizip/make_vms.com +25 -0
  147. package/deps/zlib/contrib/minizip/miniunz.c +647 -0
  148. package/deps/zlib/contrib/minizip/miniunzip.1 +63 -0
  149. package/deps/zlib/contrib/minizip/minizip.1 +46 -0
  150. package/deps/zlib/contrib/minizip/minizip.c +511 -0
  151. package/deps/zlib/contrib/minizip/minizip.pc.in +13 -0
  152. package/deps/zlib/contrib/minizip/minizip.pc.txt +13 -0
  153. package/deps/zlib/contrib/minizip/minizipConfig.cmake.in +27 -0
  154. package/deps/zlib/contrib/minizip/mztools.c +294 -0
  155. package/deps/zlib/contrib/minizip/mztools.h +37 -0
  156. package/deps/zlib/contrib/minizip/skipset.h +366 -0
  157. package/deps/zlib/contrib/minizip/test/CMakeLists.txt +176 -0
  158. package/deps/zlib/contrib/minizip/test/add_subdirectory_exclude_test.cmake.in +29 -0
  159. package/deps/zlib/contrib/minizip/test/add_subdirectory_test.cmake.in +28 -0
  160. package/deps/zlib/contrib/minizip/test/find_package_no_components_test.cmake.in +26 -0
  161. package/deps/zlib/contrib/minizip/test/find_package_test.cmake.in +26 -0
  162. package/deps/zlib/contrib/minizip/test/find_package_wrong_components_test.cmake.in +26 -0
  163. package/deps/zlib/contrib/minizip/test/test_helper.cm +32 -0
  164. package/deps/zlib/contrib/minizip/unzip.c +1984 -0
  165. package/deps/zlib/contrib/minizip/unzip.h +442 -0
  166. package/deps/zlib/contrib/minizip/zip.c +2246 -0
  167. package/deps/zlib/contrib/minizip/zip.h +371 -0
  168. package/deps/zlib/contrib/nuget/nuget.csproj +45 -0
  169. package/deps/zlib/contrib/nuget/nuget.sln +22 -0
  170. package/deps/zlib/contrib/pascal/example.pas +599 -0
  171. package/deps/zlib/contrib/pascal/readme.txt +76 -0
  172. package/deps/zlib/contrib/pascal/zlibd32.mak +99 -0
  173. package/deps/zlib/contrib/pascal/zlibpas.pas +276 -0
  174. package/deps/zlib/contrib/puff/CMakeLists.txt +154 -0
  175. package/deps/zlib/contrib/puff/Makefile +42 -0
  176. package/deps/zlib/contrib/puff/README +63 -0
  177. package/deps/zlib/contrib/puff/bin-writer.c +26 -0
  178. package/deps/zlib/contrib/puff/puff.c +840 -0
  179. package/deps/zlib/contrib/puff/puff.h +35 -0
  180. package/deps/zlib/contrib/puff/puffConfig.cmake.in +18 -0
  181. package/deps/zlib/contrib/puff/pufftest.c +168 -0
  182. package/deps/zlib/contrib/puff/test/CMakeLists.txt +262 -0
  183. package/deps/zlib/contrib/puff/test/add_subdirectory_exclude_test.cmake.in +26 -0
  184. package/deps/zlib/contrib/puff/test/add_subdirectory_test.cmake.in +25 -0
  185. package/deps/zlib/contrib/puff/test/find_package_no_components_test.cmake.in +24 -0
  186. package/deps/zlib/contrib/puff/test/find_package_test.cmake.in +24 -0
  187. package/deps/zlib/contrib/puff/test/find_package_wrong_components_test.cmake.in +24 -0
  188. package/deps/zlib/contrib/puff/test/tester-cov.cmake +58 -0
  189. package/deps/zlib/contrib/puff/test/tester.cmake +16 -0
  190. package/deps/zlib/contrib/puff/zeros.raw +0 -0
  191. package/deps/zlib/contrib/testzlib/CMakeLists.txt +44 -0
  192. package/deps/zlib/contrib/testzlib/testzlib.c +275 -0
  193. package/deps/zlib/contrib/testzlib/testzlib.txt +10 -0
  194. package/deps/zlib/contrib/vstudio/readme.txt +22 -0
  195. package/deps/zlib/contrib/zlib1-dll/CMakeLists.txt +196 -0
  196. package/deps/zlib/contrib/zlib1-dll/readme.txt +21 -0
  197. package/deps/zlib/crc32.c +983 -0
  198. package/deps/zlib/crc32.h +9446 -0
  199. package/deps/zlib/deflate.c +2185 -0
  200. package/deps/zlib/deflate.h +383 -0
  201. package/deps/zlib/doc/algorithm.txt +209 -0
  202. package/deps/zlib/doc/crc-doc.1.0.pdf +0 -0
  203. package/deps/zlib/doc/rfc1950.txt +619 -0
  204. package/deps/zlib/doc/rfc1951.txt +955 -0
  205. package/deps/zlib/doc/rfc1952.txt +675 -0
  206. package/deps/zlib/doc/txtvsbin.txt +107 -0
  207. package/deps/zlib/examples/README.examples +54 -0
  208. package/deps/zlib/examples/enough.c +597 -0
  209. package/deps/zlib/examples/fitblk.c +233 -0
  210. package/deps/zlib/examples/gun.c +702 -0
  211. package/deps/zlib/examples/gzappend.c +504 -0
  212. package/deps/zlib/examples/gzjoin.c +449 -0
  213. package/deps/zlib/examples/gzlog.c +1061 -0
  214. package/deps/zlib/examples/gzlog.h +91 -0
  215. package/deps/zlib/examples/gznorm.c +474 -0
  216. package/deps/zlib/examples/zlib_how.html +550 -0
  217. package/deps/zlib/examples/zpipe.c +206 -0
  218. package/deps/zlib/examples/zran.c +546 -0
  219. package/deps/zlib/examples/zran.h +53 -0
  220. package/deps/zlib/gzclose.c +23 -0
  221. package/deps/zlib/gzguts.h +216 -0
  222. package/deps/zlib/gzlib.c +609 -0
  223. package/deps/zlib/gzread.c +668 -0
  224. package/deps/zlib/gzwrite.c +700 -0
  225. package/deps/zlib/infback.c +581 -0
  226. package/deps/zlib/inffast.c +321 -0
  227. package/deps/zlib/inffast.h +11 -0
  228. package/deps/zlib/inffixed.h +94 -0
  229. package/deps/zlib/inflate.c +1413 -0
  230. package/deps/zlib/inflate.h +126 -0
  231. package/deps/zlib/inftrees.c +424 -0
  232. package/deps/zlib/inftrees.h +64 -0
  233. package/deps/zlib/make_vms.com +867 -0
  234. package/deps/zlib/msdos/Makefile.bor +115 -0
  235. package/deps/zlib/msdos/Makefile.dj2 +104 -0
  236. package/deps/zlib/msdos/Makefile.emx +69 -0
  237. package/deps/zlib/msdos/Makefile.msc +112 -0
  238. package/deps/zlib/msdos/Makefile.tc +100 -0
  239. package/deps/zlib/os400/README400 +48 -0
  240. package/deps/zlib/os400/bndsrc +144 -0
  241. package/deps/zlib/os400/make.sh +383 -0
  242. package/deps/zlib/os400/zlibfixed.rpgle +578 -0
  243. package/deps/zlib/os400/zlibfree.rpgle +634 -0
  244. package/deps/zlib/qnx/package.qpg +141 -0
  245. package/deps/zlib/test/CMakeLists.txt +318 -0
  246. package/deps/zlib/test/add_subdirectory_exclude_test.cmake.in +29 -0
  247. package/deps/zlib/test/add_subdirectory_test.cmake.in +28 -0
  248. package/deps/zlib/test/example.c +552 -0
  249. package/deps/zlib/test/find_package_no_components_test.cmake.in +27 -0
  250. package/deps/zlib/test/find_package_test.cmake.in +27 -0
  251. package/deps/zlib/test/find_package_wrong_components_test.cmake.in +27 -0
  252. package/deps/zlib/test/infcover.c +672 -0
  253. package/deps/zlib/test/minigzip.c +592 -0
  254. package/deps/zlib/treebuild.xml +116 -0
  255. package/deps/zlib/trees.c +1119 -0
  256. package/deps/zlib/trees.h +128 -0
  257. package/deps/zlib/uncompr.c +101 -0
  258. package/deps/zlib/watcom/watcom_f.mak +43 -0
  259. package/deps/zlib/watcom/watcom_l.mak +43 -0
  260. package/deps/zlib/win32/DLL_FAQ.txt +381 -0
  261. package/deps/zlib/win32/Makefile.bor +109 -0
  262. package/deps/zlib/win32/Makefile.gcc +177 -0
  263. package/deps/zlib/win32/Makefile.msc +159 -0
  264. package/deps/zlib/win32/README-WIN32.txt +103 -0
  265. package/deps/zlib/win32/VisualC.txt +3 -0
  266. package/deps/zlib/win32/zlib.def +104 -0
  267. package/deps/zlib/win32/zlib1.rc +37 -0
  268. package/deps/zlib/zconf.h.in +551 -0
  269. package/deps/zlib/zlib.3 +149 -0
  270. package/deps/zlib/zlib.3.pdf +0 -0
  271. package/deps/zlib/zlib.h +2057 -0
  272. package/deps/zlib/zlib.map +116 -0
  273. package/deps/zlib/zlib.pc.cmakein +14 -0
  274. package/deps/zlib/zlib.pc.in +14 -0
  275. package/deps/zlib/zlibConfig.cmake.in +18 -0
  276. package/deps/zlib/zutil.c +313 -0
  277. package/deps/zlib/zutil.h +331 -0
  278. package/dist/index.d.ts +266 -0
  279. package/dist/index.js +1146 -0
  280. package/dist/libwz.js +5632 -0
  281. package/dist/libwz.wasm +0 -0
  282. package/include/wz/CRC32.h +182 -0
  283. package/include/wz/PngUtility.h +72 -0
  284. package/include/wz/PortalType.h +124 -0
  285. package/include/wz/Properties/WzBinaryProperty.h +70 -0
  286. package/include/wz/Properties/WzCanvasProperty.h +55 -0
  287. package/include/wz/Properties/WzConvexProperty.h +34 -0
  288. package/include/wz/Properties/WzDoubleProperty.h +32 -0
  289. package/include/wz/Properties/WzFloatProperty.h +30 -0
  290. package/include/wz/Properties/WzIntProperty.h +30 -0
  291. package/include/wz/Properties/WzLongProperty.h +30 -0
  292. package/include/wz/Properties/WzLuaProperty.h +31 -0
  293. package/include/wz/Properties/WzNullProperty.h +15 -0
  294. package/include/wz/Properties/WzPngProperty.h +53 -0
  295. package/include/wz/Properties/WzRawDataProperty.h +46 -0
  296. package/include/wz/Properties/WzShortProperty.h +31 -0
  297. package/include/wz/Properties/WzStringProperty.h +32 -0
  298. package/include/wz/Properties/WzSubProperty.h +35 -0
  299. package/include/wz/Properties/WzUOLProperty.h +44 -0
  300. package/include/wz/Properties/WzVectorProperty.h +40 -0
  301. package/include/wz/Properties/WzVideoProperty.h +43 -0
  302. package/include/wz/Result.h +58 -0
  303. package/include/wz/Util/Defines.h +16 -0
  304. package/include/wz/Util/ListFileParser.h +20 -0
  305. package/include/wz/Util/WzBinaryReader.h +95 -0
  306. package/include/wz/Util/WzBinaryWriter.h +72 -0
  307. package/include/wz/Util/WzBlobDataSource.h +30 -0
  308. package/include/wz/Util/WzDataSource.h +49 -0
  309. package/include/wz/Util/WzKeyGenerator.h +28 -0
  310. package/include/wz/Util/WzMutableKey.h +39 -0
  311. package/include/wz/Util/WzPath.h +37 -0
  312. package/include/wz/Util/WzStream.h +86 -0
  313. package/include/wz/Util/WzTool.h +42 -0
  314. package/include/wz/WzAESConstant.h +17 -0
  315. package/include/wz/WzDirectory.h +97 -0
  316. package/include/wz/WzEnums.h +76 -0
  317. package/include/wz/WzFile.h +99 -0
  318. package/include/wz/WzHeader.h +47 -0
  319. package/include/wz/WzImage.h +97 -0
  320. package/include/wz/WzImageProperty.h +92 -0
  321. package/include/wz/WzObject.h +55 -0
  322. package/include/wz/WzPropertyCollection.h +115 -0
  323. package/include/wz/wz.h +41 -0
  324. package/include/wz/wz_api.h +432 -0
  325. package/package.json +93 -0
  326. package/src/PngUtility.cpp +328 -0
  327. package/src/Properties/WzBinaryProperty.cpp +183 -0
  328. package/src/Properties/WzCanvasProperty.cpp +262 -0
  329. package/src/Properties/WzConvexProperty.cpp +159 -0
  330. package/src/Properties/WzDoubleProperty.cpp +12 -0
  331. package/src/Properties/WzFloatProperty.cpp +17 -0
  332. package/src/Properties/WzIntProperty.cpp +12 -0
  333. package/src/Properties/WzLongProperty.cpp +12 -0
  334. package/src/Properties/WzLuaProperty.cpp +37 -0
  335. package/src/Properties/WzNullProperty.cpp +11 -0
  336. package/src/Properties/WzPngProperty.cpp +637 -0
  337. package/src/Properties/WzRawDataProperty.cpp +116 -0
  338. package/src/Properties/WzShortProperty.cpp +12 -0
  339. package/src/Properties/WzStringProperty.cpp +44 -0
  340. package/src/Properties/WzSubProperty.cpp +129 -0
  341. package/src/Properties/WzUOLProperty.cpp +136 -0
  342. package/src/Properties/WzVectorProperty.cpp +22 -0
  343. package/src/Properties/WzVideoProperty.cpp +115 -0
  344. package/src/Util/ListFileParser.cpp +48 -0
  345. package/src/Util/WzBinaryReader.cpp +368 -0
  346. package/src/Util/WzBinaryWriter.cpp +305 -0
  347. package/src/Util/WzBlobDataSource.cpp +47 -0
  348. package/src/Util/WzDataSource.cpp +61 -0
  349. package/src/Util/WzKeyGenerator.cpp +43 -0
  350. package/src/Util/WzMutableKey.cpp +59 -0
  351. package/src/Util/WzStream.cpp +196 -0
  352. package/src/Util/WzTool.cpp +266 -0
  353. package/src/WzAESConstant.cpp +12 -0
  354. package/src/WzDirectory.cpp +669 -0
  355. package/src/WzEnums.cpp +20 -0
  356. package/src/WzFile.cpp +450 -0
  357. package/src/WzImage.cpp +350 -0
  358. package/src/WzImageProperty.cpp +469 -0
  359. package/src/WzObject.cpp +174 -0
  360. package/src/WzPropertyCollection.cpp +84 -0
  361. package/src/capi/wz_api.cpp +1996 -0
  362. package/src/node/binding.cpp +1776 -0
@@ -0,0 +1,368 @@
1
+ #include "wz/Util/WzBinaryReader.h"
2
+ #include <algorithm>
3
+ #include <cstring>
4
+ #include <limits>
5
+ #include <utility>
6
+ #include "wz/Util/WzTool.h"
7
+ #include "wz/WzAESConstant.h"
8
+ #include "wz/WzImage.h"
9
+
10
+ namespace wz {
11
+
12
+ // Simple UTF-16 to UTF-8 conversion (no deprecated codecvt)
13
+ static std::string Utf16ToUtf8(const std::u16string& utf16) {
14
+ std::string result;
15
+ result.reserve(utf16.size() * 3);
16
+ for (char16_t ch : utf16) {
17
+ if (ch < 0x80) {
18
+ result.push_back(static_cast<char>(ch));
19
+ } else if (ch < 0x800) {
20
+ result.push_back(static_cast<char>(0xC0 | (ch >> 6)));
21
+ result.push_back(static_cast<char>(0x80 | (ch & 0x3F)));
22
+ } else {
23
+ result.push_back(static_cast<char>(0xE0 | (ch >> 12)));
24
+ result.push_back(static_cast<char>(0x80 | ((ch >> 6) & 0x3F)));
25
+ result.push_back(static_cast<char>(0x80 | (ch & 0x3F)));
26
+ }
27
+ }
28
+ return result;
29
+ }
30
+
31
+ WzBinaryReader::WzBinaryReader(std::shared_ptr<WzDataSource> source,
32
+ const std::array<uint8_t, 4>& WzIv,
33
+ int64_t startOffset)
34
+ : source_(std::move(source)),
35
+ position_(startOffset),
36
+ cache_(kCacheSize),
37
+ wzKey_(WzKeyGenerator::GenerateWzKey(WzIv)),
38
+ startOffset_(startOffset) {}
39
+
40
+ WzBinaryReader::~WzBinaryReader() {
41
+ Close();
42
+ }
43
+
44
+ WzBinaryReader::WzBinaryReader(WzBinaryReader&& other) noexcept
45
+ : source_(std::move(other.source_)),
46
+ position_(other.position_),
47
+ cache_(std::move(other.cache_)),
48
+ cacheOffset_(other.cacheOffset_),
49
+ cacheSize_(other.cacheSize_),
50
+ wzKey_(std::move(other.wzKey_)),
51
+ hash_(other.hash_),
52
+ header_(other.header_),
53
+ startOffset_(other.startOffset_) {
54
+ other.header_ = nullptr;
55
+ other.position_ = 0;
56
+ other.cacheOffset_ = 0;
57
+ other.cacheSize_ = 0;
58
+ }
59
+
60
+ WzBinaryReader& WzBinaryReader::operator=(WzBinaryReader&& other) noexcept {
61
+ if (this != &other) {
62
+ Close();
63
+ source_ = std::move(other.source_);
64
+ position_ = other.position_;
65
+ cache_ = std::move(other.cache_);
66
+ cacheOffset_ = other.cacheOffset_;
67
+ cacheSize_ = other.cacheSize_;
68
+ wzKey_ = std::move(other.wzKey_);
69
+ hash_ = other.hash_;
70
+ header_ = other.header_;
71
+ startOffset_ = other.startOffset_;
72
+ other.header_ = nullptr;
73
+ other.position_ = 0;
74
+ other.cacheOffset_ = 0;
75
+ other.cacheSize_ = 0;
76
+ }
77
+ return *this;
78
+ }
79
+
80
+ uint8_t WzBinaryReader::ReadByte() {
81
+ uint8_t b = 0;
82
+ ReadExact(&b, sizeof(b));
83
+ return b;
84
+ }
85
+
86
+ int8_t WzBinaryReader::ReadSByte() {
87
+ int8_t b = 0;
88
+ ReadExact(&b, sizeof(b));
89
+ return b;
90
+ }
91
+
92
+ int16_t WzBinaryReader::ReadInt16() {
93
+ int16_t v = 0;
94
+ ReadExact(&v, sizeof(v));
95
+ return v;
96
+ }
97
+
98
+ int32_t WzBinaryReader::ReadInt32() {
99
+ int32_t v = 0;
100
+ ReadExact(&v, sizeof(v));
101
+ return v;
102
+ }
103
+
104
+ int64_t WzBinaryReader::ReadInt64() {
105
+ int64_t v = 0;
106
+ ReadExact(&v, sizeof(v));
107
+ return v;
108
+ }
109
+
110
+ uint16_t WzBinaryReader::ReadUInt16() {
111
+ uint16_t v = 0;
112
+ ReadExact(&v, sizeof(v));
113
+ return v;
114
+ }
115
+
116
+ uint32_t WzBinaryReader::ReadUInt32() {
117
+ uint32_t v = 0;
118
+ ReadExact(&v, sizeof(v));
119
+ return v;
120
+ }
121
+
122
+ uint64_t WzBinaryReader::ReadUInt64() {
123
+ uint64_t v = 0;
124
+ ReadExact(&v, sizeof(v));
125
+ return v;
126
+ }
127
+
128
+ float WzBinaryReader::ReadSingle() {
129
+ float v = 0;
130
+ ReadExact(&v, sizeof(v));
131
+ return v;
132
+ }
133
+
134
+ double WzBinaryReader::ReadDouble() {
135
+ double v = 0;
136
+ ReadExact(&v, sizeof(v));
137
+ return v;
138
+ }
139
+
140
+ std::vector<uint8_t> WzBinaryReader::ReadBytes(size_t count) {
141
+ std::vector<uint8_t> buf(count);
142
+ if (!ReadExact(buf.data(), count)) return {};
143
+ return buf;
144
+ }
145
+
146
+ int64_t WzBinaryReader::Position() {
147
+ return position_;
148
+ }
149
+
150
+ void WzBinaryReader::SetPosition(int64_t pos) {
151
+ position_ = pos;
152
+ }
153
+
154
+ std::string WzBinaryReader::DecodeAscii(int length) {
155
+ std::string result(length, '\0');
156
+ uint8_t mask = 0xAA;
157
+ for (int i = 0; i < length; i++) {
158
+ uint8_t encryptedChar = ReadByte();
159
+ encryptedChar ^= mask;
160
+ encryptedChar ^= wzKey_[i];
161
+ result[i] = static_cast<char>(encryptedChar);
162
+ mask++;
163
+ }
164
+ return result;
165
+ }
166
+
167
+ std::string WzBinaryReader::DecodeUnicode(int length) {
168
+ std::u16string utf16(length, u'\0');
169
+ uint16_t mask = 0xAAAA;
170
+ for (int i = 0; i < length; i++) {
171
+ uint16_t encryptedChar = ReadUInt16();
172
+ encryptedChar ^= mask;
173
+ encryptedChar ^=
174
+ static_cast<uint16_t>((wzKey_[i * 2 + 1] << 8) + wzKey_[i * 2]);
175
+ utf16[i] = static_cast<char16_t>(encryptedChar);
176
+ mask++;
177
+ }
178
+ return Utf16ToUtf8(utf16);
179
+ }
180
+
181
+ std::string WzBinaryReader::ReadString() {
182
+ int8_t smallLength = ReadSByte();
183
+ if (smallLength == 0) return {};
184
+
185
+ int length;
186
+ if (smallLength > 0)
187
+ length =
188
+ (smallLength == INT8_MAX) ? ReadInt32() : static_cast<int>(smallLength);
189
+ else
190
+ length = (smallLength == INT8_MIN) ? ReadInt32()
191
+ : static_cast<int>(-smallLength);
192
+
193
+ if (length <= 0) return {};
194
+
195
+ if (smallLength > 0)
196
+ return DecodeUnicode(length);
197
+ else
198
+ return DecodeAscii(length);
199
+ }
200
+
201
+ std::string WzBinaryReader::ReadString(size_t length) {
202
+ std::vector<char> buf(length);
203
+ ReadExact(buf.data(), length);
204
+ return std::string(buf.data(), length);
205
+ }
206
+
207
+ std::string WzBinaryReader::ReadNullTerminatedString() {
208
+ std::string result;
209
+ char c = '\0';
210
+ while (ReadExact(&c, 1) && c != '\0') {
211
+ result += c;
212
+ }
213
+ return result;
214
+ }
215
+
216
+ int32_t WzBinaryReader::ReadCompressedInt() {
217
+ int8_t sb = ReadSByte();
218
+ if (sb == INT8_MIN) {
219
+ return ReadInt32();
220
+ }
221
+ return sb;
222
+ }
223
+
224
+ int64_t WzBinaryReader::ReadLong() {
225
+ int8_t sb = ReadSByte();
226
+ if (sb == INT8_MIN) {
227
+ return ReadInt64();
228
+ }
229
+ return sb;
230
+ }
231
+
232
+ int64_t WzBinaryReader::Available() {
233
+ if (!source_ || position_ < 0) return 0;
234
+ const uint64_t pos = static_cast<uint64_t>(position_);
235
+ const uint64_t size = source_->Size();
236
+ if (pos >= size) return 0;
237
+ const uint64_t available = size - pos;
238
+ if (available > static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
239
+ return std::numeric_limits<int64_t>::max();
240
+ }
241
+ return static_cast<int64_t>(available);
242
+ }
243
+
244
+ uint64_t WzBinaryReader::SourceSize() const {
245
+ return source_ ? source_->Size() : 0;
246
+ }
247
+
248
+ int64_t WzBinaryReader::ReadOffset() {
249
+ uint32_t offset = static_cast<uint32_t>(Position());
250
+ offset = (offset - header_->FStart()) ^ 0xFFFFFFFF;
251
+ offset *= hash_;
252
+ offset -= WzAESConstant::WZ_OffsetConstant;
253
+ offset = WzTool::RotateLeft(offset, static_cast<uint8_t>(offset & 0x1F));
254
+ uint32_t encryptedOffset = ReadUInt32();
255
+ offset ^= encryptedOffset;
256
+ offset += header_->FStart() * 2;
257
+ return static_cast<int64_t>(offset) + startOffset_;
258
+ }
259
+
260
+ std::string WzBinaryReader::ReadStringAtOffset(int64_t offset, bool readByte) {
261
+ int64_t currentOffset = Position();
262
+ SetPosition(offset - startOffset_);
263
+ if (readByte) {
264
+ ReadByte();
265
+ }
266
+ std::string returnString = ReadString();
267
+ SetPosition(currentOffset);
268
+ return returnString;
269
+ }
270
+
271
+ std::string WzBinaryReader::ReadStringBlock(int64_t offset) {
272
+ uint8_t flag = ReadByte();
273
+ switch (flag) {
274
+ case 0:
275
+ case WzImage::WzImageHeaderByte_WithoutOffset:
276
+ return ReadString();
277
+ case 1:
278
+ case WzImage::WzImageHeaderByte_WithOffset:
279
+ return ReadStringAtOffset(offset + ReadInt32());
280
+ default:
281
+ return {};
282
+ }
283
+ }
284
+
285
+ void WzBinaryReader::SetOffsetFromFStartToPosition(int offset) {
286
+ SetPosition(static_cast<int64_t>(header_->FStart() + offset) - startOffset_);
287
+ }
288
+
289
+ Result<void> WzBinaryReader::RollbackStreamPosition(int byOffset) {
290
+ int64_t pos = Position() - static_cast<int64_t>(byOffset);
291
+ if (pos < startOffset_)
292
+ return std::unexpected(
293
+ Error::IoError("Cant rollback stream position below 0"));
294
+ SetPosition(pos);
295
+ return {};
296
+ }
297
+
298
+ std::string WzBinaryReader::DecryptString(
299
+ const std::u16string& stringToDecrypt) {
300
+ size_t len = stringToDecrypt.length();
301
+ std::u16string output(len, u'\0');
302
+ for (size_t i = 0; i < len; i++) {
303
+ output[i] = static_cast<char16_t>(
304
+ static_cast<uint16_t>(stringToDecrypt[i]) ^
305
+ static_cast<uint16_t>((wzKey_[i * 2 + 1] << 8) + wzKey_[i * 2]));
306
+ }
307
+ return Utf16ToUtf8(output);
308
+ }
309
+
310
+ std::string WzBinaryReader::DecryptNonUnicodeString(
311
+ const std::u16string& stringToDecrypt) {
312
+ size_t len = stringToDecrypt.length();
313
+ std::u16string output(len, u'\0');
314
+ for (size_t i = 0; i < len; i++) {
315
+ output[i] =
316
+ static_cast<char16_t>(static_cast<uint16_t>(stringToDecrypt[i]) ^
317
+ static_cast<uint16_t>(wzKey_[i]));
318
+ }
319
+ return Utf16ToUtf8(output);
320
+ }
321
+
322
+ void WzBinaryReader::PrintHexBytes(int numberOfBytes) {
323
+ // Debug only
324
+ (void)numberOfBytes;
325
+ }
326
+
327
+ void WzBinaryReader::Close() {
328
+ source_.reset();
329
+ cache_.clear();
330
+ cacheOffset_ = 0;
331
+ cacheSize_ = 0;
332
+ }
333
+
334
+ bool WzBinaryReader::ReadExact(void* destination, size_t count) {
335
+ if (count == 0) return true;
336
+ auto* output = static_cast<uint8_t*>(destination);
337
+ size_t total = 0;
338
+
339
+ while (total < count) {
340
+ if (position_ < 0) return false;
341
+ const uint64_t current = static_cast<uint64_t>(position_);
342
+ const uint64_t cacheEnd = cacheOffset_ + cacheSize_;
343
+ if (cacheSize_ == 0 || current < cacheOffset_ || current >= cacheEnd) {
344
+ if (!FillCache()) return false;
345
+ if (cacheSize_ == 0) return false;
346
+ }
347
+
348
+ const size_t cacheIndex = static_cast<size_t>(current - cacheOffset_);
349
+ const size_t available = cacheSize_ - cacheIndex;
350
+ const size_t toCopy = std::min(count - total, available);
351
+ std::memcpy(output + total, cache_.data() + cacheIndex, toCopy);
352
+ total += toCopy;
353
+ position_ += static_cast<int64_t>(toCopy);
354
+ }
355
+ return true;
356
+ }
357
+
358
+ bool WzBinaryReader::FillCache() {
359
+ if (!source_ || position_ < 0) return false;
360
+ cacheOffset_ = static_cast<uint64_t>(position_);
361
+ cacheSize_ = 0;
362
+ auto readResult = source_->ReadAt(cacheOffset_, cache_);
363
+ if (!readResult.has_value()) return false;
364
+ cacheSize_ = readResult.value();
365
+ return true;
366
+ }
367
+
368
+ } // namespace wz
@@ -0,0 +1,305 @@
1
+ #include "wz/Util/WzBinaryWriter.h"
2
+ #include <cstring>
3
+ #include <utility>
4
+ #include "wz/WzAESConstant.h"
5
+
6
+ namespace wz {
7
+
8
+ namespace {
9
+
10
+ std::u16string Utf8ToUtf16(const std::string& value) {
11
+ std::u16string result;
12
+ result.reserve(value.size());
13
+
14
+ for (size_t i = 0; i < value.size();) {
15
+ uint8_t ch = static_cast<uint8_t>(value[i]);
16
+ uint32_t codePoint = 0;
17
+ size_t extraBytes = 0;
18
+
19
+ if ((ch & 0x80) == 0) {
20
+ codePoint = ch;
21
+ } else if ((ch & 0xE0) == 0xC0) {
22
+ codePoint = ch & 0x1F;
23
+ extraBytes = 1;
24
+ } else if ((ch & 0xF0) == 0xE0) {
25
+ codePoint = ch & 0x0F;
26
+ extraBytes = 2;
27
+ } else if ((ch & 0xF8) == 0xF0) {
28
+ codePoint = ch & 0x07;
29
+ extraBytes = 3;
30
+ } else {
31
+ result.push_back(static_cast<char16_t>(ch));
32
+ ++i;
33
+ continue;
34
+ }
35
+
36
+ if (i + extraBytes >= value.size()) {
37
+ result.push_back(static_cast<char16_t>(ch));
38
+ ++i;
39
+ continue;
40
+ }
41
+
42
+ bool valid = true;
43
+ for (size_t j = 1; j <= extraBytes; ++j) {
44
+ uint8_t next = static_cast<uint8_t>(value[i + j]);
45
+ if ((next & 0xC0) != 0x80) {
46
+ valid = false;
47
+ break;
48
+ }
49
+ codePoint = (codePoint << 6) | (next & 0x3F);
50
+ }
51
+
52
+ if (!valid) {
53
+ result.push_back(static_cast<char16_t>(ch));
54
+ ++i;
55
+ continue;
56
+ }
57
+
58
+ if (codePoint <= 0xFFFF) {
59
+ result.push_back(static_cast<char16_t>(codePoint));
60
+ } else {
61
+ codePoint -= 0x10000;
62
+ result.push_back(static_cast<char16_t>(0xD800 + (codePoint >> 10)));
63
+ result.push_back(static_cast<char16_t>(0xDC00 + (codePoint & 0x3FF)));
64
+ }
65
+ i += extraBytes + 1;
66
+ }
67
+
68
+ return result;
69
+ }
70
+
71
+ bool NeedsUnicode(const std::u16string& value) {
72
+ for (char16_t ch : value) {
73
+ if (ch > INT8_MAX) return true;
74
+ }
75
+ return false;
76
+ }
77
+
78
+ uint32_t RotateLeft32(uint32_t value, uint8_t count) {
79
+ count &= 0x1F;
80
+ if (count == 0) return value;
81
+ return static_cast<uint32_t>((value << count) | (value >> (32 - count)));
82
+ }
83
+
84
+ } // namespace
85
+
86
+ WzBinaryWriter::WzBinaryWriter(WzStream& output,
87
+ const std::array<uint8_t, 4>& WzIv)
88
+ : output_(&output), wzKey_(WzKeyGenerator::GenerateWzKey(WzIv)) {}
89
+
90
+ WzBinaryWriter::WzBinaryWriter(WzStream& output,
91
+ const std::array<uint8_t, 4>& WzIv,
92
+ uint32_t hash)
93
+ : output_(&output),
94
+ wzKey_(WzKeyGenerator::GenerateWzKey(WzIv)),
95
+ hash_(hash) {}
96
+
97
+ WzBinaryWriter::WzBinaryWriter(WzBinaryWriter&& other) noexcept
98
+ : output_(other.output_),
99
+ wzKey_(std::move(other.wzKey_)),
100
+ hash_(other.hash_),
101
+ header_(other.header_),
102
+ stringCache_(std::move(other.stringCache_)) {
103
+ other.output_ = nullptr;
104
+ }
105
+
106
+ WzBinaryWriter& WzBinaryWriter::operator=(WzBinaryWriter&& other) noexcept {
107
+ if (this != &other) {
108
+ output_ = other.output_;
109
+ wzKey_ = std::move(other.wzKey_);
110
+ hash_ = other.hash_;
111
+ header_ = other.header_;
112
+ stringCache_ = std::move(other.stringCache_);
113
+ other.output_ = nullptr;
114
+ }
115
+ return *this;
116
+ }
117
+
118
+ int64_t WzBinaryWriter::Position() {
119
+ return output_ ? output_->Position() : -1;
120
+ }
121
+
122
+ void WzBinaryWriter::ClearStringCache() {
123
+ stringCache_.clear();
124
+ }
125
+
126
+ bool WzBinaryWriter::WriteRawByte(uint8_t value) {
127
+ return output_ && output_->WriteByte(value);
128
+ }
129
+
130
+ template <typename T>
131
+ void WzBinaryWriter::WriteLittleEndian(T value) {
132
+ uint8_t bytes[sizeof(T)];
133
+ std::memcpy(bytes, &value, sizeof(T));
134
+ #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
135
+ for (size_t i = 0; i < sizeof(T) / 2; ++i) {
136
+ std::swap(bytes[i], bytes[sizeof(T) - 1 - i]);
137
+ }
138
+ #endif
139
+ BaseStream().Write(bytes, sizeof(T));
140
+ }
141
+
142
+ void WzBinaryWriter::WriteByte(uint8_t value) {
143
+ WriteRawByte(value);
144
+ }
145
+
146
+ void WzBinaryWriter::WriteSByte(int8_t value) {
147
+ WriteByte(static_cast<uint8_t>(value));
148
+ }
149
+
150
+ void WzBinaryWriter::WriteInt16(int16_t value) {
151
+ WriteLittleEndian(value);
152
+ }
153
+
154
+ void WzBinaryWriter::WriteInt32(int32_t value) {
155
+ WriteLittleEndian(value);
156
+ }
157
+
158
+ void WzBinaryWriter::WriteInt64(int64_t value) {
159
+ WriteLittleEndian(value);
160
+ }
161
+
162
+ void WzBinaryWriter::WriteUInt16(uint16_t value) {
163
+ WriteLittleEndian(value);
164
+ }
165
+
166
+ void WzBinaryWriter::WriteUInt32(uint32_t value) {
167
+ WriteLittleEndian(value);
168
+ }
169
+
170
+ void WzBinaryWriter::WriteUInt64(uint64_t value) {
171
+ WriteLittleEndian(value);
172
+ }
173
+
174
+ void WzBinaryWriter::WriteSingle(float value) {
175
+ WriteLittleEndian(value);
176
+ }
177
+
178
+ void WzBinaryWriter::WriteDouble(double value) {
179
+ WriteLittleEndian(value);
180
+ }
181
+
182
+ void WzBinaryWriter::WriteString(const std::string& value) {
183
+ if (value.empty()) {
184
+ WriteByte(0);
185
+ return;
186
+ }
187
+
188
+ std::u16string utf16 = Utf8ToUtf16(value);
189
+ if (NeedsUnicode(utf16)) {
190
+ WriteUnicodeString(utf16);
191
+ } else {
192
+ WriteAsciiString(value);
193
+ }
194
+ }
195
+
196
+ void WzBinaryWriter::WriteAsciiString(const std::string& value) {
197
+ const int32_t length = static_cast<int32_t>(value.length());
198
+ if (length > INT8_MAX) {
199
+ WriteSByte(INT8_MIN);
200
+ WriteInt32(length);
201
+ } else {
202
+ WriteSByte(static_cast<int8_t>(-length));
203
+ }
204
+
205
+ uint8_t mask = 0xAA;
206
+ for (int32_t i = 0; i < length; ++i) {
207
+ uint8_t encryptedChar = static_cast<uint8_t>(value[i]);
208
+ encryptedChar ^= wzKey_[i];
209
+ encryptedChar ^= mask;
210
+ WriteByte(encryptedChar);
211
+ ++mask;
212
+ }
213
+ }
214
+
215
+ void WzBinaryWriter::WriteUnicodeString(const std::u16string& value) {
216
+ const int32_t length = static_cast<int32_t>(value.length());
217
+ if (length >= INT8_MAX) {
218
+ WriteSByte(INT8_MAX);
219
+ WriteInt32(length);
220
+ } else {
221
+ WriteSByte(static_cast<int8_t>(length));
222
+ }
223
+
224
+ uint16_t mask = 0xAAAA;
225
+ for (int32_t i = 0; i < length; ++i) {
226
+ uint16_t encryptedChar = static_cast<uint16_t>(value[i]);
227
+ encryptedChar ^=
228
+ static_cast<uint16_t>((wzKey_[i * 2 + 1] << 8) + wzKey_[i * 2]);
229
+ encryptedChar ^= mask;
230
+ WriteUInt16(encryptedChar);
231
+ ++mask;
232
+ }
233
+ }
234
+
235
+ void WzBinaryWriter::WriteNullTerminatedString(const std::string& value) {
236
+ BaseStream().Write(value.data(), value.size());
237
+ WriteByte(0);
238
+ }
239
+
240
+ void WzBinaryWriter::WriteStringValue(const std::string& value,
241
+ uint8_t withoutOffset,
242
+ uint8_t withOffset) {
243
+ auto found = stringCache_.find(value);
244
+ if (value.length() > 4 && found != stringCache_.end()) {
245
+ WriteByte(withOffset);
246
+ WriteInt32(found->second);
247
+ return;
248
+ }
249
+
250
+ WriteByte(withoutOffset);
251
+ int32_t stringOffset = static_cast<int32_t>(Position());
252
+ WriteString(value);
253
+ stringCache_.try_emplace(value, stringOffset);
254
+ }
255
+
256
+ bool WzBinaryWriter::WriteWzObjectValue(const std::string& value,
257
+ WzDirectoryType type) {
258
+ std::string storeName =
259
+ std::to_string(static_cast<uint8_t>(type)) + "_" + value;
260
+ auto found = stringCache_.find(storeName);
261
+ if (value.length() > 4 && found != stringCache_.end()) {
262
+ WriteByte(
263
+ static_cast<uint8_t>(WzDirectoryType::RetrieveStringFromOffset_2));
264
+ WriteInt32(found->second);
265
+ return true;
266
+ }
267
+
268
+ int32_t stringOffset =
269
+ static_cast<int32_t>(Position() - static_cast<int64_t>(header_.FStart()));
270
+ WriteByte(static_cast<uint8_t>(type));
271
+ WriteString(value);
272
+ stringCache_.try_emplace(storeName, stringOffset);
273
+ return false;
274
+ }
275
+
276
+ void WzBinaryWriter::WriteCompressedInt(int32_t value) {
277
+ if (value > INT8_MAX || value <= INT8_MIN) {
278
+ WriteSByte(INT8_MIN);
279
+ WriteInt32(value);
280
+ } else {
281
+ WriteSByte(static_cast<int8_t>(value));
282
+ }
283
+ }
284
+
285
+ void WzBinaryWriter::WriteCompressedLong(int64_t value) {
286
+ if (value > INT8_MAX || value <= INT8_MIN) {
287
+ WriteSByte(INT8_MIN);
288
+ WriteInt64(value);
289
+ } else {
290
+ WriteSByte(static_cast<int8_t>(value));
291
+ }
292
+ }
293
+
294
+ void WzBinaryWriter::WriteOffset(int64_t value) {
295
+ uint32_t encOffset = static_cast<uint32_t>(Position());
296
+ encOffset = (encOffset - header_.FStart()) ^ 0xFFFFFFFFu;
297
+ encOffset *= hash_;
298
+ encOffset -= WzAESConstant::WZ_OffsetConstant;
299
+ encOffset = RotateLeft32(encOffset, static_cast<uint8_t>(encOffset));
300
+ uint32_t writeOffset =
301
+ encOffset ^ (static_cast<uint32_t>(value) - (header_.FStart() * 2));
302
+ WriteUInt32(writeOffset);
303
+ }
304
+
305
+ } // namespace wz
@@ -0,0 +1,47 @@
1
+ #include "wz/Util/WzBlobDataSource.h"
2
+
3
+ #include <algorithm>
4
+ #include <limits>
5
+ #include <utility>
6
+
7
+ namespace wz {
8
+
9
+ WzBlobDataSource::WzBlobDataSource(uint64_t size, ReadCallback read_callback)
10
+ : size_(size), read_callback_(std::move(read_callback)) {}
11
+
12
+ Result<size_t> WzBlobDataSource::ReadAt(uint64_t offset,
13
+ std::span<uint8_t> destination) {
14
+ if (offset > size_) {
15
+ return std::unexpected(Error::IoError("Read offset is beyond blob size"));
16
+ }
17
+
18
+ const uint64_t available = size_ - offset;
19
+ const size_t count = static_cast<size_t>(
20
+ std::min<uint64_t>(available, static_cast<uint64_t>(destination.size())));
21
+ if (count == 0) return 0;
22
+ if (count > static_cast<size_t>(std::numeric_limits<int>::max())) {
23
+ return std::unexpected(Error::IoError("Blob read size exceeds limits"));
24
+ }
25
+ if (offset > 9007199254740991ULL) {
26
+ return std::unexpected(Error::IoError("Blob read offset exceeds limits"));
27
+ }
28
+
29
+ if (!read_callback_) {
30
+ return std::unexpected(Error::IoError("Blob read callback is not set"));
31
+ }
32
+
33
+ auto bytes_read = read_callback_(offset, destination.subspan(0, count));
34
+ if (!bytes_read.has_value()) {
35
+ return std::unexpected(bytes_read.error());
36
+ }
37
+ if (bytes_read.value() != count) {
38
+ return std::unexpected(Error::IoError("Failed to read blob range"));
39
+ }
40
+ return bytes_read.value();
41
+ }
42
+
43
+ uint64_t WzBlobDataSource::Size() const {
44
+ return size_;
45
+ }
46
+
47
+ } // namespace wz