diff --git a/crates/untwist-deobfuscate/src/branch_reach.rs b/crates/untwist-deobfuscate/src/branch_reach.rs new file mode 100644 index 00000000..4de4f57d --- /dev/null +++ b/crates/untwist-deobfuscate/src/branch_reach.rs @@ -0,0 +1,133 @@ +use oxc_ast::ast::*; +use oxc_ast_visit::{walk_js, VisitJs}; +use oxc_semantic::Scoping; +use oxc_span::Span; +use oxc_syntax::scope::ScopeFlags; +use oxc_syntax::symbol::SymbolId; +use rustc_hash::FxHashSet; + +struct InBranch<'e> { + scoping: &'e Scoping, + escapes: &'e FxHashSet, + dormant: &'e FxHashSet, + depth: usize, + found: FxHashSet, + read_outside: FxHashSet, + declared: FxHashSet, +} + +impl InBranch<'_> { + fn note(&mut self, span: Span) { + if self.depth > 0 && self.escapes.contains(&span) { + self.found.insert(span); + } + } + + fn branch(&mut self, visit: impl FnOnce(&mut Self) -> T) -> T { + self.depth += 1; + let out = visit(self); + self.depth -= 1; + out + } +} + +fn declared_symbol(function: &Function<'_>) -> Option { + match function.is_declaration() { + true => function.id.as_ref()?.symbol_id.get(), + false => None, + } +} + +impl<'a> VisitJs<'a> for InBranch<'_> { + fn visit_function(&mut self, it: &Function<'a>, flags: ScopeFlags) { + let symbol = declared_symbol(it); + if let Some(symbol) = symbol { + self.declared.insert(symbol); + } + match symbol.is_some_and(|symbol| self.dormant.contains(&symbol)) { + true => self.branch(|scan| walk_js::walk_function(scan, it, flags)), + false => walk_js::walk_function(self, it, flags), + } + } + + fn visit_if_statement(&mut self, it: &IfStatement<'a>) { + self.visit_expression(&it.test); + self.branch(|scan| scan.visit_statement(&it.consequent)); + if let Some(alternate) = &it.alternate { + self.branch(|scan| scan.visit_statement(alternate)); + } + } + + fn visit_conditional_expression(&mut self, it: &ConditionalExpression<'a>) { + self.visit_expression(&it.test); + self.branch(|scan| scan.visit_expression(&it.consequent)); + self.branch(|scan| scan.visit_expression(&it.alternate)); + } + + fn visit_logical_expression(&mut self, it: &LogicalExpression<'a>) { + self.visit_expression(&it.left); + self.branch(|scan| scan.visit_expression(&it.right)); + } + + fn visit_switch_case(&mut self, it: &SwitchCase<'a>) { + if let Some(test) = &it.test { + self.visit_expression(test); + } + self.branch(|scan| scan.visit_statements(&it.consequent)); + } + + fn visit_call_expression(&mut self, it: &CallExpression<'a>) { + self.note(it.span); + walk_js::walk_call_expression(self, it); + } + + fn visit_identifier_reference(&mut self, it: &IdentifierReference<'a>) { + self.note(it.span); + if self.depth > 0 { + return; + } + let Some(reference) = it.reference_id.get() else { + return; + }; + let reference = self.scoping.get_reference(reference); + if let Some(symbol) = reference.symbol_id().filter(|_| reference.is_read()) { + self.read_outside.insert(symbol); + } + } +} + +fn scan<'e>( + (program, scoping): (&Program<'_>, &'e Scoping), + escapes: &'e FxHashSet, + dormant: &'e FxHashSet, +) -> InBranch<'e> { + let mut scan = InBranch { + scoping, + escapes, + dormant, + depth: 0, + found: FxHashSet::default(), + read_outside: FxHashSet::default(), + declared: FxHashSet::default(), + }; + scan.visit_program(program); + scan +} + +pub fn in_branches( + program: &Program<'_>, + scoping: &Scoping, + escapes: &FxHashSet, +) -> FxHashSet { + let none = FxHashSet::default(); + let first = scan((program, scoping), escapes, &none); + let dormant: FxHashSet = first + .declared + .difference(&first.read_outside) + .copied() + .collect(); + if dormant.is_empty() { + return first.found; + } + scan((program, scoping), escapes, &dormant).found +} diff --git a/crates/untwist-deobfuscate/src/bridge.rs b/crates/untwist-deobfuscate/src/bridge.rs index 5f872d94..62b90c17 100644 --- a/crates/untwist-deobfuscate/src/bridge.rs +++ b/crates/untwist-deobfuscate/src/bridge.rs @@ -7,6 +7,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use untwist_eval::decode::{decoded_to_expression, Call, Decoded, DecoderProgram, FnRef}; use crate::array_rotator::find_rotators; +use crate::branch_reach::in_branches; use crate::calls::{collect_base, Collected}; use crate::dead_guards::{enclosing_guards, BranchGuard, EscapeGuards}; use crate::notes; @@ -114,9 +115,10 @@ fn escaped_decoders_by_unit( } fn guarded_escapes( - program: &Program<'_>, + (program, scoping): (&Program<'_>, &Scoping), collected: &mut Collected<'_>, (sites, rotators): (&Sites, &FxHashMap), + decoder_spans: impl Fn(usize) -> Vec, ) -> FxHashMap { let in_own_rotator = |(index, span): &(usize, Span)| { sites @@ -136,7 +138,12 @@ fn guarded_escapes( return by_unit; } let enclosing = enclosing_guards(program, &escapes); + let branched = match crate::legacy_reach::speculates_escapes() { + true => in_branches(program, scoping, &escapes), + false => FxHashSet::default(), + }; let mut unguarded: FxHashSet = FxHashSet::default(); + let mut speculated: FxHashSet = FxHashSet::default(); let mut found: Vec<(usize, bool, Vec)> = Vec::new(); let values = collected.decoder_values.iter().map(|escape| (escape, true)); let dynamic = collected.dynamic_calls.iter().map(|escape| (escape, false)); @@ -146,6 +153,9 @@ fn guarded_escapes( }; match enclosing.get(span).filter(|guards| !guards.is_empty()) { Some(guards) => found.push((unit, is_value, guards.clone())), + None if branched.contains(span) => { + speculated.insert(unit); + } None => { unguarded.insert(unit); } @@ -162,6 +172,11 @@ fn guarded_escapes( collected .dynamic_calls .retain(|(index, _)| !is_guarded(index)); + for unit in speculated { + if !unguarded.contains(&unit) { + by_unit.entry(unit).or_default().speculative = decoder_spans(unit); + } + } for (unit, is_value, guards) in found { if unguarded.contains(&unit) { continue; @@ -573,7 +588,21 @@ pub fn build_requests_in_lane<'p>( .zip(&rotators) .filter_map(|((unit, _, _), located)| Some((*unit, located.as_ref()?.0))) .collect(); - guarded_escapes(program, &mut collected, (&sites, &rotator_spans)) + let decoder_spans = |unit: usize| -> Vec { + members + .get(&unit) + .into_iter() + .flatten() + .filter_map(|position| stamped.decoders.get(*position)?.symbol) + .map(|symbol| scoping.symbol_span(symbol)) + .collect() + }; + guarded_escapes( + (program, scoping), + &mut collected, + (&sites, &rotator_spans), + decoder_spans, + ) } else { FxHashMap::default() }; diff --git a/crates/untwist-deobfuscate/src/calls/agnostic/holds.rs b/crates/untwist-deobfuscate/src/calls/agnostic/holds.rs index e55ddaf0..c12302a6 100644 --- a/crates/untwist-deobfuscate/src/calls/agnostic/holds.rs +++ b/crates/untwist-deobfuscate/src/calls/agnostic/holds.rs @@ -76,7 +76,13 @@ fn prototype_base(member: &MemberExpression<'_>) -> bool { } fn literal_key(property: &ObjectProperty<'_>) -> bool { - !property.computed || matches!(property.key, PropertyKey::StringLiteral(_)) + !property.computed + || matches!( + property.key, + PropertyKey::StringLiteral(_) + | PropertyKey::NumericLiteral(_) + | PropertyKey::Identifier(_) + ) } impl<'a> Sites<'_, 'a> { @@ -137,6 +143,7 @@ impl<'a> Sites<'_, 'a> { None => self.binding_hold(inner, id, next, false), }, Expression::CallExpression(call) => self.call_hold(call, next), + Expression::NewExpression(new) if self.fresh_instance(new, next) => Hold::Stored, _ if self.string_valued(inner) => Hold::No, _ => Hold::Yes, } @@ -151,6 +158,15 @@ impl<'a> Sites<'_, 'a> { self.watched_element(expr) || self.str_value(expr, super::roles::KEY_DEPTH).is_some() } + fn fresh_instance(&self, new: &NewExpression<'a>, depth: u8) -> bool { + self.fresh_construction(new) + && new.arguments.iter().all(|argument| { + argument + .as_expression() + .is_some_and(|expr| self.hold_at(expr, depth) == Hold::No) + }) + } + fn call_hold(&self, call: &CallExpression<'a>, depth: u8) -> Hold { if self.resolve.is_some_and(|map| map.contains_key(&call.span)) { return Hold::No; diff --git a/crates/untwist-deobfuscate/src/calls/agnostic/mod.rs b/crates/untwist-deobfuscate/src/calls/agnostic/mod.rs index 226214f7..5a2bfdb2 100644 --- a/crates/untwist-deobfuscate/src/calls/agnostic/mod.rs +++ b/crates/untwist-deobfuscate/src/calls/agnostic/mod.rs @@ -208,6 +208,19 @@ pub fn global_reach<'a>( reach_of(&found) } +pub fn global_observation<'a>( + program: &'a Program<'a>, + scoping: &Scoping, + machinery: &[Span], + reach: ReachWatch<'_>, +) -> Option { + let watch = settle::Watch { + printers_quiet: true, + ..reach_watch(reach) + }; + reach_of(&settle(program, scoping, (None, machinery, watch)).0).observed +} + pub fn global_reach_with_texts<'a>( program: &'a Program<'a>, scoping: &Scoping, diff --git a/crates/untwist-deobfuscate/src/calls/agnostic/observe.rs b/crates/untwist-deobfuscate/src/calls/agnostic/observe.rs index c728859a..6fabc953 100644 --- a/crates/untwist-deobfuscate/src/calls/agnostic/observe.rs +++ b/crates/untwist-deobfuscate/src/calls/agnostic/observe.rs @@ -98,7 +98,7 @@ impl<'a> Sites<'_, 'a> { } } - fn name_assigned(&self, name: &str) -> bool { + pub(super) fn name_assigned(&self, name: &str) -> bool { if is_foreign_global(name) { return true; } diff --git a/crates/untwist-deobfuscate/src/calls/agnostic/reach.rs b/crates/untwist-deobfuscate/src/calls/agnostic/reach.rs index f3cb3b49..8777454a 100644 --- a/crates/untwist-deobfuscate/src/calls/agnostic/reach.rs +++ b/crates/untwist-deobfuscate/src/calls/agnostic/reach.rs @@ -12,6 +12,22 @@ use oxc_syntax::operator::BinaryOperator; use untwist_core::semantic::{observers, Observers}; use untwist_eval::coerce::number_to_string; +const FRESH_CONSTRUCTORS: [&str; 13] = [ + "Error", + "EvalError", + "RangeError", + "ReferenceError", + "SyntaxError", + "TypeError", + "URIError", + "Date", + "RegExp", + "Map", + "Set", + "WeakMap", + "WeakSet", +]; + #[derive(Default)] struct ReturnExprs<'a> { exprs: Vec<&'a Expression<'a>>, @@ -166,6 +182,16 @@ impl<'a> Sites<'_, 'a> { && self.fresh.bindings.is_array_function(symbol)) } + pub(super) fn fresh_construction(&self, new: &NewExpression<'a>) -> bool { + let Expression::Identifier(callee) = new.callee.without_parentheses() else { + return false; + }; + let name = callee.name.as_str(); + FRESH_CONSTRUCTORS.contains(&name) + && self.fresh.symbol(callee).is_none() + && !self.name_assigned(name) + } + fn ambient_creation(&self, expr: &Expression<'a>) -> bool { if !self.extended.get() { return false; @@ -240,6 +266,7 @@ impl<'a> Sites<'_, 'a> { self.identifier_non_global(id, depth) } Expression::CallExpression(call) => self.call_non_global(call, depth), + Expression::NewExpression(new) => self.fresh_construction(new), Expression::StaticMemberExpression(member) => { member.property.name == "length" && self.fresh.holds_fresh_sequence(&member.object) } @@ -306,11 +333,9 @@ impl<'a> Sites<'_, 'a> { if name_key { return true; } - if self - .fresh - .literal_init(id) - .is_some_and(|init| self.is_array_result(init) || self.ambient_creation(init)) - { + if self.fresh.literal_init(id).is_some_and(|init| { + self.fresh.is_fresh(init) || self.is_array_result(init) || self.ambient_creation(init) + }) { return true; } let Some((symbol, func, index)) = self.resolvable_param(id) else { diff --git a/crates/untwist-deobfuscate/src/dead_guards.rs b/crates/untwist-deobfuscate/src/dead_guards.rs index de9ad036..4ae16db8 100644 --- a/crates/untwist-deobfuscate/src/dead_guards.rs +++ b/crates/untwist-deobfuscate/src/dead_guards.rs @@ -57,6 +57,7 @@ fn comparison(test: &Expression<'_>) -> Option { pub struct EscapeGuards { pub values: Vec>, pub dynamic: Vec>, + pub speculative: Vec, } struct Enclosing<'e> { diff --git a/crates/untwist-deobfuscate/src/decoded.rs b/crates/untwist-deobfuscate/src/decoded.rs index 41037b76..257ba2db 100644 --- a/crates/untwist-deobfuscate/src/decoded.rs +++ b/crates/untwist-deobfuscate/src/decoded.rs @@ -250,6 +250,9 @@ fn apply_decoded_values<'a>( if returned != request.calls.len() { decoded.partial.push((returned, request.calls.len())); } + if evaluated > 0 { + crate::legacy_reach::defer_escapes(&request.escape_guards.speculative); + } inlined && returned == request.calls.len() && evaluated == returned } diff --git a/crates/untwist-deobfuscate/src/decoded/layered.rs b/crates/untwist-deobfuscate/src/decoded/layered.rs index 3103e90c..dbc2ba85 100644 --- a/crates/untwist-deobfuscate/src/decoded/layered.rs +++ b/crates/untwist-deobfuscate/src/decoded/layered.rs @@ -12,7 +12,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use super::conflict::prototype_conflict; use super::values::reaches_intrinsics; use crate::bridge::DecodeRequest; -use crate::calls::agnostic::{global_reach, guard_writes, ReachWatch}; +use crate::calls::agnostic::{global_observation, global_reach, guard_writes, ReachWatch}; use crate::legacy_reach::{self, Layered}; use crate::proof::{alias_refusal, alias_sites, builtin_aliases, points_to_sites, UsedNames}; use crate::root_reach::root_alias_names; @@ -21,7 +21,7 @@ use untwist_eval::object::{ProtoRead, PROTOTYPE_LINKS}; const TOKEN_PREFIX: &str = "layered:"; -const MIN_LATENT_ENTRIES: usize = 2; +const MIN_LATENT_ENTRIES: usize = 1; #[derive(Default)] struct Frame { @@ -352,8 +352,6 @@ pub fn settle_observations(program: &Program<'_>, scoping: &Scoping) { fns: &[], observe: true, }; - global_reach(program, scoping, (None, machinery), watch) - .observed - .is_some() + global_observation(program, scoping, machinery, watch).is_some() }); } diff --git a/crates/untwist-deobfuscate/src/driver.rs b/crates/untwist-deobfuscate/src/driver.rs index a9d43bb1..6317ada8 100644 --- a/crates/untwist-deobfuscate/src/driver.rs +++ b/crates/untwist-deobfuscate/src/driver.rs @@ -942,6 +942,8 @@ fn deobfuscate_with<'a>( memo: &Rc>, ) -> (Semantics, RunReport) { let _deferral = crate::legacy_reach::open_stage(!opts.unsafe_transforms && !opts.nested_root); + let _escapes = + crate::legacy_reach::open_escape_stage(opts.unsafe_transforms && !opts.nested_root); let mut aggregate = Aggregate::new(); let sem = prepare(alloc, program, prepared, opts, &mut aggregate); if input_spells_the_stamp(program, &sem, opts) { @@ -972,6 +974,11 @@ fn deobfuscate_with<'a>( if opts.round_cap_undo.get() == RoundCapUndo::Requested { return (sem, aggregate.finish()); } + crate::legacy_reach::settle_escapes(|decoders| { + sem.scoping + .symbol_ids() + .any(|symbol| decoders.contains(&sem.scoping.symbol_span(symbol))) + }); let sem = finalize_unresolved_machinery(alloc, program, sem, (opts, &shared), &mut aggregate); let sem = match &before { Some(before) => kept_when_stamps_survive(alloc, program, (sem, before), &mut aggregate), diff --git a/crates/untwist-deobfuscate/src/legacy_reach.rs b/crates/untwist-deobfuscate/src/legacy_reach.rs index c0f64e40..072fa6d6 100644 --- a/crates/untwist-deobfuscate/src/legacy_reach.rs +++ b/crates/untwist-deobfuscate/src/legacy_reach.rs @@ -1,5 +1,7 @@ use std::cell::RefCell; +use oxc_span::Span; + use crate::mutants::deferred_legacy_reach_trusted; #[derive(Clone, Debug, Default)] @@ -21,6 +23,9 @@ struct Deferral { layered: Vec<(String, Layered)>, observations: Vec>, unverified: bool, + escapes_open: bool, + escapes: Vec, + reached: bool, } thread_local! { @@ -57,6 +62,48 @@ impl Drop for Stage { } } +pub(crate) struct EscapeStage { + open: bool, + escapes: Vec, +} + +pub(crate) fn open_escape_stage(on: bool) -> EscapeStage { + DEFERRAL.with(|deferral| { + let mut deferral = deferral.borrow_mut(); + let open = on && deferral.rerunnable && !deferral.forbidden; + EscapeStage { + open: std::mem::replace(&mut deferral.escapes_open, open), + escapes: std::mem::take(&mut deferral.escapes), + } + }) +} + +impl Drop for EscapeStage { + fn drop(&mut self) { + DEFERRAL.with(|deferral| { + let mut deferral = deferral.borrow_mut(); + deferral.unverified |= !deferral.escapes.is_empty(); + deferral.escapes_open = self.open; + deferral.escapes = std::mem::take(&mut self.escapes); + }); + } +} + +pub(crate) fn speculates_escapes() -> bool { + DEFERRAL.with(|deferral| deferral.borrow().escapes_open) +} + +pub(crate) fn defer_escapes(decoders: &[Span]) { + DEFERRAL.with(|deferral| deferral.borrow_mut().escapes.extend_from_slice(decoders)); +} + +pub(crate) fn settle_escapes(survives: impl FnOnce(&[Span]) -> bool) { + let escapes = DEFERRAL.with(|deferral| std::mem::take(&mut deferral.borrow_mut().escapes)); + if !escapes.is_empty() && survives(&escapes) { + DEFERRAL.with(|deferral| deferral.borrow_mut().unverified = true); + } +} + pub(crate) fn defers() -> bool { DEFERRAL.with(|deferral| deferral.borrow().open) } @@ -198,7 +245,11 @@ pub fn settle_observations(mut observed: impl FnMut(&[&str]) -> bool) { observed(&names) }); if failed { - DEFERRAL.with(|deferral| deferral.borrow_mut().unverified = true); + DEFERRAL.with(|deferral| { + let mut deferral = deferral.borrow_mut(); + deferral.unverified = true; + deferral.reached = true; + }); } } @@ -207,6 +258,8 @@ pub(crate) fn settle_layered(mut holds: impl FnMut(&Layered) -> bool) { for (token, obligation) in layered { if holds(&obligation) { verify_one(&token); + } else { + DEFERRAL.with(|deferral| deferral.borrow_mut().reached = true); } } } @@ -236,13 +289,19 @@ pub fn unverified() -> bool { }) } +pub fn reach_failed() -> bool { + DEFERRAL.with(|deferral| deferral.borrow().reached) +} + pub(crate) fn forget() { DEFERRAL.with(|deferral| { let mut deferral = deferral.borrow_mut(); deferral.unverified = false; + deferral.reached = false; deferral.pending.clear(); deferral.layered.clear(); deferral.observations.clear(); + deferral.escapes.clear(); }); } diff --git a/crates/untwist-deobfuscate/src/lib.rs b/crates/untwist-deobfuscate/src/lib.rs index 7d1b52b0..0469eaaf 100644 --- a/crates/untwist-deobfuscate/src/lib.rs +++ b/crates/untwist-deobfuscate/src/lib.rs @@ -1,6 +1,7 @@ mod alias_forms; pub mod array_rotator; pub mod bindings; +mod branch_reach; pub mod bridge; mod builtin_values; pub mod call_checks; @@ -57,6 +58,7 @@ mod wrapper_consts; mod wrapper_effects; mod wrapper_immediate; mod wrapper_sites; +mod wrapper_speculation; pub mod wrappers; mod write_only; diff --git a/crates/untwist-deobfuscate/src/proof/escape.rs b/crates/untwist-deobfuscate/src/proof/escape.rs index 340aa39f..1df3220a 100644 --- a/crates/untwist-deobfuscate/src/proof/escape.rs +++ b/crates/untwist-deobfuscate/src/proof/escape.rs @@ -4,6 +4,8 @@ use oxc_semantic::{Scoping, SymbolId}; use oxc_span::{GetSpan, Span}; use oxc_syntax::scope::ScopeFlags; use rustc_hash::{FxHashMap, FxHashSet}; +use std::cell::RefCell; +use std::rc::Rc; use untwist_core::semantic::build_scoping; use untwist_eval::object::PROTOTYPE_LINKS; @@ -67,7 +69,17 @@ fn is_function_literal(expr: &Expression<'_>) -> bool { ) } +type StrictKey = (Span, u32, Vec, u32); + +#[derive(Clone)] +struct StrictScan { + pending: Vec, + matched: FxHashSet<&'static str>, + found: Option, +} + struct Escape<'s> { + strict_scans: Rc>>, scoping: &'s Scoping, globals: &'s FxHashSet<&'static str>, found: Option, @@ -80,6 +92,7 @@ struct Escape<'s> { context: &'s EscapeContext, pending_exempt: Option<&'s FxHashSet>, pending: Vec, + pending_seen: FxHashSet, defer_object_operand: bool, object_operand: Option, written: Vec, @@ -255,10 +268,11 @@ impl<'s> Escape<'s> { let key_span = key_call.span; let forcing = self.pending_call_span(&member.expression).is_some(); let object_symbol = self.symbol_of(&member.object); - let mut strict = self.child_scan(); - strict.visit_arguments(args, false); - self.pending.extend(strict.pending); - self.pending.push(PendingSite::ProxyKey { + let strict = self.strict_scan(call_span, args); + for site in strict.pending { + self.add_pending(site); + } + self.add_pending(PendingSite::ProxyKey { call_span, key_span, object_symbol, @@ -268,8 +282,36 @@ impl<'s> Escape<'s> { }); } + fn add_pending(&mut self, site: PendingSite) { + if self.pending_seen.insert(format!("{site:?}")) { + self.pending.push(site); + } + } + + fn strict_scan(&self, call_span: Span, args: &[Argument<'_>]) -> StrictScan { + let key = ( + call_span, + self.depth, + self.this_stack.clone(), + self.class_depth, + ); + if let Some(known) = self.strict_scans.borrow().get(&key) { + return known.clone(); + } + let mut strict = self.child_scan(); + strict.visit_arguments(args, false); + let scanned = StrictScan { + pending: strict.pending, + matched: strict.matched, + found: strict.found, + }; + self.strict_scans.borrow_mut().insert(key, scanned.clone()); + scanned + } + fn child_scan(&self) -> Escape<'s> { let mut child = Escape::new(self.scoping, self.globals, self.context, self.resolve); + child.strict_scans = Rc::clone(&self.strict_scans); child.depth = self.depth; child.this_stack = self.this_stack.clone(); child.class_depth = self.class_depth; @@ -284,6 +326,7 @@ impl<'s> Escape<'s> { resolve: Option<&'s dyn Fn(Span) -> Option>, ) -> Self { Escape { + strict_scans: Rc::default(), scoping, globals, found: None, @@ -296,6 +339,7 @@ impl<'s> Escape<'s> { context, pending_exempt: None, pending: Vec::new(), + pending_seen: FxHashSet::default(), defer_object_operand: false, object_operand: None, written: Vec::new(), @@ -379,7 +423,7 @@ impl<'s> Escape<'s> { return false; } let forcing = self.template_forcing(&member.expression); - self.pending.push(PendingSite::GlobalKey { + self.add_pending(PendingSite::GlobalKey { outer_span: member.span, key, forcing, @@ -410,7 +454,7 @@ impl<'s> Escape<'s> { return false; } let forcing = self.template_forcing(&member.expression); - self.pending.push(PendingSite::RootKey { + self.add_pending(PendingSite::RootKey { outer_span: member.span, root, key, @@ -608,7 +652,7 @@ impl<'s> Escape<'s> { if self.pending_exempt.is_some() { if let Some(text) = self.pending_template(first) { let forcing = self.template_forcing(first); - self.pending.push(PendingSite::Sink { + self.add_pending(PendingSite::Sink { outer_span: span, text, forcing, diff --git a/crates/untwist-deobfuscate/src/proof/storage.rs b/crates/untwist-deobfuscate/src/proof/storage.rs index e746abcb..6493a5cb 100644 --- a/crates/untwist-deobfuscate/src/proof/storage.rs +++ b/crates/untwist-deobfuscate/src/proof/storage.rs @@ -9,6 +9,8 @@ use untwist_core::ast_util::js_text::js_text; use super::written::{text_template, WrittenKey}; use crate::value_flow::{flow_rule_disabled, STORAGE_PROXY}; +const TEMPLATE_WEIGHT_CAP: usize = 4096; + #[derive(Clone, Debug)] pub(super) enum StorageMember { Text(WrittenKey), @@ -299,6 +301,13 @@ impl Storage<'_> { }; let left = text_template(left.as_expression()?, Some(self))?; let right = text_template(right.as_expression()?, Some(self))?; + let joins = members + .values() + .filter(|value| matches!(value, StorageMember::Concat)) + .count(); + if (left.weight() + right.weight()).saturating_mul(joins) > TEMPLATE_WEIGHT_CAP { + return None; + } Self::choose(member, members, |value| match value { StorageMember::Concat => Some(WrittenKey::Concat(vec![left.clone(), right.clone()])), StorageMember::Text(_) | StorageMember::Other => None, diff --git a/crates/untwist-deobfuscate/src/proof/written.rs b/crates/untwist-deobfuscate/src/proof/written.rs index 3ce31826..e880b0a0 100644 --- a/crates/untwist-deobfuscate/src/proof/written.rs +++ b/crates/untwist-deobfuscate/src/proof/written.rs @@ -19,6 +19,19 @@ pub enum WrittenKey { } impl WrittenKey { + pub fn weight(&self) -> usize { + match self { + WrittenKey::Name(_) | WrittenKey::Pending(_) => 1, + WrittenKey::Concat(parts) => 1 + parts.iter().map(WrittenKey::weight).sum::(), + WrittenKey::Choice { options, .. } => { + 1 + options + .iter() + .map(|(_, option)| option.weight()) + .sum::() + } + } + } + pub fn resolved(&self, resolve: &dyn Fn(Span) -> Option) -> Option { match self { WrittenKey::Name(name) => Some(name.clone()), diff --git a/crates/untwist-deobfuscate/src/string_array/mod.rs b/crates/untwist-deobfuscate/src/string_array/mod.rs index cc5284ec..64dc99c1 100644 --- a/crates/untwist-deobfuscate/src/string_array/mod.rs +++ b/crates/untwist-deobfuscate/src/string_array/mod.rs @@ -111,6 +111,13 @@ fn first_initialised<'k, 'a>(statements: &'k [Statement<'a>]) -> Option<&'k Stat .find(|statement| !is_uninitialised(statement)) } +fn unbraced<'k, 'a>(mut statements: &'k [Statement<'a>]) -> &'k [Statement<'a>] { + while let [Statement::BlockStatement(block)] = statements { + statements = &block.body; + } + statements +} + fn returns_array(expr: &Expression<'_>, array: &str) -> bool { let Expression::FunctionExpression(function) = expr else { return false; @@ -121,7 +128,7 @@ fn returns_array(expr: &Expression<'_>, array: &str) -> bool { let Some(body) = function.body.as_ref() else { return false; }; - let Some(statements) = without_inert(&body.statements, &[array]) else { + let Some(statements) = without_inert(unbraced(&body.statements), &[array]) else { return false; }; let [Statement::ReturnStatement(statement)] = statements.as_slice() else { diff --git a/crates/untwist-deobfuscate/src/wrapper_calls.rs b/crates/untwist-deobfuscate/src/wrapper_calls.rs index 3b90e5f7..bb1945ab 100644 --- a/crates/untwist-deobfuscate/src/wrapper_calls.rs +++ b/crates/untwist-deobfuscate/src/wrapper_calls.rs @@ -32,6 +32,7 @@ use crate::wrapper_args::{kinds_fit, SiteView}; use crate::wrapper_chain::{drop_broken_chains, promote_forwarders, Candidate, Chain, Fits}; use crate::wrapper_effects::{inline_keeping_effects, inline_local_writes}; use crate::wrapper_sites::{called_expression, collect_sites, CallSite, FunctionsAt, Sites}; +use crate::wrapper_speculation; pub const WRAPPER_ROUND_CAP: usize = 16; @@ -249,9 +250,11 @@ struct WrapperSearch<'p, 's> { scoping: &'s Scoping, units: MachineryDepth, checked: bool, + speculating: bool, found: Vec, forwarders: Vec>, rejected: Vec<(Span, &'static str)>, + unstable: Vec, } impl<'p> WrapperSearch<'p, '_> { @@ -274,6 +277,13 @@ impl<'p> WrapperSearch<'p, '_> { if !binding_is_stable(self.scoping, shape.symbol) { return Some(notes::WRAPPER_BINDING_UNSTABLE); } + self.refusal_of_body(function) + } + + fn refusal_of_body(&self, function: &Function<'_>) -> Option<&'static str> { + if returns_nested_function(function) { + return Some(notes::WRAPPER_NESTED_FUNCTION); + } if !body_is_self_contained(function, self.scoping, None) { return Some(notes::WRAPPER_BODY_NOT_SELF_CONTAINED); } @@ -293,6 +303,12 @@ impl<'p> WrapperSearch<'p, '_> { return; } match self.refusal(&shape, function) { + Some(notes::WRAPPER_BINDING_UNSTABLE) if self.speculating => { + match self.refusal_of_body(function) { + Some(reason) => self.rejected.push((shape.statement, reason)), + None => self.unstable.push(shape), + } + } Some(reason) => self.rejected.push((shape.statement, reason)), None => self.found.push(shape), } @@ -616,17 +632,22 @@ fn find_wrappers( scoping: cx.scoping(), units: MachineryDepth::every_unit(), checked, + speculating: cx.opts.unsafe_transforms && crate::legacy_reach::speculates_escapes(), found: Vec::new(), forwarders: Vec::new(), rejected: Vec::new(), + unstable: Vec::new(), }; search.visit_program(program); let WrapperSearch { mut found, forwarders, mut rejected, + unstable, .. } = search; + let admitted = + wrapper_speculation::admit(program, cx.scoping(), unstable, (&mut found, &mut rejected)); if found.is_empty() && rejected.is_empty() { return None; } @@ -639,6 +660,7 @@ fn find_wrappers( refuse_annex_b_bindings(&mut found, site, program, cx); drop_broken_chains(&mut found); } + wrapper_speculation::defer(cx.scoping(), &found, &admitted); Some((found, rejected)) } diff --git a/crates/untwist-deobfuscate/src/wrapper_speculation.rs b/crates/untwist-deobfuscate/src/wrapper_speculation.rs new file mode 100644 index 00000000..8e56b308 --- /dev/null +++ b/crates/untwist-deobfuscate/src/wrapper_speculation.rs @@ -0,0 +1,92 @@ +use oxc_ast::ast::*; +use oxc_ast_visit::VisitJs; +use oxc_semantic::Scoping; +use oxc_span::Span; +use oxc_syntax::symbol::SymbolId; +use rustc_hash::FxHashSet; + +use crate::branch_reach::in_branches; +use crate::notes; +use crate::wrapper_calls::WrapperShape; + +struct Writes<'s> { + scoping: &'s Scoping, + symbols: &'s FxHashSet, + found: Vec<(SymbolId, Span)>, +} + +impl<'a> VisitJs<'a> for Writes<'_> { + fn visit_identifier_reference(&mut self, it: &IdentifierReference<'a>) { + let Some(reference) = it.reference_id.get() else { + return; + }; + let reference = self.scoping.get_reference(reference); + if let Some(symbol) = reference.symbol_id() { + if reference.is_write() && self.symbols.contains(&symbol) { + self.found.push((symbol, it.span)); + } + } + } +} + +fn declared_by_function(scoping: &Scoping, symbol: SymbolId) -> bool { + scoping.symbol_flags(symbol).is_function() + && scoping + .scope_flags(scoping.symbol_scope_id(symbol)) + .is_var() +} + +fn branched_writes_only( + program: &Program<'_>, + scoping: &Scoping, + candidates: &FxHashSet, +) -> FxHashSet { + let mut writes = Writes { + scoping, + symbols: candidates, + found: Vec::new(), + }; + writes.visit_program(program); + let spans: FxHashSet = writes.found.iter().map(|(_, span)| *span).collect(); + let branched = in_branches(program, scoping, &spans); + let mut held: FxHashSet = writes.found.iter().map(|(symbol, _)| *symbol).collect(); + for (symbol, span) in &writes.found { + if !branched.contains(span) { + held.remove(symbol); + } + } + held +} + +pub(crate) fn admit( + program: &Program<'_>, + scoping: &Scoping, + unstable: Vec, + (found, rejected): (&mut Vec, &mut Vec<(Span, &'static str)>), +) -> FxHashSet { + let candidates: FxHashSet = unstable + .iter() + .map(|shape| shape.symbol) + .filter(|symbol| declared_by_function(scoping, *symbol)) + .collect(); + let admitted = match candidates.is_empty() { + true => FxHashSet::default(), + false => branched_writes_only(program, scoping, &candidates), + }; + for shape in unstable { + match admitted.contains(&shape.symbol) { + true => found.push(shape), + false => rejected.push((shape.statement, notes::WRAPPER_BINDING_UNSTABLE)), + } + } + admitted +} + +pub(crate) fn defer(scoping: &Scoping, found: &[WrapperShape], admitted: &FxHashSet) { + let spans: Vec = found + .iter() + .filter(|shape| admitted.contains(&shape.symbol)) + .map(|shape| scoping.symbol_span(shape.symbol)) + .collect(); + crate::legacy_reach::defer_escapes(&spans); +} diff --git a/crates/untwist/src/pipeline/notes.rs b/crates/untwist/src/pipeline/notes.rs index d79c0926..572f7767 100644 --- a/crates/untwist/src/pipeline/notes.rs +++ b/crates/untwist/src/pipeline/notes.rs @@ -262,14 +262,23 @@ pub(super) fn consolidate_reach(mut notes: Vec) -> Vec { } pub(super) fn reach_refusals(notes: &[Note]) -> Vec { - notes + let carried: Vec = notes .iter() .filter(|note| note.message == notes::STRING_ARRAY_GLOBAL_REACH) .map(|note| Note { kind: NoteKind::Refusal, ..note.clone() }) - .collect() + .collect(); + if !carried.is_empty() || !untwist_deobfuscate::legacy_reach::reach_failed() { + return carried; + } + vec![Note { + pass: "inline-decoded-strings", + kind: NoteKind::Refusal, + message: notes::STRING_ARRAY_GLOBAL_REACH.to_string(), + span: None, + }] } pub(super) fn carry_reach(notes: Vec, earlier: Vec) -> Vec { diff --git a/crates/untwist/tests/data/obfuscator_sweep/branch-escape-live.js b/crates/untwist/tests/data/obfuscator_sweep/branch-escape-live.js new file mode 100644 index 00000000..120d6189 --- /dev/null +++ b/crates/untwist/tests/data/obfuscator_sweep/branch-escape-live.js @@ -0,0 +1,14 @@ +function c() { + var o = ['hello', 'log', 'world']; + c = function () { return o; }; + return c(); +} +function d(a) { + a = a - 0x10; + var e = c(); + return e[a]; +} +if (Date.now() > 0) { + console.log([0x10, 0x12].map(d).join(' ')); +} +console[d(0x11)](d(0x10)); diff --git a/crates/untwist/tests/data/obfuscator_sweep/fresh-instance-printed.js b/crates/untwist/tests/data/obfuscator_sweep/fresh-instance-printed.js new file mode 100644 index 00000000..6ff1e359 --- /dev/null +++ b/crates/untwist/tests/data/obfuscator_sweep/fresh-instance-printed.js @@ -0,0 +1,6 @@ +function _0xa(){const a=["oops","reject","log","node:path"];_0xa=function(){return a};return _0xa()} +function _0xb(i){i=i-0;const t=_0xa();return t[i]} +function _0xc(){const b=_0xb;const a=[b(0),b(1),b(2),b(3)];_0xc=function(){return a};return _0xc()} +function _0xd(i){i=i-0;const t=_0xc();return t[i]} +const path=_0xd(3); +console[_0xd(2)](path, new Map(), new Error(_0xd(0)).message); diff --git a/crates/untwist/tests/data/obfuscator_sweep/one-entry-outer-array.js b/crates/untwist/tests/data/obfuscator_sweep/one-entry-outer-array.js new file mode 100644 index 00000000..8be4c75c --- /dev/null +++ b/crates/untwist/tests/data/obfuscator_sweep/one-entry-outer-array.js @@ -0,0 +1 @@ +function _0x5930(){var _0x2b55ef=['406314RtcrQj','2090880jCfwHe','log','1735551ZXqoUW','45ATcEHH','40FpWnrS','2337ExYMFr','113GEPkxc','3574991MNPudN','21138370kMySLU','4028kBzKRQ','27238wvECnP'];_0x5930=function(){return _0x2b55ef;};return _0x5930();}(function(_0x47cd42,_0x2c80de){var _0x2d2175=_0x37a9,_0x26f7f7=_0x47cd42();while(!![]){try{var _0x106ada=parseInt(_0x2d2175(0x1e0))/0x1*(parseInt(_0x2d2175(0x1e4))/0x2)+parseInt(_0x2d2175(0x1df))/0x3*(-parseInt(_0x2d2175(0x1e3))/0x4)+parseInt(_0x2d2175(0x1dd))/0x5*(parseInt(_0x2d2175(0x1e5))/0x6)+parseInt(_0x2d2175(0x1e1))/0x7+parseInt(_0x2d2175(0x1da))/0x8+parseInt(_0x2d2175(0x1dc))/0x9*(parseInt(_0x2d2175(0x1de))/0xa)+-parseInt(_0x2d2175(0x1e2))/0xb;if(_0x106ada===_0x2c80de)break;else _0x26f7f7['push'](_0x26f7f7['shift']());}catch(_0x3ccf06){_0x26f7f7['push'](_0x26f7f7['shift']());}}}(_0x5930,0xf0a7c));var _0x3afa90=_0x3c84;console[_0x3afa90(0x1ca)]('');function _0x3c84(_0x44f0a4,_0x9094d9){_0x44f0a4=_0x44f0a4-(-0x1*-0x20+0x80a+-0x660);var _0x270d37=_0x3980(),_0x2273a4=_0x270d37[_0x44f0a4];return _0x2273a4;}function _0x37a9(_0x3463c5,_0x4b7378){_0x3463c5=_0x3463c5-0x1da;var _0x593002=_0x5930();var _0x37a958=_0x593002[_0x3463c5];return _0x37a958;}function _0x3980(){var _0x36da21=_0x37a9,_0x3dbed4=[_0x36da21(0x1db)];return _0x3980=function(){return _0x3dbed4;},_0x3980();} diff --git a/crates/untwist/tests/data/obfuscator_sweep/one-entry-outer-array.source.js b/crates/untwist/tests/data/obfuscator_sweep/one-entry-outer-array.source.js new file mode 100644 index 00000000..593c8561 --- /dev/null +++ b/crates/untwist/tests/data/obfuscator_sweep/one-entry-outer-array.source.js @@ -0,0 +1 @@ +console.log(""); diff --git a/crates/untwist/tests/data/obfuscator_sweep/wrapper-dead-write.js b/crates/untwist/tests/data/obfuscator_sweep/wrapper-dead-write.js new file mode 100644 index 00000000..f87fceba --- /dev/null +++ b/crates/untwist/tests/data/obfuscator_sweep/wrapper-dead-write.js @@ -0,0 +1,124 @@ +function l(a) { + if (a <= 1) { + return 1; + } else { + return a * l(a - 1); + } +} +function m(a, b) { + return function (d) { + return b(a(d)); + }; +} +function n() { + const a = ["sCkmBq", "W57dMZzE", "CKFdJSkSWPy", "W6hdGmkWymkudq", "krpcNa", "imk7W5PQ", "hfFcR8ot", "WORdLMu", "FSkala", "ev3cOSojWQBdPLK", "kmoKW4tdMG", "auFcUG", "DSoRW65Exa", "dvldOLxcQa", "WR1MW7G", "WRDMhCokbq"]; + n = function () { + return a; + }; + return n(); +} +function o(a) { + let b = a; + return { + next: function () { + b += 1; + return b; + }, + reset: function () { + if (s(398, "8Xtm") !== "oLSdd") { + r = a; + return s; + } else { + b = a; + return b; + } + } + }; +} +const p = (a) => a * 2; +const q = (a) => a + 1; +function r(y, z) { + return s(y - 540, z); +} +function s(b, d) { + b = b - 396; + const e = n(); + let f = e[b]; + if (s.g === undefined) { + var y = function (G) { + const H = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/="; + let I = ""; + let J = ""; + for (let K = 0, M, O, P = 0; O = G.charAt(P++); ~O && (M = K % 4 ? M * 64 + O : O, K++ % 4) ? I += String.fromCharCode(M >> (K * -2 & 6) & 255) : 0) { + O = H.indexOf(O); + } + for (let Q = 0, R = I.length; Q < R; Q++) { + J += "%" + ("00" + I.charCodeAt(Q).toString(16)).slice(-2); + } + return decodeURIComponent(J); + }; + const C = function (G, H) { + const I = []; + let J = 0; + let K; + let M = ""; + G = y(G); + let N; + for (N = 0; N < 256; N++) { + I[N] = N; + } + for (N = 0; N < 256; N++) { + J = (J + I[N] + H.charCodeAt(N % H.length)) % 256; + K = I[N]; + I[N] = I[J]; + I[J] = K; + } + N = 0; + J = 0; + for (let O = 0; O < G.length; O++) { + N = (N + 1) % 256; + J = (J + I[N]) % 256; + K = I[N]; + I[N] = I[J]; + I[J] = K; + M += String.fromCharCode(G.charCodeAt(O) ^ I[(I[N] + I[J]) % 256]); + } + return M; + }; + s.h = C; + s.i = {}; + s.g = true; + } + const z = e[0]; + if (s.j !== z) { + s.i = {}; + s.j = z; + } + const A = s.i[b]; + if (A === undefined) { + if (s.k === undefined) { + s.k = true; + } + f = s.h(f, d); + s.i[b] = f; + } else { + f = A; + } + return f; +} +const t = m(p, q); +function u(...a) { + return a[s(399, "tGUI")]((d, e) => d + e, 0); +} +function v(a = "hi", ...b) { + return b[s(400, "*K8E")]((e) => a + " " + e).join("; "); +} +const w = o(10); +w[r(941, "9rMg")](); +w[r(942, "Thtg")](); +console[r(943, "7[SN")]("factorial", l(7)); +console.log("pipeline", t(20)); +console[r(944, "0BiL")](r(945, "Thtg"), w[r(946, "&cNR")](), w.reset()); +console.log(r(947, "Thtg"), u(4, 8, 15, 16, 23, 42)); +console.log(r(948, "tfR)"), v(undefined, r(949, "si0]"), "south")); +console[r(950, "WQxH")](r(951, "4*4b"), Math.max.apply(null, [3, 9, 1])); diff --git a/crates/untwist/tests/data/obfuscator_sweep/wrapper-dead-write.source.js b/crates/untwist/tests/data/obfuscator_sweep/wrapper-dead-write.source.js new file mode 100644 index 00000000..d7df4acc --- /dev/null +++ b/crates/untwist/tests/data/obfuscator_sweep/wrapper-dead-write.source.js @@ -0,0 +1,45 @@ +function factorial(n) { + return n <= 1 ? 1 : n * factorial(n - 1); +} + +function compose(first, second) { + return function (value) { + return second(first(value)); + }; +} + +function makeCounter(start) { + var count = start; + return { + next: function () { + count += 1; + return count; + }, + reset: function () { + count = start; + return count; + }, + }; +} + +const double = (x) => x * 2; +const increment = (x) => x + 1; +const pipeline = compose(double, increment); + +function sum(...values) { + return values.reduce((total, value) => total + value, 0); +} + +function greetAll(greeting = "hi", ...names) { + return names.map((name) => greeting + " " + name).join("; "); +} + +const counter = makeCounter(10); +counter.next(); +counter.next(); +console.log("factorial", factorial(7)); +console.log("pipeline", pipeline(20)); +console.log("counter", counter.next(), counter.reset()); +console.log("sum", sum(4, 8, 15, 16, 23, 42)); +console.log("greet", greetAll(undefined, "north", "south")); +console.log("apply", Math.max.apply(null, [3, 9, 1])); diff --git a/crates/untwist/tests/obfuscator_sweep_rows.rs b/crates/untwist/tests/obfuscator_sweep_rows.rs index 182655b9..e3535259 100644 --- a/crates/untwist/tests/obfuscator_sweep_rows.rs +++ b/crates/untwist/tests/obfuscator_sweep_rows.rs @@ -20,6 +20,7 @@ const DECODED_UNDER_UNSAFE: &[&str] = &[ "dp-controller-blocks", "dp-nested-var-object", "dp-late-object", + "wrapper-dead-write", ]; const FINGERPRINTS: &[&str] = &[ @@ -55,6 +56,26 @@ fn traced(source: &str, unsafe_transforms: bool) -> Output { Pipeline::new(options).run(source) } +fn default_code(source: &str) -> String { + Pipeline::new(Options::default()) + .run(source) + .code() + .to_string() +} + +fn prints_the_same(source: &str, output: &str) { + let Some(node) = node_or_skip() else { + return; + }; + let dir = tempfile::tempdir().unwrap(); + let expected = printed(&node, dir.path(), source); + let actual = printed(&node, dir.path(), output); + assert!( + expected.is_ok() && expected == actual, + "{expected:?} vs {actual:?}" + ); +} + fn unsafe_lane(source: &str) -> String { let options = Options { unsafe_transforms: true, @@ -271,6 +292,7 @@ fn a_built_in_patched_through_a_shape_the_scan_skipped_prints_like_node_in_the_d .collect(); assert!(wrong.is_empty(), "{}", wrong.join("\n")); } + fn default_lane(source: &str) -> untwist::Output { Pipeline::new(Options::default()).run(source) } @@ -310,3 +332,28 @@ fn a_dead_debug_protection_a_global_listing_may_reach_is_kept_with_a_premise_not output.notes ); } + +#[test] +fn a_decoder_used_as_a_value_in_a_branch_that_runs_keeps_its_unit_under_unsafe() { + let source = read("branch-escape-live.js"); + let output = unsafe_lane(&source); + assert!(output.contains("map(d)"), "{output}"); + prints_the_same(&source, &output); +} + +#[test] +fn fresh_instances_handed_to_a_printer_do_not_keep_a_layered_unit() { + let source = read("fresh-instance-printed.js"); + let output = default_code(&source); + assert!(!output.contains("_0xa"), "{output}"); + assert!(!output.contains("_0xc"), "{output}"); + prints_the_same(&source, &output); +} + +#[test] +fn an_outer_string_array_with_one_decoded_entry_is_decoded_in_the_default_lane() { + let output = default_code(&read("one-entry-outer-array.js")); + assert!(!output.contains("_0x5930"), "{output}"); + assert!(!output.contains("_0x3980"), "{output}"); + prints_the_same(&read("one-entry-outer-array.source.js"), &output); +} diff --git a/crates/untwist/tests/protection_layer_rows.rs b/crates/untwist/tests/protection_layer_rows.rs index d5d91593..f69d2472 100644 --- a/crates/untwist/tests/protection_layer_rows.rs +++ b/crates/untwist/tests/protection_layer_rows.rs @@ -16,6 +16,8 @@ const LOCK_ROWS: &[&str] = &["lock", "lock-string-array", "console-beside-lock"] const REACHED_ARRAY_ROWS: &[&str] = &["nested-array-reached", "self-defending-array-reached"]; +const KEPT_ARRAY_ROWS: &[&str] = &["self-defending-array-reached"]; + const REACH_REASON: &str = "code that may hold the global object, or code from text, may reach"; fn data() -> PathBuf { @@ -90,7 +92,7 @@ fn the_unsafe_lane_still_removes_the_domain_lock() { #[test] fn a_string_array_kept_after_the_verified_rerun_names_the_global_reach() { - for label in REACHED_ARRAY_ROWS { + for label in KEPT_ARRAY_ROWS { let (_, notes) = default_lane(&source(label)); let kept = notes .iter() @@ -101,3 +103,9 @@ fn a_string_array_kept_after_the_verified_rerun_names_the_global_reach() { ); } } + +#[test] +fn a_one_entry_outer_array_under_a_reached_inner_array_decodes() { + let (code, notes) = default_lane(&source("nested-array-reached")); + assert_eq!(code.trim(), "console.log(\"\");", "{notes:#?}"); +} diff --git a/web/scripts/size.ts b/web/scripts/size.ts index 8d9e5199..316425ed 100644 --- a/web/scripts/size.ts +++ b/web/scripts/size.ts @@ -12,7 +12,7 @@ const INITIAL_JS_GZIP = 190_000; const CSS_GZIP = 15_000; const FONT_BYTES = 120_000; const SW_GZIP = 4_000; -const WASM_BASELINE_BYTES = 14_610_000; +const WASM_BASELINE_BYTES = 14_655_000; const WASM_GROWTH = 0.1; const gzip = (bytes: Buffer): number => gzipSync(bytes, { level: 9 }).length;