LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
ThreadCommand.hpp
Go to the documentation of this file.
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_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}
35class LIEF_API ThreadCommand : public LoadCommand {
42 friend class BinaryParser;
43 public:
44 ThreadCommand() = default;
45 ThreadCommand(const details::thread_command& cmd,
46 Header::CPU_TYPE arch = Header::CPU_TYPE::ANY);
47 ThreadCommand(uint32_t flavor, uint32_t count,
48 Header::CPU_TYPE arch= Header::CPU_TYPE::ANY);
49
50 ThreadCommand& operator=(const ThreadCommand& copy) = default;
51 ThreadCommand(const ThreadCommand& copy) = default;
52
53 std::unique_ptr<LoadCommand> clone() const override {
54 return std::unique_ptr<ThreadCommand>(new ThreadCommand(*this));
55 }
56
57 ~ThreadCommand() override = default;
58 uint32_t flavor() const {
66 return flavor_;
67 }
68 uint32_t count() const {
73 return count_;
74 }
75 Header::CPU_TYPE architecture() const {
78 return architecture_;
79 }
80 span<const uint8_t> state() const {
84 return state_;
85 }
86
87 span<uint8_t> state() {
88 return state_;
89 }
90 uint64_t pc() const;
96
97 void state(std::vector<uint8_t> state) {
98 state_ = std::move(state);
99 }
100
101 void flavor(uint32_t flavor) {
102 flavor_ = flavor;
103 }
104 void count(uint32_t count) {
105 count_ = count;
106 }
107 void architecture(Header::CPU_TYPE arch) {
108 architecture_ = arch;
109 }
110
111 void accept(Visitor& visitor) const override;
112
113 std::ostream& print(std::ostream& os) const override;
114
115 static bool classof(const LoadCommand* cmd) {
116 const LoadCommand::TYPE type = cmd->command();
117 return type == LoadCommand::TYPE::THREAD ||
118 type == LoadCommand::TYPE::UNIXTHREAD;
119 }
120
121 private:
122 uint32_t flavor_ = 0;
123 uint32_t count_ = 0;
124 Header::CPU_TYPE architecture_ = Header::CPU_TYPE::ANY;
125 std::vector<uint8_t> state_;
126
127};
128
129}
130}
131#endif
LoadCommand.hpp
Header.hpp
LIEF::MachO::BinaryParser
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
LIEF::MachO::LoadCommand
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:37
LIEF::MachO::LoadCommand::command
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:124
LIEF::MachO::ThreadCommand
Class that represents the LC_THREAD / LC_UNIXTHREAD commands and that can be used to get the binary e...
Definition ThreadCommand.hpp:41
LIEF::MachO::ThreadCommand::state
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:83
LIEF::MachO::ThreadCommand::ThreadCommand
ThreadCommand(const ThreadCommand &copy)=default
LIEF::MachO::ThreadCommand::ThreadCommand
ThreadCommand()=default
LIEF::MachO::ThreadCommand::count
void count(uint32_t count)
Definition ThreadCommand.hpp:104
LIEF::MachO::ThreadCommand::accept
void accept(Visitor &visitor) const override
LIEF::MachO::ThreadCommand::print
std::ostream & print(std::ostream &os) const override
LIEF::MachO::ThreadCommand::classof
static bool classof(const LoadCommand *cmd)
Definition ThreadCommand.hpp:115
LIEF::MachO::ThreadCommand::ThreadCommand
ThreadCommand(uint32_t flavor, uint32_t count, Header::CPU_TYPE arch=Header::CPU_TYPE::ANY)
LIEF::MachO::ThreadCommand::state
void state(std::vector< uint8_t > state)
Definition ThreadCommand.hpp:97
LIEF::MachO::ThreadCommand::flavor
void flavor(uint32_t flavor)
Definition ThreadCommand.hpp:101
LIEF::MachO::ThreadCommand::ThreadCommand
ThreadCommand(const details::thread_command &cmd, Header::CPU_TYPE arch=Header::CPU_TYPE::ANY)
LIEF::MachO::ThreadCommand::architecture
void architecture(Header::CPU_TYPE arch)
Definition ThreadCommand.hpp:107
LIEF::MachO::ThreadCommand::operator=
ThreadCommand & operator=(const ThreadCommand &copy)=default
LIEF::MachO::ThreadCommand::state
span< uint8_t > state()
Definition ThreadCommand.hpp:87
LIEF::MachO::ThreadCommand::~ThreadCommand
~ThreadCommand() override=default
LIEF::MachO::ThreadCommand::architecture
Header::CPU_TYPE architecture() const
The CPU architecture that is targeted by this ThreadCommand.
Definition ThreadCommand.hpp:77
LIEF::MachO::ThreadCommand::pc
uint64_t pc() const
Return the initial Program Counter regardless of the underlying architecture. This value,...
LIEF::MachO::ThreadCommand::count
uint32_t count() const
Size of the thread state data with 32-bits alignment.
Definition ThreadCommand.hpp:72
LIEF::MachO::ThreadCommand::clone
std::unique_ptr< LoadCommand > clone() const override
Definition ThreadCommand.hpp:53
LIEF::MachO::ThreadCommand::flavor
uint32_t flavor() const
Integer that defines a special flavor for the thread.
Definition ThreadCommand.hpp:65
LIEF::MachO::details
Definition endianness_support.hpp:59
LIEF::MachO
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
span.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41