LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
MainCommand.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_MAIN_COMMAND_H
17#define LIEF_MACHO_MAIN_COMMAND_H
18#include <ostream>
19
20#include "LIEF/visibility.h"
21
22#include "LIEF/MachO/enums.hpp"
23#include "LIEF/MachO/LoadCommand.hpp"
24
25namespace LIEF {
26namespace MachO {
27
28namespace details {
29struct entry_point_command;
30}
31
34class LIEF_API MainCommand : public LoadCommand {
35 public:
36 MainCommand() = default;
37 MainCommand(const details::entry_point_command& cmd);
38 MainCommand(uint64_t entrypoint, uint64_t stacksize);
39
40 MainCommand& operator=(const MainCommand& copy) = default;
41 MainCommand(const MainCommand& copy) = default;
42
43 std::unique_ptr<LoadCommand> clone() const override {
44 return std::unique_ptr<MainCommand>(new MainCommand(*this));
45 }
46
47 ~MainCommand() override = default;
48
51 uint64_t entrypoint() const {
52 return entrypoint_;
53 }
54
56 uint64_t stack_size() const {
57 return stack_size_;
58 }
59
60 void entrypoint(uint64_t entrypoint) {
61 entrypoint_ = entrypoint;
62 }
63 void stack_size(uint64_t stacksize) {
64 stack_size_ = stacksize;
65 }
66
67 std::ostream& print(std::ostream& os) const override;
68
69 void accept(Visitor& visitor) const override;
70
71 static bool classof(const LoadCommand* cmd) {
72 return cmd->command() == LoadCommand::TYPE::MAIN;
73 }
74
75 private:
76 uint64_t entrypoint_ = 0;
77 uint64_t stack_size_ = 0;
78};
79
80}
81}
82#endif
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:36
Class that represent the LC_MAIN command. This kind of command can be used to determine the entrypoin...
Definition MainCommand.hpp:34
uint64_t entrypoint() const
Offset of the main function relative to the __TEXT segment.
Definition MainCommand.hpp:51
uint64_t stack_size() const
The initial stack size (if not 0)
Definition MainCommand.hpp:56
LIEF namespace.
Definition Abstract/Binary.hpp:32