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
|
@@ -8,294 +8,287 @@
|
|
|
8
8
|
//! conditional values into `if` branches so only the selected expression runs. Runs after
|
|
9
9
|
//! simplification, which could otherwise combine the statements again.
|
|
10
10
|
|
|
11
|
-
use
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
use swc_core::ecma::ast::{
|
|
16
|
-
AssignOp, BinaryOp, CondExpr, Decl, Expr, IfStmt, LabeledStmt, Lit, Program, ReturnStmt, Stmt,
|
|
17
|
-
ThrowStmt, UnaryExpr, UnaryOp, VarDeclKind, VarDeclOrExpr,
|
|
11
|
+
use oxc::allocator::{TakeIn, Vec};
|
|
12
|
+
use oxc::ast::ast::{
|
|
13
|
+
ConditionalExpression, Expression, LabeledStatement, Program, Statement,
|
|
14
|
+
VariableDeclarationKind,
|
|
18
15
|
};
|
|
19
|
-
use
|
|
16
|
+
use oxc::ast_visit::{VisitMut, walk_mut};
|
|
17
|
+
use oxc::span::{GetSpan, SPAN, Span};
|
|
18
|
+
use oxc::syntax::operator::{AssignmentOperator, LogicalOperator, UnaryOperator};
|
|
20
19
|
|
|
21
20
|
use super::analysis::Analysis;
|
|
22
|
-
use
|
|
21
|
+
use super::ast;
|
|
23
22
|
|
|
24
|
-
pub(super) fn run(program: &mut Program
|
|
25
|
-
let mut expand =
|
|
26
|
-
|
|
23
|
+
pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
|
|
24
|
+
let mut expand = Expand {
|
|
25
|
+
analysis,
|
|
26
|
+
changed: false,
|
|
27
|
+
};
|
|
28
|
+
expand.visit_program(program);
|
|
27
29
|
expand.changed
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
struct
|
|
32
|
+
struct Expand<'b, 'a> {
|
|
33
|
+
analysis: &'b Analysis<'a>,
|
|
31
34
|
changed: bool,
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
*statements = expanded;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
fn visit_mut_stmt(&mut self, statement: &mut Stmt) {
|
|
45
|
-
statement.visit_mut_children_with(self);
|
|
46
|
-
let statements = self.expand(statement.take());
|
|
47
|
-
// This position accepts one statement. Wrap multi-statement expansions in a block.
|
|
48
|
-
*statement = match <[Stmt; 1]>::try_from(statements) {
|
|
49
|
-
Ok([single]) => single,
|
|
50
|
-
Err(statements) => ast::block(statements),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
37
|
+
/// The statement that applies to each arm of an expanded conditional.
|
|
38
|
+
enum Arm {
|
|
39
|
+
Expression,
|
|
40
|
+
Return,
|
|
41
|
+
Throw,
|
|
42
|
+
}
|
|
53
43
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
statement.body.visit_mut_children_with(self);
|
|
44
|
+
/// Keeps `name = (effects, function () {})` and equivalent arrow and class sequences intact.
|
|
45
|
+
/// Removing the sequence could give the anonymous value an inferred `.name` it did not have.
|
|
46
|
+
fn anonymous(expression: &Expression<'_>) -> bool {
|
|
47
|
+
match expression.get_inner_expression() {
|
|
48
|
+
Expression::SequenceExpression(sequence) => {
|
|
49
|
+
sequence.expressions.last().is_some_and(anonymous)
|
|
61
50
|
}
|
|
51
|
+
Expression::FunctionExpression(function) => function.id.is_none(),
|
|
52
|
+
Expression::ClassExpression(class) => class.id.is_none(),
|
|
53
|
+
Expression::ArrowFunctionExpression(_) => true,
|
|
54
|
+
_ => false,
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
57
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
58
|
+
impl<'a> Expand<'_, 'a> {
|
|
59
|
+
/// Wraps newly exposed string statements in a block so they cannot become directives.
|
|
60
|
+
fn statement(&self, expression: Expression<'a>) -> Statement<'a> {
|
|
61
|
+
let builder = &self.analysis.ast;
|
|
62
|
+
let span = expression.span();
|
|
63
|
+
let string = matches!(expression, Expression::StringLiteral(_));
|
|
64
|
+
let statement = ast::expression_statement(expression, builder);
|
|
65
|
+
if string {
|
|
66
|
+
Statement::new_block_statement(span, Vec::from_array_in([statement], builder), builder)
|
|
67
|
+
} else {
|
|
68
|
+
statement
|
|
69
|
+
}
|
|
77
70
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
fn is_string_statement(statement: &Stmt) -> bool {
|
|
81
|
-
matches!(
|
|
82
|
-
statement,
|
|
83
|
-
Stmt::Expr(statement) if matches!(&*statement.expr, Expr::Lit(Lit::Str(_)))
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
71
|
|
|
87
|
-
///
|
|
88
|
-
///
|
|
89
|
-
fn
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
72
|
+
/// Moves leading sequence operands into `prefix` as statements and returns the final value.
|
|
73
|
+
/// Callers use this only where lifting operands preserves evaluation order.
|
|
74
|
+
fn split(
|
|
75
|
+
&mut self,
|
|
76
|
+
expression: Expression<'a>,
|
|
77
|
+
prefix: &mut Vec<'a, Statement<'a>>,
|
|
78
|
+
) -> Expression<'a> {
|
|
79
|
+
match expression {
|
|
80
|
+
Expression::ParenthesizedExpression(parenthesized) => {
|
|
81
|
+
self.changed = true;
|
|
82
|
+
self.split(parenthesized.unbox().expression, prefix)
|
|
83
|
+
}
|
|
84
|
+
Expression::SequenceExpression(sequence) => {
|
|
85
|
+
let mut expressions = sequence.unbox().expressions;
|
|
86
|
+
let last = expressions
|
|
87
|
+
.pop()
|
|
88
|
+
.expect("a JavaScript sequence is nonempty");
|
|
89
|
+
self.changed = true;
|
|
90
|
+
for expression in expressions {
|
|
91
|
+
let statement = self.statement(expression);
|
|
92
|
+
prefix.extend(self.expand(statement))
|
|
93
|
+
}
|
|
94
|
+
self.split(last, prefix)
|
|
95
|
+
}
|
|
96
|
+
expression => expression,
|
|
97
|
+
}
|
|
100
98
|
}
|
|
101
|
-
}
|
|
102
99
|
|
|
103
|
-
|
|
104
|
-
/// Applies the same statement to either arm of a conditional value.
|
|
100
|
+
/// Turns a conditional into an `if` statement that applies `arm` to each branch.
|
|
105
101
|
fn conditional(
|
|
106
102
|
&mut self,
|
|
107
|
-
conditional:
|
|
103
|
+
conditional: ConditionalExpression<'a>,
|
|
108
104
|
span: Span,
|
|
109
|
-
|
|
110
|
-
) ->
|
|
105
|
+
arm: Arm,
|
|
106
|
+
) -> Statement<'a> {
|
|
107
|
+
let builder = &self.analysis.ast;
|
|
111
108
|
self.changed = true;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
))
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
/// preserved. Leaves commas in callees, assignment targets, and loop tests or updates in
|
|
124
|
-
/// place.
|
|
125
|
-
fn split_sequence(&mut self, mut expression: Box<Expr>) -> (Vec<Stmt>, Box<Expr>) {
|
|
126
|
-
while let Expr::Paren(paren) = *expression {
|
|
127
|
-
expression = paren.expr;
|
|
128
|
-
self.changed = true;
|
|
129
|
-
}
|
|
130
|
-
if let Expr::Seq(sequence) = &mut *expression
|
|
131
|
-
&& let Some(last) = sequence.exprs.pop()
|
|
132
|
-
{
|
|
133
|
-
self.changed = true;
|
|
134
|
-
let mut prefix = Vec::new();
|
|
135
|
-
for expression in mem::take(&mut sequence.exprs) {
|
|
136
|
-
prefix.extend(self.expand(expression_statement(expression)));
|
|
137
|
-
}
|
|
138
|
-
let (tail_prefix, last) = self.split_sequence(last);
|
|
139
|
-
prefix.extend(tail_prefix);
|
|
140
|
-
(prefix, last)
|
|
141
|
-
} else {
|
|
142
|
-
(vec![], expression)
|
|
143
|
-
}
|
|
109
|
+
let mut branch = |expression| {
|
|
110
|
+
let statement = match arm {
|
|
111
|
+
Arm::Expression => self.statement(expression),
|
|
112
|
+
Arm::Return => Statement::new_return_statement(span, Some(expression), builder),
|
|
113
|
+
Arm::Throw => Statement::new_throw_statement(span, expression, builder),
|
|
114
|
+
};
|
|
115
|
+
Statement::new_block_statement(span, self.expand(statement), builder)
|
|
116
|
+
};
|
|
117
|
+
let consequent = branch(conditional.consequent);
|
|
118
|
+
let alternate = branch(conditional.alternate);
|
|
119
|
+
Statement::new_if_statement(span, conditional.test, consequent, Some(alternate), builder)
|
|
144
120
|
}
|
|
145
121
|
|
|
146
|
-
|
|
147
|
-
|
|
122
|
+
/// Lifts commas and conditional values only at safe statement positions. Member assignment
|
|
123
|
+
/// receivers and keys, compound assignments, callees, loop tests, and loop updates keep their
|
|
124
|
+
/// original evaluation sites. Variable initializers also retain earlier lexical initialization.
|
|
125
|
+
fn expand(&mut self, statement: Statement<'a>) -> Vec<'a, Statement<'a>> {
|
|
126
|
+
let builder = &self.analysis.ast;
|
|
127
|
+
let mut prefix = Vec::new_in(builder);
|
|
148
128
|
let mut statement = match statement {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
&&
|
|
129
|
+
Statement::ExpressionStatement(statement)
|
|
130
|
+
if matches!(statement.expression, Expression::StringLiteral(_)) =>
|
|
131
|
+
{
|
|
132
|
+
return Vec::from_array_in([Statement::ExpressionStatement(statement)], builder);
|
|
133
|
+
}
|
|
134
|
+
Statement::ExpressionStatement(mut statement) => {
|
|
135
|
+
let expression = statement.expression.take_in(builder);
|
|
136
|
+
statement.expression = self.split(expression, &mut prefix);
|
|
137
|
+
if let Expression::AssignmentExpression(assignment) = &mut statement.expression
|
|
138
|
+
&& assignment.operator == AssignmentOperator::Assign
|
|
139
|
+
&& self.analysis.target_id(&assignment.left).is_some()
|
|
140
|
+
&& !anonymous(&assignment.right)
|
|
159
141
|
{
|
|
160
|
-
|
|
161
|
-
prefix.extend(effects);
|
|
162
|
-
assignment.right = value;
|
|
142
|
+
assignment.right = self.split(assignment.right.take_in(builder), &mut prefix);
|
|
163
143
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
144
|
+
let span = statement.span;
|
|
145
|
+
match statement.unbox().expression {
|
|
146
|
+
Expression::ConditionalExpression(conditional) => {
|
|
147
|
+
self.conditional(conditional.unbox(), span, Arm::Expression)
|
|
167
148
|
}
|
|
168
|
-
|
|
169
|
-
if
|
|
149
|
+
Expression::LogicalExpression(logical)
|
|
150
|
+
if logical.operator != LogicalOperator::Coalesce =>
|
|
170
151
|
{
|
|
171
152
|
self.changed = true;
|
|
172
|
-
let
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
153
|
+
let logical = logical.unbox();
|
|
154
|
+
let test = match logical.operator {
|
|
155
|
+
LogicalOperator::Or => Expression::new_unary_expression(
|
|
156
|
+
logical.span,
|
|
157
|
+
UnaryOperator::LogicalNot,
|
|
158
|
+
logical.left,
|
|
159
|
+
builder,
|
|
160
|
+
),
|
|
161
|
+
_ => logical.left,
|
|
180
162
|
};
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
cons: Box::new(ast::block(
|
|
185
|
-
self.expand(expression_statement(binary.right)),
|
|
186
|
-
)),
|
|
187
|
-
alt: None,
|
|
188
|
-
})
|
|
189
|
-
}
|
|
190
|
-
// Splitting or removing parentheses can expose a string.
|
|
191
|
-
expression => {
|
|
192
|
-
statement.expr = Box::new(expression);
|
|
193
|
-
guard_directive(Stmt::Expr(statement))
|
|
163
|
+
let body = self.statement(logical.right);
|
|
164
|
+
let body = Statement::new_block_statement(span, self.expand(body), builder);
|
|
165
|
+
Statement::new_if_statement(span, test, body, None, builder)
|
|
194
166
|
}
|
|
167
|
+
expression => self.statement(expression),
|
|
195
168
|
}
|
|
196
169
|
}
|
|
197
|
-
|
|
198
|
-
let
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
prefix = effects;
|
|
203
|
-
match *argument {
|
|
204
|
-
Expr::Cond(conditional) => {
|
|
205
|
-
self.conditional(conditional, statement.span, |arg| {
|
|
206
|
-
Stmt::Return(ReturnStmt {
|
|
207
|
-
span: statement.span,
|
|
208
|
-
arg: Some(arg),
|
|
209
|
-
})
|
|
210
|
-
})
|
|
170
|
+
Statement::ReturnStatement(mut statement) => {
|
|
171
|
+
let argument = statement.argument.take();
|
|
172
|
+
match argument.map(|argument| self.split(argument, &mut prefix)) {
|
|
173
|
+
Some(Expression::ConditionalExpression(conditional)) => {
|
|
174
|
+
self.conditional(conditional.unbox(), statement.span, Arm::Return)
|
|
211
175
|
}
|
|
212
|
-
|
|
176
|
+
Some(Expression::UnaryExpression(unary))
|
|
177
|
+
if unary.operator == UnaryOperator::Void =>
|
|
178
|
+
{
|
|
213
179
|
self.changed = true;
|
|
214
|
-
|
|
215
|
-
|
|
180
|
+
let effect = self.statement(unary.unbox().argument);
|
|
181
|
+
prefix.extend(self.expand(effect));
|
|
182
|
+
Statement::ReturnStatement(statement)
|
|
216
183
|
}
|
|
217
184
|
argument => {
|
|
218
|
-
statement.
|
|
219
|
-
|
|
185
|
+
statement.argument = argument;
|
|
186
|
+
Statement::ReturnStatement(statement)
|
|
220
187
|
}
|
|
221
188
|
}
|
|
222
189
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
} else {
|
|
233
|
-
Stmt::Throw(statement)
|
|
190
|
+
Statement::ThrowStatement(mut statement) => {
|
|
191
|
+
match self.split(statement.argument.take_in(builder), &mut prefix) {
|
|
192
|
+
Expression::ConditionalExpression(conditional) => {
|
|
193
|
+
self.conditional(conditional.unbox(), statement.span, Arm::Throw)
|
|
194
|
+
}
|
|
195
|
+
argument => {
|
|
196
|
+
statement.argument = argument;
|
|
197
|
+
Statement::ThrowStatement(statement)
|
|
198
|
+
}
|
|
234
199
|
}
|
|
235
200
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
201
|
+
Statement::SwitchStatement(mut statement) => {
|
|
202
|
+
let discriminant = statement.discriminant.take_in(builder);
|
|
203
|
+
statement.discriminant = self.split(discriminant, &mut prefix);
|
|
204
|
+
Statement::SwitchStatement(statement)
|
|
239
205
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
Stmt::Decl(Decl::Var(mut declaration)) => {
|
|
245
|
-
let storing = match declaration.kind {
|
|
246
|
-
VarDeclKind::Var => declaration
|
|
247
|
-
.decls
|
|
206
|
+
Statement::VariableDeclaration(mut declaration) => {
|
|
207
|
+
let first = match declaration.kind {
|
|
208
|
+
VariableDeclarationKind::Var => declaration
|
|
209
|
+
.declarations
|
|
248
210
|
.iter()
|
|
249
211
|
.position(|declarator| declarator.init.is_some()),
|
|
250
|
-
|
|
212
|
+
_ => Some(0),
|
|
251
213
|
};
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
&& !
|
|
214
|
+
let declarations = &mut declaration.declarations;
|
|
215
|
+
if let Some(declarator) = first.and_then(|first| declarations.get_mut(first))
|
|
216
|
+
&& let Some(init) = declarator.init.take_if(|init| !anonymous(init))
|
|
255
217
|
{
|
|
256
|
-
|
|
218
|
+
declarator.init = Some(self.split(init, &mut prefix))
|
|
257
219
|
}
|
|
258
|
-
|
|
220
|
+
Statement::VariableDeclaration(declaration)
|
|
259
221
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
initializer => initializer,
|
|
268
|
-
};
|
|
269
|
-
Stmt::For(statement)
|
|
222
|
+
Statement::ForStatement(mut statement) => {
|
|
223
|
+
if let Some(init) = statement.init.take_if(|init| init.is_expression()) {
|
|
224
|
+
let init = self.statement(init.into_expression());
|
|
225
|
+
prefix.extend(self.expand(init));
|
|
226
|
+
self.changed = true
|
|
227
|
+
}
|
|
228
|
+
Statement::ForStatement(statement)
|
|
270
229
|
}
|
|
271
230
|
statement => statement,
|
|
272
231
|
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
let (effects, test) = self.split_sequence(conditional.test.take());
|
|
276
|
-
prefix.extend(effects);
|
|
277
|
-
conditional.test = test;
|
|
232
|
+
if let Statement::IfStatement(statement) = &mut statement {
|
|
233
|
+
statement.test = self.split(statement.test.take_in(builder), &mut prefix)
|
|
278
234
|
}
|
|
279
235
|
prefix.push(statement);
|
|
280
236
|
prefix
|
|
281
237
|
}
|
|
282
238
|
}
|
|
283
239
|
|
|
240
|
+
impl<'a> VisitMut<'a> for Expand<'_, 'a> {
|
|
241
|
+
fn visit_statements(&mut self, statements: &mut Vec<'a, Statement<'a>>) {
|
|
242
|
+
let mut expanded = Vec::new_in(&self.analysis.ast);
|
|
243
|
+
for mut statement in statements.take_in(&self.analysis.ast) {
|
|
244
|
+
walk_mut::walk_statement(self, &mut statement);
|
|
245
|
+
expanded.extend(self.expand(statement));
|
|
246
|
+
}
|
|
247
|
+
*statements = expanded;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
fn visit_statement(&mut self, statement: &mut Statement<'a>) {
|
|
251
|
+
walk_mut::walk_statement(self, statement);
|
|
252
|
+
let builder = &self.analysis.ast;
|
|
253
|
+
let mut expanded = self.expand(statement.take_in(builder));
|
|
254
|
+
*statement = if expanded.len() == 1 {
|
|
255
|
+
expanded.pop().expect("one statement")
|
|
256
|
+
} else {
|
|
257
|
+
Statement::new_block_statement(SPAN, expanded, builder)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/// Keeps a labeled loop directly under its label, so lifted statements cannot break
|
|
262
|
+
/// `continue label`.
|
|
263
|
+
fn visit_labeled_statement(&mut self, statement: &mut LabeledStatement<'a>) {
|
|
264
|
+
if let Statement::LabeledStatement(nested) = &mut statement.body {
|
|
265
|
+
self.visit_labeled_statement(nested)
|
|
266
|
+
} else {
|
|
267
|
+
walk_mut::walk_statement(self, &mut statement.body)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
284
272
|
#[cfg(test)]
|
|
285
273
|
mod tests {
|
|
286
274
|
use crate::deobfuscate::testing;
|
|
287
275
|
|
|
288
276
|
#[test]
|
|
289
277
|
fn expands_sequences_conditionals_and_void_returns() {
|
|
290
|
-
let transform = |source: &str| testing::rewrite(source, super::run
|
|
278
|
+
let transform = |source: &str| testing::rewrite(source, super::run);
|
|
291
279
|
let output = transform(
|
|
292
280
|
"function f(flag) { first(), second(); flag && (third(), fourth()); \
|
|
293
281
|
flag || fallback(); return before(), flag ? (yes(), result()) : void no(); }",
|
|
294
282
|
);
|
|
295
283
|
testing::assert_contains(
|
|
296
284
|
&output,
|
|
297
|
-
&[
|
|
298
|
-
|
|
285
|
+
&[
|
|
286
|
+
"if (flag)",
|
|
287
|
+
"if (!flag)",
|
|
288
|
+
"return result();",
|
|
289
|
+
"first(); second();",
|
|
290
|
+
"no(); return;",
|
|
291
|
+
],
|
|
299
292
|
);
|
|
300
293
|
testing::assert_lacks(&output, &["&&", " ? "]);
|
|
301
294
|
let output = transform(
|
|
@@ -305,13 +298,17 @@ mod tests {
|
|
|
305
298
|
);
|
|
306
299
|
testing::assert_contains(
|
|
307
300
|
&output,
|
|
308
|
-
&[
|
|
309
|
-
|
|
301
|
+
&[
|
|
302
|
+
"throw one;",
|
|
303
|
+
"throw two;",
|
|
304
|
+
"before(); if (flag)",
|
|
305
|
+
"select(); switch(flag)",
|
|
306
|
+
],
|
|
310
307
|
);
|
|
311
308
|
assert!(!output.contains("throw prepare()"), "{output}");
|
|
312
309
|
// A single-statement body expands without changing which `if` an `else` binds to.
|
|
313
310
|
let output = transform("function f(a, b) { if (a) b ? yes() : no(); else other(); }");
|
|
314
|
-
testing::assert_contains(&output, &["if (a)", "if (b)"]
|
|
311
|
+
testing::assert_contains(&output, &["if (a)", "if (b)"]);
|
|
315
312
|
assert_eq!(output.matches("else").count(), 2, "{output}");
|
|
316
313
|
assert!(!output.contains('?'), "{output}");
|
|
317
314
|
assert_eq!(transform(&output), output);
|
|
@@ -319,7 +316,7 @@ mod tests {
|
|
|
319
316
|
|
|
320
317
|
#[test]
|
|
321
318
|
fn preserves_evaluation_order_frequency_labels_and_references() {
|
|
322
|
-
let transform = |source: &str| testing::rewrite(source, super::run
|
|
319
|
+
let transform = |source: &str| testing::rewrite(source, super::run);
|
|
323
320
|
// Only sequences assigned to identifiers are lifted out of assignments.
|
|
324
321
|
let output = transform(
|
|
325
322
|
"function f(a, b, obj) { a = (b = obj.x, first(), b + 1); \
|
|
@@ -334,8 +331,6 @@ mod tests {
|
|
|
334
331
|
"obj[key()] = (effect(), value)",
|
|
335
332
|
"obj.y = (effect(), value)",
|
|
336
333
|
"a += (effect(), 1)",
|
|
337
|
-
],
|
|
338
|
-
&[
|
|
339
334
|
"effect(); a = function named() {}",
|
|
340
335
|
"b = obj.x; first(); a = b + 1;",
|
|
341
336
|
],
|
|
@@ -347,8 +342,11 @@ mod tests {
|
|
|
347
342
|
);
|
|
348
343
|
testing::assert_contains(
|
|
349
344
|
&output,
|
|
350
|
-
&[
|
|
351
|
-
|
|
345
|
+
&[
|
|
346
|
+
"w = (third(), more)",
|
|
347
|
+
"g = (effect(), function() {})",
|
|
348
|
+
"first(); if (flag) { second(); } var v = value",
|
|
349
|
+
],
|
|
352
350
|
);
|
|
353
351
|
// Earlier uninitialized `var` declarations have no effect.
|
|
354
352
|
let output = transform(
|
|
@@ -356,8 +354,10 @@ mod tests {
|
|
|
356
354
|
);
|
|
357
355
|
testing::assert_contains(
|
|
358
356
|
&output,
|
|
359
|
-
&[
|
|
360
|
-
|
|
357
|
+
&[
|
|
358
|
+
"d = (c = second(), other)",
|
|
359
|
+
"a = first(); var a, b = value;",
|
|
360
|
+
],
|
|
361
361
|
);
|
|
362
362
|
let output = transform(
|
|
363
363
|
"function f() { for (start(), setup(); test(), ready; tick(), step()) body(); \
|
|
@@ -374,8 +374,8 @@ mod tests {
|
|
|
374
374
|
"for(let i = 0;",
|
|
375
375
|
"while(poll(), ready)",
|
|
376
376
|
"while (poll(), ready)",
|
|
377
|
+
"start(); setup();",
|
|
377
378
|
],
|
|
378
|
-
&["start(); setup();"],
|
|
379
379
|
);
|
|
380
380
|
let output = transform(
|
|
381
381
|
r#"function f() { (0, obj.method)(); (0, eval)("x");
|
|
@@ -387,6 +387,6 @@ mod tests {
|
|
|
387
387
|
"consume(first(), (second(), third()))",
|
|
388
388
|
"return left && right;",
|
|
389
389
|
];
|
|
390
|
-
testing::assert_contains(&output, &expected
|
|
390
|
+
testing::assert_contains(&output, &expected);
|
|
391
391
|
}
|
|
392
392
|
}
|