cfsolve 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- 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 +7 -5
- 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/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/vendor/cfsolve/Cargo.lock +561 -1729
- data/vendor/cfsolve/Cargo.toml +26 -8
- data/vendor/cfsolve/README.md +4 -0
- 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/vm_snapshot.rs +32 -33
- 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 +23 -18
- 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 +5 -5
- 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/audit.rs +4 -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 +62 -31
- data/vendor/cfsolve/src/stage2/call_stack.rs +1415 -1025
- data/vendor/cfsolve/src/stage2/challenge_page.rs +3 -2
- 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/performance.rs +12 -8
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +134 -108
- data/vendor/cfsolve/src/stage2/vocabulary.rs +1 -11
- data/vendor/cfsolve/src/stage2.rs +2 -0
- data/vendor/cfsolve/src/vm/disassemble.rs +7 -3
- data/vendor/cfsolve/src/vm/dispatch.rs +93 -65
- data/vendor/cfsolve/src/vm/extract.rs +347 -250
- data/vendor/cfsolve/src/vm/interpret/access.rs +63 -48
- 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 +123 -59
- 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 +1736 -0
- data/vendor/cfsolve/src/vm/interpret/plan.rs +586 -338
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +116 -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 +56 -49
- data/vendor/cfsolve/src/vm/output.rs +13 -5
- data/vendor/cfsolve/src/vm/packed_names.rs +11 -7
- data/vendor/cfsolve/src/vm/session.rs +185 -120
- data/vendor/cfsolve/src/vm/value.rs +22 -19
- data/vendor/cfsolve/src/vm.rs +2 -1
- data/vendor/cfsolve/vendor/btls-sys/Cargo.toml +3 -0
- data/vendor/cfsolve/vendor/btls-sys/build/main.rs +20 -0
- metadata +94 -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
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//! Visits the parts of statements and expressions that always run with them, in order, so a pass
|
|
2
|
+
//! can learn facts from assignments and declarations that hold once those parts have run.
|
|
3
|
+
//!
|
|
4
|
+
//! Always running are: a statement's expression, the argument of `return` and `throw`, an `if`
|
|
5
|
+
//! test, a `switch` discriminant, and variable initializers; within those, every operand of a
|
|
6
|
+
//! sequence, the left operand of `&&`, `||` and `??`, and both sides of an assignment. Every
|
|
7
|
+
//! other part is visited normally, so facts learned in a conditional part do not escape it.
|
|
8
|
+
|
|
9
|
+
use oxc::ast::ast::{AssignmentExpression, Expression, Statement, VariableDeclarator};
|
|
10
|
+
use oxc::ast_visit::VisitMut;
|
|
11
|
+
|
|
12
|
+
pub(in crate::deobfuscate) trait Unconditional<'a>: VisitMut<'a> {
|
|
13
|
+
/// Called once `assignment`, which always runs, has run.
|
|
14
|
+
fn assigned(&mut self, assignment: &AssignmentExpression<'a>);
|
|
15
|
+
|
|
16
|
+
/// Called once the initializer of `declarator`, which always runs, has run.
|
|
17
|
+
fn declared(&mut self, declarator: &VariableDeclarator<'a>);
|
|
18
|
+
|
|
19
|
+
fn unconditional_expression(&mut self, expression: &mut Expression<'a>) {
|
|
20
|
+
match expression {
|
|
21
|
+
Expression::ParenthesizedExpression(parenthesized) => {
|
|
22
|
+
self.unconditional_expression(&mut parenthesized.expression)
|
|
23
|
+
}
|
|
24
|
+
Expression::SequenceExpression(sequence) => {
|
|
25
|
+
for expression in &mut sequence.expressions {
|
|
26
|
+
self.unconditional_expression(expression)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
Expression::LogicalExpression(logical) => {
|
|
30
|
+
self.unconditional_expression(&mut logical.left);
|
|
31
|
+
self.visit_expression(&mut logical.right)
|
|
32
|
+
}
|
|
33
|
+
Expression::AssignmentExpression(assignment) => {
|
|
34
|
+
self.visit_assignment_target(&mut assignment.left);
|
|
35
|
+
self.unconditional_expression(&mut assignment.right);
|
|
36
|
+
self.assigned(assignment)
|
|
37
|
+
}
|
|
38
|
+
expression => self.visit_expression(expression),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fn unconditional_statement(&mut self, statement: &mut Statement<'a>) {
|
|
43
|
+
match statement {
|
|
44
|
+
Statement::ExpressionStatement(statement) => {
|
|
45
|
+
self.unconditional_expression(&mut statement.expression)
|
|
46
|
+
}
|
|
47
|
+
Statement::ReturnStatement(statement) => {
|
|
48
|
+
if let Some(argument) = &mut statement.argument {
|
|
49
|
+
self.unconditional_expression(argument)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
Statement::ThrowStatement(statement) => {
|
|
53
|
+
self.unconditional_expression(&mut statement.argument)
|
|
54
|
+
}
|
|
55
|
+
Statement::IfStatement(branch) => {
|
|
56
|
+
self.unconditional_expression(&mut branch.test);
|
|
57
|
+
self.visit_statement(&mut branch.consequent);
|
|
58
|
+
if let Some(alternate) = &mut branch.alternate {
|
|
59
|
+
self.visit_statement(alternate)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
Statement::SwitchStatement(switch) => {
|
|
63
|
+
self.unconditional_expression(&mut switch.discriminant);
|
|
64
|
+
for case in &mut switch.cases {
|
|
65
|
+
self.visit_switch_case(case)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
Statement::VariableDeclaration(declaration) => {
|
|
69
|
+
for declarator in &mut declaration.declarations {
|
|
70
|
+
if let Some(value) = &mut declarator.init {
|
|
71
|
+
self.unconditional_expression(value);
|
|
72
|
+
self.declared(declarator)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
statement => self.visit_statement(statement),
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -1,62 +1,280 @@
|
|
|
1
1
|
//! Shared conservative analysis for deobfuscation rewrites.
|
|
2
2
|
//!
|
|
3
|
-
//!
|
|
4
|
-
//!
|
|
5
|
-
//!
|
|
3
|
+
//! Oxc resolves the original program once, and moved references keep those binding identities
|
|
4
|
+
//! until final hygiene. Read and write counts are recollected from the current tree after each
|
|
5
|
+
//! change.
|
|
6
6
|
|
|
7
|
-
use
|
|
8
|
-
use
|
|
7
|
+
use oxc::allocator::{Allocator, CloneIn, GetAllocator};
|
|
8
|
+
use oxc::ast::ast::{
|
|
9
|
+
AssignmentTarget, BindingIdentifier, Expression, IdentifierReference, Program,
|
|
10
|
+
};
|
|
11
|
+
use oxc::ast::builder::{AstBuilder, GetAstBuilder};
|
|
12
|
+
use oxc::semantic::Scoping;
|
|
13
|
+
use oxc::span::{SPAN, Span};
|
|
14
|
+
use oxc::str::Ident;
|
|
15
|
+
use oxc::syntax::node::NodeId;
|
|
16
|
+
use oxc::syntax::operator::{AssignmentOperator, UnaryOperator};
|
|
17
|
+
use oxc::syntax::reference::{Reference, ReferenceFlags, ReferenceId};
|
|
18
|
+
use oxc::syntax::scope::ScopeId;
|
|
19
|
+
use oxc::syntax::symbol::{SymbolFlags, SymbolId};
|
|
20
|
+
use oxc_ecmascript::GlobalContext;
|
|
21
|
+
use oxc_ecmascript::constant_evaluation::ConstantEvaluationCtx;
|
|
22
|
+
use oxc_ecmascript::side_effects::{
|
|
23
|
+
MayHaveSideEffects, MayHaveSideEffectsContext, PropertyReadSideEffects,
|
|
24
|
+
};
|
|
9
25
|
|
|
10
26
|
mod bindings;
|
|
11
27
|
pub(super) mod effects;
|
|
12
|
-
mod globals;
|
|
13
28
|
pub(super) mod hoisting;
|
|
14
|
-
pub(super) mod
|
|
15
|
-
mod
|
|
29
|
+
pub(super) mod properties;
|
|
30
|
+
pub(super) mod unconditional;
|
|
16
31
|
|
|
17
|
-
|
|
18
|
-
pub(super) use globals::Globals;
|
|
19
|
-
pub(super) use properties::{Properties, constant_index, member_key, prop_key};
|
|
32
|
+
use bindings::Bindings;
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
use super::ast;
|
|
35
|
+
|
|
36
|
+
/// A binding identity. Unresolved globals use the first reference to their spelling, which lets
|
|
37
|
+
/// helpers assigned to globals participate without inventing symbols.
|
|
38
|
+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
|
39
|
+
pub(super) enum Id {
|
|
40
|
+
Local(SymbolId),
|
|
41
|
+
Global(ReferenceId),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
impl Id {
|
|
45
|
+
fn of(reference: &IdentifierReference<'_>, scoping: &Scoping) -> Option<Self> {
|
|
46
|
+
let resolved = scoping.get_reference(reference.reference_id.get()?);
|
|
47
|
+
match resolved.symbol_id() {
|
|
48
|
+
Some(symbol) => Some(Self::Local(symbol)),
|
|
49
|
+
None => {
|
|
50
|
+
let globals = scoping.root_unresolved_references().get(&reference.name)?;
|
|
51
|
+
globals.first().copied().map(Self::Global)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub(super) fn local(self) -> Option<SymbolId> {
|
|
57
|
+
match self {
|
|
58
|
+
Self::Local(symbol) => Some(symbol),
|
|
59
|
+
Self::Global(_) => None,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
pub(super) fn is_global(self) -> bool {
|
|
64
|
+
matches!(self, Self::Global(_))
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// The program's resolved scoping and the binding uses of its current tree.
|
|
69
|
+
pub(super) struct Analysis<'a> {
|
|
70
|
+
pub ast: AstBuilder<'a>,
|
|
71
|
+
pub scoping: Scoping,
|
|
72
|
+
pub bindings: Bindings,
|
|
28
73
|
}
|
|
29
74
|
|
|
30
|
-
impl Analysis {
|
|
31
|
-
|
|
32
|
-
pub(crate) fn new(unresolved_mark: Mark) -> Self {
|
|
75
|
+
impl<'a> Analysis<'a> {
|
|
76
|
+
pub(super) fn new(allocator: &'a Allocator, scoping: Scoping) -> Self {
|
|
33
77
|
Self {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
78
|
+
ast: AstBuilder::new(allocator),
|
|
79
|
+
scoping,
|
|
80
|
+
bindings: Bindings::default(),
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
pub(super) fn id(&self, reference: &IdentifierReference<'_>) -> Option<Id> {
|
|
85
|
+
Id::of(reference, &self.scoping)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
pub(super) fn expression_id(&self, expression: &Expression<'_>) -> Option<Id> {
|
|
89
|
+
self.id(expression.get_identifier_reference()?)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
pub(super) fn target_id(&self, target: &AssignmentTarget<'_>) -> Option<Id> {
|
|
93
|
+
match target {
|
|
94
|
+
AssignmentTarget::AssignmentTargetIdentifier(reference) => self.id(reference),
|
|
95
|
+
_ => None,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// Matches a plain `binding = value` assignment.
|
|
100
|
+
pub(super) fn assignment<'b>(
|
|
101
|
+
&self,
|
|
102
|
+
expression: &'b Expression<'a>,
|
|
103
|
+
) -> Option<(Id, &'b Expression<'a>)> {
|
|
104
|
+
let Expression::AssignmentExpression(assignment) = expression.get_inner_expression() else {
|
|
105
|
+
return None;
|
|
106
|
+
};
|
|
107
|
+
if assignment.operator != AssignmentOperator::Assign {
|
|
108
|
+
return None;
|
|
109
|
+
}
|
|
110
|
+
Some((self.target_id(&assignment.left)?, &assignment.right))
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// Checks for a reference to the global `name`, which no local binding shadows.
|
|
114
|
+
pub(super) fn is_global(&self, reference: &IdentifierReference<'_>, name: &str) -> bool {
|
|
115
|
+
reference.name == name && self.id(reference).is_none_or(Id::is_global)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Checks for global `undefined`, or `void` of an operand without side effects, so dropping,
|
|
119
|
+
/// repeating, or moving the expression cannot be observed.
|
|
120
|
+
pub(super) fn is_undefined(&self, expression: &Expression<'_>) -> bool {
|
|
121
|
+
match expression {
|
|
122
|
+
Expression::Identifier(identifier) => self.is_global(identifier, "undefined"),
|
|
123
|
+
Expression::UnaryExpression(unary) => {
|
|
124
|
+
unary.operator == UnaryOperator::Void
|
|
125
|
+
&& (ast::fold_number(&unary.argument, &|_| None).is_some()
|
|
126
|
+
|| !unary.argument.may_have_side_effects(self))
|
|
127
|
+
}
|
|
128
|
+
_ => false,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
pub(super) fn scope(&self, id: Id) -> ScopeId {
|
|
133
|
+
match id {
|
|
134
|
+
Id::Local(symbol) => self.scoping.symbol_scope_id(symbol),
|
|
135
|
+
Id::Global(_) => self.scoping.root_scope_id(),
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
pub(super) fn name(&self, id: Id) -> &str {
|
|
140
|
+
match id {
|
|
141
|
+
Id::Local(symbol) => self.scoping.symbol_name(symbol),
|
|
142
|
+
Id::Global(reference) => {
|
|
143
|
+
let mut globals = self.scoping.root_unresolved_references().iter();
|
|
144
|
+
let (name, _) = globals
|
|
145
|
+
.find(|(_, references)| references.first() == Some(&reference))
|
|
146
|
+
.expect("a global identity is the first reference to its name");
|
|
147
|
+
name.as_str()
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
pub(super) fn span(&self, id: Id) -> Span {
|
|
153
|
+
match id {
|
|
154
|
+
Id::Local(symbol) => self.scoping.symbol_span(symbol),
|
|
155
|
+
Id::Global(_) => SPAN,
|
|
37
156
|
}
|
|
38
157
|
}
|
|
39
158
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
159
|
+
/// Copies `node` into the arena so later tree mutations cannot change it. Semantic IDs are
|
|
160
|
+
/// kept because references must retain their original binding identities.
|
|
161
|
+
pub(super) fn save<T: CloneIn<'a, Cloned = T>>(&self, node: &T) -> &'a T {
|
|
162
|
+
let allocator = self.allocator();
|
|
163
|
+
allocator.alloc(node.clone_in_with_semantic_ids(allocator))
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/// Recollects uses from the rewritten tree while keeping the original binding identities.
|
|
167
|
+
pub(super) fn refresh(&mut self, program: &Program<'a>) {
|
|
168
|
+
self.bindings = Bindings::collect(program, &self.scoping)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/// Checks whether a symbol or an unresolved global already uses `name`.
|
|
172
|
+
fn is_name_taken(&self, name: &str) -> bool {
|
|
173
|
+
self.scoping
|
|
174
|
+
.symbol_ids()
|
|
175
|
+
.any(|symbol| self.scoping.symbol_name(symbol) == name)
|
|
176
|
+
|| self.scoping.root_unresolved_references().contains_key(name)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/// Returns the first of `base_1`, `base_2`, and so on that no symbol or global uses.
|
|
180
|
+
pub(super) fn suffixed_name(&self, base: &str) -> String {
|
|
181
|
+
let mut names = (1..).map(|suffix| format!("{base}_{suffix}"));
|
|
182
|
+
names
|
|
183
|
+
.find(|name| !self.is_name_taken(name))
|
|
184
|
+
.expect("the suffixes are unbounded")
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/// Creates a local named `base`, or `base_1`, `base_2`, and so on if that name is taken.
|
|
188
|
+
pub(super) fn fresh_binding(
|
|
189
|
+
&mut self,
|
|
190
|
+
base: &str,
|
|
191
|
+
scope: ScopeId,
|
|
192
|
+
span: Span,
|
|
193
|
+
) -> BindingIdentifier<'a> {
|
|
194
|
+
let name = if self.is_name_taken(base) {
|
|
195
|
+
self.suffixed_name(base)
|
|
196
|
+
} else {
|
|
197
|
+
base.to_owned()
|
|
198
|
+
};
|
|
199
|
+
self.binding(&name, scope, span)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/// Creates a new symbol, which may reuse the spelling of another binding.
|
|
203
|
+
pub(super) fn binding(
|
|
204
|
+
&mut self,
|
|
205
|
+
name: &str,
|
|
206
|
+
scope: ScopeId,
|
|
207
|
+
span: Span,
|
|
208
|
+
) -> BindingIdentifier<'a> {
|
|
209
|
+
let name = Ident::from_str_in(name, &self.ast);
|
|
210
|
+
let symbol = self.scoping.create_symbol(
|
|
211
|
+
span,
|
|
212
|
+
name,
|
|
213
|
+
SymbolFlags::FunctionScopedVariable,
|
|
214
|
+
scope,
|
|
215
|
+
NodeId::DUMMY,
|
|
216
|
+
);
|
|
217
|
+
self.scoping.add_binding(scope, name, symbol);
|
|
218
|
+
BindingIdentifier::new_with_symbol_id(span, name, symbol, &self.ast)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/// Creates a reference to a local and records its read and write flags in the scoping.
|
|
222
|
+
pub(super) fn reference(
|
|
223
|
+
&mut self,
|
|
224
|
+
symbol: SymbolId,
|
|
225
|
+
span: Span,
|
|
226
|
+
flags: ReferenceFlags,
|
|
227
|
+
) -> IdentifierReference<'a> {
|
|
228
|
+
let scope = self.scoping.symbol_scope_id(symbol);
|
|
229
|
+
let name = Ident::from_str_in(self.scoping.symbol_name(symbol), &self.ast);
|
|
230
|
+
let reference = self.scoping.create_reference(Reference::new_with_symbol_id(
|
|
231
|
+
NodeId::DUMMY,
|
|
232
|
+
symbol,
|
|
233
|
+
scope,
|
|
234
|
+
flags,
|
|
235
|
+
));
|
|
236
|
+
self.scoping.add_resolved_reference(symbol, reference);
|
|
237
|
+
IdentifierReference::new_with_reference_id(span, name, reference, &self.ast)
|
|
44
238
|
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
impl<'a> GetAllocator<'a> for Analysis<'a> {
|
|
242
|
+
fn allocator(&self) -> &'a Allocator {
|
|
243
|
+
self.ast.allocator()
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
impl<'a> GetAstBuilder<'a> for Analysis<'a> {
|
|
248
|
+
type Builder = AstBuilder<'a>;
|
|
249
|
+
|
|
250
|
+
fn builder(&self) -> &Self::Builder {
|
|
251
|
+
&self.ast
|
|
252
|
+
}
|
|
253
|
+
}
|
|
45
254
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
255
|
+
impl<'a> GlobalContext<'a> for Analysis<'a> {
|
|
256
|
+
fn is_global_reference(&self, reference: &IdentifierReference<'a>) -> bool {
|
|
257
|
+
self.id(reference).is_none_or(Id::is_global)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/// Unknown globals and property reads may have effects; purity annotations are not trusted.
|
|
262
|
+
impl<'a> MayHaveSideEffectsContext<'a> for Analysis<'a> {
|
|
263
|
+
fn annotations(&self) -> bool {
|
|
264
|
+
false
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
fn manual_pure_functions(&self, _: &Expression<'_>) -> bool {
|
|
268
|
+
false
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
fn property_read_side_effects(&self) -> PropertyReadSideEffects {
|
|
272
|
+
PropertyReadSideEffects::All
|
|
56
273
|
}
|
|
57
274
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
self.properties = None;
|
|
275
|
+
fn unknown_global_side_effects(&self) -> bool {
|
|
276
|
+
true
|
|
61
277
|
}
|
|
62
278
|
}
|
|
279
|
+
|
|
280
|
+
impl<'a> ConstantEvaluationCtx<'a> for Analysis<'a> {}
|
|
@@ -5,100 +5,97 @@
|
|
|
5
5
|
//! ```
|
|
6
6
|
//!
|
|
7
7
|
//! Requires a single array assignment and reads at constant indices only (see
|
|
8
|
-
//! [`Properties`]
|
|
9
|
-
//!
|
|
10
|
-
//! or invoke getters.
|
|
8
|
+
//! [`Properties::only_indexed`]). Elements must be literals or bindings unchanged by assignments
|
|
9
|
+
//! or `arguments`. Excludes globals because repeated reads could throw or invoke getters.
|
|
11
10
|
|
|
12
|
-
use
|
|
13
|
-
use
|
|
11
|
+
use oxc::allocator::{CloneIn, GetAllocator};
|
|
12
|
+
use oxc::ast::ast::{ArrayExpressionElement, Expression, Program};
|
|
13
|
+
use oxc::ast_visit::{Visit, VisitMut, walk, walk_mut};
|
|
14
|
+
use oxc::span::GetSpanMut;
|
|
14
15
|
|
|
15
|
-
use super::analysis::
|
|
16
|
-
use super::{
|
|
17
|
-
use
|
|
16
|
+
use super::analysis::properties::Properties;
|
|
17
|
+
use super::analysis::{Analysis, Id};
|
|
18
|
+
use super::{HashMap, ast, removal};
|
|
18
19
|
|
|
19
|
-
pub(super) fn run(program: &mut Program
|
|
20
|
-
let
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// An element reads the same value wherever the array is indexed.
|
|
25
|
-
let is_fixed = |element: &Expr| match element {
|
|
26
|
-
Expr::Ident(identifier) => {
|
|
27
|
-
bindings.write_count(&identifier.to_id()) == 0
|
|
28
|
-
&& !bindings.is_mapped_parameter(&identifier.to_id())
|
|
29
|
-
&& !effects::may_have_effects(element, globals)
|
|
30
|
-
}
|
|
31
|
-
_ => true,
|
|
20
|
+
pub(super) fn run<'a>(program: &mut Program<'a>, analysis: &mut Analysis<'a>) -> bool {
|
|
21
|
+
let properties = Properties::collect(program, analysis);
|
|
22
|
+
let mut packed = Packed {
|
|
23
|
+
analysis,
|
|
24
|
+
arrays: HashMap::default(),
|
|
32
25
|
};
|
|
33
|
-
packed.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
packed.visit_program(program);
|
|
27
|
+
let mut arrays = packed.arrays;
|
|
28
|
+
arrays.retain(|&id, _| {
|
|
29
|
+
analysis.bindings.is_written_once(&id) && properties.only_indexed(id, analysis)
|
|
37
30
|
});
|
|
38
|
-
if
|
|
31
|
+
if arrays.is_empty() {
|
|
39
32
|
return false;
|
|
40
33
|
}
|
|
41
|
-
let mut unpack =
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
let mut unpack = Unpack {
|
|
35
|
+
analysis,
|
|
36
|
+
arrays: &arrays,
|
|
44
37
|
changed: false,
|
|
45
38
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
changed || removed
|
|
39
|
+
unpack.visit_program(program);
|
|
40
|
+
removal::remove_definitions(program, analysis, &arrays.keys().copied().collect())
|
|
41
|
+
|| unpack.changed
|
|
50
42
|
}
|
|
51
43
|
|
|
52
|
-
///
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
/// Collects the elements of arrays assigned to bindings.
|
|
45
|
+
struct Packed<'b, 'a> {
|
|
46
|
+
analysis: &'b Analysis<'a>,
|
|
47
|
+
arrays: HashMap<Id, Vec<Expression<'a>>>,
|
|
48
|
+
}
|
|
55
49
|
|
|
56
|
-
impl
|
|
57
|
-
fn
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
impl<'a> Packed<'_, 'a> {
|
|
51
|
+
fn element(&self, element: &ArrayExpressionElement<'a>) -> Option<Expression<'a>> {
|
|
52
|
+
let element = element.as_expression()?;
|
|
53
|
+
let fixed = match element {
|
|
54
|
+
Expression::Identifier(identifier) => self
|
|
55
|
+
.analysis
|
|
56
|
+
.id(identifier)
|
|
57
|
+
.is_some_and(|id| self.analysis.bindings.is_never_written(&id)),
|
|
58
|
+
element => element.is_literal(),
|
|
59
|
+
};
|
|
60
|
+
fixed.then(|| element.clone_in_with_semantic_ids(self.analysis.allocator()))
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
|
|
68
|
-
fn
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
.collect()
|
|
64
|
+
impl<'a> Visit<'a> for Packed<'_, 'a> {
|
|
65
|
+
fn visit_expression(&mut self, expression: &Expression<'a>) {
|
|
66
|
+
if let Some((id, Expression::ArrayExpression(array))) = self.analysis.assignment(expression)
|
|
67
|
+
{
|
|
68
|
+
let elements = array.elements.iter().map(|element| self.element(element));
|
|
69
|
+
if let Some(elements) = elements.collect() {
|
|
70
|
+
self.arrays.insert(id, elements);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
walk::walk_expression(self, expression)
|
|
74
|
+
}
|
|
79
75
|
}
|
|
80
76
|
|
|
81
|
-
struct
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
struct Unpack<'b, 'a> {
|
|
78
|
+
analysis: &'b Analysis<'a>,
|
|
79
|
+
arrays: &'b HashMap<Id, Vec<Expression<'a>>>,
|
|
84
80
|
changed: bool,
|
|
85
81
|
}
|
|
86
82
|
|
|
87
|
-
impl VisitMut for
|
|
88
|
-
fn
|
|
89
|
-
|
|
90
|
-
if let
|
|
91
|
-
&& let Some(
|
|
92
|
-
&& let Some(
|
|
93
|
-
&& let Some(
|
|
83
|
+
impl<'a> VisitMut<'a> for Unpack<'_, 'a> {
|
|
84
|
+
fn visit_expression(&mut self, expression: &mut Expression<'a>) {
|
|
85
|
+
walk_mut::walk_expression(self, expression);
|
|
86
|
+
if let Expression::ComputedMemberExpression(member) = expression
|
|
87
|
+
&& let Some(id) = self.analysis.expression_id(&member.object)
|
|
88
|
+
&& let Some(array) = self.arrays.get(&id)
|
|
89
|
+
&& let Some(index) = ast::index(&member.expression)
|
|
94
90
|
{
|
|
91
|
+
let span = member.span;
|
|
92
|
+
let mut value = match array.get(index) {
|
|
93
|
+
Some(element) => element.clone_in_with_semantic_ids(self.analysis.allocator()),
|
|
94
|
+
None => Expression::new_identifier(span, "undefined", &self.analysis.ast),
|
|
95
|
+
};
|
|
96
|
+
*value.span_mut() = span;
|
|
97
|
+
*expression = value;
|
|
95
98
|
self.changed = true;
|
|
96
|
-
// Out-of-bounds array reads produce `undefined`. Give the replacement the original
|
|
97
|
-
// read's source position, which JavaScript engines use in call stack traces.
|
|
98
|
-
*expression = elements
|
|
99
|
-
.get(index)
|
|
100
|
-
.map(|element| element.clone().with_span(member.span))
|
|
101
|
-
.unwrap_or_else(|| Expr::Ident(self.globals.reference("undefined", member.span)));
|
|
102
99
|
}
|
|
103
100
|
}
|
|
104
101
|
}
|
|
@@ -109,7 +106,7 @@ mod tests {
|
|
|
109
106
|
|
|
110
107
|
#[test]
|
|
111
108
|
fn unpacks_arrays_that_neither_change_nor_escape() {
|
|
112
|
-
let unpack = |source: &str| testing::rewrite(source, super::run
|
|
109
|
+
let unpack = |source: &str| testing::rewrite(source, super::run);
|
|
113
110
|
let output = unpack(
|
|
114
111
|
"g = function (a, b) { var f; f = [a, b, 3]; return f[1] ^ f[0] + f[2] + f[5]; };",
|
|
115
112
|
);
|