Line data Source code
1 : use lief_ffi as ffi;
2 : use std::marker::PhantomData;
3 :
4 : use super::properties::{Properties, PropertyType};
5 : use super::NoteBase;
6 : use crate::common::{into_optional, FromFFI};
7 : use crate::declare_fwd_iterator;
8 :
9 : /// Note representing a GNU Property (`NT_GNU_PROPERTY_TYPE_0`)
10 : pub struct NoteGnuProperty<'a> {
11 : ptr: cxx::UniquePtr<ffi::ELF_NoteGnuProperty>,
12 : _owner: PhantomData<&'a ffi::ELF_Binary>,
13 : }
14 :
15 : impl NoteGnuProperty<'_> {
16 : /// Return the properties as an iterator
17 65 : pub fn properties(&self) -> PropertiesIt<'_> {
18 65 : PropertiesIt::new(self.ptr.properties())
19 65 : }
20 :
21 : /// Find a property by its type
22 26 : pub fn find(&self, prop_type: PropertyType) -> Option<Properties<'_>> {
23 26 : into_optional(self.ptr.find(prop_type.into()))
24 26 : }
25 : }
26 :
27 : impl NoteBase for NoteGnuProperty<'_> {
28 338 : fn get_base(&self) -> &ffi::ELF_Note {
29 338 : self.ptr.as_ref().unwrap().as_ref()
30 338 : }
31 : }
32 :
33 : impl FromFFI<ffi::ELF_NoteGnuProperty> for NoteGnuProperty<'_> {
34 169 : fn from_ffi(ptr: cxx::UniquePtr<ffi::ELF_NoteGnuProperty>) -> Self {
35 169 : Self {
36 169 : ptr,
37 169 : _owner: PhantomData,
38 169 : }
39 169 : }
40 : }
41 :
42 : impl std::fmt::Debug for NoteGnuProperty<'_> {
43 104 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 104 : let base = self as &dyn NoteBase;
45 104 : f.debug_struct("NoteGnuProperty")
46 104 : .field("base", &base)
47 104 : .finish()
48 104 : }
49 : }
50 :
51 104 : declare_fwd_iterator!(
52 104 : PropertiesIt,
53 104 : Properties<'a>,
54 104 : ffi::ELF_NoteGnuProperty_Property,
55 104 : ffi::ELF_NoteGnuProperty,
56 104 : ffi::ELF_NoteGnuProperty_it_properties
57 104 : );
|