LIEF/api/python/PE/objects/pyDataDirectory.cpp

74 lines
2.5 KiB
C++
Raw Normal View History

2017-03-30 16:56:49 +02:00
/* Copyright 2017 R. Thomas
* Copyright 2017 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 <string>
#include <sstream>
#include "LIEF/visitors/Hash.hpp"
#include "LIEF/PE/DataDirectory.hpp"
#include "pyPE.hpp"
template<class T>
using getter_t = T (DataDirectory::*)(void) const;
template<class T>
using setter_t = void (DataDirectory::*)(T);
void init_PE_DataDirectory_class(py::module& m) {
py::class_<DataDirectory>(m, "DataDirectory")
.def(py::init<>())
.def_property("rva",
static_cast<getter_t<uint32_t>>(&DataDirectory::RVA),
2017-04-26 09:27:56 +02:00
static_cast<setter_t<uint32_t>>(&DataDirectory::RVA),
"**Relative** virtual address of the content associated with the current data directory")
2017-03-30 16:56:49 +02:00
.def_property("size",
static_cast<getter_t<uint32_t>>(&DataDirectory::size),
2017-04-26 09:27:56 +02:00
static_cast<setter_t<uint32_t>>(&DataDirectory::size),
"Size in bytes of the content associated with the current data directory")
2017-03-30 16:56:49 +02:00
.def_property_readonly("section",
static_cast<Section& (DataDirectory::*) (void)>(&DataDirectory::section),
2017-04-26 09:27:56 +02:00
"" RST_CLASS_REF(lief.PE.Section) " associated with the current data directory",
2017-03-30 16:56:49 +02:00
py::return_value_policy::reference)
.def_property_readonly("type",
&DataDirectory::type,
2017-04-26 09:27:56 +02:00
"Type (" RST_CLASS_REF(lief.PE.DATA_DIRECTORY) ") of the current data directory",
2017-03-30 16:56:49 +02:00
py::return_value_policy::reference_internal)
.def_property_readonly("has_section",
&DataDirectory::has_section,
2017-04-26 09:27:56 +02:00
"``True`` if the current data directory is tied to a " RST_CLASS_REF(lief.PE.Section) "")
2017-03-30 16:56:49 +02:00
.def("__eq__", &DataDirectory::operator==)
.def("__ne__", &DataDirectory::operator!=)
.def("__hash__",
[] (const DataDirectory& data_directory) {
return LIEF::Hash::hash(data_directory);
})
.def("__str__", [] (const DataDirectory& datadir)
{
std::ostringstream stream;
stream << datadir;
std::string str = stream.str();
return str;
});
}