/* 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/DosHeader.hpp" #include #include namespace LIEF { namespace PE { template using getter_abs_t = T (DosHeader::*)(void) const; template using setter_abs_t = void (DosHeader::*)(T); using getter_t = getter_abs_t; using setter_t = setter_abs_t; template<> void create(py::module& m) { py::class_(m, "DosHeader") .def(py::init<>()) .def_property("magic", static_cast(&DosHeader::magic), static_cast(&DosHeader::magic)) .def_property("used_bytes_in_the_last_page", static_cast(&DosHeader::used_bytes_in_the_last_page), static_cast(&DosHeader::used_bytes_in_the_last_page)) .def_property("file_size_in_pages", static_cast(&DosHeader::file_size_in_pages), static_cast(&DosHeader::file_size_in_pages)) .def_property("numberof_relocation", static_cast(&DosHeader::numberof_relocation), static_cast(&DosHeader::numberof_relocation)) .def_property("header_size_in_paragraphs", static_cast(&DosHeader::header_size_in_paragraphs), static_cast(&DosHeader::header_size_in_paragraphs)) .def_property("minimum_extra_paragraphs", static_cast(&DosHeader::minimum_extra_paragraphs), static_cast(&DosHeader::minimum_extra_paragraphs)) .def_property("maximum_extra_paragraphs", static_cast(&DosHeader::maximum_extra_paragraphs), static_cast(&DosHeader::maximum_extra_paragraphs)) .def_property("initial_relative_ss", static_cast(&DosHeader::initial_relative_ss), static_cast(&DosHeader::initial_relative_ss)) .def_property("initial_sp", static_cast(&DosHeader::initial_sp), static_cast(&DosHeader::initial_sp)) .def_property("checksum", static_cast(&DosHeader::checksum), static_cast(&DosHeader::checksum)) .def_property("initial_ip", static_cast(&DosHeader::initial_ip), static_cast(&DosHeader::initial_ip)) .def_property("initial_relative_cs", static_cast(&DosHeader::initial_relative_cs), static_cast(&DosHeader::initial_relative_cs)) .def_property("addressof_relocation_table", static_cast(&DosHeader::addressof_relocation_table), static_cast(&DosHeader::addressof_relocation_table)) .def_property("overlay_number", static_cast(&DosHeader::overlay_number), static_cast(&DosHeader::overlay_number)) .def_property("oem_id", static_cast(&DosHeader::oem_id), static_cast(&DosHeader::oem_id)) .def_property("oem_info", static_cast(&DosHeader::oem_info), static_cast(&DosHeader::oem_info)) .def_property("addressof_new_exeheader", static_cast>(&DosHeader::addressof_new_exeheader), static_cast>(&DosHeader::addressof_new_exeheader)) .def("__eq__", &DosHeader::operator==) .def("__ne__", &DosHeader::operator!=) .def("__hash__", [] (const DosHeader& dos_header) { return Hash::hash(dos_header); }) .def("__str__", [] (const DosHeader& header) { std::ostringstream stream; stream << header; std::string str = stream.str(); return str; }); } } }