|
| 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/MachO/hash.hpp" |
| 22 | +#include "LIEF/MachO/BuildVersion.hpp" |
| 23 | +#include "LIEF/MachO/EnumToString.hpp" |
| 24 | + |
| 25 | +#include "enums_wrapper.hpp" |
| 26 | + |
| 27 | +#include "pyMachO.hpp" |
| 28 | + |
| 29 | +#define PY_ENUM(x) LIEF::MachO::to_string(x), x |
| 30 | + |
| 31 | +namespace LIEF { |
| 32 | +namespace MachO { |
| 33 | + |
| 34 | +template<class T> |
| 35 | +using getter_t = T (BuildVersion::*)(void) const; |
| 36 | + |
| 37 | +template<class T> |
| 38 | +using setter_t = void (BuildVersion::*)(T); |
| 39 | + |
| 40 | + |
| 41 | +template<> |
| 42 | +void create<BuildVersion>(py::module& m) { |
| 43 | + |
| 44 | + py::class_<BuildVersion, LoadCommand> cls(m, "BuildVersion"); |
| 45 | + py::class_<BuildToolVersion, LIEF::Object> tool_version_cls(m, "BuildToolVersion"); |
| 46 | + |
| 47 | + |
| 48 | + // Build Tool Version |
| 49 | + // ================== |
| 50 | + tool_version_cls |
| 51 | + .def_property_readonly("tool", |
| 52 | + &BuildToolVersion::tool, |
| 53 | + "" RST_CLASS_REF(.BuildeVersion.TOOLS) " type") |
| 54 | + |
| 55 | + .def_property_readonly("version", |
| 56 | + &BuildToolVersion::version, |
| 57 | + "Version of the tool") |
| 58 | + |
| 59 | + .def("__eq__", &BuildToolVersion::operator==) |
| 60 | + .def("__ne__", &BuildToolVersion::operator!=) |
| 61 | + .def("__hash__", |
| 62 | + [] (const BuildToolVersion& version) { |
| 63 | + return Hash::hash(version); |
| 64 | + }) |
| 65 | + |
| 66 | + .def("__str__", |
| 67 | + [] (const BuildToolVersion& version) |
| 68 | + { |
| 69 | + std::ostringstream stream; |
| 70 | + stream << version; |
| 71 | + return stream.str(); |
| 72 | + }); |
| 73 | + |
| 74 | + |
| 75 | + LIEF::enum_<BuildToolVersion::TOOLS>(tool_version_cls, "TOOLS") |
| 76 | + .value(PY_ENUM(BuildToolVersion::TOOLS::UNKNOWN)) |
| 77 | + .value(PY_ENUM(BuildToolVersion::TOOLS::CLANG)) |
| 78 | + .value(PY_ENUM(BuildToolVersion::TOOLS::SWIFT)) |
| 79 | + .value(PY_ENUM(BuildToolVersion::TOOLS::LD)); |
| 80 | + |
| 81 | + cls |
| 82 | + |
| 83 | + .def_property("platform", |
| 84 | + static_cast<getter_t<BuildVersion::PLATFORMS>>(&BuildVersion::platform), |
| 85 | + static_cast<setter_t<BuildVersion::PLATFORMS>>(&BuildVersion::platform), |
| 86 | + "Target " RST_CLASS_REF(.BuildVersion.PLATFORMS) "") |
| 87 | + |
| 88 | + .def_property("minos", |
| 89 | + static_cast<getter_t<BuildVersion::version_t>>(&BuildVersion::minos), |
| 90 | + static_cast<setter_t<BuildVersion::version_t>>(&BuildVersion::minos), |
| 91 | + "Minimal OS version on which this binary was built to run") |
| 92 | + |
| 93 | + .def_property("sdk", |
| 94 | + static_cast<getter_t<BuildVersion::version_t>>(&BuildVersion::minos), |
| 95 | + static_cast<setter_t<BuildVersion::version_t>>(&BuildVersion::minos), |
| 96 | + "SDK Version") |
| 97 | + |
| 98 | + .def_property_readonly("tools", |
| 99 | + static_cast<getter_t<BuildVersion::tools_list_t>>(&BuildVersion::tools), |
| 100 | + "List of " RST_CLASS_REF(BuildToolVersion) " used when while this binary") |
| 101 | + |
| 102 | + .def("__eq__", &BuildVersion::operator==) |
| 103 | + .def("__ne__", &BuildVersion::operator!=) |
| 104 | + .def("__hash__", |
| 105 | + [] (const BuildVersion& version) { |
| 106 | + return Hash::hash(version); |
| 107 | + }) |
| 108 | + |
| 109 | + .def("__str__", |
| 110 | + [] (const BuildVersion& version) |
| 111 | + { |
| 112 | + std::ostringstream stream; |
| 113 | + stream << version; |
| 114 | + return stream.str(); |
| 115 | + }); |
| 116 | + |
| 117 | + |
| 118 | + LIEF::enum_<BuildVersion::PLATFORMS>(cls, "PLATFORMS") |
| 119 | + .value(PY_ENUM(BuildVersion::PLATFORMS::UNKNOWN)) |
| 120 | + .value(PY_ENUM(BuildVersion::PLATFORMS::MACOS)) |
| 121 | + .value(PY_ENUM(BuildVersion::PLATFORMS::IOS)) |
| 122 | + .value(PY_ENUM(BuildVersion::PLATFORMS::TVOS)) |
| 123 | + .value(PY_ENUM(BuildVersion::PLATFORMS::WATCHOS)); |
| 124 | + |
| 125 | +} |
| 126 | + |
| 127 | +} |
| 128 | +} |
0 commit comments