/* Copyright 2017 - 2022 R. Thomas * Copyright 2017 - 2022 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 #include "pyAbstract.hpp" #include "LIEF/Abstract/Section.hpp" namespace LIEF { 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", R"delim( Class which represents an abstracted section )delim") .def(py::init(), "Default constructor") .def(py::init(), "Constructor from section name", "name"_a) .def_property("name", [] (const Section& obj) { return safe_string_converter(obj.name()); }, static_cast>(&Section::name), "Section's name") .def_property_readonly("fullname", &Section::fullname, "Return the **fullname** of the section including the trailing bytes") .def_property("size", static_cast>(&Section::size), static_cast>(&Section::size), "Section's size") .def_property("offset", static_cast>(&Section::offset), static_cast>(&Section::offset), "Section's file offset") .def_property("virtual_address", static_cast>(&Section::virtual_address), static_cast>(&Section::virtual_address), "Section's virtual address") .def_property("content", [] (const Section& self) { span content = self.content(); return py::memoryview::from_memory(content.data(), content.size()); }, static_cast&>>(&Section::content), "Section's content") .def_property_readonly("entropy", &Section::entropy, "Section's entropy") .def("search", static_cast(&Section::search), "Look for **integer** within the current section", "number"_a, "pos"_a = 0, "size"_a = 0) .def("search", static_cast(&Section::search), "Look for **string** within the current section", "str"_a, "pos"_a = 0) .def("search_all", static_cast (Section::*)(uint64_t, size_t) const>(&Section::search_all), "Look for **all** integers within the current section", "number"_a, "size"_a = 0) .def("search_all", static_cast (Section::*)(const std::string&) const>(&Section::search_all), "Look for all **strings** within the current section", "str"_a) .def("__str__", [] (const Section& section) { std::ostringstream stream; stream << section; std::string str = stream.str(); return str; }); } }