cfsolve 0.1.2 → 0.1.4

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 (395) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +8 -3
  4. data/THIRD_PARTY_LICENSES/README.md +71 -254
  5. data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
  6. data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
  7. data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
  8. data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
  9. data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
  10. data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
  11. data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
  12. data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
  13. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
  14. data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
  15. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
  16. data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
  17. data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
  18. data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
  19. data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
  20. data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
  21. data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
  22. data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
  23. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
  24. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
  25. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
  26. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
  27. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
  28. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
  29. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
  30. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
  31. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
  32. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
  33. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
  34. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
  35. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
  36. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
  37. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
  38. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
  39. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
  40. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
  41. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
  42. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
  43. data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
  44. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
  45. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
  46. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
  47. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
  48. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
  49. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
  50. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
  51. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
  52. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
  53. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
  54. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
  55. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
  56. data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
  57. data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
  58. data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
  59. data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
  60. data/UPSTREAM.md +14 -6
  61. data/ext/cfsolve/Cargo.lock +534 -1727
  62. data/ext/cfsolve/Cargo.toml +4 -0
  63. data/ext/cfsolve/src/main.rs +1 -1
  64. data/lib/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
  65. data/lib/cfsolve/profiles/chrome-157-macos.json +613 -0
  66. data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  67. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  68. data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
  69. data/lib/cfsolve/version.rb +2 -2
  70. data/lib/cfsolve.rb +1 -1
  71. data/vendor/cfsolve/Cargo.lock +561 -1729
  72. data/vendor/cfsolve/Cargo.toml +26 -8
  73. data/vendor/cfsolve/README.md +57 -5
  74. data/vendor/cfsolve/examples/check_answers.rs +2 -2
  75. data/vendor/cfsolve/examples/compare_session.rs +1 -2
  76. data/vendor/cfsolve/examples/solver_profile.rs +84 -0
  77. data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
  78. data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
  79. data/vendor/cfsolve/examples/tls_echo.rs +3 -3
  80. data/vendor/cfsolve/examples/turnstile_smoke.rs +58 -0
  81. data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
  82. data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
  83. data/vendor/cfsolve/profiles/chrome-157-macos.json +613 -0
  84. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  85. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  86. data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
  87. data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
  88. data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
  89. data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
  90. data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
  91. data/vendor/cfsolve/src/capture/proxy.rs +44 -13
  92. data/vendor/cfsolve/src/capture/sessions.rs +4 -3
  93. data/vendor/cfsolve/src/capture/upstream.rs +1 -1
  94. data/vendor/cfsolve/src/challenge/codec.rs +4 -2
  95. data/vendor/cfsolve/src/challenge/expression.rs +161 -117
  96. data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
  97. data/vendor/cfsolve/src/challenge/installed.rs +13 -6
  98. data/vendor/cfsolve/src/challenge/merge.rs +120 -80
  99. data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
  100. data/vendor/cfsolve/src/challenge/payload.rs +69 -31
  101. data/vendor/cfsolve/src/challenge/program.rs +197 -178
  102. data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
  103. data/vendor/cfsolve/src/challenge/source.rs +151 -96
  104. data/vendor/cfsolve/src/challenge/state.rs +180 -148
  105. data/vendor/cfsolve/src/challenge/tally.rs +64 -50
  106. data/vendor/cfsolve/src/challenge.rs +1 -0
  107. data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
  108. data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
  109. data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
  110. data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
  111. data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
  112. data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
  113. data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
  114. data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
  115. data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
  116. data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
  117. data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
  118. data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
  119. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
  120. data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
  121. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
  122. data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
  123. data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
  124. data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
  125. data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
  126. data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
  127. data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
  128. data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
  129. data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
  130. data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
  131. data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
  132. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
  133. data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
  134. data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
  135. data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
  136. data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
  137. data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
  138. data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
  139. data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
  140. data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
  141. data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
  142. data/vendor/cfsolve/src/deobfuscate.rs +15 -11
  143. data/vendor/cfsolve/src/embedding_page/extra_params.rs +132 -24
  144. data/vendor/cfsolve/src/embedding_page/page.rs +41 -1
  145. data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
  146. data/vendor/cfsolve/src/error.rs +40 -5
  147. data/vendor/cfsolve/src/fingerprint.rs +8 -2
  148. data/vendor/cfsolve/src/http/client.rs +7 -10
  149. data/vendor/cfsolve/src/http/requests.rs +2 -2
  150. data/vendor/cfsolve/src/js/ast.rs +479 -263
  151. data/vendor/cfsolve/src/lib.rs +1 -0
  152. data/vendor/cfsolve/src/listing/fold.rs +19 -9
  153. data/vendor/cfsolve/src/listing/query.rs +1 -47
  154. data/vendor/cfsolve/src/performance_clock.rs +20 -1
  155. data/vendor/cfsolve/src/profiling.rs +49 -0
  156. data/vendor/cfsolve/src/script.rs +35 -24
  157. data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
  158. data/vendor/cfsolve/src/session/channel.rs +2 -2
  159. data/vendor/cfsolve/src/session/initial.rs +12 -11
  160. data/vendor/cfsolve/src/session/probes.rs +1 -0
  161. data/vendor/cfsolve/src/session/sink.rs +26 -1
  162. data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
  163. data/vendor/cfsolve/src/session.rs +1 -1
  164. data/vendor/cfsolve/src/solver.rs +3 -1
  165. data/vendor/cfsolve/src/stage2/analysis/analyze.rs +33 -4
  166. data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
  167. data/vendor/cfsolve/src/stage2/analysis/discovery.rs +13 -2
  168. data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
  169. data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
  170. data/vendor/cfsolve/src/stage2/benchmark.rs +113 -41
  171. data/vendor/cfsolve/src/stage2/call_stack.rs +1564 -1041
  172. data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
  173. data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +1 -0
  174. data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
  175. data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
  176. data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
  177. data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
  178. data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
  179. data/vendor/cfsolve/src/stage2/probes/dates.rs +44 -0
  180. data/vendor/cfsolve/src/stage2/probes/parent_info_array.rs +326 -0
  181. data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
  182. data/vendor/cfsolve/src/stage2/probes/stack.rs +117 -4
  183. data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +80 -2
  184. data/vendor/cfsolve/src/stage2/probes.rs +1 -0
  185. data/vendor/cfsolve/src/stage2/queries.rs +50 -0
  186. data/vendor/cfsolve/src/stage2/reference.rs +5 -0
  187. data/vendor/cfsolve/src/stage2/registry.rs +8 -2
  188. data/vendor/cfsolve/src/stage2/replay.rs +34 -3
  189. data/vendor/cfsolve/src/stage2/stylesheets.rs +35 -0
  190. data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
  191. data/vendor/cfsolve/src/stage2/trace.rs +134 -108
  192. data/vendor/cfsolve/src/stage2/value_labels.rs +185 -0
  193. data/vendor/cfsolve/src/stage2/vocabulary.rs +112 -17
  194. data/vendor/cfsolve/src/stage2.rs +3 -0
  195. data/vendor/cfsolve/src/vm/disassemble.rs +75 -7
  196. data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
  197. data/vendor/cfsolve/src/vm/encoded_names.rs +635 -0
  198. data/vendor/cfsolve/src/vm/extract.rs +550 -250
  199. data/vendor/cfsolve/src/vm/fixtures/free_functions/README.md +9 -0
  200. data/vendor/cfsolve/src/vm/fixtures/free_functions/machine.js +7438 -0
  201. data/vendor/cfsolve/src/vm/fixtures/free_functions/program.base64 +1 -0
  202. data/vendor/cfsolve/src/vm/interpret/access.rs +71 -50
  203. data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
  204. data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
  205. data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
  206. data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
  207. data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
  208. data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
  209. data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
  210. data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
  211. data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
  212. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +160 -58
  213. data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
  214. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
  215. data/vendor/cfsolve/src/vm/interpret/pattern.rs +1765 -0
  216. data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
  217. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +392 -0
  218. data/vendor/cfsolve/src/vm/interpret/run.rs +120 -45
  219. data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
  220. data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
  221. data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
  222. data/vendor/cfsolve/src/vm/interpret.rs +9 -1
  223. data/vendor/cfsolve/src/vm/machine.rs +116 -51
  224. data/vendor/cfsolve/src/vm/output.rs +19 -6
  225. data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
  226. data/vendor/cfsolve/src/vm/registers.rs +35 -21
  227. data/vendor/cfsolve/src/vm/session.rs +189 -121
  228. data/vendor/cfsolve/src/vm/value.rs +22 -19
  229. data/vendor/cfsolve/src/vm.rs +3 -1
  230. data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
  231. data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
  232. metadata +106 -178
  233. data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
  234. data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
  235. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
  236. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
  237. data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
  238. data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
  239. data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
  240. data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
  241. data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
  242. data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
  243. data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
  244. data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
  245. data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
  246. data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
  247. data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
  248. data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
  249. data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
  250. data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
  251. data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
  252. data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
  253. data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
  254. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
  255. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
  256. data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
  257. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
  258. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
  259. data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
  260. data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
  261. data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
  262. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
  263. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
  264. data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
  265. data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
  266. data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
  267. data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
  268. data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
  269. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
  270. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
  271. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
  272. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
  273. data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
  274. data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
  275. data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
  276. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
  277. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
  278. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
  279. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
  280. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
  281. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
  282. data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
  283. data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
  284. data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
  285. data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
  286. data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
  287. data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
  288. data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
  289. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
  290. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
  291. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
  292. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
  293. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
  294. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
  295. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
  296. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
  297. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
  298. data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
  299. data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
  300. data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
  301. data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
  302. data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
  303. data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
  304. data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
  305. data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
  306. data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
  307. data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
  308. data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
  309. data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
  310. data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
  311. data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
  312. data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
  313. data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
  314. data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
  315. data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
  316. data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
  317. data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
  318. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
  319. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
  320. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
  321. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
  322. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
  323. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
  324. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
  325. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
  326. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
  327. data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
  328. data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
  329. data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
  330. data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
  331. data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
  332. data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
  333. data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
  334. data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
  335. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
  336. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
  337. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
  338. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
  339. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
  340. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
  341. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
  342. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
  343. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
  344. data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
  345. data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
  346. data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
  347. data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
  348. data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
  349. data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
  350. data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
  351. data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
  352. data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
  353. data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
  354. data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
  355. data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
  356. data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
  357. data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
  358. data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
  359. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
  360. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
  361. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
  362. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
  363. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
  364. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
  365. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
  366. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
  367. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
  368. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
  369. data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
  370. data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
  371. data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
  372. /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
  373. /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
  374. /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
  375. /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
  376. /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
  377. /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
  378. /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
  379. /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
  380. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
  381. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
  382. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
  383. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
  384. /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
  385. /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
  386. /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
  387. /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
  388. /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
  389. /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
  390. /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
  391. /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
  392. /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
  393. /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
  394. /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
  395. /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
@@ -5,75 +5,65 @@
5
5
  //! ```
6
6
  //!
7
7
  //! Applies only to operators whose `ToInt32` or `ToUint32` conversion discards the fractional
8
- //! part before evaluation.
8
+ //! part before evaluation. Integer operands are also wrapped to their signed 32-bit
9
+ //! representation; shifts retain the same low bits and shift count after the corresponding
10
+ //! JavaScript conversions.
9
11
 
10
- use swc_core::ecma::ast::{AssignExpr, BinExpr, BinaryOp, Expr, Lit, Program, UnaryExpr, UnaryOp};
11
- use swc_core::ecma::visit::{VisitMut, VisitMutWith};
12
+ use oxc::ast::ast::{AssignmentExpression, BinaryExpression, Expression, Program, UnaryExpression};
13
+ use oxc::ast_visit::{VisitMut, walk_mut};
14
+ use oxc::span::GetSpan;
12
15
 
13
16
  use super::analysis::Analysis;
17
+ use super::ast;
18
+ use crate::js;
14
19
 
15
- pub(super) fn run(program: &mut Program, _: &mut Analysis) -> bool {
16
- let mut truncate = TruncateOperands { changed: false };
17
- program.visit_mut_with(&mut truncate);
20
+ pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
21
+ let mut truncate = Truncate {
22
+ analysis,
23
+ changed: false,
24
+ };
25
+ truncate.visit_program(program);
18
26
  truncate.changed
19
27
  }
20
28
 
21
- struct TruncateOperands {
29
+ struct Truncate<'b, 'a> {
30
+ analysis: &'b Analysis<'a>,
22
31
  changed: bool,
23
32
  }
24
33
 
25
- impl VisitMut for TruncateOperands {
26
- fn visit_mut_bin_expr(&mut self, binary: &mut BinExpr) {
27
- binary.visit_mut_children_with(self);
28
-
29
- if is_bitwise(binary.op) {
30
- self.changed |= truncate_operand(&mut binary.left);
31
- self.changed |= truncate_operand(&mut binary.right);
34
+ impl<'a> Truncate<'_, 'a> {
35
+ fn truncate(&mut self, operand: &mut Expression<'a>) {
36
+ if let Some(number) = ast::number(operand) {
37
+ let truncated = js::int32(number) as f64;
38
+ if number != truncated {
39
+ *operand = ast::number_literal(operand.span(), truncated, &self.analysis.ast);
40
+ self.changed = true;
41
+ }
32
42
  }
33
43
  }
44
+ }
34
45
 
35
- fn visit_mut_assign_expr(&mut self, assignment: &mut AssignExpr) {
36
- assignment.visit_mut_children_with(self);
37
-
38
- if assignment.op.to_update().is_some_and(is_bitwise) {
39
- self.changed |= truncate_operand(&mut assignment.right);
46
+ impl<'a> VisitMut<'a> for Truncate<'_, 'a> {
47
+ fn visit_binary_expression(&mut self, binary: &mut BinaryExpression<'a>) {
48
+ walk_mut::walk_binary_expression(self, binary);
49
+ if binary.operator.is_bitwise() {
50
+ self.truncate(&mut binary.left);
51
+ self.truncate(&mut binary.right);
40
52
  }
41
53
  }
42
54
 
43
- fn visit_mut_unary_expr(&mut self, unary: &mut UnaryExpr) {
44
- unary.visit_mut_children_with(self);
45
-
46
- if unary.op == UnaryOp::Tilde {
47
- self.changed |= truncate_operand(&mut unary.arg);
55
+ fn visit_assignment_expression(&mut self, assignment: &mut AssignmentExpression<'a>) {
56
+ walk_mut::walk_assignment_expression(self, assignment);
57
+ if assignment.operator.is_bitwise() {
58
+ self.truncate(&mut assignment.right);
48
59
  }
49
60
  }
50
- }
51
-
52
- pub(super) fn is_bitwise(operator: BinaryOp) -> bool {
53
- matches!(
54
- operator,
55
- BinaryOp::BitAnd
56
- | BinaryOp::BitOr
57
- | BinaryOp::BitXor
58
- | BinaryOp::LShift
59
- | BinaryOp::RShift
60
- | BinaryOp::ZeroFillRShift
61
- )
62
- }
63
61
 
64
- /// Returns whether a fractional part was removed.
65
- fn truncate_operand(operand: &mut Expr) -> bool {
66
- match operand {
67
- Expr::Lit(Lit::Num(number)) if number.value.is_finite() && number.value.fract() != 0.0 => {
68
- number.value = number.value.trunc();
69
- number.raw = None;
70
- true
71
- }
72
- Expr::Paren(paren) => truncate_operand(&mut paren.expr),
73
- Expr::Unary(unary) if matches!(unary.op, UnaryOp::Plus | UnaryOp::Minus) => {
74
- truncate_operand(&mut unary.arg)
62
+ fn visit_unary_expression(&mut self, unary: &mut UnaryExpression<'a>) {
63
+ walk_mut::walk_unary_expression(self, unary);
64
+ if unary.operator.is_bitwise() {
65
+ self.truncate(&mut unary.argument)
75
66
  }
76
- _ => false,
77
67
  }
78
68
  }
79
69
 
@@ -83,23 +73,23 @@ mod tests {
83
73
 
84
74
  #[test]
85
75
  fn truncates_only_bitwise_operands() {
86
- let transform = |source: &str| testing::rewrite(source, super::run, /* fix= */ true);
76
+ let transform = |source: &str| testing::rewrite(source, super::run);
87
77
  let output = transform(
88
78
  "function f(x) { return (x & 255.51) ^ (x | 8.27) ^ (x ^ 60.71) ^ (x << 16.7) ^ (x >> 12.15) ^ (x >>> 10.46); }",
89
79
  );
90
80
  let expected = [
91
81
  "x & 255", "x | 8", "x ^ 60", "x << 16", "x >> 12", "x >>> 10",
92
82
  ];
93
- testing::assert_contains(&output, &expected, &[]);
83
+ testing::assert_contains(&output, &expected);
94
84
  assert!(!output.contains('.'), "{output}");
95
85
  assert_eq!(transform(&output), output);
96
86
  // Compound assignments, negated operands, and complements.
97
87
  let output =
98
88
  transform("function f(x) { x &= 63.01; x >>>= 3.94; y = x & -3.7; z = ~9.5; }");
99
- testing::assert_contains(&output, &["x &= 63", "x >>>= 3", "x & -3", "~9"], &[]);
89
+ testing::assert_contains(&output, &["x &= 63", "x >>>= 3", "x & -3", "~9"]);
100
90
  let output =
101
91
  transform("function f(x) { return [x & 255, x + 255.51, x * 1.5, 0.5, x(23.5)]; }");
102
- let kept = ["x & 255", "x + 255.51", "x * 1.5", "0.5", "x(23.5)"];
103
- testing::assert_contains(&output, &kept, &[]);
92
+ let kept = ["x & 255", "x + 255.51", "x * 1.5", ".5", "x(23.5)"];
93
+ testing::assert_contains(&output, &kept);
104
94
  }
105
95
  }
@@ -8,32 +8,49 @@
8
8
  //! blocks containing string statements created by [`super::statements`], since unwrapping them
9
9
  //! could introduce directives.
10
10
 
11
- use std::mem;
12
-
13
- use swc_core::ecma::ast::{BlockStmt, Decl, Expr, Lit, Program, Stmt, VarDeclKind};
14
- use swc_core::ecma::visit::{VisitMut, VisitMutWith};
11
+ use oxc::allocator::{TakeIn, Vec};
12
+ use oxc::ast::ast::{Expression, Program, Statement, VariableDeclarationKind};
13
+ use oxc::ast_visit::{VisitMut, walk_mut};
15
14
 
16
15
  use super::analysis::Analysis;
17
16
 
18
- pub(super) fn run(program: &mut Program, _: &mut Analysis) -> bool {
19
- let mut flatten = FlattenBlocks { changed: false };
20
- program.visit_mut_with(&mut flatten);
17
+ pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
18
+ let mut flatten = Flatten {
19
+ analysis,
20
+ changed: false,
21
+ };
22
+ flatten.visit_program(program);
21
23
  flatten.changed
22
24
  }
23
25
 
24
- struct FlattenBlocks {
26
+ struct Flatten<'b, 'a> {
27
+ analysis: &'b Analysis<'a>,
25
28
  changed: bool,
26
29
  }
27
30
 
28
- impl VisitMut for FlattenBlocks {
29
- fn visit_mut_stmts(&mut self, statements: &mut Vec<Stmt>) {
30
- statements.visit_mut_children_with(self);
31
- let mut flattened = Vec::with_capacity(statements.len());
32
- for statement in mem::take(statements) {
31
+ fn is_unscoped(statement: &Statement<'_>) -> bool {
32
+ match statement {
33
+ Statement::VariableDeclaration(declaration) => {
34
+ declaration.kind == VariableDeclarationKind::Var
35
+ }
36
+ Statement::FunctionDeclaration(_) | Statement::ClassDeclaration(_) => false,
37
+ Statement::ExpressionStatement(statement) => {
38
+ !matches!(statement.expression, Expression::StringLiteral(_))
39
+ }
40
+ _ => true,
41
+ }
42
+ }
43
+
44
+ impl<'a> VisitMut<'a> for Flatten<'_, 'a> {
45
+ fn visit_statements(&mut self, statements: &mut Vec<'a, Statement<'a>>) {
46
+ walk_mut::walk_statements(self, statements);
47
+ let builder = &self.analysis.ast;
48
+ let mut flattened = Vec::with_capacity_in(statements.len(), builder);
49
+ for statement in statements.take_in(builder) {
33
50
  match statement {
34
- Stmt::Block(block) if is_transparent(&block) => {
35
- flattened.extend(block.stmts);
36
- self.changed = true;
51
+ Statement::BlockStatement(block) if block.body.iter().all(is_unscoped) => {
52
+ flattened.extend(block.unbox().body);
53
+ self.changed = true
37
54
  }
38
55
  statement => flattened.push(statement),
39
56
  }
@@ -42,28 +59,18 @@ impl VisitMut for FlattenBlocks {
42
59
  }
43
60
  }
44
61
 
45
- fn is_transparent(block: &BlockStmt) -> bool {
46
- block.stmts.iter().all(|statement| match statement {
47
- // Moving a function-scoped `var` out of this block preserves its scope.
48
- Stmt::Decl(Decl::Var(declaration)) => declaration.kind == VarDeclKind::Var,
49
- Stmt::Decl(_) => false,
50
- Stmt::Expr(statement) => !matches!(&*statement.expr, Expr::Lit(Lit::Str(_))),
51
- _ => true,
52
- })
53
- }
54
-
55
62
  #[cfg(test)]
56
63
  mod tests {
57
64
  use crate::deobfuscate::testing;
58
65
 
59
66
  #[test]
60
67
  fn flattens_only_grouping_blocks_in_statement_lists() {
61
- let transform = |source: &str| testing::rewrite(source, super::run, /* fix= */ false);
68
+ let transform = |source: &str| testing::rewrite(source, super::run);
62
69
  let output = transform("function f() { { a(); { b(); } } var c; { var d = 1; } }");
63
- testing::assert_contains(&output, &["var d = 1;"], &["a(); b();"]);
70
+ testing::assert_contains(&output, &["var d = 1;", "a(); b();"]);
64
71
  assert_eq!(output.matches('{').count(), 1, "{output}");
65
72
  let output =
66
73
  transform("function f() { { let a = 1; use(a); } if (a) { b(); } while (c) { d(); } }");
67
- testing::assert_contains(&output, &["if (a) {", "while(c){"], &["{ let a = 1;"]);
74
+ testing::assert_contains(&output, &["if (a) {", "while(c){", "{ let a = 1;"]);
68
75
  }
69
76
  }
@@ -8,165 +8,119 @@
8
8
  //! ```
9
9
  //!
10
10
  //! The helper must be assigned once and forward parameters in order, except for swapping the
11
- //! method and receiver. The method must be read from the receiver's local binding. This keeps
11
+ //! method and receiver. The method must be read from the same receiver binding. This keeps
12
12
  //! the same `this` value as a regular method call. Calls must supply exactly one argument per
13
13
  //! parameter, without spreads, so the method receives the same arguments.
14
14
 
15
- use swc_core::common::util::take::Take;
16
- use swc_core::ecma::ast::{
17
- CallExpr, Callee, Expr, ExprOrSpread, FnDecl, Function, Id, MemberExpr, Pat, Program, Stmt,
18
- VarDeclarator,
19
- };
20
- use swc_core::ecma::visit::{Visit, VisitMut, VisitMutWith, VisitWith};
15
+ use oxc::allocator::{CloneIn, GetAllocator, Vec};
16
+ use oxc::ast::ast::{Argument, Expression, Function, Program};
17
+ use oxc::ast_visit::{VisitMut, walk_mut};
18
+ use oxc::span::GetSpan;
21
19
 
22
- use super::HashMap;
23
- use super::analysis::{Analysis, Bindings, Globals, names};
24
- use crate::js::ast;
20
+ use super::analysis::{Analysis, Id};
21
+ use super::{HashMap, ast};
25
22
 
26
- pub(super) fn run(program: &mut Program, analysis: &mut Analysis) -> bool {
27
- let globals = analysis.globals;
28
- let bindings = analysis.bindings(program);
29
- let mut helpers = Helpers::default();
30
- program.visit_with(&mut helpers);
31
- helpers.0.retain(|id, _| bindings.is_written_once(id));
32
- if helpers.0.is_empty() {
33
- return false;
34
- }
23
+ pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
24
+ let helpers = ast::functions(program, analysis, &|function| is_helper(function, analysis));
35
25
  let mut restore = Restore {
36
- helpers: &helpers.0,
37
- bindings,
38
- globals,
26
+ analysis,
27
+ helpers: &helpers,
39
28
  changed: false,
40
29
  };
41
- program.visit_mut_with(&mut restore);
30
+ restore.visit_program(program);
42
31
  restore.changed
43
32
  }
44
33
 
45
- /// Checks for a helper of the form `function(self, method, ...rest) { return (function()
46
- /// {}).call.call(method, self, ...rest); }` with plain parameters.
47
- fn is_helper(function: &Function) -> bool {
48
- let is_call = |member: &MemberExpr| ast::member_str(&member.prop) == Some("call");
49
- if let Some(parameters) = names::parameter_ids(&function.params)
34
+ /// Matches `function (receiver, method, ...rest) { return f.call.call(method, receiver, ...rest); }`
35
+ /// where `f` is a function literal.
36
+ fn is_helper(function: &Function<'_>, analysis: &Analysis<'_>) -> bool {
37
+ if let Some(parameters) = ast::parameters(function)
50
38
  && parameters.len() >= 2
51
- && !function.is_async
52
- && !function.is_generator
53
- && let Some([Stmt::Return(returned)]) = function.body.as_ref().map(|body| &body.stmts[..])
54
- && let Some(call) = returned.arg.as_deref().and_then(Expr::as_call)
55
- && let Some(callee) = call.callee.as_expr().and_then(|callee| callee.as_member())
56
- && let Some(inner) = callee.obj.as_member()
57
- && is_call(callee)
58
- && is_call(inner)
59
- && matches!(inner.obj.unwrap_parens(), Expr::Fn(_) | Expr::Arrow(_))
39
+ && !function.r#async
40
+ && !function.generator
41
+ && let Some(Expression::CallExpression(call)) =
42
+ ast::returned(function).map(Expression::get_inner_expression)
43
+ && let Some(outer) = call.callee.as_member_expression()
44
+ && let Some(inner) = outer.object().as_member_expression()
45
+ && outer
46
+ .static_property_name()
47
+ .is_some_and(|name| name == "call")
48
+ && inner
49
+ .static_property_name()
50
+ .is_some_and(|name| name == "call")
51
+ && matches!(
52
+ inner.object().get_inner_expression(),
53
+ Expression::FunctionExpression(_) | Expression::ArrowFunctionExpression(_)
54
+ )
60
55
  {
61
- let passed = call.args.iter().map(|argument| {
62
- let id = argument
63
- .expr
64
- .as_ident()
65
- .filter(|_| argument.spread.is_none())?
66
- .to_id();
67
- parameters.iter().position(|parameter| *parameter == id)
56
+ let forwarded = call.arguments.iter().map(|argument| {
57
+ let id = analysis.expression_id(argument.as_expression()?)?;
58
+ parameters.iter().position(|&parameter| parameter == id)
68
59
  });
69
- let swapped = [1, 0].into_iter().chain(2..parameters.len()).map(Some);
70
- passed.eq(swapped)
71
- } else {
72
- false
73
- }
74
- }
75
-
76
- /// Helpers by binding, with the number of parameters they forward.
77
- #[derive(Default)]
78
- struct Helpers(HashMap<Id, usize>);
79
-
80
- impl Visit for Helpers {
81
- fn visit_expr(&mut self, expression: &Expr) {
82
- if let Some((id, Expr::Fn(function))) = ast::assignment(expression)
83
- && is_helper(&function.function)
84
- {
85
- self.0.insert(id, function.function.params.len());
86
- }
87
- expression.visit_children_with(self);
88
- }
89
-
90
- fn visit_fn_decl(&mut self, declaration: &FnDecl) {
91
- if is_helper(&declaration.function) {
92
- self.0
93
- .insert(declaration.ident.to_id(), declaration.function.params.len());
94
- }
95
- declaration.visit_children_with(self);
96
- }
97
-
98
- fn visit_var_declarator(&mut self, declarator: &VarDeclarator) {
99
- if let Pat::Ident(name) = &declarator.name
100
- && let Some(Expr::Fn(function)) = declarator.init.as_deref()
101
- && is_helper(&function.function)
102
- {
103
- self.0.insert(name.to_id(), function.function.params.len());
104
- }
105
- declarator.visit_children_with(self);
60
+ return forwarded.eq([1, 0].into_iter().chain(2..parameters.len()).map(Some));
106
61
  }
62
+ false
107
63
  }
108
64
 
109
- struct Restore<'a> {
110
- helpers: &'a HashMap<Id, usize>,
111
- bindings: &'a Bindings,
112
- globals: Globals,
65
+ struct Restore<'b, 'a> {
66
+ analysis: &'b Analysis<'a>,
67
+ helpers: &'b HashMap<Id, &'a Function<'a>>,
113
68
  changed: bool,
114
69
  }
115
70
 
116
- impl Restore<'_> {
117
- /// Rewrites `helper(receiver, receiver.method, ...rest)` as a method call.
118
- fn method_call(&self, arguments: &mut Vec<ExprOrSpread>, parameters: usize) -> Option<Expr> {
119
- // The helper forwards every parameter, including missing ones as undefined, and ignores
120
- // extra arguments after evaluating them. Only a matching, spread-free call forwards the
121
- // same arguments directly to the method.
122
- if arguments.len() != parameters
123
- || arguments.iter().any(|argument| argument.spread.is_some())
71
+ impl<'a> Restore<'_, 'a> {
72
+ /// Rewrites `helper(receiver, receiver.method, ...rest)` as `receiver.method(...rest)`.
73
+ fn restore(&self, expression: &Expression<'a>) -> Option<Expression<'a>> {
74
+ let (callee, arguments) = ast::direct_call(expression)?;
75
+ let helper = self.helpers.get(&self.analysis.id(callee)?)?;
76
+ if arguments.len() != helper.params.items.len() || arguments.iter().any(Argument::is_spread)
124
77
  {
125
78
  return None;
126
79
  }
127
- let [receiver, method, ..] = &mut arguments[..] else {
80
+ let [receiver, method, rest @ ..] = arguments else {
128
81
  return None;
129
82
  };
130
- let Expr::Member(member) = &mut *method.expr else {
131
- return None;
132
- };
133
- let object = member.obj.as_ident()?.to_id();
134
- let (target, unread) = match &*receiver.expr {
135
- Expr::Ident(identifier) => (identifier.to_id(), false),
136
- assignment => {
137
- let (target, _) = ast::assignment(assignment)?;
138
- // The method access below is the only read of the assigned local.
139
- let unread = self.bindings.references(&target) == 1
140
- && target.1 != self.globals.unresolved
141
- && !self.bindings.is_mapped_parameter(&target);
142
- (target, unread)
83
+ let receiver = receiver.as_expression()?;
84
+ let method = method.as_expression()?;
85
+ let object = self
86
+ .analysis
87
+ .expression_id(method.as_member_expression()?.object())?;
88
+ let (target, receiver) = match self.analysis.expression_id(receiver) {
89
+ Some(id) => (id, receiver),
90
+ None => {
91
+ let (id, value) = self.analysis.assignment(receiver)?;
92
+ let bindings = &self.analysis.bindings;
93
+ let unread = bindings.references(&id) == 1 && !bindings.is_mapped_parameter(&id);
94
+ (id, if unread { value } else { receiver })
143
95
  }
144
96
  };
145
97
  if target != object {
146
98
  return None;
147
99
  }
148
- let mut receiver = receiver.expr.take();
149
- if unread {
150
- receiver = receiver.expect_assign().right;
151
- }
152
- member.obj = receiver;
153
- Some(Expr::Call(CallExpr {
154
- callee: Callee::Expr(method.expr.take()),
155
- args: arguments.split_off(2),
156
- ..Default::default()
157
- }))
100
+ let allocator = self.analysis.allocator();
101
+ let mut method = method.clone_in_with_semantic_ids(allocator);
102
+ let member = method.as_member_expression_mut()?;
103
+ *member.object_mut() = receiver.clone_in_with_semantic_ids(allocator);
104
+ let rest = rest
105
+ .iter()
106
+ .map(|argument| argument.clone_in_with_semantic_ids(allocator));
107
+ let rest = Vec::from_iter_in(rest, self.analysis);
108
+ Some(Expression::new_call_expression(
109
+ expression.span(),
110
+ method,
111
+ None,
112
+ rest,
113
+ false,
114
+ self.analysis,
115
+ ))
158
116
  }
159
117
  }
160
118
 
161
- impl VisitMut for Restore<'_> {
162
- fn visit_mut_expr(&mut self, expression: &mut Expr) {
163
- expression.visit_mut_children_with(self);
164
- if let Expr::Call(call) = expression
165
- && let Some(callee) = call.callee.as_expr().and_then(|callee| callee.as_ident())
166
- && let Some(&parameters) = self.helpers.get(&callee.to_id())
167
- && let Some(replacement) = self.method_call(&mut call.args, parameters)
168
- {
169
- *expression = replacement;
119
+ impl<'a> VisitMut<'a> for Restore<'_, 'a> {
120
+ fn visit_expression(&mut self, expression: &mut Expression<'a>) {
121
+ walk_mut::walk_expression(self, expression);
122
+ if let Some(restored) = self.restore(expression) {
123
+ *expression = restored;
170
124
  self.changed = true;
171
125
  }
172
126
  }
@@ -188,11 +142,9 @@ mod tests {
188
142
  call(x, ...methods, 1);
189
143
  call(x, x.send, 1);",
190
144
  super::run,
191
- /* fix= */ true,
192
145
  );
193
146
  testing::assert_contains(
194
147
  &output,
195
- &[],
196
148
  &[
197
149
  "call(x, x.send);",
198
150
  "call(x, x.send, 1, effect());",
@@ -218,11 +170,9 @@ mod tests {
218
170
  call(x, x.y.z, 9, 10);
219
171
  }",
220
172
  super::run,
221
- /* fix= */ true,
222
173
  );
223
174
  testing::assert_contains(
224
175
  &output,
225
- &[],
226
176
  &[
227
177
  "x.send(1, 2);",
228
178
  "g().open(3, 4);",
@@ -240,7 +190,6 @@ mod tests {
240
190
  let output = testing::rewrite(
241
191
  &format!("var call = {helper}; call(x, x.send, 1);"),
242
192
  super::run,
243
- /* fix= */ true,
244
193
  );
245
194
  assert!(output.contains("call(x, x.send"), "{output}");
246
195
  }