yara_sys/
lib.rs

1#![allow(non_camel_case_types)]
2#![allow(non_snake_case)]
3#![allow(non_upper_case_globals)]
4
5pub mod errors;
6
7pub use crate::errors::*;
8
9use std::os::raw::c_char;
10
11#[allow(clippy::all)]
12mod bindings {
13    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
14}
15pub use bindings::*;
16
17pub mod scan_flags {
18    pub use super::{
19        SCAN_FLAGS_FAST_MODE, SCAN_FLAGS_NO_TRYCATCH, SCAN_FLAGS_PROCESS_MEMORY,
20        SCAN_FLAGS_REPORT_RULES_MATCHING, SCAN_FLAGS_REPORT_RULES_NOT_MATCHING,
21    };
22}
23
24#[derive(Clone, Copy, Debug, Eq, PartialEq)]
25pub enum MetaType {
26    Integer,
27    String,
28    Boolean,
29}
30
31impl MetaType {
32    #[deny(unused_variables)]
33    pub fn from_code(code: i32) -> Result<Self, i32> {
34        use self::MetaType::*;
35        match code as u32 {
36            META_TYPE_INTEGER => Ok(Integer),
37            META_TYPE_STRING => Ok(String),
38            META_TYPE_BOOLEAN => Ok(Boolean),
39            _ => Err(code),
40        }
41    }
42}
43
44impl YR_MATCHES {
45    #[deprecated = "Useless now"]
46    pub fn get_head(&self) -> *const YR_MATCH {
47        self.head
48    }
49
50    #[deprecated = "Useless now"]
51    pub fn get_tail(&self) -> *const YR_MATCH {
52        self.tail
53    }
54}
55
56// TODO: Find a better way than accessing anonymous fields.
57impl YR_META {
58    pub fn get_identifier(&self) -> *const c_char {
59        unsafe { self.__bindgen_anon_1.identifier }
60    }
61
62    pub fn get_string(&self) -> *const c_char {
63        unsafe { self.__bindgen_anon_2.string }
64    }
65}
66
67impl YR_NAMESPACE {
68    pub fn get_name(&self) -> *const c_char {
69        unsafe { self.__bindgen_anon_1.name }
70    }
71}
72
73impl YR_RULES {
74    pub fn get_rules_table(&self) -> *const YR_RULE {
75        unsafe { self.__bindgen_anon_1.rules_table }
76    }
77}
78
79impl YR_RULE {
80    pub fn get_identifier(&self) -> *const c_char {
81        unsafe { self.__bindgen_anon_1.identifier }
82    }
83
84    pub fn get_tags(&self) -> *const c_char {
85        unsafe { self.__bindgen_anon_2.tags }
86    }
87
88    pub fn get_metas(&self) -> *const YR_META {
89        unsafe { self.__bindgen_anon_3.metas }
90    }
91
92    pub fn get_strings(&self) -> *const YR_STRING {
93        unsafe { self.__bindgen_anon_4.strings }
94    }
95
96    pub fn get_ns(&self) -> *const YR_NAMESPACE {
97        unsafe { self.__bindgen_anon_5.ns }
98    }
99
100    pub fn enable(&mut self) {
101        unsafe {
102            yr_rule_enable(self);
103        }
104    }
105
106    pub fn disable(&mut self) {
107        unsafe {
108            yr_rule_disable(self);
109        }
110    }
111}
112
113impl YR_STRING {
114    pub fn get_identifier(&self) -> *const c_char {
115        unsafe { self.__bindgen_anon_3.identifier }
116    }
117
118    pub fn get_string(&self) -> *const c_char {
119        unsafe { self.__bindgen_anon_1.string as _ }
120    }
121}