Skip to content

Commit 918438c

Browse files
committed
Enable to remove sections using the abstract layer
1 parent 6134129 commit 918438c

File tree

18 files changed

+200
-20
lines changed

18 files changed

+200
-20
lines changed

api/python/Abstract/objects/pyBinary.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ void init_LIEF_Binary_class(py::module& m) {
7171
&Binary::entrypoint,
7272
"Binary's entrypoint")
7373

74+
.def("remove_section",
75+
static_cast<void (Binary::*)(const std::string&, bool)>(&Binary::remove_section),
76+
"Remove the section with the given name",
77+
"name"_a, "clear"_a = false)
78+
7479
.def_property_readonly("sections",
7580
static_cast<it_t<it_sections>>(&Binary::sections),
7681
"Return a list in **read only** of binary's abstract " RST_CLASS_REF(lief.Section) "",

api/python/ELF/objects/pyBinary.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,6 @@ void create<Binary>(py::module& m) {
403403
"Remove the given library",
404404
"library_name"_a)
405405

406-
.def("remove_section",
407-
&Binary::remove_section,
408-
"Remove the given section from its name",
409-
"section_name"_a, "clear"_a = false)
410-
411406
.def("get_library",
412407
static_cast<no_const_func<DynamicEntryLibrary&, const std::string&>>(&Binary::get_library),
413408
"Return the " RST_CLASS_REF(lief.ELF.DynamicEntryLibrary) " with the given ``name``",

api/python/MachO/objects/pySection.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ void create<Section>(py::module& m) {
9797
static_cast<getter_t<Section::flag_list_t>>(&Section::flags_list),
9898
py::return_value_policy::reference_internal)
9999

100+
.def_property_readonly("segment",
101+
static_cast<SegmentCommand& (Section::*)(void)>(&Section::segment),
102+
"" RST_CLASS_REF(lief.MachO.SegmentCommand) " segment associated with the section",
103+
py::return_value_policy::reference)
104+
105+
.def_property_readonly("has_segment",
106+
&Section::has_segment,
107+
"True if the current section has a segment associated with")
108+
100109
.def("has",
101110
static_cast<bool(Section::*)(MACHO_SECTION_FLAGS) const>(&Section::has),
102111
"Check if the section has the given " RST_CLASS_REF(lief.MachO.SECTION_FLAGS) "",

api/python/PE/objects/pyBinary.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ void create<Binary>(py::module& m) {
178178
"section"_a, py::arg("type") = PE_SECTION_TYPES::UNKNOWN,
179179
py::return_value_policy::reference)
180180

181-
//.def("delete_section", (void (Binary::*)(const std::string&)) &Binary::delete_section)
182181
//.def("get_import_section",
183182
// static_cast<no_const_getter<Section&>>(&Binary::get_import_section),
184183
// py::return_value_policy::reference_internal)

include/LIEF/Abstract/Binary.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class LIEF_API Binary : public Object {
7777
it_sections sections(void);
7878
it_const_sections sections(void) const;
7979

80+
virtual void remove_section(const std::string& name, bool clear = false) = 0;
81+
8082
//! @brief Returns binary's relocations
8183
it_relocations relocations(void);
8284
it_const_relocations relocations(void) const;

include/LIEF/ELF/Binary.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ class LIEF_API Binary : public LIEF::Binary {
374374
//!
375375
//! We clear data used by this section and it's removed from
376376
//! section table
377-
void remove_section(const std::string& name, bool clear = false);
377+
virtual void remove_section(const std::string& name, bool clear = false) override;
378378

379379
//! @brief Reconstruct the binary object and write it in `filename`
380380
//! @param filename Path to write the reconstructed binary

include/LIEF/MachO/Binary.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ class LIEF_API Binary : public LIEF::Binary {
154154
//! or the last one
155155
Section* add_section(const SegmentCommand& segment, const Section& section);
156156

157+
virtual void remove_section(const std::string& name, bool clear = false) override;
158+
157159
//! Remove the given command
158160
bool remove(const LoadCommand& command);
159161

include/LIEF/MachO/Section.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ class LIEF_API Section : public LIEF::Section {
8686
flag_list_t flags_list(void) const;
8787
uint32_t raw_flags(void) const;
8888

89+
bool has_segment(void) const;
90+
SegmentCommand& segment(void);
91+
const SegmentCommand& segment(void) const;
92+
93+
void clear(uint8_t v);
94+
8995
it_relocations relocations(void);
9096
it_const_relocations relocations(void) const;
9197

include/LIEF/PE/Binary.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class LIEF_API Binary : public LIEF::Binary {
200200
//! @brief Delete the section with the given name
201201
//!
202202
//! @param[in] name Name of section to delete
203-
void delete_section(const std::string& name);
203+
virtual void remove_section(const std::string& name, bool clear = false) override;
204204

205205
//! @brief Add a section to the binary and return the section added.
206206
Section& add_section(

include/LIEF/PE/Section.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class LIEF_API Section : public LIEF::Section {
7373
const std::set<PE_SECTION_TYPES>& types(void) const;
7474
bool has_characteristic(SECTION_CHARACTERISTICS c) const;
7575
std::set<SECTION_CHARACTERISTICS> characteristics_list(void) const;
76+
void clear(uint8_t c);
7677

7778

7879
virtual void name(const std::string& name) override;

0 commit comments

Comments
 (0)