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,17 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
use std::mem;
|
|
4
4
|
|
|
5
|
-
use
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
use oxc::ast::ast::{
|
|
6
|
+
AssignmentExpression, BindingPattern, Expression, SimpleAssignmentTarget, Statement,
|
|
7
|
+
UpdateExpression, VariableDeclarator,
|
|
8
|
+
};
|
|
9
|
+
use oxc::ast_visit::{Visit, walk};
|
|
8
10
|
|
|
9
|
-
use super::run::{Frame, Run, Stop};
|
|
11
|
+
use super::run::{CallScope, Frame, Run, Stop};
|
|
12
|
+
use crate::js::ast::{Binding, Script};
|
|
10
13
|
use crate::vm::HashMap;
|
|
11
14
|
use crate::vm::session::Session;
|
|
12
15
|
use crate::vm::value::{Env, Scope, Value};
|
|
13
16
|
|
|
14
17
|
/// Runs the enclosing scope's `prelude`, then the VM's setup `statements`. Returns setup
|
|
15
|
-
/// bindings and errors associated with
|
|
18
|
+
/// bindings and errors associated with bindings that interrupted statements may have written.
|
|
16
19
|
///
|
|
17
20
|
/// Setup can read prelude values, but handlers cannot assume they remain unchanged. Prelude
|
|
18
21
|
/// bindings and failures are therefore excluded from the session. Functions created during
|
|
@@ -20,12 +23,15 @@ use crate::vm::value::{Env, Scope, Value};
|
|
|
20
23
|
#[must_use]
|
|
21
24
|
pub(crate) fn setup<'a>(
|
|
22
25
|
session: &Session<'a>,
|
|
23
|
-
prelude: &'a
|
|
24
|
-
statements: &'a [
|
|
25
|
-
) -> (
|
|
26
|
+
prelude: &[&'a Statement<'a>],
|
|
27
|
+
statements: &'a [Statement<'a>],
|
|
28
|
+
) -> (
|
|
29
|
+
HashMap<Binding<'a>, Value<'a>>,
|
|
30
|
+
HashMap<Binding<'a>, String>,
|
|
31
|
+
) {
|
|
26
32
|
let mut run = Run::new(session, &[], Vec::new(), None);
|
|
27
33
|
let around = Env::scope(HashMap::default(), None);
|
|
28
|
-
run.run_setup(around.clone(), prelude);
|
|
34
|
+
run.run_setup(around.clone(), prelude.iter().copied());
|
|
29
35
|
run.unavailable.to_mut().clear();
|
|
30
36
|
let own = Env::scope(HashMap::default(), Some(around.clone()));
|
|
31
37
|
run.run_setup(own.clone(), statements);
|
|
@@ -36,20 +42,27 @@ pub(crate) fn setup<'a>(
|
|
|
36
42
|
|
|
37
43
|
impl<'ast> Run<'ast, '_> {
|
|
38
44
|
/// Runs setup `statements` in `scope`, which functions declared beside the class share until
|
|
39
|
-
/// setup ends. Records the
|
|
40
|
-
fn run_setup(
|
|
45
|
+
/// setup ends. Records the bindings interrupted statements may have written.
|
|
46
|
+
fn run_setup(
|
|
47
|
+
&mut self,
|
|
48
|
+
scope: Scope<'ast>,
|
|
49
|
+
statements: impl IntoIterator<Item = &'ast Statement<'ast>>,
|
|
50
|
+
) {
|
|
41
51
|
self.frames.push(Frame {
|
|
42
52
|
this: Value::Undefined,
|
|
43
|
-
scope: scope.clone(),
|
|
53
|
+
scope: CallScope::Own(scope.clone()),
|
|
44
54
|
});
|
|
45
55
|
self.setup = Some(scope);
|
|
46
56
|
for statement in statements {
|
|
47
|
-
let mut written = Written
|
|
48
|
-
|
|
57
|
+
let mut written = Written {
|
|
58
|
+
script: self.session.script,
|
|
59
|
+
bindings: Vec::new(),
|
|
60
|
+
};
|
|
61
|
+
written.visit_statement(statement);
|
|
49
62
|
match self.statement(statement) {
|
|
50
63
|
Ok(_) => {
|
|
51
|
-
for
|
|
52
|
-
self.unavailable.to_mut().remove(&
|
|
64
|
+
for binding in written.bindings {
|
|
65
|
+
self.unavailable.to_mut().remove(&binding);
|
|
53
66
|
}
|
|
54
67
|
}
|
|
55
68
|
Err(stop) => {
|
|
@@ -57,14 +70,18 @@ impl<'ast> Run<'ast, '_> {
|
|
|
57
70
|
Stop::Throw(value) => format!("it throws {}", value.expr()),
|
|
58
71
|
Stop::Unsupported(reason) => reason,
|
|
59
72
|
};
|
|
60
|
-
for
|
|
73
|
+
for binding in written.bindings {
|
|
61
74
|
// Global-object members are not tracked, so writes to them do not
|
|
62
75
|
// invalidate a tracked binding.
|
|
63
|
-
if let Ok(Value::Namespace(_)) = self.lookup(
|
|
76
|
+
if let Ok(Value::Namespace(_)) = self.lookup(binding) {
|
|
64
77
|
continue;
|
|
65
78
|
}
|
|
66
|
-
self.
|
|
67
|
-
|
|
79
|
+
self.frame_mut()
|
|
80
|
+
.own_scope()
|
|
81
|
+
.borrow_mut()
|
|
82
|
+
.variables
|
|
83
|
+
.remove(&binding);
|
|
84
|
+
self.unavailable.to_mut().insert(binding, reason.clone());
|
|
68
85
|
}
|
|
69
86
|
}
|
|
70
87
|
}
|
|
@@ -72,42 +89,60 @@ impl<'ast> Run<'ast, '_> {
|
|
|
72
89
|
}
|
|
73
90
|
}
|
|
74
91
|
|
|
75
|
-
///
|
|
76
|
-
|
|
77
|
-
|
|
92
|
+
/// Bindings a statement may declare, assign, or mutate through property writes.
|
|
93
|
+
struct Written<'a> {
|
|
94
|
+
script: Script<'a>,
|
|
95
|
+
bindings: Vec<Binding<'a>>,
|
|
96
|
+
}
|
|
78
97
|
|
|
79
|
-
impl Visit for Written {
|
|
80
|
-
fn
|
|
81
|
-
if let
|
|
82
|
-
self.
|
|
98
|
+
impl<'a> Visit<'a> for Written<'a> {
|
|
99
|
+
fn visit_variable_declarator(&mut self, declarator: &VariableDeclarator<'a>) {
|
|
100
|
+
if let BindingPattern::BindingIdentifier(name) = &declarator.id {
|
|
101
|
+
self.bindings.push(Binding::Symbol(name.symbol_id()));
|
|
83
102
|
}
|
|
84
|
-
|
|
103
|
+
walk::walk_variable_declarator(self, declarator);
|
|
85
104
|
}
|
|
86
105
|
|
|
87
|
-
fn
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
SimpleAssignTarget::Member(member) => self.root(&member.obj),
|
|
91
|
-
_ => {}
|
|
106
|
+
fn visit_assignment_expression(&mut self, assignment: &AssignmentExpression<'a>) {
|
|
107
|
+
if let Some(target) = assignment.left.as_simple_assignment_target() {
|
|
108
|
+
self.target(target);
|
|
92
109
|
}
|
|
93
|
-
|
|
110
|
+
walk::walk_assignment_expression(self, assignment);
|
|
94
111
|
}
|
|
95
112
|
|
|
96
|
-
fn
|
|
97
|
-
self.
|
|
98
|
-
|
|
113
|
+
fn visit_update_expression(&mut self, update: &UpdateExpression<'a>) {
|
|
114
|
+
self.target(&update.argument);
|
|
115
|
+
walk::walk_update_expression(self, update);
|
|
99
116
|
}
|
|
100
117
|
}
|
|
101
118
|
|
|
102
|
-
impl Written {
|
|
103
|
-
///
|
|
104
|
-
fn
|
|
119
|
+
impl<'a> Written<'a> {
|
|
120
|
+
/// Records an assigned name, or the root of an assigned member.
|
|
121
|
+
fn target(&mut self, target: &SimpleAssignmentTarget<'a>) {
|
|
122
|
+
match target {
|
|
123
|
+
SimpleAssignmentTarget::AssignmentTargetIdentifier(name) => {
|
|
124
|
+
self.bindings.push(self.script.binding(name));
|
|
125
|
+
}
|
|
126
|
+
target => {
|
|
127
|
+
if let Some(member) = target.as_member_expression() {
|
|
128
|
+
self.root(member.object());
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/// Records the binding at the root of a member-expression chain.
|
|
135
|
+
fn root(&mut self, mut expression: &Expression<'a>) {
|
|
105
136
|
loop {
|
|
106
|
-
match
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
137
|
+
match expression {
|
|
138
|
+
Expression::Identifier(name) => {
|
|
139
|
+
return self.bindings.push(self.script.binding(name));
|
|
140
|
+
}
|
|
141
|
+
Expression::ParenthesizedExpression(paren) => expression = &paren.expression,
|
|
142
|
+
other => match other.as_member_expression() {
|
|
143
|
+
Some(member) => expression = member.object(),
|
|
144
|
+
None => return,
|
|
145
|
+
},
|
|
111
146
|
}
|
|
112
147
|
}
|
|
113
148
|
}
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
//! The program string decoder, run natively.
|
|
2
|
+
//!
|
|
3
|
+
//! Each encrypted string record names its bytes in the program and a key. The decoder derives a
|
|
4
|
+
//! record key with BLAKE3, checks a keyed BLAKE3 MAC of the ciphertext, and XORs the ciphertext
|
|
5
|
+
//! with a BLAKE3 keystream. Interpreting it dominates string decryption, which every handler run
|
|
6
|
+
//! that loads a string constant needs.
|
|
7
|
+
//!
|
|
8
|
+
//! The decoder, its MAC and keystream functions must match [`DECODER`], [`MAC`] and
|
|
9
|
+
//! [`KEYSTREAM`] (see [`super::pattern`]), the functions they call must be the recognized
|
|
10
|
+
//! mixer and BLAKE3 compression intrinsics, and the session values they read must be the
|
|
11
|
+
//! character table, `Array`, and bound `charCodeAt` and `repeat` they are in known builds.
|
|
12
|
+
//! Each call also resolves every binding as the interpreter would. Records outside what the native
|
|
13
|
+
//! version reproduces exactly, including every record the script would reject, are interpreted.
|
|
14
|
+
|
|
15
|
+
use std::collections::BTreeSet;
|
|
16
|
+
use std::ptr;
|
|
17
|
+
|
|
18
|
+
use oxc::ast::ast::Function;
|
|
19
|
+
|
|
20
|
+
use super::builtin::Builtin;
|
|
21
|
+
use super::formula::{Formula, Input};
|
|
22
|
+
use super::intrinsic::{self, Counter, Intrinsic};
|
|
23
|
+
use super::mix32::Mix32;
|
|
24
|
+
use super::pattern;
|
|
25
|
+
use super::run::Run;
|
|
26
|
+
use crate::js;
|
|
27
|
+
use crate::js::ast::Binding;
|
|
28
|
+
use crate::vm::convert;
|
|
29
|
+
use crate::vm::session::Session;
|
|
30
|
+
use crate::vm::value::{Callable, JsString, Value};
|
|
31
|
+
|
|
32
|
+
/// `decoder(record)`: `record` is `[program, offset, length, b3, b4, key]`.
|
|
33
|
+
const DECODER: &str = "
|
|
34
|
+
function decoder(record) {
|
|
35
|
+
var bytes, offset, length, key, seed, block, count, text, keystream, index, value;
|
|
36
|
+
bytes = record[0];
|
|
37
|
+
offset = record[1];
|
|
38
|
+
length = record[2];
|
|
39
|
+
key = record[5];
|
|
40
|
+
seed = $mix(offset);
|
|
41
|
+
block = [$c_block, offset, length, 0, 0, 0, 0, record[4] << 8 | record[3], 0, 0, 0, 0, 0, 0, 0, 0];
|
|
42
|
+
count = 0;
|
|
43
|
+
for (; count < 16; count++) {
|
|
44
|
+
block[3 + (count >>> 2)] |= read(count) << 8 * (count & 3);
|
|
45
|
+
}
|
|
46
|
+
count = read(16) << 8 | read(17);
|
|
47
|
+
if (count > length) throw Error();
|
|
48
|
+
key = [key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]];
|
|
49
|
+
$compress(key, block, 0, 32, 27);
|
|
50
|
+
block = new $array(count);
|
|
51
|
+
text = ``;
|
|
52
|
+
index = 0;
|
|
53
|
+
for (; index < 4; index++) {
|
|
54
|
+
text += $table[255 & key[0] >>> index * 8];
|
|
55
|
+
}
|
|
56
|
+
index = 0;
|
|
57
|
+
for (; index < count; index++) {
|
|
58
|
+
value = read(18 + index);
|
|
59
|
+
block[index] = value;
|
|
60
|
+
text += $table[value];
|
|
61
|
+
}
|
|
62
|
+
index = 8 + 2 * text.length;
|
|
63
|
+
text = $mac(text, index, 0, ((index - 1) / 1024 | 0) + 1, true, key, true);
|
|
64
|
+
index = 0;
|
|
65
|
+
value = 0;
|
|
66
|
+
for (; value < 16; value++) {
|
|
67
|
+
index |= read(18 + length + value) ^ text[value >>> 2] >>> 8 * (value & 3) & 255;
|
|
68
|
+
}
|
|
69
|
+
if (index) throw Error();
|
|
70
|
+
text = ``;
|
|
71
|
+
index = 0;
|
|
72
|
+
for (; index < count; index++) {
|
|
73
|
+
if ((31 & index) === 0) {
|
|
74
|
+
keystream = $keystream(key, index >>> 5);
|
|
75
|
+
}
|
|
76
|
+
text += $table[block[index] ^ keystream[index >>> 2 & 7] >>> (index & 3) * 8 & 255];
|
|
77
|
+
}
|
|
78
|
+
return text + $repeat(`\\0`, length - count);
|
|
79
|
+
function read(position) {
|
|
80
|
+
var mixed;
|
|
81
|
+
mixed = seed + 2654435769 * position | 0;
|
|
82
|
+
return $e_read;
|
|
83
|
+
}
|
|
84
|
+
}";
|
|
85
|
+
|
|
86
|
+
/// `mac(text, length, chunk, chunks, root, key, keyed)`: the keyed BLAKE3 hash of `length`
|
|
87
|
+
/// bytes, eight zero bytes then `text` as UTF-16BE, starting at 1024-byte chunk `chunk`.
|
|
88
|
+
const MAC: &str = "
|
|
89
|
+
function mac(text, length, chunk, chunks, root, key, keyed) {
|
|
90
|
+
var left, flags;
|
|
91
|
+
var state;
|
|
92
|
+
state = key ? [key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]] : [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225];
|
|
93
|
+
flags = key ? 16 : 0;
|
|
94
|
+
if (chunks > 1) {
|
|
95
|
+
var half;
|
|
96
|
+
half = 1;
|
|
97
|
+
for (; 2 * half < chunks; half *= 2);
|
|
98
|
+
left = $self(text, length, chunk, half, false, key, keyed);
|
|
99
|
+
text = $self(text, length, chunk + half, chunks - half, false, key, keyed);
|
|
100
|
+
$compress(state, [left[0], left[1], left[2], left[3], left[4], left[5], left[6], left[7], text[0], text[1], text[2], text[3], text[4], text[5], text[6], text[7]], 0, 64, (root ? 8 : 0) | (flags | 4));
|
|
101
|
+
return state;
|
|
102
|
+
}
|
|
103
|
+
left = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
104
|
+
chunks = chunk * 1024;
|
|
105
|
+
length = chunks + 1024 < length ? chunks + 1024 : length;
|
|
106
|
+
key = chunks;
|
|
107
|
+
for (; key < length; key += 64) {
|
|
108
|
+
half = 0;
|
|
109
|
+
for (; half < 16; half++) {
|
|
110
|
+
let position = key / 2 + 2 * half - 4, word = 0;
|
|
111
|
+
if (position < 0) {
|
|
112
|
+
word = keyed ? 0 : half === 0 ? $c_prefix0 : $c_prefix1;
|
|
113
|
+
} else {
|
|
114
|
+
if (position < text.length) {
|
|
115
|
+
word = $code(text, position) << 16 | (position + 1 < text.length ? $code(text, position + 1) : 0);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
left[half] = (word & 255) << 24 | (word & 65280) << 8 | word >>> 8 & 65280 | word >>> 24;
|
|
119
|
+
}
|
|
120
|
+
half = key + 64 >= length;
|
|
121
|
+
$compress(state, left, chunk, half ? length - key : 64, flags | (chunks === key ? 1 : 0) | (half ? 2 : 0) | (half && root ? 8 : 0));
|
|
122
|
+
}
|
|
123
|
+
return state;
|
|
124
|
+
}";
|
|
125
|
+
|
|
126
|
+
/// `keystream(key, counter)`: one 32-byte keystream block.
|
|
127
|
+
const KEYSTREAM: &str = "
|
|
128
|
+
function keystream(key, counter) {
|
|
129
|
+
key = [key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7]];
|
|
130
|
+
$compress(key, [$c_stream, counter, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 0, 8, 27);
|
|
131
|
+
return key;
|
|
132
|
+
}";
|
|
133
|
+
|
|
134
|
+
/// A recognized decoder: the bindings it reads, the functions they must resolve to, and its
|
|
135
|
+
/// constants.
|
|
136
|
+
pub(crate) struct StringDecoder<'ast> {
|
|
137
|
+
mixer: Mix32,
|
|
138
|
+
/// Bindings resolving to script functions: the decoder's callees and the binary helpers
|
|
139
|
+
/// declared beside the class that its match inlined.
|
|
140
|
+
functions: Vec<NamedFunction<'ast>>,
|
|
141
|
+
/// Inlined binary helpers that are session bindings.
|
|
142
|
+
bound_helpers: Vec<NamedFunction<'ast>>,
|
|
143
|
+
table: Binding<'ast>,
|
|
144
|
+
array: Binding<'ast>,
|
|
145
|
+
repeat: Binding<'ast>,
|
|
146
|
+
code: Binding<'ast>,
|
|
147
|
+
block: f64,
|
|
148
|
+
/// A program byte's value, from `bytes`, `offset`, `position`, `record` and `mixed`.
|
|
149
|
+
read: Formula,
|
|
150
|
+
stream: f64,
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
struct NamedFunction<'ast> {
|
|
154
|
+
binding: Binding<'ast>,
|
|
155
|
+
function: &'ast Function<'ast>,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
impl<'ast> StringDecoder<'ast> {
|
|
159
|
+
/// Recognizes the session's record decoder.
|
|
160
|
+
pub(crate) fn recognize(session: &Session<'ast>) -> Option<Self> {
|
|
161
|
+
let decoder = session.record_decoder?;
|
|
162
|
+
let script = session.script;
|
|
163
|
+
let helpers = pattern::binary_helpers(session);
|
|
164
|
+
let captures = pattern::matches(&pattern::template(DECODER), script, decoder, &helpers)?;
|
|
165
|
+
// Functions resolve through bindings first.
|
|
166
|
+
let function = |binding: Binding<'ast>| {
|
|
167
|
+
if session.bindings.contains_key(&binding) {
|
|
168
|
+
return None;
|
|
169
|
+
}
|
|
170
|
+
session.function(binding)
|
|
171
|
+
};
|
|
172
|
+
let mix = captures.name("$mix")?;
|
|
173
|
+
let compress = captures.name("$compress")?;
|
|
174
|
+
let mac = captures.name("$mac")?;
|
|
175
|
+
let keystream = captures.name("$keystream")?;
|
|
176
|
+
let mix_function = function(mix)?;
|
|
177
|
+
let compress_function = function(compress)?;
|
|
178
|
+
let mac_function = function(mac)?;
|
|
179
|
+
let keystream_function = function(keystream)?;
|
|
180
|
+
let native = |function| {
|
|
181
|
+
session
|
|
182
|
+
.intrinsics
|
|
183
|
+
.get(&intrinsic::address(function))
|
|
184
|
+
.copied()
|
|
185
|
+
};
|
|
186
|
+
let Some(Intrinsic::Mix32(mixer)) = native(mix_function) else {
|
|
187
|
+
return None;
|
|
188
|
+
};
|
|
189
|
+
let Some(Intrinsic::Blake3Compress) = native(compress_function) else {
|
|
190
|
+
return None;
|
|
191
|
+
};
|
|
192
|
+
let mac_captures =
|
|
193
|
+
pattern::matches(&pattern::template(MAC), script, mac_function, &helpers)?;
|
|
194
|
+
let stream_captures = pattern::matches(
|
|
195
|
+
&pattern::template(KEYSTREAM),
|
|
196
|
+
script,
|
|
197
|
+
keystream_function,
|
|
198
|
+
&helpers,
|
|
199
|
+
)?;
|
|
200
|
+
if mac_captures.name("$self")? != mac
|
|
201
|
+
|| mac_captures.name("$compress")? != compress
|
|
202
|
+
|| stream_captures.name("$compress")? != compress
|
|
203
|
+
{
|
|
204
|
+
return None;
|
|
205
|
+
}
|
|
206
|
+
let table = captures.name("$table")?;
|
|
207
|
+
let array = captures.name("$array")?;
|
|
208
|
+
let repeat = captures.name("$repeat")?;
|
|
209
|
+
let code = mac_captures.name("$code")?;
|
|
210
|
+
// Values the decoder reads are session bindings, not functions or builtins.
|
|
211
|
+
if ![table, array, repeat, code]
|
|
212
|
+
.iter()
|
|
213
|
+
.all(|binding| session.bindings.contains_key(binding))
|
|
214
|
+
{
|
|
215
|
+
return None;
|
|
216
|
+
}
|
|
217
|
+
let named = |binding, function| NamedFunction { binding, function };
|
|
218
|
+
let mut functions = vec![
|
|
219
|
+
named(mix, mix_function),
|
|
220
|
+
named(compress, compress_function),
|
|
221
|
+
named(mac, mac_function),
|
|
222
|
+
named(keystream, keystream_function),
|
|
223
|
+
];
|
|
224
|
+
let mut bound_helpers = Vec::new();
|
|
225
|
+
let inlined: BTreeSet<Binding<'ast>> = (captures.helpers.iter())
|
|
226
|
+
.chain(&mac_captures.helpers)
|
|
227
|
+
.chain(&stream_captures.helpers)
|
|
228
|
+
.copied()
|
|
229
|
+
.collect();
|
|
230
|
+
for binding in inlined {
|
|
231
|
+
if let Some(value) = session.bindings.get(&binding) {
|
|
232
|
+
let function = pattern::script_function(value);
|
|
233
|
+
let function = function.expect("bound binary helpers are script functions");
|
|
234
|
+
bound_helpers.push(named(binding, function));
|
|
235
|
+
} else {
|
|
236
|
+
let function = session.function(binding);
|
|
237
|
+
let function = function.expect("unbound binary helpers are declared functions");
|
|
238
|
+
functions.push(named(binding, function));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
Some(Self {
|
|
242
|
+
mixer,
|
|
243
|
+
functions,
|
|
244
|
+
bound_helpers,
|
|
245
|
+
table,
|
|
246
|
+
array,
|
|
247
|
+
repeat,
|
|
248
|
+
code,
|
|
249
|
+
block: captures.constant("$c_block")?,
|
|
250
|
+
read: captures.formula("$e_read")?,
|
|
251
|
+
stream: stream_captures.constant("$c_stream")?,
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/// Decrypts `record` as the script would, or returns `None` to interpret it.
|
|
256
|
+
pub(super) fn decrypt(&self, run: &Run<'ast, '_>, record: &Value<'ast>) -> Option<Value<'ast>> {
|
|
257
|
+
if run.setup.is_some() || !self.resolves(run) {
|
|
258
|
+
return None;
|
|
259
|
+
}
|
|
260
|
+
let Value::Array(record) = record else {
|
|
261
|
+
return None;
|
|
262
|
+
};
|
|
263
|
+
let record = record.borrow();
|
|
264
|
+
let [
|
|
265
|
+
Value::Program,
|
|
266
|
+
Value::Number(offset),
|
|
267
|
+
Value::Number(length),
|
|
268
|
+
Value::Number(low),
|
|
269
|
+
Value::Number(high),
|
|
270
|
+
Value::Array(key),
|
|
271
|
+
..,
|
|
272
|
+
] = &record[..]
|
|
273
|
+
else {
|
|
274
|
+
return None;
|
|
275
|
+
};
|
|
276
|
+
let (offset, length) = (*offset, *length);
|
|
277
|
+
let (low, high) = (js::int32(*low), js::int32(*high));
|
|
278
|
+
let key: [u32; 8] = intrinsic::words(key.borrow().get(..8)?)?;
|
|
279
|
+
let program = run.program;
|
|
280
|
+
let seed = self.mixer.call(offset);
|
|
281
|
+
// Byte values only: other results would index the character table outside it.
|
|
282
|
+
let read = |position: f64| -> Option<i32> {
|
|
283
|
+
let mixed = js::int32(seed + 2_654_435_769.0 * position);
|
|
284
|
+
let value = self.read.evaluate(&[
|
|
285
|
+
("bytes", Input::Bytes(program)),
|
|
286
|
+
("offset", Input::Number(offset)),
|
|
287
|
+
("position", Input::Number(position)),
|
|
288
|
+
("record", Input::Array(&record)),
|
|
289
|
+
("mixed", Input::Number(f64::from(mixed))),
|
|
290
|
+
])?;
|
|
291
|
+
(value.fract() == 0.0 && (0.0..=255.0).contains(&value)).then_some(value as i32)
|
|
292
|
+
};
|
|
293
|
+
// The record key, derived from the record's position, length and first bytes.
|
|
294
|
+
let mut header = [0i32; 4];
|
|
295
|
+
for count in 0..16 {
|
|
296
|
+
header[count >> 2] |= read(count as f64)? << (8 * (count & 3));
|
|
297
|
+
}
|
|
298
|
+
let mut block = [self.block, offset, length, 0.0, 0.0, 0.0, 0.0, 0.0];
|
|
299
|
+
for (slot, word) in block[3..7].iter_mut().zip(header) {
|
|
300
|
+
*slot = f64::from(word);
|
|
301
|
+
}
|
|
302
|
+
block[7] = f64::from(high << 8 | low);
|
|
303
|
+
let mut words = [0u32; 16];
|
|
304
|
+
words[..8].copy_from_slice(&intrinsic::words::<8>(&block.map(Value::Number))?);
|
|
305
|
+
let key = intrinsic::compress(&key, &words, Counter::of(0.0), 32, 27);
|
|
306
|
+
let count = read(16.0)? << 8 | read(17.0)?;
|
|
307
|
+
if f64::from(count) > length {
|
|
308
|
+
return None;
|
|
309
|
+
}
|
|
310
|
+
let count = usize::try_from(count).ok()?;
|
|
311
|
+
let mut ciphertext = Vec::with_capacity(count);
|
|
312
|
+
for index in 0..count {
|
|
313
|
+
ciphertext.push(u8::try_from(read((18 + index) as f64)?).ok()?);
|
|
314
|
+
}
|
|
315
|
+
// The MAC covers the key's first word and the ciphertext.
|
|
316
|
+
let mut text = Vec::with_capacity(4 + count);
|
|
317
|
+
text.extend((0..4).map(|index| ((key[0] >> (8 * index)) & 255) as u16));
|
|
318
|
+
text.extend(ciphertext.iter().map(|&byte| u16::from(byte)));
|
|
319
|
+
let bytes = 8 + 2 * text.len();
|
|
320
|
+
let mac = mac(&text, bytes, 0, (bytes - 1) / 1024 + 1, true, &key);
|
|
321
|
+
let mut difference = 0;
|
|
322
|
+
for value in 0..16 {
|
|
323
|
+
let expected = (mac[value >> 2] >> (8 * (value & 3))) & 255;
|
|
324
|
+
difference |= read(18.0 + length + value as f64)? ^ expected as i32;
|
|
325
|
+
}
|
|
326
|
+
if difference != 0 {
|
|
327
|
+
return None;
|
|
328
|
+
}
|
|
329
|
+
let mut plain = Vec::with_capacity(count);
|
|
330
|
+
let mut stream = [0u32; 8];
|
|
331
|
+
for (index, byte) in ciphertext.iter().enumerate() {
|
|
332
|
+
if index & 31 == 0 {
|
|
333
|
+
let mut block = [0u32; 16];
|
|
334
|
+
block[0] = intrinsic::words::<1>(&[Value::Number(self.stream)])?[0];
|
|
335
|
+
block[1] = (index >> 5) as u32;
|
|
336
|
+
stream = intrinsic::compress(&key, &block, Counter::of(0.0), 8, 27);
|
|
337
|
+
}
|
|
338
|
+
let mask = (stream[(index >> 2) & 7] >> ((index & 3) * 8)) & 255;
|
|
339
|
+
plain.push(u16::from(*byte) ^ mask as u16);
|
|
340
|
+
}
|
|
341
|
+
// `"\0".repeat(length - count)`, within the interpreter's length limit.
|
|
342
|
+
let padding = convert::length(length - count as f64)?;
|
|
343
|
+
plain.resize(count + padding, 0);
|
|
344
|
+
Some(Value::String(JsString::from(plain)))
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/// Whether every binding the decoder reads resolves, in `run`, to what was recognized.
|
|
348
|
+
fn resolves(&self, run: &Run<'ast, '_>) -> bool {
|
|
349
|
+
let unshadowed = |binding: &Binding<'ast>| !run.unavailable.contains_key(binding);
|
|
350
|
+
let value = |binding: &Binding<'ast>| {
|
|
351
|
+
if !unshadowed(binding) {
|
|
352
|
+
return None;
|
|
353
|
+
}
|
|
354
|
+
run.globals
|
|
355
|
+
.get(binding)
|
|
356
|
+
.or_else(|| run.session.bindings.get(binding))
|
|
357
|
+
};
|
|
358
|
+
let functions = self
|
|
359
|
+
.functions
|
|
360
|
+
.iter()
|
|
361
|
+
.all(|NamedFunction { binding, function }| {
|
|
362
|
+
unshadowed(binding)
|
|
363
|
+
&& run.globals.get(binding).is_none_or(|global| {
|
|
364
|
+
pattern::script_function(global)
|
|
365
|
+
.is_some_and(|found| ptr::eq(found, *function))
|
|
366
|
+
})
|
|
367
|
+
});
|
|
368
|
+
let bound_helpers = self
|
|
369
|
+
.bound_helpers
|
|
370
|
+
.iter()
|
|
371
|
+
.all(|NamedFunction { binding, function }| {
|
|
372
|
+
value(binding)
|
|
373
|
+
.and_then(pattern::script_function)
|
|
374
|
+
.is_some_and(|found| ptr::eq(found, *function))
|
|
375
|
+
});
|
|
376
|
+
functions
|
|
377
|
+
&& bound_helpers
|
|
378
|
+
&& value(&self.table).is_some_and(is_character_table)
|
|
379
|
+
&& value(&self.array).is_some_and(|array| is_builtin(array, Builtin::Array))
|
|
380
|
+
&& value(&self.repeat).is_some_and(|repeat| is_bound_call(repeat, Builtin::Repeat))
|
|
381
|
+
&& value(&self.code).is_some_and(|code| is_bound_call(code, Builtin::CharCodeAt))
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/// The MAC function on `bytes` bytes of `text`, from chunk `chunk`, for keyed calls without a
|
|
386
|
+
/// prefix, as the decoder makes them.
|
|
387
|
+
fn mac(
|
|
388
|
+
text: &[u16],
|
|
389
|
+
bytes: usize,
|
|
390
|
+
chunk: usize,
|
|
391
|
+
chunks: usize,
|
|
392
|
+
root: bool,
|
|
393
|
+
key: &[u32; 8],
|
|
394
|
+
) -> [u32; 8] {
|
|
395
|
+
const KEYED: u32 = 16;
|
|
396
|
+
if chunks > 1 {
|
|
397
|
+
let mut half = 1;
|
|
398
|
+
while 2 * half < chunks {
|
|
399
|
+
half *= 2;
|
|
400
|
+
}
|
|
401
|
+
let mut block = [0u32; 16];
|
|
402
|
+
block[..8].copy_from_slice(&mac(text, bytes, chunk, half, false, key));
|
|
403
|
+
block[8..].copy_from_slice(&mac(text, bytes, chunk + half, chunks - half, false, key));
|
|
404
|
+
let flags = if root { 8 } else { 0 } | KEYED | 4;
|
|
405
|
+
return intrinsic::compress(key, &block, Counter::of(0.0), 64, flags);
|
|
406
|
+
}
|
|
407
|
+
let mut state = *key;
|
|
408
|
+
let start = chunk * 1024;
|
|
409
|
+
let end = (start + 1024).min(bytes);
|
|
410
|
+
let mut position = start;
|
|
411
|
+
while position < end {
|
|
412
|
+
let mut block = [0u32; 16];
|
|
413
|
+
for (half, slot) in block.iter_mut().enumerate() {
|
|
414
|
+
// Code unit index; the first four units are the zero prefix.
|
|
415
|
+
let unit = (position / 2 + 2 * half).checked_sub(4);
|
|
416
|
+
let word = match unit {
|
|
417
|
+
Some(unit) if unit < text.len() => {
|
|
418
|
+
let low = text.get(unit + 1).map_or(0, |&unit| u32::from(unit));
|
|
419
|
+
u32::from(text[unit]) << 16 | low
|
|
420
|
+
}
|
|
421
|
+
_ => 0,
|
|
422
|
+
};
|
|
423
|
+
*slot = word.swap_bytes();
|
|
424
|
+
}
|
|
425
|
+
let last = position + 64 >= end;
|
|
426
|
+
let length = if last { end - position } else { 64 };
|
|
427
|
+
let flags = KEYED
|
|
428
|
+
| u32::from(start == position)
|
|
429
|
+
| if last { 2 } else { 0 }
|
|
430
|
+
| if last && root { 8 } else { 0 };
|
|
431
|
+
let counter = Counter::of(chunk as f64);
|
|
432
|
+
state = intrinsic::compress(&state, &block, counter, length as u32, flags);
|
|
433
|
+
position += 64;
|
|
434
|
+
}
|
|
435
|
+
state
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/// `String.fromCharCode(i)` at each index `i` below 256.
|
|
439
|
+
fn is_character_table(table: &Value<'_>) -> bool {
|
|
440
|
+
let Value::Array(elements) = table else {
|
|
441
|
+
return false;
|
|
442
|
+
};
|
|
443
|
+
let elements = elements.borrow();
|
|
444
|
+
elements.len() == 256
|
|
445
|
+
&& elements.iter().enumerate().all(|(index, element)| {
|
|
446
|
+
matches!(element, Value::String(text) if text.units() == [index as u16])
|
|
447
|
+
})
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
fn is_builtin(value: &Value<'_>, builtin: Builtin) -> bool {
|
|
451
|
+
matches!(value, Value::Function(callable)
|
|
452
|
+
if matches!(&**callable, Callable::Builtin(found) if *found == builtin))
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/// `Function.prototype.call.bind(method)`, as `bind.bind(call)(method)` creates it.
|
|
456
|
+
fn is_bound_call(value: &Value<'_>, method: Builtin) -> bool {
|
|
457
|
+
let Value::Function(callable) = value else {
|
|
458
|
+
return false;
|
|
459
|
+
};
|
|
460
|
+
matches!(&**callable, Callable::Bound { target, this, arguments }
|
|
461
|
+
if arguments.is_empty() && is_builtin(target, Builtin::Call) && is_builtin(this, method))
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
#[cfg(test)]
|
|
465
|
+
mod tests {
|
|
466
|
+
use std::{env, fs};
|
|
467
|
+
|
|
468
|
+
use crate::script::Source;
|
|
469
|
+
|
|
470
|
+
/// Recognizes the decoder of a saved deobfuscated script named by `CFSOLVE_DECODER_SCRIPT`.
|
|
471
|
+
#[test]
|
|
472
|
+
fn recognizes_saved_script() {
|
|
473
|
+
let Some(path) = env::var_os("CFSOLVE_DECODER_SCRIPT") else {
|
|
474
|
+
return;
|
|
475
|
+
};
|
|
476
|
+
let source = fs::read_to_string(path).expect("the saved script is readable");
|
|
477
|
+
let source = Source::try_new(&source).expect("the saved script parses");
|
|
478
|
+
let machine = source.machine().expect("the saved script builds a machine");
|
|
479
|
+
assert!(machine.session.string_decoder.is_some(), "string decoder");
|
|
480
|
+
assert!(machine.native_dispatch.is_some(), "native dispatch");
|
|
481
|
+
}
|
|
482
|
+
}
|