/* 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/PE/resources/ResourceIcon.hpp" #include #include namespace LIEF { namespace PE { template using getter_t = T (ResourceIcon::*)(void) const; template using setter_t = void (ResourceIcon::*)(T); template<> void create(py::module& m) { py::class_(m, "ResourceIcon") .def(py::init(), "Constructor that takes a icon path as input", "icon_path"_a) .def_property("id", static_cast>(&ResourceIcon::id), static_cast>(&ResourceIcon::id), "Id associated with the icon") .def_property("lang", static_cast>(&ResourceIcon::lang), static_cast>(&ResourceIcon::lang), "Language (" RST_CLASS_REF(lief.PE.RESOURCE_LANGS) ") associated with the icon") .def_property("sublang", static_cast>(&ResourceIcon::sublang), static_cast>(&ResourceIcon::sublang), "Sub language (" RST_CLASS_REF(lief.PE.RESOURCE_SUBLANGS) ") associated with the icon") .def_property("width", static_cast>(&ResourceIcon::width), static_cast>(&ResourceIcon::width), "Width in pixels of the image") .def_property("height", static_cast>(&ResourceIcon::height), static_cast>(&ResourceIcon::height), "Height in pixels of the image") .def_property("color_count", static_cast>(&ResourceIcon::color_count), static_cast>(&ResourceIcon::color_count), "Number of colors in image (0 if >=8bpp)") .def_property("reserved", static_cast>(&ResourceIcon::reserved), static_cast>(&ResourceIcon::reserved), "Reserved (must be 0)") .def_property("planes", static_cast>(&ResourceIcon::planes), static_cast>(&ResourceIcon::planes), "Color Planes") .def_property("bit_count", static_cast>(&ResourceIcon::bit_count), static_cast>(&ResourceIcon::bit_count), "Bits per pixel") .def_property("pixels", static_cast&>>(&ResourceIcon::pixels), static_cast&>>(&ResourceIcon::pixels)) .def("save", &ResourceIcon::save, "Save the icon to the given filepath", "filepath"_a) .def("__eq__", &ResourceIcon::operator==) .def("__ne__", &ResourceIcon::operator!=) .def("__hash__", [] (const ResourceIcon& icon) { return Hash::hash(icon); }) .def("__str__", [] (const ResourceIcon& icon) { std::ostringstream stream; stream << icon; std::string str = stream.str(); return str; }); } } }