|
| 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/ThreadCommand.hpp" |
| 23 | + |
| 24 | +#include "pyMachO.hpp" |
| 25 | + |
| 26 | +template<class T> |
| 27 | +using getter_t = T (ThreadCommand::*)(void) const; |
| 28 | + |
| 29 | +template<class T> |
| 30 | +using setter_t = void (ThreadCommand::*)(T); |
| 31 | + |
| 32 | + |
| 33 | +void init_MachO_ThreadCommand_class(py::module& m) { |
| 34 | + |
| 35 | + py::class_<ThreadCommand, LoadCommand>(m, "ThreadCommand") |
| 36 | + |
| 37 | + .def_property("flavor", |
| 38 | + static_cast<getter_t<uint32_t>>(&ThreadCommand::flavor), |
| 39 | + static_cast<setter_t<uint32_t>>(&ThreadCommand::flavor), |
| 40 | + "", |
| 41 | + py::return_value_policy::reference_internal) |
| 42 | + |
| 43 | + |
| 44 | + .def_property("state", |
| 45 | + static_cast<getter_t<const std::vector<uint8_t>&>>(&ThreadCommand::state), |
| 46 | + static_cast<setter_t<const std::vector<uint8_t>&>>(&ThreadCommand::state), |
| 47 | + "", |
| 48 | + py::return_value_policy::reference_internal) |
| 49 | + |
| 50 | + |
| 51 | + .def_property("count", |
| 52 | + static_cast<getter_t<uint32_t>>(&ThreadCommand::count), |
| 53 | + static_cast<setter_t<uint32_t>>(&ThreadCommand::count), |
| 54 | + "", |
| 55 | + py::return_value_policy::reference_internal) |
| 56 | + |
| 57 | + .def_property_readonly("pc", |
| 58 | + static_cast<getter_t<uint64_t>>(&ThreadCommand::pc), |
| 59 | + py::return_value_policy::reference_internal) |
| 60 | + |
| 61 | + .def("__eq__", &ThreadCommand::operator==) |
| 62 | + .def("__ne__", &ThreadCommand::operator!=) |
| 63 | + .def("__hash__", |
| 64 | + [] (const ThreadCommand& thread) { |
| 65 | + return LIEF::Hash::hash(thread); |
| 66 | + }) |
| 67 | + |
| 68 | + |
| 69 | + .def("__str__", |
| 70 | + [] (const ThreadCommand& thread) |
| 71 | + { |
| 72 | + std::ostringstream stream; |
| 73 | + stream << thread; |
| 74 | + std::string str = stream.str(); |
| 75 | + return str; |
| 76 | + }); |
| 77 | + |
| 78 | +} |
0 commit comments