cfsolve 0.1.1 → 0.1.3

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 (404) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/README.md +10 -9
  4. data/THIRD_PARTY_LICENSES/README.md +71 -254
  5. data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
  6. data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
  7. data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
  8. data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
  9. data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
  10. data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
  11. data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
  12. data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
  13. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
  14. data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
  15. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
  16. data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
  17. data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
  18. data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
  19. data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
  20. data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
  21. data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
  22. data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
  23. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
  24. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
  25. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
  26. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
  27. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
  28. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
  29. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
  30. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
  31. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
  32. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
  33. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
  34. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
  35. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
  36. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
  37. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
  38. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
  39. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
  40. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
  41. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
  42. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
  43. data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
  44. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
  45. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
  46. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
  47. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
  48. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
  49. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
  50. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
  51. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
  52. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
  53. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
  54. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
  55. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
  56. data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
  57. data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
  58. data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
  59. data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
  60. data/UPSTREAM.md +10 -8
  61. data/ext/cfsolve/Cargo.lock +534 -1727
  62. data/ext/cfsolve/Cargo.toml +4 -0
  63. data/ext/cfsolve/src/main.rs +1 -1
  64. data/lib/cfsolve/profiles/safari-26-ios/answers.json +2570 -1894
  65. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
  66. data/lib/cfsolve/profiles/safari-26-ios.json +102 -156
  67. data/lib/cfsolve/version.rb +2 -2
  68. data/vendor/cfsolve/Cargo.lock +561 -1729
  69. data/vendor/cfsolve/Cargo.toml +26 -8
  70. data/vendor/cfsolve/README.md +4 -35
  71. data/vendor/cfsolve/examples/build_profile.rs +17 -15
  72. data/vendor/cfsolve/examples/capture_session.rs +37 -0
  73. data/vendor/cfsolve/examples/check_answers.rs +66 -0
  74. data/vendor/cfsolve/examples/compare_session.rs +189 -0
  75. data/vendor/cfsolve/examples/solver_profile.rs +84 -0
  76. data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
  77. data/vendor/cfsolve/examples/stage2_snapshot.rs +6 -3
  78. data/vendor/cfsolve/examples/tls_echo.rs +3 -3
  79. data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
  80. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +2570 -1894
  81. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
  82. data/vendor/cfsolve/profiles/safari-26-ios.json +102 -156
  83. data/vendor/cfsolve/scripts/capture_cssom.mjs +42 -0
  84. data/vendor/cfsolve/scripts/serve_cssom.py +111 -0
  85. data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
  86. data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
  87. data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
  88. data/vendor/cfsolve/src/capture/profile.rs +7 -18
  89. data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
  90. data/vendor/cfsolve/src/capture/proxy.rs +44 -13
  91. data/vendor/cfsolve/src/capture/recorded.rs +42 -7
  92. data/vendor/cfsolve/src/capture/sessions.rs +4 -3
  93. data/vendor/cfsolve/src/capture/upstream.rs +1 -1
  94. data/vendor/cfsolve/src/challenge/codec.rs +4 -2
  95. data/vendor/cfsolve/src/challenge/expression.rs +161 -117
  96. data/vendor/cfsolve/src/challenge/installed/audit.rs +132 -0
  97. data/vendor/cfsolve/src/challenge/installed.rs +127 -269
  98. data/vendor/cfsolve/src/challenge/merge.rs +120 -80
  99. data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
  100. data/vendor/cfsolve/src/challenge/payload.rs +175 -35
  101. data/vendor/cfsolve/src/challenge/program.rs +197 -178
  102. data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
  103. data/vendor/cfsolve/src/challenge/source.rs +151 -96
  104. data/vendor/cfsolve/src/challenge/state.rs +236 -122
  105. data/vendor/cfsolve/src/challenge/tally.rs +64 -50
  106. data/vendor/cfsolve/src/challenge.rs +1 -0
  107. data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
  108. data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
  109. data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
  110. data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
  111. data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
  112. data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
  113. data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
  114. data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
  115. data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
  116. data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
  117. data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
  118. data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
  119. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
  120. data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
  121. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
  122. data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
  123. data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
  124. data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +201 -205
  125. data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
  126. data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +346 -536
  127. data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
  128. data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
  129. data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
  130. data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
  131. data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
  132. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
  133. data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
  134. data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +361 -322
  135. data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
  136. data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
  137. data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
  138. data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
  139. data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
  140. data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
  141. data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
  142. data/vendor/cfsolve/src/deobfuscate.rs +15 -11
  143. data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -32
  144. data/vendor/cfsolve/src/embedding_page/page.rs +28 -2
  145. data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
  146. data/vendor/cfsolve/src/error.rs +40 -5
  147. data/vendor/cfsolve/src/fingerprint.rs +8 -2
  148. data/vendor/cfsolve/src/http/client.rs +9 -1
  149. data/vendor/cfsolve/src/http/requests.rs +2 -2
  150. data/vendor/cfsolve/src/js/ast.rs +479 -254
  151. data/vendor/cfsolve/src/js/objects.rs +9 -2
  152. data/vendor/cfsolve/src/lib.rs +1 -0
  153. data/vendor/cfsolve/src/listing/fold.rs +19 -92
  154. data/vendor/cfsolve/src/listing/query.rs +26 -291
  155. data/vendor/cfsolve/src/listing.rs +0 -1
  156. data/vendor/cfsolve/src/performance_clock.rs +20 -1
  157. data/vendor/cfsolve/src/profiling.rs +49 -0
  158. data/vendor/cfsolve/src/script.rs +35 -24
  159. data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
  160. data/vendor/cfsolve/src/session/channel.rs +2 -2
  161. data/vendor/cfsolve/src/session/initial.rs +19 -10
  162. data/vendor/cfsolve/src/session/probes.rs +160 -125
  163. data/vendor/cfsolve/src/session/sink.rs +26 -1
  164. data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
  165. data/vendor/cfsolve/src/session/timing.rs +58 -53
  166. data/vendor/cfsolve/src/session/widget.rs +5 -6
  167. data/vendor/cfsolve/src/session.rs +1 -1
  168. data/vendor/cfsolve/src/solver.rs +3 -1
  169. data/vendor/cfsolve/src/stage2/analysis/analyze.rs +50 -33
  170. data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
  171. data/vendor/cfsolve/src/stage2/analysis/discovery.rs +61 -66
  172. data/vendor/cfsolve/src/stage2/analysis/envelope.rs +33 -22
  173. data/vendor/cfsolve/src/stage2/analysis/recognize.rs +3 -5
  174. data/vendor/cfsolve/src/stage2/analysis.rs +0 -1
  175. data/vendor/cfsolve/src/stage2/audit_globals.rs +378 -0
  176. data/vendor/cfsolve/src/stage2/benchmark.rs +66 -38
  177. data/vendor/cfsolve/src/stage2/call_stack.rs +1463 -1017
  178. data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
  179. data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
  180. data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
  181. data/vendor/cfsolve/src/stage2/interaction/native.rs +2 -1
  182. data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -7
  183. data/vendor/cfsolve/src/stage2/payload/recover.rs +56 -25
  184. data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
  185. data/vendor/cfsolve/src/stage2/probes/ice.rs +11 -10
  186. data/vendor/cfsolve/src/stage2/probes/media.rs +47 -33
  187. data/vendor/cfsolve/src/stage2/probes/performance.rs +13 -8
  188. data/vendor/cfsolve/src/stage2/probes/rects.rs +12 -17
  189. data/vendor/cfsolve/src/stage2/probes/stack.rs +50 -103
  190. data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +17 -86
  191. data/vendor/cfsolve/src/stage2/probes.rs +0 -1
  192. data/vendor/cfsolve/src/stage2/queries.rs +50 -0
  193. data/vendor/cfsolve/src/stage2/records.rs +4 -13
  194. data/vendor/cfsolve/src/stage2/reference.json +1 -1
  195. data/vendor/cfsolve/src/stage2/reference.rs +98 -100
  196. data/vendor/cfsolve/src/stage2/registry.rs +41 -34
  197. data/vendor/cfsolve/src/stage2/replay.rs +182 -254
  198. data/vendor/cfsolve/src/stage2/stylesheets.rs +176 -0
  199. data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
  200. data/vendor/cfsolve/src/stage2/trace.rs +152 -108
  201. data/vendor/cfsolve/src/stage2/vocabulary.rs +103 -403
  202. data/vendor/cfsolve/src/stage2.rs +4 -1
  203. data/vendor/cfsolve/src/vm/disassemble.rs +46 -13
  204. data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
  205. data/vendor/cfsolve/src/vm/extract.rs +347 -250
  206. data/vendor/cfsolve/src/vm/interpret/access.rs +67 -68
  207. data/vendor/cfsolve/src/vm/interpret/builtin.rs +16 -63
  208. data/vendor/cfsolve/src/vm/interpret/call.rs +192 -51
  209. data/vendor/cfsolve/src/vm/interpret/compile.rs +643 -0
  210. data/vendor/cfsolve/src/vm/interpret/copies.rs +232 -120
  211. data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +149 -40
  212. data/vendor/cfsolve/src/vm/interpret/evaluate.rs +189 -572
  213. data/vendor/cfsolve/src/vm/interpret/explore.rs +159 -46
  214. data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
  215. data/vendor/cfsolve/src/vm/interpret/frozen.rs +169 -0
  216. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +414 -0
  217. data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
  218. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
  219. data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
  220. data/vendor/cfsolve/src/vm/interpret/plan.rs +605 -330
  221. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
  222. data/vendor/cfsolve/src/vm/interpret/run.rs +314 -54
  223. data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
  224. data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
  225. data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
  226. data/vendor/cfsolve/src/vm/interpret.rs +16 -3
  227. data/vendor/cfsolve/src/vm/machine.rs +58 -47
  228. data/vendor/cfsolve/src/vm/output.rs +13 -5
  229. data/vendor/cfsolve/src/vm/packed_names.rs +311 -0
  230. data/vendor/cfsolve/src/vm/session.rs +197 -110
  231. data/vendor/cfsolve/src/vm/value.rs +35 -19
  232. data/vendor/cfsolve/src/vm.rs +3 -1
  233. data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
  234. data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
  235. data/vendor/cfsolve/vendor/btls-sys/src/lib.rs +3 -0
  236. metadata +106 -183
  237. data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
  238. data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
  239. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
  240. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
  241. data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
  242. data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
  243. data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
  244. data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
  245. data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
  246. data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
  247. data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
  248. data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
  249. data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
  250. data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
  251. data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
  252. data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
  253. data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
  254. data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
  255. data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
  256. data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
  257. data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
  258. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
  259. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
  260. data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
  261. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
  262. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
  263. data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
  264. data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
  265. data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
  266. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
  267. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
  268. data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
  269. data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
  270. data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
  271. data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
  272. data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
  273. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
  274. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
  275. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
  276. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
  277. data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
  278. data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
  279. data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
  280. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
  281. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
  282. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
  283. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
  284. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
  285. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
  286. data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
  287. data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
  288. data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
  289. data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
  290. data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
  291. data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
  292. data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
  293. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
  294. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
  295. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
  296. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
  297. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
  298. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
  299. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
  300. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
  301. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
  302. data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
  303. data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
  304. data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
  305. data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
  306. data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
  307. data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
  308. data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
  309. data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
  310. data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
  311. data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
  312. data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
  313. data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
  314. data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
  315. data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
  316. data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
  317. data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
  318. data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
  319. data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
  320. data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
  321. data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
  322. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
  323. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
  324. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
  325. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
  326. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
  327. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
  328. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
  329. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
  330. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
  331. data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
  332. data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
  333. data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
  334. data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
  335. data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
  336. data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
  337. data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
  338. data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
  339. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
  340. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
  341. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
  342. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
  343. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
  344. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
  345. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
  346. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
  347. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
  348. data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
  349. data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
  350. data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
  351. data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
  352. data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
  353. data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
  354. data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
  355. data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
  356. data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
  357. data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
  358. data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
  359. data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
  360. data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
  361. data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
  362. data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
  363. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
  364. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
  365. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
  366. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
  367. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
  368. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
  369. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
  370. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
  371. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
  372. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
  373. data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
  374. data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
  375. data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
  376. data/vendor/cfsolve/src/listing/normalize.rs +0 -264
  377. data/vendor/cfsolve/src/stage2/analysis/outputs.rs +0 -327
  378. data/vendor/cfsolve/src/stage2/probes/stylesheets.rs +0 -249
  379. data/vendor/cfsolve/src/stage2/reference-expanded.json +0 -42
  380. data/vendor/cfsolve/src/stage2/session_names.rs +0 -470
  381. /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
  382. /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
  383. /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
  384. /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
  385. /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
  386. /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
  387. /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
  388. /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
  389. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
  390. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
  391. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
  392. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
  393. /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
  394. /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
  395. /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
  396. /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
  397. /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
  398. /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
  399. /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
  400. /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
  401. /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
  402. /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
  403. /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
  404. /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
@@ -0,0 +1,414 @@
1
+ //! Native versions of script functions. Register bookkeeping is recognized structurally;
2
+ //! BLAKE3 compression must also agree on test inputs. Calls outside each native version's
3
+ //! supported arguments are interpreted.
4
+
5
+ use std::ptr;
6
+
7
+ use oxc::ast::ast::{Function, NumericLiteral, ObjectProperty};
8
+ use oxc::ast_visit::{Visit, walk};
9
+ use oxc::semantic::ScopeFlags;
10
+
11
+ use super::copies::Copies;
12
+ use super::mix32::Mix32;
13
+ use super::register_helpers::{self, Helper};
14
+ use super::run::Run;
15
+ use crate::js;
16
+ use crate::vm::session::Session;
17
+ use crate::vm::value::{Callable, Value};
18
+ use crate::vm::{HashMap, extract};
19
+
20
+ /// A native function equivalent to a script function.
21
+ #[derive(Clone, Copy)]
22
+ pub(crate) enum Intrinsic {
23
+ /// Bookkeeping on the interpreter's unmasked register file.
24
+ Register(Helper),
25
+ Mix32(Mix32),
26
+ /// `compress(cv, block, counter, length, flags)`: overwrites the 8 words of `cv` with the
27
+ /// BLAKE3 compression of the 16-word `block`.
28
+ Blake3Compress,
29
+ }
30
+
31
+ /// Script functions with native equivalents, by function address.
32
+ pub(crate) type Intrinsics = HashMap<usize, Intrinsic>;
33
+
34
+ /// The address identifying `function` in [`Intrinsics`].
35
+ pub(super) fn address(function: &Function<'_>) -> usize {
36
+ ptr::from_ref(function).addr()
37
+ }
38
+
39
+ /// Finds register helpers and mixers, and validates BLAKE3 candidates taking five parameters
40
+ /// and mentioning its initialization vector's first word, which some builds store complemented.
41
+ pub(crate) fn intrinsics(session: &Session<'_>) -> Intrinsics {
42
+ let mut intrinsics = Intrinsics::default();
43
+ let script = session.script;
44
+ for function in session.functions.values() {
45
+ let intrinsic = if let Some(helper) = register_helpers::recognize(script, function) {
46
+ Intrinsic::Register(helper)
47
+ } else if let Some(mixer) = Mix32::recognize(script, function) {
48
+ Intrinsic::Mix32(mixer)
49
+ } else if extract::parameter_count(&function.params) == 5
50
+ // `~IV[0]` is written as the negation of `IV[0] + 1`.
51
+ && (mentions(function, f64::from(IV[0]))
52
+ || mentions(function, f64::from(IV[0]) + 1.0))
53
+ && compresses_like_native(session, function)
54
+ {
55
+ Intrinsic::Blake3Compress
56
+ } else {
57
+ continue;
58
+ };
59
+ intrinsics.insert(address(function), intrinsic);
60
+ }
61
+ intrinsics
62
+ }
63
+
64
+ impl Intrinsic {
65
+ /// Runs a register helper or mixer natively. Returns `None` for BLAKE3 compression, which
66
+ /// [`blake3_compress`] runs, and for arguments outside what the native version reproduces
67
+ /// exactly, leaving the call to the interpreter.
68
+ pub(super) fn call<'ast>(
69
+ self,
70
+ run: &mut Run<'ast, '_>,
71
+ arguments: &[Value<'ast>],
72
+ ) -> Option<Value<'ast>> {
73
+ let register = match self {
74
+ Self::Mix32(mixer) => {
75
+ let Some(Value::Number(number)) = arguments.first() else {
76
+ return None;
77
+ };
78
+ return Some(Value::Number(mixer.call(*number)));
79
+ }
80
+ Self::Register(Helper::Number) => {
81
+ return arguments
82
+ .first()
83
+ .filter(|value| matches!(value, Value::Number(_)))
84
+ .cloned();
85
+ }
86
+ Self::Register(Helper::Mask) => {
87
+ return matches!(arguments.first(), Some(Value::Registers))
88
+ .then_some(Value::Undefined);
89
+ }
90
+ Self::Register(Helper::Pc) => run.session.layout.pc,
91
+ Self::Register(Helper::Key) => run.session.layout.key,
92
+ Self::Blake3Compress => return None,
93
+ };
94
+ let [Value::Registers, value @ Value::Number(number), ..] = arguments else {
95
+ return None;
96
+ };
97
+ // Both setter branches store exactly this value for signed integers other than -0.
98
+ if *number != f64::from(js::int32(*number)) || (*number == 0.0 && number.is_sign_negative())
99
+ {
100
+ return None;
101
+ }
102
+ run.set_register(register, value.clone());
103
+ Some(value.clone())
104
+ }
105
+ }
106
+
107
+ /// Runs [`Intrinsic::Blake3Compress`]. Returns `None` if the arguments are outside what it
108
+ /// reproduces exactly, leaving the call to the interpreter.
109
+ pub(super) fn blake3_compress<'ast>(arguments: &[Value<'ast>]) -> Option<Value<'ast>> {
110
+ let [
111
+ Value::Array(cv),
112
+ Value::Array(block),
113
+ counter,
114
+ length,
115
+ flags,
116
+ ] = arguments
117
+ else {
118
+ return None;
119
+ };
120
+ let output = {
121
+ let (cv, block) = (cv.borrow(), block.borrow());
122
+ compress(
123
+ &words(cv.get(..8)?)?,
124
+ &words(block.get(..16)?)?,
125
+ Counter::of(counter.as_number()?),
126
+ js::int32(length.as_number()?) as u32,
127
+ js::int32(flags.as_number()?) as u32,
128
+ )
129
+ };
130
+ let mut cv = cv.borrow_mut();
131
+ for (slot, word) in cv.iter_mut().zip(output) {
132
+ // The script stores the results of `^`, which are signed.
133
+ *slot = Value::Number(f64::from(word as i32));
134
+ }
135
+ Some(Value::Undefined)
136
+ }
137
+
138
+ impl Value<'_> {
139
+ fn as_number(&self) -> Option<f64> {
140
+ match self {
141
+ Self::Number(number) => Some(*number),
142
+ _ => None,
143
+ }
144
+ }
145
+ }
146
+
147
+ /// Converts state or message words. The script first adds three words before truncating, which
148
+ /// matches wrapping addition only while the sum is exact, so larger or fractional words are
149
+ /// rejected.
150
+ pub(super) fn words<const N: usize>(values: &[Value<'_>]) -> Option<[u32; N]> {
151
+ let mut words = [0; N];
152
+ for (word, value) in words.iter_mut().zip(values) {
153
+ let number = value.as_number()?;
154
+ if number.fract() != 0.0 || number.abs() >= 2f64.powi(51) {
155
+ return None;
156
+ }
157
+ *word = js::int32(number) as u32;
158
+ }
159
+ Some(words)
160
+ }
161
+
162
+ /// A block counter split as the script splits it: `counter | 0` and
163
+ /// `counter / 4294967296 | 0`.
164
+ #[derive(Clone, Copy)]
165
+ pub(super) struct Counter {
166
+ low: u32,
167
+ high: u32,
168
+ }
169
+
170
+ impl Counter {
171
+ pub(super) fn of(counter: f64) -> Self {
172
+ Self {
173
+ low: js::int32(counter) as u32,
174
+ high: js::int32(counter / 4_294_967_296.0) as u32,
175
+ }
176
+ }
177
+ }
178
+
179
+ const IV: [u32; 8] = [
180
+ 0x6a09_e667,
181
+ 0xbb67_ae85,
182
+ 0x3c6e_f372,
183
+ 0xa54f_f53a,
184
+ 0x510e_527f,
185
+ 0x9b05_688c,
186
+ 0x1f83_d9ab,
187
+ 0x5be0_cd19,
188
+ ];
189
+
190
+ /// Message word order of each round after the first, relative to the previous round.
191
+ const PERMUTATION: [usize; 16] = [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8];
192
+
193
+ /// The BLAKE3 compression function, truncated to the chaining value.
194
+ pub(super) fn compress(
195
+ cv: &[u32; 8],
196
+ block: &[u32; 16],
197
+ counter: Counter,
198
+ length: u32,
199
+ flags: u32,
200
+ ) -> [u32; 8] {
201
+ let mut state = [0; 16];
202
+ state[..8].copy_from_slice(cv);
203
+ state[8..12].copy_from_slice(&IV[..4]);
204
+ state[12..].copy_from_slice(&[counter.low, counter.high, length, flags]);
205
+ let mut message = *block;
206
+ for round in 0..7 {
207
+ if round > 0 {
208
+ message = PERMUTATION.map(|index| message[index]);
209
+ }
210
+ mix(&mut state, [0, 4, 8, 12], message[0], message[1]);
211
+ mix(&mut state, [1, 5, 9, 13], message[2], message[3]);
212
+ mix(&mut state, [2, 6, 10, 14], message[4], message[5]);
213
+ mix(&mut state, [3, 7, 11, 15], message[6], message[7]);
214
+ mix(&mut state, [0, 5, 10, 15], message[8], message[9]);
215
+ mix(&mut state, [1, 6, 11, 12], message[10], message[11]);
216
+ mix(&mut state, [2, 7, 8, 13], message[12], message[13]);
217
+ mix(&mut state, [3, 4, 9, 14], message[14], message[15]);
218
+ }
219
+ std::array::from_fn(|index| state[index] ^ state[index + 8])
220
+ }
221
+
222
+ /// The BLAKE3 quarter-round `G` on state words `a`, `b`, `c` and `d`.
223
+ fn mix(state: &mut [u32; 16], [a, b, c, d]: [usize; 4], x: u32, y: u32) {
224
+ state[a] = state[a].wrapping_add(state[b]).wrapping_add(x);
225
+ state[d] = (state[d] ^ state[a]).rotate_right(16);
226
+ state[c] = state[c].wrapping_add(state[d]);
227
+ state[b] = (state[b] ^ state[c]).rotate_right(12);
228
+ state[a] = state[a].wrapping_add(state[b]).wrapping_add(y);
229
+ state[d] = (state[d] ^ state[a]).rotate_right(8);
230
+ state[c] = state[c].wrapping_add(state[d]);
231
+ state[b] = (state[b] ^ state[c]).rotate_right(7);
232
+ }
233
+
234
+ /// Whether `function` contains the numeric literal `number`.
235
+ fn mentions(function: &Function<'_>, number: f64) -> bool {
236
+ struct Finder {
237
+ number: f64,
238
+ found: bool,
239
+ }
240
+
241
+ impl<'a> Visit<'a> for Finder {
242
+ fn visit_numeric_literal(&mut self, literal: &NumericLiteral<'a>) {
243
+ self.found |= literal.value == self.number;
244
+ }
245
+
246
+ /// A numeric key names a property; only computed keys hold values.
247
+ fn visit_object_property(&mut self, property: &ObjectProperty<'a>) {
248
+ if property.computed {
249
+ walk::walk_object_property(self, property);
250
+ } else {
251
+ self.visit_expression(&property.value);
252
+ }
253
+ }
254
+ }
255
+
256
+ let mut finder = Finder {
257
+ number,
258
+ found: false,
259
+ };
260
+ finder.visit_function(function, ScopeFlags::Function);
261
+ finder.found
262
+ }
263
+
264
+ /// Whether interpreting `function` gives the result of [`blake3_compress`] on every
265
+ /// test input, returning nothing and recording no effects.
266
+ fn compresses_like_native<'ast>(session: &Session<'ast>, function: &'ast Function<'ast>) -> bool {
267
+ TEST_INPUTS.iter().all(|input| {
268
+ let native = input.arguments();
269
+ if blake3_compress(&native).is_none() {
270
+ return false;
271
+ }
272
+ // Clones share the arrays, so `interpreted` shows what the script wrote.
273
+ let interpreted = input.arguments();
274
+ let mut run = Run::new(session, &[], Vec::new(), Some(Copies::default()));
275
+ let callable = Callable::Script {
276
+ name: None,
277
+ function,
278
+ scope: None,
279
+ };
280
+ let outcome = run.invoke(&callable, Value::Undefined, interpreted.clone());
281
+ let same = matches!(outcome, Ok(Value::Undefined))
282
+ && run.effects.is_empty()
283
+ && numbers(&interpreted[0]) == numbers(&native[0]);
284
+ for scope in run.scopes() {
285
+ scope.borrow_mut().variables.clear();
286
+ }
287
+ same
288
+ })
289
+ }
290
+
291
+ /// Arguments for [`Intrinsic::Blake3Compress`], covering signed and unsigned words and a counter
292
+ /// above 32 bits.
293
+ struct TestInput {
294
+ cv: [f64; 8],
295
+ block: [f64; 16],
296
+ counter: f64,
297
+ length: f64,
298
+ flags: f64,
299
+ }
300
+
301
+ const TEST_INPUTS: [TestInput; 2] = [
302
+ TestInput {
303
+ cv: [
304
+ 3_144_134_277.0,
305
+ -1_521_486_534.0,
306
+ 7.0,
307
+ 4_294_967_295.0,
308
+ 1_359_893_119.0,
309
+ 0.0,
310
+ -1.0,
311
+ 2_147_483_648.0,
312
+ ],
313
+ block: [
314
+ 1.0,
315
+ 2.0,
316
+ 3.0,
317
+ 255.0,
318
+ 65_536.0,
319
+ -2.0,
320
+ 1_779_033_703.0,
321
+ 3_000_000_000.0,
322
+ 12.0,
323
+ -2_147_483_648.0,
324
+ 99.0,
325
+ 100_000.0,
326
+ 31.0,
327
+ 4_000_000_000.0,
328
+ 5.0,
329
+ 6.0,
330
+ ],
331
+ counter: 4_294_967_301.0,
332
+ length: 64.0,
333
+ flags: 11.0,
334
+ },
335
+ TestInput {
336
+ cv: [
337
+ 1_779_033_703.0,
338
+ 3_144_134_277.0,
339
+ 1_013_904_242.0,
340
+ 2_773_480_762.0,
341
+ 1_359_893_119.0,
342
+ 2_600_822_924.0,
343
+ 528_734_635.0,
344
+ 1_541_459_225.0,
345
+ ],
346
+ block: [
347
+ 827_605_328.0,
348
+ 17.0,
349
+ 0.0,
350
+ 0.0,
351
+ -5.0,
352
+ 0.0,
353
+ 0.0,
354
+ 1_234.0,
355
+ 0.0,
356
+ 0.0,
357
+ 0.0,
358
+ 0.0,
359
+ 0.0,
360
+ 0.0,
361
+ 0.0,
362
+ 0.0,
363
+ ],
364
+ counter: 3.0,
365
+ length: 13.0,
366
+ flags: 1.0,
367
+ },
368
+ ];
369
+
370
+ impl TestInput {
371
+ fn arguments<'ast>(&self) -> Vec<Value<'ast>> {
372
+ let array =
373
+ |numbers: &[f64]| Value::array(numbers.iter().copied().map(Value::Number).collect());
374
+ vec![
375
+ array(&self.cv),
376
+ array(&self.block),
377
+ Value::Number(self.counter),
378
+ Value::Number(self.length),
379
+ Value::Number(self.flags),
380
+ ]
381
+ }
382
+ }
383
+
384
+ fn numbers(value: &Value<'_>) -> Option<Vec<f64>> {
385
+ let Value::Array(elements) = value else {
386
+ return None;
387
+ };
388
+ elements.borrow().iter().map(Value::as_number).collect()
389
+ }
390
+
391
+ #[cfg(test)]
392
+ mod tests {
393
+ use super::*;
394
+
395
+ /// BLAKE3 of the empty input is one compression of an empty block with the chunk-start,
396
+ /// chunk-end and root flags.
397
+ #[test]
398
+ fn compresses_like_blake3() {
399
+ let digest = compress(&IV, &[0; 16], Counter::of(0.0), 0, 1 | 2 | 8);
400
+ let bytes: Vec<u8> = digest.iter().flat_map(|word| word.to_le_bytes()).collect();
401
+ let hex: String = bytes.iter().map(|byte| format!("{byte:02x}")).collect();
402
+ assert_eq!(
403
+ hex,
404
+ "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262"
405
+ );
406
+ }
407
+
408
+ #[test]
409
+ fn rejects_inexact_words() {
410
+ let mut arguments = TEST_INPUTS[0].arguments();
411
+ arguments[1] = Value::array(vec![Value::Number(0.5); 16]);
412
+ assert!(blake3_compress(&arguments).is_none());
413
+ }
414
+ }
@@ -0,0 +1,189 @@
1
+ //! The straight-line integer mixer used for instruction positions and string offsets. Match
2
+ //! every operation and recover its constants; leave all other functions to the interpreter.
3
+
4
+ use oxc::ast::ast::{
5
+ AssignmentExpression, AssignmentOperator, AssignmentTarget, BinaryExpression, Expression,
6
+ Function, Statement,
7
+ };
8
+ use oxc::semantic::SymbolId;
9
+ use oxc::syntax::operator::BinaryOperator;
10
+
11
+ use crate::js;
12
+ use crate::js::ast::{self, Script};
13
+ use crate::vm::extract;
14
+
15
+ #[derive(Clone, Copy)]
16
+ pub(crate) struct Mix32 {
17
+ seed: i32,
18
+ rounds: [Round; 2],
19
+ final_shift: u32,
20
+ }
21
+
22
+ /// `x = (x ^ x >>> shift) * multiplier | 0`.
23
+ #[derive(Clone, Copy)]
24
+ struct Round {
25
+ shift: u32,
26
+ multiplier: f64,
27
+ }
28
+
29
+ impl Mix32 {
30
+ pub(super) fn recognize(script: Script<'_>, function: &Function<'_>) -> Option<Self> {
31
+ if function.r#async || function.generator {
32
+ return None;
33
+ }
34
+ let [parameter] = extract::parameters(&function.params)?[..] else {
35
+ return None;
36
+ };
37
+ let parameter = parameter.symbol_id();
38
+ let body = function.body.as_deref()?;
39
+ if !body.directives.is_empty() {
40
+ return None;
41
+ }
42
+ // Statements after the `return` never run, unless they declare something.
43
+ let statements = &body.statements;
44
+ let end = statements
45
+ .iter()
46
+ .position(|statement| matches!(statement, Statement::ReturnStatement(_)))?
47
+ + 1;
48
+ if statements[end..].iter().any(Statement::is_declaration) {
49
+ return None;
50
+ }
51
+ let [seed, first, second, returned] = &statements[..end] else {
52
+ return None;
53
+ };
54
+ let Statement::ReturnStatement(returned) = returned else {
55
+ return None;
56
+ };
57
+ let seed = assignment(seed)?;
58
+ if !is_target(script, &seed.left, parameter)
59
+ || seed.operator != AssignmentOperator::BitwiseXOR
60
+ {
61
+ return None;
62
+ }
63
+ Some(Self {
64
+ seed: js::int32(number(&seed.right)?),
65
+ rounds: [
66
+ round(script, parameter, first)?,
67
+ round(script, parameter, second)?,
68
+ ],
69
+ final_shift: mixed(script, parameter, returned.argument.as_ref()?)?,
70
+ })
71
+ }
72
+
73
+ pub(super) fn call(self, number: f64) -> f64 {
74
+ let mut value = js::int32(number) ^ self.seed;
75
+ for Round { shift, multiplier } in self.rounds {
76
+ let mixed = value ^ ((value as u32) >> shift) as i32;
77
+ value = js::int32(f64::from(mixed) * multiplier);
78
+ }
79
+ f64::from(value ^ ((value as u32) >> self.final_shift) as i32)
80
+ }
81
+ }
82
+
83
+ fn number(expression: &Expression<'_>) -> Option<f64> {
84
+ ast::fold_number(expression, &|_| None)
85
+ }
86
+
87
+ /// Whether `expression`, inside any parentheses, is a reference to `symbol`.
88
+ pub(super) fn is_symbol(script: Script<'_>, expression: &Expression<'_>, symbol: SymbolId) -> bool {
89
+ script.refers_to(expression.without_parentheses(), symbol)
90
+ }
91
+
92
+ /// Whether an assignment target is the identifier of `symbol`.
93
+ fn is_target(script: Script<'_>, target: &AssignmentTarget<'_>, symbol: SymbolId) -> bool {
94
+ matches!(target, AssignmentTarget::AssignmentTargetIdentifier(name)
95
+ if script.symbol(name) == Some(symbol))
96
+ }
97
+
98
+ /// The assignment an expression statement makes.
99
+ pub(super) fn assignment<'s, 'a>(
100
+ statement: &'s Statement<'a>,
101
+ ) -> Option<&'s AssignmentExpression<'a>> {
102
+ match statement {
103
+ Statement::ExpressionStatement(statement) => match &statement.expression {
104
+ Expression::AssignmentExpression(assignment) => Some(assignment),
105
+ _ => None,
106
+ },
107
+ _ => None,
108
+ }
109
+ }
110
+
111
+ /// The binary expression inside any parentheses.
112
+ pub(super) fn binary<'s, 'a>(expression: &'s Expression<'a>) -> Option<&'s BinaryExpression<'a>> {
113
+ match expression.without_parentheses() {
114
+ Expression::BinaryExpression(binary) => Some(binary),
115
+ _ => None,
116
+ }
117
+ }
118
+
119
+ /// The shift of `x ^ x >>> shift`, where `x` is the `parameter`.
120
+ fn mixed(script: Script<'_>, parameter: SymbolId, expression: &Expression<'_>) -> Option<u32> {
121
+ let is_parameter = |expression: &Expression<'_>| is_symbol(script, expression, parameter);
122
+ let xor = binary(expression)?;
123
+ if xor.operator != BinaryOperator::BitwiseXOR {
124
+ return None;
125
+ }
126
+ let shifted = if is_parameter(&xor.left) {
127
+ &xor.right
128
+ } else if is_parameter(&xor.right) {
129
+ &xor.left
130
+ } else {
131
+ return None;
132
+ };
133
+ let shifted = binary(shifted)?;
134
+ if shifted.operator != BinaryOperator::ShiftRightZeroFill || !is_parameter(&shifted.left) {
135
+ return None;
136
+ }
137
+ Some(js::int32(number(&shifted.right)?) as u32 & 31)
138
+ }
139
+
140
+ fn round(script: Script<'_>, parameter: SymbolId, statement: &Statement<'_>) -> Option<Round> {
141
+ let assignment = assignment(statement)?;
142
+ if assignment.operator != AssignmentOperator::Assign
143
+ || !is_target(script, &assignment.left, parameter)
144
+ {
145
+ return None;
146
+ }
147
+ let truncated = binary(&assignment.right)?;
148
+ if truncated.operator != BinaryOperator::BitwiseOR {
149
+ return None;
150
+ }
151
+ let product = if number(&truncated.left) == Some(0.0) {
152
+ &truncated.right
153
+ } else if number(&truncated.right) == Some(0.0) {
154
+ &truncated.left
155
+ } else {
156
+ return None;
157
+ };
158
+ let product = binary(product)?;
159
+ if product.operator != BinaryOperator::Multiplication {
160
+ return None;
161
+ }
162
+ let (shift, multiplier) = match number(&product.left) {
163
+ Some(multiplier) => (mixed(script, parameter, &product.right)?, multiplier),
164
+ None => (
165
+ mixed(script, parameter, &product.left)?,
166
+ number(&product.right)?,
167
+ ),
168
+ };
169
+ Some(Round { shift, multiplier })
170
+ }
171
+
172
+ #[cfg(test)]
173
+ mod tests {
174
+ use super::*;
175
+ use crate::vm::interpret::register_helpers::tests::assert_native_matches_interpreted;
176
+
177
+ #[test]
178
+ fn native_mixers_match_their_scripts() {
179
+ for source in [
180
+ "function f(x) { x ^= 1265281276; x = (x ^ x >>> 16) * 40503 | 0; x = 13849 * (x ^ x >>> 13) | 0; return x >>> 16 ^ x; }",
181
+ "function f(renamed) { renamed ^= -123; renamed = 0 | 7 * (renamed >>> 3 ^ renamed); renamed = ((renamed ^ renamed >>> 0) * 11) | 0; return renamed ^ renamed >>> 31; }",
182
+ "function f(x) { x ^= 1265281276; x = (x >>> 16 ^ x) * 40503 | 0; x = 0 | 13849 * (x ^ x >>> 13); return x ^ x >>> 16; return; }",
183
+ ] {
184
+ assert_native_matches_interpreted(source, |script, function| {
185
+ Mix32::recognize(script, function).is_some()
186
+ });
187
+ }
188
+ }
189
+ }