LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
BuildVersion.hpp
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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#ifndef LIEF_MACHO_BUILD_VERSION_COMMAND_H
17#define LIEF_MACHO_BUILD_VERSION_COMMAND_H
18#include <vector>
19#include <ostream>
20#include <array>
21
22#include "LIEF/visibility.h"
23
24#include "LIEF/MachO/LoadCommand.hpp"
25#include "LIEF/MachO/BuildToolVersion.hpp"
26
27namespace LIEF {
28namespace MachO {
29
30namespace details {
31struct build_version_command;
32}
33
34class LIEF_API BuildVersion : public LoadCommand {
35 friend class BinaryParser;
36
37 public:
39 using version_t = std::array<uint32_t, 3>;
40
41 using tools_list_t = std::vector<BuildToolVersion>;
42
43 public:
44 enum class PLATFORMS {
45 UNKNOWN = 0,
46 MACOS = 1,
47 IOS = 2,
48 TVOS = 3,
49 WATCHOS = 4,
50 };
51
52 public:
53 BuildVersion() = default;
54 BuildVersion(const details::build_version_command& version_cmd);
55 BuildVersion(const PLATFORMS platform,
56 const version_t &minos,
57 const version_t &sdk,
58 const tools_list_t &tools);
59
60 BuildVersion& operator=(const BuildVersion& copy) = default;
61 BuildVersion(const BuildVersion& copy) = default;
62
63 std::unique_ptr<LoadCommand> clone() const override {
64 return std::unique_ptr<BuildVersion>(new BuildVersion(*this));
65 }
66
67 version_t minos() const {
68 return minos_;
69 }
70
71 void minos(version_t version) {
72 minos_ = version;
73 }
74
75 version_t sdk() const {
76 return sdk_;
77 }
78 void sdk(version_t version) {
79 sdk_ = version;
80 }
81
82 PLATFORMS platform() const {
83 return platform_;
84 }
85 void platform(PLATFORMS plat) {
86 platform_ = plat;
87 }
88
89 const tools_list_t& tools() const {
90 return tools_;
91 }
92
93 ~BuildVersion() override = default;
94
95 void accept(Visitor& visitor) const override;
96
97 std::ostream& print(std::ostream& os) const override;
98
99 static bool classof(const LoadCommand* cmd) {
100 return cmd->command() == LoadCommand::TYPE::BUILD_VERSION;
101 }
102
103 private:
104 PLATFORMS platform_ = PLATFORMS::UNKNOWN;
105 version_t minos_;
106 version_t sdk_;
107 tools_list_t tools_;
108};
109
110LIEF_API const char* to_string(BuildVersion::PLATFORMS e);
111
112}
113}
114#endif
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:73
Definition BuildVersion.hpp:34
std::array< uint32_t, 3 > version_t
Version is an array of 3 integers.
Definition BuildVersion.hpp:39
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:36
art_version_t version(const std::string &file)
Return the ART version of the given file.
LIEF namespace.
Definition Abstract/Binary.hpp:32