cradle-plugin-api 0.1.2

API for cradle plugins
Documentation
use cradle_shared::CheckResult;
use std::ffi::c_void;

/// Result struct for each plugin
/// Specifies the plugin name and a vector of the results
pub struct PluginResults {
    plugin: &'static str,
    results: Vec<CheckResult>,
}

impl PluginResults {
    /// Creates a new [`PluginResults`] object
    pub fn new(plugin: &'static str) -> Self {
        Self {
            plugin,
            results: Vec::new(),
        }
    }
    /// Helper to create a passing result check
    pub fn pass(&mut self, check: &str, msg: impl Into<String>) {
        self.results
            .push(CheckResult::pass(self.plugin, check, msg));
    }

    /// Helper to create a warning result check
    pub fn warn(&mut self, check: &str, msg: impl Into<String>) {
        self.results
            .push(CheckResult::warn(self.plugin, check, msg));
    }

    /// Helper to create a failure result check
    pub fn fail(&mut self, check: &str, msg: impl Into<String>) {
        self.results
            .push(CheckResult::fail(self.plugin, check, msg));
    }

    /// Helper to create an information result check
    pub fn info(&mut self, check: &str, msg: impl Into<String>) {
        self.results
            .push(CheckResult::info(self.plugin, check, msg));
    }

    /// Helper to create a warning result check with details
    pub fn warn_with(&mut self, check: &str, msg: impl Into<String>, details: impl Into<String>) {
        self.results
            .push(CheckResult::warn(self.plugin, check, msg).with_details(details));
    }

    /// Helper to create a failure result check with details
    pub fn fail_with(&mut self, check: &str, msg: impl Into<String>, details: impl Into<String>) {
        self.results
            .push(CheckResult::fail(self.plugin, check, msg).with_details(details));
    }

    /// Pushes a result into the array
    pub fn push(&mut self, result: CheckResult) {
        self.results.push(result);
    }

    /// Takes ownership of the stored results and returns them
    pub fn take(&mut self) -> Vec<CheckResult> {
        std::mem::take(&mut self.results)
    }

    /// Returns the length of the inner result array
    pub fn len(&self) -> usize {
        self.results.len()
    }

    /// Returns true if the inner results array is empty
    pub fn is_empty(&self) -> bool {
        self.results.is_empty()
    }
}

/// Events emitted by the agent during execution
#[non_exhaustive]
pub enum AgentEvent<'a> {
    /// A Process was created
    ProcessCreated {
        /// The PID of the created process
        pid: u32,
        /// The process handle
        process: *mut c_void,
        /// Path of the process
        target_path: &'a str,
        /// Bytes of the process
        target_bytes: &'a [u8],
    },
    /// A DLL has been loaded
    DllLoaded {
        /// Name of the DLL
        name: &'a str,
        /// Base address
        base: usize,
    },
    /// First breakpoint to be triggered
    InitialBreakpoint,
    /// A Thread has been created
    ThreadCreated {
        /// Thread ID
        tid: u32,
        /// Thread handle
        handle: *mut c_void,
    },
    /// Process finished executing
    Finished,
    /// Thread finished executing
    ThreadFinished {
        /// Thread ID
        tid: u32,
    },
    /// Process emitted a debug string
    DebugString {
        /// Debug string value
        string: &'a str,
    },
    /// Cradle agent has finished initializing
    AgentInitialized {
        /// Target process path
        target_path: &'a str,
    },
    /// Cradle agent has finished executing
    AgentFinished,
    /// Unknown event
    Unknown,
}