Improve API of ELF's Section

API changes:
  - 'has_flag' renamed to 'has'
  - 'add_flag' renamed to 'add'
  - 'remove_flag' renamed to 'remove'
  - operator+= to add a flag - added
  - operator-= to remove a flag - added
  - 'has' for Segment object - added
This commit is contained in:
Romain Thomas
2017-08-02 08:19:26 +02:00
parent 4425292210
commit 43bd06f8f3
3 changed files with 78 additions and 16 deletions
+36 -5
View File
@@ -103,12 +103,30 @@ void init_ELF_Section_class(py::module& m) {
"Return segment(s) associated with the given section",
py::return_value_policy::reference_internal)
.def("__contains__",
[] (const Section &section, SECTION_FLAGS flag)
{
return section.has_flag(flag);
}, "Test if the current section has the given flag")
.def("add",
&Section::add,
"Add the given " RST_CLASS_REF(lief.ELF.SECTION_FLAGS) " to the list of "
":attr:`~lief.ELF.Section.flags`",
"flag"_a)
.def("remove",
&Section::remove,
"Remove the given " RST_CLASS_REF(lief.ELF.SECTION_FLAGS) " to the list of "
":attr:`~lief.ELF.Section.flags`",
"flag"_a)
.def("has",
static_cast<bool (Section::*)(SECTION_FLAGS) const>(&Section::has),
"Check if the given " RST_CLASS_REF(lief.ELF.SECTION_FLAGS) " is present",
"flag"_a)
.def("has",
static_cast<bool (Section::*)(const Segment&) const>(&Section::has),
"Check if the given " RST_CLASS_REF(lief.ELF.Segment) " is present "
"in :attr:`~lief.ELF.Section.segments`",
"segment"_a)
.def("__eq__", &Section::operator==)
.def("__ne__", &Section::operator!=)
@@ -117,6 +135,19 @@ void init_ELF_Section_class(py::module& m) {
return LIEF::Hash::hash(section);
})
.def(py::self += SECTION_FLAGS())
.def(py::self -= SECTION_FLAGS())
.def("__contains__",
static_cast<bool (Section::*)(SECTION_FLAGS) const>(&Section::has),
"Check if the given " RST_CLASS_REF(lief.ELF.SECTION_FLAGS) " is present")
.def("__contains__",
static_cast<bool (Section::*)(const Segment&) const>(&Section::has),
"Check if the given " RST_CLASS_REF(lief.ELF.Segment) " is present "
"in :attr:`~lief.ELF.Section.segments`")
.def("__str__",
[] (const Section& section)
{