use lief_ffi as ffi;
use std::marker::PhantomData;
use super::NoteBase;
use super::properties::{Properties, PropertyType};
use crate::common::{FromFFI, into_optional};
use crate::declare_fwd_iterator;
pub struct NoteGnuProperty<'a> {
ptr: cxx::UniquePtr<ffi::ELF_NoteGnuProperty>,
_owner: PhantomData<&'a ffi::ELF_Binary>,
}
impl NoteGnuProperty<'_> {
pub fn properties(&self) -> PropertiesIt<'_> {
PropertiesIt::new(self.ptr.properties())
}
pub fn find(&self, prop_type: PropertyType) -> Option<Properties<'_>> {
into_optional(self.ptr.find(prop_type.into()))
}
}
impl NoteBase for NoteGnuProperty<'_> {
fn get_base(&self) -> &ffi::ELF_Note {
self.ptr.as_ref().unwrap().as_ref()
}
}
impl FromFFI<ffi::ELF_NoteGnuProperty> for NoteGnuProperty<'_> {
fn from_ffi(ptr: cxx::UniquePtr<ffi::ELF_NoteGnuProperty>) -> Self {
Self {
ptr,
_owner: PhantomData,
}
}
}
impl std::fmt::Debug for NoteGnuProperty<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let base = self as &dyn NoteBase;
f.debug_struct("NoteGnuProperty")
.field("base", &base)
.finish()
}
}
declare_fwd_iterator!(
PropertiesIt,
Properties<'a>,
ffi::ELF_NoteGnuProperty_Property,
ffi::ELF_NoteGnuProperty,
ffi::ELF_NoteGnuProperty_it_properties
);