js_deobfuscator/engine/module.rs
1//! Module trait — the contract every transformation pass implements.
2//!
3//! Leaf type — depends only on OXC types.
4
5use oxc::allocator::Allocator;
6use oxc::ast::ast::Program;
7use oxc::semantic::Scoping;
8
9use super::error::Result;
10
11/// Result of a single module's transformation pass.
12pub struct TransformResult {
13 /// Number of AST modifications made.
14 pub modifications: usize,
15 /// Scoping state after transformation (may be shared or rebuilt).
16 pub scoping: Scoping,
17}
18
19/// A deobfuscation transformation module.
20///
21/// Each module is a self-contained transformation pass. Modules run in a
22/// fixed order within the convergence loop. The engine chains scoping
23/// between modules and rebuilds it when `changes_symbols` returns true.
24pub trait Module: Send + Sync {
25 /// Human-readable name for logging.
26 fn name(&self) -> &'static str;
27
28 /// Whether this module adds/removes declarations or renames bindings.
29 ///
30 /// If true and modifications > 0, the engine rebuilds scoping after
31 /// this module runs.
32 fn changes_symbols(&self) -> bool {
33 false
34 }
35
36 /// Run the transformation.
37 fn transform<'a>(
38 &mut self,
39 allocator: &'a Allocator,
40 program: &mut Program<'a>,
41 scoping: Scoping,
42 ) -> Result<TransformResult>;
43}