2025-06-24 20:27:06 +02:00
|
|
|
mod ast;
|
2026-02-25 21:16:36 -05:00
|
|
|
mod callgraph;
|
2025-06-28 17:36:14 +02:00
|
|
|
mod cfg;
|
2026-02-24 23:44:07 -05:00
|
|
|
mod cfg_analysis;
|
2025-06-16 16:46:22 +02:00
|
|
|
mod cli;
|
|
|
|
|
mod commands;
|
2025-06-16 23:54:18 +02:00
|
|
|
mod database;
|
2025-06-23 20:27:16 +02:00
|
|
|
mod errors;
|
2026-02-25 21:16:36 -05:00
|
|
|
mod evidence;
|
|
|
|
|
mod fmt;
|
2026-02-24 23:44:07 -05:00
|
|
|
mod interop;
|
2025-06-28 17:36:14 +02:00
|
|
|
mod labels;
|
2026-02-25 04:02:11 -05:00
|
|
|
mod output;
|
2025-06-24 20:27:06 +02:00
|
|
|
mod patterns;
|
2026-02-25 21:16:36 -05:00
|
|
|
mod rank;
|
|
|
|
|
mod state;
|
2026-02-24 23:44:07 -05:00
|
|
|
mod summary;
|
2026-02-25 21:16:36 -05:00
|
|
|
mod suppress;
|
2026-02-24 23:44:07 -05:00
|
|
|
mod symbol;
|
|
|
|
|
mod taint;
|
2025-06-24 20:27:06 +02:00
|
|
|
mod utils;
|
|
|
|
|
mod walk;
|
2025-06-16 16:46:22 +02:00
|
|
|
|
2025-06-24 20:27:06 +02:00
|
|
|
use crate::errors::NyxResult;
|
2025-06-16 16:46:22 +02:00
|
|
|
use crate::utils::Config;
|
|
|
|
|
use clap::Parser;
|
2025-06-24 20:27:06 +02:00
|
|
|
use cli::Cli;
|
|
|
|
|
use console::style;
|
2025-06-16 16:46:22 +02:00
|
|
|
use directories::ProjectDirs;
|
|
|
|
|
use std::fs;
|
2025-06-23 18:25:10 +02:00
|
|
|
use std::time::Instant;
|
2025-06-16 16:46:22 +02:00
|
|
|
use tracing_subscriber::fmt::time;
|
2025-06-24 20:27:06 +02:00
|
|
|
use tracing_subscriber::prelude::*;
|
2026-02-25 21:16:36 -05:00
|
|
|
use tracing_subscriber::{EnvFilter, Registry, fmt as tracing_fmt};
|
2025-06-16 16:46:22 +02:00
|
|
|
// use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
|
|
|
|
// use tracing_appender::non_blocking;
|
|
|
|
|
|
|
|
|
|
fn init_tracing() {
|
2025-06-17 10:55:50 +02:00
|
|
|
// let file_appender = RollingFileAppender::new(Rotation::HOURLY, "logs", "nyx-scanner.log");
|
2025-06-16 16:46:22 +02:00
|
|
|
// let (file_writer, guard) = non_blocking(file_appender);
|
2025-06-24 20:27:06 +02:00
|
|
|
|
2026-02-25 21:16:36 -05:00
|
|
|
let fmt_layer = tracing_fmt::layer()
|
2025-06-24 20:27:06 +02:00
|
|
|
.pretty()
|
|
|
|
|
.with_thread_ids(true)
|
2025-06-16 16:46:22 +02:00
|
|
|
.with_timer(time::UtcTime::rfc_3339());
|
2025-06-24 20:27:06 +02:00
|
|
|
|
2025-06-16 16:46:22 +02:00
|
|
|
// let file_layer = fmt::layer()
|
2025-06-24 20:27:06 +02:00
|
|
|
// .with_writer(file_writer)
|
|
|
|
|
// .without_time()
|
2025-06-16 16:46:22 +02:00
|
|
|
// .json();
|
|
|
|
|
|
|
|
|
|
Registry::default()
|
2025-06-24 20:27:06 +02:00
|
|
|
.with(EnvFilter::from_default_env())
|
|
|
|
|
.with(fmt_layer)
|
2025-06-16 23:47:50 +02:00
|
|
|
.init();
|
2025-06-16 16:46:22 +02:00
|
|
|
}
|
|
|
|
|
|
2025-06-23 20:59:49 +02:00
|
|
|
fn main() -> NyxResult<()> {
|
2025-06-23 18:25:10 +02:00
|
|
|
let now = Instant::now();
|
2025-06-16 16:46:22 +02:00
|
|
|
init_tracing();
|
|
|
|
|
|
|
|
|
|
tracing::debug!("CLI starting up");
|
|
|
|
|
let cli = Cli::parse();
|
|
|
|
|
|
2026-02-25 21:16:36 -05:00
|
|
|
let proj_dirs =
|
|
|
|
|
ProjectDirs::from("", "", "nyx").ok_or("Unable to determine project directories")?;
|
2025-06-16 16:46:22 +02:00
|
|
|
|
2026-02-24 23:44:07 -05:00
|
|
|
// todo: check if we want to actually build a config file, maybe some environments will not want to have anything written
|
2025-06-16 16:46:22 +02:00
|
|
|
let config_dir = proj_dirs.config_dir();
|
|
|
|
|
fs::create_dir_all(config_dir)?;
|
|
|
|
|
|
|
|
|
|
let database_dir = proj_dirs.data_local_dir();
|
|
|
|
|
fs::create_dir_all(database_dir)?;
|
|
|
|
|
|
2026-02-25 04:02:11 -05:00
|
|
|
let (mut config, config_note) = Config::load(config_dir)?;
|
2025-06-16 16:46:22 +02:00
|
|
|
|
2025-06-28 17:36:14 +02:00
|
|
|
rayon::ThreadPoolBuilder::new()
|
|
|
|
|
.stack_size(config.performance.rayon_thread_stack_size)
|
|
|
|
|
.build_global()
|
|
|
|
|
.expect("set rayon stack size");
|
|
|
|
|
|
2026-02-25 04:02:11 -05:00
|
|
|
let quiet = config.output.quiet || cli.command.is_structured_output();
|
2025-06-16 16:46:22 +02:00
|
|
|
|
2026-02-25 04:02:11 -05:00
|
|
|
// Print config note before scanning (human-readable mode only).
|
|
|
|
|
if let Some(note) = config_note.filter(|_| !quiet) {
|
|
|
|
|
eprint!("{note}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
commands::handle_command(cli.command, database_dir, config_dir, &mut config)?;
|
|
|
|
|
|
|
|
|
|
if !quiet {
|
2026-02-25 21:16:36 -05:00
|
|
|
eprintln!(
|
2026-02-25 04:02:11 -05:00
|
|
|
"{} in {:.3}s.",
|
|
|
|
|
style("Finished").green().bold(),
|
|
|
|
|
now.elapsed().as_secs_f32()
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-06-16 16:46:22 +02:00
|
|
|
Ok(())
|
|
|
|
|
}
|