Skip to main content

simple_analysis/
simple_analysis.rs

1#!/usr/bin/env cargo
2//! Simple executable analysis example
3//! 
4//! Run with: cargo run --example simple_analysis
5
6use execheck::{analyze_file, print_report, OutputFormat, SecurityReport, ReportSummary};
7use std::path::PathBuf;
8
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    // Analyze a single executable file
11    let file_path = PathBuf::from("/bin/ls");
12    
13    println!("Analyzing: {}", file_path.display());
14    
15    match analyze_file(&file_path) {
16        Ok(result) => {
17            println!("\n=== Analysis Results ===");
18            println!("File: {}", result.file_path);
19            println!("Type: {}", result.file_type);
20            println!("Status: {}", result.overall_status);
21            
22            println!("\n=== Security Checks ===");
23            for (check, value) in &result.checks {
24                println!("  {}: {}", check, value);
25            }
26            
27            // Create a report and print it in human-readable format
28            println!("\n=== Formatted Report ===");
29            let report = SecurityReport {
30                files: vec![result],
31                summary: ReportSummary {
32                    total_files: 1,
33                    secure_files: 1,
34                    insecure_files: 0,
35                    unsupported_files: 0,
36                },
37            };
38            
39            print_report(&report, &OutputFormat::Human, None)?;
40        }
41        Err(e) => {
42            eprintln!("Failed to analyze file: {}", e);
43            std::process::exit(1);
44        }
45    }
46    
47    Ok(())
48}