cfsolve 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (368) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/THIRD_PARTY_LICENSES/README.md +71 -254
  4. data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
  5. data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
  6. data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
  7. data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
  8. data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
  9. data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
  10. data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
  11. data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
  12. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
  13. data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
  14. data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
  15. data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
  16. data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
  17. data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
  18. data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
  19. data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
  20. data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
  21. data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
  22. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
  23. data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
  24. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
  25. data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
  26. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
  27. data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
  28. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
  29. data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
  30. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
  31. data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
  32. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
  33. data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
  34. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
  35. data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
  36. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
  37. data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
  38. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
  39. data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
  40. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
  41. data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
  42. data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
  43. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
  44. data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
  45. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
  46. data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
  47. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
  48. data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
  49. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
  50. data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
  51. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
  52. data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
  53. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
  54. data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
  55. data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
  56. data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
  57. data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
  58. data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
  59. data/UPSTREAM.md +7 -5
  60. data/ext/cfsolve/Cargo.lock +534 -1727
  61. data/ext/cfsolve/Cargo.toml +4 -0
  62. data/ext/cfsolve/src/main.rs +1 -1
  63. data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  64. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  65. data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
  66. data/lib/cfsolve/version.rb +2 -2
  67. data/vendor/cfsolve/Cargo.lock +561 -1729
  68. data/vendor/cfsolve/Cargo.toml +26 -8
  69. data/vendor/cfsolve/README.md +4 -0
  70. data/vendor/cfsolve/examples/check_answers.rs +2 -2
  71. data/vendor/cfsolve/examples/compare_session.rs +1 -2
  72. data/vendor/cfsolve/examples/solver_profile.rs +84 -0
  73. data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
  74. data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
  75. data/vendor/cfsolve/examples/tls_echo.rs +3 -3
  76. data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
  77. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
  78. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
  79. data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
  80. data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
  81. data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
  82. data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
  83. data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
  84. data/vendor/cfsolve/src/capture/proxy.rs +44 -13
  85. data/vendor/cfsolve/src/capture/sessions.rs +4 -3
  86. data/vendor/cfsolve/src/capture/upstream.rs +1 -1
  87. data/vendor/cfsolve/src/challenge/codec.rs +4 -2
  88. data/vendor/cfsolve/src/challenge/expression.rs +161 -117
  89. data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
  90. data/vendor/cfsolve/src/challenge/installed.rs +13 -6
  91. data/vendor/cfsolve/src/challenge/merge.rs +120 -80
  92. data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
  93. data/vendor/cfsolve/src/challenge/payload.rs +69 -31
  94. data/vendor/cfsolve/src/challenge/program.rs +197 -178
  95. data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
  96. data/vendor/cfsolve/src/challenge/source.rs +151 -96
  97. data/vendor/cfsolve/src/challenge/state.rs +180 -148
  98. data/vendor/cfsolve/src/challenge/tally.rs +64 -50
  99. data/vendor/cfsolve/src/challenge.rs +1 -0
  100. data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
  101. data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
  102. data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
  103. data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
  104. data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
  105. data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
  106. data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
  107. data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
  108. data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
  109. data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
  110. data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
  111. data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
  112. data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
  113. data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
  114. data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
  115. data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
  116. data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
  117. data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
  118. data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
  119. data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
  120. data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
  121. data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
  122. data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
  123. data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
  124. data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
  125. data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
  126. data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
  127. data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
  128. data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
  129. data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
  130. data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
  131. data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
  132. data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
  133. data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
  134. data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
  135. data/vendor/cfsolve/src/deobfuscate.rs +15 -11
  136. data/vendor/cfsolve/src/embedding_page/extra_params.rs +23 -18
  137. data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
  138. data/vendor/cfsolve/src/error.rs +40 -5
  139. data/vendor/cfsolve/src/fingerprint.rs +8 -2
  140. data/vendor/cfsolve/src/http/client.rs +7 -10
  141. data/vendor/cfsolve/src/http/requests.rs +2 -2
  142. data/vendor/cfsolve/src/js/ast.rs +479 -263
  143. data/vendor/cfsolve/src/lib.rs +1 -0
  144. data/vendor/cfsolve/src/listing/fold.rs +19 -9
  145. data/vendor/cfsolve/src/listing/query.rs +1 -47
  146. data/vendor/cfsolve/src/performance_clock.rs +20 -1
  147. data/vendor/cfsolve/src/profiling.rs +49 -0
  148. data/vendor/cfsolve/src/script.rs +35 -24
  149. data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
  150. data/vendor/cfsolve/src/session/channel.rs +2 -2
  151. data/vendor/cfsolve/src/session/initial.rs +5 -5
  152. data/vendor/cfsolve/src/session/sink.rs +26 -1
  153. data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
  154. data/vendor/cfsolve/src/session.rs +1 -1
  155. data/vendor/cfsolve/src/solver.rs +3 -1
  156. data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
  157. data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
  158. data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
  159. data/vendor/cfsolve/src/stage2/benchmark.rs +62 -31
  160. data/vendor/cfsolve/src/stage2/call_stack.rs +1415 -1025
  161. data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
  162. data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
  163. data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
  164. data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
  165. data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
  166. data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
  167. data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
  168. data/vendor/cfsolve/src/stage2/queries.rs +50 -0
  169. data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
  170. data/vendor/cfsolve/src/stage2/trace.rs +134 -108
  171. data/vendor/cfsolve/src/stage2/vocabulary.rs +1 -11
  172. data/vendor/cfsolve/src/stage2.rs +2 -0
  173. data/vendor/cfsolve/src/vm/disassemble.rs +7 -3
  174. data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
  175. data/vendor/cfsolve/src/vm/extract.rs +347 -250
  176. data/vendor/cfsolve/src/vm/interpret/access.rs +63 -48
  177. data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
  178. data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
  179. data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
  180. data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
  181. data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
  182. data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
  183. data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
  184. data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
  185. data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
  186. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +123 -59
  187. data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
  188. data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
  189. data/vendor/cfsolve/src/vm/interpret/pattern.rs +1736 -0
  190. data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
  191. data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
  192. data/vendor/cfsolve/src/vm/interpret/run.rs +116 -45
  193. data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
  194. data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
  195. data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
  196. data/vendor/cfsolve/src/vm/interpret.rs +9 -1
  197. data/vendor/cfsolve/src/vm/machine.rs +56 -49
  198. data/vendor/cfsolve/src/vm/output.rs +13 -5
  199. data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
  200. data/vendor/cfsolve/src/vm/session.rs +185 -120
  201. data/vendor/cfsolve/src/vm/value.rs +22 -19
  202. data/vendor/cfsolve/src/vm.rs +2 -1
  203. data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
  204. data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
  205. metadata +94 -178
  206. data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
  207. data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
  208. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
  209. data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
  210. data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
  211. data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
  212. data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
  213. data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
  214. data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
  215. data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
  216. data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
  217. data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
  218. data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
  219. data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
  220. data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
  221. data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
  222. data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
  223. data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
  224. data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
  225. data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
  226. data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
  227. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
  228. data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
  229. data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
  230. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
  231. data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
  232. data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
  233. data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
  234. data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
  235. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
  236. data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
  237. data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
  238. data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
  239. data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
  240. data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
  241. data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
  242. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
  243. data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
  244. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
  245. data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
  246. data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
  247. data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
  248. data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
  249. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
  250. data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
  251. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
  252. data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
  253. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
  254. data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
  255. data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
  256. data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
  257. data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
  258. data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
  259. data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
  260. data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
  261. data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
  262. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
  263. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
  264. data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
  265. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
  266. data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
  267. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
  268. data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
  269. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
  270. data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
  271. data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
  272. data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
  273. data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
  274. data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
  275. data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
  276. data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
  277. data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
  278. data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
  279. data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
  280. data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
  281. data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
  282. data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
  283. data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
  284. data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
  285. data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
  286. data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
  287. data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
  288. data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
  289. data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
  290. data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
  291. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
  292. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
  293. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
  294. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
  295. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
  296. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
  297. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
  298. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
  299. data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
  300. data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
  301. data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
  302. data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
  303. data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
  304. data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
  305. data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
  306. data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
  307. data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
  308. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
  309. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
  310. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
  311. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
  312. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
  313. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
  314. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
  315. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
  316. data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
  317. data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
  318. data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
  319. data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
  320. data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
  321. data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
  322. data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
  323. data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
  324. data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
  325. data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
  326. data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
  327. data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
  328. data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
  329. data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
  330. data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
  331. data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
  332. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
  333. data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
  334. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
  335. data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
  336. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
  337. data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
  338. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
  339. data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
  340. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
  341. data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
  342. data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
  343. data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
  344. data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
  345. /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
  346. /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
  347. /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
  348. /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
  349. /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
  350. /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
  351. /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
  352. /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
  353. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
  354. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
  355. /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
  356. /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
  357. /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
  358. /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
  359. /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
  360. /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
  361. /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
  362. /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
  363. /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
  364. /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
  365. /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
  366. /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
  367. /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
  368. /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
@@ -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;",