//! OSTP Guard - Anti-Reverse Engineering Protection Module
//!
//! This module provides:
//! - Compile-time string obfuscation (XOR encryption)
//! - Runtime anti-debugging detection
//! - Anti-VM/sandbox detection
//! - Control flow obfuscation helpers
//! - Active probing detection and IP banning

pub mod obfuscate;
pub mod anti_debug;
pub mod anti_vm;
pub mod control_flow;
pub mod probe;

pub use obfuscate::*;
pub use anti_debug::*;
pub use anti_vm::*;
pub use control_flow::*;
pub use probe::*;

/// Error codes - obscure hex values instead of readable strings
pub mod error_codes {
    pub const E_NET_TIMEOUT: u32 = 0xDEADC0DE;
    pub const E_AUTH_FAIL: u32 = 0xCAFEBABE;
    pub const E_HANDSHAKE: u32 = 0xBAADF00D;
    pub const E_CRYPTO: u32 = 0xFEEDFACE;
    pub const E_INTERNAL: u32 = 0xC0FFEE00;
    pub const E_BANNED: u32 = 0x0BADC0DE;
}

/// Initialize all protection measures
/// Call this at the start of main()
#[inline(never)]
pub fn init_protection() -> bool {
    // Anti-debug check
    if anti_debug::is_debugger_present() {
        return false;
    }
    
    // Anti-VM check  
    if anti_vm::is_virtual_machine() {
        return false;
    }
    
    true
}

/// Perform fake work when tampering detected
/// This looks like legitimate network activity
#[inline(never)]
pub fn decoy_loop() -> ! {
    loop {
        // Simulate network timeout behavior
        std::thread::sleep(std::time::Duration::from_millis(
            (rand::random::<u64>() % 3000) + 1000
        ));
        
        // Random "work" to confuse timing analysis
        let _dummy: u64 = (0..1000)
            .map(|i| i ^ rand::random::<u64>())
            .fold(0, |a, b| a.wrapping_add(b));
    }
}
