idalib/
processor.rs

1use std::marker::PhantomData;
2
3use crate::ffi::processor::*;
4use crate::idb::IDB;
5use crate::Address;
6
7pub use crate::ffi::processor::ids as id;
8
9pub struct Processor<'a> {
10    ptr: *const processor_t,
11    _marker: PhantomData<&'a IDB>,
12}
13
14pub type ProcessorId = i32;
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
17pub struct ProcessorFamily(ProcessorId);
18
19impl ProcessorFamily {
20    pub fn is_386(&self) -> bool {
21        self.0 == id::PLFM_386 as _
22    }
23
24    pub fn is_z80(&self) -> bool {
25        self.0 == id::PLFM_Z80 as _
26    }
27
28    pub fn is_i860(&self) -> bool {
29        self.0 == id::PLFM_I860 as _
30    }
31
32    pub fn is_8051(&self) -> bool {
33        self.0 == id::PLFM_8051 as _
34    }
35
36    pub fn is_tms(&self) -> bool {
37        self.0 == id::PLFM_TMS as _
38    }
39
40    pub fn is_6502(&self) -> bool {
41        self.0 == id::PLFM_6502 as _
42    }
43
44    pub fn is_pdp(&self) -> bool {
45        self.0 == id::PLFM_PDP as _
46    }
47
48    pub fn is_68k(&self) -> bool {
49        self.0 == id::PLFM_68K as _
50    }
51
52    pub fn is_java(&self) -> bool {
53        self.0 == id::PLFM_JAVA as _
54    }
55
56    pub fn is_6800(&self) -> bool {
57        self.0 == id::PLFM_6800 as _
58    }
59
60    pub fn is_st7(&self) -> bool {
61        self.0 == id::PLFM_ST7 as _
62    }
63
64    pub fn is_mc6812(&self) -> bool {
65        self.0 == id::PLFM_MC6812 as _
66    }
67
68    pub fn is_mips(&self) -> bool {
69        self.0 == id::PLFM_MIPS as _
70    }
71
72    pub fn is_arm(&self) -> bool {
73        self.0 == id::PLFM_ARM as _
74    }
75
76    pub fn is_tmsc6(&self) -> bool {
77        self.0 == id::PLFM_TMSC6 as _
78    }
79
80    pub fn is_ppc(&self) -> bool {
81        self.0 == id::PLFM_PPC as _
82    }
83
84    pub fn is_80196(&self) -> bool {
85        self.0 == id::PLFM_80196 as _
86    }
87
88    pub fn is_z8(&self) -> bool {
89        self.0 == id::PLFM_Z8 as _
90    }
91
92    pub fn is_sh(&self) -> bool {
93        self.0 == id::PLFM_SH as _
94    }
95
96    pub fn is_net(&self) -> bool {
97        self.0 == id::PLFM_NET as _
98    }
99
100    pub fn is_avr(&self) -> bool {
101        self.0 == id::PLFM_AVR as _
102    }
103
104    pub fn is_h8(&self) -> bool {
105        self.0 == id::PLFM_H8 as _
106    }
107
108    pub fn is_pic(&self) -> bool {
109        self.0 == id::PLFM_PIC as _
110    }
111
112    pub fn is_sparc(&self) -> bool {
113        self.0 == id::PLFM_SPARC as _
114    }
115
116    pub fn is_alpha(&self) -> bool {
117        self.0 == id::PLFM_ALPHA as _
118    }
119
120    pub fn is_hppa(&self) -> bool {
121        self.0 == id::PLFM_HPPA as _
122    }
123
124    pub fn is_h8500(&self) -> bool {
125        self.0 == id::PLFM_H8500 as _
126    }
127
128    pub fn is_tricore(&self) -> bool {
129        self.0 == id::PLFM_TRICORE as _
130    }
131
132    pub fn is_dsp56k(&self) -> bool {
133        self.0 == id::PLFM_DSP56K as _
134    }
135
136    pub fn is_c166(&self) -> bool {
137        self.0 == id::PLFM_C166 as _
138    }
139
140    pub fn is_st20(&self) -> bool {
141        self.0 == id::PLFM_ST20 as _
142    }
143
144    pub fn is_ia64(&self) -> bool {
145        self.0 == id::PLFM_IA64 as _
146    }
147
148    pub fn is_i960(&self) -> bool {
149        self.0 == id::PLFM_I960 as _
150    }
151
152    pub fn is_f2mc(&self) -> bool {
153        self.0 == id::PLFM_F2MC as _
154    }
155
156    pub fn is_tms320c54(&self) -> bool {
157        self.0 == id::PLFM_TMS320C54 as _
158    }
159
160    pub fn is_tms320c55(&self) -> bool {
161        self.0 == id::PLFM_TMS320C55 as _
162    }
163
164    pub fn is_trimedia(&self) -> bool {
165        self.0 == id::PLFM_TRIMEDIA as _
166    }
167
168    pub fn is_m32r(&self) -> bool {
169        self.0 == id::PLFM_M32R as _
170    }
171
172    pub fn is_nec_78k0(&self) -> bool {
173        self.0 == id::PLFM_NEC_78K0 as _
174    }
175
176    pub fn is_nec_78k0s(&self) -> bool {
177        self.0 == id::PLFM_NEC_78K0S as _
178    }
179
180    pub fn is_m740(&self) -> bool {
181        self.0 == id::PLFM_M740 as _
182    }
183
184    pub fn is_m7700(&self) -> bool {
185        self.0 == id::PLFM_M7700 as _
186    }
187
188    pub fn is_st9(&self) -> bool {
189        self.0 == id::PLFM_ST9 as _
190    }
191
192    pub fn is_fr(&self) -> bool {
193        self.0 == id::PLFM_FR as _
194    }
195
196    pub fn is_mc6816(&self) -> bool {
197        self.0 == id::PLFM_MC6816 as _
198    }
199
200    pub fn is_m7900(&self) -> bool {
201        self.0 == id::PLFM_M7900 as _
202    }
203
204    pub fn is_tms320c3(&self) -> bool {
205        self.0 == id::PLFM_TMS320C3 as _
206    }
207
208    pub fn is_kr1878(&self) -> bool {
209        self.0 == id::PLFM_KR1878 as _
210    }
211
212    pub fn is_ad218x(&self) -> bool {
213        self.0 == id::PLFM_AD218X as _
214    }
215
216    pub fn is_oakdsp(&self) -> bool {
217        self.0 == id::PLFM_OAKDSP as _
218    }
219
220    pub fn is_tlcs900(&self) -> bool {
221        self.0 == id::PLFM_TLCS900 as _
222    }
223
224    pub fn is_c39(&self) -> bool {
225        self.0 == id::PLFM_C39 as _
226    }
227
228    pub fn is_cr16(&self) -> bool {
229        self.0 == id::PLFM_CR16 as _
230    }
231
232    pub fn is_mn102l00(&self) -> bool {
233        self.0 == id::PLFM_MN102L00 as _
234    }
235
236    pub fn is_tms320c1x(&self) -> bool {
237        self.0 == id::PLFM_TMS320C1X as _
238    }
239
240    pub fn is_nec_v850x(&self) -> bool {
241        self.0 == id::PLFM_NEC_V850X as _
242    }
243
244    pub fn is_scr_adpt(&self) -> bool {
245        self.0 == id::PLFM_SCR_ADPT as _
246    }
247
248    pub fn is_ebc(&self) -> bool {
249        self.0 == id::PLFM_EBC as _
250    }
251
252    pub fn is_msp430(&self) -> bool {
253        self.0 == id::PLFM_MSP430 as _
254    }
255
256    pub fn is_spu(&self) -> bool {
257        self.0 == id::PLFM_SPU as _
258    }
259
260    pub fn is_dalvik(&self) -> bool {
261        self.0 == id::PLFM_DALVIK as _
262    }
263
264    pub fn is_65c816(&self) -> bool {
265        self.0 == id::PLFM_65C816 as _
266    }
267
268    pub fn is_m16c(&self) -> bool {
269        self.0 == id::PLFM_M16C as _
270    }
271
272    pub fn is_arc(&self) -> bool {
273        self.0 == id::PLFM_ARC as _
274    }
275
276    pub fn is_unsp(&self) -> bool {
277        self.0 == id::PLFM_UNSP as _
278    }
279
280    pub fn is_tms320c28(&self) -> bool {
281        self.0 == id::PLFM_TMS320C28 as _
282    }
283
284    pub fn is_dsp96k(&self) -> bool {
285        self.0 == id::PLFM_DSP96K as _
286    }
287
288    pub fn is_spc700(&self) -> bool {
289        self.0 == id::PLFM_SPC700 as _
290    }
291
292    pub fn is_ad2106x(&self) -> bool {
293        self.0 == id::PLFM_AD2106X as _
294    }
295
296    pub fn is_pic16(&self) -> bool {
297        self.0 == id::PLFM_PIC16 as _
298    }
299
300    pub fn is_s390(&self) -> bool {
301        self.0 == id::PLFM_S390 as _
302    }
303
304    pub fn is_xtensa(&self) -> bool {
305        self.0 == id::PLFM_XTENSA as _
306    }
307
308    pub fn is_riscv(&self) -> bool {
309        self.0 == id::PLFM_RISCV as _
310    }
311
312    pub fn is_rl78(&self) -> bool {
313        self.0 == id::PLFM_RL78 as _
314    }
315
316    pub fn is_rx(&self) -> bool {
317        self.0 == id::PLFM_RX as _
318    }
319
320    pub fn is_wasm(&self) -> bool {
321        self.0 == id::PLFM_WASM as _
322    }
323}
324
325impl<'a> Processor<'a> {
326    pub(crate) fn from_ptr(ptr: *const processor_t) -> Self {
327        Self {
328            ptr,
329            _marker: PhantomData,
330        }
331    }
332
333    pub fn id(&self) -> ProcessorId {
334        unsafe { idalib_ph_id(self.ptr) }
335    }
336
337    pub fn family(&self) -> ProcessorFamily {
338        ProcessorFamily(self.id())
339    }
340
341    pub fn long_name(&self) -> String {
342        unsafe { idalib_ph_long_name(self.ptr) }
343    }
344
345    pub fn short_name(&self) -> String {
346        unsafe { idalib_ph_short_name(self.ptr) }
347    }
348
349    pub fn is_thumb_at(&self, ea: Address) -> bool {
350        unsafe { idalib_is_thumb_at(self.ptr, ea.into()) }
351    }
352}