1use std::marker::PhantomData;
2
3use bitflags::bitflags;
4
5use crate::ffi::plugin::*;
6use crate::idb::IDB;
7
8pub use crate::ffi::processor::ids as id;
9
10#[cfg(feature = "plugin")]
11mod plugmod;
12#[cfg(feature = "plugin")]
13pub use plugmod::*;
14
15
16bitflags! {
17 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
18 pub struct PluginFlags: u64 {
19 const MOD = flags::PLUGIN_MOD as u64;
20 const DRAW = flags::PLUGIN_DRAW as u64;
21 const SEG = flags::PLUGIN_SEG as u64;
22 const UNL = flags::PLUGIN_UNL as u64;
23 const HIDE = flags::PLUGIN_HIDE as u64;
24 const DBG = flags::PLUGIN_DBG as u64;
25 const PROC = flags::PLUGIN_PROC as u64;
26 const FIX = flags::PLUGIN_FIX as u64;
27 const MULTI = flags::PLUGIN_MULTI as u64;
28 const SCRIPTED = flags::PLUGIN_SCRIPTED as u64;
29 }
30}
31
32pub struct Plugin<'a> {
33 ptr: *const plugin_t,
34 _marker: PhantomData<&'a IDB>,
35}
36
37impl<'a> Plugin<'a> {
38 pub(crate) fn from_ptr(ptr: *const plugin_t) -> Self {
39 Self {
40 ptr,
41 _marker: PhantomData,
42 }
43 }
44
45 pub fn run(&self, arg: usize) -> bool {
46 unsafe { run_plugin(self.ptr, arg) }
47 }
48
49 pub fn version(&self) -> u64 {
50 unsafe { idalib_plugin_version(self.ptr) }
51 }
52
53 pub fn flags(&self) -> PluginFlags {
54 let bits = unsafe { idalib_plugin_flags(self.ptr) };
55 PluginFlags::from_bits_retain(bits)
56 }
57}