LIEF: Library to Instrument Executable Formats Version 2.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 <memory>
19#include <ostream>
20#include <vector>
21
23#include "LIEF/span.hpp"
24#include "LIEF/visibility.h"
25
26#include "LIEF/MachO/Header.hpp"
28
29
30namespace LIEF::MachO {
31
32class BinaryParser;
33
34namespace details {
35struct thread_command;
36}
37
45 friend class BinaryParser;
46
47 public:
48 ThreadCommand() = default;
49 ThreadCommand(const details::thread_command& cmd,
51 ThreadCommand(uint32_t flavor, uint32_t count,
53
54 ThreadCommand& operator=(const ThreadCommand& copy) = default;
55 ThreadCommand(const ThreadCommand& copy) = default;
56
57 std::unique_ptr<LoadCommand> clone() const override {
58 return std::make_unique<ThreadCommand>(*this);
59 }
60
61 ~ThreadCommand() override = default;
62
69 uint32_t flavor() const {
70 return flavor_;
71 }
72
76 uint32_t count() const {
77 return count_;
78 }
79
82 return architecture_;
83 }
84
89 return state_;
90 }
91
93 return state_;
94 }
95
100 uint64_t pc() const;
101
102 void state(std::vector<uint8_t> state) {
103 state_ = std::move(state);
104 }
105
106 void flavor(uint32_t flavor) {
107 flavor_ = flavor;
108 }
109 void count(uint32_t count) {
110 count_ = count;
111 }
113 architecture_ = arch;
114 }
115
116 void accept(Visitor& visitor) const override;
117
118 std::ostream& print(std::ostream& os) const override;
119
120 static bool classof(const LoadCommand* cmd) {
121 const LoadCommand::TYPE type = cmd->command();
122 return type == LoadCommand::TYPE::THREAD ||
124 }
125
126 private:
127 uint32_t flavor_ = 0;
128 uint32_t count_ = 0;
130 std::vector<uint8_t> state_;
131};
132
133}
134
135#endif
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:79
CPU_TYPE
Definition MachO/Header.hpp:107
@ ANY
Definition MachO/Header.hpp:108
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:132
TYPE
Definition LoadCommand.hpp:47
@ THREAD
Definition LoadCommand.hpp:52
@ UNIXTHREAD
Definition LoadCommand.hpp:53
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:88
ThreadCommand(const ThreadCommand &copy)=default
void count(uint32_t count)
Definition ThreadCommand.hpp:109
void accept(Visitor &visitor) const override
friend class BinaryParser
Definition ThreadCommand.hpp:45
std::ostream & print(std::ostream &os) const override
static bool classof(const LoadCommand *cmd)
Definition ThreadCommand.hpp:120
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:102
void flavor(uint32_t flavor)
Definition ThreadCommand.hpp:106
ThreadCommand(const details::thread_command &cmd, Header::CPU_TYPE arch=Header::CPU_TYPE::ANY)
void architecture(Header::CPU_TYPE arch)
Definition ThreadCommand.hpp:112
ThreadCommand & operator=(const ThreadCommand &copy)=default
span< uint8_t > state()
Definition ThreadCommand.hpp:92
~ThreadCommand() override=default
Header::CPU_TYPE architecture() const
The CPU architecture that is targeted by this ThreadCommand.
Definition ThreadCommand.hpp:81
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:76
std::unique_ptr< LoadCommand > clone() const override
Definition ThreadCommand.hpp:57
uint32_t flavor() const
Integer that defines a special flavor for the thread.
Definition ThreadCommand.hpp:69
Definition Visitor.hpp:212
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition endianness_support.hpp:59
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:45