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
22#include "LIEF/visibility.h"
23#include "LIEF/span.hpp"
24
26#include "LIEF/MachO/Header.hpp"
27
28namespace LIEF {
29namespace MachO {
30
31class BinaryParser;
32
33namespace details {
34struct thread_command;
35}
36
44 friend class BinaryParser;
45
46 public:
47 ThreadCommand() = default;
48 ThreadCommand(const details::thread_command& cmd,
50 ThreadCommand(uint32_t flavor, uint32_t count,
52
53 ThreadCommand& operator=(const ThreadCommand& copy) = default;
54 ThreadCommand(const ThreadCommand& copy) = default;
55
56 std::unique_ptr<LoadCommand> clone() const override {
57 return std::unique_ptr<ThreadCommand>(new ThreadCommand(*this));
58 }
59
60 ~ThreadCommand() override = default;
61
68 uint32_t flavor() const {
69 return flavor_;
70 }
71
75 uint32_t count() const {
76 return count_;
77 }
78
81 return architecture_;
82 }
83
88 return state_;
89 }
90
92 return state_;
93 }
94
99 uint64_t pc() const;
100
101 void state(std::vector<uint8_t> state) {
102 state_ = std::move(state);
103 }
104
105 void flavor(uint32_t flavor) {
106 flavor_ = flavor;
107 }
108 void count(uint32_t count) {
109 count_ = count;
110 }
112 architecture_ = arch;
113 }
114
115 void accept(Visitor& visitor) const override;
116
117 std::ostream& print(std::ostream& os) const override;
118
119 static bool classof(const LoadCommand* cmd) {
120 const LoadCommand::TYPE type = cmd->command();
121 return type == LoadCommand::TYPE::THREAD ||
123 }
124
125 private:
126 uint32_t flavor_ = 0;
127 uint32_t count_ = 0;
129 std::vector<uint8_t> state_;
130};
131
132}
133}
134#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:130
TYPE
Definition LoadCommand.hpp:46
@ THREAD
Definition LoadCommand.hpp:51
@ UNIXTHREAD
Definition LoadCommand.hpp:52
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:87
ThreadCommand(const ThreadCommand &copy)=default
void count(uint32_t count)
Definition ThreadCommand.hpp:108
void accept(Visitor &visitor) const override
friend class BinaryParser
Definition ThreadCommand.hpp:44
std::ostream & print(std::ostream &os) const override
static bool classof(const LoadCommand *cmd)
Definition ThreadCommand.hpp:119
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:101
void flavor(uint32_t flavor)
Definition ThreadCommand.hpp:105
ThreadCommand(const details::thread_command &cmd, Header::CPU_TYPE arch=Header::CPU_TYPE::ANY)
void architecture(Header::CPU_TYPE arch)
Definition ThreadCommand.hpp:111
ThreadCommand & operator=(const ThreadCommand &copy)=default
span< uint8_t > state()
Definition ThreadCommand.hpp:91
~ThreadCommand() override=default
Header::CPU_TYPE architecture() const
The CPU architecture that is targeted by this ThreadCommand.
Definition ThreadCommand.hpp:80
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:75
std::unique_ptr< LoadCommand > clone() const override
Definition ThreadCommand.hpp:56
uint32_t flavor() const
Integer that defines a special flavor for the thread.
Definition ThreadCommand.hpp:68
Definition Visitor.hpp:212
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
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:41
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:45