|
| 1 | +/* Copyright 2017 R. Thomas |
| 2 | + * Copyright 2017 Quarkslab |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#include <algorithm> |
| 17 | + |
| 18 | +#include <string> |
| 19 | +#include <sstream> |
| 20 | + |
| 21 | +#include "LIEF/visitors/Hash.hpp" |
| 22 | +#include "LIEF/MachO/SourceVersion.hpp" |
| 23 | + |
| 24 | +#include "pyMachO.hpp" |
| 25 | + |
| 26 | +template<class T> |
| 27 | +using getter_t = T (SourceVersion::*)(void) const; |
| 28 | + |
| 29 | +template<class T> |
| 30 | +using setter_t = void (SourceVersion::*)(T); |
| 31 | + |
| 32 | + |
| 33 | +void init_MachO_SourceVersion_class(py::module& m) { |
| 34 | + |
| 35 | + py::class_<SourceVersion, LoadCommand>(m, "SourceVersion") |
| 36 | + |
| 37 | + .def_property("version", |
| 38 | + static_cast<getter_t<const version_t&>>(&SourceVersion::version), |
| 39 | + static_cast<setter_t<const version_t&>>(&SourceVersion::version), |
| 40 | + "TODO", |
| 41 | + py::return_value_policy::reference_internal) |
| 42 | + |
| 43 | + |
| 44 | + .def("__eq__", &SourceVersion::operator==) |
| 45 | + .def("__ne__", &SourceVersion::operator!=) |
| 46 | + .def("__hash__", |
| 47 | + [] (const SourceVersion& version) { |
| 48 | + return LIEF::Hash::hash(version); |
| 49 | + }) |
| 50 | + |
| 51 | + |
| 52 | + .def("__str__", |
| 53 | + [] (const SourceVersion& version) |
| 54 | + { |
| 55 | + std::ostringstream stream; |
| 56 | + stream << version; |
| 57 | + std::string str = stream.str(); |
| 58 | + return str; |
| 59 | + }); |
| 60 | + |
| 61 | +} |
0 commit comments