cfsolve 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/README.md +10 -9
  4. data/THIRD_PARTY_LICENSES/README.md +71 -254
  5. data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
  6. data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
  7. data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
  8. data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
  9. data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
  10. data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
  11. data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
  12. data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
  13. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
  14. data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
  15. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
  16. data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
  17. data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
  18. data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
  19. data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
  20. data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
  21. data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
  22. data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
  23. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
  24. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
  25. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
  26. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
  27. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
  28. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
  29. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
  30. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
  31. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
  32. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
  33. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
  34. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
  35. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
  36. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
  37. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
  38. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
  39. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
  40. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
  41. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
  42. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
  43. data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
  44. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
  45. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
  46. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
  47. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
  48. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
  49. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
  50. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
  51. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
  52. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
  53. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
  54. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
  55. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
  56. data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
  57. data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
  58. data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
  59. data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
  60. data/UPSTREAM.md +10 -8
  61. data/ext/cfsolve/Cargo.lock +534 -1727
  62. data/ext/cfsolve/Cargo.toml +4 -0
  63. data/ext/cfsolve/src/main.rs +1 -1
  64. data/lib/cfsolve/profiles/safari-26-ios/answers.json +2570 -1894
  65. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
  66. data/lib/cfsolve/profiles/safari-26-ios.json +102 -156
  67. data/lib/cfsolve/version.rb +2 -2
  68. data/vendor/cfsolve/Cargo.lock +561 -1729
  69. data/vendor/cfsolve/Cargo.toml +26 -8
  70. data/vendor/cfsolve/README.md +4 -35
  71. data/vendor/cfsolve/examples/build_profile.rs +17 -15
  72. data/vendor/cfsolve/examples/capture_session.rs +37 -0
  73. data/vendor/cfsolve/examples/check_answers.rs +66 -0
  74. data/vendor/cfsolve/examples/compare_session.rs +189 -0
  75. data/vendor/cfsolve/examples/solver_profile.rs +84 -0
  76. data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
  77. data/vendor/cfsolve/examples/stage2_snapshot.rs +6 -3
  78. data/vendor/cfsolve/examples/tls_echo.rs +3 -3
  79. data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
  80. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +2570 -1894
  81. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
  82. data/vendor/cfsolve/profiles/safari-26-ios.json +102 -156
  83. data/vendor/cfsolve/scripts/capture_cssom.mjs +42 -0
  84. data/vendor/cfsolve/scripts/serve_cssom.py +111 -0
  85. data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
  86. data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
  87. data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
  88. data/vendor/cfsolve/src/capture/profile.rs +7 -18
  89. data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
  90. data/vendor/cfsolve/src/capture/proxy.rs +44 -13
  91. data/vendor/cfsolve/src/capture/recorded.rs +42 -7
  92. data/vendor/cfsolve/src/capture/sessions.rs +4 -3
  93. data/vendor/cfsolve/src/capture/upstream.rs +1 -1
  94. data/vendor/cfsolve/src/challenge/codec.rs +4 -2
  95. data/vendor/cfsolve/src/challenge/expression.rs +161 -117
  96. data/vendor/cfsolve/src/challenge/installed/audit.rs +132 -0
  97. data/vendor/cfsolve/src/challenge/installed.rs +127 -269
  98. data/vendor/cfsolve/src/challenge/merge.rs +120 -80
  99. data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
  100. data/vendor/cfsolve/src/challenge/payload.rs +175 -35
  101. data/vendor/cfsolve/src/challenge/program.rs +197 -178
  102. data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
  103. data/vendor/cfsolve/src/challenge/source.rs +151 -96
  104. data/vendor/cfsolve/src/challenge/state.rs +236 -122
  105. data/vendor/cfsolve/src/challenge/tally.rs +64 -50
  106. data/vendor/cfsolve/src/challenge.rs +1 -0
  107. data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
  108. data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
  109. data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
  110. data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
  111. data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
  112. data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
  113. data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
  114. data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
  115. data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
  116. data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
  117. data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
  118. data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
  119. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
  120. data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
  121. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
  122. data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
  123. data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
  124. data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +201 -205
  125. data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
  126. data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +346 -536
  127. data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
  128. data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
  129. data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
  130. data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
  131. data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
  132. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
  133. data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
  134. data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +361 -322
  135. data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
  136. data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
  137. data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
  138. data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
  139. data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
  140. data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
  141. data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
  142. data/vendor/cfsolve/src/deobfuscate.rs +15 -11
  143. data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -32
  144. data/vendor/cfsolve/src/embedding_page/page.rs +28 -2
  145. data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
  146. data/vendor/cfsolve/src/error.rs +40 -5
  147. data/vendor/cfsolve/src/fingerprint.rs +8 -2
  148. data/vendor/cfsolve/src/http/client.rs +9 -1
  149. data/vendor/cfsolve/src/http/requests.rs +2 -2
  150. data/vendor/cfsolve/src/js/ast.rs +479 -254
  151. data/vendor/cfsolve/src/js/objects.rs +9 -2
  152. data/vendor/cfsolve/src/lib.rs +1 -0
  153. data/vendor/cfsolve/src/listing/fold.rs +19 -92
  154. data/vendor/cfsolve/src/listing/query.rs +26 -291
  155. data/vendor/cfsolve/src/listing.rs +0 -1
  156. data/vendor/cfsolve/src/performance_clock.rs +20 -1
  157. data/vendor/cfsolve/src/profiling.rs +49 -0
  158. data/vendor/cfsolve/src/script.rs +35 -24
  159. data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
  160. data/vendor/cfsolve/src/session/channel.rs +2 -2
  161. data/vendor/cfsolve/src/session/initial.rs +19 -10
  162. data/vendor/cfsolve/src/session/probes.rs +160 -125
  163. data/vendor/cfsolve/src/session/sink.rs +26 -1
  164. data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
  165. data/vendor/cfsolve/src/session/timing.rs +58 -53
  166. data/vendor/cfsolve/src/session/widget.rs +5 -6
  167. data/vendor/cfsolve/src/session.rs +1 -1
  168. data/vendor/cfsolve/src/solver.rs +3 -1
  169. data/vendor/cfsolve/src/stage2/analysis/analyze.rs +50 -33
  170. data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
  171. data/vendor/cfsolve/src/stage2/analysis/discovery.rs +61 -66
  172. data/vendor/cfsolve/src/stage2/analysis/envelope.rs +33 -22
  173. data/vendor/cfsolve/src/stage2/analysis/recognize.rs +3 -5
  174. data/vendor/cfsolve/src/stage2/analysis.rs +0 -1
  175. data/vendor/cfsolve/src/stage2/audit_globals.rs +378 -0
  176. data/vendor/cfsolve/src/stage2/benchmark.rs +66 -38
  177. data/vendor/cfsolve/src/stage2/call_stack.rs +1463 -1017
  178. data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
  179. data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
  180. data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
  181. data/vendor/cfsolve/src/stage2/interaction/native.rs +2 -1
  182. data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -7
  183. data/vendor/cfsolve/src/stage2/payload/recover.rs +56 -25
  184. data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
  185. data/vendor/cfsolve/src/stage2/probes/ice.rs +11 -10
  186. data/vendor/cfsolve/src/stage2/probes/media.rs +47 -33
  187. data/vendor/cfsolve/src/stage2/probes/performance.rs +13 -8
  188. data/vendor/cfsolve/src/stage2/probes/rects.rs +12 -17
  189. data/vendor/cfsolve/src/stage2/probes/stack.rs +50 -103
  190. data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +17 -86
  191. data/vendor/cfsolve/src/stage2/probes.rs +0 -1
  192. data/vendor/cfsolve/src/stage2/queries.rs +50 -0
  193. data/vendor/cfsolve/src/stage2/records.rs +4 -13
  194. data/vendor/cfsolve/src/stage2/reference.json +1 -1
  195. data/vendor/cfsolve/src/stage2/reference.rs +98 -100
  196. data/vendor/cfsolve/src/stage2/registry.rs +41 -34
  197. data/vendor/cfsolve/src/stage2/replay.rs +182 -254
  198. data/vendor/cfsolve/src/stage2/stylesheets.rs +176 -0
  199. data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
  200. data/vendor/cfsolve/src/stage2/trace.rs +152 -108
  201. data/vendor/cfsolve/src/stage2/vocabulary.rs +103 -403
  202. data/vendor/cfsolve/src/stage2.rs +4 -1
  203. data/vendor/cfsolve/src/vm/disassemble.rs +46 -13
  204. data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
  205. data/vendor/cfsolve/src/vm/extract.rs +347 -250
  206. data/vendor/cfsolve/src/vm/interpret/access.rs +67 -68
  207. data/vendor/cfsolve/src/vm/interpret/builtin.rs +16 -63
  208. data/vendor/cfsolve/src/vm/interpret/call.rs +192 -51
  209. data/vendor/cfsolve/src/vm/interpret/compile.rs +643 -0
  210. data/vendor/cfsolve/src/vm/interpret/copies.rs +232 -120
  211. data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +149 -40
  212. data/vendor/cfsolve/src/vm/interpret/evaluate.rs +189 -572
  213. data/vendor/cfsolve/src/vm/interpret/explore.rs +159 -46
  214. data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
  215. data/vendor/cfsolve/src/vm/interpret/frozen.rs +169 -0
  216. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +414 -0
  217. data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
  218. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
  219. data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
  220. data/vendor/cfsolve/src/vm/interpret/plan.rs +605 -330
  221. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
  222. data/vendor/cfsolve/src/vm/interpret/run.rs +314 -54
  223. data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
  224. data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
  225. data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
  226. data/vendor/cfsolve/src/vm/interpret.rs +16 -3
  227. data/vendor/cfsolve/src/vm/machine.rs +58 -47
  228. data/vendor/cfsolve/src/vm/output.rs +13 -5
  229. data/vendor/cfsolve/src/vm/packed_names.rs +311 -0
  230. data/vendor/cfsolve/src/vm/session.rs +197 -110
  231. data/vendor/cfsolve/src/vm/value.rs +35 -19
  232. data/vendor/cfsolve/src/vm.rs +3 -1
  233. data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
  234. data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
  235. data/vendor/cfsolve/vendor/btls-sys/src/lib.rs +3 -0
  236. metadata +106 -183
  237. data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
  238. data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
  239. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
  240. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
  241. data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
  242. data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
  243. data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
  244. data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
  245. data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
  246. data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
  247. data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
  248. data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
  249. data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
  250. data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
  251. data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
  252. data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
  253. data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
  254. data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
  255. data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
  256. data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
  257. data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
  258. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
  259. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
  260. data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
  261. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
  262. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
  263. data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
  264. data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
  265. data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
  266. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
  267. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
  268. data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
  269. data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
  270. data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
  271. data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
  272. data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
  273. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
  274. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
  275. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
  276. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
  277. data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
  278. data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
  279. data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
  280. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
  281. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
  282. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
  283. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
  284. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
  285. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
  286. data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
  287. data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
  288. data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
  289. data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
  290. data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
  291. data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
  292. data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
  293. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
  294. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
  295. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
  296. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
  297. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
  298. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
  299. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
  300. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
  301. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
  302. data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
  303. data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
  304. data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
  305. data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
  306. data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
  307. data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
  308. data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
  309. data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
  310. data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
  311. data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
  312. data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
  313. data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
  314. data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
  315. data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
  316. data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
  317. data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
  318. data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
  319. data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
  320. data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
  321. data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
  322. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
  323. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
  324. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
  325. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
  326. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
  327. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
  328. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
  329. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
  330. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
  331. data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
  332. data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
  333. data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
  334. data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
  335. data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
  336. data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
  337. data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
  338. data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
  339. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
  340. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
  341. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
  342. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
  343. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
  344. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
  345. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
  346. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
  347. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
  348. data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
  349. data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
  350. data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
  351. data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
  352. data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
  353. data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
  354. data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
  355. data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
  356. data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
  357. data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
  358. data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
  359. data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
  360. data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
  361. data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
  362. data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
  363. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
  364. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
  365. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
  366. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
  367. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
  368. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
  369. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
  370. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
  371. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
  372. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
  373. data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
  374. data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
  375. data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
  376. data/vendor/cfsolve/src/listing/normalize.rs +0 -264
  377. data/vendor/cfsolve/src/stage2/analysis/outputs.rs +0 -327
  378. data/vendor/cfsolve/src/stage2/probes/stylesheets.rs +0 -249
  379. data/vendor/cfsolve/src/stage2/reference-expanded.json +0 -42
  380. data/vendor/cfsolve/src/stage2/session_names.rs +0 -470
  381. /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
  382. /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
  383. /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
  384. /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
  385. /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
  386. /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
  387. /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
  388. /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
  389. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
  390. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
  391. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
  392. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
  393. /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
  394. /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
  395. /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
  396. /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
  397. /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
  398. /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
  399. /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
  400. /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
  401. /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
  402. /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
  403. /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
  404. /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
@@ -25,105 +25,56 @@
25
25
 
26
26
  use std::iter;
27
27
 
28
- use swc_core::ecma::ast::{
29
- BinaryOp, CallExpr, Callee, Expr, ExprOrSpread, FnDecl, Function, Id, Lit, Program, Stmt,
30
- UnaryOp,
31
- };
32
- use swc_core::ecma::visit::{Visit, VisitMut, VisitMutWith, VisitWith};
33
-
34
- use super::analysis::{Analysis, Globals, effects, names};
35
- use super::{HashMap, helper_objects};
36
- use crate::js::ast;
37
-
38
- /// Dispatcher patterns enabled for a pass.
39
- #[derive(Clone, Copy, PartialEq, Eq)]
40
- enum Reach {
41
- /// Applied calls and operations selected by the first argument.
42
- Decoding,
43
- /// Also includes direct calls and selection by any numeric argument.
44
- All,
28
+ use oxc::allocator::{CloneIn, GetAllocator, Vec as ArenaVec};
29
+ use oxc::ast::ast::{Argument, Expression, Function, Program, Statement};
30
+ use oxc::ast_visit::{VisitMut, walk_mut};
31
+ use oxc::span::Span;
32
+ use oxc::syntax::operator::{BinaryOperator, UnaryOperator};
33
+ use oxc_ecmascript::side_effects::MayHaveSideEffects;
34
+
35
+ use super::analysis::{Analysis, Id};
36
+ use super::{HashMap, ast};
37
+
38
+ /// Inlines applications and operations selected by the first numeric argument, preserving
39
+ /// direct-call frames.
40
+ pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
41
+ inline(program, analysis, /* all= */ false)
45
42
  }
46
43
 
47
- pub(super) fn run(program: &mut Program, analysis: &mut Analysis) -> bool {
48
- inline(program, analysis, Reach::Decoding)
44
+ /// Also inlines direct target calls and numeric selectors in later argument positions.
45
+ pub(super) fn run_all<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
46
+ inline(program, analysis, /* all= */ true)
49
47
  }
50
48
 
51
- pub(super) fn run_all(program: &mut Program, analysis: &mut Analysis) -> bool {
52
- inline(program, analysis, Reach::All)
53
- }
54
-
55
- fn inline(program: &mut Program, analysis: &mut Analysis, reach: Reach) -> bool {
56
- let globals = analysis.globals;
57
- let bindings = analysis.bindings(program);
58
- let mut functions = Functions::default();
59
- program.visit_with(&mut functions);
60
- // The declaration or assignment that defines the function is its only write, so every call
61
- // reaches this function.
62
- functions.0.retain(|id, _| bindings.is_written_once(id));
63
- if functions.0.is_empty() {
64
- return false;
65
- }
66
- let mut inline = InlineDispatchers {
67
- functions: &functions.0,
68
- globals,
69
- reach,
49
+ fn inline<'a>(program: &mut Program<'a>, analysis: &Analysis<'a>, all: bool) -> bool {
50
+ let functions = ast::functions(program, analysis, &|function| {
51
+ let body = function.body.as_ref();
52
+ body.is_some_and(|body| may_select(&body.statements))
53
+ });
54
+ let mut inline = Inline {
55
+ analysis,
56
+ functions: &functions,
57
+ all,
70
58
  changed: false,
71
59
  };
72
- program.visit_mut_with(&mut inline);
60
+ inline.visit_program(program);
73
61
  inline.changed
74
62
  }
75
63
 
76
- /// Functions with only identifier parameters.
77
- #[derive(Default)]
78
- struct Functions(HashMap<Id, Candidate>);
79
-
80
- struct Candidate {
81
- params: Vec<Id>,
82
- body: Vec<Stmt>,
83
- }
84
-
85
- impl Candidate {
86
- fn try_new(function: &Function) -> Option<Self> {
87
- let params = names::parameter_ids(&function.params)?;
88
- let body = &function.body.as_ref()?.stmts;
89
- (!params.is_empty() && !function.is_async && !function.is_generator && may_select(body))
90
- .then(|| Self {
91
- params,
92
- body: body.clone(),
93
- })
94
- }
95
- }
96
-
97
- impl Visit for Functions {
98
- fn visit_expr(&mut self, expression: &Expr) {
99
- if let Some((id, Expr::Fn(function))) = ast::assignment(expression)
100
- && let Some(candidate) = Candidate::try_new(&function.function)
101
- {
102
- self.0.insert(id, candidate);
103
- }
104
- expression.visit_children_with(self);
105
- }
106
-
107
- fn visit_fn_decl(&mut self, declaration: &FnDecl) {
108
- if let Some(candidate) = Candidate::try_new(&declaration.function) {
109
- self.0.insert(declaration.ident.to_id(), candidate);
110
- }
111
- declaration.visit_children_with(self);
112
- }
113
- }
114
-
115
- /// Checks whether some selector could reach `return value` through [`Path::run`]. Avoids
116
- /// cloning large unrelated functions, such as VM helpers.
117
- fn may_select<'a>(statements: impl IntoIterator<Item = &'a Stmt>) -> bool {
64
+ /// Rejects unrelated function bodies before taking an arena snapshot. A supported path must
65
+ /// reach a return through blocks, conditionals, or switches without executing other statements.
66
+ fn may_select<'b, 'a: 'b>(statements: impl IntoIterator<Item = &'b Statement<'a>>) -> bool {
118
67
  for statement in statements {
119
68
  let selects = match statement {
120
- Stmt::Return(returned) => return returned.arg.is_some(),
121
- Stmt::Block(block) => may_select(&block.stmts),
122
- Stmt::Empty(_) => false,
123
- Stmt::If(conditional) => {
124
- may_select([&*conditional.cons]) || may_select(conditional.alt.as_deref())
69
+ Statement::ReturnStatement(statement) => return statement.argument.is_some(),
70
+ Statement::BlockStatement(block) => may_select(&block.body),
71
+ Statement::EmptyStatement(_) => false,
72
+ Statement::IfStatement(branch) => {
73
+ may_select([&branch.consequent]) || may_select(branch.alternate.iter())
74
+ }
75
+ Statement::SwitchStatement(switch) => {
76
+ switch.cases.iter().any(|case| may_select(&case.consequent))
125
77
  }
126
- Stmt::Switch(switch) => switch.cases.iter().any(|case| may_select(&case.cons)),
127
78
  _ => return false,
128
79
  };
129
80
  if selects {
@@ -133,51 +84,89 @@ fn may_select<'a>(statements: impl IntoIterator<Item = &'a Stmt>) -> bool {
133
84
  false
134
85
  }
135
86
 
136
- /// Follows a function body for known numeric parameter values.
137
- struct Path {
87
+ /// Follows a helper body using only the numeric parameter values known at this call.
88
+ struct Path<'b, 'a> {
138
89
  values: HashMap<Id, f64>,
90
+ analysis: &'b Analysis<'a>,
139
91
  }
140
92
 
141
- impl Path {
142
- /// Returns `Some(Some(value))` for a return with a value, `Some(None)` for normal
143
- /// completion, and `None` for a path it cannot analyze.
144
- fn run<'body>(
93
+ impl<'a> Path<'_, 'a> {
94
+ fn number(&self, expression: &Expression<'a>) -> Option<f64> {
95
+ ast::fold_number(expression, &|leaf| {
96
+ let id = self.analysis.expression_id(leaf)?;
97
+ self.values.get(&id).copied()
98
+ })
99
+ }
100
+
101
+ fn truthy(&self, expression: &Expression<'a>) -> Option<bool> {
102
+ match expression.get_inner_expression() {
103
+ Expression::BooleanLiteral(literal) => Some(literal.value),
104
+ Expression::UnaryExpression(unary) if unary.operator == UnaryOperator::LogicalNot => {
105
+ Some(!self.truthy(&unary.argument)?)
106
+ }
107
+ Expression::BinaryExpression(binary) => {
108
+ let left = self.number(&binary.left)?;
109
+ let right = self.number(&binary.right)?;
110
+ Some(match binary.operator {
111
+ BinaryOperator::Equality | BinaryOperator::StrictEquality => left == right,
112
+ BinaryOperator::Inequality | BinaryOperator::StrictInequality => left != right,
113
+ BinaryOperator::LessThan => left < right,
114
+ BinaryOperator::LessEqualThan => left <= right,
115
+ BinaryOperator::GreaterThan => left > right,
116
+ BinaryOperator::GreaterEqualThan => left >= right,
117
+ _ => return None,
118
+ })
119
+ }
120
+ _ => None,
121
+ }
122
+ }
123
+
124
+ /// Returns `Some(Some(value))` for a reached value return, `Some(None)` for normal completion,
125
+ /// and `None` for an unsupported path. Switch selection follows fallthrough until a return;
126
+ /// paths with a `break` are left to other rewrites.
127
+ fn run<'c>(
145
128
  &self,
146
- statements: impl IntoIterator<Item = &'body Stmt>,
147
- ) -> Option<Option<&'body Expr>> {
129
+ statements: impl IntoIterator<Item = &'c Statement<'a>>,
130
+ ) -> Option<Option<&'c Expression<'a>>>
131
+ where
132
+ 'a: 'c,
133
+ {
148
134
  for statement in statements {
149
135
  let returned = match statement {
150
- Stmt::Return(returned) => return Some(Some(returned.arg.as_deref()?)),
151
- Stmt::Block(block) => self.run(&block.stmts)?,
152
- Stmt::Empty(_) => None,
153
- Stmt::If(conditional) => match self.truthy(&conditional.test)? {
154
- true => self.run([&*conditional.cons])?,
155
- false => self.run(conditional.alt.as_deref())?,
156
- },
157
- Stmt::Switch(switch) => {
136
+ Statement::ReturnStatement(statement) => {
137
+ return Some(Some(statement.argument.as_ref()?));
138
+ }
139
+ Statement::BlockStatement(block) => self.run(&block.body)?,
140
+ Statement::EmptyStatement(_) => None,
141
+ Statement::IfStatement(branch) => {
142
+ if self.truthy(&branch.test)? {
143
+ self.run([&branch.consequent])?
144
+ } else {
145
+ self.run(branch.alternate.iter())?
146
+ }
147
+ }
148
+ Statement::SwitchStatement(switch) => {
158
149
  let value = self.number(&switch.discriminant)?;
159
- let mut matching = None;
150
+ let mut matched = None;
160
151
  let mut default = None;
161
152
  for (index, case) in switch.cases.iter().enumerate() {
162
- let Some(test) = &case.test else {
163
- default.get_or_insert(index);
164
- continue;
165
- };
166
- if self.number(test)? == value {
167
- matching.get_or_insert(index);
153
+ if let Some(test) = &case.test {
154
+ if self.number(test)? == value {
155
+ matched.get_or_insert(index);
156
+ }
157
+ } else {
158
+ default = Some(index)
168
159
  }
169
160
  }
170
- let Some(start) = matching.or(default) else {
161
+ let Some(start) = matched.or(default) else {
171
162
  continue;
172
163
  };
173
- // Fall through from the matching case until a return.
174
- let body: Vec<&Stmt> = switch.cases[start..]
175
- .iter()
176
- .flat_map(|case| &case.cons)
177
- .collect();
164
+ let cases = switch.cases[start..].iter();
165
+ let body: Vec<&Statement<'a>> =
166
+ cases.flat_map(|case| &case.consequent).collect();
178
167
  if body
179
168
  .iter()
180
- .any(|statement| matches!(statement, Stmt::Break(_)))
169
+ .any(|statement| matches!(statement, Statement::BreakStatement(_)))
181
170
  {
182
171
  return None;
183
172
  }
@@ -191,203 +180,157 @@ impl Path {
191
180
  }
192
181
  Some(None)
193
182
  }
194
-
195
- fn truthy(&self, expression: &Expr) -> Option<bool> {
196
- match expression {
197
- Expr::Paren(inner) => self.truthy(&inner.expr),
198
- Expr::Unary(unary) if unary.op == UnaryOp::Bang => Some(!self.truthy(&unary.arg)?),
199
- Expr::Lit(Lit::Bool(value)) => Some(value.value),
200
- Expr::Bin(binary) => {
201
- let (left, right) = (self.number(&binary.left)?, self.number(&binary.right)?);
202
- match binary.op {
203
- BinaryOp::EqEqEq | BinaryOp::EqEq => Some(left == right),
204
- BinaryOp::NotEqEq | BinaryOp::NotEq => Some(left != right),
205
- BinaryOp::Lt => Some(left < right),
206
- BinaryOp::LtEq => Some(left <= right),
207
- BinaryOp::Gt => Some(left > right),
208
- BinaryOp::GtEq => Some(left >= right),
209
- _ => None,
210
- }
211
- }
212
- _ => None,
213
- }
214
- }
215
-
216
- fn number(&self, expression: &Expr) -> Option<f64> {
217
- ast::fold_number(expression, &|leaf| {
218
- self.values.get(&leaf.as_ident()?.to_id()).copied()
219
- })
220
- }
221
- }
222
-
223
- /// Returns parameter positions for the target and arguments of a call such as `target(a, b)`. Each
224
- /// must refer to a parameter.
225
- fn parameter_call(expression: &Expr, params: &[Id]) -> Option<Vec<usize>> {
226
- let call = expression.as_call()?;
227
- let arguments = call
228
- .args
229
- .iter()
230
- .map(|arg| arg.spread.is_none().then_some(&*arg.expr));
231
- iter::once(Some(&**call.callee.as_expr()?))
232
- .chain(arguments)
233
- .map(|expression| parameter_position(expression?, params))
234
- .collect()
235
- }
236
-
237
- /// Returns the index in `params` of the parameter named by `expression`.
238
- fn parameter_position(expression: &Expr, params: &[Id]) -> Option<usize> {
239
- let id = expression.as_ident()?.to_id();
240
- params.iter().position(|param| *param == id)
241
- }
242
-
243
- /// The parameter positions of `target` and `args` in `Reflect.apply(target, undefined, args)`.
244
- struct ReflectApply {
245
- target: usize,
246
- arguments: usize,
247
183
  }
248
184
 
249
- fn reflect_apply(expression: &Expr, params: &[Id], globals: Globals) -> Option<ReflectApply> {
250
- if let Some((reflect, [function, this, arguments])) = ast::method_call(expression, "apply")
251
- && reflect
252
- .as_ident()
253
- .is_some_and(|id| globals.is(id, "Reflect"))
254
- && [function, this, arguments]
255
- .iter()
256
- .all(|arg| arg.spread.is_none())
257
- && match &*this.expr {
258
- Expr::Ident(id) => globals.is(id, "undefined"),
259
- Expr::Unary(unary) => {
260
- unary.op == UnaryOp::Void && !effects::may_have_effects(&unary.arg, globals)
261
- }
262
- _ => false,
185
+ /// Accepts unary and binary operations whose leaves pass `leaf`, excluding `delete`.
186
+ fn operation(expression: &Expression<'_>, leaf: &impl Fn(&Expression<'_>) -> bool) -> bool {
187
+ match expression.get_inner_expression() {
188
+ Expression::UnaryExpression(unary) => {
189
+ unary.operator != UnaryOperator::Delete && operation(&unary.argument, leaf)
190
+ }
191
+ Expression::BinaryExpression(binary) => {
192
+ operation(&binary.left, leaf) && operation(&binary.right, leaf)
193
+ }
194
+ Expression::LogicalExpression(logical) => {
195
+ operation(&logical.left, leaf) && operation(&logical.right, leaf)
263
196
  }
264
- {
265
- Some(ReflectApply {
266
- target: parameter_position(&function.expr, params)?,
267
- arguments: parameter_position(&arguments.expr, params)?,
268
- })
269
- } else {
270
- None
271
- }
272
- }
273
-
274
- /// Operators other than `delete` combining leaves that `leaf` accepts.
275
- fn is_operation(expression: &Expr, leaf: &impl Fn(&Expr) -> bool) -> bool {
276
- match expression {
277
- Expr::Paren(inner) => is_operation(&inner.expr, leaf),
278
- Expr::Unary(unary) => unary.op != UnaryOp::Delete && is_operation(&unary.arg, leaf),
279
- Expr::Bin(binary) => is_operation(&binary.left, leaf) && is_operation(&binary.right, leaf),
280
197
  expression => leaf(expression),
281
198
  }
282
199
  }
283
200
 
284
- struct InlineDispatchers<'functions> {
285
- functions: &'functions HashMap<Id, Candidate>,
286
- globals: Globals,
287
- reach: Reach,
201
+ struct Inline<'b, 'a> {
202
+ analysis: &'b Analysis<'a>,
203
+ functions: &'b HashMap<Id, &'a Function<'a>>,
204
+ all: bool,
288
205
  changed: bool,
289
206
  }
290
207
 
291
- impl InlineDispatchers<'_> {
292
- fn replacement(&self, callee: &Id, args: &[ExprOrSpread]) -> Option<Expr> {
293
- let candidate = self.functions.get(callee)?;
294
- if args.iter().any(|arg| arg.spread.is_some()) {
208
+ impl<'a> Inline<'_, 'a> {
209
+ /// Selects the reached return without evaluating unknown code, then checks its forwarding form.
210
+ /// Direct calls must preserve argument order and omit only numeric selectors. `Reflect.apply`
211
+ /// requires global `Reflect` and an effect-free undefined receiver. Repeated or reordered
212
+ /// operator operands must themselves be effect-free.
213
+ fn replacement(
214
+ &self,
215
+ id: Id,
216
+ arguments: &[Argument<'a>],
217
+ span: Span,
218
+ ) -> Option<Expression<'a>> {
219
+ let analysis = self.analysis;
220
+ let function = *self.functions.get(&id)?;
221
+ if function.r#async || function.generator {
295
222
  return None;
296
223
  }
297
- let number = |arg: &ExprOrSpread| match &*arg.expr {
298
- Expr::Lit(Lit::Num(number)) => Some(number.value),
299
- _ => None,
300
- };
301
- number(args.first()?)?;
302
- let selectors = match self.reach {
303
- Reach::Decoding => 1,
304
- Reach::All => args.len(),
305
- };
306
- // Returns the selected expression only if choosing it requires constant selector
307
- // comparisons with no other evaluation.
308
- let path = Path {
309
- values: candidate
310
- .params
311
- .iter()
312
- .zip(&args[..selectors])
313
- .filter_map(|(param, arg)| Some((param.clone(), number(arg)?)))
314
- .collect(),
224
+ let parameters = ast::parameters(function)?;
225
+ let arguments: Vec<&Expression<'a>> = arguments
226
+ .iter()
227
+ .map(Argument::as_expression)
228
+ .collect::<Option<_>>()?;
229
+ ast::number(arguments.first()?)?;
230
+ let count = if self.all { arguments.len() } else { 1 };
231
+ let known = parameters.iter().zip(arguments.iter().take(count));
232
+ let values = known
233
+ .filter_map(|(&id, argument)| Some((id, ast::number(argument)?)))
234
+ .collect();
235
+ let path = Path { values, analysis };
236
+ let returned = path.run(&function.body.as_ref()?.statements)??;
237
+ let position = |expression: Option<&Expression<'a>>| {
238
+ let id = analysis.expression_id(expression?)?;
239
+ parameters.iter().position(|parameter| *parameter == id)
315
240
  };
316
- let returned = path.run(&candidate.body)??;
317
- if self.reach == Reach::All
318
- && let Some(positions) = parameter_call(returned, &candidate.params)
319
- && args.len() == candidate.params.len()
320
- && positions.is_sorted_by(|before, after| before < after)
321
- && (0..args.len())
322
- .all(|index| positions.contains(&index) || number(&args[index]).is_some())
323
- && let [target, passed @ ..] = &positions[..]
324
- && args[*target].expr.is_ident()
241
+ if self.all
242
+ && let Expression::CallExpression(call) = returned
243
+ && let Some(positions) = iter::once(Some(&call.callee))
244
+ .chain(call.arguments.iter().map(Argument::as_expression))
245
+ .map(&position)
246
+ .collect::<Option<Vec<usize>>>()
247
+ && arguments.len() == parameters.len()
248
+ && positions.is_sorted_by(|left, right| left < right)
249
+ && (0..arguments.len())
250
+ .all(|index| positions.contains(&index) || ast::number(arguments[index]).is_some())
251
+ && let [target, passed @ ..] = positions.as_slice()
252
+ && matches!(arguments[*target], Expression::Identifier(_))
325
253
  {
326
- return Some(Expr::Call(CallExpr {
327
- callee: Callee::Expr(args[*target].expr.clone()),
328
- args: passed.iter().map(|&index| args[index].clone()).collect(),
329
- ..Default::default()
330
- }));
254
+ let passed = passed.iter().map(|&index| self.argument(arguments[index]));
255
+ let passed = ArenaVec::from_iter_in(passed, &analysis.ast);
256
+ return Some(self.call(span, arguments[*target], passed));
331
257
  }
332
- if let Some(apply) = reflect_apply(returned, &candidate.params, self.globals)
333
- && let Some(target) = args.get(apply.target)
334
- && target.expr.is_ident()
335
- && let Expr::Array(applied) = &*args.get(apply.arguments)?.expr
336
- && let Some(applied) = applied
337
- .elems
338
- .iter()
339
- .map(|element| element.clone().filter(|element| element.spread.is_none()))
340
- .collect::<Option<Vec<_>>>()
258
+ if let Some((reflect, [function, this, applied])) = ast::method_call(returned, "apply")
259
+ && let Expression::Identifier(reflect) = reflect
260
+ && analysis.is_global(reflect, "Reflect")
261
+ && let Some(this) = this.as_expression()
262
+ && analysis.is_undefined(this)
341
263
  {
342
- return Some(Expr::Call(CallExpr {
343
- callee: Callee::Expr(target.expr.clone()),
344
- args: applied,
345
- ..Default::default()
346
- }));
264
+ let target = position(function.as_expression())?;
265
+ let applied = position(applied.as_expression())?;
266
+ let (Expression::Identifier(_), Expression::ArrayExpression(array)) =
267
+ (arguments.get(target)?, arguments.get(applied)?)
268
+ else {
269
+ return None;
270
+ };
271
+ let elements = array.elements.iter();
272
+ let passed = elements
273
+ .map(|element| Some(self.argument(element.as_expression()?)))
274
+ .collect::<Option<Vec<_>>>()?;
275
+ let passed = ArenaVec::from_iter_in(passed, &analysis.ast);
276
+ return Some(self.call(span, arguments[target], passed));
347
277
  }
348
- // The operation may repeat or reorder arguments. Allow only literals and bindings whose
349
- // reads have no effects. Unknown globals could throw or invoke getters.
350
- let is_parameter_or_number = |leaf: &Expr| match leaf {
351
- Expr::Ident(id) => candidate.params.contains(&id.to_id()),
352
- leaf => matches!(leaf, Expr::Lit(Lit::Num(_))),
278
+ let forwards = |expression: &Expression<'_>| {
279
+ let id = analysis.expression_id(expression);
280
+ id.is_some_and(|id| parameters.contains(&id))
281
+ || matches!(expression, Expression::NumericLiteral(_))
353
282
  };
354
- let is_pure = |leaf: &Expr| match leaf {
355
- Expr::Ident(_) => !effects::may_have_effects(leaf, self.globals),
356
- leaf => matches!(leaf, Expr::Lit(Lit::Num(_) | Lit::Str(_) | Lit::Bool(_))),
283
+ let effect_free = |expression: &Expression<'_>| {
284
+ expression.is_literal()
285
+ || matches!(expression, Expression::Identifier(_))
286
+ && !expression.may_have_side_effects(analysis)
357
287
  };
358
- if args.len() == candidate.params.len()
359
- && is_operation(returned, &is_parameter_or_number)
360
- && args.iter().all(|arg| is_operation(&arg.expr, &is_pure))
361
- {
362
- let values: HashMap<Id, &Expr> = candidate
363
- .params
288
+ if arguments.len() == parameters.len()
289
+ && operation(returned, &forwards)
290
+ && arguments
364
291
  .iter()
365
- .cloned()
366
- .zip(args.iter().map(|arg| &*arg.expr))
367
- .collect();
368
- // The operation calls nothing, so no parameter needs detaching.
369
- Some(helper_objects::replace_parameters(returned, values))
370
- } else {
371
- None
292
+ .all(|argument| operation(argument, &effect_free))
293
+ {
294
+ let values = parameters.into_iter().zip(arguments).collect();
295
+ return Some(ast::replace_parameters(returned, &values, analysis));
372
296
  }
297
+ None
298
+ }
299
+
300
+ fn argument(&self, expression: &Expression<'a>) -> Argument<'a> {
301
+ Argument::from(expression.clone_in_with_semantic_ids(self.analysis.allocator()))
302
+ }
303
+
304
+ fn call(
305
+ &self,
306
+ span: Span,
307
+ callee: &Expression<'a>,
308
+ arguments: ArenaVec<'a, Argument<'a>>,
309
+ ) -> Expression<'a> {
310
+ let callee = callee.clone_in_with_semantic_ids(self.analysis.allocator());
311
+ Expression::new_call_expression(span, callee, None, arguments, false, &self.analysis.ast)
373
312
  }
374
313
  }
375
314
 
376
- impl VisitMut for InlineDispatchers<'_> {
377
- fn visit_mut_expr(&mut self, expression: &mut Expr) {
378
- expression.visit_mut_children_with(self);
379
- if let Some((callee, args)) = ast::direct_call(expression)
380
- && let Some(replacement) = self.replacement(&callee.to_id(), args)
315
+ impl<'a> VisitMut<'a> for Inline<'_, 'a> {
316
+ fn visit_expression(&mut self, expression: &mut Expression<'a>) {
317
+ walk_mut::walk_expression(self, expression);
318
+ if let Some((callee, arguments)) = ast::direct_call(expression)
319
+ && let Some(id) = self.analysis.id(callee)
320
+ && let Some(value) = self.replacement(id, arguments, callee.span)
381
321
  {
382
- *expression = replacement;
383
- self.changed = true;
322
+ *expression = value;
323
+ self.changed = true
384
324
  }
385
325
  }
386
326
  }
387
327
 
388
328
  #[cfg(test)]
389
329
  mod tests {
390
- use crate::deobfuscate::testing;
330
+ use oxc::allocator::Allocator;
331
+ use oxc::ast::ast::Statement;
332
+
333
+ use crate::deobfuscate::{pipeline, testing};
391
334
 
392
335
  const APPLY: &str = "var b; b = function (n, m, r) {
393
336
  switch (3832 ^ n) {
@@ -402,7 +345,7 @@ mod tests {
402
345
 
403
346
  #[test]
404
347
  fn applies_the_target_only_for_provable_applications() {
405
- let inline = |source: &str| testing::rewrite(source, super::run, /* fix= */ true);
348
+ let inline = |source: &str| testing::rewrite(source, super::run);
406
349
  let output = inline(&format!(
407
350
  "{APPLY} f(b(971996, encode, [x, 1]), b(428000, g, []));"
408
351
  ));
@@ -422,7 +365,7 @@ mod tests {
422
365
 
423
366
  #[test]
424
367
  fn calls_targets_selected_by_several_selectors_only_in_argument_order() {
425
- let inline = |source: &str| testing::rewrite(source, super::run_all, /* fix= */ true);
368
+ let inline = |source: &str| testing::rewrite(source, super::run_all);
426
369
  let dispatchers = "function c(n, m, f, x, y) {
427
370
  switch (n ^ 5) { case 1: switch (3 ^ m) { case 1: return f(x, y); } return; }
428
371
  }
@@ -430,7 +373,7 @@ mod tests {
430
373
  let source = format!("{dispatchers} g(c(4, 2, encode, a(), b));");
431
374
  let output = inline(&source);
432
375
  assert!(output.contains("g(encode(a(), b))"), "{output}");
433
- let decoding = testing::rewrite(&source, super::run, /* fix= */ true);
376
+ let decoding = testing::rewrite(&source, super::run);
434
377
  assert!(decoding.contains("g(c(4, 2,"), "{decoding}");
435
378
  for call in [
436
379
  "c(4, 2, o.encode, a, b)",
@@ -445,11 +388,11 @@ mod tests {
445
388
 
446
389
  #[test]
447
390
  fn inlines_selected_operations_through_switches_if_chains_and_xor_keys() {
448
- let inline = |source: &str| testing::rewrite(source, super::run, /* fix= */ true);
391
+ let inline = |source: &str| testing::rewrite(source, super::run);
449
392
  let output = inline(&format!(
450
393
  "{OPERATOR} function g(a, b) {{ f(w(1, 630, 622), w(2, a, b + 1), w(9, 7, 2)); }}"
451
394
  ));
452
- testing::assert_contains(&output, &["f(630 - 622, (b + 1) * a, 7 % 2)"], &[]);
395
+ testing::assert_contains(&output, &["f(630 - 622, (b + 1) * a, 7 % 2)"]);
453
396
  let output = inline(
454
397
  "t = function (V, c, X) {
455
398
  if (!(V !== 0)) { return c + X; } else { if (!(2 === V)) { return c % X; } else { return X * c; } }
@@ -457,7 +400,7 @@ mod tests {
457
400
  function q(J, r, n) { switch (2774 ^ J) { case 0: return r | n; default: return r & n; } }
458
401
  function g(a, b) { f(t(0, a, b), t(2, a, b), t(5, a, b), q(2774, a, b), q(2775, a, b)); }",
459
402
  );
460
- testing::assert_contains(&output, &["f(a + b, b * a, a % b, a | b, a & b)"], &[]);
403
+ testing::assert_contains(&output, &["f(a + b, b * a, a % b, a | b, a & b)"]);
461
404
  // Arguments with effects and unknown selectors stay.
462
405
  for call in ["w(1, g(), 2)", "w(n, 1, 2)", "w(1, 2)", "w(1, missing, 2)"] {
463
406
  let output = inline(&format!("{OPERATOR} f({call});"));
@@ -467,17 +410,14 @@ mod tests {
467
410
 
468
411
  #[test]
469
412
  fn only_bodies_that_can_select_a_return_are_candidates() {
470
- use swc_core::ecma::ast::{Decl, Stmt};
471
-
472
413
  let selects = |body: &str| {
473
- let script =
474
- crate::js::ast::parse_javascript("a test", &format!("function f(n) {{ {body} }}"))
475
- .unwrap()
476
- .script;
477
- let Some(Stmt::Decl(Decl::Fn(function))) = script.body.first() else {
478
- panic!("not a function declaration: {body}");
414
+ let allocator = Allocator::default();
415
+ let source = format!("function f(n) {{ {body} }}");
416
+ let (program, _) = pipeline::parse(&allocator, &source).unwrap();
417
+ let Statement::FunctionDeclaration(function) = &program.body[0] else {
418
+ panic!("not a function declaration")
479
419
  };
480
- super::may_select(&function.function.body.as_ref().unwrap().stmts)
420
+ super::may_select(&function.body.as_ref().unwrap().statements)
481
421
  };
482
422
  for body in [
483
423
  "return 1;",