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
|
@@ -2,99 +2,169 @@
|
|
|
2
2
|
//! helper functions, state fields, and program runner. [`super::session`] evaluates what this
|
|
3
3
|
//! module finds.
|
|
4
4
|
|
|
5
|
+
use std::ptr;
|
|
6
|
+
|
|
5
7
|
use anyhow::{Context, Result, bail, ensure};
|
|
6
|
-
use
|
|
7
|
-
use
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
use oxc::ast::AstKind;
|
|
9
|
+
use oxc::ast::ast::{
|
|
10
|
+
Argument as CallArgument, AssignmentExpression, AssignmentTarget, BindingIdentifier,
|
|
11
|
+
BindingPattern, CallExpression, Class, ClassElement, Expression, FormalParameters, Function,
|
|
12
|
+
FunctionBody, MemberExpression, MethodDefinitionKind, Statement, SwitchStatement,
|
|
11
13
|
};
|
|
12
|
-
use
|
|
14
|
+
use oxc::ast_visit::{Visit, walk};
|
|
15
|
+
use oxc::semantic::{ScopeFlags, SymbolId};
|
|
16
|
+
use oxc::span::GetSpan;
|
|
17
|
+
use oxc::syntax::operator::AssignmentOperator;
|
|
13
18
|
|
|
14
19
|
use super::output::Position;
|
|
15
20
|
use super::{HashMap, convert};
|
|
16
|
-
use crate::
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
pub
|
|
21
|
-
pub
|
|
21
|
+
use crate::candidates;
|
|
22
|
+
use crate::js::ast::{self, Binding, Script};
|
|
23
|
+
|
|
24
|
+
pub(super) struct MachineScope<'a> {
|
|
25
|
+
pub body: &'a FunctionBody<'a>,
|
|
26
|
+
pub class: &'a Class<'a>,
|
|
27
|
+
pub run: &'a Function<'a>,
|
|
28
|
+
/// Newer scripts pass the machine as the first argument of a free function.
|
|
29
|
+
pub machine: Option<SymbolId>,
|
|
22
30
|
}
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
/// Finds the installed VM runner and its class, either a `run` method or a free function,
|
|
33
|
+
/// in the innermost declaring function body.
|
|
34
|
+
pub(super) fn find<'a>(script: Script<'a>) -> Option<MachineScope<'a>> {
|
|
35
|
+
script
|
|
36
|
+
.functions()
|
|
37
|
+
.filter_map(|function| {
|
|
38
|
+
let body = function.body.as_deref()?;
|
|
39
|
+
let runner = body.statements.iter().find_map(installed_runner)?;
|
|
40
|
+
let Expression::Identifier(class_name) = runner.class else {
|
|
41
|
+
return None;
|
|
42
|
+
};
|
|
43
|
+
let class = body
|
|
44
|
+
.statements
|
|
45
|
+
.iter()
|
|
46
|
+
.find_map(|statement| match statement {
|
|
47
|
+
Statement::ClassDeclaration(class)
|
|
48
|
+
if class.id.as_ref().map(|id| id.symbol_id())
|
|
49
|
+
== script.symbol(class_name) =>
|
|
50
|
+
{
|
|
51
|
+
Some(&**class)
|
|
52
|
+
}
|
|
53
|
+
_ => None,
|
|
54
|
+
})?;
|
|
55
|
+
let (run, machine) = match runner.function {
|
|
56
|
+
Some(Expression::Identifier(name)) => {
|
|
57
|
+
let run = *functions(&body.statements).get(&script.symbol(name)?)?;
|
|
58
|
+
(run, Some(parameter(&run.params, 0)?.symbol_id()))
|
|
59
|
+
}
|
|
60
|
+
None => (method(class, "run")?, None),
|
|
61
|
+
_ => return None,
|
|
62
|
+
};
|
|
63
|
+
Some(MachineScope {
|
|
64
|
+
body,
|
|
65
|
+
class,
|
|
66
|
+
run,
|
|
67
|
+
machine,
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
.last()
|
|
33
71
|
}
|
|
34
72
|
|
|
35
73
|
/// Collects the statements that run before the VM's scope is entered, both at script level and
|
|
36
|
-
/// in each enclosing function
|
|
37
|
-
pub(super) fn prelude
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
body
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
74
|
+
/// in each enclosing function: at each level, the statements before the one containing `body`.
|
|
75
|
+
pub(super) fn prelude<'a>(
|
|
76
|
+
script: Script<'a>,
|
|
77
|
+
body: &'a FunctionBody<'a>,
|
|
78
|
+
) -> Vec<&'a Statement<'a>> {
|
|
79
|
+
let mut enclosing: Vec<&'a [Statement<'a>]> = script
|
|
80
|
+
.nodes
|
|
81
|
+
.ancestor_kinds(body.node_id.get())
|
|
82
|
+
.filter_map(|kind| match kind {
|
|
83
|
+
AstKind::Function(function) => function.body.as_deref(),
|
|
84
|
+
_ => None,
|
|
85
|
+
})
|
|
86
|
+
.filter(|enclosing| !ptr::eq(*enclosing, body))
|
|
87
|
+
.map(|enclosing| &enclosing.statements[..])
|
|
88
|
+
.collect();
|
|
89
|
+
enclosing.push(&script.program.body);
|
|
55
90
|
let mut prelude = Vec::new();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
target: body.span,
|
|
63
|
-
body: None,
|
|
91
|
+
for statements in enclosing.into_iter().rev() {
|
|
92
|
+
let Some(index) = statements
|
|
93
|
+
.iter()
|
|
94
|
+
.position(|statement| statement.span().contains_inclusive(body.span))
|
|
95
|
+
else {
|
|
96
|
+
break;
|
|
64
97
|
};
|
|
65
|
-
statements[index]
|
|
66
|
-
statements.truncate(index);
|
|
67
|
-
prelude.append(&mut statements);
|
|
68
|
-
match enclosing.body {
|
|
69
|
-
Some(enclosing) if enclosing.span != body.span => statements = enclosing.stmts,
|
|
70
|
-
_ => break,
|
|
71
|
-
}
|
|
98
|
+
prelude.extend(&statements[..index]);
|
|
72
99
|
}
|
|
73
100
|
prelude
|
|
74
101
|
}
|
|
75
102
|
|
|
76
103
|
/// Functions declared beside the class: handlers and their helpers.
|
|
77
|
-
pub(super) fn functions
|
|
104
|
+
pub(super) fn functions<'a>(
|
|
105
|
+
statements: &'a [Statement<'a>],
|
|
106
|
+
) -> HashMap<SymbolId, &'a Function<'a>> {
|
|
78
107
|
statements
|
|
79
108
|
.iter()
|
|
80
|
-
.filter_map(|statement| {
|
|
81
|
-
|
|
82
|
-
|
|
109
|
+
.filter_map(|statement| match statement {
|
|
110
|
+
Statement::FunctionDeclaration(function) => {
|
|
111
|
+
Some((function.id.as_ref()?.symbol_id(), &**function))
|
|
112
|
+
}
|
|
113
|
+
_ => None,
|
|
83
114
|
})
|
|
84
115
|
.collect()
|
|
85
116
|
}
|
|
86
117
|
|
|
87
|
-
|
|
118
|
+
/// Every parameter, if each is a plain identifier: no pattern, default, or rest.
|
|
119
|
+
pub(super) fn parameters<'a>(
|
|
120
|
+
parameters: &'a FormalParameters<'a>,
|
|
121
|
+
) -> Option<Vec<&'a BindingIdentifier<'a>>> {
|
|
122
|
+
if parameters.rest.is_some() {
|
|
123
|
+
return None;
|
|
124
|
+
}
|
|
125
|
+
(0..parameters.items.len())
|
|
126
|
+
.map(|index| parameter(parameters, index))
|
|
127
|
+
.collect()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/// The parameter at `index`, if it is a plain identifier.
|
|
131
|
+
pub(super) fn parameter<'a>(
|
|
132
|
+
parameters: &'a FormalParameters<'a>,
|
|
133
|
+
index: usize,
|
|
134
|
+
) -> Option<&'a BindingIdentifier<'a>> {
|
|
135
|
+
let parameter = parameters.items.get(index)?;
|
|
136
|
+
match ¶meter.pattern {
|
|
137
|
+
BindingPattern::BindingIdentifier(name) if parameter.initializer.is_none() => Some(name),
|
|
138
|
+
_ => None,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/// The number of parameters, including a rest parameter.
|
|
143
|
+
pub(super) fn parameter_count(parameters: &FormalParameters<'_>) -> usize {
|
|
144
|
+
parameters.items.len() + usize::from(parameters.rest.is_some())
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/// The constructor's statements.
|
|
148
|
+
pub(super) fn constructor<'a>(class: &'a Class<'a>) -> Result<&'a [Statement<'a>]> {
|
|
88
149
|
class
|
|
150
|
+
.body
|
|
89
151
|
.body
|
|
90
152
|
.iter()
|
|
91
|
-
.find_map(|
|
|
153
|
+
.find_map(|element| match element {
|
|
154
|
+
ClassElement::MethodDefinition(method)
|
|
155
|
+
if method.kind == MethodDefinitionKind::Constructor =>
|
|
156
|
+
{
|
|
157
|
+
Some(&method.value.body.as_deref()?.statements[..])
|
|
158
|
+
}
|
|
159
|
+
_ => None,
|
|
160
|
+
})
|
|
92
161
|
.context("the VM class has no constructor")
|
|
93
162
|
}
|
|
94
163
|
|
|
95
164
|
/// What a `run` local holds.
|
|
96
165
|
#[derive(Clone)]
|
|
97
166
|
enum Source {
|
|
167
|
+
Machine,
|
|
98
168
|
Parameter(usize),
|
|
99
169
|
/// `this.<name>`.
|
|
100
170
|
Field(String),
|
|
@@ -108,6 +178,7 @@ enum Source {
|
|
|
108
178
|
|
|
109
179
|
/// Register layout and state setup recovered from `run`.
|
|
110
180
|
pub(super) struct RunMethod<'ast> {
|
|
181
|
+
pub access: super::registers::Access<'ast>,
|
|
111
182
|
/// Field containing the register file. Fields on that file identify the program counter and
|
|
112
183
|
/// dispatch key registers.
|
|
113
184
|
pub registers: String,
|
|
@@ -120,7 +191,7 @@ pub(super) struct RunMethod<'ast> {
|
|
|
120
191
|
/// Dispatch function declared beside the class and called by `run` with the machine. Some builds
|
|
121
192
|
/// move both loops out of `run`; both dispatch the same handlers.
|
|
122
193
|
pub(crate) struct DispatchLoop<'ast> {
|
|
123
|
-
pub function: &'ast Function
|
|
194
|
+
pub function: &'ast Function<'ast>,
|
|
124
195
|
/// Argument values passed by `run`, in parameter order.
|
|
125
196
|
pub arguments: Vec<Argument>,
|
|
126
197
|
}
|
|
@@ -136,65 +207,96 @@ pub(crate) enum Argument {
|
|
|
136
207
|
|
|
137
208
|
impl DispatchLoop<'_> {
|
|
138
209
|
/// The parameter receiving the machine.
|
|
139
|
-
fn machine(&self) -> Option
|
|
210
|
+
fn machine(&self) -> Option<SymbolId> {
|
|
140
211
|
let position = self
|
|
141
212
|
.arguments
|
|
142
213
|
.iter()
|
|
143
214
|
.position(|argument| *argument == Argument::Machine)?;
|
|
144
|
-
Some(&self.function.params
|
|
215
|
+
Some(parameter(&self.function.params, position)?.symbol_id())
|
|
145
216
|
}
|
|
146
217
|
}
|
|
147
218
|
|
|
219
|
+
/// The locals of `run` and what they hold.
|
|
220
|
+
struct Locals<'a> {
|
|
221
|
+
script: Script<'a>,
|
|
222
|
+
sources: HashMap<Binding<'a>, Source>,
|
|
223
|
+
free: bool,
|
|
224
|
+
}
|
|
225
|
+
|
|
148
226
|
/// Tracks assignments in `run`, including copies of register fields and indices, program counter
|
|
149
227
|
/// and key setup, storing the third argument in the cells register, reading the program register,
|
|
150
228
|
/// and calling dispatch loops. An unsupported assignment clears the known value of its local.
|
|
151
229
|
pub(super) fn run_method<'a>(
|
|
152
|
-
|
|
153
|
-
|
|
230
|
+
script: Script<'a>,
|
|
231
|
+
functions: &HashMap<SymbolId, &'a Function<'a>>,
|
|
232
|
+
run: &'a Function<'a>,
|
|
233
|
+
machine: Option<SymbolId>,
|
|
154
234
|
) -> Result<RunMethod<'a>> {
|
|
155
|
-
let body = run.body.
|
|
156
|
-
let
|
|
157
|
-
.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
))
|
|
235
|
+
let body = run.body.as_deref().context("the run method has no body")?;
|
|
236
|
+
let sources = (0..run.params.items.len())
|
|
237
|
+
.filter_map(|index| {
|
|
238
|
+
let name = parameter(&run.params, index)?;
|
|
239
|
+
let source = if machine == Some(name.symbol_id()) {
|
|
240
|
+
Source::Machine
|
|
241
|
+
} else {
|
|
242
|
+
Source::Parameter(index - usize::from(machine.is_some()))
|
|
243
|
+
};
|
|
244
|
+
Some((Binding::Symbol(name.symbol_id()), source))
|
|
165
245
|
})
|
|
166
246
|
.collect();
|
|
247
|
+
let mut locals = Locals {
|
|
248
|
+
script,
|
|
249
|
+
sources,
|
|
250
|
+
free: machine.is_some(),
|
|
251
|
+
};
|
|
167
252
|
let mut cells = None;
|
|
168
253
|
let mut loaded = Vec::new();
|
|
169
|
-
|
|
170
|
-
|
|
254
|
+
let mut reader = None;
|
|
255
|
+
let mut writer = None;
|
|
256
|
+
let function = |expression: &Expression<'a>| {
|
|
257
|
+
let Expression::CallExpression(call) = expression else {
|
|
258
|
+
return None;
|
|
259
|
+
};
|
|
260
|
+
let Expression::Identifier(callee) = &call.callee else {
|
|
261
|
+
return None;
|
|
262
|
+
};
|
|
263
|
+
functions.get(&script.symbol(callee)?).copied()
|
|
264
|
+
};
|
|
265
|
+
for statement in &body.statements {
|
|
266
|
+
let Statement::ExpressionStatement(statement) = statement else {
|
|
171
267
|
continue;
|
|
172
268
|
};
|
|
173
|
-
let expressions: Vec<&
|
|
174
|
-
|
|
175
|
-
|
|
269
|
+
let expressions: Vec<&Expression<'a>> = match &statement.expression {
|
|
270
|
+
Expression::SequenceExpression(sequence) => sequence.expressions.iter().collect(),
|
|
271
|
+
expression => vec![expression],
|
|
176
272
|
};
|
|
177
|
-
for
|
|
178
|
-
if let Some((Source::Field(registers), arguments)) =
|
|
273
|
+
for expression in expressions {
|
|
274
|
+
if let Some((Source::Field(registers), arguments)) =
|
|
275
|
+
locals.method_call(expression, "write")
|
|
179
276
|
&& let [Some(Source::Field(index)), Some(Source::Parameter(2))] = &arguments[..]
|
|
180
277
|
{
|
|
181
278
|
cells = Some((registers, index.clone()));
|
|
279
|
+
writer = function(expression);
|
|
182
280
|
continue;
|
|
183
281
|
}
|
|
184
|
-
let
|
|
185
|
-
let AssignTarget::Simple(SimpleAssignTarget::Ident(name)) = &assign.left else {
|
|
282
|
+
let Expression::AssignmentExpression(assignment) = expression else {
|
|
186
283
|
continue;
|
|
187
284
|
};
|
|
188
|
-
let
|
|
189
|
-
|
|
285
|
+
let AssignmentTarget::AssignmentTargetIdentifier(name) = &assignment.left else {
|
|
286
|
+
continue;
|
|
287
|
+
};
|
|
288
|
+
let value = match assignment.operator {
|
|
289
|
+
AssignmentOperator::Assign => locals.source(&assignment.right),
|
|
190
290
|
_ => None,
|
|
191
291
|
};
|
|
192
292
|
if let Some(Source::Register { registers, index }) = &value {
|
|
193
293
|
loaded.push((registers.clone(), index.clone()));
|
|
294
|
+
reader = function(&assignment.right);
|
|
194
295
|
}
|
|
296
|
+
let binding = script.binding(name);
|
|
195
297
|
match value {
|
|
196
|
-
Some(value) => locals.insert(
|
|
197
|
-
None => locals.remove(&
|
|
298
|
+
Some(value) => locals.sources.insert(binding, value),
|
|
299
|
+
None => locals.sources.remove(&binding),
|
|
198
300
|
};
|
|
199
301
|
}
|
|
200
302
|
}
|
|
@@ -211,19 +313,22 @@ pub(super) fn run_method<'a>(
|
|
|
211
313
|
};
|
|
212
314
|
let program = program.clone();
|
|
213
315
|
let mut calls = DispatchCall {
|
|
316
|
+
script,
|
|
214
317
|
functions,
|
|
318
|
+
machine,
|
|
215
319
|
found: None,
|
|
216
320
|
};
|
|
217
|
-
|
|
321
|
+
calls.visit_function_body(body);
|
|
218
322
|
let (function, call) = calls
|
|
219
323
|
.found
|
|
220
324
|
.context("the run method calls no dispatch loop with the machine")?;
|
|
221
325
|
let arguments = call
|
|
222
|
-
.
|
|
326
|
+
.arguments
|
|
223
327
|
.iter()
|
|
224
|
-
.map(|argument| match
|
|
225
|
-
|
|
226
|
-
|
|
328
|
+
.map(|argument| match ast::argument_expression(argument) {
|
|
329
|
+
Expression::ThisExpression(_) => Argument::Machine,
|
|
330
|
+
Expression::Identifier(name) => match locals.sources.get(&script.binding(name)) {
|
|
331
|
+
Some(Source::Machine) => Argument::Machine,
|
|
227
332
|
Some(Source::Field(field)) if *field == registers => Argument::Registers,
|
|
228
333
|
Some(Source::Register { index, .. }) if *index == program => Argument::Program,
|
|
229
334
|
_ => Argument::Other,
|
|
@@ -232,6 +337,14 @@ pub(super) fn run_method<'a>(
|
|
|
232
337
|
})
|
|
233
338
|
.collect();
|
|
234
339
|
Ok(RunMethod {
|
|
340
|
+
access: if machine.is_some() {
|
|
341
|
+
super::registers::Access::Functions {
|
|
342
|
+
read: reader.context("the free VM runner has no register reader")?,
|
|
343
|
+
write: writer.context("the free VM runner has no register writer")?,
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
super::registers::Access::Methods
|
|
347
|
+
},
|
|
235
348
|
registers,
|
|
236
349
|
cells,
|
|
237
350
|
program,
|
|
@@ -244,122 +357,182 @@ pub(super) fn run_method<'a>(
|
|
|
244
357
|
|
|
245
358
|
/// Finds the first call in `run` whose first argument is the machine and whose target contains a
|
|
246
359
|
/// dispatch switch.
|
|
247
|
-
struct DispatchCall<'functions, '
|
|
248
|
-
|
|
249
|
-
|
|
360
|
+
struct DispatchCall<'functions, 'a> {
|
|
361
|
+
script: Script<'a>,
|
|
362
|
+
functions: &'functions HashMap<SymbolId, &'a Function<'a>>,
|
|
363
|
+
machine: Option<SymbolId>,
|
|
364
|
+
found: Option<(&'a Function<'a>, &'a CallExpression<'a>)>,
|
|
250
365
|
}
|
|
251
366
|
|
|
252
|
-
impl Visit for DispatchCall<'_, '
|
|
253
|
-
fn
|
|
367
|
+
impl<'a> Visit<'a> for DispatchCall<'_, 'a> {
|
|
368
|
+
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
254
369
|
if self.found.is_none()
|
|
255
|
-
&& call
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
370
|
+
&& call.arguments.first().is_some_and(|first| {
|
|
371
|
+
let first = ast::argument_expression(first);
|
|
372
|
+
matches!(first, Expression::ThisExpression(_))
|
|
373
|
+
|| self
|
|
374
|
+
.machine
|
|
375
|
+
.is_some_and(|machine| self.script.refers_to(first, machine))
|
|
376
|
+
})
|
|
377
|
+
&& let Expression::Identifier(callee) = &call.callee
|
|
378
|
+
&& let Some(symbol) = self.script.symbol(callee)
|
|
379
|
+
&& let Some(&function) = self.functions.get(&symbol)
|
|
261
380
|
&& first_switch_in(function).is_some()
|
|
262
381
|
{
|
|
263
|
-
self.found = Some((
|
|
382
|
+
self.found = Some((
|
|
383
|
+
function,
|
|
384
|
+
self.script.lend(call, AstKind::as_call_expression),
|
|
385
|
+
));
|
|
264
386
|
}
|
|
265
|
-
|
|
387
|
+
walk::walk_call_expression(self, call);
|
|
266
388
|
}
|
|
267
389
|
}
|
|
268
390
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
.
|
|
280
|
-
|
|
281
|
-
|
|
391
|
+
impl<'a> Locals<'a> {
|
|
392
|
+
/// Resolves `<object>.<name>(<arguments>)`, including the values of the object and
|
|
393
|
+
/// arguments.
|
|
394
|
+
fn method_call(
|
|
395
|
+
&self,
|
|
396
|
+
expression: &Expression<'a>,
|
|
397
|
+
name: &str,
|
|
398
|
+
) -> Option<(Source, Vec<Option<Source>>)> {
|
|
399
|
+
let (object, arguments) = if let Some(call) = ast::method_call(expression, name) {
|
|
400
|
+
call
|
|
401
|
+
} else if self.free
|
|
402
|
+
&& let Expression::CallExpression(call) = expression
|
|
403
|
+
{
|
|
404
|
+
let [object, arguments @ ..] = &call.arguments[..] else {
|
|
405
|
+
return None;
|
|
406
|
+
};
|
|
407
|
+
if arguments.len() != if name == "read" { 1 } else { 2 } {
|
|
408
|
+
return None;
|
|
409
|
+
}
|
|
410
|
+
(ast::argument_expression(object), arguments)
|
|
411
|
+
} else {
|
|
412
|
+
return None;
|
|
413
|
+
};
|
|
414
|
+
let arguments = arguments
|
|
415
|
+
.iter()
|
|
416
|
+
.map(|argument| self.source(ast::argument_expression(argument)))
|
|
417
|
+
.collect();
|
|
418
|
+
Some((self.source(object)?, arguments))
|
|
419
|
+
}
|
|
282
420
|
|
|
283
|
-
fn source(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
421
|
+
fn source(&self, expression: &Expression<'a>) -> Option<Source> {
|
|
422
|
+
match expression {
|
|
423
|
+
Expression::Identifier(name) => self.sources.get(&self.script.binding(name)).cloned(),
|
|
424
|
+
Expression::ThisExpression(_) => Some(Source::Machine),
|
|
425
|
+
Expression::ParenthesizedExpression(paren) => self.source(&paren.expression),
|
|
426
|
+
Expression::CallExpression(_) => match self.method_call(expression, "read")? {
|
|
427
|
+
(Source::Field(registers), arguments) => match &arguments[..] {
|
|
428
|
+
[Some(Source::Field(index))] => Some(Source::Register {
|
|
429
|
+
registers,
|
|
430
|
+
index: index.clone(),
|
|
431
|
+
}),
|
|
432
|
+
_ => None,
|
|
433
|
+
},
|
|
296
434
|
_ => None,
|
|
297
435
|
},
|
|
298
|
-
|
|
299
|
-
|
|
436
|
+
expression => {
|
|
437
|
+
let member = expression.as_member_expression()?;
|
|
438
|
+
matches!(self.source(member.object()), Some(Source::Machine))
|
|
439
|
+
.then(|| ast::member_str(member).map(|name| Source::Field(name.to_owned())))?
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/// The field `this.<field>` reads.
|
|
446
|
+
pub(super) fn this_field<'a>(expression: &Expression<'a>) -> Option<&'a str> {
|
|
447
|
+
let member = expression.as_member_expression()?;
|
|
448
|
+
match member.object() {
|
|
449
|
+
Expression::ThisExpression(_) => ast::member_str(member),
|
|
300
450
|
_ => None,
|
|
301
451
|
}
|
|
302
452
|
}
|
|
303
453
|
|
|
304
454
|
/// Finds the string decryption function called by the register reader as
|
|
305
455
|
/// `decrypt(this.<values>[index])`.
|
|
306
|
-
pub(super) fn record_decoder
|
|
456
|
+
pub(super) fn record_decoder<'a>(
|
|
457
|
+
script: Script<'a>,
|
|
458
|
+
body: &'a FunctionBody<'a>,
|
|
459
|
+
access: super::registers::Access<'a>,
|
|
460
|
+
) -> Option<SymbolId> {
|
|
307
461
|
/// Matches `<decoder>(this.<values>[<index>])`.
|
|
308
|
-
struct Decoders {
|
|
309
|
-
|
|
310
|
-
|
|
462
|
+
struct Decoders<'a> {
|
|
463
|
+
script: Script<'a>,
|
|
464
|
+
index: SymbolId,
|
|
465
|
+
object: Option<SymbolId>,
|
|
466
|
+
access: super::registers::Access<'a>,
|
|
467
|
+
found: Vec<Binding<'a>>,
|
|
311
468
|
}
|
|
312
469
|
|
|
313
|
-
impl Visit for Decoders {
|
|
314
|
-
fn
|
|
315
|
-
if let
|
|
316
|
-
&& let [argument] = &call.
|
|
317
|
-
&& let Some(member) = argument.
|
|
318
|
-
&& member
|
|
319
|
-
.obj
|
|
320
|
-
.as_member()
|
|
321
|
-
.is_some_and(|values| values.obj.is_this())
|
|
470
|
+
impl<'a> Visit<'a> for Decoders<'a> {
|
|
471
|
+
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
472
|
+
if let Expression::Identifier(callee) = &call.callee
|
|
473
|
+
&& let [argument] = &call.arguments[..]
|
|
474
|
+
&& let Some(member) = ast::argument_expression(argument).as_member_expression()
|
|
322
475
|
&& member
|
|
323
|
-
.
|
|
324
|
-
.
|
|
325
|
-
.
|
|
326
|
-
|
|
476
|
+
.object()
|
|
477
|
+
.as_member_expression()
|
|
478
|
+
.is_some_and(|values| {
|
|
479
|
+
matches!(values.object(), Expression::ThisExpression(_))
|
|
480
|
+
|| (self.object.is_some_and(|object| {
|
|
481
|
+
self.script.refers_to(values.object(), object)
|
|
482
|
+
}) && ast::member_str(values)
|
|
483
|
+
.and_then(|name| self.access.member(name))
|
|
484
|
+
== Some(super::registers::Member::Values))
|
|
485
|
+
})
|
|
486
|
+
&& let MemberExpression::ComputedMemberExpression(member) = member
|
|
487
|
+
&& self.script.refers_to(&member.expression, self.index)
|
|
327
488
|
{
|
|
328
|
-
self.found.push(
|
|
489
|
+
self.found.push(self.script.binding(callee));
|
|
329
490
|
}
|
|
330
|
-
|
|
491
|
+
walk::walk_call_expression(self, call);
|
|
331
492
|
}
|
|
332
493
|
}
|
|
333
494
|
|
|
334
|
-
let read
|
|
335
|
-
|
|
336
|
-
|
|
495
|
+
let (read, object, index) = match access {
|
|
496
|
+
super::registers::Access::Methods => {
|
|
497
|
+
let read = body
|
|
498
|
+
.statements
|
|
499
|
+
.iter()
|
|
500
|
+
.find_map(|statement| match statement {
|
|
501
|
+
Statement::ClassDeclaration(class) if method(class, "write").is_some() => {
|
|
502
|
+
method(class, "read")
|
|
503
|
+
}
|
|
504
|
+
_ => None,
|
|
505
|
+
})?;
|
|
506
|
+
(read, None, 0)
|
|
337
507
|
}
|
|
338
|
-
|
|
339
|
-
|
|
508
|
+
super::registers::Access::Functions { read, .. } => {
|
|
509
|
+
(read, Some(parameter(&read.params, 0)?.symbol_id()), 1)
|
|
510
|
+
}
|
|
511
|
+
};
|
|
340
512
|
let mut decoders = Decoders {
|
|
341
|
-
|
|
513
|
+
script,
|
|
514
|
+
object,
|
|
515
|
+
access,
|
|
516
|
+
index: parameter(&read.params, index)?.symbol_id(),
|
|
342
517
|
found: Vec::new(),
|
|
343
518
|
};
|
|
344
|
-
|
|
345
|
-
|
|
519
|
+
decoders.visit_function(read, ScopeFlags::Function);
|
|
520
|
+
decoders.found.sort();
|
|
521
|
+
decoders.found.dedup();
|
|
522
|
+
let [Binding::Symbol(decoder)] = decoders.found[..] else {
|
|
523
|
+
return None;
|
|
524
|
+
};
|
|
346
525
|
Some(decoder)
|
|
347
526
|
}
|
|
348
527
|
|
|
349
|
-
/// The
|
|
350
|
-
fn
|
|
351
|
-
body.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
pub(super) fn method<'a>(class: &'a Class, name: &str) -> Option<&'a Function> {
|
|
360
|
-
class.body.iter().find_map(|member| match member {
|
|
361
|
-
ClassMember::Method(method) if ast::static_key_str(&method.key) == Some(name) => {
|
|
362
|
-
Some(&*method.function)
|
|
528
|
+
/// The method, getter, or setter named `name`, excluding the constructor.
|
|
529
|
+
pub(super) fn method<'a>(class: &'a Class<'a>, name: &str) -> Option<&'a Function<'a>> {
|
|
530
|
+
class.body.body.iter().find_map(|element| match element {
|
|
531
|
+
ClassElement::MethodDefinition(method)
|
|
532
|
+
if method.kind != MethodDefinitionKind::Constructor
|
|
533
|
+
&& ast::static_key_str(&method.key, method.computed) == Some(name) =>
|
|
534
|
+
{
|
|
535
|
+
Some(&*method.value)
|
|
363
536
|
}
|
|
364
537
|
_ => None,
|
|
365
538
|
})
|
|
@@ -367,40 +540,46 @@ pub(super) fn method<'a>(class: &'a Class, name: &str) -> Option<&'a Function> {
|
|
|
367
540
|
|
|
368
541
|
/// Extracts opcode and handler pairs from `case <opcode>: <handler>(<machine>); break;`.
|
|
369
542
|
pub(super) fn handlers<'a>(
|
|
370
|
-
|
|
543
|
+
script: Script<'a>,
|
|
544
|
+
functions: &HashMap<SymbolId, &'a Function<'a>>,
|
|
371
545
|
dispatch: &DispatchLoop<'a>,
|
|
372
|
-
) -> Result<HashMap<u8, &'a Function
|
|
546
|
+
) -> Result<HashMap<u8, &'a Function<'a>>> {
|
|
373
547
|
let switch = first_switch_in(dispatch.function).context("the dispatch loop has no switch")?;
|
|
374
548
|
let machine = dispatch.machine();
|
|
375
|
-
let is_machine = |argument: &
|
|
376
|
-
argument.
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
.as_ident()
|
|
380
|
-
.is_some_and(|name| Some(&name.sym) == machine)
|
|
549
|
+
let is_machine = |argument: &CallArgument<'_>| {
|
|
550
|
+
argument.as_expression().is_some_and(|argument| {
|
|
551
|
+
machine.is_some_and(|machine| script.refers_to(argument, machine))
|
|
552
|
+
})
|
|
381
553
|
};
|
|
382
554
|
let mut handlers = HashMap::default();
|
|
383
555
|
for case in &switch.cases {
|
|
384
556
|
let Some(test) = &case.test else { continue };
|
|
385
|
-
let
|
|
557
|
+
let Expression::NumericLiteral(opcode) = test else {
|
|
386
558
|
bail!("a dispatch case is not a number");
|
|
387
559
|
};
|
|
388
560
|
let opcode = convert::byte(opcode.value).context("a dispatch case is not an opcode")?;
|
|
389
561
|
let call = case
|
|
390
|
-
.
|
|
562
|
+
.consequent
|
|
391
563
|
.iter()
|
|
392
|
-
.find_map(|statement| statement
|
|
564
|
+
.find_map(|statement| match statement {
|
|
565
|
+
Statement::ExpressionStatement(statement) => match &statement.expression {
|
|
566
|
+
Expression::CallExpression(call) => Some(call),
|
|
567
|
+
_ => None,
|
|
568
|
+
},
|
|
569
|
+
_ => None,
|
|
570
|
+
})
|
|
393
571
|
.with_context(|| format!("dispatch case {opcode} calls no handler"))?;
|
|
394
|
-
let
|
|
572
|
+
let Expression::Identifier(name) = &call.callee else {
|
|
395
573
|
bail!("dispatch case {opcode} calls no named handler");
|
|
396
574
|
};
|
|
397
|
-
let function =
|
|
398
|
-
.
|
|
399
|
-
.
|
|
575
|
+
let function = script
|
|
576
|
+
.symbol(name)
|
|
577
|
+
.and_then(|symbol| functions.get(&symbol))
|
|
578
|
+
.with_context(|| format!("no handler function {}", name.name))?;
|
|
400
579
|
ensure!(
|
|
401
|
-
matches!(&call.
|
|
580
|
+
matches!(&call.arguments[..], [argument] if is_machine(argument)),
|
|
402
581
|
"dispatch case {opcode} does not pass {} only the machine",
|
|
403
|
-
name.
|
|
582
|
+
name.name
|
|
404
583
|
);
|
|
405
584
|
let previous = handlers.insert(opcode, *function);
|
|
406
585
|
ensure!(previous.is_none(), "opcode {opcode} has two dispatch cases");
|
|
@@ -409,30 +588,35 @@ pub(super) fn handlers<'a>(
|
|
|
409
588
|
}
|
|
410
589
|
|
|
411
590
|
/// Finds the first dispatch switch in the body of `function`.
|
|
412
|
-
fn first_switch_in(function: &Function) -> Option<&
|
|
413
|
-
function
|
|
591
|
+
fn first_switch_in<'a>(function: &'a Function<'a>) -> Option<&'a SwitchStatement<'a>> {
|
|
592
|
+
function
|
|
593
|
+
.body
|
|
594
|
+
.as_deref()?
|
|
595
|
+
.statements
|
|
596
|
+
.iter()
|
|
597
|
+
.find_map(first_switch)
|
|
414
598
|
}
|
|
415
599
|
|
|
416
600
|
/// Finds the first dispatch `switch`; both dispatch loops use the same form.
|
|
417
|
-
fn first_switch(statement: &
|
|
601
|
+
fn first_switch<'a>(statement: &'a Statement<'a>) -> Option<&'a SwitchStatement<'a>> {
|
|
418
602
|
match statement {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
first_switch(&branch.
|
|
603
|
+
Statement::SwitchStatement(switch) => Some(switch),
|
|
604
|
+
Statement::BlockStatement(block) => block.body.iter().find_map(first_switch),
|
|
605
|
+
Statement::WhileStatement(looping) => first_switch(&looping.body),
|
|
606
|
+
Statement::IfStatement(branch) => {
|
|
607
|
+
first_switch(&branch.consequent).or_else(|| first_switch(branch.alternate.as_ref()?))
|
|
424
608
|
}
|
|
425
|
-
|
|
609
|
+
Statement::TryStatement(attempt) => attempt.block.body.iter().find_map(first_switch),
|
|
426
610
|
_ => None,
|
|
427
611
|
}
|
|
428
612
|
}
|
|
429
613
|
|
|
430
614
|
/// Where the program runner starts a program (see [`Runner`]).
|
|
431
|
-
pub(super) fn entry(body: &
|
|
615
|
+
pub(super) fn entry(body: &FunctionBody<'_>) -> Result<Position> {
|
|
432
616
|
let runner = body
|
|
433
|
-
.
|
|
617
|
+
.statements
|
|
434
618
|
.iter()
|
|
435
|
-
.find_map(
|
|
619
|
+
.find_map(installed_runner)
|
|
436
620
|
.context("no program runner in the VM's scope")?;
|
|
437
621
|
let pc = convert::position(runner.pc).context("the runner starts at no program position")?;
|
|
438
622
|
let key = convert::byte(runner.key).context("the runner starts with no dispatch key")?;
|
|
@@ -448,75 +632,108 @@ struct Runner<'ast> {
|
|
|
448
632
|
pc: f64,
|
|
449
633
|
/// Initial dispatch key from the source.
|
|
450
634
|
key: f64,
|
|
635
|
+
class: &'ast Expression<'ast>,
|
|
636
|
+
function: Option<&'ast Expression<'ast>>,
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
fn installed_runner<'a>(statement: &'a Statement<'a>) -> Option<Runner<'a>> {
|
|
640
|
+
let Statement::ExpressionStatement(statement) = statement else {
|
|
641
|
+
return None;
|
|
642
|
+
};
|
|
643
|
+
let Expression::AssignmentExpression(assignment) = &statement.expression else {
|
|
644
|
+
return None;
|
|
645
|
+
};
|
|
646
|
+
Runner::installed_by(assignment)
|
|
451
647
|
}
|
|
452
648
|
|
|
453
649
|
impl<'ast> Runner<'ast> {
|
|
454
|
-
fn installed_by(
|
|
455
|
-
let
|
|
650
|
+
fn installed_by(assignment: &'ast AssignmentExpression<'ast>) -> Option<Self> {
|
|
651
|
+
let target = assignment.left.as_member_expression()?;
|
|
652
|
+
if matches!(target.object(), Expression::Super(_)) {
|
|
653
|
+
return None;
|
|
654
|
+
}
|
|
655
|
+
let Expression::FunctionExpression(function) = &assignment.right else {
|
|
456
656
|
return None;
|
|
457
657
|
};
|
|
458
|
-
let body =
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
] = after_bare_declarations(&body.stmts)
|
|
658
|
+
let body = function.body.as_deref()?;
|
|
659
|
+
if !body.directives.is_empty() {
|
|
660
|
+
return None;
|
|
661
|
+
}
|
|
662
|
+
let [Statement::ReturnStatement(returned)] = after_bare_declarations(&body.statements)
|
|
464
663
|
else {
|
|
465
664
|
return None;
|
|
466
665
|
};
|
|
467
|
-
let
|
|
666
|
+
let expression = returned.argument.as_ref()?;
|
|
667
|
+
let (machine, arguments, function) =
|
|
668
|
+
if let Some((machine, arguments)) = ast::method_call(expression, "run") {
|
|
669
|
+
(machine, arguments, None)
|
|
670
|
+
} else if let Expression::CallExpression(call) = expression {
|
|
671
|
+
let [machine, arguments @ ..] = &call.arguments[..] else {
|
|
672
|
+
return None;
|
|
673
|
+
};
|
|
674
|
+
(
|
|
675
|
+
ast::argument_expression(machine),
|
|
676
|
+
arguments,
|
|
677
|
+
Some(&call.callee),
|
|
678
|
+
)
|
|
679
|
+
} else {
|
|
680
|
+
return None;
|
|
681
|
+
};
|
|
682
|
+
let [pc, key, ..] = arguments else {
|
|
468
683
|
return None;
|
|
469
684
|
};
|
|
470
|
-
let (
|
|
471
|
-
(
|
|
685
|
+
let (
|
|
686
|
+
Expression::NewExpression(new),
|
|
687
|
+
Expression::NumericLiteral(pc),
|
|
688
|
+
Expression::NumericLiteral(key),
|
|
689
|
+
) = (
|
|
690
|
+
machine,
|
|
691
|
+
ast::argument_expression(pc),
|
|
692
|
+
ast::argument_expression(key),
|
|
693
|
+
)
|
|
472
694
|
else {
|
|
473
695
|
return None;
|
|
474
696
|
};
|
|
475
697
|
Some(Self {
|
|
476
|
-
name: ast::member_str(
|
|
698
|
+
name: ast::member_str(target)?,
|
|
477
699
|
pc: pc.value,
|
|
478
700
|
key: key.value,
|
|
701
|
+
class: &new.callee,
|
|
702
|
+
function,
|
|
479
703
|
})
|
|
480
704
|
}
|
|
481
705
|
}
|
|
482
706
|
|
|
483
707
|
/// Returns the installed program runner's name if exactly one exists (see [`Runner`]).
|
|
484
|
-
pub(crate) fn runner_name(script:
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
self.0.push(runner.name.to_owned());
|
|
492
|
-
}
|
|
493
|
-
assign.visit_children_with(self);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
let mut names = Names::default();
|
|
498
|
-
script.visit_with(&mut names);
|
|
499
|
-
let [name]: [String; 1] = names.0.try_into().ok()?;
|
|
500
|
-
Some(name)
|
|
708
|
+
pub(crate) fn runner_name(script: Script<'_>) -> Option<String> {
|
|
709
|
+
let runners = script.nodes.iter().filter_map(|node| match node.kind() {
|
|
710
|
+
AstKind::AssignmentExpression(assignment) => Runner::installed_by(assignment),
|
|
711
|
+
_ => None,
|
|
712
|
+
});
|
|
713
|
+
let runner = candidates::exactly_one(runners, "program runner").ok()?;
|
|
714
|
+
Some(runner.name.to_owned())
|
|
501
715
|
}
|
|
502
716
|
|
|
503
717
|
/// Whether `call` calls the runner `name` installs, as `name(...)` or `<global>.name(...)`.
|
|
504
|
-
pub(crate) fn calls_runner(call: &
|
|
505
|
-
match call.callee.
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
718
|
+
pub(crate) fn calls_runner(call: &CallExpression<'_>, name: &str) -> bool {
|
|
719
|
+
match call.callee.without_parentheses() {
|
|
720
|
+
Expression::Identifier(callee) => callee.name == name,
|
|
721
|
+
callee => callee.as_member_expression().is_some_and(|member| {
|
|
722
|
+
!matches!(member.object(), Expression::Super(_))
|
|
723
|
+
&& ast::member_str(member) == Some(name)
|
|
724
|
+
}),
|
|
509
725
|
}
|
|
510
726
|
}
|
|
511
727
|
|
|
512
728
|
/// Skips leading `var x;` declarations. Deobfuscation removes helper objects used to calculate
|
|
513
729
|
/// `run` arguments but may leave their declarations.
|
|
514
|
-
fn after_bare_declarations(statements: &[
|
|
730
|
+
fn after_bare_declarations<'b, 'a>(statements: &'b [Statement<'a>]) -> &'b [Statement<'a>] {
|
|
515
731
|
let start = statements
|
|
516
732
|
.iter()
|
|
517
733
|
.position(|statement| {
|
|
518
|
-
!matches!(statement,
|
|
519
|
-
if declaration.
|
|
734
|
+
!matches!(statement, Statement::VariableDeclaration(declaration)
|
|
735
|
+
if !declaration.kind.is_using()
|
|
736
|
+
&& declaration.declarations.iter().all(|declarator| declarator.init.is_none()))
|
|
520
737
|
})
|
|
521
738
|
.unwrap_or(statements.len());
|
|
522
739
|
&statements[start..]
|
|
@@ -525,13 +742,15 @@ fn after_bare_declarations(statements: &[Stmt]) -> &[Stmt] {
|
|
|
525
742
|
#[cfg(test)]
|
|
526
743
|
mod tests {
|
|
527
744
|
use super::*;
|
|
745
|
+
use crate::js::ast::ParsedScript;
|
|
528
746
|
|
|
529
747
|
fn entry_of(source: &str) -> Result<Position> {
|
|
530
|
-
let parsed =
|
|
531
|
-
let
|
|
748
|
+
let parsed = ParsedScript::parse("t", source).unwrap();
|
|
749
|
+
let script = parsed.script();
|
|
750
|
+
let Some(Statement::FunctionDeclaration(function)) = script.program.body.first() else {
|
|
532
751
|
panic!("the test source declares no function");
|
|
533
752
|
};
|
|
534
|
-
entry(function.
|
|
753
|
+
entry(function.body.as_deref().unwrap())
|
|
535
754
|
}
|
|
536
755
|
|
|
537
756
|
#[test]
|
|
@@ -539,6 +758,7 @@ mod tests {
|
|
|
539
758
|
for source in [
|
|
540
759
|
"function f(O) { O.vlJM8 = function(p) { return new M(p).run(0, 238, []); }; }",
|
|
541
760
|
"function f(O) { O.vlJM8 = function(p) { var a; var b, c; return new M(p).run(0, 238, []); }; }",
|
|
761
|
+
"function f(O) { O.vlJM8 = function(p) { return execute(new M(p), 0, 238, []); }; }",
|
|
542
762
|
] {
|
|
543
763
|
assert_eq!(entry_of(source).unwrap(), Position::new(0, 238), "{source}");
|
|
544
764
|
}
|
|
@@ -549,22 +769,102 @@ mod tests {
|
|
|
549
769
|
);
|
|
550
770
|
}
|
|
551
771
|
|
|
772
|
+
#[test]
|
|
773
|
+
fn extracts_free_runner_and_register_helpers_by_binding() {
|
|
774
|
+
let parsed = ParsedScript::parse("moved VM", r#"
|
|
775
|
+
function scope(global) {
|
|
776
|
+
class Unrelated { run() {} }
|
|
777
|
+
class Registers { constructor() {} }
|
|
778
|
+
class Machine { constructor(program) {} }
|
|
779
|
+
function load(registers, index) { return registers.H[index]; }
|
|
780
|
+
function store(registers, index, value) { registers.H[index] = value; }
|
|
781
|
+
function opcode(machine) {}
|
|
782
|
+
function dispatch(machine, registers, pending, program) {
|
|
783
|
+
while (true) { switch (program[0]) { case 42: opcode(machine); break; } }
|
|
784
|
+
}
|
|
785
|
+
function execute(machine, pc, key, cells) {
|
|
786
|
+
var registers, index, program;
|
|
787
|
+
registers = machine.registers;
|
|
788
|
+
index = machine.cells;
|
|
789
|
+
store(registers, index, cells);
|
|
790
|
+
index = machine.program;
|
|
791
|
+
program = load(registers, index);
|
|
792
|
+
dispatch(machine, registers, null, program);
|
|
793
|
+
}
|
|
794
|
+
global.start = function(program) { return execute(new Machine(program), 0, 231, []); };
|
|
795
|
+
}
|
|
796
|
+
"#).unwrap();
|
|
797
|
+
let script = parsed.script();
|
|
798
|
+
assert_eq!(runner_name(script).as_deref(), Some("start"));
|
|
799
|
+
let found = find(script).unwrap();
|
|
800
|
+
assert_eq!(found.class.id.as_ref().unwrap().name, "Machine");
|
|
801
|
+
assert_eq!(entry(found.body).unwrap(), Position::new(0, 231));
|
|
802
|
+
let functions = functions(&found.body.statements);
|
|
803
|
+
let layout = run_method(script, &functions, found.run, found.machine).unwrap();
|
|
804
|
+
assert_eq!(
|
|
805
|
+
(&*layout.registers, &*layout.cells, &*layout.program),
|
|
806
|
+
("registers", "cells", "program")
|
|
807
|
+
);
|
|
808
|
+
let super::super::registers::Access::Functions { read, write } = layout.access else {
|
|
809
|
+
panic!("expected free register accessors");
|
|
810
|
+
};
|
|
811
|
+
assert_eq!(read.id.as_ref().unwrap().name, "load");
|
|
812
|
+
assert_eq!(write.id.as_ref().unwrap().name, "store");
|
|
813
|
+
assert_eq!(
|
|
814
|
+
layout.dispatch.arguments,
|
|
815
|
+
vec![
|
|
816
|
+
Argument::Machine,
|
|
817
|
+
Argument::Registers,
|
|
818
|
+
Argument::Other,
|
|
819
|
+
Argument::Program
|
|
820
|
+
]
|
|
821
|
+
);
|
|
822
|
+
let handlers = handlers(script, &functions, &layout.dispatch).unwrap();
|
|
823
|
+
assert_eq!(handlers[&42].id.as_ref().unwrap().name, "opcode");
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
#[test]
|
|
827
|
+
fn method_runner_selects_its_constructed_class() {
|
|
828
|
+
let parsed = ParsedScript::parse(
|
|
829
|
+
"two classes",
|
|
830
|
+
r#"
|
|
831
|
+
function scope(global) {
|
|
832
|
+
class Unrelated { run() {} }
|
|
833
|
+
class Machine { run() {} }
|
|
834
|
+
global.start = function(program) { return new Machine(program).run(0, 1, []); };
|
|
835
|
+
}
|
|
836
|
+
"#,
|
|
837
|
+
)
|
|
838
|
+
.unwrap();
|
|
839
|
+
let found = find(parsed.script()).unwrap();
|
|
840
|
+
assert_eq!(found.class.id.as_ref().unwrap().name, "Machine");
|
|
841
|
+
assert!(found.machine.is_none());
|
|
842
|
+
}
|
|
843
|
+
|
|
552
844
|
#[test]
|
|
553
845
|
fn names_the_runner_its_callers_call() {
|
|
554
|
-
let parsed =
|
|
846
|
+
let parsed = ParsedScript::parse(
|
|
555
847
|
"t",
|
|
556
848
|
"O.vlJM8 = function(p) { return new M(p).run(0, 238, []); }; \
|
|
557
849
|
O.other = function(p) { return M(p).run(0, 238, []); }; O.vlJM8('a'); vlJM8('b');",
|
|
558
850
|
)
|
|
559
851
|
.unwrap();
|
|
560
|
-
let
|
|
852
|
+
let script = parsed.script();
|
|
853
|
+
let name = runner_name(script).unwrap();
|
|
561
854
|
assert_eq!(name, "vlJM8");
|
|
562
|
-
let calls: Vec<&
|
|
563
|
-
.
|
|
855
|
+
let calls: Vec<&CallExpression<'_>> = script
|
|
856
|
+
.program
|
|
564
857
|
.body
|
|
565
858
|
.iter()
|
|
566
|
-
.filter_map(|statement| statement
|
|
859
|
+
.filter_map(|statement| match statement {
|
|
860
|
+
Statement::ExpressionStatement(statement) => match &statement.expression {
|
|
861
|
+
Expression::CallExpression(call) => Some(&**call),
|
|
862
|
+
_ => None,
|
|
863
|
+
},
|
|
864
|
+
_ => None,
|
|
865
|
+
})
|
|
567
866
|
.collect();
|
|
867
|
+
assert_eq!(calls.len(), 2);
|
|
568
868
|
assert!(calls.iter().all(|call| calls_runner(call, &name)));
|
|
569
869
|
}
|
|
570
870
|
}
|