cfsolve 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +8 -3
- data/THIRD_PARTY_LICENSES/README.md +71 -254
- data/THIRD_PARTY_LICENSES/{derive_builder_macro-0.20.2/LICENSE-APACHE → bytecount-0.6.9/LICENSE.Apache2} +0 -1
- data/THIRD_PARTY_LICENSES/{darling-0.20.11/LICENSE → bytecount-0.6.9/LICENSE.MIT} +1 -3
- data/THIRD_PARTY_LICENSES/{ident_case-1.0.1/LICENSE → cobs-0.3.0/LICENSE-MIT} +1 -1
- data/THIRD_PARTY_LICENSES/cow-utils-0.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → embedded-io-0.4.0}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.6.1}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{browserslist-data-0.1.4 → escape-simd-0.1.1}/LICENSE +1 -1
- data/THIRD_PARTY_LICENSES/escape-simd-0.1.1/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/LICENSE +21 -0
- data/THIRD_PARTY_LICENSES/{miette-7.6.0/LICENSE → json-escape-simd-3.1.3/LICENSE-APACHE} +0 -1
- data/THIRD_PARTY_LICENSES/json-escape-simd-3.1.3/NOTICE +62 -0
- data/THIRD_PARTY_LICENSES/memchr-2.8.3/UNLICENSE +24 -0
- data/THIRD_PARTY_LICENSES/{derive_builder_core-0.20.2 → nonmax-0.5.5}/LICENSE-APACHE +1 -2
- data/THIRD_PARTY_LICENSES/{dashmap-5.5.3/LICENSE → nonmax-0.5.5/LICENSE-MIT} +2 -4
- data/THIRD_PARTY_LICENSES/{rand-0.8.5 → num-bigint-0.5.1}/LICENSE-MIT +0 -1
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{browserslist-rs-0.19.0 → oxc-browserslist-5.0.1}/LICENSE +1 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_allocator-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_macros-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ast_visit-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_codegen-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_compat-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_data_structures-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_diagnostics-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_ecmascript-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_estree-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_index-5.0.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_parser-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_regular_expression-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_semantic-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_span-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_str-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/LICENSE +22 -0
- data/THIRD_PARTY_LICENSES/oxc_syntax-0.157.0/THIRD-PARTY-LICENSE +763 -0
- data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-MIT +1 -1
- data/THIRD_PARTY_LICENSES/{bytes-str-0.2.7/LICENSE → self_cell-1.3.0/LICENSE-APACHE} +1 -2
- data/THIRD_PARTY_LICENSES/self_cell-1.3.0/LICENSE-GPLv2 +339 -0
- data/THIRD_PARTY_LICENSES/{darling_core-0.20.11 → smawk-0.3.3}/LICENSE +1 -1
- data/UPSTREAM.md +14 -6
- data/ext/cfsolve/Cargo.lock +534 -1727
- data/ext/cfsolve/Cargo.toml +4 -0
- data/ext/cfsolve/src/main.rs +1 -1
- data/lib/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
- data/lib/cfsolve/profiles/chrome-157-macos.json +613 -0
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +266 -265
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/lib/cfsolve/profiles/safari-26-ios.json +106 -152
- data/lib/cfsolve/version.rb +2 -2
- data/lib/cfsolve.rb +1 -1
- data/vendor/cfsolve/Cargo.lock +561 -1729
- data/vendor/cfsolve/Cargo.toml +26 -8
- data/vendor/cfsolve/README.md +57 -5
- data/vendor/cfsolve/examples/check_answers.rs +2 -2
- data/vendor/cfsolve/examples/compare_session.rs +1 -2
- data/vendor/cfsolve/examples/solver_profile.rs +84 -0
- data/vendor/cfsolve/examples/solver_smoke.rs +9 -8
- data/vendor/cfsolve/examples/stage2_snapshot.rs +2 -2
- data/vendor/cfsolve/examples/tls_echo.rs +3 -3
- data/vendor/cfsolve/examples/turnstile_smoke.rs +58 -0
- data/vendor/cfsolve/examples/vm_snapshot.rs +32 -33
- data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
- data/vendor/cfsolve/profiles/chrome-157-macos.json +613 -0
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +266 -265
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +312 -312
- data/vendor/cfsolve/profiles/safari-26-ios.json +106 -152
- data/vendor/cfsolve/src/bin/capture-proxy/main.rs +3 -2
- data/vendor/cfsolve/src/bin/challenge/cli.rs +8 -2
- data/vendor/cfsolve/src/bin/challenge/main.rs +7 -2
- data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- data/vendor/cfsolve/src/capture/sessions.rs +4 -3
- data/vendor/cfsolve/src/capture/upstream.rs +1 -1
- data/vendor/cfsolve/src/challenge/codec.rs +4 -2
- data/vendor/cfsolve/src/challenge/expression.rs +161 -117
- data/vendor/cfsolve/src/challenge/installed/audit.rs +11 -10
- data/vendor/cfsolve/src/challenge/installed.rs +13 -6
- data/vendor/cfsolve/src/challenge/merge.rs +120 -80
- data/vendor/cfsolve/src/challenge/orchestrator.rs +57 -44
- data/vendor/cfsolve/src/challenge/payload.rs +69 -31
- data/vendor/cfsolve/src/challenge/program.rs +197 -178
- data/vendor/cfsolve/src/challenge/reduced_timing.rs +55 -40
- data/vendor/cfsolve/src/challenge/source.rs +151 -96
- data/vendor/cfsolve/src/challenge/state.rs +180 -148
- data/vendor/cfsolve/src/challenge/tally.rs +64 -50
- data/vendor/cfsolve/src/challenge.rs +1 -0
- data/vendor/cfsolve/src/deobfuscate/analysis/bindings.rs +187 -185
- data/vendor/cfsolve/src/deobfuscate/analysis/effects.rs +42 -51
- data/vendor/cfsolve/src/deobfuscate/analysis/hoisting.rs +147 -228
- data/vendor/cfsolve/src/deobfuscate/analysis/properties.rs +250 -425
- data/vendor/cfsolve/src/deobfuscate/analysis/unconditional.rs +79 -0
- data/vendor/cfsolve/src/deobfuscate/analysis.rs +259 -41
- data/vendor/cfsolve/src/deobfuscate/argument_arrays.rs +70 -73
- data/vendor/cfsolve/src/deobfuscate/arrow_blocks.rs +91 -104
- data/vendor/cfsolve/src/deobfuscate/ast.rs +383 -0
- data/vendor/cfsolve/src/deobfuscate/bitwise.rs +44 -54
- data/vendor/cfsolve/src/deobfuscate/blocks.rs +36 -29
- data/vendor/cfsolve/src/deobfuscate/call_helpers.rs +80 -131
- data/vendor/cfsolve/src/deobfuscate/control_flow.rs +239 -297
- data/vendor/cfsolve/src/deobfuscate/copy_propagation.rs +114 -135
- data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +62 -61
- data/vendor/cfsolve/src/deobfuscate/dead_properties.rs +197 -214
- data/vendor/cfsolve/src/deobfuscate/dispatch.rs +238 -298
- data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +198 -203
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +338 -513
- data/vendor/cfsolve/src/deobfuscate/hygiene.rs +197 -0
- data/vendor/cfsolve/src/deobfuscate/int32_helpers.rs +121 -155
- data/vendor/cfsolve/src/deobfuscate/literals.rs +116 -67
- data/vendor/cfsolve/src/deobfuscate/loops.rs +43 -43
- data/vendor/cfsolve/src/deobfuscate/memoized_strings.rs +127 -131
- data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +262 -220
- data/vendor/cfsolve/src/deobfuscate/pipeline.rs +199 -244
- data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +353 -327
- data/vendor/cfsolve/src/deobfuscate/removal.rs +83 -52
- data/vendor/cfsolve/src/deobfuscate/simplify.rs +147 -0
- data/vendor/cfsolve/src/deobfuscate/state_machines.rs +88 -110
- data/vendor/cfsolve/src/deobfuscate/statements.rs +228 -228
- data/vendor/cfsolve/src/deobfuscate/static_members.rs +46 -31
- data/vendor/cfsolve/src/deobfuscate/testing.rs +49 -59
- data/vendor/cfsolve/src/deobfuscate/unused_bindings.rs +92 -102
- data/vendor/cfsolve/src/deobfuscate.rs +15 -11
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +132 -24
- data/vendor/cfsolve/src/embedding_page/page.rs +41 -1
- data/vendor/cfsolve/src/embedding_page/render_sample.rs +184 -147
- data/vendor/cfsolve/src/error.rs +40 -5
- data/vendor/cfsolve/src/fingerprint.rs +8 -2
- data/vendor/cfsolve/src/http/client.rs +7 -10
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -263
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -9
- data/vendor/cfsolve/src/listing/query.rs +1 -47
- data/vendor/cfsolve/src/performance_clock.rs +20 -1
- data/vendor/cfsolve/src/profiling.rs +49 -0
- data/vendor/cfsolve/src/script.rs +35 -24
- data/vendor/cfsolve/src/session/challenge_page.rs +41 -21
- data/vendor/cfsolve/src/session/channel.rs +2 -2
- data/vendor/cfsolve/src/session/initial.rs +12 -11
- data/vendor/cfsolve/src/session/probes.rs +1 -0
- data/vendor/cfsolve/src/session/sink.rs +26 -1
- data/vendor/cfsolve/src/session/tests/challenge_page.rs +36 -1
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +33 -4
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +13 -2
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +2 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +142 -74
- data/vendor/cfsolve/src/stage2/benchmark.rs +113 -41
- data/vendor/cfsolve/src/stage2/call_stack.rs +1564 -1041
- data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
- data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +1 -0
- data/vendor/cfsolve/src/stage2/interaction/checkbox.rs +202 -150
- data/vendor/cfsolve/src/stage2/interaction/click.rs +2 -2
- data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -4
- data/vendor/cfsolve/src/stage2/payload/recover.rs +2 -2
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/dates.rs +44 -0
- data/vendor/cfsolve/src/stage2/probes/parent_info_array.rs +326 -0
- data/vendor/cfsolve/src/stage2/probes/performance.rs +12 -8
- data/vendor/cfsolve/src/stage2/probes/stack.rs +117 -4
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +80 -2
- data/vendor/cfsolve/src/stage2/probes.rs +1 -0
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/reference.rs +5 -0
- data/vendor/cfsolve/src/stage2/registry.rs +8 -2
- data/vendor/cfsolve/src/stage2/replay.rs +34 -3
- data/vendor/cfsolve/src/stage2/stylesheets.rs +35 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +134 -108
- data/vendor/cfsolve/src/stage2/value_labels.rs +185 -0
- data/vendor/cfsolve/src/stage2/vocabulary.rs +112 -17
- data/vendor/cfsolve/src/stage2.rs +3 -0
- data/vendor/cfsolve/src/vm/disassemble.rs +75 -7
- data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
- data/vendor/cfsolve/src/vm/encoded_names.rs +635 -0
- data/vendor/cfsolve/src/vm/extract.rs +550 -250
- data/vendor/cfsolve/src/vm/fixtures/free_functions/README.md +9 -0
- data/vendor/cfsolve/src/vm/fixtures/free_functions/machine.js +7438 -0
- data/vendor/cfsolve/src/vm/fixtures/free_functions/program.base64 +1 -0
- data/vendor/cfsolve/src/vm/interpret/access.rs +71 -50
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +10 -10
- data/vendor/cfsolve/src/vm/interpret/call.rs +116 -52
- data/vendor/cfsolve/src/vm/interpret/compile.rs +79 -62
- data/vendor/cfsolve/src/vm/interpret/copies.rs +2 -2
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +63 -42
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +65 -575
- data/vendor/cfsolve/src/vm/interpret/explore.rs +7 -10
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +3 -5
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +160 -58
- data/vendor/cfsolve/src/vm/interpret/mix32.rs +189 -0
- data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +220 -0
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +1765 -0
- data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +392 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +120 -45
- data/vendor/cfsolve/src/vm/interpret/semantics.rs +71 -46
- data/vendor/cfsolve/src/vm/interpret/setup.rs +80 -45
- data/vendor/cfsolve/src/vm/interpret/string_decoder.rs +482 -0
- data/vendor/cfsolve/src/vm/interpret.rs +9 -1
- data/vendor/cfsolve/src/vm/machine.rs +116 -51
- data/vendor/cfsolve/src/vm/output.rs +19 -6
- data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
- data/vendor/cfsolve/src/vm/registers.rs +35 -21
- data/vendor/cfsolve/src/vm/session.rs +189 -121
- data/vendor/cfsolve/src/vm/value.rs +22 -19
- data/vendor/cfsolve/src/vm.rs +3 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- metadata +106 -178
- data/THIRD_PARTY_LICENSES/Inflector-0.11.4/LICENSE.md +0 -22
- data/THIRD_PARTY_LICENSES/arrayvec-0.7.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/ascii-1.1.0/LICENSE-MIT +0 -22
- data/THIRD_PARTY_LICENSES/ast_node-5.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/better_scoped_tls-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/bitvec-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/COPYING +0 -8
- data/THIRD_PARTY_LICENSES/bstr-1.12.1/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/cargo-platform-0.1.9/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/cargo_metadata-0.19.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/darling_macro-0.20.11/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/debugid-0.8.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/derive_builder-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_core-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/derive_builder_macro-0.20.2/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/foldhash-0.1.5/LICENSE +0 -19
- data/THIRD_PARTY_LICENSES/from_variant-3.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/funty-2.0.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/hashbrown-0.16.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/heck-0.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/hermit-abi-0.5.2/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/hstr-3.0.3/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/if_chain-1.0.3/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/is-macro-0.3.7/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/itoa-1.0.17/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/jsonc-parser-0.26.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/lazy_static-1.5.0/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/lru-0.16.2/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/COPYING +0 -3
- data/THIRD_PARTY_LICENSES/memchr-2.7.6/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/miette-derive-7.6.0/LICENSE +0 -229
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/COPYRIGHT +0 -7
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/normpath-0.2.0/LICENSE-THIRD-PARTY +0 -210
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/num_cpus-1.17.0/LICENSE-MIT +0 -20
- data/THIRD_PARTY_LICENSES/owo-colors-4.2.3/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/par-core-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/par-iter-2.0.0/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-0.1.0/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-APACHE +0 -13
- data/THIRD_PARTY_LICENSES/path-clean-1.0.1/LICENSE-MIT +0 -18
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/pathdiff-0.2.3/LICENSE-MIT +0 -23
- data/THIRD_PARTY_LICENSES/petgraph-0.7.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/precomputed-map-0.2.0/LICENSE +0 -21
- data/THIRD_PARTY_LICENSES/preset_env_base-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/radium-0.7.0/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/radix_fmt-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/rand-0.8.5/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand-0.8.5/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/COPYRIGHT +0 -12
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-APACHE +0 -187
- data/THIRD_PARTY_LICENSES/rand_core-0.6.4/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/regress-0.10.5/LICENSE-MIT +0 -21
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-APACHE +0 -176
- data/THIRD_PARTY_LICENSES/ryu-1.0.22/LICENSE-BOOST +0 -23
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/scoped-tls-1.0.1/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/siphasher-0.3.11/COPYING +0 -7
- data/THIRD_PARTY_LICENSES/smallvec-1.15.1/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/smartstring-1.0.1/LICENCE.md +0 -355
- data/THIRD_PARTY_LICENSES/st-map-0.2.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/static-map-macro-0.3.4/LICENSE +0 -202
- data/THIRD_PARTY_LICENSES/string_enum-1.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/strsim-0.11.1/LICENSE +0 -23
- data/THIRD_PARTY_LICENSES/swc-52.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_allocator-4.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_atoms-9.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_common-18.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_compiler_base-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config-3.1.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_config_macro-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_core-54.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ast-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen-21.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_codegen_macros-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_bugfixes-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_common-30.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2015-39.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2016-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2017-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2018-36.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2019-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2020-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2021-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es2022-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_compat_es3-26.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_ext_transforms-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_hooks-0.3.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_loader-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_minifier-42.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_parser-32.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_preset_env-45.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transformer-6.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms-44.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_base-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_classes-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_compat-40.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_module-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_optimization-37.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_proposal-35.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_react-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_transforms_typescript-38.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_usage_analyzer-27.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_utils-25.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_ecma_visit-19.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_eq_ignore_macros-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_error_reporters-20.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_macros_common-1.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_node_comments-18.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_timer-1.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_trace_macro-2.0.2/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_transform_common-12.0.0/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/swc_visit-2.0.1/LICENSE +0 -201
- data/THIRD_PARTY_LICENSES/tap-1.0.1/LICENSE.txt +0 -21
- data/THIRD_PARTY_LICENSES/tracing-0.1.44/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-attributes-0.1.31/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/tracing-core-0.1.36/LICENSE +0 -25
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/triomphe-0.1.15/LICENSE-MIT +0 -27
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/unicode-width-0.1.14/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/uuid-1.19.0/LICENSE-MIT +0 -26
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-9.0.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-APACHE +0 -201
- data/THIRD_PARTY_LICENSES/vergen-lib-0.1.6/LICENSE-MIT +0 -25
- data/THIRD_PARTY_LICENSES/wyz-0.5.1/LICENSE.txt +0 -21
- data/vendor/cfsolve/src/deobfuscate/analysis/globals.rs +0 -33
- data/vendor/cfsolve/src/deobfuscate/analysis/names.rs +0 -52
- /data/THIRD_PARTY_LICENSES/{derive_builder-0.20.2 → cobs-0.3.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{compact_str-0.7.1 → compact_str-0.10.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{ahash-0.8.12 → embedded-io-0.4.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{arrayvec-0.7.6 → embedded-io-0.6.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{normpath-0.2.0 → escape-simd-0.1.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{bstr-1.12.1 → itertools-0.15.0}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{petgraph-0.7.1 → itertools-0.15.0}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{itoa-1.0.17 → itoa-1.0.19}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → itoa-1.0.19}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/COPYING +0 -0
- /data/THIRD_PARTY_LICENSES/{globset-0.4.18 → memchr-2.8.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{camino-1.2.2 → num-bigint-0.5.1}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{swc_sourcemap-9.3.4 → oxc_sourcemap-9.0.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf-0.11.3 → phf-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_generator-0.11.3 → phf_generator-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_macros-0.11.3 → phf_macros-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{phf_shared-0.11.3 → phf_shared-0.14.0}/LICENSE +0 -0
- /data/THIRD_PARTY_LICENSES/{fixedbitset-0.5.7 → postcard-1.1.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.14.5 → smallvec-1.16.5}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{smallvec-1.15.1 → smallvec-1.16.5}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{unicode-width-0.1.14 → unicode-segmentation-1.13.3}/COPYRIGHT +0 -0
- /data/THIRD_PARTY_LICENSES/{hashbrown-0.16.1 → unicode-segmentation-1.13.3}/LICENSE-APACHE +0 -0
- /data/THIRD_PARTY_LICENSES/{heck-0.5.0 → unicode-segmentation-1.13.3}/LICENSE-MIT +0 -0
- /data/THIRD_PARTY_LICENSES/{cargo-platform-0.1.9 → zmij_ecma-1.0.23}/LICENSE-MIT +0 -0
|
@@ -22,292 +22,309 @@
|
|
|
22
22
|
//! use the selector, `arguments`, or declarations from another case. Each new function gets
|
|
23
23
|
//! separate bindings for the remaining parameters. Cases with no callers are removed.
|
|
24
24
|
|
|
25
|
-
use
|
|
26
|
-
use
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
use oxc::allocator::{Box, CloneIn, GetAllocator, TakeIn, Vec as ArenaVec};
|
|
26
|
+
use oxc::ast::ast::{
|
|
27
|
+
Argument, BindingIdentifier, BindingPattern, CallExpression, Expression, Function,
|
|
28
|
+
FunctionType, IdentifierReference, Program, Statement,
|
|
29
29
|
};
|
|
30
|
-
use
|
|
30
|
+
use oxc::ast_visit::{Visit, VisitMut, walk, walk_mut};
|
|
31
|
+
use oxc::span::GetSpan;
|
|
32
|
+
use oxc::syntax::node::NodeId;
|
|
33
|
+
use oxc::syntax::reference::ReferenceFlags;
|
|
34
|
+
use oxc::syntax::scope::ScopeFlags;
|
|
35
|
+
use oxc::syntax::symbol::SymbolId;
|
|
31
36
|
|
|
32
|
-
use super::analysis::{Analysis,
|
|
33
|
-
use super::
|
|
34
|
-
use super::{HashMap, HashSet};
|
|
35
|
-
use crate::js::ast;
|
|
37
|
+
use super::analysis::{Analysis, Id};
|
|
38
|
+
use super::ast::LabeledContinue;
|
|
39
|
+
use super::{HashMap, HashSet, ast};
|
|
36
40
|
|
|
37
|
-
pub(super) fn run(program: &mut Program
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
|
|
42
|
+
let candidates = ast::functions(program, analysis, &|function| {
|
|
43
|
+
function.r#type == FunctionType::FunctionDeclaration
|
|
44
|
+
&& function.body.as_ref().is_some_and(|body| {
|
|
45
|
+
matches!(body.statements.as_slice(), [Statement::SwitchStatement(_)])
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
let mut functions = HashMap::default();
|
|
49
|
+
for (id, function) in candidates {
|
|
50
|
+
if let Some(selection) = selection(function, analysis) {
|
|
51
|
+
functions.insert(id, selection);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
44
54
|
let mut calls = Calls {
|
|
45
|
-
|
|
55
|
+
analysis,
|
|
56
|
+
functions: &functions,
|
|
46
57
|
picked: HashMap::default(),
|
|
47
58
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let mut splits: HashMap<Id, Vec<Option<Ident>>> = HashMap::default();
|
|
59
|
+
calls.visit_program(program);
|
|
60
|
+
let mut splits = HashMap::default();
|
|
51
61
|
for (id, picked) in calls.picked {
|
|
52
|
-
|
|
62
|
+
if picked.calls != analysis.bindings.references(&id) {
|
|
53
63
|
continue;
|
|
54
|
-
}
|
|
55
|
-
let
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
.collect();
|
|
64
|
-
splits.insert(id, names);
|
|
64
|
+
}
|
|
65
|
+
let scope = analysis.scope(id);
|
|
66
|
+
let base = analysis.name(id).to_owned();
|
|
67
|
+
let span = analysis.span(id);
|
|
68
|
+
let names = (0..functions[&id].labels.len()).map(|index| {
|
|
69
|
+
let used = picked.cases.contains(&index);
|
|
70
|
+
used.then(|| analysis.fresh_binding(&format!("{base}_{index}"), scope, span))
|
|
71
|
+
});
|
|
72
|
+
splits.insert(id, names.collect());
|
|
65
73
|
}
|
|
66
74
|
if splits.is_empty() {
|
|
67
75
|
return false;
|
|
68
76
|
}
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
Unmerge {
|
|
78
|
+
analysis,
|
|
79
|
+
functions: &functions,
|
|
71
80
|
splits: &splits,
|
|
72
|
-
}
|
|
81
|
+
}
|
|
82
|
+
.visit_program(program);
|
|
73
83
|
true
|
|
74
84
|
}
|
|
75
85
|
|
|
76
|
-
/// Maps selector values to cases in a merged function.
|
|
77
|
-
struct Selection {
|
|
86
|
+
/// Maps numeric selector values to cases in a merged function.
|
|
87
|
+
struct Selection<'a> {
|
|
78
88
|
selector: Id,
|
|
79
|
-
discriminant:
|
|
89
|
+
discriminant: &'a Expression<'a>,
|
|
80
90
|
labels: Vec<f64>,
|
|
81
91
|
}
|
|
82
92
|
|
|
83
|
-
impl Selection {
|
|
84
|
-
///
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
93
|
+
impl Selection<'_> {
|
|
94
|
+
/// Evaluates the discriminant with the call's literal first argument as the selector, and
|
|
95
|
+
/// finds the matching case label.
|
|
96
|
+
fn called_case(&self, call: &CallExpression<'_>, analysis: &Analysis<'_>) -> Option<usize> {
|
|
97
|
+
let value = ast::number(call.arguments.first()?.as_expression()?)?;
|
|
98
|
+
let selected = ast::fold_number(self.discriminant, &|expression| {
|
|
99
|
+
(analysis.expression_id(expression) == Some(self.selector)).then_some(value)
|
|
88
100
|
})?;
|
|
89
|
-
self.labels.iter().position(|&label| label ==
|
|
101
|
+
self.labels.iter().position(|&label| label == selected)
|
|
90
102
|
}
|
|
91
103
|
}
|
|
92
104
|
|
|
93
|
-
///
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
ast::fold_number(&switch.discriminant,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
let labels = switch
|
|
110
|
-
.cases
|
|
111
|
-
.iter()
|
|
112
|
-
.map(|case| ast::fold_number(case.test.as_deref()?, &|_| None))
|
|
113
|
-
.collect::<Option<Vec<_>>>()?;
|
|
114
|
-
let separate = !function.is_async
|
|
115
|
-
&& !function.is_generator
|
|
116
|
-
&& names::mentions(&*switch.discriminant, std::slice::from_ref(&selector))
|
|
117
|
-
&& self.bindings.references(&selector) == 1
|
|
118
|
-
&& !names::uses_arguments(&switch.cases)
|
|
119
|
-
&& switch.cases.iter().all(|case| {
|
|
120
|
-
matches!(case.cons.last(), Some(Stmt::Return(_) | Stmt::Throw(_)))
|
|
121
|
-
&& !escapes(&case.cons)
|
|
122
|
-
})
|
|
123
|
-
&& independent(switch);
|
|
124
|
-
separate.then(|| Selection {
|
|
125
|
-
selector,
|
|
126
|
-
discriminant: (*switch.discriminant).clone(),
|
|
127
|
-
labels,
|
|
128
|
-
})
|
|
105
|
+
/// Recognizes a switch controlled only by the first parameter. Cases must return or throw,
|
|
106
|
+
/// never use the selector or `arguments`, and never refer to declarations from another case.
|
|
107
|
+
fn selection<'a>(function: &'a Function<'a>, analysis: &Analysis<'a>) -> Option<Selection<'a>> {
|
|
108
|
+
let selector = *ast::parameters(function)?.first()?;
|
|
109
|
+
let [Statement::SwitchStatement(switch)] = function.body.as_ref()?.statements.as_slice() else {
|
|
110
|
+
return None;
|
|
111
|
+
};
|
|
112
|
+
let depends_on_selector = |expression: &Expression<'_>| {
|
|
113
|
+
(analysis.expression_id(expression) == Some(selector)).then_some(0.0)
|
|
114
|
+
};
|
|
115
|
+
if function.r#async
|
|
116
|
+
|| function.generator
|
|
117
|
+
|| analysis.bindings.references(&selector) != 1
|
|
118
|
+
|| ast::fold_number(&switch.discriminant, &depends_on_selector).is_none()
|
|
119
|
+
{
|
|
120
|
+
return None;
|
|
129
121
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
122
|
+
let labels: Vec<f64> = switch
|
|
123
|
+
.cases
|
|
124
|
+
.iter()
|
|
125
|
+
.map(|case| ast::fold_number(case.test.as_ref()?, &|_| None))
|
|
126
|
+
.collect::<Option<_>>()?;
|
|
127
|
+
let mut declarations = vec![];
|
|
128
|
+
for case in &switch.cases {
|
|
129
|
+
if !matches!(
|
|
130
|
+
case.consequent.last(),
|
|
131
|
+
Some(Statement::ReturnStatement(_) | Statement::ThrowStatement(_))
|
|
132
|
+
) || ast::escapes(&case.consequent, LabeledContinue::Any)
|
|
136
133
|
{
|
|
137
|
-
|
|
134
|
+
return None;
|
|
135
|
+
}
|
|
136
|
+
let mut declared = Declared::default();
|
|
137
|
+
for statement in &case.consequent {
|
|
138
|
+
declared.visit_statement(statement)
|
|
138
139
|
}
|
|
139
|
-
|
|
140
|
+
if declared.arguments {
|
|
141
|
+
return None;
|
|
142
|
+
}
|
|
143
|
+
declarations.push(declared.ids);
|
|
140
144
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
})
|
|
153
|
-
.collect();
|
|
154
|
-
switch.cases.iter().enumerate().all(|(index, case)| {
|
|
155
|
-
declared
|
|
156
|
-
.iter()
|
|
157
|
-
.enumerate()
|
|
158
|
-
.all(|(other, ids)| other == index || !names::mentions(&case.cons, ids))
|
|
145
|
+
for (index, case) in switch.cases.iter().enumerate() {
|
|
146
|
+
for (other, ids) in declarations.iter().enumerate() {
|
|
147
|
+
if index != other && ast::mentions(&case.consequent, ids, analysis) {
|
|
148
|
+
return None;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
Some(Selection {
|
|
153
|
+
selector,
|
|
154
|
+
discriminant: &switch.discriminant,
|
|
155
|
+
labels,
|
|
159
156
|
})
|
|
160
157
|
}
|
|
161
158
|
|
|
159
|
+
/// Collects a case's bindings, outside nested functions, and whether it mentions `arguments`.
|
|
162
160
|
#[derive(Default)]
|
|
163
|
-
struct
|
|
161
|
+
struct Declared {
|
|
162
|
+
ids: Vec<Id>,
|
|
163
|
+
arguments: bool,
|
|
164
|
+
}
|
|
164
165
|
|
|
165
|
-
impl Visit for
|
|
166
|
-
fn
|
|
167
|
-
|
|
168
|
-
.
|
|
169
|
-
|
|
166
|
+
impl<'a> Visit<'a> for Declared {
|
|
167
|
+
fn visit_binding_identifier(&mut self, binding: &BindingIdentifier<'a>) {
|
|
168
|
+
if let Some(symbol) = binding.symbol_id.get() {
|
|
169
|
+
self.ids.push(Id::Local(symbol))
|
|
170
|
+
}
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
fn
|
|
173
|
-
self.
|
|
174
|
-
declaration.visit_children_with(self);
|
|
173
|
+
fn visit_identifier_reference(&mut self, reference: &IdentifierReference<'a>) {
|
|
174
|
+
self.arguments |= ast::is_arguments(reference);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
fn
|
|
178
|
-
self.0.push(declaration.ident.to_id());
|
|
179
|
-
declaration.visit_children_with(self);
|
|
180
|
-
}
|
|
177
|
+
fn visit_function(&mut self, _: &Function<'a>, _: ScopeFlags) {}
|
|
181
178
|
}
|
|
182
179
|
|
|
183
|
-
/// Finds the cases selected by calls to a merged function. Returns `None` if any reference is not a
|
|
184
|
-
/// direct call with a literal selector that matches a case.
|
|
185
180
|
#[derive(Default)]
|
|
186
181
|
struct Picked {
|
|
187
182
|
calls: usize,
|
|
188
183
|
cases: HashSet<usize>,
|
|
189
184
|
}
|
|
190
185
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
186
|
+
/// Counts the calls of each merged function with a constant selector and the cases they pick.
|
|
187
|
+
struct Calls<'b, 'a> {
|
|
188
|
+
analysis: &'b Analysis<'a>,
|
|
189
|
+
functions: &'b HashMap<Id, Selection<'a>>,
|
|
190
|
+
picked: HashMap<Id, Picked>,
|
|
194
191
|
}
|
|
195
192
|
|
|
196
|
-
|
|
197
|
-
fn
|
|
198
|
-
|
|
199
|
-
let spreads = call.args.iter().any(|argument| argument.spread.is_some());
|
|
200
|
-
let selector = match call.args.first().map(|first| &*first.expr) {
|
|
201
|
-
Some(Expr::Lit(Lit::Num(number))) if !spreads => Some(number.value),
|
|
202
|
-
_ => None,
|
|
203
|
-
};
|
|
204
|
-
Some((callee, selector))
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
impl Visit for Calls<'_> {
|
|
208
|
-
fn visit_call_expr(&mut self, call: &CallExpr) {
|
|
209
|
-
if let Some((id, selector)) = selected_call(call)
|
|
193
|
+
impl<'a> Visit<'a> for Calls<'_, 'a> {
|
|
194
|
+
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
195
|
+
if let Some(id) = self.analysis.expression_id(&call.callee)
|
|
210
196
|
&& let Some(selection) = self.functions.get(&id)
|
|
197
|
+
&& let Some(case) = selection.called_case(call, self.analysis)
|
|
198
|
+
&& !call.optional
|
|
199
|
+
&& !call.arguments.iter().any(Argument::is_spread)
|
|
211
200
|
{
|
|
212
|
-
let
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
.entry(id)
|
|
216
|
-
.or_insert_with(|| Some(Picked::default()));
|
|
217
|
-
match (picked.as_mut(), case) {
|
|
218
|
-
(Some(picked), Some(case)) => {
|
|
219
|
-
picked.calls += 1;
|
|
220
|
-
picked.cases.insert(case);
|
|
221
|
-
}
|
|
222
|
-
_ => *picked = None,
|
|
223
|
-
}
|
|
201
|
+
let picked = self.picked.entry(id).or_default();
|
|
202
|
+
picked.calls += 1;
|
|
203
|
+
picked.cases.insert(case);
|
|
224
204
|
}
|
|
225
|
-
|
|
205
|
+
walk::walk_call_expression(self, call)
|
|
226
206
|
}
|
|
227
207
|
}
|
|
228
208
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
let Some(Stmt::Switch(switch)) = body.stmts.pop() else {
|
|
234
|
-
unreachable!("checked when collected");
|
|
235
|
-
};
|
|
236
|
-
let _selector = function.params.remove(0);
|
|
237
|
-
let mut functions = vec![];
|
|
238
|
-
for (case, name) in switch.cases.into_iter().zip(names) {
|
|
239
|
-
let Some(name) = name else { continue };
|
|
240
|
-
// Give each split function separate parameter bindings.
|
|
241
|
-
let context = SyntaxContext::empty().apply_mark(Mark::new());
|
|
242
|
-
let renamed: HashMap<Id, Ident> = function
|
|
243
|
-
.params
|
|
244
|
-
.iter()
|
|
245
|
-
.filter_map(|parameter| parameter.pat.as_ident())
|
|
246
|
-
.map(|parameter| {
|
|
247
|
-
let fresh = Ident::new(parameter.sym.clone(), parameter.span, context);
|
|
248
|
-
(parameter.to_id(), fresh)
|
|
249
|
-
})
|
|
250
|
-
.collect();
|
|
251
|
-
let mut rename = Rename(&renamed);
|
|
252
|
-
let mut separate = function.clone();
|
|
253
|
-
separate.params.visit_mut_with(&mut rename);
|
|
254
|
-
let mut stmts = case.cons;
|
|
255
|
-
stmts.visit_mut_with(&mut rename);
|
|
256
|
-
separate.body = Some(BlockStmt {
|
|
257
|
-
stmts,
|
|
258
|
-
..body.clone()
|
|
259
|
-
});
|
|
260
|
-
functions.push(Stmt::Decl(Decl::Fn(FnDecl {
|
|
261
|
-
ident: name.clone(),
|
|
262
|
-
declare: false,
|
|
263
|
-
function: separate,
|
|
264
|
-
})));
|
|
265
|
-
}
|
|
266
|
-
functions
|
|
209
|
+
struct Unmerge<'b, 'a> {
|
|
210
|
+
analysis: &'b mut Analysis<'a>,
|
|
211
|
+
functions: &'b HashMap<Id, Selection<'a>>,
|
|
212
|
+
splits: &'b HashMap<Id, Vec<Option<BindingIdentifier<'a>>>>,
|
|
267
213
|
}
|
|
268
214
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
215
|
+
impl<'a> Unmerge<'_, 'a> {
|
|
216
|
+
/// Creates a separate declaration for each selected case, omitting cases with no callers.
|
|
217
|
+
/// Each new function gets its own scope and parameter symbols; references are rebound to those
|
|
218
|
+
/// symbols so later rewrites and hygiene cannot conflate parameters from different cases.
|
|
219
|
+
fn split(
|
|
220
|
+
&mut self,
|
|
221
|
+
mut function: Function<'a>,
|
|
222
|
+
names: &[Option<BindingIdentifier<'a>>],
|
|
223
|
+
) -> ArenaVec<'a, Statement<'a>> {
|
|
224
|
+
let allocator = self.analysis.allocator();
|
|
225
|
+
let mut split = ArenaVec::new_in(&allocator);
|
|
226
|
+
let Some(body) = &mut function.body else {
|
|
227
|
+
return split;
|
|
228
|
+
};
|
|
229
|
+
// The switch moves out, so each copy of the function clones only its own case.
|
|
230
|
+
let statements = body.statements.take_in(&allocator);
|
|
231
|
+
let Some(Statement::SwitchStatement(switch)) = statements.first() else {
|
|
232
|
+
return split;
|
|
233
|
+
};
|
|
234
|
+
let merged_scope = function
|
|
235
|
+
.scope_id
|
|
236
|
+
.get()
|
|
237
|
+
.expect("semantic analysis assigns function scopes");
|
|
238
|
+
let parent = self.analysis.scoping.scope_parent_id(merged_scope);
|
|
239
|
+
for (case, name) in switch.cases.iter().zip(names) {
|
|
240
|
+
let Some(name) = name else { continue };
|
|
241
|
+
let mut separate = function.clone_in_with_semantic_ids(allocator);
|
|
242
|
+
separate.id = Some(name.clone_in_with_semantic_ids(allocator));
|
|
243
|
+
separate.params.items.remove(0);
|
|
244
|
+
let scope =
|
|
245
|
+
self.analysis
|
|
246
|
+
.scoping
|
|
247
|
+
.add_scope(parent, NodeId::DUMMY, ScopeFlags::Function);
|
|
248
|
+
separate.scope_id.set(Some(scope));
|
|
249
|
+
let mut renamed = HashMap::default();
|
|
250
|
+
for parameter in &mut separate.params.items {
|
|
251
|
+
if let Some(binding) = parameter.pattern.get_binding_identifier() {
|
|
252
|
+
let fresh = self.analysis.binding(&binding.name, scope, binding.span);
|
|
253
|
+
renamed.insert(Id::Local(binding.symbol_id()), fresh.symbol_id());
|
|
254
|
+
let fresh = Box::new_in(fresh, &allocator);
|
|
255
|
+
parameter.pattern = BindingPattern::BindingIdentifier(fresh);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
let mut statements = case.consequent.clone_in_with_semantic_ids(allocator);
|
|
259
|
+
let mut rename = Rename {
|
|
260
|
+
analysis: self.analysis,
|
|
261
|
+
renamed: &renamed,
|
|
262
|
+
};
|
|
263
|
+
rename.visit_statements(&mut statements);
|
|
264
|
+
if let Some(body) = &mut separate.body {
|
|
265
|
+
body.statements = statements;
|
|
266
|
+
}
|
|
267
|
+
split.push(Statement::FunctionDeclaration(Box::new_in(
|
|
268
|
+
separate, &allocator,
|
|
269
|
+
)));
|
|
270
|
+
}
|
|
271
|
+
split
|
|
272
|
+
}
|
|
272
273
|
}
|
|
273
274
|
|
|
274
|
-
impl VisitMut for Unmerge<'_> {
|
|
275
|
-
fn
|
|
276
|
-
|
|
277
|
-
let
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
275
|
+
impl<'a> VisitMut<'a> for Unmerge<'_, 'a> {
|
|
276
|
+
fn visit_statements(&mut self, statements: &mut ArenaVec<'a, Statement<'a>>) {
|
|
277
|
+
walk_mut::walk_statements(self, statements);
|
|
278
|
+
let splits = self.splits;
|
|
279
|
+
let mut out = ArenaVec::new_in(&self.analysis.ast);
|
|
280
|
+
for statement in statements.take_in(&self.analysis.ast) {
|
|
281
|
+
let Statement::FunctionDeclaration(function) = statement else {
|
|
282
|
+
out.push(statement);
|
|
283
|
+
continue;
|
|
284
|
+
};
|
|
285
|
+
match ast::function_id(&function).and_then(|id| splits.get(&id)) {
|
|
286
|
+
Some(names) => out.extend(self.split(function.unbox(), names)),
|
|
287
|
+
None => out.push(Statement::FunctionDeclaration(function)),
|
|
287
288
|
}
|
|
288
289
|
}
|
|
289
|
-
*statements =
|
|
290
|
+
*statements = out;
|
|
290
291
|
}
|
|
291
292
|
|
|
292
|
-
fn
|
|
293
|
-
|
|
294
|
-
if let Some(
|
|
293
|
+
fn visit_call_expression(&mut self, call: &mut CallExpression<'a>) {
|
|
294
|
+
walk_mut::walk_call_expression(self, call);
|
|
295
|
+
if let Some(id) = self.analysis.expression_id(&call.callee)
|
|
295
296
|
&& let Some(names) = self.splits.get(&id)
|
|
296
|
-
&& let Some(case) = self.functions[&id].
|
|
297
|
-
&& let Some(
|
|
297
|
+
&& let Some(case) = self.functions[&id].called_case(call, self.analysis)
|
|
298
|
+
&& let Some(name) = &names[case]
|
|
298
299
|
{
|
|
299
|
-
|
|
300
|
-
|
|
300
|
+
let span = call.callee.span();
|
|
301
|
+
let reference = self
|
|
302
|
+
.analysis
|
|
303
|
+
.reference(name.symbol_id(), span, ReferenceFlags::Read);
|
|
304
|
+
call.callee = Expression::Identifier(Box::new_in(reference, &self.analysis.ast));
|
|
305
|
+
call.arguments.remove(0);
|
|
301
306
|
}
|
|
302
307
|
}
|
|
303
308
|
}
|
|
304
309
|
|
|
305
|
-
|
|
310
|
+
/// Rebinds references to the parameters of a split function.
|
|
311
|
+
struct Rename<'b, 'a> {
|
|
312
|
+
analysis: &'b mut Analysis<'a>,
|
|
313
|
+
renamed: &'b HashMap<Id, SymbolId>,
|
|
314
|
+
}
|
|
306
315
|
|
|
307
|
-
impl VisitMut for Rename<'_> {
|
|
308
|
-
fn
|
|
309
|
-
if let Some(
|
|
310
|
-
|
|
316
|
+
impl<'a> VisitMut<'a> for Rename<'_, 'a> {
|
|
317
|
+
fn visit_identifier_reference(&mut self, reference: &mut IdentifierReference<'a>) {
|
|
318
|
+
if let Some(id) = self.analysis.id(reference)
|
|
319
|
+
&& let Some(&renamed) = self.renamed.get(&id)
|
|
320
|
+
{
|
|
321
|
+
// Resolving `id` required a reference ID.
|
|
322
|
+
let flags = self
|
|
323
|
+
.analysis
|
|
324
|
+
.scoping
|
|
325
|
+
.get_reference(reference.reference_id())
|
|
326
|
+
.flags();
|
|
327
|
+
*reference = self.analysis.reference(renamed, reference.span, flags);
|
|
311
328
|
}
|
|
312
329
|
}
|
|
313
330
|
}
|
|
@@ -316,9 +333,35 @@ impl VisitMut for Rename<'_> {
|
|
|
316
333
|
mod tests {
|
|
317
334
|
use crate::deobfuscate::testing;
|
|
318
335
|
|
|
336
|
+
#[test]
|
|
337
|
+
fn splits_cases_with_labeled_jumps_inside_the_handler() {
|
|
338
|
+
let output = testing::rewrite(
|
|
339
|
+
r#"function m(s,a) {
|
|
340
|
+
switch(s^5) {
|
|
341
|
+
case 1: handler: { if(a) break handler; work(a); } return;
|
|
342
|
+
case 2: loop: while(a) { a--; if(a) continue loop; break loop; } return;
|
|
343
|
+
}
|
|
344
|
+
} m(4,x); m(7,y);"#,
|
|
345
|
+
super::run,
|
|
346
|
+
);
|
|
347
|
+
testing::assert_contains(
|
|
348
|
+
&output,
|
|
349
|
+
&[
|
|
350
|
+
"function m_0(a)",
|
|
351
|
+
"function m_1(a)",
|
|
352
|
+
"break handler;",
|
|
353
|
+
"continue loop;",
|
|
354
|
+
"break loop;",
|
|
355
|
+
"m_0(x);",
|
|
356
|
+
"m_1(y);",
|
|
357
|
+
],
|
|
358
|
+
);
|
|
359
|
+
testing::assert_lacks(&output, &["switch"]);
|
|
360
|
+
}
|
|
361
|
+
|
|
319
362
|
#[test]
|
|
320
363
|
fn splits_cases_that_literal_selectors_pick() {
|
|
321
|
-
let transform = |source: &str| testing::rewrite(source, super::run
|
|
364
|
+
let transform = |source: &str| testing::rewrite(source, super::run);
|
|
322
365
|
let merged = "function m(s, a) {
|
|
323
366
|
switch (s ^ 5) {
|
|
324
367
|
case 1: var x = a + 1; return x;
|
|
@@ -329,7 +372,6 @@ mod tests {
|
|
|
329
372
|
let output = transform(&format!("{merged} h(m(4, p), m(7, q), m(4, r));"));
|
|
330
373
|
testing::assert_contains(
|
|
331
374
|
&output,
|
|
332
|
-
&[],
|
|
333
375
|
&[
|
|
334
376
|
"function m_0(a) { var x = a + 1; return x; }",
|
|
335
377
|
"function m_1(a) { g(a); return; }",
|