Skip to content
Permalink
Browse files
Add Mach-O/dyld_info API
  • Loading branch information
romainthomas committed Jul 5, 2017
1 parent 98ca302 commit 0e972d6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
@@ -124,6 +124,15 @@ void init_MachO_Binary_class(py::module& m) {
"Return binary's " RST_CLASS_REF(lief.MachO.DylinkerCommand) " if any.",
py::return_value_policy::reference)

.def_property_readonly("has_dyld_info",
&Binary::has_dyld_info,
"``True`` if the binary has a " RST_CLASS_REF(lief.MachO.DyldInfo) " command.",
py::return_value_policy::reference_internal)

.def_property_readonly("dyld_info",
static_cast<no_const_getter<DyldInfo&>>(&Binary::dyld_info),
"Return binary's " RST_CLASS_REF(lief.MachO.DyldInfo) " if any.",
py::return_value_policy::reference)


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

@@ -217,6 +217,10 @@ def main():
action='store_true', dest='show_dylinker',
help='Display the Dylinker command')

parser.add_argument('--dyldinfo',
action='store_true', dest='show_dyldinfo',
help='Display the DyldInfo command')

parser.add_argument("binary",
metavar="<macho-file>",
help='Target Mach-O File')
@@ -35,6 +35,7 @@
#include "LIEF/MachO/SymbolCommand.hpp"
#include "LIEF/MachO/MainCommand.hpp"
#include "LIEF/MachO/DynamicSymbolCommand.hpp"
#include "LIEF/MachO/DyldInfo.hpp"

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

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

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

//! @brief ``true`` if the binary has an MachO::DylinkerCommand.
//! @brief ``true`` if the binary has a MachO::DylinkerCommand.
bool has_dylinker(void) const;

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

//! @brief ``true`` if the binary has a MachO::DyldInfo command.
bool has_dyld_info(void) const;

//! @brief Return the MachO::Dyl
DyldInfo& dyld_info(void);
const DyldInfo& dyld_info(void) const;

template<class T>
bool has_command(void) const;

@@ -526,6 +526,19 @@ const DylinkerCommand& Binary::dylinker(void) const {
return this->get_command<DylinkerCommand>();
}

// DyldInfo
// ++++++++
bool Binary::has_dyld_info(void) const {
return this->has_command<DyldInfo>();
}

DyldInfo& Binary::dyld_info(void) {
return this->get_command<DyldInfo>();
}

const DyldInfo& Binary::dyld_info(void) const {
return this->get_command<DyldInfo>();
}



0 comments on commit 0e972d6

Please sign in to comment.