synchrony_rs/
lib.rs

1//! # synchrony-rs
2//!
3//! A fast JavaScript deobfuscator written in Rust.
4//!
5//! ## Quick start
6//! ```rust
7//! use synchrony_rs::{DeobfuscateOptions, Deobfuscator};
8//! use synchrony_rs::transformers::Simplify;
9//! use std::sync::Arc;
10//!
11//! let deob = Deobfuscator::new();
12//! let options = DeobfuscateOptions {
13//!     custom_transformers: Some(vec![Arc::new(Simplify::new())]),
14//!     ..Default::default()
15//! };
16//! let output = deob.deobfuscate_source("var a = 1;", Some(options)).unwrap();
17//! assert!(output.contains("a"));
18//! ```
19//!
20//! ## Custom options
21//! ```rust
22//! use synchrony_rs::{Deobfuscator, DeobfuscateOptions, SourceType};
23//!
24//! let deob = Deobfuscator::new();
25//! let options = DeobfuscateOptions {
26//!     source_type: SourceType::Script,
27//!     rename: false,
28//!     ..Default::default()
29//! };
30//! let _ = deob.deobfuscate_source("var a = 1;", Some(options)).unwrap();
31//! ```
32//!
33//! ## Features
34//! - `cli`: enables the `synchrony` binary (disabled in `no-default-features` builds).
35//! - `tracing`: enables debug logging via the `tracing` crate.
36//!
37//! ## CLI
38//! Build the CLI with default features and run `synchrony --help` for usage.
39
40pub mod context;
41pub mod deobfuscator;
42pub mod error;
43#[cfg(feature = "format")]
44pub mod format;
45pub mod options;
46pub mod scope;
47pub mod transformers;
48mod visitor;
49mod words;
50
51#[cfg(feature = "wasm")]
52pub mod wasm;
53#[cfg(feature = "wasm")]
54pub mod wasm_logger;
55
56pub use context::Context;
57pub use deobfuscator::{DeobfuscateOptions, Deobfuscator, SourceType};
58pub use error::{DeobfuscateError, Result};
59
60/// Logging macros. On WASM builds they forward to a JS log sink.
61#[cfg(feature = "wasm")]
62macro_rules! log_info {
63    ($($arg:tt)*) => {
64        crate::wasm_logger::log(
65            crate::wasm_logger::LogLevel::Info,
66            &format!($($arg)*),
67        )
68    }
69}
70
71#[cfg(all(not(feature = "wasm"), feature = "tracing"))]
72macro_rules! log_info {
73    ($($arg:tt)*) => { tracing::info!($($arg)*) }
74}
75
76#[cfg(all(not(feature = "wasm"), not(feature = "tracing")))]
77macro_rules! log_info {
78    ($($arg:tt)*) => {{
79        let _: ::std::fmt::Arguments<'_> = ::std::format_args!($($arg)*);
80    }};
81}
82
83#[cfg(feature = "wasm")]
84macro_rules! log_debug {
85    ($($arg:tt)*) => {
86        crate::wasm_logger::log(
87            crate::wasm_logger::LogLevel::Debug,
88            &format!($($arg)*),
89        )
90    }
91}
92
93#[cfg(all(not(feature = "wasm"), feature = "tracing"))]
94macro_rules! log_debug {
95    ($($arg:tt)*) => { tracing::debug!($($arg)*) }
96}
97
98#[cfg(all(not(feature = "wasm"), not(feature = "tracing")))]
99macro_rules! log_debug {
100    ($($arg:tt)*) => {{
101        let _: ::std::fmt::Arguments<'_> = ::std::format_args!($($arg)*);
102    }};
103}
104
105pub(crate) use log_debug;
106pub(crate) use log_info;