Skip to content

Commit 0e972d6

Browse files
committed
Add Mach-O/dyld_info API
1 parent 98ca302 commit 0e972d6

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

api/python/MachO/objects/pyBinary.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ void init_MachO_Binary_class(py::module& m) {
124124
"Return binary's " RST_CLASS_REF(lief.MachO.DylinkerCommand) " if any.",
125125
py::return_value_policy::reference)
126126

127+
.def_property_readonly("has_dyld_info",
128+
&Binary::has_dyld_info,
129+
"``True`` if the binary has a " RST_CLASS_REF(lief.MachO.DyldInfo) " command.",
130+
py::return_value_policy::reference_internal)
131+
132+
.def_property_readonly("dyld_info",
133+
static_cast<no_const_getter<DyldInfo&>>(&Binary::dyld_info),
134+
"Return binary's " RST_CLASS_REF(lief.MachO.DyldInfo) " if any.",
135+
py::return_value_policy::reference)
127136

128137

129138
.def("__str__",

api/python/MachO/objects/pyDyldInfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void init_MachO_DyldInfo_class(py::module& m) {
137137
"If there is no exported symbol, the byte is zero. If there\n"
138138
"is exported info, it follows the length byte. The exported\n"
139139
"info normally consists of a flags and offset both encoded\n"
140-
"in uleb128. The offset is location of the content named\n"
140+
"in `uleb128 <https://en.wikipedia.org/wiki/LEB128>`_. The offset is location of the content named\n"
141141
"by the symbol. It is the offset from the mach_header for\n"
142142
"the image.\n\n"
143143

examples/python/macho_reader.py

+4
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ def main():
217217
action='store_true', dest='show_dylinker',
218218
help='Display the Dylinker command')
219219

220+
parser.add_argument('--dyldinfo',
221+
action='store_true', dest='show_dyldinfo',
222+
help='Display the DyldInfo command')
223+
220224
parser.add_argument("binary",
221225
metavar="<macho-file>",
222226
help='Target Mach-O File')

include/LIEF/MachO/Binary.hpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "LIEF/MachO/SymbolCommand.hpp"
3636
#include "LIEF/MachO/MainCommand.hpp"
3737
#include "LIEF/MachO/DynamicSymbolCommand.hpp"
38+
#include "LIEF/MachO/DyldInfo.hpp"
3839

3940
namespace LIEF {
4041
namespace MachO {
@@ -172,20 +173,27 @@ class DLL_PUBLIC Binary : public LIEF::Binary {
172173
UUIDCommand& uuid(void);
173174
const UUIDCommand& uuid(void) const;
174175

175-
//! @brief ``true`` if the binary has an MachO::MainCommand command.
176+
//! @brief ``true`` if the binary has a MachO::MainCommand command.
176177
bool has_main_command(void) const;
177178

178179
//! @brief Return the MachO::MainCommand
179180
MainCommand& main_command(void);
180181
const MainCommand& main_command(void) const;
181182

182-
//! @brief ``true`` if the binary has an MachO::DylinkerCommand.
183+
//! @brief ``true`` if the binary has a MachO::DylinkerCommand.
183184
bool has_dylinker(void) const;
184185

185186
//! @brief Return the MachO::DylinkerCommand
186187
DylinkerCommand& dylinker(void);
187188
const DylinkerCommand& dylinker(void) const;
188189

190+
//! @brief ``true`` if the binary has a MachO::DyldInfo command.
191+
bool has_dyld_info(void) const;
192+
193+
//! @brief Return the MachO::Dyl
194+
DyldInfo& dyld_info(void);
195+
const DyldInfo& dyld_info(void) const;
196+
189197
template<class T>
190198
bool has_command(void) const;
191199

src/MachO/Binary.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,19 @@ const DylinkerCommand& Binary::dylinker(void) const {
526526
return this->get_command<DylinkerCommand>();
527527
}
528528

529+
// DyldInfo
530+
// ++++++++
531+
bool Binary::has_dyld_info(void) const {
532+
return this->has_command<DyldInfo>();
533+
}
534+
535+
DyldInfo& Binary::dyld_info(void) {
536+
return this->get_command<DyldInfo>();
537+
}
538+
539+
const DyldInfo& Binary::dyld_info(void) const {
540+
return this->get_command<DyldInfo>();
541+
}
529542

530543

531544

0 commit comments

Comments
 (0)