/* Copyright 2017 - 2021 R. Thomas * Copyright 2017 - 2021 Quarkslab * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "pyPE.hpp" #include "LIEF/PE/hash.hpp" #include "LIEF/Abstract/Section.hpp" #include "LIEF/PE/Section.hpp" #include #include namespace LIEF { namespace PE { template using getter_t = T (Section::*)(void) const; template using setter_t = void (Section::*)(T); template<> void create
(py::module& m) { py::class_(m, "Section") .def(py::init<>()) .def(py::init&, const std::string&, uint32_t>(), "Constructor from " ":attr:`~lief.PE.Section.content`, " ":attr:`~lief.PE.Section.name` and " ":attr:`~lief.PE.Section.characteristics`", "content"_a, py::arg("name") = "", py::arg("characteristics") = 0) .def(py::init(), "Constructor from " ":attr:`~lief.PE.Section.name`", "name"_a) .def_property("virtual_size", static_cast>(&Section::virtual_size), static_cast>(&Section::virtual_size), "The total size of the section when loaded into " "memory. If this value is greater than " ":attr:`~lief.PE.Section.sizeof_raw_data`, the section is zero-padded. ") .def_property("sizeof_raw_data", static_cast>(&Section::sizeof_raw_data), static_cast>(&Section::sizeof_raw_data), "Alias of :attr:`~lief.PE.Section.size`") .def_property("pointerto_raw_data", static_cast>(&Section::pointerto_raw_data), static_cast>(&Section::pointerto_raw_data), "Alias of :attr:`~lief.PE.Section.offset`") .def_property("pointerto_relocation", static_cast>(&Section::pointerto_relocation), static_cast>(&Section::pointerto_relocation), "The file pointer to the beginning of relocation " "entries for the section. This is set to zero for " "executable images or if there are no " "relocations.") .def_property("pointerto_line_numbers", static_cast>(&Section::pointerto_line_numbers), static_cast>(&Section::pointerto_line_numbers), "The file pointer to the beginning of line-number " "entries for the section. This is set to zero if " "there are no COFF line numbers. This value " "should be zero for an image because COFF " "debugging information is deprecated.") .def_property("numberof_relocations", static_cast>(&Section::numberof_relocations), static_cast>(&Section::numberof_relocations), "The number of relocation entries for the section. " "This is set to zero for executable images.") .def_property("numberof_line_numbers", static_cast>(&Section::numberof_line_numbers), static_cast>(&Section::numberof_line_numbers), "The number of line-number entries for the " "section. This value should be zero for an image " "because COFF debugging information is " "deprecated.") .def_property("characteristics", static_cast>(&Section::characteristics), static_cast>(&Section::characteristics), "The " RST_CLASS_REF(lief.PE.SECTION_CHARACTERISTICS) " that describe the characteristics of the section") .def_property_readonly("characteristics_lists", &Section::characteristics_list, ":attr:`~lief.PE.Section.characteristics` as a ``list``") .def_property_readonly("fullname", &Section::fullname, "Return the **fullname** of the section including the trailing bytes") .def("has_characteristic", &Section::has_characteristic, "``True`` if the a section has the given " RST_CLASS_REF(lief.PE.SECTION_CHARACTERISTICS) "", "characteristic"_a) .def_property_readonly("padding", [] (const Section& sec) { const std::vector& data = sec.padding(); return py::bytes(reinterpret_cast(data.data()), data.size()); }, "Section padding content as bytes") .def("__eq__", &Section::operator==) .def("__ne__", &Section::operator!=) .def("__hash__", [] (const Section& section) { return Hash::hash(section); }) .def("__str__", [] (const Section& section) { std::ostringstream stream; stream << section; std::string str = stream.str(); return str; }); } } }