1use std::rc::Rc;
2
3#[derive(Debug, PartialEq)]
4pub struct DexFile {
5 pub header: super::Header,
6 pub file_data: DexFileData,
7 pub classes: Vec<ClassDefinition>
8 }
12
13#[derive(Debug, PartialEq)]
14pub struct DexFileData {
15 pub string_data: Vec<Rc<String>>,
16 pub type_identifiers: Vec<Rc<String>>,
17 pub prototypes: Vec<Rc<Prototype>>,
18 pub fields: Vec<Rc<Field>>,
19 pub methods: Vec<Rc<Method>>
20}
21
22#[derive(Debug, PartialEq)]
23pub struct CallSiteItem {
24 pub method_handle: Rc<Method>,
25 pub method_name: Rc<String>,
26 pub method_type: Rc<Prototype>,
27 pub constant_values: Vec<EncodedValue>
28}
29
30#[derive(Debug, PartialEq)]
31pub struct Header {
32 pub version: i32,
33 pub checksum: String,
34 pub signature: [u8; 20],
35 pub file_size: u32,
36 pub endianness: nom::Endianness
37}
38
39#[derive(Debug, PartialEq)]
40pub struct Prototype {
41 pub shorty: Rc<String>,
42 pub return_type: Rc<String>,
43 pub parameters: Vec<Rc<String>>
44}
45
46#[derive(Debug, PartialEq)]
47pub struct Field {
48 pub definer: Rc<String>,
49 pub type_: Rc<String>,
50 pub name: Rc<String>
51}
52
53#[derive(Debug, PartialEq)]
54pub struct Method {
55 pub definer: Rc<String>,
56 pub prototype: Rc<Prototype>,
57 pub name: Rc<String>
58}
59
60#[derive(Debug, PartialEq)]
61pub struct ClassAnnotation {
62 pub visibility: Visibility,
63 pub type_: Rc<String>,
64 pub elements: Vec<AnnotationElement>
65}
66
67#[derive(Debug, PartialEq, Clone)]
68pub struct AnnotationElement {
69 pub name: Rc<String>,
70 pub value: EncodedValue
71}
72
73#[derive(Debug, PartialEq)]
74pub struct ClassDefinition {
75 pub class_type: Rc<String>,
76 pub access_flags: Vec<AccessFlag>,
77 pub superclass: Option<Rc<String>>,
78 pub interfaces: Vec<Rc<String>>,
79 pub source_file_name: Option<Rc<String>>,
80 pub annotations: Option<Annotations>,
81 pub class_data: Option<ClassData>,
82 pub static_values: Vec<EncodedValue>
83}
84
85#[derive(Debug, PartialEq)]
86pub struct Annotations {
87 pub class_annotations: Vec<ClassAnnotation>,
88 pub field_annotations: Vec<FieldAnnotation>,
89 pub method_annotations: Vec<MethodAnnotation>,
90 pub parameter_annotations: Vec<ParameterAnnotation>
91}
92
93#[derive(Debug, PartialEq)]
94pub struct ClassData {
95 pub static_fields: Vec<EncodedField>,
96 pub instance_fields: Vec<EncodedField>,
97 pub direct_methods: Vec<EncodedMethod>,
98 pub virtual_methods: Vec<EncodedMethod>
99}
100
101#[derive(Debug, PartialEq)]
102pub struct EncodedField {
103 pub field: Rc<Field>,
104 pub access_flags: Vec<AccessFlag>
105}
106
107#[derive(Debug, PartialEq)]
108pub struct EncodedMethod {
109 pub method: Rc<Method>,
110 pub access_flags: Vec<AccessFlag>,
111 pub code: Option<Code>
112}
113
114#[derive(Debug, PartialEq)]
115pub struct MethodAnnotation {
116 pub method: Rc<Method>,
117 pub annotations: Vec<AnnotationItem>
118}
119
120#[derive(Debug, PartialEq)]
121pub struct ParameterAnnotation {
122 pub method: Rc<Method>,
123 pub annotations: Vec<AnnotationItem>
124}
125
126#[derive(Debug, PartialEq)]
127pub struct FieldAnnotation {
128 pub field_data: Rc<Field>,
129 pub annotations: Vec<AnnotationItem>
130}
131
132#[derive(Debug, PartialEq, Clone)]
133pub struct AnnotationItem {
134 pub visibility: Visibility,
135 pub type_: Rc<String>,
136 pub annotations: Vec<AnnotationElement>
137}
138
139#[derive(Debug, PartialEq, Clone)]
140pub enum Visibility {
141 BUILD,
142 RUNTIME,
143 SYSTEM
144}
145
146#[derive(Debug, PartialEq)]
148pub struct Code {
149 pub registers_size: u16,
151 pub ins_size: u16,
153 pub outs_size: u16,
155 pub debug_info: Option<DebugInfo>,
156 pub insns: Vec<u16>,
157 pub tries: Vec<TryItem>,
158 pub handlers: Vec<EncodedCatchHandler>
159}
160
161#[derive(Debug, PartialEq)]
163pub struct TryItem {
164 pub code_units: Vec<u16>,
165 pub handler: EncodedCatchHandler
166}
167
168#[derive(Debug, PartialEq)]
170pub struct EncodedCatchHandler {
171 pub handlers: Vec<EncodedTypeAddrPair>,
172 pub catch_all_addr: Option<u32>
175}
176
177#[derive(Debug, PartialEq)]
179pub struct EncodedTypeAddrPair {
180 pub type_: Rc<String>,
182 pub addr: u32
184}
185
186#[derive(Debug, PartialEq)]
188pub struct DebugInfo {
189 pub line_start: u32,
190 pub parameter_names: Vec<i32>,
191 pub bytecode: Vec<DebugItemBytecodes>
192}
193
194#[derive(Debug, PartialEq, Clone)]
195pub enum EncodedValue {
196 Byte(u8),
197 Short(i16),
198 Char(u16),
199 Int(i32),
200 Long(i64),
201 Float(f32),
202 Double(f64),
203 MethodType(Rc<Prototype>),
204 MethodHandle(Rc<Method>),
205 String(Rc<String>),
206 Type(Rc<String>),
207 Field(Rc<Field>),
208 Method(Rc<Method>),
209 Enum(Rc<Field>),
210 Array(Vec<EncodedValue>),
211 Annotation(EncodedAnnotationItem),
212 Null,
213 Boolean(bool)
214}
215
216#[derive(Debug, PartialEq, Clone)]
217pub struct EncodedAnnotationItem {
218 pub type_: Rc<String>,
219 pub values: Vec<AnnotationElement>
220}
221
222#[allow(non_camel_case_types)]
224#[derive(Debug, PartialEq)]
225pub enum DebugItemBytecodes {
226 DBG_END_SEQUENCE,
227 DBG_ADVANCE_PC,
228 DBG_ADVANCE_LINE,
229 DBG_START_LOCAL,
230 DBG_START_LOCAL_EXTENDED,
231 DBG_END_LOCAL,
232 DBG_RESTART_LOCAL,
233 DBG_SET_PROLOGUE_END,
234 DBG_SET_EPILOGUE_BEGIN,
235 DBG_SET_FILE,
236 SPECIAL_OPCODE(u8)
237}
238
239#[allow(non_camel_case_types)]
241#[derive(PartialEq, Debug)]
242pub enum AccessFlag {
243 ACC_PUBLIC,
244 ACC_PRIVATE,
245 ACC_PROTECTED,
246 ACC_STATIC,
247 ACC_FINAL,
248 ACC_SYNCHRONIZED,
249 ACC_VOLATILE,
250 ACC_BRIDGE,
251 ACC_TRANSIENT,
252 ACC_VARARGS,
253 ACC_NATIVE,
254 ACC_INTERFACE,
255 ACC_ABSTRACT,
256 ACC_STRICT,
257 ACC_SYNTHETIC,
258 ACC_ANNOTATION,
259 ACC_ENUM,
260 UNUSED,
261 ACC_CONSTRUCTOR,
262 ACC_DECLARED_SYNCHRONIZED
263}