cfsolve 0.1.3 → 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 +15 -0
- data/README.md +8 -3
- data/UPSTREAM.md +8 -2
- data/lib/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
- data/lib/cfsolve/profiles/chrome-157-macos.json +613 -0
- data/lib/cfsolve/version.rb +2 -2
- data/lib/cfsolve.rb +1 -1
- data/vendor/cfsolve/README.md +53 -5
- data/vendor/cfsolve/examples/turnstile_smoke.rs +58 -0
- data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +4777 -0
- data/vendor/cfsolve/profiles/chrome-157-macos.json +613 -0
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +110 -7
- data/vendor/cfsolve/src/embedding_page/page.rs +41 -1
- data/vendor/cfsolve/src/session/initial.rs +7 -6
- data/vendor/cfsolve/src/session/probes.rs +1 -0
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +33 -4
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +13 -2
- data/vendor/cfsolve/src/stage2/benchmark.rs +59 -18
- data/vendor/cfsolve/src/stage2/call_stack.rs +169 -36
- data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +1 -0
- 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/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/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/value_labels.rs +185 -0
- data/vendor/cfsolve/src/stage2/vocabulary.rs +111 -6
- data/vendor/cfsolve/src/stage2.rs +1 -0
- data/vendor/cfsolve/src/vm/disassemble.rs +68 -4
- data/vendor/cfsolve/src/vm/encoded_names.rs +635 -0
- data/vendor/cfsolve/src/vm/extract.rs +246 -43
- 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 +8 -2
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +39 -1
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +33 -4
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +14 -6
- data/vendor/cfsolve/src/vm/interpret/run.rs +4 -0
- data/vendor/cfsolve/src/vm/machine.rs +63 -5
- data/vendor/cfsolve/src/vm/output.rs +6 -1
- data/vendor/cfsolve/src/vm/registers.rs +35 -21
- data/vendor/cfsolve/src/vm/session.rs +6 -3
- data/vendor/cfsolve/src/vm.rs +1 -0
- metadata +13 -1
|
@@ -407,7 +407,7 @@ struct Machine<'a, 'cases> {
|
|
|
407
407
|
/// The dispatch loops `run` calls.
|
|
408
408
|
loops: Vec<DispatchLoop<'a>>,
|
|
409
409
|
cases: &'cases CaseOpcodes,
|
|
410
|
-
runner: Call
|
|
410
|
+
runner: Vec<Call>,
|
|
411
411
|
listeners: Vec<Invocation<'a>>,
|
|
412
412
|
}
|
|
413
413
|
|
|
@@ -419,21 +419,47 @@ impl<'a, 'cases> Machine<'a, 'cases> {
|
|
|
419
419
|
// copying arguments when required by the VM function.
|
|
420
420
|
let mut runners = Vec::new();
|
|
421
421
|
for (name, function) in &script.functions {
|
|
422
|
+
let scope = Scope::new(js.name(*name), function, &script.appliers);
|
|
422
423
|
for call in calls_of(js, function) {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
&& call.arguments.len() == 3
|
|
427
|
-
&& matches!(
|
|
428
|
-
ast::argument_expression(&call.arguments[2]),
|
|
424
|
+
if !call.arguments.last().is_some_and(|argument| {
|
|
425
|
+
matches!(
|
|
426
|
+
ast::argument_expression(argument),
|
|
429
427
|
Expression::ConditionalExpression(_)
|
|
430
428
|
)
|
|
429
|
+
}) {
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
let calls_run = member(&call.callee)
|
|
433
|
+
.is_some_and(|member| ast::member_str(member) == Some("run"));
|
|
434
|
+
if calls_run && call.arguments.len() == 3 {
|
|
435
|
+
runners.push((*name, Invocation::at(Site::new(call)), None));
|
|
436
|
+
} else if let Ok(invocation) = scope.target(call)
|
|
437
|
+
&& invocation.passed == Some(4)
|
|
438
|
+
&& let Some(callee) = invocation.callee
|
|
439
|
+
&& let Ok(run) = script.function(callee)
|
|
440
|
+
&& let Some(machine) =
|
|
441
|
+
run.parameters().and_then(|params| params.first().copied())
|
|
431
442
|
{
|
|
432
|
-
|
|
443
|
+
let loops = dispatch_loops(&script, &run, Some(machine));
|
|
444
|
+
if !loops.is_empty() {
|
|
445
|
+
runners.push((
|
|
446
|
+
*name,
|
|
447
|
+
invocation,
|
|
448
|
+
Some((
|
|
449
|
+
DispatchMethod {
|
|
450
|
+
class: None,
|
|
451
|
+
run,
|
|
452
|
+
frame: Name::same(script.appliers.name(callee).to_owned()),
|
|
453
|
+
},
|
|
454
|
+
loops,
|
|
455
|
+
)),
|
|
456
|
+
));
|
|
457
|
+
}
|
|
433
458
|
}
|
|
434
459
|
}
|
|
435
460
|
}
|
|
436
|
-
let (runner, run_call) =
|
|
461
|
+
let (runner, run_call, free_dispatch) =
|
|
462
|
+
candidates::exactly_one(runners, "closure-to-VM runner call")?;
|
|
437
463
|
let runner = Callee::Binding(runner);
|
|
438
464
|
let mut listeners = Listeners {
|
|
439
465
|
runner,
|
|
@@ -442,16 +468,18 @@ impl<'a, 'cases> Machine<'a, 'cases> {
|
|
|
442
468
|
};
|
|
443
469
|
listeners.visit_program(js.program);
|
|
444
470
|
let listeners: Vec<Invocation> = listeners.found.into_iter().collect::<Result<_>>()?;
|
|
445
|
-
let
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
471
|
+
let (dispatch, loops) = match free_dispatch {
|
|
472
|
+
Some(dispatch) => dispatch,
|
|
473
|
+
None => {
|
|
474
|
+
let dispatches = classes.into_iter().filter_map(|dispatch| {
|
|
475
|
+
let loops = dispatch_loops(&script, &dispatch.run, None);
|
|
476
|
+
(!loops.is_empty()).then_some((dispatch, loops))
|
|
477
|
+
});
|
|
478
|
+
candidates::exactly_one(dispatches, "VM dispatch method")?
|
|
479
|
+
}
|
|
480
|
+
};
|
|
450
481
|
Ok(Self {
|
|
451
|
-
runner:
|
|
452
|
-
name: Name::same(script.appliers.name(runner).to_owned()),
|
|
453
|
-
site: Site::new(run_call),
|
|
454
|
-
},
|
|
482
|
+
runner: run_call.frames(Name::same(script.appliers.name(runner).to_owned())),
|
|
455
483
|
listeners,
|
|
456
484
|
dispatch,
|
|
457
485
|
loops,
|
|
@@ -482,7 +510,12 @@ impl<'a, 'cases> Machine<'a, 'cases> {
|
|
|
482
510
|
let name = appliers.name(handler);
|
|
483
511
|
let frame = Name {
|
|
484
512
|
v8: if dispatch.method {
|
|
485
|
-
format!(
|
|
513
|
+
format!(
|
|
514
|
+
"{}.{name}",
|
|
515
|
+
self.dispatch
|
|
516
|
+
.class
|
|
517
|
+
.context("missing VM class for method handler")?
|
|
518
|
+
)
|
|
486
519
|
} else {
|
|
487
520
|
name.to_owned()
|
|
488
521
|
},
|
|
@@ -500,15 +533,11 @@ impl<'a, 'cases> Machine<'a, 'cases> {
|
|
|
500
533
|
|
|
501
534
|
/// Appends frames from the call to `handler` through the dispatch loop, `run`, and the runner.
|
|
502
535
|
fn entered(&self, handler: &Handler<'a, '_>, mut frames: Vec<Call>) -> Vec<Call> {
|
|
503
|
-
let DispatchMethod { class, key, .. } = &self.dispatch;
|
|
504
536
|
let dispatch_loop = handler.dispatch_loop;
|
|
505
537
|
let name = self.script.appliers.name(dispatch_loop.name);
|
|
506
538
|
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());
|
|
539
|
+
frames.extend(dispatch_loop.call.frames(self.dispatch.frame.clone()));
|
|
540
|
+
frames.extend(self.runner.iter().cloned());
|
|
512
541
|
frames
|
|
513
542
|
}
|
|
514
543
|
|
|
@@ -643,11 +672,16 @@ struct DispatchLoop<'a> {
|
|
|
643
672
|
const DISPATCH_CASES: usize = 40;
|
|
644
673
|
|
|
645
674
|
/// Finds functions with dispatch switches that `run` calls with the machine.
|
|
646
|
-
fn dispatch_loops<'a>(
|
|
675
|
+
fn dispatch_loops<'a>(
|
|
676
|
+
script: &Script<'a>,
|
|
677
|
+
run: &Body<'a>,
|
|
678
|
+
machine: Option<SymbolId>,
|
|
679
|
+
) -> Vec<DispatchLoop<'a>> {
|
|
647
680
|
struct Calls<'a> {
|
|
648
681
|
js: ast::Script<'a>,
|
|
649
682
|
found: Vec<(&'a CallExpression<'a>, bool)>,
|
|
650
683
|
guarded: bool,
|
|
684
|
+
machine: Option<SymbolId>,
|
|
651
685
|
}
|
|
652
686
|
impl<'a> Visit<'a> for Calls<'a> {
|
|
653
687
|
fn visit_function(&mut self, _: &Function<'a>, _: ScopeFlags) {}
|
|
@@ -671,10 +705,13 @@ fn dispatch_loops<'a>(script: &Script<'a>, run: &Body<'a>) -> Vec<DispatchLoop<'
|
|
|
671
705
|
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
672
706
|
if !is_optional_call(call)
|
|
673
707
|
&& call.arguments.iter().any(|argument| {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
Expression::
|
|
677
|
-
|
|
708
|
+
match ast::argument_expression(argument).without_parentheses() {
|
|
709
|
+
Expression::ThisExpression(_) => self.machine.is_none(),
|
|
710
|
+
Expression::Identifier(reference) => {
|
|
711
|
+
self.machine.is_some() && self.js.symbol(reference) == self.machine
|
|
712
|
+
}
|
|
713
|
+
_ => false,
|
|
714
|
+
}
|
|
678
715
|
})
|
|
679
716
|
{
|
|
680
717
|
let call = self.js.lend(call, AstKind::as_call_expression);
|
|
@@ -687,6 +724,7 @@ fn dispatch_loops<'a>(script: &Script<'a>, run: &Body<'a>) -> Vec<DispatchLoop<'
|
|
|
687
724
|
js: script.js(),
|
|
688
725
|
found: Vec::new(),
|
|
689
726
|
guarded: false,
|
|
727
|
+
machine,
|
|
690
728
|
};
|
|
691
729
|
run.visit(&mut calls);
|
|
692
730
|
let scope = Scope::new("", run, &script.appliers);
|
|
@@ -993,12 +1031,11 @@ fn number<'a>(expression: &Expression<'a>, constants: &Constants<'a>) -> Option<
|
|
|
993
1031
|
})
|
|
994
1032
|
}
|
|
995
1033
|
|
|
996
|
-
///
|
|
1034
|
+
/// The VM class method or free function that calls the dispatch loops.
|
|
997
1035
|
struct DispatchMethod<'a> {
|
|
998
|
-
class:
|
|
1036
|
+
class: Option<&'a str>,
|
|
999
1037
|
run: Body<'a>,
|
|
1000
|
-
|
|
1001
|
-
key: Option<&'a str>,
|
|
1038
|
+
frame: Name,
|
|
1002
1039
|
}
|
|
1003
1040
|
|
|
1004
1041
|
impl<'a> Script<'a> {
|
|
@@ -1084,9 +1121,14 @@ impl<'a> Script<'a> {
|
|
|
1084
1121
|
&& let Some(name) = &class.id
|
|
1085
1122
|
{
|
|
1086
1123
|
self.classes.push(DispatchMethod {
|
|
1087
|
-
class: name.name.as_str(),
|
|
1124
|
+
class: Some(name.name.as_str()),
|
|
1088
1125
|
run: Body::of(&method.value),
|
|
1089
|
-
|
|
1126
|
+
frame: Name {
|
|
1127
|
+
v8: format!("{}.run", name.name),
|
|
1128
|
+
jsc: ast::key_str(&method.key, method.computed)
|
|
1129
|
+
.unwrap_or_default()
|
|
1130
|
+
.to_owned(),
|
|
1131
|
+
},
|
|
1090
1132
|
});
|
|
1091
1133
|
}
|
|
1092
1134
|
}
|
|
@@ -2221,6 +2263,97 @@ impl<'a> Visit<'a> for Listeners<'a, '_> {
|
|
|
2221
2263
|
mod tests {
|
|
2222
2264
|
use super::*;
|
|
2223
2265
|
|
|
2266
|
+
#[test]
|
|
2267
|
+
fn recovers_method_and_free_dispatch_stacks() {
|
|
2268
|
+
let cases: String = (0..=DISPATCH_CASES)
|
|
2269
|
+
.map(|opcode| format!("case {opcode}: construct(vm); break;"))
|
|
2270
|
+
.collect();
|
|
2271
|
+
for (declaration, call, v8, jsc) in [
|
|
2272
|
+
(
|
|
2273
|
+
"class Machine { run(pc,key,args) { dispatch(this); } }",
|
|
2274
|
+
"vm.run(pc,key,copy ? args.slice() : args)",
|
|
2275
|
+
"Machine.run",
|
|
2276
|
+
"run",
|
|
2277
|
+
),
|
|
2278
|
+
(
|
|
2279
|
+
"function drive(vm,pc,key,args) { dispatch(vm); }",
|
|
2280
|
+
"drive(vm,pc,key,copy ? args.slice() : args)",
|
|
2281
|
+
"drive",
|
|
2282
|
+
"drive",
|
|
2283
|
+
),
|
|
2284
|
+
] {
|
|
2285
|
+
let source = format!(
|
|
2286
|
+
"function construct(vm) {{ return new Error(); }}\n\
|
|
2287
|
+
function dispatch(vm) {{ switch(opcode) {{ {cases} }} }}\n\
|
|
2288
|
+
{declaration}\n\
|
|
2289
|
+
function resume(vm,pc,key,args,copy) {{ return {call}; }}"
|
|
2290
|
+
);
|
|
2291
|
+
let (_, opcodes) = deobfuscate_with_cases(source.clone()).unwrap();
|
|
2292
|
+
let result =
|
|
2293
|
+
geometry(&source, &opcodes, |machine| machine.construction(1, false)).unwrap();
|
|
2294
|
+
assert_eq!(
|
|
2295
|
+
result
|
|
2296
|
+
.frames
|
|
2297
|
+
.iter()
|
|
2298
|
+
.map(|frame| frame.function.as_str())
|
|
2299
|
+
.collect::<Vec<_>>(),
|
|
2300
|
+
["construct", "dispatch", v8, "resume"]
|
|
2301
|
+
);
|
|
2302
|
+
assert_eq!(
|
|
2303
|
+
result
|
|
2304
|
+
.jsc_frames
|
|
2305
|
+
.iter()
|
|
2306
|
+
.map(|frame| frame.function.as_str())
|
|
2307
|
+
.collect::<Vec<_>>(),
|
|
2308
|
+
["construct", "dispatch", jsc, "resume"]
|
|
2309
|
+
);
|
|
2310
|
+
for frames in [&result.frames, &result.jsc_frames] {
|
|
2311
|
+
assert_eq!(
|
|
2312
|
+
frames.iter().map(|frame| frame.line).collect::<Vec<_>>(),
|
|
2313
|
+
[0, 1, 2, 3]
|
|
2314
|
+
);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
#[test]
|
|
2320
|
+
fn free_dispatch_stacks_preserve_helpers_and_merged_frames() {
|
|
2321
|
+
let cases: String = (0..=DISPATCH_CASES)
|
|
2322
|
+
.map(|opcode| format!("case {opcode}: construct(vm); break;"))
|
|
2323
|
+
.collect();
|
|
2324
|
+
for (declaration, call, expected) in [
|
|
2325
|
+
(
|
|
2326
|
+
"function drive(vm,pc,key,args) { dispatch(vm); } function apply(s,f,a,b,c,d) { switch(s^5) { case 6: return f(a,b,c,d); } }",
|
|
2327
|
+
"apply(3,drive,vm,pc,key,copy ? args.slice() : args)",
|
|
2328
|
+
&["construct", "dispatch", "drive", "apply", "resume"][..],
|
|
2329
|
+
),
|
|
2330
|
+
(
|
|
2331
|
+
"function choose(s,vm,pc,key,args) { switch(s^5) { case 6: { dispatch(vm); } return; case 7: { unrelated(); } return; } }",
|
|
2332
|
+
"choose(3,vm,pc,key,copy ? args.slice() : args)",
|
|
2333
|
+
&["construct", "dispatch", "choose", "resume"][..],
|
|
2334
|
+
),
|
|
2335
|
+
] {
|
|
2336
|
+
let source = format!(
|
|
2337
|
+
"function construct(vm) {{ return new Error(); }}\n\
|
|
2338
|
+
function dispatch(vm) {{ switch(opcode) {{ {cases} }} }}\n\
|
|
2339
|
+
{declaration}\n\
|
|
2340
|
+
function resume(vm,pc,key,args,copy) {{ return {call}; }}"
|
|
2341
|
+
);
|
|
2342
|
+
let (_, opcodes) = deobfuscate_with_cases(source.clone()).unwrap();
|
|
2343
|
+
let result =
|
|
2344
|
+
geometry(&source, &opcodes, |machine| machine.construction(1, false)).unwrap();
|
|
2345
|
+
for frames in [&result.frames, &result.jsc_frames] {
|
|
2346
|
+
assert_eq!(
|
|
2347
|
+
frames
|
|
2348
|
+
.iter()
|
|
2349
|
+
.map(|frame| frame.function.as_str())
|
|
2350
|
+
.collect::<Vec<_>>(),
|
|
2351
|
+
expected
|
|
2352
|
+
);
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2224
2357
|
/// The decoded program captured during deobfuscation equals the one decoding alone
|
|
2225
2358
|
/// produces, for a saved script named by `CFSOLVE_CAPTURE_SCRIPT`.
|
|
2226
2359
|
#[test]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
~function(){var d,e,g,i,k,l,n,p,r;var a=(function(J){var I={__proto__:null},q=J.String;return function(L){var w=I[L];if(w===void 0){var b=J.atob(L),m=61659,w=``,E=0,O=[];while(E<b.length){m=(m<<8|m>>>8)&65535;var M=b.charCodeAt(E++)^m>>>8;if(M===255){m=(m<<8|m>>>8)&65535;M=b.charCodeAt(E++)^m>>>8;m=(m<<8|m>>>8)&65535;M|=(b.charCodeAt(E++)^m>>>8)<<8}O.push(M);if(O.length===128){w+=q.fromCharCode.apply(q,O);O=[]}}w+=q.fromCharCode.apply(q,O);I[L]=w}return w}})(globalThis);d=a("t5W1l6+Y");e=a("uJi6gpifv5WahA==");g=a("tpm1");i=a("tZ+s");k=a("qJyyk74=");l=a("q5+ohJaVqIO6l74=");n=a("sp6ohLqeuJU=");p=a("voirn6mEqA==");r=a("q4WomA==");~function(){var c=["a","b","c","d"];var m=a("mredirmhnrGasZqymZedl5qo47K9sZa2mbGasZqxmraah56xnrG4kZmhgYSBp+qGuJ6ws5qxnZiasZqygpeaspqnlrGal52bmrGWu7aXtLWph5a0mqiosr2HnceSsZmymqiXyZ6jmrGKoZWDiqGdifSirLKSsZmy6qGZivSirLOSsZmymcO/spqol8mTsZaYmqGRsZKxmbafoZqXmrWeuLijnrOam5qzirOasYqhs6CfoZ/Jn7y3xZXF7cW+pL6Vrqiww7WCt8WVxe+YmoesspiJmrGKqLOIkqGfyZ+8t8WVxe3FvqS+la6osMO1grfFlcXvmJqHlbGSsZ6Xmt/pwZqjmrT0oaHBvqOvhOKosIK5lo3FkMLowb6jr4T0ke+y9JKOspKxi8mfv6mKjYSpgePBuZHthpWn6YWpio2Eqcmpl5PJr6Gel5rf673owumzicnihLybvZa5qZG46MLps4nf6YWalunBmqOatPShoaXuxunA6r++hK++j56pko+l7sbpwPSR77L0ko6ykrGLyZ+9t5jpo5O6gpSwmKKnk6qSk7eY6aOTyamXk8mvoZ6Xmt/rva2EqLWxx+ySmbnw2+mHiKCthKi1sd/phZqW6cGao5q09KGiio2kn8iowY6H9LyVppagooqNpJ/I9JHvsvSSjrKSoZ6Xmt/rvaq94pK6kbGgjMK2n6HBr4CqveKSupbphZqjnrSSsZmyvre0mZqx67GYiZqziaHrspiHlbGSsZ6Xmt/pwZqjnrKSsYvJn6CNxZDC6MG+o6+E4qiwgrmWjcWQwujJqZeemJqJmrOKqOKBkpeSvpqxqLySsZPJnIeYw5Kxk8mch5zDtLOasvSiqLOvxpqXmpbrkprHvpeY37C0moedx5qo47K+iZqxiqGdifSimpeatZ6yv5uesriG65Gao5qxiqGRwoqhnYn0orSzkrGZsprDgbKaqJfJnJeWl5q1nrW/m56yuIbrkZmzmrGKoY3CiqGdifSitLaSsZmymZ6Bspqol8mcl4KXmrWeuL+bnrK4huuRmYmespqbmpeatY6+mrOasYqhv4iSoZKzirGRsZKxmbKYteO+mqDrvZXF78O1mr6VlcXvw7WavpWVxe/DtZmetJ+xnrySsZmyvriemJqg672Vxe/DtZq+lZXF78O1mr6VlcXvw7WZnrSawJqXmqOatPSqjrKSsYvJn7OvhJDC64K5o6+EkMLrgrmjr4SQwujJsZeTybehnpea3+u9jYSrp+mcuZGNhKun6Zy5kY2Eq6fphum/mpbpppqjmrT0oaKyicSduLylvrKJxJ24vKW+sonEnbj0qe+y9KqOspKxi8mfu6LAqbyIg6+7osCpvIiDr7uiwKm8j8mxl5PJt6Gel5rf673qiZOokpS4mOqJk6iSlLiY6omTqJKW6b+alummmqOatPShrLOxh5Cgmp/js7GHkKCan+OzsYeQoPSp77L0qo6ykrGLyZ+z6MiXlqyE9LPoyJeWrIT0s+jIl5ahybGXk8m3oZ6YmqOatPSho6m6prOAjLe3qbqms4CMt7epuqazgPSp77KSoZaXmrWdxLqZkrGfoZq8krGRtp+hnryawJqXmqOatPSqjrKSoZ6Xmt/rvZDC64K5o6+EkMLrgrmjr4SQwuuCuZbpv5qjnrSSsZGyvcK0mZqX67GYh6iXmpbrqZq8uJealuupmpK+l5Kxk8mcsZDDtLOasvSivLSvxpqXmpbrqZm8vpeSsZPJnLGMw7SzmrL0ory3r8aal5qW66mZx76XmMG4spqoqJeatZy1s5+8ubiG66KSoZ6zirOasYmh67GawJqXmqOasvSh67Kal5axmaGCuJmxsLuYh7y+n5fjvZKhnpeatZ3fupmSsZ+hmryYiZqy9KKosa+JmrL0oqiyr8aal5qW65Kagr6XkrGTyZyHlMO0sa6kmpeWsr6Hnd+anqiXmryVtIPDmLqWuom0mrGYsYvFl8meiZ6ympual5q1jr6asZGxkrGZspqlgr6as5qxiqGdiJKhkpeatZ3buKOesZrAmpealuu9mqGYsYuHnrG8tOOymrma35qhmLGLiZK09JWCsvShrLGasZjfmrGasa2HmrGavOOxmrGY35KXk8nusZPJn7GasZq047GasZrfmrGasYuHmrGatOOZmaDom5qjmrT0lbiykrGLye6XnpealuibmqOatfSVirKSsYvJ7oeemJqjmrGKqO6BkpeavpqxqJeam46+mqGol5qW672aoZixi4eesby047KauZrfmqGYsYuJkrT0lYKy9KGssZqxmN+asZqxrYeasZq847GasZjf9JWKsvShrLGasZrfmrGasYuHmrGatOOxmrGa3/SVirKSsYvJ7oeemJqhqJealuuWmryol5qW65aakq6XkrGTyZOHkMe0s5qy9KLjtK7Gmrw=");function U(q){var D=atob(q);var N=D[d];var v=new Uint8Array(N);for(var f=0;f<N;f++){v[f]=D[e](f)}return v}var z=0;function j(q,D,N){q[D](Math[g](N,plan._0edcdf5edd841b2aaa59320c)>>>0);var v=performance[i]();var f=q[D](N>>>.04);var Q=performance[i]()-v;z+=f;return Q}function o(q,D){var N={};N[`_a83f5892274c8cb05c4b9e2c`]=q;var v=N;D&&(v._595f60a3a872bf4393044b12=String(D)[k](0,256));self[l]({"_b1b7232329cf8343b9b9de2f":v})}(function(){try{if(typeof WebAssembly===a("rp6/lb2ZtZW/")){o(`_959dae60c4f18fa855adbea9`);return}var q=plan._5789c64e096112b22c52e80f;var D=plan._7f8289304361962296ebf3f6;var N=performance[i]();WebAssembly[a("sp6ohLqer5m6hL4=")](U(m)[a("uYW9lr6C")],{})[a("r5i+ng==")](function(f){try{var Q=performance[i]()-N;var S=f[n][p];var J=[];for(var Y=0;Y<q[d];Y++){J[r]([])}var V=performance[i]();for(var E=0;E<plan._447c0ac98523cf3d6a2324d9;E++){for(var Y=0;Y<q[d];Y++){var y=c[q[Y]];J[Y][r](j(S,y,D[Y]))}}var h=performance[i]()-V;self._9fc7bdf2f9548c78328993d9=z;self[l]({"_b1b7232329cf8343b9b9de2f":{"_e712758a2abf0550c8c03caf":J,"_330c1c3a2512b4edd9f7a483":Q,"_6e07b0330abb107d89bcb031":h}})}catch(P){o(`_098c9045191c50327f66c1c2`,P)}},function(f){o(`_8b9e542c34b5583e7dc6c3cc`,f)})}catch(v){o(`_098c9045191c50327f66c1c2`,v)}})()}();}()
|
|
@@ -4,6 +4,7 @@ use anyhow::{Context, Result};
|
|
|
4
4
|
use chrono::{DateTime, Local, NaiveDate, NaiveTime, TimeZone, Utc};
|
|
5
5
|
use indexmap::IndexMap;
|
|
6
6
|
use serde::{Deserialize, Serialize};
|
|
7
|
+
use std::collections::BTreeMap;
|
|
7
8
|
|
|
8
9
|
use crate::engine::Engine;
|
|
9
10
|
use crate::js::{JsObject, json};
|
|
@@ -13,6 +14,30 @@ use crate::stage2::reference;
|
|
|
13
14
|
/// The historical years the probe parses.
|
|
14
15
|
const YEARS: [i32; 5] = [999, 1060, 1937, 1945, 1989];
|
|
15
16
|
|
|
17
|
+
/// The three current-date outputs follow the last historical year. Newer programs move API
|
|
18
|
+
/// names into captured decoder cells, so reference alignment alone can mispair these fields.
|
|
19
|
+
pub(crate) fn names(
|
|
20
|
+
features: &[String],
|
|
21
|
+
writes: &[String],
|
|
22
|
+
) -> Option<BTreeMap<String, &'static str>> {
|
|
23
|
+
let year = features.iter().position(|text| text == "1989")?;
|
|
24
|
+
let [today, offset, method, zone] = features.get(year + 1..year + 5)? else {
|
|
25
|
+
return None;
|
|
26
|
+
};
|
|
27
|
+
if method != "getTimezoneOffset"
|
|
28
|
+
|| ![today, offset, zone]
|
|
29
|
+
.iter()
|
|
30
|
+
.all(|field| writes.contains(field))
|
|
31
|
+
{
|
|
32
|
+
return None;
|
|
33
|
+
}
|
|
34
|
+
Some(BTreeMap::from([
|
|
35
|
+
(today.clone(), reference::DATES_TODAY),
|
|
36
|
+
(offset.clone(), reference::DATES_OFFSET),
|
|
37
|
+
(zone.clone(), reference::DATES_ZONE),
|
|
38
|
+
]))
|
|
39
|
+
}
|
|
40
|
+
|
|
16
41
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
17
42
|
pub struct Fields {
|
|
18
43
|
/// The field reporting each historical year's parsing difference, in program order.
|
|
@@ -105,6 +130,25 @@ mod tests {
|
|
|
105
130
|
use super::*;
|
|
106
131
|
use crate::js::{self, JsValue};
|
|
107
132
|
|
|
133
|
+
#[test]
|
|
134
|
+
fn pins_date_outputs_after_the_historical_years() {
|
|
135
|
+
let features = [
|
|
136
|
+
"last_year",
|
|
137
|
+
"1989",
|
|
138
|
+
"today",
|
|
139
|
+
"offset",
|
|
140
|
+
"getTimezoneOffset",
|
|
141
|
+
"zone",
|
|
142
|
+
]
|
|
143
|
+
.map(str::to_owned);
|
|
144
|
+
let writes = ["last_year", "today", "offset", "zone"].map(str::to_owned);
|
|
145
|
+
let names = names(&features, &writes).unwrap();
|
|
146
|
+
assert_eq!(names["today"], reference::DATES_TODAY);
|
|
147
|
+
assert_eq!(names["offset"], reference::DATES_OFFSET);
|
|
148
|
+
assert_eq!(names["zone"], reference::DATES_ZONE);
|
|
149
|
+
assert!(super::names(&features, &writes[..3]).is_none());
|
|
150
|
+
}
|
|
151
|
+
|
|
108
152
|
fn fields() -> Fields {
|
|
109
153
|
js::from_value(json!({"years": {"legacy": 999, "old": 1060, "winter": 1989}})).unwrap()
|
|
110
154
|
}
|