cfsolve 0.1.1 → 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 +18 -0
- data/README.md +10 -9
- 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 +10 -8
- 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 +2570 -1894
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
- data/lib/cfsolve/profiles/safari-26-ios.json +102 -156
- 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 -35
- data/vendor/cfsolve/examples/build_profile.rs +17 -15
- data/vendor/cfsolve/examples/capture_session.rs +37 -0
- data/vendor/cfsolve/examples/check_answers.rs +66 -0
- data/vendor/cfsolve/examples/compare_session.rs +189 -0
- 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 +6 -3
- 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 +2570 -1894
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1867 -1192
- data/vendor/cfsolve/profiles/safari-26-ios.json +102 -156
- data/vendor/cfsolve/scripts/capture_cssom.mjs +42 -0
- data/vendor/cfsolve/scripts/serve_cssom.py +111 -0
- 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/profile.rs +7 -18
- data/vendor/cfsolve/src/capture/proxy/tests.rs +1 -1
- data/vendor/cfsolve/src/capture/proxy.rs +44 -13
- data/vendor/cfsolve/src/capture/recorded.rs +42 -7
- 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 +132 -0
- data/vendor/cfsolve/src/challenge/installed.rs +127 -269
- 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 +175 -35
- 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 +236 -122
- 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 +201 -205
- data/vendor/cfsolve/src/deobfuscate/function_lengths.rs +32 -38
- data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +346 -536
- 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 +361 -322
- 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 -32
- data/vendor/cfsolve/src/embedding_page/page.rs +28 -2
- 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 +9 -1
- data/vendor/cfsolve/src/http/requests.rs +2 -2
- data/vendor/cfsolve/src/js/ast.rs +479 -254
- data/vendor/cfsolve/src/js/objects.rs +9 -2
- data/vendor/cfsolve/src/lib.rs +1 -0
- data/vendor/cfsolve/src/listing/fold.rs +19 -92
- data/vendor/cfsolve/src/listing/query.rs +26 -291
- data/vendor/cfsolve/src/listing.rs +0 -1
- 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 +19 -10
- data/vendor/cfsolve/src/session/probes.rs +160 -125
- 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/timing.rs +58 -53
- data/vendor/cfsolve/src/session/widget.rs +5 -6
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/solver.rs +3 -1
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +50 -33
- data/vendor/cfsolve/src/stage2/analysis/audit.rs +4 -2
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +61 -66
- data/vendor/cfsolve/src/stage2/analysis/envelope.rs +33 -22
- data/vendor/cfsolve/src/stage2/analysis/recognize.rs +3 -5
- data/vendor/cfsolve/src/stage2/analysis.rs +0 -1
- data/vendor/cfsolve/src/stage2/audit_globals.rs +378 -0
- data/vendor/cfsolve/src/stage2/benchmark.rs +66 -38
- data/vendor/cfsolve/src/stage2/call_stack.rs +1463 -1017
- 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/native.rs +2 -1
- data/vendor/cfsolve/src/stage2/interaction/plan.rs +5 -7
- data/vendor/cfsolve/src/stage2/payload/recover.rs +56 -25
- data/vendor/cfsolve/src/stage2/probes/clock.rs +1 -3
- data/vendor/cfsolve/src/stage2/probes/ice.rs +11 -10
- data/vendor/cfsolve/src/stage2/probes/media.rs +47 -33
- data/vendor/cfsolve/src/stage2/probes/performance.rs +13 -8
- data/vendor/cfsolve/src/stage2/probes/rects.rs +12 -17
- data/vendor/cfsolve/src/stage2/probes/stack.rs +50 -103
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +17 -86
- data/vendor/cfsolve/src/stage2/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/queries.rs +50 -0
- data/vendor/cfsolve/src/stage2/records.rs +4 -13
- data/vendor/cfsolve/src/stage2/reference.json +1 -1
- data/vendor/cfsolve/src/stage2/reference.rs +98 -100
- data/vendor/cfsolve/src/stage2/registry.rs +41 -34
- data/vendor/cfsolve/src/stage2/replay.rs +182 -254
- data/vendor/cfsolve/src/stage2/stylesheets.rs +176 -0
- data/vendor/cfsolve/src/stage2/syntax.rs +88 -0
- data/vendor/cfsolve/src/stage2/trace.rs +152 -108
- data/vendor/cfsolve/src/stage2/vocabulary.rs +103 -403
- data/vendor/cfsolve/src/stage2.rs +4 -1
- data/vendor/cfsolve/src/vm/disassemble.rs +46 -13
- 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 +67 -68
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +16 -63
- data/vendor/cfsolve/src/vm/interpret/call.rs +192 -51
- data/vendor/cfsolve/src/vm/interpret/compile.rs +643 -0
- data/vendor/cfsolve/src/vm/interpret/copies.rs +232 -120
- data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +149 -40
- data/vendor/cfsolve/src/vm/interpret/evaluate.rs +189 -572
- data/vendor/cfsolve/src/vm/interpret/explore.rs +159 -46
- data/vendor/cfsolve/src/vm/interpret/formula.rs +131 -0
- data/vendor/cfsolve/src/vm/interpret/frozen.rs +169 -0
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +414 -0
- 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 +605 -330
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +384 -0
- data/vendor/cfsolve/src/vm/interpret/run.rs +314 -54
- 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 +16 -3
- data/vendor/cfsolve/src/vm/machine.rs +58 -47
- data/vendor/cfsolve/src/vm/output.rs +13 -5
- data/vendor/cfsolve/src/vm/packed_names.rs +311 -0
- data/vendor/cfsolve/src/vm/session.rs +197 -110
- data/vendor/cfsolve/src/vm/value.rs +35 -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
- data/vendor/cfsolve/vendor/btls-sys/src/lib.rs +3 -0
- metadata +106 -183
- 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/vendor/cfsolve/src/listing/normalize.rs +0 -264
- data/vendor/cfsolve/src/stage2/analysis/outputs.rs +0 -327
- data/vendor/cfsolve/src/stage2/probes/stylesheets.rs +0 -249
- data/vendor/cfsolve/src/stage2/reference-expanded.json +0 -42
- data/vendor/cfsolve/src/stage2/session_names.rs +0 -470
- /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,93 +2,125 @@
|
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
self.found = Some((body.clone(), class.clone()));
|
|
30
|
-
}
|
|
31
|
-
function.visit_children_with(self);
|
|
32
|
-
}
|
|
21
|
+
use crate::candidates;
|
|
22
|
+
use crate::js::ast::{self, Binding, Script};
|
|
23
|
+
|
|
24
|
+
/// Finds a class with a `run` method and the innermost function body declaring it: the last such
|
|
25
|
+
/// body in source order.
|
|
26
|
+
pub(super) fn find<'a>(script: Script<'a>) -> Option<(&'a FunctionBody<'a>, &'a Class<'a>)> {
|
|
27
|
+
script
|
|
28
|
+
.functions()
|
|
29
|
+
.filter_map(|function| {
|
|
30
|
+
let body = function.body.as_deref()?;
|
|
31
|
+
Some((body, machine_class(body)?))
|
|
32
|
+
})
|
|
33
|
+
.last()
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
/// 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
|
-
|
|
37
|
+
/// in each enclosing function: at each level, the statements before the one containing `body`.
|
|
38
|
+
pub(super) fn prelude<'a>(
|
|
39
|
+
script: Script<'a>,
|
|
40
|
+
body: &'a FunctionBody<'a>,
|
|
41
|
+
) -> Vec<&'a Statement<'a>> {
|
|
42
|
+
let mut enclosing: Vec<&'a [Statement<'a>]> = script
|
|
43
|
+
.nodes
|
|
44
|
+
.ancestor_kinds(body.node_id.get())
|
|
45
|
+
.filter_map(|kind| match kind {
|
|
46
|
+
AstKind::Function(function) => function.body.as_deref(),
|
|
47
|
+
_ => None,
|
|
48
|
+
})
|
|
49
|
+
.filter(|enclosing| !ptr::eq(*enclosing, body))
|
|
50
|
+
.map(|enclosing| &enclosing.statements[..])
|
|
51
|
+
.collect();
|
|
52
|
+
enclosing.push(&script.program.body);
|
|
55
53
|
let mut prelude = Vec::new();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
target: body.span,
|
|
63
|
-
body: None,
|
|
54
|
+
for statements in enclosing.into_iter().rev() {
|
|
55
|
+
let Some(index) = statements
|
|
56
|
+
.iter()
|
|
57
|
+
.position(|statement| statement.span().contains_inclusive(body.span))
|
|
58
|
+
else {
|
|
59
|
+
break;
|
|
64
60
|
};
|
|
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
|
-
}
|
|
61
|
+
prelude.extend(&statements[..index]);
|
|
72
62
|
}
|
|
73
63
|
prelude
|
|
74
64
|
}
|
|
75
65
|
|
|
76
66
|
/// Functions declared beside the class: handlers and their helpers.
|
|
77
|
-
pub(super) fn functions
|
|
67
|
+
pub(super) fn functions<'a>(
|
|
68
|
+
statements: &'a [Statement<'a>],
|
|
69
|
+
) -> HashMap<SymbolId, &'a Function<'a>> {
|
|
78
70
|
statements
|
|
79
71
|
.iter()
|
|
80
|
-
.filter_map(|statement| {
|
|
81
|
-
|
|
82
|
-
|
|
72
|
+
.filter_map(|statement| match statement {
|
|
73
|
+
Statement::FunctionDeclaration(function) => {
|
|
74
|
+
Some((function.id.as_ref()?.symbol_id(), &**function))
|
|
75
|
+
}
|
|
76
|
+
_ => None,
|
|
83
77
|
})
|
|
84
78
|
.collect()
|
|
85
79
|
}
|
|
86
80
|
|
|
87
|
-
|
|
81
|
+
/// Every parameter, if each is a plain identifier: no pattern, default, or rest.
|
|
82
|
+
pub(super) fn parameters<'a>(
|
|
83
|
+
parameters: &'a FormalParameters<'a>,
|
|
84
|
+
) -> Option<Vec<&'a BindingIdentifier<'a>>> {
|
|
85
|
+
if parameters.rest.is_some() {
|
|
86
|
+
return None;
|
|
87
|
+
}
|
|
88
|
+
(0..parameters.items.len())
|
|
89
|
+
.map(|index| parameter(parameters, index))
|
|
90
|
+
.collect()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// The parameter at `index`, if it is a plain identifier.
|
|
94
|
+
pub(super) fn parameter<'a>(
|
|
95
|
+
parameters: &'a FormalParameters<'a>,
|
|
96
|
+
index: usize,
|
|
97
|
+
) -> Option<&'a BindingIdentifier<'a>> {
|
|
98
|
+
let parameter = parameters.items.get(index)?;
|
|
99
|
+
match ¶meter.pattern {
|
|
100
|
+
BindingPattern::BindingIdentifier(name) if parameter.initializer.is_none() => Some(name),
|
|
101
|
+
_ => None,
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/// The number of parameters, including a rest parameter.
|
|
106
|
+
pub(super) fn parameter_count(parameters: &FormalParameters<'_>) -> usize {
|
|
107
|
+
parameters.items.len() + usize::from(parameters.rest.is_some())
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// The constructor's statements.
|
|
111
|
+
pub(super) fn constructor<'a>(class: &'a Class<'a>) -> Result<&'a [Statement<'a>]> {
|
|
88
112
|
class
|
|
113
|
+
.body
|
|
89
114
|
.body
|
|
90
115
|
.iter()
|
|
91
|
-
.find_map(|
|
|
116
|
+
.find_map(|element| match element {
|
|
117
|
+
ClassElement::MethodDefinition(method)
|
|
118
|
+
if method.kind == MethodDefinitionKind::Constructor =>
|
|
119
|
+
{
|
|
120
|
+
Some(&method.value.body.as_deref()?.statements[..])
|
|
121
|
+
}
|
|
122
|
+
_ => None,
|
|
123
|
+
})
|
|
92
124
|
.context("the VM class has no constructor")
|
|
93
125
|
}
|
|
94
126
|
|
|
@@ -120,7 +152,7 @@ pub(super) struct RunMethod<'ast> {
|
|
|
120
152
|
/// Dispatch function declared beside the class and called by `run` with the machine. Some builds
|
|
121
153
|
/// move both loops out of `run`; both dispatch the same handlers.
|
|
122
154
|
pub(crate) struct DispatchLoop<'ast> {
|
|
123
|
-
pub function: &'ast Function
|
|
155
|
+
pub function: &'ast Function<'ast>,
|
|
124
156
|
/// Argument values passed by `run`, in parameter order.
|
|
125
157
|
pub arguments: Vec<Argument>,
|
|
126
158
|
}
|
|
@@ -136,65 +168,72 @@ pub(crate) enum Argument {
|
|
|
136
168
|
|
|
137
169
|
impl DispatchLoop<'_> {
|
|
138
170
|
/// The parameter receiving the machine.
|
|
139
|
-
fn machine(&self) -> Option
|
|
171
|
+
fn machine(&self) -> Option<SymbolId> {
|
|
140
172
|
let position = self
|
|
141
173
|
.arguments
|
|
142
174
|
.iter()
|
|
143
175
|
.position(|argument| *argument == Argument::Machine)?;
|
|
144
|
-
Some(&self.function.params
|
|
176
|
+
Some(parameter(&self.function.params, position)?.symbol_id())
|
|
145
177
|
}
|
|
146
178
|
}
|
|
147
179
|
|
|
180
|
+
/// The locals of `run` and what they hold.
|
|
181
|
+
struct Locals<'a> {
|
|
182
|
+
script: Script<'a>,
|
|
183
|
+
sources: HashMap<Binding<'a>, Source>,
|
|
184
|
+
}
|
|
185
|
+
|
|
148
186
|
/// Tracks assignments in `run`, including copies of register fields and indices, program counter
|
|
149
187
|
/// and key setup, storing the third argument in the cells register, reading the program register,
|
|
150
188
|
/// and calling dispatch loops. An unsupported assignment clears the known value of its local.
|
|
151
189
|
pub(super) fn run_method<'a>(
|
|
152
|
-
|
|
153
|
-
|
|
190
|
+
script: Script<'a>,
|
|
191
|
+
functions: &HashMap<SymbolId, &'a Function<'a>>,
|
|
192
|
+
run: &'a Function<'a>,
|
|
154
193
|
) -> Result<RunMethod<'a>> {
|
|
155
|
-
let body = run.body.
|
|
156
|
-
let
|
|
157
|
-
.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
.filter_map(|(index, parameter)| {
|
|
161
|
-
Some((
|
|
162
|
-
parameter.pat.as_ident()?.sym.clone(),
|
|
163
|
-
Source::Parameter(index),
|
|
164
|
-
))
|
|
194
|
+
let body = run.body.as_deref().context("the run method has no body")?;
|
|
195
|
+
let sources = (0..run.params.items.len())
|
|
196
|
+
.filter_map(|index| {
|
|
197
|
+
let name = parameter(&run.params, index)?;
|
|
198
|
+
Some((Binding::Symbol(name.symbol_id()), Source::Parameter(index)))
|
|
165
199
|
})
|
|
166
200
|
.collect();
|
|
201
|
+
let mut locals = Locals { script, sources };
|
|
167
202
|
let mut cells = None;
|
|
168
203
|
let mut loaded = Vec::new();
|
|
169
|
-
for statement in &body.
|
|
170
|
-
let
|
|
204
|
+
for statement in &body.statements {
|
|
205
|
+
let Statement::ExpressionStatement(statement) = statement else {
|
|
171
206
|
continue;
|
|
172
207
|
};
|
|
173
|
-
let expressions: Vec<&
|
|
174
|
-
|
|
175
|
-
|
|
208
|
+
let expressions: Vec<&Expression<'a>> = match &statement.expression {
|
|
209
|
+
Expression::SequenceExpression(sequence) => sequence.expressions.iter().collect(),
|
|
210
|
+
expression => vec![expression],
|
|
176
211
|
};
|
|
177
|
-
for
|
|
178
|
-
if let Some((Source::Field(registers), arguments)) =
|
|
212
|
+
for expression in expressions {
|
|
213
|
+
if let Some((Source::Field(registers), arguments)) =
|
|
214
|
+
locals.method_call(expression, "write")
|
|
179
215
|
&& let [Some(Source::Field(index)), Some(Source::Parameter(2))] = &arguments[..]
|
|
180
216
|
{
|
|
181
217
|
cells = Some((registers, index.clone()));
|
|
182
218
|
continue;
|
|
183
219
|
}
|
|
184
|
-
let
|
|
185
|
-
|
|
220
|
+
let Expression::AssignmentExpression(assignment) = expression else {
|
|
221
|
+
continue;
|
|
222
|
+
};
|
|
223
|
+
let AssignmentTarget::AssignmentTargetIdentifier(name) = &assignment.left else {
|
|
186
224
|
continue;
|
|
187
225
|
};
|
|
188
|
-
let value = match
|
|
189
|
-
|
|
226
|
+
let value = match assignment.operator {
|
|
227
|
+
AssignmentOperator::Assign => locals.source(&assignment.right),
|
|
190
228
|
_ => None,
|
|
191
229
|
};
|
|
192
230
|
if let Some(Source::Register { registers, index }) = &value {
|
|
193
231
|
loaded.push((registers.clone(), index.clone()));
|
|
194
232
|
}
|
|
233
|
+
let binding = script.binding(name);
|
|
195
234
|
match value {
|
|
196
|
-
Some(value) => locals.insert(
|
|
197
|
-
None => locals.remove(&
|
|
235
|
+
Some(value) => locals.sources.insert(binding, value),
|
|
236
|
+
None => locals.sources.remove(&binding),
|
|
198
237
|
};
|
|
199
238
|
}
|
|
200
239
|
}
|
|
@@ -211,19 +250,20 @@ pub(super) fn run_method<'a>(
|
|
|
211
250
|
};
|
|
212
251
|
let program = program.clone();
|
|
213
252
|
let mut calls = DispatchCall {
|
|
253
|
+
script,
|
|
214
254
|
functions,
|
|
215
255
|
found: None,
|
|
216
256
|
};
|
|
217
|
-
|
|
257
|
+
calls.visit_function_body(body);
|
|
218
258
|
let (function, call) = calls
|
|
219
259
|
.found
|
|
220
260
|
.context("the run method calls no dispatch loop with the machine")?;
|
|
221
261
|
let arguments = call
|
|
222
|
-
.
|
|
262
|
+
.arguments
|
|
223
263
|
.iter()
|
|
224
|
-
.map(|argument| match
|
|
225
|
-
|
|
226
|
-
|
|
264
|
+
.map(|argument| match ast::argument_expression(argument) {
|
|
265
|
+
Expression::ThisExpression(_) => Argument::Machine,
|
|
266
|
+
Expression::Identifier(name) => match locals.sources.get(&script.binding(name)) {
|
|
227
267
|
Some(Source::Field(field)) if *field == registers => Argument::Registers,
|
|
228
268
|
Some(Source::Register { index, .. }) if *index == program => Argument::Program,
|
|
229
269
|
_ => Argument::Other,
|
|
@@ -244,122 +284,149 @@ pub(super) fn run_method<'a>(
|
|
|
244
284
|
|
|
245
285
|
/// Finds the first call in `run` whose first argument is the machine and whose target contains a
|
|
246
286
|
/// dispatch switch.
|
|
247
|
-
struct DispatchCall<'functions, '
|
|
248
|
-
|
|
249
|
-
|
|
287
|
+
struct DispatchCall<'functions, 'a> {
|
|
288
|
+
script: Script<'a>,
|
|
289
|
+
functions: &'functions HashMap<SymbolId, &'a Function<'a>>,
|
|
290
|
+
found: Option<(&'a Function<'a>, &'a CallExpression<'a>)>,
|
|
250
291
|
}
|
|
251
292
|
|
|
252
|
-
impl Visit for DispatchCall<'_, '
|
|
253
|
-
fn
|
|
293
|
+
impl<'a> Visit<'a> for DispatchCall<'_, 'a> {
|
|
294
|
+
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
254
295
|
if self.found.is_none()
|
|
255
|
-
&& call
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
296
|
+
&& call.arguments.first().is_some_and(|first| {
|
|
297
|
+
matches!(
|
|
298
|
+
ast::argument_expression(first),
|
|
299
|
+
Expression::ThisExpression(_)
|
|
300
|
+
)
|
|
301
|
+
})
|
|
302
|
+
&& let Expression::Identifier(callee) = &call.callee
|
|
303
|
+
&& let Some(symbol) = self.script.symbol(callee)
|
|
304
|
+
&& let Some(&function) = self.functions.get(&symbol)
|
|
261
305
|
&& first_switch_in(function).is_some()
|
|
262
306
|
{
|
|
263
|
-
self.found = Some((
|
|
307
|
+
self.found = Some((
|
|
308
|
+
function,
|
|
309
|
+
self.script.lend(call, AstKind::as_call_expression),
|
|
310
|
+
));
|
|
264
311
|
}
|
|
265
|
-
|
|
312
|
+
walk::walk_call_expression(self, call);
|
|
266
313
|
}
|
|
267
314
|
}
|
|
268
315
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
316
|
+
impl<'a> Locals<'a> {
|
|
317
|
+
/// Resolves `<object>.<name>(<arguments>)`, including the values of the object and
|
|
318
|
+
/// arguments.
|
|
319
|
+
fn method_call(
|
|
320
|
+
&self,
|
|
321
|
+
expression: &Expression<'a>,
|
|
322
|
+
name: &str,
|
|
323
|
+
) -> Option<(Source, Vec<Option<Source>>)> {
|
|
324
|
+
let (object, arguments) = ast::method_call(expression, name)?;
|
|
325
|
+
let arguments = arguments
|
|
326
|
+
.iter()
|
|
327
|
+
.map(|argument| self.source(ast::argument_expression(argument)))
|
|
328
|
+
.collect();
|
|
329
|
+
Some((self.source(object)?, arguments))
|
|
330
|
+
}
|
|
282
331
|
|
|
283
|
-
fn source(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}),
|
|
332
|
+
fn source(&self, expression: &Expression<'a>) -> Option<Source> {
|
|
333
|
+
match expression {
|
|
334
|
+
Expression::Identifier(name) => self.sources.get(&self.script.binding(name)).cloned(),
|
|
335
|
+
Expression::ParenthesizedExpression(paren) => self.source(&paren.expression),
|
|
336
|
+
Expression::CallExpression(_) => match self.method_call(expression, "read")? {
|
|
337
|
+
(Source::Field(registers), arguments) => match &arguments[..] {
|
|
338
|
+
[Some(Source::Field(index))] => Some(Source::Register {
|
|
339
|
+
registers,
|
|
340
|
+
index: index.clone(),
|
|
341
|
+
}),
|
|
342
|
+
_ => None,
|
|
343
|
+
},
|
|
296
344
|
_ => None,
|
|
297
345
|
},
|
|
298
|
-
|
|
299
|
-
}
|
|
346
|
+
expression => Some(Source::Field(this_field(expression)?.to_owned())),
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/// The field `this.<field>` reads.
|
|
352
|
+
pub(super) fn this_field<'a>(expression: &Expression<'a>) -> Option<&'a str> {
|
|
353
|
+
let member = expression.as_member_expression()?;
|
|
354
|
+
match member.object() {
|
|
355
|
+
Expression::ThisExpression(_) => ast::member_str(member),
|
|
300
356
|
_ => None,
|
|
301
357
|
}
|
|
302
358
|
}
|
|
303
359
|
|
|
304
360
|
/// Finds the string decryption function called by the register reader as
|
|
305
361
|
/// `decrypt(this.<values>[index])`.
|
|
306
|
-
pub(super) fn record_decoder
|
|
362
|
+
pub(super) fn record_decoder<'a>(
|
|
363
|
+
script: Script<'a>,
|
|
364
|
+
body: &'a FunctionBody<'a>,
|
|
365
|
+
) -> Option<SymbolId> {
|
|
307
366
|
/// Matches `<decoder>(this.<values>[<index>])`.
|
|
308
|
-
struct Decoders {
|
|
309
|
-
|
|
310
|
-
|
|
367
|
+
struct Decoders<'a> {
|
|
368
|
+
script: Script<'a>,
|
|
369
|
+
index: SymbolId,
|
|
370
|
+
found: Vec<Binding<'a>>,
|
|
311
371
|
}
|
|
312
372
|
|
|
313
|
-
impl Visit for Decoders {
|
|
314
|
-
fn
|
|
315
|
-
if let
|
|
316
|
-
&& let [argument] = &call.
|
|
317
|
-
&& let Some(member) = argument.
|
|
373
|
+
impl<'a> Visit<'a> for Decoders<'a> {
|
|
374
|
+
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
375
|
+
if let Expression::Identifier(callee) = &call.callee
|
|
376
|
+
&& let [argument] = &call.arguments[..]
|
|
377
|
+
&& let Some(member) = ast::argument_expression(argument).as_member_expression()
|
|
318
378
|
&& member
|
|
319
|
-
.
|
|
320
|
-
.
|
|
321
|
-
.is_some_and(|values| values.
|
|
322
|
-
&& member
|
|
323
|
-
|
|
324
|
-
.as_computed()
|
|
325
|
-
.and_then(|index| index.expr.as_ident())
|
|
326
|
-
.is_some_and(|name| name.sym == self.index)
|
|
379
|
+
.object()
|
|
380
|
+
.as_member_expression()
|
|
381
|
+
.is_some_and(|values| matches!(values.object(), Expression::ThisExpression(_)))
|
|
382
|
+
&& let MemberExpression::ComputedMemberExpression(member) = member
|
|
383
|
+
&& self.script.refers_to(&member.expression, self.index)
|
|
327
384
|
{
|
|
328
|
-
self.found.push(
|
|
385
|
+
self.found.push(self.script.binding(callee));
|
|
329
386
|
}
|
|
330
|
-
|
|
387
|
+
walk::walk_call_expression(self, call);
|
|
331
388
|
}
|
|
332
389
|
}
|
|
333
390
|
|
|
334
|
-
let read = body
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
391
|
+
let read = body
|
|
392
|
+
.statements
|
|
393
|
+
.iter()
|
|
394
|
+
.find_map(|statement| match statement {
|
|
395
|
+
Statement::ClassDeclaration(class) if method(class, "write").is_some() => {
|
|
396
|
+
method(class, "read")
|
|
397
|
+
}
|
|
398
|
+
_ => None,
|
|
399
|
+
})?;
|
|
340
400
|
let mut decoders = Decoders {
|
|
341
|
-
|
|
401
|
+
script,
|
|
402
|
+
index: parameter(&read.params, 0)?.symbol_id(),
|
|
342
403
|
found: Vec::new(),
|
|
343
404
|
};
|
|
344
|
-
|
|
345
|
-
let [decoder]
|
|
405
|
+
decoders.visit_function(read, ScopeFlags::Function);
|
|
406
|
+
let [Binding::Symbol(decoder)] = decoders.found[..] else {
|
|
407
|
+
return None;
|
|
408
|
+
};
|
|
346
409
|
Some(decoder)
|
|
347
410
|
}
|
|
348
411
|
|
|
349
412
|
/// The first class declaration with a `run` method.
|
|
350
|
-
fn machine_class(body: &
|
|
351
|
-
body.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
413
|
+
fn machine_class<'a>(body: &'a FunctionBody<'a>) -> Option<&'a Class<'a>> {
|
|
414
|
+
body.statements
|
|
415
|
+
.iter()
|
|
416
|
+
.find_map(|statement| match statement {
|
|
417
|
+
Statement::ClassDeclaration(class) if method(class, "run").is_some() => Some(&**class),
|
|
418
|
+
_ => None,
|
|
419
|
+
})
|
|
357
420
|
}
|
|
358
421
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
422
|
+
/// The method, getter, or setter named `name`, excluding the constructor.
|
|
423
|
+
pub(super) fn method<'a>(class: &'a Class<'a>, name: &str) -> Option<&'a Function<'a>> {
|
|
424
|
+
class.body.body.iter().find_map(|element| match element {
|
|
425
|
+
ClassElement::MethodDefinition(method)
|
|
426
|
+
if method.kind != MethodDefinitionKind::Constructor
|
|
427
|
+
&& ast::static_key_str(&method.key, method.computed) == Some(name) =>
|
|
428
|
+
{
|
|
429
|
+
Some(&*method.value)
|
|
363
430
|
}
|
|
364
431
|
_ => None,
|
|
365
432
|
})
|
|
@@ -367,40 +434,46 @@ pub(super) fn method<'a>(class: &'a Class, name: &str) -> Option<&'a Function> {
|
|
|
367
434
|
|
|
368
435
|
/// Extracts opcode and handler pairs from `case <opcode>: <handler>(<machine>); break;`.
|
|
369
436
|
pub(super) fn handlers<'a>(
|
|
370
|
-
|
|
437
|
+
script: Script<'a>,
|
|
438
|
+
functions: &HashMap<SymbolId, &'a Function<'a>>,
|
|
371
439
|
dispatch: &DispatchLoop<'a>,
|
|
372
|
-
) -> Result<HashMap<u8, &'a Function
|
|
440
|
+
) -> Result<HashMap<u8, &'a Function<'a>>> {
|
|
373
441
|
let switch = first_switch_in(dispatch.function).context("the dispatch loop has no switch")?;
|
|
374
442
|
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)
|
|
443
|
+
let is_machine = |argument: &CallArgument<'_>| {
|
|
444
|
+
argument.as_expression().is_some_and(|argument| {
|
|
445
|
+
machine.is_some_and(|machine| script.refers_to(argument, machine))
|
|
446
|
+
})
|
|
381
447
|
};
|
|
382
448
|
let mut handlers = HashMap::default();
|
|
383
449
|
for case in &switch.cases {
|
|
384
450
|
let Some(test) = &case.test else { continue };
|
|
385
|
-
let
|
|
451
|
+
let Expression::NumericLiteral(opcode) = test else {
|
|
386
452
|
bail!("a dispatch case is not a number");
|
|
387
453
|
};
|
|
388
454
|
let opcode = convert::byte(opcode.value).context("a dispatch case is not an opcode")?;
|
|
389
455
|
let call = case
|
|
390
|
-
.
|
|
456
|
+
.consequent
|
|
391
457
|
.iter()
|
|
392
|
-
.find_map(|statement| statement
|
|
458
|
+
.find_map(|statement| match statement {
|
|
459
|
+
Statement::ExpressionStatement(statement) => match &statement.expression {
|
|
460
|
+
Expression::CallExpression(call) => Some(call),
|
|
461
|
+
_ => None,
|
|
462
|
+
},
|
|
463
|
+
_ => None,
|
|
464
|
+
})
|
|
393
465
|
.with_context(|| format!("dispatch case {opcode} calls no handler"))?;
|
|
394
|
-
let
|
|
466
|
+
let Expression::Identifier(name) = &call.callee else {
|
|
395
467
|
bail!("dispatch case {opcode} calls no named handler");
|
|
396
468
|
};
|
|
397
|
-
let function =
|
|
398
|
-
.
|
|
399
|
-
.
|
|
469
|
+
let function = script
|
|
470
|
+
.symbol(name)
|
|
471
|
+
.and_then(|symbol| functions.get(&symbol))
|
|
472
|
+
.with_context(|| format!("no handler function {}", name.name))?;
|
|
400
473
|
ensure!(
|
|
401
|
-
matches!(&call.
|
|
474
|
+
matches!(&call.arguments[..], [argument] if is_machine(argument)),
|
|
402
475
|
"dispatch case {opcode} does not pass {} only the machine",
|
|
403
|
-
name.
|
|
476
|
+
name.name
|
|
404
477
|
);
|
|
405
478
|
let previous = handlers.insert(opcode, *function);
|
|
406
479
|
ensure!(previous.is_none(), "opcode {opcode} has two dispatch cases");
|
|
@@ -409,30 +482,41 @@ pub(super) fn handlers<'a>(
|
|
|
409
482
|
}
|
|
410
483
|
|
|
411
484
|
/// Finds the first dispatch switch in the body of `function`.
|
|
412
|
-
fn first_switch_in(function: &Function) -> Option<&
|
|
413
|
-
function
|
|
485
|
+
fn first_switch_in<'a>(function: &'a Function<'a>) -> Option<&'a SwitchStatement<'a>> {
|
|
486
|
+
function
|
|
487
|
+
.body
|
|
488
|
+
.as_deref()?
|
|
489
|
+
.statements
|
|
490
|
+
.iter()
|
|
491
|
+
.find_map(first_switch)
|
|
414
492
|
}
|
|
415
493
|
|
|
416
494
|
/// Finds the first dispatch `switch`; both dispatch loops use the same form.
|
|
417
|
-
fn first_switch(statement: &
|
|
495
|
+
fn first_switch<'a>(statement: &'a Statement<'a>) -> Option<&'a SwitchStatement<'a>> {
|
|
418
496
|
match statement {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
first_switch(&branch.
|
|
497
|
+
Statement::SwitchStatement(switch) => Some(switch),
|
|
498
|
+
Statement::BlockStatement(block) => block.body.iter().find_map(first_switch),
|
|
499
|
+
Statement::WhileStatement(looping) => first_switch(&looping.body),
|
|
500
|
+
Statement::IfStatement(branch) => {
|
|
501
|
+
first_switch(&branch.consequent).or_else(|| first_switch(branch.alternate.as_ref()?))
|
|
424
502
|
}
|
|
425
|
-
|
|
503
|
+
Statement::TryStatement(attempt) => attempt.block.body.iter().find_map(first_switch),
|
|
426
504
|
_ => None,
|
|
427
505
|
}
|
|
428
506
|
}
|
|
429
507
|
|
|
430
508
|
/// Where the program runner starts a program (see [`Runner`]).
|
|
431
|
-
pub(super) fn entry(body: &
|
|
509
|
+
pub(super) fn entry(body: &FunctionBody<'_>) -> Result<Position> {
|
|
432
510
|
let runner = body
|
|
433
|
-
.
|
|
511
|
+
.statements
|
|
434
512
|
.iter()
|
|
435
|
-
.find_map(|statement|
|
|
513
|
+
.find_map(|statement| match statement {
|
|
514
|
+
Statement::ExpressionStatement(statement) => match &statement.expression {
|
|
515
|
+
Expression::AssignmentExpression(assignment) => Runner::installed_by(assignment),
|
|
516
|
+
_ => None,
|
|
517
|
+
},
|
|
518
|
+
_ => None,
|
|
519
|
+
})
|
|
436
520
|
.context("no program runner in the VM's scope")?;
|
|
437
521
|
let pc = convert::position(runner.pc).context("the runner starts at no program position")?;
|
|
438
522
|
let key = convert::byte(runner.key).context("the runner starts with no dispatch key")?;
|
|
@@ -451,29 +535,39 @@ struct Runner<'ast> {
|
|
|
451
535
|
}
|
|
452
536
|
|
|
453
537
|
impl<'ast> Runner<'ast> {
|
|
454
|
-
fn installed_by(
|
|
455
|
-
let
|
|
538
|
+
fn installed_by(assignment: &AssignmentExpression<'ast>) -> Option<Self> {
|
|
539
|
+
let target = assignment.left.as_member_expression()?;
|
|
540
|
+
if matches!(target.object(), Expression::Super(_)) {
|
|
541
|
+
return None;
|
|
542
|
+
}
|
|
543
|
+
let Expression::FunctionExpression(function) = &assignment.right else {
|
|
456
544
|
return None;
|
|
457
545
|
};
|
|
458
|
-
let body =
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
] = after_bare_declarations(&body.stmts)
|
|
546
|
+
let body = function.body.as_deref()?;
|
|
547
|
+
if !body.directives.is_empty() {
|
|
548
|
+
return None;
|
|
549
|
+
}
|
|
550
|
+
let [Statement::ReturnStatement(returned)] = after_bare_declarations(&body.statements)
|
|
464
551
|
else {
|
|
465
552
|
return None;
|
|
466
553
|
};
|
|
467
|
-
let (machine, [pc, key, ..]) = ast::method_call(
|
|
554
|
+
let (machine, [pc, key, ..]) = ast::method_call(returned.argument.as_ref()?, "run")? else {
|
|
468
555
|
return None;
|
|
469
556
|
};
|
|
470
|
-
let (
|
|
471
|
-
(
|
|
557
|
+
let (
|
|
558
|
+
Expression::NewExpression(_),
|
|
559
|
+
Expression::NumericLiteral(pc),
|
|
560
|
+
Expression::NumericLiteral(key),
|
|
561
|
+
) = (
|
|
562
|
+
machine,
|
|
563
|
+
ast::argument_expression(pc),
|
|
564
|
+
ast::argument_expression(key),
|
|
565
|
+
)
|
|
472
566
|
else {
|
|
473
567
|
return None;
|
|
474
568
|
};
|
|
475
569
|
Some(Self {
|
|
476
|
-
name: ast::member_str(
|
|
570
|
+
name: ast::member_str(target)?,
|
|
477
571
|
pc: pc.value,
|
|
478
572
|
key: key.value,
|
|
479
573
|
})
|
|
@@ -481,42 +575,35 @@ impl<'ast> Runner<'ast> {
|
|
|
481
575
|
}
|
|
482
576
|
|
|
483
577
|
/// 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)
|
|
578
|
+
pub(crate) fn runner_name(script: Script<'_>) -> Option<String> {
|
|
579
|
+
let runners = script.nodes.iter().filter_map(|node| match node.kind() {
|
|
580
|
+
AstKind::AssignmentExpression(assignment) => Runner::installed_by(assignment),
|
|
581
|
+
_ => None,
|
|
582
|
+
});
|
|
583
|
+
let runner = candidates::exactly_one(runners, "program runner").ok()?;
|
|
584
|
+
Some(runner.name.to_owned())
|
|
501
585
|
}
|
|
502
586
|
|
|
503
587
|
/// 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
|
-
|
|
588
|
+
pub(crate) fn calls_runner(call: &CallExpression<'_>, name: &str) -> bool {
|
|
589
|
+
match call.callee.without_parentheses() {
|
|
590
|
+
Expression::Identifier(callee) => callee.name == name,
|
|
591
|
+
callee => callee.as_member_expression().is_some_and(|member| {
|
|
592
|
+
!matches!(member.object(), Expression::Super(_))
|
|
593
|
+
&& ast::member_str(member) == Some(name)
|
|
594
|
+
}),
|
|
509
595
|
}
|
|
510
596
|
}
|
|
511
597
|
|
|
512
598
|
/// Skips leading `var x;` declarations. Deobfuscation removes helper objects used to calculate
|
|
513
599
|
/// `run` arguments but may leave their declarations.
|
|
514
|
-
fn after_bare_declarations(statements: &[
|
|
600
|
+
fn after_bare_declarations<'b, 'a>(statements: &'b [Statement<'a>]) -> &'b [Statement<'a>] {
|
|
515
601
|
let start = statements
|
|
516
602
|
.iter()
|
|
517
603
|
.position(|statement| {
|
|
518
|
-
!matches!(statement,
|
|
519
|
-
if declaration.
|
|
604
|
+
!matches!(statement, Statement::VariableDeclaration(declaration)
|
|
605
|
+
if !declaration.kind.is_using()
|
|
606
|
+
&& declaration.declarations.iter().all(|declarator| declarator.init.is_none()))
|
|
520
607
|
})
|
|
521
608
|
.unwrap_or(statements.len());
|
|
522
609
|
&statements[start..]
|
|
@@ -525,13 +612,15 @@ fn after_bare_declarations(statements: &[Stmt]) -> &[Stmt] {
|
|
|
525
612
|
#[cfg(test)]
|
|
526
613
|
mod tests {
|
|
527
614
|
use super::*;
|
|
615
|
+
use crate::js::ast::ParsedScript;
|
|
528
616
|
|
|
529
617
|
fn entry_of(source: &str) -> Result<Position> {
|
|
530
|
-
let parsed =
|
|
531
|
-
let
|
|
618
|
+
let parsed = ParsedScript::parse("t", source).unwrap();
|
|
619
|
+
let script = parsed.script();
|
|
620
|
+
let Some(Statement::FunctionDeclaration(function)) = script.program.body.first() else {
|
|
532
621
|
panic!("the test source declares no function");
|
|
533
622
|
};
|
|
534
|
-
entry(function.
|
|
623
|
+
entry(function.body.as_deref().unwrap())
|
|
535
624
|
}
|
|
536
625
|
|
|
537
626
|
#[test]
|
|
@@ -551,20 +640,28 @@ mod tests {
|
|
|
551
640
|
|
|
552
641
|
#[test]
|
|
553
642
|
fn names_the_runner_its_callers_call() {
|
|
554
|
-
let parsed =
|
|
643
|
+
let parsed = ParsedScript::parse(
|
|
555
644
|
"t",
|
|
556
645
|
"O.vlJM8 = function(p) { return new M(p).run(0, 238, []); }; \
|
|
557
646
|
O.other = function(p) { return M(p).run(0, 238, []); }; O.vlJM8('a'); vlJM8('b');",
|
|
558
647
|
)
|
|
559
648
|
.unwrap();
|
|
560
|
-
let
|
|
649
|
+
let script = parsed.script();
|
|
650
|
+
let name = runner_name(script).unwrap();
|
|
561
651
|
assert_eq!(name, "vlJM8");
|
|
562
|
-
let calls: Vec<&
|
|
563
|
-
.
|
|
652
|
+
let calls: Vec<&CallExpression<'_>> = script
|
|
653
|
+
.program
|
|
564
654
|
.body
|
|
565
655
|
.iter()
|
|
566
|
-
.filter_map(|statement| statement
|
|
656
|
+
.filter_map(|statement| match statement {
|
|
657
|
+
Statement::ExpressionStatement(statement) => match &statement.expression {
|
|
658
|
+
Expression::CallExpression(call) => Some(&**call),
|
|
659
|
+
_ => None,
|
|
660
|
+
},
|
|
661
|
+
_ => None,
|
|
662
|
+
})
|
|
567
663
|
.collect();
|
|
664
|
+
assert_eq!(calls.len(), 2);
|
|
568
665
|
assert!(calls.iter().all(|call| calls_runner(call, &name)));
|
|
569
666
|
}
|
|
570
667
|
}
|