cfsolve 0.1.2 → 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 (368) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/THIRD_PARTY_LICENSES/README.md +71 -254
  4. data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
  5. data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
  6. data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
  7. data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
  8. data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
  9. data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
  10. data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
  11. data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
  12. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
  13. data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
  14. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
  15. data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
  16. data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
  17. data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
  18. data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
  19. data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
  20. data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
  21. data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
  22. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
  23. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
  24. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
  25. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
  26. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
  27. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
  28. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
  29. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
  30. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
  31. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
  32. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
  33. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
  34. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
  35. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
  36. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
  37. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
  38. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
  39. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
  40. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
  41. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
  42. data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
  43. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
  44. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
  45. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
  46. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
  47. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
  48. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
  49. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
  50. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
  51. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
  52. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
  53. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
  54. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
  55. data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
  56. data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
  57. data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
  58. data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
  59. data/UPSTREAM.md +7 -5
  60. data/ext/cfsolve/Cargo.lock +534 -1727
  61. data/ext/cfsolve/Cargo.toml +4 -0
  62. data/ext/cfsolve/src/main.rs +1 -1
  63. data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  64. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  65. data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
  66. data/lib/cfsolve/version.rb +2 -2
  67. data/vendor/cfsolve/Cargo.lock +561 -1729
  68. data/vendor/cfsolve/Cargo.toml +26 -8
  69. data/vendor/cfsolve/README.md +4 -0
  70. data/vendor/cfsolve/examples/check_answers.rs +2 -2
  71. data/vendor/cfsolve/examples/compare_session.rs +1 -2
  72. data/vendor/cfsolve/examples/solver_profile.rs +84 -0
  73. data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
  74. data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
  75. data/vendor/cfsolve/examples/tls_echo.rs +3 -3
  76. data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
  77. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  78. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  79. data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
  80. data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
  81. data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
  82. data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
  83. data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
  84. data/vendor/cfsolve/src/capture/proxy.rs +44 -13
  85. data/vendor/cfsolve/src/capture/sessions.rs +4 -3
  86. data/vendor/cfsolve/src/capture/upstream.rs +1 -1
  87. data/vendor/cfsolve/src/challenge/codec.rs +4 -2
  88. data/vendor/cfsolve/src/challenge/expression.rs +161 -117
  89. data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
  90. data/vendor/cfsolve/src/challenge/installed.rs +13 -6
  91. data/vendor/cfsolve/src/challenge/merge.rs +120 -80
  92. data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
  93. data/vendor/cfsolve/src/challenge/payload.rs +69 -31
  94. data/vendor/cfsolve/src/challenge/program.rs +197 -178
  95. data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
  96. data/vendor/cfsolve/src/challenge/source.rs +151 -96
  97. data/vendor/cfsolve/src/challenge/state.rs +180 -148
  98. data/vendor/cfsolve/src/challenge/tally.rs +64 -50
  99. data/vendor/cfsolve/src/challenge.rs +1 -0
  100. data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
  101. data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
  102. data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
  103. data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
  104. data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
  105. data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
  106. data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
  107. data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
  108. data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
  109. data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
  110. data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
  111. data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
  112. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
  113. data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
  114. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
  115. data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
  116. data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
  117. data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
  118. data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
  119. data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
  120. data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
  121. data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
  122. data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
  123. data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
  124. data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
  125. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
  126. data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
  127. data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
  128. data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
  129. data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
  130. data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
  131. data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
  132. data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
  133. data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
  134. data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
  135. data/vendor/cfsolve/src/deobfuscate.rs +15 -11
  136. data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -18
  137. data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
  138. data/vendor/cfsolve/src/error.rs +40 -5
  139. data/vendor/cfsolve/src/fingerprint.rs +8 -2
  140. data/vendor/cfsolve/src/http/client.rs +7 -10
  141. data/vendor/cfsolve/src/http/requests.rs +2 -2
  142. data/vendor/cfsolve/src/js/ast.rs +479 -263
  143. data/vendor/cfsolve/src/lib.rs +1 -0
  144. data/vendor/cfsolve/src/listing/fold.rs +19 -9
  145. data/vendor/cfsolve/src/listing/query.rs +1 -47
  146. data/vendor/cfsolve/src/performance_clock.rs +20 -1
  147. data/vendor/cfsolve/src/profiling.rs +49 -0
  148. data/vendor/cfsolve/src/script.rs +35 -24
  149. data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
  150. data/vendor/cfsolve/src/session/channel.rs +2 -2
  151. data/vendor/cfsolve/src/session/initial.rs +5 -5
  152. data/vendor/cfsolve/src/session/sink.rs +26 -1
  153. data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
  154. data/vendor/cfsolve/src/session.rs +1 -1
  155. data/vendor/cfsolve/src/solver.rs +3 -1
  156. data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
  157. data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
  158. data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
  159. data/vendor/cfsolve/src/stage2/benchmark.rs +62 -31
  160. data/vendor/cfsolve/src/stage2/call_stack.rs +1415 -1025
  161. data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
  162. data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
  163. data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
  164. data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
  165. data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
  166. data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
  167. data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
  168. data/vendor/cfsolve/src/stage2/queries.rs +50 -0
  169. data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
  170. data/vendor/cfsolve/src/stage2/trace.rs +134 -108
  171. data/vendor/cfsolve/src/stage2/vocabulary.rs +1 -11
  172. data/vendor/cfsolve/src/stage2.rs +2 -0
  173. data/vendor/cfsolve/src/vm/disassemble.rs +7 -3
  174. data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
  175. data/vendor/cfsolve/src/vm/extract.rs +347 -250
  176. data/vendor/cfsolve/src/vm/interpret/access.rs +63 -48
  177. data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
  178. data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
  179. data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
  180. data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
  181. data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
  182. data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
  183. data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
  184. data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
  185. data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
  186. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +123 -59
  187. data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
  188. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
  189. data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
  190. data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
  191. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
  192. data/vendor/cfsolve/src/vm/interpret/run.rs +116 -45
  193. data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
  194. data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
  195. data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
  196. data/vendor/cfsolve/src/vm/interpret.rs +9 -1
  197. data/vendor/cfsolve/src/vm/machine.rs +56 -49
  198. data/vendor/cfsolve/src/vm/output.rs +13 -5
  199. data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
  200. data/vendor/cfsolve/src/vm/session.rs +185 -120
  201. data/vendor/cfsolve/src/vm/value.rs +22 -19
  202. data/vendor/cfsolve/src/vm.rs +2 -1
  203. data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
  204. data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
  205. metadata +94 -178
  206. data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
  207. data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
  208. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
  209. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
  210. data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
  211. data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
  212. data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
  213. data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
  214. data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
  215. data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
  216. data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
  217. data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
  218. data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
  219. data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
  220. data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
  221. data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
  222. data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
  223. data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
  224. data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
  225. data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
  226. data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
  227. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
  228. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
  229. data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
  230. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
  231. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
  232. data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
  233. data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
  234. data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
  235. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
  236. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
  237. data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
  238. data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
  239. data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
  240. data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
  241. data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
  242. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
  243. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
  244. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
  245. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
  246. data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
  247. data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
  248. data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
  249. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
  250. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
  251. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
  252. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
  253. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
  254. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
  255. data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
  256. data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
  257. data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
  258. data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
  259. data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
  260. data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
  261. data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
  262. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
  263. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
  264. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
  265. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
  266. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
  267. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
  268. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
  269. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
  270. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
  271. data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
  272. data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
  273. data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
  274. data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
  275. data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
  276. data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
  277. data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
  278. data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
  279. data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
  280. data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
  281. data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
  282. data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
  283. data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
  284. data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
  285. data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
  286. data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
  287. data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
  288. data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
  289. data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
  290. data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
  291. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
  292. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
  293. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
  294. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
  295. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
  296. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
  297. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
  298. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
  299. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
  300. data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
  301. data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
  302. data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
  303. data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
  304. data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
  305. data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
  306. data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
  307. data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
  308. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
  309. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
  310. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
  311. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
  312. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
  313. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
  314. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
  315. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
  316. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
  317. data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
  318. data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
  319. data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
  320. data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
  321. data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
  322. data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
  323. data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
  324. data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
  325. data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
  326. data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
  327. data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
  328. data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
  329. data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
  330. data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
  331. data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
  332. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
  333. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
  334. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
  335. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
  336. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
  337. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
  338. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
  339. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
  340. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
  341. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
  342. data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
  343. data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
  344. data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
  345. /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
  346. /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
  347. /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
  348. /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
  349. /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
  350. /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
  351. /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
  352. /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
  353. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
  354. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
  355. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
  356. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
  357. /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
  358. /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
  359. /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
  360. /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
  361. /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
  362. /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
  363. /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
  364. /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
  365. /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
  366. /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
  367. /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
  368. /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
@@ -2,17 +2,20 @@
2
2
 
3
3
  use std::mem;
4
4
 
5
- use swc_core::atoms::Atom;
6
- use swc_core::ecma::ast::{Expr, Pat, SimpleAssignTarget, Stmt, UpdateExpr, VarDeclarator};
7
- use swc_core::ecma::visit::{Visit, VisitWith};
5
+ use oxc::ast::ast::{
6
+ AssignmentExpression, BindingPattern, Expression, SimpleAssignmentTarget, Statement,
7
+ UpdateExpression, VariableDeclarator,
8
+ };
9
+ use oxc::ast_visit::{Visit, walk};
8
10
 
9
- use super::run::{Frame, Run, Stop};
11
+ use super::run::{CallScope, Frame, Run, Stop};
12
+ use crate::js::ast::{Binding, Script};
10
13
  use crate::vm::HashMap;
11
14
  use crate::vm::session::Session;
12
15
  use crate::vm::value::{Env, Scope, Value};
13
16
 
14
17
  /// Runs the enclosing scope's `prelude`, then the VM's setup `statements`. Returns setup
15
- /// bindings and errors associated with names that interrupted statements may have written.
18
+ /// bindings and errors associated with bindings that interrupted statements may have written.
16
19
  ///
17
20
  /// Setup can read prelude values, but handlers cannot assume they remain unchanged. Prelude
18
21
  /// bindings and failures are therefore excluded from the session. Functions created during
@@ -20,12 +23,15 @@ use crate::vm::value::{Env, Scope, Value};
20
23
  #[must_use]
21
24
  pub(crate) fn setup<'a>(
22
25
  session: &Session<'a>,
23
- prelude: &'a [Stmt],
24
- statements: &'a [Stmt],
25
- ) -> (HashMap<Atom, Value<'a>>, HashMap<Atom, String>) {
26
+ prelude: &[&'a Statement<'a>],
27
+ statements: &'a [Statement<'a>],
28
+ ) -> (
29
+ HashMap<Binding<'a>, Value<'a>>,
30
+ HashMap<Binding<'a>, String>,
31
+ ) {
26
32
  let mut run = Run::new(session, &[], Vec::new(), None);
27
33
  let around = Env::scope(HashMap::default(), None);
28
- run.run_setup(around.clone(), prelude);
34
+ run.run_setup(around.clone(), prelude.iter().copied());
29
35
  run.unavailable.to_mut().clear();
30
36
  let own = Env::scope(HashMap::default(), Some(around.clone()));
31
37
  run.run_setup(own.clone(), statements);
@@ -36,20 +42,27 @@ pub(crate) fn setup<'a>(
36
42
 
37
43
  impl<'ast> Run<'ast, '_> {
38
44
  /// Runs setup `statements` in `scope`, which functions declared beside the class share until
39
- /// setup ends. Records the names interrupted statements may have written.
40
- fn run_setup(&mut self, scope: Scope<'ast>, statements: &'ast [Stmt]) {
45
+ /// setup ends. Records the bindings interrupted statements may have written.
46
+ fn run_setup(
47
+ &mut self,
48
+ scope: Scope<'ast>,
49
+ statements: impl IntoIterator<Item = &'ast Statement<'ast>>,
50
+ ) {
41
51
  self.frames.push(Frame {
42
52
  this: Value::Undefined,
43
- scope: scope.clone(),
53
+ scope: CallScope::Own(scope.clone()),
44
54
  });
45
55
  self.setup = Some(scope);
46
56
  for statement in statements {
47
- let mut written = Written::default();
48
- statement.visit_with(&mut written);
57
+ let mut written = Written {
58
+ script: self.session.script,
59
+ bindings: Vec::new(),
60
+ };
61
+ written.visit_statement(statement);
49
62
  match self.statement(statement) {
50
63
  Ok(_) => {
51
- for name in written.0 {
52
- self.unavailable.to_mut().remove(&name);
64
+ for binding in written.bindings {
65
+ self.unavailable.to_mut().remove(&binding);
53
66
  }
54
67
  }
55
68
  Err(stop) => {
@@ -57,14 +70,18 @@ impl<'ast> Run<'ast, '_> {
57
70
  Stop::Throw(value) => format!("it throws {}", value.expr()),
58
71
  Stop::Unsupported(reason) => reason,
59
72
  };
60
- for name in written.0 {
73
+ for binding in written.bindings {
61
74
  // Global-object members are not tracked, so writes to them do not
62
75
  // invalidate a tracked binding.
63
- if let Ok(Value::Namespace(_)) = self.lookup(&name) {
76
+ if let Ok(Value::Namespace(_)) = self.lookup(binding) {
64
77
  continue;
65
78
  }
66
- self.frame().scope.borrow_mut().variables.remove(&name);
67
- self.unavailable.to_mut().insert(name, reason.clone());
79
+ self.frame_mut()
80
+ .own_scope()
81
+ .borrow_mut()
82
+ .variables
83
+ .remove(&binding);
84
+ self.unavailable.to_mut().insert(binding, reason.clone());
68
85
  }
69
86
  }
70
87
  }
@@ -72,42 +89,60 @@ impl<'ast> Run<'ast, '_> {
72
89
  }
73
90
  }
74
91
 
75
- /// Names a statement may declare, assign, or mutate through property writes.
76
- #[derive(Default)]
77
- struct Written(Vec<Atom>);
92
+ /// Bindings a statement may declare, assign, or mutate through property writes.
93
+ struct Written<'a> {
94
+ script: Script<'a>,
95
+ bindings: Vec<Binding<'a>>,
96
+ }
78
97
 
79
- impl Visit for Written {
80
- fn visit_var_declarator(&mut self, declarator: &VarDeclarator) {
81
- if let Pat::Ident(name) = &declarator.name {
82
- self.0.push(name.id.sym.clone());
98
+ impl<'a> Visit<'a> for Written<'a> {
99
+ fn visit_variable_declarator(&mut self, declarator: &VariableDeclarator<'a>) {
100
+ if let BindingPattern::BindingIdentifier(name) = &declarator.id {
101
+ self.bindings.push(Binding::Symbol(name.symbol_id()));
83
102
  }
84
- declarator.visit_children_with(self);
103
+ walk::walk_variable_declarator(self, declarator);
85
104
  }
86
105
 
87
- fn visit_simple_assign_target(&mut self, target: &SimpleAssignTarget) {
88
- match target {
89
- SimpleAssignTarget::Ident(name) => self.0.push(name.id.sym.clone()),
90
- SimpleAssignTarget::Member(member) => self.root(&member.obj),
91
- _ => {}
106
+ fn visit_assignment_expression(&mut self, assignment: &AssignmentExpression<'a>) {
107
+ if let Some(target) = assignment.left.as_simple_assignment_target() {
108
+ self.target(target);
92
109
  }
93
- target.visit_children_with(self);
110
+ walk::walk_assignment_expression(self, assignment);
94
111
  }
95
112
 
96
- fn visit_update_expr(&mut self, update: &UpdateExpr) {
97
- self.root(&update.arg);
98
- update.visit_children_with(self);
113
+ fn visit_update_expression(&mut self, update: &UpdateExpression<'a>) {
114
+ self.target(&update.argument);
115
+ walk::walk_update_expression(self, update);
99
116
  }
100
117
  }
101
118
 
102
- impl Written {
103
- /// Returns the root name of a member-expression chain.
104
- fn root(&mut self, mut expr: &Expr) {
119
+ impl<'a> Written<'a> {
120
+ /// Records an assigned name, or the root of an assigned member.
121
+ fn target(&mut self, target: &SimpleAssignmentTarget<'a>) {
122
+ match target {
123
+ SimpleAssignmentTarget::AssignmentTargetIdentifier(name) => {
124
+ self.bindings.push(self.script.binding(name));
125
+ }
126
+ target => {
127
+ if let Some(member) = target.as_member_expression() {
128
+ self.root(member.object());
129
+ }
130
+ }
131
+ }
132
+ }
133
+
134
+ /// Records the binding at the root of a member-expression chain.
135
+ fn root(&mut self, mut expression: &Expression<'a>) {
105
136
  loop {
106
- match expr {
107
- Expr::Ident(name) => return self.0.push(name.sym.clone()),
108
- Expr::Member(member) => expr = &member.obj,
109
- Expr::Paren(paren) => expr = &paren.expr,
110
- _ => return,
137
+ match expression {
138
+ Expression::Identifier(name) => {
139
+ return self.bindings.push(self.script.binding(name));
140
+ }
141
+ Expression::ParenthesizedExpression(paren) => expression = &paren.expression,
142
+ other => match other.as_member_expression() {
143
+ Some(member) => expression = member.object(),
144
+ None => return,
145
+ },
111
146
  }
112
147
  }
113
148
  }
@@ -0,0 +1,482 @@
1
+ //! The program string decoder, run natively.
2
+ //!
3
+ //! Each encrypted string record names its bytes in the program and a key. The decoder derives a
4
+ //! record key with BLAKE3, checks a keyed BLAKE3 MAC of the ciphertext, and XORs the ciphertext
5
+ //! with a BLAKE3 keystream. Interpreting it dominates string decryption, which every handler run
6
+ //! that loads a string constant needs.
7
+ //!
8
+ //! The decoder, its MAC and keystream functions must match [`DECODER`], [`MAC`] and
9
+ //! [`KEYSTREAM`] (see [`super::pattern`]), the functions they call must be the recognized
10
+ //! mixer and BLAKE3 compression intrinsics, and the session values they read must be the
11
+ //! character table, `Array`, and bound `charCodeAt` and `repeat` they are in known builds.
12
+ //! Each call also resolves every binding as the interpreter would. Records outside what the native
13
+ //! version reproduces exactly, including every record the script would reject, are interpreted.
14
+
15
+ use std::collections::BTreeSet;
16
+ use std::ptr;
17
+
18
+ use oxc::ast::ast::Function;
19
+
20
+ use super::builtin::Builtin;
21
+ use super::formula::{Formula, Input};
22
+ use super::intrinsic::{self, Counter, Intrinsic};
23
+ use super::mix32::Mix32;
24
+ use super::pattern;
25
+ use super::run::Run;
26
+ use crate::js;
27
+ use crate::js::ast::Binding;
28
+ use crate::vm::convert;
29
+ use crate::vm::session::Session;
30
+ use crate::vm::value::{Callable, JsString, Value};
31
+
32
+ /// `decoder(record)`: `record` is `[program, offset, length, b3, b4, key]`.
33
+ const DECODER: &str = "
34
+ function decoder(record) {
35
+ var bytes, offset, length, key, seed, block, count, text, keystream, index, value;
36
+ bytes = record[0];
37
+ offset = record[1];
38
+ length = record[2];
39
+ key = record[5];
40
+ seed = $mix(offset);
41
+ block = [$c_block, offset, length, 0, 0, 0, 0, record[4] << 8 | record[3], 0, 0, 0, 0, 0, 0, 0, 0];
42
+ count = 0;
43
+ for (; count < 16; count++) {
44
+ block[3 + (count >>> 2)] |= read(count) << 8 * (count & 3);
45
+ }
46
+ count = read(16) << 8 | read(17);
47
+ if (count > length) throw Error();
48
+ key = [key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]];
49
+ $compress(key, block, 0, 32, 27);
50
+ block = new $array(count);
51
+ text = ``;
52
+ index = 0;
53
+ for (; index < 4; index++) {
54
+ text += $table[255 & key[0] >>> index * 8];
55
+ }
56
+ index = 0;
57
+ for (; index < count; index++) {
58
+ value = read(18 + index);
59
+ block[index] = value;
60
+ text += $table[value];
61
+ }
62
+ index = 8 + 2 * text.length;
63
+ text = $mac(text, index, 0, ((index - 1) / 1024 | 0) + 1, true, key, true);
64
+ index = 0;
65
+ value = 0;
66
+ for (; value < 16; value++) {
67
+ index |= read(18 + length + value) ^ text[value >>> 2] >>> 8 * (value & 3) & 255;
68
+ }
69
+ if (index) throw Error();
70
+ text = ``;
71
+ index = 0;
72
+ for (; index < count; index++) {
73
+ if ((31 & index) === 0) {
74
+ keystream = $keystream(key, index >>> 5);
75
+ }
76
+ text += $table[block[index] ^ keystream[index >>> 2 & 7] >>> (index & 3) * 8 & 255];
77
+ }
78
+ return text + $repeat(`\\0`, length - count);
79
+ function read(position) {
80
+ var mixed;
81
+ mixed = seed + 2654435769 * position | 0;
82
+ return $e_read;
83
+ }
84
+ }";
85
+
86
+ /// `mac(text, length, chunk, chunks, root, key, keyed)`: the keyed BLAKE3 hash of `length`
87
+ /// bytes, eight zero bytes then `text` as UTF-16BE, starting at 1024-byte chunk `chunk`.
88
+ const MAC: &str = "
89
+ function mac(text, length, chunk, chunks, root, key, keyed) {
90
+ var left, flags;
91
+ var state;
92
+ state = key ? [key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]] : [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225];
93
+ flags = key ? 16 : 0;
94
+ if (chunks > 1) {
95
+ var half;
96
+ half = 1;
97
+ for (; 2 * half < chunks; half *= 2);
98
+ left = $self(text, length, chunk, half, false, key, keyed);
99
+ text = $self(text, length, chunk + half, chunks - half, false, key, keyed);
100
+ $compress(state, [left[0], left[1], left[2], left[3], left[4], left[5], left[6], left[7], text[0], text[1], text[2], text[3], text[4], text[5], text[6], text[7]], 0, 64, (root ? 8 : 0) | (flags | 4));
101
+ return state;
102
+ }
103
+ left = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
104
+ chunks = chunk * 1024;
105
+ length = chunks + 1024 < length ? chunks + 1024 : length;
106
+ key = chunks;
107
+ for (; key < length; key += 64) {
108
+ half = 0;
109
+ for (; half < 16; half++) {
110
+ let position = key / 2 + 2 * half - 4, word = 0;
111
+ if (position < 0) {
112
+ word = keyed ? 0 : half === 0 ? $c_prefix0 : $c_prefix1;
113
+ } else {
114
+ if (position < text.length) {
115
+ word = $code(text, position) << 16 | (position + 1 < text.length ? $code(text, position + 1) : 0);
116
+ }
117
+ }
118
+ left[half] = (word & 255) << 24 | (word & 65280) << 8 | word >>> 8 & 65280 | word >>> 24;
119
+ }
120
+ half = key + 64 >= length;
121
+ $compress(state, left, chunk, half ? length - key : 64, flags | (chunks === key ? 1 : 0) | (half ? 2 : 0) | (half && root ? 8 : 0));
122
+ }
123
+ return state;
124
+ }";
125
+
126
+ /// `keystream(key, counter)`: one 32-byte keystream block.
127
+ const KEYSTREAM: &str = "
128
+ function keystream(key, counter) {
129
+ key = [key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]];
130
+ $compress(key, [$c_stream, counter, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 0, 8, 27);
131
+ return key;
132
+ }";
133
+
134
+ /// A recognized decoder: the bindings it reads, the functions they must resolve to, and its
135
+ /// constants.
136
+ pub(crate) struct StringDecoder<'ast> {
137
+ mixer: Mix32,
138
+ /// Bindings resolving to script functions: the decoder's callees and the binary helpers
139
+ /// declared beside the class that its match inlined.
140
+ functions: Vec<NamedFunction<'ast>>,
141
+ /// Inlined binary helpers that are session bindings.
142
+ bound_helpers: Vec<NamedFunction<'ast>>,
143
+ table: Binding<'ast>,
144
+ array: Binding<'ast>,
145
+ repeat: Binding<'ast>,
146
+ code: Binding<'ast>,
147
+ block: f64,
148
+ /// A program byte's value, from `bytes`, `offset`, `position`, `record` and `mixed`.
149
+ read: Formula,
150
+ stream: f64,
151
+ }
152
+
153
+ struct NamedFunction<'ast> {
154
+ binding: Binding<'ast>,
155
+ function: &'ast Function<'ast>,
156
+ }
157
+
158
+ impl<'ast> StringDecoder<'ast> {
159
+ /// Recognizes the session's record decoder.
160
+ pub(crate) fn recognize(session: &Session<'ast>) -> Option<Self> {
161
+ let decoder = session.record_decoder?;
162
+ let script = session.script;
163
+ let helpers = pattern::binary_helpers(session);
164
+ let captures = pattern::matches(&pattern::template(DECODER), script, decoder, &helpers)?;
165
+ // Functions resolve through bindings first.
166
+ let function = |binding: Binding<'ast>| {
167
+ if session.bindings.contains_key(&binding) {
168
+ return None;
169
+ }
170
+ session.function(binding)
171
+ };
172
+ let mix = captures.name("$mix")?;
173
+ let compress = captures.name("$compress")?;
174
+ let mac = captures.name("$mac")?;
175
+ let keystream = captures.name("$keystream")?;
176
+ let mix_function = function(mix)?;
177
+ let compress_function = function(compress)?;
178
+ let mac_function = function(mac)?;
179
+ let keystream_function = function(keystream)?;
180
+ let native = |function| {
181
+ session
182
+ .intrinsics
183
+ .get(&intrinsic::address(function))
184
+ .copied()
185
+ };
186
+ let Some(Intrinsic::Mix32(mixer)) = native(mix_function) else {
187
+ return None;
188
+ };
189
+ let Some(Intrinsic::Blake3Compress) = native(compress_function) else {
190
+ return None;
191
+ };
192
+ let mac_captures =
193
+ pattern::matches(&pattern::template(MAC), script, mac_function, &helpers)?;
194
+ let stream_captures = pattern::matches(
195
+ &pattern::template(KEYSTREAM),
196
+ script,
197
+ keystream_function,
198
+ &helpers,
199
+ )?;
200
+ if mac_captures.name("$self")? != mac
201
+ || mac_captures.name("$compress")? != compress
202
+ || stream_captures.name("$compress")? != compress
203
+ {
204
+ return None;
205
+ }
206
+ let table = captures.name("$table")?;
207
+ let array = captures.name("$array")?;
208
+ let repeat = captures.name("$repeat")?;
209
+ let code = mac_captures.name("$code")?;
210
+ // Values the decoder reads are session bindings, not functions or builtins.
211
+ if ![table, array, repeat, code]
212
+ .iter()
213
+ .all(|binding| session.bindings.contains_key(binding))
214
+ {
215
+ return None;
216
+ }
217
+ let named = |binding, function| NamedFunction { binding, function };
218
+ let mut functions = vec![
219
+ named(mix, mix_function),
220
+ named(compress, compress_function),
221
+ named(mac, mac_function),
222
+ named(keystream, keystream_function),
223
+ ];
224
+ let mut bound_helpers = Vec::new();
225
+ let inlined: BTreeSet<Binding<'ast>> = (captures.helpers.iter())
226
+ .chain(&mac_captures.helpers)
227
+ .chain(&stream_captures.helpers)
228
+ .copied()
229
+ .collect();
230
+ for binding in inlined {
231
+ if let Some(value) = session.bindings.get(&binding) {
232
+ let function = pattern::script_function(value);
233
+ let function = function.expect("bound binary helpers are script functions");
234
+ bound_helpers.push(named(binding, function));
235
+ } else {
236
+ let function = session.function(binding);
237
+ let function = function.expect("unbound binary helpers are declared functions");
238
+ functions.push(named(binding, function));
239
+ }
240
+ }
241
+ Some(Self {
242
+ mixer,
243
+ functions,
244
+ bound_helpers,
245
+ table,
246
+ array,
247
+ repeat,
248
+ code,
249
+ block: captures.constant("$c_block")?,
250
+ read: captures.formula("$e_read")?,
251
+ stream: stream_captures.constant("$c_stream")?,
252
+ })
253
+ }
254
+
255
+ /// Decrypts `record` as the script would, or returns `None` to interpret it.
256
+ pub(super) fn decrypt(&self, run: &Run<'ast, '_>, record: &Value<'ast>) -> Option<Value<'ast>> {
257
+ if run.setup.is_some() || !self.resolves(run) {
258
+ return None;
259
+ }
260
+ let Value::Array(record) = record else {
261
+ return None;
262
+ };
263
+ let record = record.borrow();
264
+ let [
265
+ Value::Program,
266
+ Value::Number(offset),
267
+ Value::Number(length),
268
+ Value::Number(low),
269
+ Value::Number(high),
270
+ Value::Array(key),
271
+ ..,
272
+ ] = &record[..]
273
+ else {
274
+ return None;
275
+ };
276
+ let (offset, length) = (*offset, *length);
277
+ let (low, high) = (js::int32(*low), js::int32(*high));
278
+ let key: [u32; 8] = intrinsic::words(key.borrow().get(..8)?)?;
279
+ let program = run.program;
280
+ let seed = self.mixer.call(offset);
281
+ // Byte values only: other results would index the character table outside it.
282
+ let read = |position: f64| -> Option<i32> {
283
+ let mixed = js::int32(seed + 2_654_435_769.0 * position);
284
+ let value = self.read.evaluate(&[
285
+ ("bytes", Input::Bytes(program)),
286
+ ("offset", Input::Number(offset)),
287
+ ("position", Input::Number(position)),
288
+ ("record", Input::Array(&record)),
289
+ ("mixed", Input::Number(f64::from(mixed))),
290
+ ])?;
291
+ (value.fract() == 0.0 && (0.0..=255.0).contains(&value)).then_some(value as i32)
292
+ };
293
+ // The record key, derived from the record's position, length and first bytes.
294
+ let mut header = [0i32; 4];
295
+ for count in 0..16 {
296
+ header[count >> 2] |= read(count as f64)? << (8 * (count & 3));
297
+ }
298
+ let mut block = [self.block, offset, length, 0.0, 0.0, 0.0, 0.0, 0.0];
299
+ for (slot, word) in block[3..7].iter_mut().zip(header) {
300
+ *slot = f64::from(word);
301
+ }
302
+ block[7] = f64::from(high << 8 | low);
303
+ let mut words = [0u32; 16];
304
+ words[..8].copy_from_slice(&intrinsic::words::<8>(&block.map(Value::Number))?);
305
+ let key = intrinsic::compress(&key, &words, Counter::of(0.0), 32, 27);
306
+ let count = read(16.0)? << 8 | read(17.0)?;
307
+ if f64::from(count) > length {
308
+ return None;
309
+ }
310
+ let count = usize::try_from(count).ok()?;
311
+ let mut ciphertext = Vec::with_capacity(count);
312
+ for index in 0..count {
313
+ ciphertext.push(u8::try_from(read((18 + index) as f64)?).ok()?);
314
+ }
315
+ // The MAC covers the key's first word and the ciphertext.
316
+ let mut text = Vec::with_capacity(4 + count);
317
+ text.extend((0..4).map(|index| ((key[0] >> (8 * index)) & 255) as u16));
318
+ text.extend(ciphertext.iter().map(|&byte| u16::from(byte)));
319
+ let bytes = 8 + 2 * text.len();
320
+ let mac = mac(&text, bytes, 0, (bytes - 1) / 1024 + 1, true, &key);
321
+ let mut difference = 0;
322
+ for value in 0..16 {
323
+ let expected = (mac[value >> 2] >> (8 * (value & 3))) & 255;
324
+ difference |= read(18.0 + length + value as f64)? ^ expected as i32;
325
+ }
326
+ if difference != 0 {
327
+ return None;
328
+ }
329
+ let mut plain = Vec::with_capacity(count);
330
+ let mut stream = [0u32; 8];
331
+ for (index, byte) in ciphertext.iter().enumerate() {
332
+ if index & 31 == 0 {
333
+ let mut block = [0u32; 16];
334
+ block[0] = intrinsic::words::<1>(&[Value::Number(self.stream)])?[0];
335
+ block[1] = (index >> 5) as u32;
336
+ stream = intrinsic::compress(&key, &block, Counter::of(0.0), 8, 27);
337
+ }
338
+ let mask = (stream[(index >> 2) & 7] >> ((index & 3) * 8)) & 255;
339
+ plain.push(u16::from(*byte) ^ mask as u16);
340
+ }
341
+ // `"\0".repeat(length - count)`, within the interpreter's length limit.
342
+ let padding = convert::length(length - count as f64)?;
343
+ plain.resize(count + padding, 0);
344
+ Some(Value::String(JsString::from(plain)))
345
+ }
346
+
347
+ /// Whether every binding the decoder reads resolves, in `run`, to what was recognized.
348
+ fn resolves(&self, run: &Run<'ast, '_>) -> bool {
349
+ let unshadowed = |binding: &Binding<'ast>| !run.unavailable.contains_key(binding);
350
+ let value = |binding: &Binding<'ast>| {
351
+ if !unshadowed(binding) {
352
+ return None;
353
+ }
354
+ run.globals
355
+ .get(binding)
356
+ .or_else(|| run.session.bindings.get(binding))
357
+ };
358
+ let functions = self
359
+ .functions
360
+ .iter()
361
+ .all(|NamedFunction { binding, function }| {
362
+ unshadowed(binding)
363
+ && run.globals.get(binding).is_none_or(|global| {
364
+ pattern::script_function(global)
365
+ .is_some_and(|found| ptr::eq(found, *function))
366
+ })
367
+ });
368
+ let bound_helpers = self
369
+ .bound_helpers
370
+ .iter()
371
+ .all(|NamedFunction { binding, function }| {
372
+ value(binding)
373
+ .and_then(pattern::script_function)
374
+ .is_some_and(|found| ptr::eq(found, *function))
375
+ });
376
+ functions
377
+ && bound_helpers
378
+ && value(&self.table).is_some_and(is_character_table)
379
+ && value(&self.array).is_some_and(|array| is_builtin(array, Builtin::Array))
380
+ && value(&self.repeat).is_some_and(|repeat| is_bound_call(repeat, Builtin::Repeat))
381
+ && value(&self.code).is_some_and(|code| is_bound_call(code, Builtin::CharCodeAt))
382
+ }
383
+ }
384
+
385
+ /// The MAC function on `bytes` bytes of `text`, from chunk `chunk`, for keyed calls without a
386
+ /// prefix, as the decoder makes them.
387
+ fn mac(
388
+ text: &[u16],
389
+ bytes: usize,
390
+ chunk: usize,
391
+ chunks: usize,
392
+ root: bool,
393
+ key: &[u32; 8],
394
+ ) -> [u32; 8] {
395
+ const KEYED: u32 = 16;
396
+ if chunks > 1 {
397
+ let mut half = 1;
398
+ while 2 * half < chunks {
399
+ half *= 2;
400
+ }
401
+ let mut block = [0u32; 16];
402
+ block[..8].copy_from_slice(&mac(text, bytes, chunk, half, false, key));
403
+ block[8..].copy_from_slice(&mac(text, bytes, chunk + half, chunks - half, false, key));
404
+ let flags = if root { 8 } else { 0 } | KEYED | 4;
405
+ return intrinsic::compress(key, &block, Counter::of(0.0), 64, flags);
406
+ }
407
+ let mut state = *key;
408
+ let start = chunk * 1024;
409
+ let end = (start + 1024).min(bytes);
410
+ let mut position = start;
411
+ while position < end {
412
+ let mut block = [0u32; 16];
413
+ for (half, slot) in block.iter_mut().enumerate() {
414
+ // Code unit index; the first four units are the zero prefix.
415
+ let unit = (position / 2 + 2 * half).checked_sub(4);
416
+ let word = match unit {
417
+ Some(unit) if unit < text.len() => {
418
+ let low = text.get(unit + 1).map_or(0, |&unit| u32::from(unit));
419
+ u32::from(text[unit]) << 16 | low
420
+ }
421
+ _ => 0,
422
+ };
423
+ *slot = word.swap_bytes();
424
+ }
425
+ let last = position + 64 >= end;
426
+ let length = if last { end - position } else { 64 };
427
+ let flags = KEYED
428
+ | u32::from(start == position)
429
+ | if last { 2 } else { 0 }
430
+ | if last && root { 8 } else { 0 };
431
+ let counter = Counter::of(chunk as f64);
432
+ state = intrinsic::compress(&state, &block, counter, length as u32, flags);
433
+ position += 64;
434
+ }
435
+ state
436
+ }
437
+
438
+ /// `String.fromCharCode(i)` at each index `i` below 256.
439
+ fn is_character_table(table: &Value<'_>) -> bool {
440
+ let Value::Array(elements) = table else {
441
+ return false;
442
+ };
443
+ let elements = elements.borrow();
444
+ elements.len() == 256
445
+ && elements.iter().enumerate().all(|(index, element)| {
446
+ matches!(element, Value::String(text) if text.units() == [index as u16])
447
+ })
448
+ }
449
+
450
+ fn is_builtin(value: &Value<'_>, builtin: Builtin) -> bool {
451
+ matches!(value, Value::Function(callable)
452
+ if matches!(&**callable, Callable::Builtin(found) if *found == builtin))
453
+ }
454
+
455
+ /// `Function.prototype.call.bind(method)`, as `bind.bind(call)(method)` creates it.
456
+ fn is_bound_call(value: &Value<'_>, method: Builtin) -> bool {
457
+ let Value::Function(callable) = value else {
458
+ return false;
459
+ };
460
+ matches!(&**callable, Callable::Bound { target, this, arguments }
461
+ if arguments.is_empty() && is_builtin(target, Builtin::Call) && is_builtin(this, method))
462
+ }
463
+
464
+ #[cfg(test)]
465
+ mod tests {
466
+ use std::{env, fs};
467
+
468
+ use crate::script::Source;
469
+
470
+ /// Recognizes the decoder of a saved deobfuscated script named by `CFSOLVE_DECODER_SCRIPT`.
471
+ #[test]
472
+ fn recognizes_saved_script() {
473
+ let Some(path) = env::var_os("CFSOLVE_DECODER_SCRIPT") else {
474
+ return;
475
+ };
476
+ let source = fs::read_to_string(path).expect("the saved script is readable");
477
+ let source = Source::try_new(&source).expect("the saved script parses");
478
+ let machine = source.machine().expect("the saved script builds a machine");
479
+ assert!(machine.session.string_decoder.is_some(), "string decoder");
480
+ assert!(machine.native_dispatch.is_some(), "native dispatch");
481
+ }
482
+ }