Skip to main content

macho_cpp/
types.rs

1use serde::Serialize;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize)]
4#[serde(rename_all = "snake_case")]
5/// The CppConfidence type.
6#[non_exhaustive]
7pub enum CppConfidence {
8    /// The Exact variant.
9    Exact,
10    /// The High variant.
11    High,
12    /// The Medium variant.
13    Medium,
14    /// The Low variant.
15    Low,
16    /// The Hook variant.
17    Hook,
18}
19
20impl CppConfidence {
21    /// Performs max.
22    pub fn max(self, other: Self) -> Self {
23        self.max_by(other, |left, right| left.cmp(right))
24    }
25
26    fn max_by<F>(self, other: Self, cmp: F) -> Self
27    where
28        F: Fn(&Self, &Self) -> std::cmp::Ordering,
29    {
30        if cmp(&self, &other).is_ge() {
31            self
32        } else {
33            other
34        }
35    }
36}
37
38#[derive(Debug, Clone, Serialize)]
39#[serde(rename_all = "snake_case")]
40/// The CppEvidenceKind type.
41#[non_exhaustive]
42pub enum CppEvidenceKind {
43    /// The MangledSymbol variant.
44    MangledSymbol,
45    /// The DemangledSymbol variant.
46    DemangledSymbol,
47    /// The Vtable variant.
48    Vtable,
49    /// The TypeInfo variant.
50    TypeInfo,
51    /// The BodyAnalysis variant.
52    BodyAnalysis,
53    /// The CrossBinary variant.
54    CrossBinary,
55    /// The ExternalHeader variant.
56    ExternalHeader,
57}
58
59#[derive(Debug, Clone, Serialize)]
60/// The CppEvidence type.
61pub struct CppEvidence {
62    /// The kind field.
63    pub kind: CppEvidenceKind,
64    /// The confidence field.
65    pub confidence: CppConfidence,
66    /// The detail field.
67    pub detail: String,
68}
69
70#[derive(Debug, Clone, Serialize)]
71#[serde(rename_all = "snake_case")]
72/// The CppTypeInfoKind type.
73#[non_exhaustive]
74pub enum CppTypeInfoKind {
75    /// The Class variant.
76    Class,
77    /// The SingleInheritance variant.
78    SingleInheritance,
79    /// The VirtualMultipleInheritance variant.
80    VirtualMultipleInheritance,
81    /// The Unknown variant.
82    Unknown,
83}
84
85#[derive(Debug, Clone, Serialize)]
86/// The CppBaseClass type.
87pub struct CppBaseClass {
88    /// The name field.
89    pub name: String,
90    /// The offset field.
91    pub offset: Option<i64>,
92    /// The flags field.
93    pub flags: u64,
94    /// The is_virtual field.
95    pub is_virtual: bool,
96    /// The is_public field.
97    pub is_public: bool,
98    /// The evidence field.
99    pub evidence: Vec<CppEvidence>,
100}
101
102#[derive(Debug, Clone, Serialize)]
103/// The CppTypeInfoNode type.
104pub struct CppTypeInfoNode {
105    /// The name field.
106    pub name: String,
107    /// The mangled_name field.
108    pub mangled_name: String,
109    /// The address field.
110    pub address: u64,
111    /// The kind field.
112    pub kind: CppTypeInfoKind,
113    /// The bases field.
114    pub bases: Vec<CppBaseClass>,
115    /// The evidence field.
116    pub evidence: Vec<CppEvidence>,
117}