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
|
@@ -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
|
+
}
|
|
@@ -11,16 +11,29 @@
|
|
|
11
11
|
mod access;
|
|
12
12
|
mod builtin;
|
|
13
13
|
mod call;
|
|
14
|
+
mod compile;
|
|
14
15
|
mod copies;
|
|
15
16
|
mod evaluate;
|
|
16
17
|
mod explore;
|
|
18
|
+
mod formula;
|
|
19
|
+
mod frozen;
|
|
20
|
+
mod intrinsic;
|
|
21
|
+
mod mix32;
|
|
22
|
+
mod native_dispatch;
|
|
23
|
+
mod pattern;
|
|
17
24
|
mod plan;
|
|
25
|
+
mod register_helpers;
|
|
18
26
|
mod run;
|
|
19
27
|
mod semantics;
|
|
20
28
|
mod setup;
|
|
29
|
+
mod string_decoder;
|
|
21
30
|
|
|
22
31
|
pub(crate) use builtin::Builtin;
|
|
23
|
-
pub(crate) use explore::{Invocation, MAXIMUM_PATHS, Way, decode, explore};
|
|
24
|
-
pub(crate) use
|
|
25
|
-
pub(crate) use
|
|
32
|
+
pub(crate) use explore::{Branching, Invocation, MAXIMUM_PATHS, Way, decode, explore};
|
|
33
|
+
pub(crate) use frozen::Frozen;
|
|
34
|
+
pub(crate) use intrinsic::{Intrinsics, intrinsics};
|
|
35
|
+
pub(crate) use native_dispatch::NativeDispatch;
|
|
36
|
+
pub(crate) use plan::{Plans, Routine};
|
|
37
|
+
pub(crate) use run::{Decrypted, Run, Spare};
|
|
26
38
|
pub(crate) use setup::setup;
|
|
39
|
+
pub(crate) use string_decoder::StringDecoder;
|
|
@@ -1,42 +1,49 @@
|
|
|
1
1
|
//! A session's VM, found in its script and ready to decode instructions.
|
|
2
2
|
|
|
3
|
-
use
|
|
4
|
-
|
|
3
|
+
use std::rc::Rc;
|
|
4
|
+
|
|
5
|
+
use anyhow::{Context, Result};
|
|
6
|
+
use oxc::ast::ast::{Class, Function, FunctionBody, Statement};
|
|
7
|
+
use oxc::semantic::SymbolId;
|
|
5
8
|
|
|
6
9
|
use super::HashMap;
|
|
7
10
|
use super::dispatch::{Decoded, Dispatch};
|
|
8
|
-
use super::extract::{self,
|
|
9
|
-
use super::interpret::{self, Invocation, MAXIMUM_PATHS, Way};
|
|
11
|
+
use super::extract::{self, RunMethod};
|
|
12
|
+
use super::interpret::{self, Decrypted, Invocation, MAXIMUM_PATHS, NativeDispatch, Way};
|
|
10
13
|
use super::output::{Cause, Failure, Instruction, Position};
|
|
11
14
|
use super::session::Session;
|
|
12
15
|
use super::value::Value;
|
|
16
|
+
use crate::js::ast::Script;
|
|
13
17
|
|
|
14
|
-
/// The VM class, enclosing function body, opcode decoder, and statements
|
|
15
|
-
/// its scope is entered.
|
|
16
|
-
pub struct Definition {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/// The VM class, enclosing function body, `run` method layout, opcode decoder, and statements
|
|
19
|
+
/// executed before its scope is entered, in the script that defines them.
|
|
20
|
+
pub struct Definition<'a> {
|
|
21
|
+
pub(super) script: Script<'a>,
|
|
22
|
+
pub(super) body: &'a FunctionBody<'a>,
|
|
23
|
+
pub(super) class: &'a Class<'a>,
|
|
24
|
+
pub(super) prelude: Vec<&'a Statement<'a>>,
|
|
25
|
+
/// Functions declared beside the class: handlers and their helpers.
|
|
26
|
+
pub(super) functions: HashMap<SymbolId, &'a Function<'a>>,
|
|
27
|
+
pub(super) run: RunMethod<'a>,
|
|
28
|
+
dispatch: Dispatch<'a>,
|
|
21
29
|
}
|
|
22
30
|
|
|
23
|
-
impl Definition {
|
|
31
|
+
impl<'a> Definition<'a> {
|
|
24
32
|
/// Finds the VM in `script`. Fails unless a class has a `run` method whose dispatch loop has
|
|
25
33
|
/// the expected shape.
|
|
26
|
-
pub fn from_script(script:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let
|
|
31
|
-
script.
|
|
32
|
-
let (body, class) = finder.found.context("no VM class in the script")?;
|
|
33
|
-
let run = extract::method(&class, "run").context("the VM class has no run method")?;
|
|
34
|
-
let functions = extract::functions(&body.stmts);
|
|
35
|
-
let dispatch = Dispatch::from_loop(&extract::run_method(&functions, run)?.dispatch)?;
|
|
34
|
+
pub(crate) fn from_script(script: Script<'a>) -> Result<Self> {
|
|
35
|
+
let (body, class) = extract::find(script).context("no VM class in the script")?;
|
|
36
|
+
let run = extract::method(class, "run").context("the VM class has no run method")?;
|
|
37
|
+
let functions = extract::functions(&body.statements);
|
|
38
|
+
let run = extract::run_method(script, &functions, run)?;
|
|
39
|
+
let dispatch = Dispatch::from_loop(script, &run.dispatch)?;
|
|
36
40
|
Ok(Self {
|
|
37
|
-
|
|
41
|
+
script,
|
|
38
42
|
body,
|
|
39
43
|
class,
|
|
44
|
+
prelude: extract::prelude(script, body),
|
|
45
|
+
functions,
|
|
46
|
+
run,
|
|
40
47
|
dispatch,
|
|
41
48
|
})
|
|
42
49
|
}
|
|
@@ -44,24 +51,34 @@ impl Definition {
|
|
|
44
51
|
|
|
45
52
|
/// One session's VM, ready to decode instructions.
|
|
46
53
|
pub struct Machine<'definition> {
|
|
47
|
-
definition: &'definition Definition
|
|
54
|
+
definition: &'definition Definition<'definition>,
|
|
48
55
|
pub(super) session: Session<'definition>,
|
|
56
|
+
/// The opcode decoder, run natively, if it has the recognized shape.
|
|
57
|
+
pub(super) native_dispatch: Option<NativeDispatch<'definition>>,
|
|
49
58
|
}
|
|
50
59
|
|
|
51
|
-
/// A program, with the instance fields the constructor derives from it
|
|
60
|
+
/// A program, with the instance fields the constructor derives from it and the strings
|
|
61
|
+
/// decrypted from it so far. Decryption depends only on the program, so copies share the
|
|
62
|
+
/// decrypted strings.
|
|
52
63
|
#[derive(Clone)]
|
|
53
64
|
pub(super) struct Loaded<'program, 'definition> {
|
|
54
65
|
program: &'program [u8],
|
|
55
66
|
pub(super) fields: HashMap<String, Value<'definition>>,
|
|
67
|
+
decrypted: Rc<Decrypted<'definition>>,
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
impl<'definition> Machine<'definition> {
|
|
59
71
|
/// Evaluates the VM's setup code and constructor.
|
|
60
|
-
pub fn try_new(definition: &'definition Definition) -> Result<Self> {
|
|
61
|
-
let
|
|
72
|
+
pub fn try_new(definition: &'definition Definition<'_>) -> Result<Self> {
|
|
73
|
+
let definition: &'definition Definition<'definition> = definition;
|
|
74
|
+
let session = Session::try_new(definition)?;
|
|
75
|
+
let dispatch = &definition.dispatch;
|
|
76
|
+
let native_dispatch =
|
|
77
|
+
NativeDispatch::recognize(&session, &dispatch.decoder, &dispatch.arguments);
|
|
62
78
|
Ok(Self {
|
|
63
79
|
definition,
|
|
64
80
|
session,
|
|
81
|
+
native_dispatch,
|
|
65
82
|
})
|
|
66
83
|
}
|
|
67
84
|
|
|
@@ -69,6 +86,7 @@ impl<'definition> Machine<'definition> {
|
|
|
69
86
|
Loaded {
|
|
70
87
|
program,
|
|
71
88
|
fields: self.session.constructed(program),
|
|
89
|
+
decrypted: Rc::default(),
|
|
72
90
|
}
|
|
73
91
|
}
|
|
74
92
|
|
|
@@ -82,21 +100,6 @@ impl<'definition> Machine<'definition> {
|
|
|
82
100
|
self.decode(&self.load(program), pc, key, &[])
|
|
83
101
|
}
|
|
84
102
|
|
|
85
|
-
/// Decodes the instruction at `pc` with register `register` holding `text`. Checks hashed
|
|
86
|
-
/// names absent from the program's literal pool, such as HTTP headers and browser
|
|
87
|
-
/// properties.
|
|
88
|
-
pub fn instruction_with_string(
|
|
89
|
-
&self,
|
|
90
|
-
program: &[u8],
|
|
91
|
-
pc: u32,
|
|
92
|
-
key: u8,
|
|
93
|
-
register: u8,
|
|
94
|
-
text: &str,
|
|
95
|
-
) -> Result<Instruction, Failure> {
|
|
96
|
-
let known = [(register, Value::string(text))];
|
|
97
|
-
self.decode(&self.load(program), pc, key, &known)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
103
|
pub(super) fn decode(
|
|
101
104
|
&self,
|
|
102
105
|
loaded: &Loaded<'_, 'definition>,
|
|
@@ -129,11 +132,18 @@ impl<'definition> Machine<'definition> {
|
|
|
129
132
|
if pc as usize >= loaded.program.len() {
|
|
130
133
|
return Err(fail(Cause::PastEnd));
|
|
131
134
|
}
|
|
132
|
-
let
|
|
133
|
-
.
|
|
134
|
-
.
|
|
135
|
-
.decode(&self.session, loaded.program, pc, key)
|
|
136
|
-
|
|
135
|
+
let native = self
|
|
136
|
+
.native_dispatch
|
|
137
|
+
.as_ref()
|
|
138
|
+
.and_then(|native| native.decode(&self.session, loaded.program, pc, key));
|
|
139
|
+
let Decoded { opcode, key: next } = match native {
|
|
140
|
+
Some(decoded) => decoded,
|
|
141
|
+
None => self
|
|
142
|
+
.definition
|
|
143
|
+
.dispatch
|
|
144
|
+
.decode(&self.session, loaded.program, pc, key)
|
|
145
|
+
.map_err(|reason| fail(Cause::Undecoded { reason }))?,
|
|
146
|
+
};
|
|
137
147
|
let handler = self
|
|
138
148
|
.session
|
|
139
149
|
.handlers
|
|
@@ -144,6 +154,7 @@ impl<'definition> Machine<'definition> {
|
|
|
144
154
|
session: &self.session,
|
|
145
155
|
program: loaded.program,
|
|
146
156
|
fields: &loaded.fields,
|
|
157
|
+
decrypted: &loaded.decrypted,
|
|
147
158
|
pc: pc + 1,
|
|
148
159
|
key: next,
|
|
149
160
|
handler,
|