cfsolve 0.1.3 → 0.1.5
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 +40 -0
- data/README.md +30 -5
- data/UPSTREAM.md +24 -3
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +805 -797
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
- data/lib/cfsolve/version.rb +2 -2
- data/lib/cfsolve.rb +21 -10
- data/vendor/cfsolve/examples/listing_dump.rs +24 -0
- data/vendor/cfsolve/examples/probe_similarity.rs +37 -0
- data/vendor/cfsolve/examples/rebase_reference.rs +96 -0
- data/vendor/cfsolve/examples/reread_capture.rs +31 -0
- data/vendor/cfsolve/examples/turnstile_smoke.rs +79 -0
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +805 -797
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
- data/vendor/cfsolve/src/capture/sessions.rs +88 -4
- data/vendor/cfsolve/src/capture.rs +1 -0
- data/vendor/cfsolve/src/deobfuscate/ast.rs +16 -0
- data/vendor/cfsolve/src/deobfuscate/control_flow.rs +1 -1
- data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +33 -0
- data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +24 -4
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +3 -3
- data/vendor/cfsolve/src/embedding_page/page.rs +76 -65
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +7 -4
- data/vendor/cfsolve/src/stage2/benchmark.rs +29 -8
- data/vendor/cfsolve/src/stage2/call_stack.rs +134 -95
- data/vendor/cfsolve/src/stage2/challenge_page.rs +10 -3
- data/vendor/cfsolve/src/stage2/probes/parent_info.rs +345 -61
- data/vendor/cfsolve/src/stage2/probes/performance.rs +42 -5
- data/vendor/cfsolve/src/stage2/probes/stack.rs +41 -0
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +11 -2
- data/vendor/cfsolve/src/stage2/reference.json +1 -1
- data/vendor/cfsolve/src/stage2/reference.rs +70 -110
- data/vendor/cfsolve/src/stage2/registry.rs +4 -3
- data/vendor/cfsolve/src/stage2/trace.rs +1 -1
- data/vendor/cfsolve/src/vm/dataflow.rs +15 -6
- data/vendor/cfsolve/src/vm/disassemble.rs +2 -1
- data/vendor/cfsolve/src/vm/encoded_strings.rs +1553 -0
- data/vendor/cfsolve/src/vm/extract.rs +205 -152
- data/vendor/cfsolve/src/vm/interpret/access.rs +0 -2
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +0 -13
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +30 -7
- data/vendor/cfsolve/src/vm/interpret/mix32.rs +216 -86
- data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +42 -21
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +268 -67
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +261 -30
- data/vendor/cfsolve/src/vm/machine.rs +14 -12
- data/vendor/cfsolve/src/vm/output.rs +4 -1
- data/vendor/cfsolve/src/vm/registers.rs +17 -23
- data/vendor/cfsolve/src/vm/session.rs +9 -4
- data/vendor/cfsolve/src/vm.rs +1 -0
- metadata +7 -1
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
//! Reconstructs `new Error()` stacks from the original script: the checkbox click's, the stack
|
|
2
2
|
//! probe's, and the challenge page's render call.
|
|
3
3
|
//!
|
|
4
|
-
//! The chain runs from the listener through the VM's runner and
|
|
4
|
+
//! The chain runs from the listener through the VM's runner and run function to the opcode
|
|
5
5
|
//! handler that constructs the error. Some builds use the runner directly as listener; others
|
|
6
6
|
//! add an arity-specific wrapper. Forwarders, helper-object methods, and selector-based
|
|
7
7
|
//! `Reflect.apply` helpers add their own frames. Recovery decodes only the string table,
|
|
8
8
|
//! preserving original positions and method keys.
|
|
9
9
|
//!
|
|
10
|
-
//! V8 names frames by call form, such as `Class.
|
|
10
|
+
//! V8 names frames by call form, such as `Class.handler` or `HTMLInputElement.<anonymous>`, and
|
|
11
11
|
//! uses callee positions. JavaScriptCore names them by definition, leaving many methods
|
|
12
12
|
//! anonymous, uses the opening argument parenthesis, and includes native `Reflect.construct`
|
|
13
13
|
//! frames. The script is sloppy code, so JavaScriptCore does not eliminate tail calls.
|
|
14
14
|
|
|
15
15
|
use std::collections::{HashMap, HashSet};
|
|
16
|
-
use std::mem;
|
|
17
16
|
use std::sync::Arc;
|
|
18
17
|
|
|
19
18
|
use anyhow::{Context, Result, bail};
|
|
20
19
|
use oxc::ast::AstKind;
|
|
21
20
|
use oxc::ast::ast::{
|
|
22
21
|
Argument, ArrayExpression, ArrayExpressionElement, AssignmentExpression, AssignmentTarget,
|
|
23
|
-
BindingPattern, CallExpression, Class,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
BindingPattern, CallExpression, Class, Expression, FormalParameter, Function, MemberExpression,
|
|
23
|
+
MethodDefinition, NewExpression, ObjectExpression, ObjectProperty, ObjectPropertyKind,
|
|
24
|
+
PropertyKind, Statement, SwitchCase, SwitchStatement, ThrowStatement, TryStatement,
|
|
25
|
+
VariableDeclarator,
|
|
27
26
|
};
|
|
28
27
|
use oxc::ast_visit::{Visit, walk};
|
|
29
28
|
use oxc::semantic::SymbolId;
|
|
@@ -238,12 +237,12 @@ pub fn recover_method_call(
|
|
|
238
237
|
})
|
|
239
238
|
}
|
|
240
239
|
|
|
241
|
-
/// Dispatch loop called by
|
|
240
|
+
/// Dispatch loop called by the run function, with details used to check stack recovery offline.
|
|
242
241
|
#[derive(Debug, Serialize)]
|
|
243
242
|
pub struct DispatchSummary {
|
|
244
243
|
pub function: String,
|
|
245
244
|
pub guarded: bool,
|
|
246
|
-
/// V8 frames from the dispatch loop to
|
|
245
|
+
/// V8 frames from the dispatch loop to the run function, innermost first.
|
|
247
246
|
pub frames: Vec<String>,
|
|
248
247
|
/// Number of opcodes dispatched by the loop.
|
|
249
248
|
pub opcodes: usize,
|
|
@@ -251,7 +250,8 @@ pub struct DispatchSummary {
|
|
|
251
250
|
pub unresolved: Vec<u8>,
|
|
252
251
|
}
|
|
253
252
|
|
|
254
|
-
/// Summarizes dispatch loops called by
|
|
253
|
+
/// Summarizes dispatch loops called by the run function, including whether each case resolves to
|
|
254
|
+
/// a function.
|
|
255
255
|
pub fn dispatch_summary(source: &str, cases: &CaseOpcodes) -> Result<Vec<DispatchSummary>> {
|
|
256
256
|
let decoded = deobfuscate::decode(source.to_owned())?;
|
|
257
257
|
let machine = Machine::new(decoded.script(), cases)?;
|
|
@@ -277,7 +277,7 @@ pub fn dispatch_summary(source: &str, cases: &CaseOpcodes) -> Result<Vec<Dispatc
|
|
|
277
277
|
unresolved.push(opcode);
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
let frames = dispatch_loop.call.frames(
|
|
280
|
+
let frames = dispatch_loop.call.frames(machine.run.frame());
|
|
281
281
|
summaries.push(DispatchSummary {
|
|
282
282
|
function: name.to_owned(),
|
|
283
283
|
guarded: dispatch_loop.guarded,
|
|
@@ -399,42 +399,48 @@ impl Callee<'_> {
|
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
-
/// The VM
|
|
403
|
-
/// parameter count.
|
|
402
|
+
/// The VM's run function, the closure runner that calls it, and listeners that wrap the closure
|
|
403
|
+
/// runner for each closure parameter count.
|
|
404
404
|
struct Machine<'a, 'cases> {
|
|
405
405
|
script: Script<'a>,
|
|
406
|
-
|
|
407
|
-
/// The dispatch loops
|
|
406
|
+
run: RunFunction<'a>,
|
|
407
|
+
/// The dispatch loops the run function calls.
|
|
408
408
|
loops: Vec<DispatchLoop<'a>>,
|
|
409
409
|
cases: &'cases CaseOpcodes,
|
|
410
|
-
runner
|
|
410
|
+
/// Frames from the call to the run function out to the closure runner, innermost first.
|
|
411
|
+
runner: Vec<Call>,
|
|
411
412
|
listeners: Vec<Invocation<'a>>,
|
|
412
413
|
}
|
|
413
414
|
|
|
414
415
|
impl<'a, 'cases> Machine<'a, 'cases> {
|
|
415
416
|
fn new(js: ast::Script<'a>, cases: &'cases CaseOpcodes) -> Result<Self> {
|
|
416
|
-
let
|
|
417
|
-
let
|
|
418
|
-
// The runner passes the closure's program counter, key, and
|
|
419
|
-
// copying arguments when required by the VM function.
|
|
417
|
+
let script = Script::new(js);
|
|
418
|
+
let run = RunFunction::installed(&script)?;
|
|
419
|
+
// The closure runner passes the machine and the closure's program counter, key, and
|
|
420
|
+
// arguments to the run function, copying arguments when required by the VM function.
|
|
420
421
|
let mut runners = Vec::new();
|
|
421
422
|
for (name, function) in &script.functions {
|
|
423
|
+
let caller = Callee::Binding(*name);
|
|
424
|
+
let caller_name = script.appliers.name(caller);
|
|
425
|
+
let scope = Scope::new(caller_name, function, &script.appliers);
|
|
422
426
|
for call in calls_of(js, function) {
|
|
423
|
-
let
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
+
let Ok(target) = scope.target(call) else {
|
|
428
|
+
continue;
|
|
429
|
+
};
|
|
430
|
+
if target.callee == Some(run.name)
|
|
431
|
+
&& let Some(handed) = handed(Arguments::of(call), &target)
|
|
432
|
+
&& let [_, _, _, Operand::Expression(cells)] = handed[..]
|
|
427
433
|
&& matches!(
|
|
428
|
-
|
|
434
|
+
cells.without_parentheses(),
|
|
429
435
|
Expression::ConditionalExpression(_)
|
|
430
436
|
)
|
|
431
437
|
{
|
|
432
|
-
runners.push((
|
|
438
|
+
runners.push((caller, target.frames(Name::same(caller_name.to_owned()))));
|
|
433
439
|
}
|
|
434
440
|
}
|
|
435
441
|
}
|
|
436
|
-
let (runner,
|
|
437
|
-
|
|
442
|
+
let (runner, runner_frames) =
|
|
443
|
+
candidates::exactly_one(runners, "closure-to-VM runner call")?;
|
|
438
444
|
let mut listeners = Listeners {
|
|
439
445
|
runner,
|
|
440
446
|
appliers: &script.appliers,
|
|
@@ -442,18 +448,14 @@ impl<'a, 'cases> Machine<'a, 'cases> {
|
|
|
442
448
|
};
|
|
443
449
|
listeners.visit_program(js.program);
|
|
444
450
|
let listeners: Vec<Invocation> = listeners.found.into_iter().collect::<Result<_>>()?;
|
|
445
|
-
let
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
let (dispatch, loops) = candidates::exactly_one(dispatches, "VM dispatch method")?;
|
|
451
|
+
let loops = dispatch_loops(&script, &run);
|
|
452
|
+
if loops.is_empty() {
|
|
453
|
+
bail!("the run function calls no dispatch loop");
|
|
454
|
+
}
|
|
450
455
|
Ok(Self {
|
|
451
|
-
runner:
|
|
452
|
-
name: Name::same(script.appliers.name(runner).to_owned()),
|
|
453
|
-
site: Site::new(run_call),
|
|
454
|
-
},
|
|
456
|
+
runner: runner_frames,
|
|
455
457
|
listeners,
|
|
456
|
-
|
|
458
|
+
run,
|
|
457
459
|
loops,
|
|
458
460
|
script,
|
|
459
461
|
cases,
|
|
@@ -482,7 +484,7 @@ impl<'a, 'cases> Machine<'a, 'cases> {
|
|
|
482
484
|
let name = appliers.name(handler);
|
|
483
485
|
let frame = Name {
|
|
484
486
|
v8: if dispatch.method {
|
|
485
|
-
format!("{}.{name}", self.
|
|
487
|
+
format!("{}.{name}", self.run.class)
|
|
486
488
|
} else {
|
|
487
489
|
name.to_owned()
|
|
488
490
|
},
|
|
@@ -498,17 +500,14 @@ impl<'a, 'cases> Machine<'a, 'cases> {
|
|
|
498
500
|
bail!("no dispatch of opcode {opcode} (guarded: {guarded})")
|
|
499
501
|
}
|
|
500
502
|
|
|
501
|
-
/// Appends frames from the call to `handler` through the dispatch loop,
|
|
503
|
+
/// Appends frames from the call to `handler` through the dispatch loop, the run function, and
|
|
504
|
+
/// the closure runner.
|
|
502
505
|
fn entered(&self, handler: &Handler<'a, '_>, mut frames: Vec<Call>) -> Vec<Call> {
|
|
503
|
-
let DispatchMethod { class, key, .. } = &self.dispatch;
|
|
504
506
|
let dispatch_loop = handler.dispatch_loop;
|
|
505
507
|
let name = self.script.appliers.name(dispatch_loop.name);
|
|
506
508
|
frames.extend(handler.dispatch.frames(Name::same(name.to_owned())));
|
|
507
|
-
frames.extend(dispatch_loop.call.frames(
|
|
508
|
-
|
|
509
|
-
jsc: key.unwrap_or_default().to_owned(),
|
|
510
|
-
}));
|
|
511
|
-
frames.push(self.runner.clone());
|
|
509
|
+
frames.extend(dispatch_loop.call.frames(self.run.frame()));
|
|
510
|
+
frames.extend(self.runner.iter().cloned());
|
|
512
511
|
frames
|
|
513
512
|
}
|
|
514
513
|
|
|
@@ -620,7 +619,7 @@ impl<'a, 'cases> Machine<'a, 'cases> {
|
|
|
620
619
|
}
|
|
621
620
|
}
|
|
622
621
|
|
|
623
|
-
/// The function
|
|
622
|
+
/// The function a dispatch loop calls for an opcode.
|
|
624
623
|
struct Handler<'a, 'machine> {
|
|
625
624
|
/// Call from the dispatch loop to this handler.
|
|
626
625
|
dispatch: Invocation<'a>,
|
|
@@ -629,10 +628,10 @@ struct Handler<'a, 'machine> {
|
|
|
629
628
|
dispatch_loop: &'machine DispatchLoop<'a>,
|
|
630
629
|
}
|
|
631
630
|
|
|
632
|
-
/// Function called by
|
|
631
|
+
/// Function called by the run function with the machine to dispatch opcodes.
|
|
633
632
|
struct DispatchLoop<'a> {
|
|
634
633
|
name: Callee<'a>,
|
|
635
|
-
/// Call from
|
|
634
|
+
/// Call from the run function, either direct or through a helper.
|
|
636
635
|
call: Invocation<'a>,
|
|
637
636
|
/// Whether the call occurs in a `try` block that handles exceptions.
|
|
638
637
|
guarded: bool,
|
|
@@ -642,10 +641,11 @@ struct DispatchLoop<'a> {
|
|
|
642
641
|
/// helper switch.
|
|
643
642
|
const DISPATCH_CASES: usize = 40;
|
|
644
643
|
|
|
645
|
-
/// Finds functions with dispatch switches that
|
|
646
|
-
fn dispatch_loops<'a>(script: &Script<'a>, run: &
|
|
644
|
+
/// Finds functions with dispatch switches that the run function calls with the machine.
|
|
645
|
+
fn dispatch_loops<'a>(script: &Script<'a>, run: &RunFunction<'a>) -> Vec<DispatchLoop<'a>> {
|
|
647
646
|
struct Calls<'a> {
|
|
648
647
|
js: ast::Script<'a>,
|
|
648
|
+
machine: SymbolId,
|
|
649
649
|
found: Vec<(&'a CallExpression<'a>, bool)>,
|
|
650
650
|
guarded: bool,
|
|
651
651
|
}
|
|
@@ -671,10 +671,8 @@ fn dispatch_loops<'a>(script: &Script<'a>, run: &Body<'a>) -> Vec<DispatchLoop<'
|
|
|
671
671
|
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
672
672
|
if !is_optional_call(call)
|
|
673
673
|
&& call.arguments.iter().any(|argument| {
|
|
674
|
-
|
|
675
|
-
ast::argument_expression(argument),
|
|
676
|
-
Expression::ThisExpression(_)
|
|
677
|
-
)
|
|
674
|
+
self.js
|
|
675
|
+
.refers_to(ast::argument_expression(argument), self.machine)
|
|
678
676
|
})
|
|
679
677
|
{
|
|
680
678
|
let call = self.js.lend(call, AstKind::as_call_expression);
|
|
@@ -685,11 +683,12 @@ fn dispatch_loops<'a>(script: &Script<'a>, run: &Body<'a>) -> Vec<DispatchLoop<'
|
|
|
685
683
|
}
|
|
686
684
|
let mut calls = Calls {
|
|
687
685
|
js: script.js(),
|
|
686
|
+
machine: run.machine,
|
|
688
687
|
found: Vec::new(),
|
|
689
688
|
guarded: false,
|
|
690
689
|
};
|
|
691
|
-
run.visit(&mut calls);
|
|
692
|
-
let scope = Scope::new(
|
|
690
|
+
run.body.visit(&mut calls);
|
|
691
|
+
let scope = Scope::new(run.frame_name, &run.body, &script.appliers);
|
|
693
692
|
calls
|
|
694
693
|
.found
|
|
695
694
|
.into_iter()
|
|
@@ -773,11 +772,10 @@ impl<'a> Body<'a> {
|
|
|
773
772
|
}
|
|
774
773
|
}
|
|
775
774
|
|
|
776
|
-
/// The script's declared and assigned functions,
|
|
777
|
-
/// `Reflect.
|
|
775
|
+
/// The script's declared and assigned functions, and aliases for `Reflect.construct` and
|
|
776
|
+
/// `Reflect.apply`.
|
|
778
777
|
struct Script<'a> {
|
|
779
778
|
functions: Vec<(Binding<'a>, Body<'a>)>,
|
|
780
|
-
classes: Vec<DispatchMethod<'a>>,
|
|
781
779
|
constructs: Vec<Callee<'a>>,
|
|
782
780
|
/// Array slots containing `Reflect.construct`, indexed by array and slot.
|
|
783
781
|
construct_slots: Vec<(Binding<'a>, usize)>,
|
|
@@ -993,12 +991,70 @@ fn number<'a>(expression: &Expression<'a>, constants: &Constants<'a>) -> Option<
|
|
|
993
991
|
})
|
|
994
992
|
}
|
|
995
993
|
|
|
996
|
-
///
|
|
997
|
-
|
|
994
|
+
/// The VM's run function, which calls the dispatch loops. The program runner installs it as
|
|
995
|
+
/// `<global>.<name> = function(p) { return <run>(new <Class>(p), pc, key, []); }`, possibly
|
|
996
|
+
/// calling it through a helper.
|
|
997
|
+
struct RunFunction<'a> {
|
|
998
|
+
/// The VM class, which V8 names handlers called as methods of the machine after.
|
|
998
999
|
class: &'a str,
|
|
999
|
-
|
|
1000
|
-
/// The
|
|
1001
|
-
|
|
1000
|
+
name: Callee<'a>,
|
|
1001
|
+
/// The run function's name in the source, which both engines name its frame after.
|
|
1002
|
+
frame_name: &'a str,
|
|
1003
|
+
body: Body<'a>,
|
|
1004
|
+
/// The parameter receiving the machine.
|
|
1005
|
+
machine: SymbolId,
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
impl<'a> RunFunction<'a> {
|
|
1009
|
+
/// Finds the run function from the one program runner.
|
|
1010
|
+
fn installed(script: &Script<'a>) -> Result<Self> {
|
|
1011
|
+
let js = script.js();
|
|
1012
|
+
let mut found = Vec::new();
|
|
1013
|
+
for function in js.functions() {
|
|
1014
|
+
let body = Body::of(function);
|
|
1015
|
+
let Some(Statement::ReturnStatement(returned)) = body.only_statement() else {
|
|
1016
|
+
continue;
|
|
1017
|
+
};
|
|
1018
|
+
let Some(Expression::CallExpression(call)) = &returned.argument else {
|
|
1019
|
+
continue;
|
|
1020
|
+
};
|
|
1021
|
+
let Ok(target) = Scope::new("", &body, &script.appliers).target(call) else {
|
|
1022
|
+
continue;
|
|
1023
|
+
};
|
|
1024
|
+
if let Some(name) = target.callee
|
|
1025
|
+
&& let Some(handed) = handed(Arguments::of(call), &target)
|
|
1026
|
+
&& let [
|
|
1027
|
+
Operand::Expression(machine),
|
|
1028
|
+
_,
|
|
1029
|
+
_,
|
|
1030
|
+
Operand::Expression(cells),
|
|
1031
|
+
] = handed[..]
|
|
1032
|
+
&& let Expression::NewExpression(machine) = machine.without_parentheses()
|
|
1033
|
+
&& let Expression::Identifier(class) = &machine.callee
|
|
1034
|
+
&& array(cells).is_some_and(|cells| cells.elements.is_empty())
|
|
1035
|
+
{
|
|
1036
|
+
found.push((name, class.name.as_str()));
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
let (name, class) = candidates::exactly_one(found, "program runner")?;
|
|
1040
|
+
let body = script.function(name)?;
|
|
1041
|
+
let machine = body
|
|
1042
|
+
.parameters()
|
|
1043
|
+
.and_then(|parameters| parameters.first().copied())
|
|
1044
|
+
.context("the run function takes no machine")?;
|
|
1045
|
+
Ok(Self {
|
|
1046
|
+
class,
|
|
1047
|
+
name,
|
|
1048
|
+
frame_name: script.appliers.name(name),
|
|
1049
|
+
body,
|
|
1050
|
+
machine,
|
|
1051
|
+
})
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
/// The run function's frame.
|
|
1055
|
+
fn frame(&self) -> Name {
|
|
1056
|
+
Name::same(self.frame_name.to_owned())
|
|
1057
|
+
}
|
|
1002
1058
|
}
|
|
1003
1059
|
|
|
1004
1060
|
impl<'a> Script<'a> {
|
|
@@ -1013,7 +1069,6 @@ impl<'a> Script<'a> {
|
|
|
1013
1069
|
let appliers = Appliers::new(js, &functions);
|
|
1014
1070
|
let mut script = Self {
|
|
1015
1071
|
functions,
|
|
1016
|
-
classes: Vec::new(),
|
|
1017
1072
|
constructs: Vec::new(),
|
|
1018
1073
|
construct_slots: Vec::new(),
|
|
1019
1074
|
applies: Vec::new(),
|
|
@@ -1021,10 +1076,8 @@ impl<'a> Script<'a> {
|
|
|
1021
1076
|
appliers,
|
|
1022
1077
|
};
|
|
1023
1078
|
for node in js.nodes.iter() {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
AstKind::Class(class) if class.is_declaration() => script.class(class),
|
|
1027
|
-
_ => {}
|
|
1079
|
+
if let AstKind::AssignmentExpression(assignment) = node.kind() {
|
|
1080
|
+
script.assignment(assignment);
|
|
1028
1081
|
}
|
|
1029
1082
|
}
|
|
1030
1083
|
script
|
|
@@ -1069,28 +1122,6 @@ impl<'a> Script<'a> {
|
|
|
1069
1122
|
}
|
|
1070
1123
|
}
|
|
1071
1124
|
|
|
1072
|
-
/// Records a class declaration's `run` method.
|
|
1073
|
-
fn class(&mut self, class: &'a Class<'a>) {
|
|
1074
|
-
let run = class.body.body.iter().find_map(|element| match element {
|
|
1075
|
-
ClassElement::MethodDefinition(method)
|
|
1076
|
-
if method.kind != MethodDefinitionKind::Constructor
|
|
1077
|
-
&& ast::static_key_str(&method.key, method.computed) == Some("run") =>
|
|
1078
|
-
{
|
|
1079
|
-
Some(method)
|
|
1080
|
-
}
|
|
1081
|
-
_ => None,
|
|
1082
|
-
});
|
|
1083
|
-
if let Some(method) = run
|
|
1084
|
-
&& let Some(name) = &class.id
|
|
1085
|
-
{
|
|
1086
|
-
self.classes.push(DispatchMethod {
|
|
1087
|
-
class: name.name.as_str(),
|
|
1088
|
-
run: Body::of(&method.value),
|
|
1089
|
-
key: ast::key_str(&method.key, method.computed),
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
1125
|
fn function(&self, callee: Callee<'a>) -> Result<Body<'a>> {
|
|
1095
1126
|
match callee {
|
|
1096
1127
|
Callee::Binding(binding) => self
|
|
@@ -1983,8 +2014,9 @@ impl<'a, 's> Scope<'a, 's> {
|
|
|
1983
2014
|
}
|
|
1984
2015
|
}
|
|
1985
2016
|
|
|
1986
|
-
/// Records forwarders defined by an object literal assigned to `holder`.
|
|
1987
|
-
///
|
|
2017
|
+
/// Records forwarders defined by an object literal assigned to `holder`. V8 names functions
|
|
2018
|
+
/// by their property keys, including computed keys. JavaScriptCore leaves functions under
|
|
2019
|
+
/// computed keys anonymous: obfuscation computes them with string decoder calls.
|
|
1988
2020
|
fn literal(&mut self, holder: Holder<'a>, object: &'a ObjectExpression<'a>) {
|
|
1989
2021
|
// Matches `key: function` properties and methods, but not accessors.
|
|
1990
2022
|
for property in &object.properties {
|
|
@@ -1992,7 +2024,14 @@ impl<'a, 's> Scope<'a, 's> {
|
|
|
1992
2024
|
&& let Expression::FunctionExpression(function) = &property.value
|
|
1993
2025
|
&& property.kind == PropertyKind::Init
|
|
1994
2026
|
&& let Some(key) = ast::static_key_str(&property.key, property.computed)
|
|
1995
|
-
&& let Some(frames) = self.forwarder(
|
|
2027
|
+
&& let Some(frames) = self.forwarder(
|
|
2028
|
+
function,
|
|
2029
|
+
if property.computed {
|
|
2030
|
+
Name::anonymous(key.to_owned())
|
|
2031
|
+
} else {
|
|
2032
|
+
Name::same(key.to_owned())
|
|
2033
|
+
},
|
|
2034
|
+
)
|
|
1996
2035
|
{
|
|
1997
2036
|
let forwarder = Forwarder {
|
|
1998
2037
|
method: frames.clone(),
|
|
@@ -11,7 +11,6 @@ use anyhow::{Context, Result, bail, ensure};
|
|
|
11
11
|
use indexmap::IndexMap;
|
|
12
12
|
use url::Url;
|
|
13
13
|
|
|
14
|
-
use crate::candidates;
|
|
15
14
|
use crate::js::{JsObject, JsValue, Options, Payload, Window, json};
|
|
16
15
|
use crate::listing::fold::DECODER_CELL;
|
|
17
16
|
use crate::listing::query::Store;
|
|
@@ -22,6 +21,7 @@ use crate::stage2::payload::{
|
|
|
22
21
|
};
|
|
23
22
|
use crate::stage2::queries;
|
|
24
23
|
use crate::vm::{Constant, Effect, Listing, Term};
|
|
24
|
+
use crate::{candidates, challenge};
|
|
25
25
|
|
|
26
26
|
/// Widget parameters passed to `turnstile.render`, excluding callbacks.
|
|
27
27
|
const RENDER_PARAMETERS: [&str; 8] = [
|
|
@@ -322,7 +322,7 @@ impl Reader<'_> {
|
|
|
322
322
|
})
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
-
/// Recovers outcome fields from callbacks. Expiry writes
|
|
325
|
+
/// Recovers outcome fields from callbacks. Expiry writes its status and clears the token;
|
|
326
326
|
/// success writes the token. Both call shared finishing functions.
|
|
327
327
|
fn outcome(&self, callbacks: &BTreeMap<String, u32>, started: &str) -> Result<SettledFields> {
|
|
328
328
|
let entry = |name: &str| {
|
|
@@ -334,9 +334,16 @@ impl Reader<'_> {
|
|
|
334
334
|
let expired: Vec<&Store> = self
|
|
335
335
|
.stores_in(self.index.function_at(entry("expired-callback")?))
|
|
336
336
|
.collect();
|
|
337
|
+
// The status is `"expired"`, or in builds with hex names, one of those names.
|
|
337
338
|
let status = expired
|
|
338
339
|
.iter()
|
|
339
|
-
.find(|store|
|
|
340
|
+
.find(|store| {
|
|
341
|
+
matches!(
|
|
342
|
+
self.origin(store.pc, &store.value),
|
|
343
|
+
Some(Expression::Literal { value: JsValue::String(text) })
|
|
344
|
+
if text == "expired" || challenge::is_hex_name(&text)
|
|
345
|
+
)
|
|
346
|
+
})
|
|
340
347
|
.context("expiry callback writes no status")?
|
|
341
348
|
.key
|
|
342
349
|
.clone();
|