1use crate::model::addr::Va;
2use crate::objc::encoding::{ObjCMethodSignature, ObjCPropertyAttributes, ObjCQualifiedType};
3use std::fmt;
4
5#[derive(Debug, Clone)]
6pub struct ObjCClass {
8 pub name: String,
10 pub superclass_name: Option<String>,
12 pub instance_methods: Vec<ObjCMethod>,
14 pub class_methods: Vec<ObjCMethod>,
16 pub ivars: Vec<ObjCIvar>,
18 pub properties: Vec<ObjCProperty>,
20 pub protocols: Vec<String>,
22 pub instance_size: u32,
24 pub is_meta: bool,
26 pub is_swift: bool,
28}
29
30#[derive(Debug, Clone)]
31pub struct ObjCCategory {
33 pub name: String,
35 pub class_name: String,
37 pub instance_methods: Vec<ObjCMethod>,
39 pub class_methods: Vec<ObjCMethod>,
41 pub properties: Vec<ObjCProperty>,
43 pub protocols: Vec<String>,
45}
46
47#[derive(Debug, Clone)]
48pub struct ObjCProtocol {
50 pub name: String,
52 pub instance_methods: Vec<ObjCMethod>,
54 pub class_methods: Vec<ObjCMethod>,
56 pub optional_instance_methods: Vec<ObjCMethod>,
58 pub optional_class_methods: Vec<ObjCMethod>,
60 pub properties: Vec<ObjCProperty>,
62 pub adopted_protocols: Vec<String>,
64}
65
66#[derive(Debug, Clone)]
67pub struct ObjCMethod {
69 pub name: String,
71 pub type_encoding: String,
73 pub imp: Va,
75}
76
77impl fmt::Display for ObjCMethod {
78 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
79 write!(f, "{} ({})", self.name, self.type_encoding)
80 }
81}
82
83impl ObjCMethod {
84 pub fn parsed_signature(&self) -> Option<ObjCMethodSignature> {
86 ObjCMethodSignature::parse(&self.type_encoding).ok()
87 }
88}
89
90#[derive(Debug, Clone)]
91pub struct ObjCIvar {
93 pub name: String,
95 pub type_encoding: Option<String>,
99 pub offset: Option<u32>,
101 pub size: u32,
103 pub alignment: u32,
105}
106
107impl ObjCIvar {
108 pub fn parsed_type(&self) -> Option<ObjCQualifiedType> {
110 ObjCQualifiedType::parse(self.type_encoding.as_deref()?).ok()
111 }
112}
113
114#[derive(Debug, Clone)]
115pub struct ObjCProperty {
117 pub name: String,
119 pub attributes: String,
121 pub is_class: bool,
123}
124
125impl ObjCProperty {
126 pub fn parsed_attributes(&self) -> ObjCPropertyAttributes {
128 ObjCPropertyAttributes::parse(&self.attributes)
129 }
130}
131
132pub(crate) const CLASS_DATA_POINTER_MASK: u64 = !7;
134pub const RO_META: u32 = 1 << 0;
136pub const RO_ROOT: u32 = 1 << 1;
138pub const RO_HAS_CXX_STRUCTORS: u32 = 1 << 2;
140pub const RO_HIDDEN: u32 = 1 << 4;
142pub const RO_IS_ARC: u32 = 1 << 7;
144pub const RO_HAS_CXX_DTOR_ONLY: u32 = 1 << 8;
146
147pub const METHOD_LIST_USES_RELATIVE_OFFSETS: u32 = 0x8000_0000;
150pub const METHOD_LIST_USES_DIRECT_SELECTOR_OFFSETS: u32 = 0x4000_0000;
152pub const METHOD_LIST_ENTSIZE_MASK: u32 = 0x0000_FFFF;