Skip to content

Commit 5b60645

Browse files
yujincheng08romainthomas
authored andcommitted
Add remove_dynamic_entries_by_tag and add_dynamic_entry
1 parent 56a2e22 commit 5b60645

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

api/rust/cargo/lief/src/elf/binary.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use num_traits::{cast, Num};
77
use lief_ffi as ffi;
88

99
use super::builder::Config;
10-
use super::dynamic::{self, DynamicEntries, Library};
10+
use super::dynamic::{self, DynamicEntries, DynamicEntry, Library};
1111
use super::hash::{Gnu, Sysv};
1212
use super::header::Header;
1313
use super::note::ItNotes;
@@ -118,6 +118,16 @@ impl Binary {
118118
DynamicEntries::new(self.ptr.dynamic_entries())
119119
}
120120

121+
/// Remove **all** dynamic entries with the given tag
122+
pub fn remove_dynamic_entries_by_tag(&mut self, tag: dynamic::Tag) {
123+
self.ptr.as_mut().unwrap().remove_dynamic_entries_by_tag(tag.into())
124+
}
125+
126+
/// Add the given dynamic entry and return the new entry
127+
pub fn add_dynamic_entry(&mut self, entry: &dynamic::Entries) -> dynamic::Entries {
128+
dynamic::Entries::from_ffi(self.ptr.as_mut().unwrap().add_dynamic_entry(entry.as_base()))
129+
}
130+
121131
/// Return an iterator over the dynamic [`crate::elf::Symbol`] of the binary
122132
pub fn dynamic_symbols(&self) -> DynamicSymbols {
123133
DynamicSymbols::new(self.ptr.dynamic_symbols())

api/rust/cargo/lief/src/elf/dynamic.rs

+8
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,14 @@ impl Flags<'_> {
832832
pub fn flags(&self) -> DtFlags {
833833
DtFlags::from(self.ptr.flags())
834834
}
835+
836+
pub fn create_dt_flag(value: u64) -> Self {
837+
Self::from_ffi(ffi::ELF_DynamicEntryFlags::create_dt_flag(value))
838+
}
839+
840+
pub fn create_dt_flag_1(value: u64) -> Self {
841+
Self::from_ffi(ffi::ELF_DynamicEntryFlags::create_dt_flag_1(value))
842+
}
835843
}
836844

837845
impl FromFFI<ffi::ELF_DynamicEntryFlags> for Flags<'_> {

api/rust/include/LIEF/rust/ELF/Binary.hpp

+8
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ class ELF_Binary : public AbstractBinary {
242242
return std::make_unique<it_dynamic_entries>(impl());
243243
}
244244

245+
void remove_dynamic_entries_by_tag(uint64_t tag) {
246+
impl().remove(LIEF::ELF::DynamicEntry::TAG(tag));
247+
}
248+
249+
auto add_dynamic_entry(const ELF_DynamicEntry& entry) {
250+
return std::make_unique<ELF_DynamicEntry>(impl().add(entry.get()));
251+
}
252+
245253
auto dynamic_symbols() const {
246254
return std::make_unique<it_dynamic_symbols>(impl());
247255
}

api/rust/include/LIEF/rust/ELF/DynamicEntryFlags.hpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
class ELF_DynamicEntryFlags : public ELF_DynamicEntry {
2020
public:
2121
using lief_t = LIEF::ELF::DynamicEntryFlags;
22-
22+
ELF_DynamicEntryFlags(const lief_t& impl) :
23+
ELF_DynamicEntry(impl.clone())
24+
{}
2325
auto flags() const {
2426
return impl().raw_flags();
2527
}
@@ -28,6 +30,14 @@ class ELF_DynamicEntryFlags : public ELF_DynamicEntry {
2830
return lief_t::classof(&entry.get());
2931
}
3032

33+
static auto create_dt_flag(uint64_t value) {
34+
return std::make_unique<ELF_DynamicEntryFlags>(lief_t::create_dt_flag(value));
35+
}
36+
37+
static auto create_dt_flag_1(uint64_t value) {
38+
return std::make_unique<ELF_DynamicEntryFlags>(lief_t::create_dt_flag_1(value));
39+
}
40+
3141
private:
3242
const lief_t& impl() const { return as<lief_t>(this); }
3343
};

0 commit comments

Comments
 (0)