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
@@ -1,242 +1,235 @@
1
- //! Counts binding reads and writes and tracks simple assigned values, so rewrites can identify
2
- //! single assignments and follow copies to their source.
1
+ //! Counts binding writes and reads in the current tree.
3
2
 
4
3
  use std::mem;
5
4
 
6
- use swc_core::ecma::ast::{
7
- ArrowExpr, AssignExpr, AssignOp, ClassDecl, Expr, FnDecl, ForHead, Function, Id, Ident, Param,
8
- Program, Prop, UpdateExpr, VarDeclarator,
5
+ use oxc::ast::ast::{
6
+ AssignmentExpression, AssignmentTarget, BindingPattern, Class, ClassType, Expression,
7
+ ForStatementLeft, FormalParameters, Function, FunctionType, IdentifierReference,
8
+ MemberExpression, Program, SimpleAssignmentTarget, UpdateExpression, VariableDeclarator,
9
9
  };
10
- use swc_core::ecma::visit::{Visit, VisitWith};
11
- use swc_ecma_utils::DestructuringFinder;
10
+ use oxc::ast_visit::{Visit, walk};
11
+ use oxc::semantic::Scoping;
12
+ use oxc::syntax::operator::AssignmentOperator;
13
+ use oxc::syntax::scope::ScopeFlags;
12
14
 
13
- use crate::deobfuscate::{HashMap, HashSet};
15
+ use super::Id;
16
+ use crate::deobfuscate::{HashMap, HashSet, ast};
14
17
 
15
- /// Tracks writes and references by resolved [`Id`]. Names are not enough
16
- /// because the obfuscator reuses them across scopes.
18
+ /// Writes and value reads by binding identity, since spelling alone does not identify a local
19
+ /// across scopes.
17
20
  ///
18
- /// Writes include assignments, updates, initialized declarations, `for-in` and `for-of`
19
- /// targets, and function or class declarations. Parameters and catch clauses do not count:
20
- /// helpers may use parameter slots whose incoming values are never read. An assigned value can
21
- /// be used for substitution only when its binding has exactly one write.
21
+ /// Writes include assignments, updates, initialized declarations, `for-in` and `for-of` targets,
22
+ /// and function or class declarations. Parameters and catch bindings do not count as writes:
23
+ /// helpers may use parameter slots whose incoming values are never read.
22
24
  #[derive(Default)]
23
- pub(crate) struct Bindings {
24
- writes: HashMap<Id, Vec<Write>>,
25
- references: HashMap<Id, usize>,
26
- /// Bindings that receive a copy of each binding's value.
27
- copies: HashMap<Id, Vec<Id>>,
28
- /// Parameters of functions and arrows.
25
+ pub(in crate::deobfuscate) struct Bindings {
26
+ writes: HashMap<Id, usize>,
27
+ /// Counted from reference flags, including the object read in `binding.property`.
28
+ reads: HashMap<Id, usize>,
29
+ /// The source of each plain copy assignment `target = source`.
30
+ copies: HashMap<Id, Id>,
31
+ /// Function and arrow parameters, including bindings inside destructuring patterns.
29
32
  parameters: HashSet<Id>,
30
- /// Parameters of functions that use `arguments`.
33
+ /// Parameters of functions that use `arguments`. In sloppy mode, `arguments[i]` can observe
34
+ /// parameter writes, so passes must preserve those stores and parameter bindings.
31
35
  mapped: HashSet<Id>,
32
- /// Whether the function being visited refers to its `arguments`.
33
- uses_arguments: bool,
34
- }
35
-
36
- /// One write, and the assigned value when analysis can follow it.
37
- enum Write {
38
- /// `binding = other` or `var binding = other`.
39
- Copy(Id),
40
- Other,
41
36
  }
42
37
 
43
38
  impl Bindings {
44
- #[must_use]
45
- pub(crate) fn collect(program: &Program) -> Self {
46
- let mut bindings = Self::default();
47
- program.visit_with(&mut bindings);
48
- bindings
39
+ pub(super) fn collect(program: &Program<'_>, scoping: &Scoping) -> Self {
40
+ let mut collect = Collect {
41
+ scoping,
42
+ bindings: Self::default(),
43
+ arguments: false,
44
+ };
45
+ collect.visit_program(program);
46
+ collect.bindings
49
47
  }
50
48
 
51
- #[must_use]
52
- pub(crate) fn write_count(&self, id: &Id) -> usize {
53
- self.writes.get(id).map_or(0, Vec::len)
49
+ pub(in crate::deobfuscate) fn write_count(&self, id: &Id) -> usize {
50
+ self.writes.get(id).copied().unwrap_or(0)
54
51
  }
55
52
 
56
- /// Checks for exactly one write, allowing later reads to use that assigned value.
57
- #[must_use]
58
- pub(crate) fn is_written_once(&self, id: &Id) -> bool {
53
+ pub(in crate::deobfuscate) fn references(&self, id: &Id) -> usize {
54
+ self.reads.get(id).copied().unwrap_or(0)
55
+ }
56
+
57
+ pub(in crate::deobfuscate) fn is_written_once(&self, id: &Id) -> bool {
59
58
  self.write_count(id) == 1
60
59
  }
61
60
 
62
- /// Returns the number of value reads, including reads through `binding.property`.
63
- #[must_use]
64
- pub(crate) fn references(&self, id: &Id) -> usize {
65
- self.references.get(id).copied().unwrap_or(0)
61
+ /// Checks for a local binding that is never assigned and that `arguments` does not alias, so
62
+ /// every read sees the value it was declared or called with.
63
+ pub(in crate::deobfuscate) fn is_never_written(&self, id: &Id) -> bool {
64
+ !id.is_global() && self.write_count(id) == 0 && !self.is_mapped_parameter(id)
66
65
  }
67
66
 
68
- /// Returns whether the binding is a function or arrow parameter that can hold an argument.
69
- #[must_use]
70
- pub(crate) fn is_parameter(&self, id: &Id) -> bool {
67
+ pub(in crate::deobfuscate) fn is_parameter(&self, id: &Id) -> bool {
71
68
  self.parameters.contains(id)
72
69
  }
73
70
 
74
- /// Checks whether this is a parameter of a function using `arguments`. In sloppy mode,
75
- /// `arguments[i]` can observe parameter writes and changes to the parameter list.
76
- #[must_use]
77
- pub(crate) fn is_mapped_parameter(&self, id: &Id) -> bool {
71
+ pub(in crate::deobfuscate) fn is_mapped_parameter(&self, id: &Id) -> bool {
78
72
  self.mapped.contains(id)
79
73
  }
80
74
 
81
- /// Returns the source binding when `id` has exactly one write that copies it.
82
- #[must_use]
83
- pub(crate) fn copy_source(&self, id: &Id) -> Option<&Id> {
84
- match self.writes.get(id)?.as_slice() {
85
- [Write::Copy(source)] => Some(source),
86
- _ => None,
87
- }
75
+ /// Returns the source of a plain copy assignment if it is the binding's only write.
76
+ pub(in crate::deobfuscate) fn copy_source(&self, id: &Id) -> Option<&Id> {
77
+ self.copies.get(id).filter(|_| self.is_written_once(id))
88
78
  }
89
79
 
90
- /// Follows [`Self::copy_source`] to the original binding in a copy chain. This identifies
91
- /// the first binding assigned a helper object.
92
- #[must_use]
93
- pub(crate) fn root(&self, id: &Id) -> Id {
94
- let mut current = id.clone();
80
+ /// Checks whether another single-write binding copies this binding's value.
81
+ pub(in crate::deobfuscate) fn is_copied(&self, id: &Id) -> bool {
82
+ self.copies
83
+ .iter()
84
+ .any(|(alias, source)| source == id && self.is_written_once(alias))
85
+ }
86
+
87
+ /// Follows single-write copies to their original binding, stopping at cycles.
88
+ pub(in crate::deobfuscate) fn root(&self, id: &Id) -> Id {
89
+ let mut id = *id;
95
90
  let mut seen = HashSet::default();
96
- while let Some(source) = self.copy_source(&current) {
97
- if !seen.insert(current.clone()) {
91
+ while let Some(&next) = self.copy_source(&id) {
92
+ if !seen.insert(id) {
98
93
  break;
99
94
  }
100
- current = source.clone();
95
+ id = next
101
96
  }
102
- current
103
- }
104
-
105
- /// The [`Self::root`] of every binding that has a copy source.
106
- #[must_use]
107
- pub(crate) fn roots(&self) -> HashMap<Id, Id> {
108
- let copies = self
109
- .writes
110
- .keys()
111
- .filter(|id| self.copy_source(id).is_some());
112
- copies.map(|id| (id.clone(), self.root(id))).collect()
97
+ id
113
98
  }
99
+ }
114
100
 
115
- /// Checks whether another binding copies `id` (see [`Self::copy_source`]).
116
- #[must_use]
117
- pub(crate) fn is_copied(&self, id: &Id) -> bool {
118
- self.copies
119
- .get(id)
120
- .is_some_and(|copies| copies.iter().any(|copy| self.copy_source(copy) == Some(id)))
121
- }
101
+ struct Collect<'s> {
102
+ scoping: &'s Scoping,
103
+ bindings: Bindings,
104
+ /// Whether the current function mentions `arguments`.
105
+ arguments: bool,
106
+ }
122
107
 
123
- fn write<N: VisitWith<DestructuringFinder<Id>>>(&mut self, target: &N) {
124
- for id in swc_ecma_utils::find_pat_ids::<_, Id>(target) {
125
- self.writes.entry(id).or_default().push(Write::Other);
108
+ impl Collect<'_> {
109
+ fn write(&mut self, id: Id, value: Option<&Expression<'_>>) {
110
+ *self.bindings.writes.entry(id).or_default() += 1;
111
+ let source = value
112
+ .and_then(Expression::get_identifier_reference)
113
+ .and_then(|reference| Id::of(reference, self.scoping));
114
+ if let Some(source) = source {
115
+ self.bindings.copies.insert(id, source);
126
116
  }
127
117
  }
128
118
 
129
- /// A write of `value` to the plain identifier `id`.
130
- fn write_value(&mut self, id: Id, value: &Expr) {
131
- let write = if let Some(source) = value.as_ident() {
132
- self.copies
133
- .entry(source.to_id())
134
- .or_default()
135
- .push(id.clone());
136
- Write::Copy(source.to_id())
137
- } else {
138
- Write::Other
139
- };
140
- self.writes.entry(id).or_default().push(write);
119
+ fn write_pattern(&mut self, pattern: &BindingPattern<'_>) {
120
+ for id in pattern_ids(pattern) {
121
+ self.write(id, None)
122
+ }
141
123
  }
124
+ }
142
125
 
143
- fn reference(&mut self, id: Id) {
144
- *self.references.entry(id).or_default() += 1;
145
- }
126
+ fn pattern_ids(pattern: &BindingPattern<'_>) -> impl Iterator<Item = Id> {
127
+ let bindings = pattern.get_binding_identifiers().into_iter();
128
+ bindings.filter_map(|binding| binding.symbol_id.get().map(Id::Local))
146
129
  }
147
130
 
148
- impl Visit for Bindings {
149
- fn visit_assign_expr(&mut self, assignment: &AssignExpr) {
150
- match assignment.left.as_ident() {
151
- Some(target) if assignment.op == AssignOp::Assign => {
152
- self.write_value(target.to_id(), &assignment.right);
153
- }
154
- _ => self.write(&assignment.left),
155
- }
156
- assignment.visit_children_with(self);
157
- }
131
+ /// Visits only target bindings; computed member operands and default values execute separately.
132
+ struct Targets<'b, 's>(&'b mut Collect<'s>);
158
133
 
159
- fn visit_update_expr(&mut self, update: &UpdateExpr) {
160
- if let Expr::Ident(id) = &*update.arg {
161
- self.write(id);
134
+ impl<'a> Visit<'a> for Targets<'_, '_> {
135
+ fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
136
+ if let Some(id) = Id::of(reference, self.0.scoping) {
137
+ self.0.write(id, None)
162
138
  }
163
- update.visit_children_with(self);
164
139
  }
165
140
 
166
- fn visit_var_declarator(&mut self, declarator: &VarDeclarator) {
167
- if let Some(init) = &declarator.init {
168
- match declarator.name.as_ident() {
169
- Some(name) => self.write_value(name.to_id(), init),
170
- None => self.write(&declarator.name),
171
- }
172
- }
173
- declarator.visit_children_with(self);
174
- }
141
+ fn visit_member_expression(&mut self, _: &MemberExpression<'a>) {}
175
142
 
176
- /// Loop heads assign on every iteration, whether or not they declare.
177
- fn visit_for_head(&mut self, head: &ForHead) {
178
- self.write(head);
179
- head.visit_children_with(self);
180
- }
143
+ fn visit_expression(&mut self, _: &Expression<'a>) {}
144
+ }
181
145
 
182
- fn visit_fn_decl(&mut self, function: &FnDecl) {
183
- self.write(&function.ident);
184
- function.visit_children_with(self);
146
+ impl<'a> Visit<'a> for Collect<'_> {
147
+ fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
148
+ self.arguments |= ast::is_arguments(reference);
149
+ if let Some(id) = Id::of(reference, self.scoping) {
150
+ let reference_id = reference.reference_id.get().expect("resolved reference");
151
+ if self.scoping.get_reference(reference_id).is_read() {
152
+ *self.bindings.reads.entry(id).or_default() += 1
153
+ }
154
+ }
185
155
  }
186
156
 
187
- fn visit_class_decl(&mut self, class: &ClassDecl) {
188
- self.write(&class.ident);
189
- class.visit_children_with(self);
157
+ fn visit_assignment_expression(&mut self, assignment: &AssignmentExpression<'a>) {
158
+ if let AssignmentTarget::AssignmentTargetIdentifier(target) = &assignment.left {
159
+ if let Some(id) = Id::of(target, self.scoping) {
160
+ let copied = assignment.operator == AssignmentOperator::Assign;
161
+ self.write(id, copied.then_some(&assignment.right))
162
+ }
163
+ } else {
164
+ Targets(self).visit_assignment_target(&assignment.left);
165
+ }
166
+ walk::walk_assignment_expression(self, assignment)
190
167
  }
191
168
 
192
- fn visit_function(&mut self, function: &Function) {
193
- // A nested function has its own `arguments`; an arrow shares its enclosing function's.
194
- let outer = mem::take(&mut self.uses_arguments);
195
- function.visit_children_with(self);
196
- if mem::replace(&mut self.uses_arguments, outer) {
197
- self.mapped.extend(
198
- function
199
- .params
200
- .iter()
201
- .flat_map(|param| swc_ecma_utils::find_pat_ids::<_, Id>(&param.pat)),
202
- );
169
+ fn visit_update_expression(&mut self, update: &UpdateExpression<'a>) {
170
+ if let SimpleAssignmentTarget::AssignmentTargetIdentifier(target) = &update.argument
171
+ && let Some(id) = Id::of(target, self.scoping)
172
+ {
173
+ self.write(id, None)
203
174
  }
175
+ walk::walk_update_expression(self, update)
204
176
  }
205
177
 
206
- fn visit_param(&mut self, parameter: &Param) {
207
- self.parameters
208
- .extend(swc_ecma_utils::find_pat_ids::<_, Id>(&parameter.pat));
209
- parameter.visit_children_with(self);
178
+ fn visit_variable_declarator(&mut self, declarator: &VariableDeclarator<'a>) {
179
+ if let Some(value) = &declarator.init {
180
+ match ast::pattern_id(&declarator.id) {
181
+ Some(id) => self.write(id, Some(value)),
182
+ None => self.write_pattern(&declarator.id),
183
+ }
184
+ }
185
+ walk::walk_variable_declarator(self, declarator)
210
186
  }
211
187
 
212
- fn visit_arrow_expr(&mut self, arrow: &ArrowExpr) {
213
- self.parameters
214
- .extend(swc_ecma_utils::find_pat_ids::<_, Id>(&arrow.params));
215
- arrow.visit_children_with(self);
188
+ fn visit_for_statement_left(&mut self, left: &ForStatementLeft<'a>) {
189
+ if let ForStatementLeft::VariableDeclaration(declaration) = left {
190
+ for declarator in &declaration.declarations {
191
+ self.write_pattern(&declarator.id)
192
+ }
193
+ } else if let Some(target) = left.as_assignment_target() {
194
+ Targets(self).visit_assignment_target(target)
195
+ }
196
+ walk::walk_for_statement_left(self, left)
216
197
  }
217
198
 
218
- fn visit_ident(&mut self, identifier: &Ident) {
219
- self.uses_arguments |= identifier.sym == "arguments";
199
+ fn visit_function(&mut self, function: &Function<'a>, flags: ScopeFlags) {
200
+ if function.r#type == FunctionType::FunctionDeclaration
201
+ && let Some(id) = ast::function_id(function)
202
+ {
203
+ self.write(id, None)
204
+ }
205
+ let outer = mem::take(&mut self.arguments);
206
+ walk::walk_function(self, function, flags);
207
+ if mem::replace(&mut self.arguments, outer) {
208
+ for parameter in &function.params.items {
209
+ self.bindings.mapped.extend(pattern_ids(&parameter.pattern));
210
+ }
211
+ }
220
212
  }
221
213
 
222
- fn visit_expr(&mut self, expression: &Expr) {
223
- if let Expr::Ident(id) = expression {
224
- self.reference(id.to_id());
214
+ fn visit_class(&mut self, class: &Class<'a>) {
215
+ if class.r#type == ClassType::ClassDeclaration
216
+ && let Some(symbol) = class.id.as_ref().and_then(|id| id.symbol_id.get())
217
+ {
218
+ self.write(Id::Local(symbol), None)
225
219
  }
226
- expression.visit_children_with(self);
220
+ walk::walk_class(self, class)
227
221
  }
228
222
 
229
- fn visit_prop(&mut self, property: &Prop) {
230
- if let Prop::Shorthand(id) = property {
231
- self.reference(id.to_id());
223
+ fn visit_formal_parameters(&mut self, parameters: &FormalParameters<'a>) {
224
+ for pattern in parameters.iter_bindings() {
225
+ self.bindings.parameters.extend(pattern_ids(pattern));
232
226
  }
233
- property.visit_children_with(self);
227
+ walk::walk_formal_parameters(self, parameters)
234
228
  }
235
229
  }
236
230
 
237
231
  #[cfg(test)]
238
232
  mod tests {
239
- use super::Bindings;
240
233
  use crate::deobfuscate::testing;
241
234
 
242
235
  #[test]
@@ -249,20 +242,29 @@ mod tests {
249
242
  for (const [a, b] of list) {}
250
243
  return once.x + escaped.y + m.z + m[\"w\"] + mutated.x + { param };
251
244
  }",
252
- |program, id| {
253
- let writes = Bindings::collect(program);
254
- assert!(writes.is_written_once(&id("once")));
255
- assert!(!writes.is_written_once(&id("twice")));
256
- assert!(writes.is_written_once(&id("escaped")));
257
- assert!(!writes.is_written_once(&id("counted")));
258
- assert!(writes.is_written_once(&id("declared")));
259
- assert!(writes.is_written_once(&id("g")));
260
- assert!(writes.is_written_once(&id("a")));
261
- assert!(!writes.is_written_once(&id("m")));
262
- assert_eq!(writes.references(&id("m")), 3);
263
- assert_eq!(writes.references(&id("escaped")), 2);
264
- assert_eq!(writes.references(&id("param")), 1);
265
- assert_eq!(writes.references(&id("mutated")), 2);
245
+ |_, analysis, id| {
246
+ let bindings = &analysis.bindings;
247
+ assert!(bindings.is_written_once(&id("once")));
248
+ assert!(!bindings.is_written_once(&id("twice")));
249
+ assert!(bindings.is_written_once(&id("escaped")));
250
+ assert!(!bindings.is_written_once(&id("counted")));
251
+ assert!(bindings.is_written_once(&id("declared")));
252
+ assert!(bindings.is_written_once(&id("g")));
253
+ assert!(bindings.is_written_once(&id("a")));
254
+ assert!(!bindings.is_written_once(&id("m")));
255
+ assert_eq!(bindings.references(&id("m")), 3);
256
+ assert_eq!(bindings.references(&id("escaped")), 2);
257
+ assert_eq!(bindings.references(&id("param")), 1);
258
+ assert_eq!(bindings.references(&id("mutated")), 2);
259
+ },
260
+ );
261
+ // Compound assignments and destructuring loop heads are writes.
262
+ testing::check(
263
+ "function f(a,b,c){a+=b;c=1;for([c] of list){}}",
264
+ |_, analysis, id| {
265
+ assert_eq!(analysis.bindings.copy_source(&id("a")), None);
266
+ assert_eq!(analysis.bindings.write_count(&id("a")), 1);
267
+ assert_eq!(analysis.bindings.write_count(&id("c")), 2);
266
268
  },
267
269
  );
268
270
  }
@@ -276,8 +278,8 @@ mod tests {
276
278
  h = {}; p = h; var q = p;
277
279
  return late;
278
280
  }",
279
- |program, id| {
280
- let bindings = Bindings::collect(program);
281
+ |_, analysis, id| {
282
+ let bindings = &analysis.bindings;
281
283
  assert_eq!(bindings.root(&id("q")), id("h"));
282
284
  assert_eq!(bindings.root(&id("late")), id("d"));
283
285
  assert_eq!(bindings.root(&id("mixed")), id("mixed"));
@@ -286,8 +288,8 @@ mod tests {
286
288
  testing::check(
287
289
  "function f(a, [b]) { return () => arguments[0]; }
288
290
  function g(c) { return function () { return arguments; }; }",
289
- |program, id| {
290
- let bindings = Bindings::collect(program);
291
+ |_, analysis, id| {
292
+ let bindings = &analysis.bindings;
291
293
  assert!(bindings.is_mapped_parameter(&id("a")));
292
294
  assert!(bindings.is_mapped_parameter(&id("b")));
293
295
  assert!(!bindings.is_mapped_parameter(&id("c")));
@@ -1,75 +1,66 @@
1
- //! Tracks expression side effects and binding reads and writes.
1
+ //! Tracks the bindings an expression reads and writes.
2
2
 
3
- use swc_core::ecma::ast::{ArrowExpr, AssignExpr, Expr, Function, Id, Ident, UpdateExpr};
4
- use swc_core::ecma::visit::{Visit, VisitWith};
5
- use swc_ecma_utils::ExprCtx;
3
+ use oxc::ast::ast::{ArrowFunctionExpression, Expression, Function, IdentifierReference};
4
+ use oxc::ast_visit::{Visit, walk};
5
+ use oxc::syntax::scope::ScopeFlags;
6
6
 
7
- use super::Globals;
7
+ use super::{Analysis, Id};
8
8
  use crate::deobfuscate::HashSet;
9
9
 
10
- /// Checks for observable effects, including getters and coercions.
11
- ///
12
- /// SWC treats local binding reads as effect-free. A global read is effect-free only if it names
13
- /// a known browser global without a getter, such as `Math` or `undefined`. Other globals may
14
- /// throw `ReferenceError` or invoke a getter.
15
- #[must_use]
16
- pub(crate) fn may_have_effects(expression: &Expr, globals: Globals) -> bool {
17
- use swc_ecma_utils::ExprExt;
18
-
19
- expression.may_have_side_effects(ExprCtx {
20
- unresolved_ctxt: globals.unresolved,
21
- is_unresolved_ref_safe: false,
22
- in_strict: false,
23
- remaining_depth: 4,
24
- })
25
- }
26
-
27
- /// Tracks binding reads and writes outside function bodies. Creating a closure does not execute
28
- /// its body. Does not analyze the effects of calls, `new`, tagged templates, `await`, or
29
- /// `yield`.
10
+ /// Binding reads and writes outside function bodies, since creating a closure does not run its
11
+ /// body. Calls, construction, tagged templates, `await`, and `yield` are opaque: they may change
12
+ /// a binding through code that this local scan cannot analyze.
30
13
  #[derive(Default)]
31
- pub(crate) struct Effects {
14
+ pub(in crate::deobfuscate) struct Effects {
32
15
  pub reads: HashSet<Id>,
33
16
  pub writes: HashSet<Id>,
34
17
  pub opaque: bool,
35
18
  }
36
19
 
37
20
  impl Effects {
38
- #[must_use]
39
- pub(crate) fn collect(expression: &Expr) -> Self {
40
- let mut effects = Self::default();
41
- expression.visit_with(&mut effects);
42
- effects
21
+ /// Uses reference flags, so writes include destructuring targets.
22
+ pub(crate) fn expression(expression: &Expression<'_>, analysis: &Analysis<'_>) -> Self {
23
+ let mut uses = Uses {
24
+ analysis,
25
+ effects: Self::default(),
26
+ };
27
+ uses.visit_expression(expression);
28
+ uses.effects
43
29
  }
44
30
  }
45
31
 
46
- impl Visit for Effects {
47
- fn visit_ident(&mut self, identifier: &Ident) {
48
- self.reads.insert(identifier.to_id());
49
- }
50
-
51
- fn visit_assign_expr(&mut self, assignment: &AssignExpr) {
52
- self.writes
53
- .extend(swc_ecma_utils::find_pat_ids::<_, Id>(&assignment.left));
54
- assignment.visit_children_with(self);
55
- }
32
+ struct Uses<'b, 'a> {
33
+ analysis: &'b Analysis<'a>,
34
+ effects: Effects,
35
+ }
56
36
 
57
- fn visit_update_expr(&mut self, update: &UpdateExpr) {
58
- if let Some(identifier) = update.arg.as_ident() {
59
- self.writes.insert(identifier.to_id());
37
+ impl<'a> Visit<'a> for Uses<'_, 'a> {
38
+ fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
39
+ if let Some(id) = self.analysis.id(reference) {
40
+ let reference_id = reference.reference_id.get().expect("resolved reference");
41
+ let flags = self.analysis.scoping.get_reference(reference_id).flags();
42
+ if flags.is_read() {
43
+ self.effects.reads.insert(id);
44
+ }
45
+ if flags.is_write() {
46
+ self.effects.writes.insert(id);
47
+ }
60
48
  }
61
- update.arg.visit_with(self);
62
49
  }
63
50
 
64
- fn visit_expr(&mut self, expression: &Expr) {
65
- self.opaque |= matches!(
51
+ fn visit_expression(&mut self, expression: &Expression<'a>) {
52
+ self.effects.opaque |= matches!(
66
53
  expression,
67
- Expr::Call(_) | Expr::New(_) | Expr::TaggedTpl(_) | Expr::Await(_) | Expr::Yield(_)
54
+ Expression::CallExpression(_)
55
+ | Expression::NewExpression(_)
56
+ | Expression::TaggedTemplateExpression(_)
57
+ | Expression::AwaitExpression(_)
58
+ | Expression::YieldExpression(_)
68
59
  );
69
- expression.visit_children_with(self);
60
+ walk::walk_expression(self, expression)
70
61
  }
71
62
 
72
- fn visit_function(&mut self, _: &Function) {}
63
+ fn visit_function(&mut self, _: &Function<'a>, _: ScopeFlags) {}
73
64
 
74
- fn visit_arrow_expr(&mut self, _: &ArrowExpr) {}
65
+ fn visit_arrow_function_expression(&mut self, _: &ArrowFunctionExpression<'a>) {}
75
66
  }