LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
ThreadCommand.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 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_THREAD_COMMAND_H
17#define LIEF_MACHO_THREAD_COMMAND_H
18#include <vector>
19#include <ostream>
20
21#include "LIEF/visibility.h"
22#include "LIEF/span.hpp"
23
25#include "LIEF/MachO/Header.hpp"
26
27namespace LIEF {
28namespace MachO {
29
30class BinaryParser;
31
32namespace details {
33struct thread_command;
34}
35
43 friend class BinaryParser;
44
45 public:
46 ThreadCommand() = default;
47 ThreadCommand(const details::thread_command& cmd,
49 ThreadCommand(uint32_t flavor, uint32_t count,
51
52 ThreadCommand& operator=(const ThreadCommand& copy) = default;
53 ThreadCommand(const ThreadCommand& copy) = default;
54
55 std::unique_ptr<LoadCommand> clone() const override {
56 return std::unique_ptr<ThreadCommand>(new ThreadCommand(*this));
57 }
58
59 ~ThreadCommand() override = default;
60
67 uint32_t flavor() const {
68 return flavor_;
69 }
70
74 uint32_t count() const {
75 return count_;
76 }
77
80 return architecture_;
81 }
82
87 return state_;
88 }
89
91 return state_;
92 }
93
98 uint64_t pc() const;
99
100 void state(std::vector<uint8_t> state) {
101 state_ = std::move(state);
102 }
103
104 void flavor(uint32_t flavor) {
105 flavor_ = flavor;
106 }
107 void count(uint32_t count) {
108 count_ = count;
109 }
111 architecture_ = arch;
112 }
113
114 void accept(Visitor& visitor) const override;
115
116 std::ostream& print(std::ostream& os) const override;
117
118 static bool classof(const LoadCommand* cmd) {
119 const LoadCommand::TYPE type = cmd->command();
120 return type == LoadCommand::TYPE::THREAD ||
122 }
123
124 private:
125 uint32_t flavor_ = 0;
126 uint32_t count_ = 0;
128 std::vector<uint8_t> state_;
129};
130
131}
132}
133#endif
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:78
CPU_TYPE
Definition MachO/Header.hpp:107
@ ANY
Definition MachO/Header.hpp:108
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:128
TYPE
Definition LoadCommand.hpp:45
@ THREAD
Definition LoadCommand.hpp:50
@ UNIXTHREAD
Definition LoadCommand.hpp:51
span< const uint8_t > state() const
The actual thread state as a vector of bytes. Depending on the architecture(), these data can be cast...
Definition ThreadCommand.hpp:86
ThreadCommand(const ThreadCommand &copy)=default
void count(uint32_t count)
Definition ThreadCommand.hpp:107
void accept(Visitor &visitor) const override
friend class BinaryParser
Definition ThreadCommand.hpp:43
std::ostream & print(std::ostream &os) const override
static bool classof(const LoadCommand *cmd)
Definition ThreadCommand.hpp:118
ThreadCommand(uint32_t flavor, uint32_t count, Header::CPU_TYPE arch=Header::CPU_TYPE::ANY)
void state(std::vector< uint8_t > state)
Definition ThreadCommand.hpp:100
void flavor(uint32_t flavor)
Definition ThreadCommand.hpp:104
ThreadCommand(const details::thread_command &cmd, Header::CPU_TYPE arch=Header::CPU_TYPE::ANY)
void architecture(Header::CPU_TYPE arch)
Definition ThreadCommand.hpp:110
ThreadCommand & operator=(const ThreadCommand &copy)=default
span< uint8_t > state()
Definition ThreadCommand.hpp:90
~ThreadCommand() override=default
Header::CPU_TYPE architecture() const
The CPU architecture that is targeted by this ThreadCommand.
Definition ThreadCommand.hpp:79
uint64_t pc() const
Return the initial Program Counter regardless of the underlying architecture. This value,...
uint32_t count() const
Size of the thread state data with 32-bits alignment.
Definition ThreadCommand.hpp:74
std::unique_ptr< LoadCommand > clone() const override
Definition ThreadCommand.hpp:55
uint32_t flavor() const
Integer that defines a special flavor for the thread.
Definition ThreadCommand.hpp:67
Definition Visitor.hpp:212
Definition endianness_support.hpp:60
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF namespace.
Definition Abstract/Binary.hpp:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:43