Expose the Dynamic symbol command

This commit is contained in:
Romain Thomas 2018-03-28 16:14:56 +02:00
parent 9c24533356
commit 237611f859
13 changed files with 702 additions and 121 deletions

View File

@ -25,6 +25,7 @@ set(LIEF_PYTHON_MACHO_SRC
"${CMAKE_CURRENT_LIST_DIR}/objects/pyThreadCommand.cpp"
"${CMAKE_CURRENT_LIST_DIR}/objects/pyRPathCommand.cpp"
"${CMAKE_CURRENT_LIST_DIR}/objects/pyParserConfig.cpp"
"${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicSymbolCommand.cpp"
"${CMAKE_CURRENT_LIST_DIR}/pyMachOStructures.cpp"
)

View File

@ -216,7 +216,7 @@ void init_MachO_Binary_class(py::module& m) {
py::return_value_policy::reference)
.def_property_readonly("has_symbol_command",
&Binary::has_rpath,
&Binary::has_symbol_command,
"``True`` if the binary has a " RST_CLASS_REF(lief.MachO.SymbolCommand) " command.",
py::return_value_policy::reference_internal)
@ -225,6 +225,16 @@ void init_MachO_Binary_class(py::module& m) {
"Return binary's " RST_CLASS_REF(lief.MachO.SymbolCommand) " if any.",
py::return_value_policy::reference)
.def_property_readonly("has_dynamic_symbol_command",
&Binary::has_dynamic_symbol_command,
"``True`` if the binary has a " RST_CLASS_REF(lief.MachO.DynamicSymbolCommand) " command.",
py::return_value_policy::reference_internal)
.def_property_readonly("dynamic_symbol_command",
static_cast<no_const_getter<DynamicSymbolCommand&>>(&Binary::dynamic_symbol_command),
"Return binary's " RST_CLASS_REF(lief.MachO.DynamicSymbolCommand) " if any.",
py::return_value_policy::reference)
.def("virtual_address_to_offset",
&Binary::virtual_address_to_offset,

View File

@ -0,0 +1,194 @@
/* Copyright 2017 R. Thomas
* Copyright 2017 Quarkslab
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <algorithm>
#include <string>
#include <sstream>
#include "LIEF/MachO/hash.hpp"
#include "LIEF/MachO/DynamicSymbolCommand.hpp"
#include "pyMachO.hpp"
template<class T>
using getter_t = T (DynamicSymbolCommand::*)(void) const;
template<class T>
using setter_t = void (DynamicSymbolCommand::*)(T);
template<class T>
using no_const_getter = T (DynamicSymbolCommand::*)(void);
void init_MachO_DynamicSymbolCommand_class(py::module& m) {
py::class_<DynamicSymbolCommand, LoadCommand>(m, "DynamicSymbolCommand")
.def_property("idx_local_symbol",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::idx_local_symbol),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::idx_local_symbol),
"Index of the first symbol in the group of local symbols."
)
.def_property("nb_local_symbols",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::nb_local_symbols),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::nb_local_symbols),
"Number of symbols in the group of local symbols."
)
.def_property("idx_external_define_symbol",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::idx_external_define_symbol),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::idx_external_define_symbol),
"Index of the first symbol in the group of defined external symbols."
)
.def_property("nb_external_define_symbols",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::nb_external_define_symbols),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::nb_external_define_symbols),
"Number of symbols in the group of defined external symbols."
)
.def_property("idx_undefined_symbol",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::idx_undefined_symbol),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::idx_undefined_symbol),
"Index of the first symbol in the group of undefined external symbols."
)
.def_property("nb_undefined_symbols",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::nb_undefined_symbols),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::nb_undefined_symbols),
"Number of symbols in the group of undefined external symbols."
)
.def_property("toc_offset",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::toc_offset),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::toc_offset),
"Byte offset from the start of the file to the table of contents data\n\n"
"Table of content is used by legacy Mach-O loader and this field should be set to 0"
)
.def_property("nb_toc",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::nb_toc),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::nb_toc),
"Number of entries in the table of contents\n\n"
"Should be set to 0 on recent Mach-O"
)
.def_property("module_table_offset",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::module_table_offset),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::module_table_offset),
"Byte offset from the start of the file to the module table data.\n\n"
"This field seems unused by recent Mach-O loader and should be set to 0"
)
.def_property("nb_module_table",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::nb_module_table),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::nb_module_table),
"Number of entries in the module table..\n\n"
"This field seems unused by recent Mach-O loader and should be set to 0"
)
.def_property("external_reference_symbol_offset",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::external_reference_symbol_offset),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::external_reference_symbol_offset),
"Byte offset from the start of the file to the external reference table data.\n\n"
"This field seems unused by recent Mach-O loader and should be set to 0"
)
.def_property("nb_external_reference_symbols",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::nb_external_reference_symbols),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::nb_external_reference_symbols),
"Number of entries in the external reference table\n\n"
"This field seems unused by recent Mach-O loader and should be set to 0"
)
.def_property("indirect_symbol_offset",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::indirect_symbol_offset),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::indirect_symbol_offset),
"Byte offset from the start of the file to the indirect symbol table data..\n\n"
"Indirect symbol table is used by the loader to speed-up symbol resolution during "
"the *lazy binding* process\n\n"
"References:\n\n"
"\t* ``dyld-519.2.1/src/ImageLoaderMachOCompressed.cpp``\n"
"\t* ``dyld-519.2.1/src/ImageLoaderMachOClassic.cpp``\n"
)
.def_property("nb_indirect_symbols",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::nb_indirect_symbols),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::nb_indirect_symbols),
"Number of entries in the indirect symbol table."
)
.def_property("external_relocation_offset",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::external_relocation_offset),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::external_relocation_offset),
"Byte offset from the start of the file to the module table data.\n\n"
"This field seems unused by recent Mach-O loader and should be set to 0"
)
.def_property("nb_external_relocations",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::nb_external_relocations),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::nb_external_relocations),
"Number of entries in the external relocation table.\n\n"
"This field seems unused by recent Mach-O loader and should be set to 0"
)
.def_property("local_relocation_offset",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::local_relocation_offset),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::local_relocation_offset),
"Byte offset from the start of the file to the local relocation table data.\n\n"
"This field seems unused by recent Mach-O loader and should be set to 0"
)
.def_property("nb_local_relocations",
static_cast<getter_t<uint32_t>>(&DynamicSymbolCommand::nb_local_relocations),
static_cast<setter_t<uint32_t>>(&DynamicSymbolCommand::nb_local_relocations),
"Number of entries in the local relocation table.\n\n"
"This field seems unused by recent Mach-O loader and should be set to 0"
)
.def("__eq__", &DynamicSymbolCommand::operator==)
.def("__ne__", &DynamicSymbolCommand::operator!=)
.def("__hash__",
[] (const DynamicSymbolCommand& cmd) {
return Hash::hash(cmd);
})
.def("__str__",
[] (const DynamicSymbolCommand& info)
{
std::ostringstream stream;
stream << info;
return stream.str();
});
}

View File

@ -49,6 +49,7 @@ void init_MachO_module(py::module& m) {
init_MachO_ExportInfo_class(LIEF_MachO_module);
init_MachO_ThreadCommand_class(LIEF_MachO_module);
init_MachO_RPathCommand_class(LIEF_MachO_module);
init_MachO_DynamicSymbolCommand_class(LIEF_MachO_module);
// Enums
init_MachO_Structures_enum(LIEF_MachO_module);

View File

@ -51,6 +51,7 @@ void init_MachO_BindingInfo_class(py::module&);
void init_MachO_ExportInfo_class(py::module&);
void init_MachO_ThreadCommand_class(py::module&);
void init_MachO_RPathCommand_class(py::module&);
void init_MachO_DynamicSymbolCommand_class(py::module&);
// Enums
void init_MachO_Structures_enum(py::module&);

0
doc/sphinx/_static/tutorial/09/telegram.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View File

@ -155,6 +155,16 @@ Symbol Command
----------
Dynamic Symbol Command
**********************
.. autoclass:: lief.MachO.DynamicSymbolCommand
:members:
:inherited-members:
:undoc-members:
----------
Dyld Info
*********

View File

@ -229,6 +229,63 @@ def print_symbols(binary):
libname))
print("")
@exceptions_handler(Exception)
def print_symbol_command(binary):
print("== Symbol Command ==")
scmd = binary.symbol_command
format_str = "{:<17} {:<30}"
format_hex = "{:<17} 0x{:<28x}"
format_dec = "{:<17} {:<30d}"
print(format_hex.format("Symbol offset", scmd.symbol_offset))
print(format_dec.format("Number of symbols", scmd.numberof_symbols))
print(format_hex.format("String offset", scmd.strings_offset))
print(format_hex.format("String size", scmd.strings_size))
print("")
@exceptions_handler(Exception)
def print_dynamic_symbol_command(binary):
print("== Dynamic Symbol Command ==")
dyscmd = binary.dynamic_symbol_command
format_str = "{:<36} {:<30}"
format_hex = "{:<36} 0x{:<28x}"
format_dec = "{:<36} {:<30d}"
print(format_dec.format("First local symbol index", dyscmd.idx_local_symbol))
print(format_dec.format("Number of local symbols", dyscmd.nb_local_symbols))
print(format_dec.format("External symbol index", dyscmd.idx_external_define_symbol))
print(format_dec.format("Number of external symbols", dyscmd.nb_external_define_symbols))
print(format_dec.format("Undefined symbol index", dyscmd.idx_undefined_symbol))
print(format_dec.format("Number of undefined symbols", dyscmd.nb_undefined_symbols))
print(format_dec.format("Table of content offset", dyscmd.toc_offset))
print(format_dec.format("Number of entries in TOC", dyscmd.nb_toc))
print(format_hex.format("Module table offset", dyscmd.module_table_offset))
print(format_dec.format("Number of entries in module table", dyscmd.nb_module_table))
print(format_hex.format("External reference table offset", dyscmd.external_reference_symbol_offset))
print(format_dec.format("Number of external reference", dyscmd.nb_external_reference_symbols))
print(format_hex.format("Indirect symbols offset", dyscmd.indirect_symbol_offset))
print(format_dec.format("Number of indirect symbols", dyscmd.nb_indirect_symbols))
print(format_hex.format("External relocation offset", dyscmd.external_relocation_offset))
print(format_dec.format("Number of external relocations", dyscmd.nb_external_relocations))
print(format_hex.format("Local relocation offset", dyscmd.local_relocation_offset))
print(format_dec.format("Number of local relocations", dyscmd.nb_local_relocations))
print("")
@exceptions_handler(Exception)
def print_uuid(binary):
@ -571,6 +628,14 @@ def main():
action='store_true', dest='show_rpath_command',
help="Display the 'Rpath Command' command")
parser.add_argument('--symbol-command',
action='store_true', dest='show_symbol_command',
help="Display the 'Symbol Command' command")
parser.add_argument('--dynamic-symbol-command',
action='store_true', dest='show_dynamic_symbol_command',
help="Display the 'Symbol Command' command")
parser.add_argument('--bind-opcodes',
action='store_true', dest='show_bind_opcodes',
help='Display the "Bind" opcodes')
@ -656,6 +721,15 @@ def main():
if (args.show_rpath_command or args.show_all) and binary.has_rpath:
print_rpath_command(binary)
if (args.show_symbol_command or args.show_all) and binary.has_symbol_command:
print_symbol_command(binary)
if (args.show_dynamic_symbol_command or args.show_all) and binary.has_dynamic_symbol_command:
print_dynamic_symbol_command(binary)
if (args.show_rpath_command or args.show_all) and binary.has_rpath:
print_rpath_command(binary)
if (args.show_rebase_opcodes or args.show_opcodes) and binary.has_dyld_info:
print_rebase_opcodes(binary)

View File

@ -283,6 +283,13 @@ class LIEF_API Binary : public LIEF::Binary {
SymbolCommand& symbol_command(void);
const SymbolCommand& symbol_command(void) const;
//! @brief ``true`` if the binary has a MachO::DynamicSymbolCommand command.
bool has_dynamic_symbol_command(void) const;
//! @brief Return the MachO::SymbolCommand
DynamicSymbolCommand& dynamic_symbol_command(void);
const DynamicSymbolCommand& dynamic_symbol_command(void) const;
template<class T>
LIEF_LOCAL bool has_command(void) const;

View File

@ -29,86 +29,161 @@ namespace LIEF {
namespace MachO {
class LIEF_API DynamicSymbolCommand : public LoadCommand {
public:
DynamicSymbolCommand(void);
DynamicSymbolCommand(const dysymtab_command *cmd);
DynamicSymbolCommand(void);
DynamicSymbolCommand(const dysymtab_command *cmd);
DynamicSymbolCommand& operator=(const DynamicSymbolCommand& copy);
DynamicSymbolCommand(const DynamicSymbolCommand& copy);
DynamicSymbolCommand& operator=(const DynamicSymbolCommand& copy);
DynamicSymbolCommand(const DynamicSymbolCommand& copy);
virtual ~DynamicSymbolCommand(void);
virtual ~DynamicSymbolCommand(void);
virtual void accept(Visitor& visitor) const override;
virtual void accept(Visitor& visitor) const override;
bool operator==(const DynamicSymbolCommand& rhs) const;
bool operator!=(const DynamicSymbolCommand& rhs) const;
bool operator==(const DynamicSymbolCommand& rhs) const;
bool operator!=(const DynamicSymbolCommand& rhs) const;
virtual std::ostream& print(std::ostream& os) const override;
virtual std::ostream& print(std::ostream& os) const override;
//! Index of the first symbol in the group of local symbols.
uint32_t idx_local_symbol(void) const;
//! Number of symbols in the group of local symbols.
uint32_t nb_local_symbols(void) const;
//! Index of the first symbol in the group of defined external symbols.
uint32_t idx_external_define_symbol(void) const;
//! Number of symbols in the group of defined external symbols.
uint32_t nb_external_define_symbols(void) const;
//! Index of the first symbol in the group of undefined external symbols.
uint32_t idx_undefined_symbol(void) const;
//! Number of symbols in the group of undefined external symbols.
uint32_t nb_undefined_symbols(void) const;
//! Byte offset from the start of the file to the table of contents data
//!
//! Table of content is used by legacy Mach-O loader and this field should be
//! set to 0
uint32_t toc_offset(void) const;
//! Number of entries in the table of contents.
//!
//! Should be set to 0 on recent Mach-O
uint32_t nb_toc(void) const;
//! Byte offset from the start of the file to the module table data.
//!
//! This field seems unused by recent Mach-O loader and should be set to 0
uint32_t module_table_offset(void) const;
//! Number of entries in the module table.
//!
//! This field seems unused by recent Mach-O loader and should be set to 0
uint32_t nb_module_table(void) const;
//! Byte offset from the start of the file to the external reference table data.
//!
//! This field seems unused by recent Mach-O loader and should be set to 0
uint32_t external_reference_symbol_offset(void) const;
//! Number of entries in the external reference table
//!
//! This field seems unused by recent Mach-O loader and should be set to 0
uint32_t nb_external_reference_symbols(void) const;
//! Byte offset from the start of the file to the indirect symbol table data.
//!
//! Indirect symbol table is used by the loader to speed-up symbol resolution during
//! the *lazy binding* process
//!
//! References:
//! * dyld-519.2.1/src/ImageLoaderMachOCompressed.cpp
//! * dyld-519.2.1/src/ImageLoaderMachOClassic.cpp
uint32_t indirect_symbol_offset(void) const;
//! Number of entries in the indirect symbol table.
//!
//! @see indirect_symbol_offset
uint32_t nb_indirect_symbols(void) const;
//! Byte offset from the start of the file to the external relocation table data.
//!
//! This field seems unused by recent Mach-O loader and should be set to 0
uint32_t external_relocation_offset(void) const;
//! Number of entries in the external relocation table.
//!
//! This field seems unused by recent Mach-O loader and should be set to 0
uint32_t nb_external_relocations(void) const;
//! Byte offset from the start of the file to the local relocation table data.
//!
//! This field seems unused by recent Mach-O loader and should be set to 0
uint32_t local_relocation_offset(void) const;
//! Number of entries in the local relocation table.
//!
//! This field seems unused by recent Mach-O loader and should be set to 0
uint32_t nb_local_relocations(void) const;
void idx_local_symbol(uint32_t value);
void nb_local_symbols(uint32_t value);
void idx_external_define_symbol(uint32_t value);
void nb_external_define_symbols(uint32_t value);
void idx_undefined_symbol(uint32_t value);
void nb_undefined_symbols(uint32_t value);
void toc_offset(uint32_t value);
void nb_toc(uint32_t value);
void module_table_offset(uint32_t value);
void nb_module_table(uint32_t value);
void external_reference_symbol_offset(uint32_t value);
void nb_external_reference_symbols(uint32_t value);
void indirect_symbol_offset(uint32_t value);
void nb_indirect_symbols(uint32_t value);
void external_relocation_offset(uint32_t value);
void nb_external_relocations(uint32_t value);
void local_relocation_offset(uint32_t value);
void nb_local_relocations(uint32_t value);
private:
//! @brief Integer indicating the index of the first symbol in the group of local symbols.
uint32_t idxLocalSymbol_;
uint32_t idx_local_symbol_;
uint32_t nb_local_symbols_;
//! @brief Integer indicating the total number of symbols in the group of local symbols.
uint32_t nbLocalSymbol_;
uint32_t idx_external_define_symbol_;
uint32_t nb_external_define_symbols_;
//! @brief Integer indicating the index of the first symbol in the group of
//! defined external symbols.
uint32_t idxExternalDefineSymbol_;
uint32_t idx_undefined_symbol_;
uint32_t nb_undefined_symbols_;
//! @brief Integer indicating the total number of symbols in the group of
//! defined external symbols.
uint32_t nbExternalDefineSymbol_;
uint32_t toc_offset_;
uint32_t nb_toc_;
//! @brief Integer indicating the index of the first symbol in the group of
//! undefined external symbols.
uint32_t idxUndefineSymbol_;
uint32_t module_table_offset_;
uint32_t nb_module_table_;
//! @brief Integer indicating the total number of symbols in the group of
//! undefined external symbols.
uint32_t nbUndefineSymbol_;
uint32_t external_reference_symbol_offset_;
uint32_t nb_external_reference_symbols_;
//! @brief Integer indicating the byte offset from the start of
//! the file to the table of contents data.
uint32_t tocOffset_;
uint32_t indirect_sym_offset_;
uint32_t nb_indirect_symbols_;
//! @brief Integer indicating the number of entries in the table of contents.
uint32_t nbToc_;
uint32_t external_relocation_offset_;
uint32_t nb_external_relocations_;
//! @brief Integer indicating the byte offset from the start of
//! the file to the module table data.
uint32_t moduleTableOffset_;
//! @brief Integer indicating the number of entries in the module table.
uint32_t nbModuleTable_;
//! @brief Integer indicating the byte offset from the start of
//! the file to the external reference table data.
uint32_t externalReferenceSymbolOffset_;
//! @brief Integer indicating the number of entries in the external reference table.
uint32_t nbExternalReferenceSymbols_;
//! @brief Integer indicating the byte offset from the start of
//! the file to the indirect symbol table data.
uint32_t indirectSymOffset_;
//! @brief Integer indicating the number of entries in the indirect symbol table.
uint32_t nbIndirectSymbols_;
//! @brief Integer indicating the byte offset from the start of
//! the file to the external relocation table data.
uint32_t externalRelocationOffset_;
//! @brief Integer indicating the number of entries in the external relocation table.
uint32_t nbExternalRelocation_;
//! @brief Integer indicating the byte offset from the start of
//! the file to the local relocation table data.
uint32_t localRelocationOffset_;
//! @brief An integer indicating the number of entries in the local relocation table.
uint32_t nbLocRelocation_;
uint32_t local_relocation_offset_;
uint32_t nb_local_relocations_;
};
}

View File

@ -785,6 +785,19 @@ const SymbolCommand& Binary::symbol_command(void) const {
return this->command<SymbolCommand>();
}
// DynamicSymbolCommand command
// ++++++++++++++++++++++++++++
bool Binary::has_dynamic_symbol_command(void) const {
return this->has_command<SymbolCommand>();
}
DynamicSymbolCommand& Binary::dynamic_symbol_command(void) {
return this->command<DynamicSymbolCommand>();
}
const DynamicSymbolCommand& Binary::dynamic_symbol_command(void) const {
return this->command<DynamicSymbolCommand>();
}

View File

@ -24,46 +24,63 @@ namespace MachO {
DynamicSymbolCommand::DynamicSymbolCommand(void) :
LoadCommand::LoadCommand{LOAD_COMMAND_TYPES::LC_DYSYMTAB, 0},
idxLocalSymbol_{0},
nbLocalSymbol_{0},
idxExternalDefineSymbol_{0},
nbExternalDefineSymbol_{0},
idxUndefineSymbol_{0},
nbUndefineSymbol_{0},
tocOffset_{0},
nbToc_{0},
moduleTableOffset_{0},
nbModuleTable_{0},
externalReferenceSymbolOffset_{0},
nbExternalReferenceSymbols_{0},
indirectSymOffset_{0},
nbIndirectSymbols_{0},
externalRelocationOffset_{0},
nbExternalRelocation_{0},
localRelocationOffset_{0},
nbLocRelocation_{0}
idx_local_symbol_{0},
nb_local_symbols_{0},
idx_external_define_symbol_{0},
nb_external_define_symbols_{0},
idx_undefined_symbol_{0},
nb_undefined_symbols_{0},
toc_offset_{0},
nb_toc_{0},
module_table_offset_{0},
nb_module_table_{0},
external_reference_symbol_offset_{0},
nb_external_reference_symbols_{0},
indirect_sym_offset_{0},
nb_indirect_symbols_{0},
external_relocation_offset_{0},
nb_external_relocations_{0},
local_relocation_offset_{0},
nb_local_relocations_{0}
{}
DynamicSymbolCommand::DynamicSymbolCommand(const dysymtab_command *cmd) :
LoadCommand::LoadCommand{static_cast<LOAD_COMMAND_TYPES>(cmd->cmd), cmd->cmdsize},
idxLocalSymbol_{cmd->ilocalsym},
nbLocalSymbol_{cmd->nlocalsym},
idxExternalDefineSymbol_{cmd->iextdefsym},
nbExternalDefineSymbol_{cmd->nextdefsym},
idxUndefineSymbol_{cmd->iundefsym},
nbUndefineSymbol_{cmd->nundefsym},
tocOffset_{cmd->tocoff},
nbToc_{cmd->ntoc},
moduleTableOffset_{cmd->modtaboff},
nbModuleTable_{cmd->nmodtab},
externalReferenceSymbolOffset_{cmd->extrefsymoff},
nbExternalReferenceSymbols_{cmd->nextrefsyms},
indirectSymOffset_{cmd->indirectsymoff},
nbIndirectSymbols_{cmd->nindirectsyms},
externalRelocationOffset_{cmd->extreloff},
nbExternalRelocation_{cmd->nextrel},
localRelocationOffset_{cmd->locreloff},
nbLocRelocation_{cmd->nlocrel}
idx_local_symbol_{cmd->ilocalsym},
nb_local_symbols_{cmd->nlocalsym},
idx_external_define_symbol_{cmd->iextdefsym},
nb_external_define_symbols_{cmd->nextdefsym},
idx_undefined_symbol_{cmd->iundefsym},
nb_undefined_symbols_{cmd->nundefsym},
toc_offset_{cmd->tocoff},
nb_toc_{cmd->ntoc},
module_table_offset_{cmd->modtaboff},
nb_module_table_{cmd->nmodtab},
external_reference_symbol_offset_{cmd->extrefsymoff},
nb_external_reference_symbols_{cmd->nextrefsyms},
indirect_sym_offset_{cmd->indirectsymoff},
nb_indirect_symbols_{cmd->nindirectsyms},
external_relocation_offset_{cmd->extreloff},
nb_external_relocations_{cmd->nextrel},
local_relocation_offset_{cmd->locreloff},
nb_local_relocations_{cmd->nlocrel}
{}
@ -75,6 +92,158 @@ DynamicSymbolCommand::DynamicSymbolCommand(const DynamicSymbolCommand&) = defaul
DynamicSymbolCommand::~DynamicSymbolCommand(void) = default;
uint32_t DynamicSymbolCommand::idx_local_symbol(void) const {
return this->idx_local_symbol_;
}
uint32_t DynamicSymbolCommand::nb_local_symbols(void) const {
return this->nb_local_symbols_;
}
uint32_t DynamicSymbolCommand::idx_external_define_symbol(void) const {
return this->idx_external_define_symbol_;
}
uint32_t DynamicSymbolCommand::nb_external_define_symbols(void) const {
return this->nb_external_define_symbols_;
}
uint32_t DynamicSymbolCommand::idx_undefined_symbol(void) const {
return this->idx_undefined_symbol_;
}
uint32_t DynamicSymbolCommand::nb_undefined_symbols(void) const {
return this->nb_undefined_symbols_;
}
uint32_t DynamicSymbolCommand::toc_offset(void) const {
return this->toc_offset_;
}
uint32_t DynamicSymbolCommand::nb_toc(void) const {
return this->nb_toc_;
}
uint32_t DynamicSymbolCommand::module_table_offset(void) const {
return this->module_table_offset_;
}
uint32_t DynamicSymbolCommand::nb_module_table(void) const {
return this->nb_module_table_;
}
uint32_t DynamicSymbolCommand::external_reference_symbol_offset(void) const {
return this->external_reference_symbol_offset_;
}
uint32_t DynamicSymbolCommand::nb_external_reference_symbols(void) const {
return this->nb_external_reference_symbols_;
}
uint32_t DynamicSymbolCommand::indirect_symbol_offset(void) const {
return this->indirect_sym_offset_;
}
uint32_t DynamicSymbolCommand::nb_indirect_symbols(void) const {
return this->nb_indirect_symbols_;
}
uint32_t DynamicSymbolCommand::external_relocation_offset(void) const {
return this->external_relocation_offset_;
}
uint32_t DynamicSymbolCommand::nb_external_relocations(void) const {
return this->nb_external_relocations_;
}
uint32_t DynamicSymbolCommand::local_relocation_offset(void) const {
return this->local_relocation_offset_;
}
uint32_t DynamicSymbolCommand::nb_local_relocations(void) const {
return this->nb_local_relocations_;
}
void DynamicSymbolCommand::idx_local_symbol(uint32_t value) {
this->idx_local_symbol_ = value;
}
void DynamicSymbolCommand::nb_local_symbols(uint32_t value) {
this->nb_local_symbols_ = value;
}
void DynamicSymbolCommand::idx_external_define_symbol(uint32_t value) {
this->idx_external_define_symbol_ = value;
}
void DynamicSymbolCommand::nb_external_define_symbols(uint32_t value) {
this->nb_external_define_symbols_ = value;
}
void DynamicSymbolCommand::idx_undefined_symbol(uint32_t value) {
this->idx_undefined_symbol_ = value;
}
void DynamicSymbolCommand::nb_undefined_symbols(uint32_t value) {
this->nb_undefined_symbols_ = value;
}
void DynamicSymbolCommand::toc_offset(uint32_t value) {
this->toc_offset_ = value;
}
void DynamicSymbolCommand::nb_toc(uint32_t value) {
this->nb_toc_ = value;
}
void DynamicSymbolCommand::module_table_offset(uint32_t value) {
this->module_table_offset_ = value;
}
void DynamicSymbolCommand::nb_module_table(uint32_t value) {
this->nb_module_table_ = value;
}
void DynamicSymbolCommand::external_reference_symbol_offset(uint32_t value) {
this->external_reference_symbol_offset_ = value;
}
void DynamicSymbolCommand::nb_external_reference_symbols(uint32_t value) {
this->nb_external_reference_symbols_ = value;
}
void DynamicSymbolCommand::indirect_symbol_offset(uint32_t value) {
this->indirect_sym_offset_ = value;
}
void DynamicSymbolCommand::nb_indirect_symbols(uint32_t value) {
this->nb_indirect_symbols_ = value;
}
void DynamicSymbolCommand::external_relocation_offset(uint32_t value) {
this->external_relocation_offset_ = value;
}
void DynamicSymbolCommand::nb_external_relocations(uint32_t value) {
this->nb_external_relocations_ = value;
}
void DynamicSymbolCommand::local_relocation_offset(uint32_t value) {
this->local_relocation_offset_ = value;
}
void DynamicSymbolCommand::nb_local_relocations(uint32_t value) {
this->nb_local_relocations_ = value;
}
void DynamicSymbolCommand::accept(Visitor& visitor) const {
visitor.visit(*this);
}
@ -92,43 +261,45 @@ bool DynamicSymbolCommand::operator!=(const DynamicSymbolCommand& rhs) const {
std::ostream& DynamicSymbolCommand::print(std::ostream& os) const {
LoadCommand::print(os);
static constexpr size_t WIDTH = 36;
os << std::hex;
os << std::left
<< std::setw(36) << "Local symbol index:" << this->idxLocalSymbol_
<< std::setw(WIDTH) << "First local symbol index:" << this->idx_local_symbol()
<< std::endl
<< std::setw(36) << "Number of local symbols:" << this->nbLocalSymbol_
<< std::setw(WIDTH) << "Number of local symbols:" << this->nb_local_symbols()
<< std::endl
<< std::setw(36) << "External symbol index:" << this->idxExternalDefineSymbol_
<< std::setw(WIDTH) << "External symbol index:" << this->idx_external_define_symbol()
<< std::endl
<< std::setw(36) << "Number of external symbols:" << this->nbExternalDefineSymbol_
<< std::setw(WIDTH) << "Number of external symbols:" << this->nb_external_define_symbols()
<< std::endl
<< std::setw(36) << "Undefined symbol index:" << this->idxUndefineSymbol_
<< std::setw(WIDTH) << "Undefined symbol index:" << this->idx_undefined_symbol()
<< std::endl
<< std::setw(36) << "Number of undefined symbols:" << this->nbUndefineSymbol_
<< std::setw(WIDTH) << "Number of undefined symbols:" << this->nb_undefined_symbols()
<< std::endl
<< std::setw(36) << "Table of content offset:" << this->tocOffset_
<< std::setw(WIDTH) << "Table of content offset:" << this->toc_offset()
<< std::endl
<< std::setw(36) << "Number of entries in TOC:" << this->nbToc_
<< std::setw(WIDTH) << "Number of entries in TOC:" << this->nb_toc()
<< std::endl
<< std::setw(36) << "Module table offset:" << this->moduleTableOffset_
<< std::setw(WIDTH) << "Module table offset:" << this->module_table_offset()
<< std::endl
<< std::setw(36) << "Number of entries in module table:" << this->nbModuleTable_
<< std::setw(WIDTH) << "Number of entries in module table:" << this->nb_module_table()
<< std::endl
<< std::setw(36) << "External reference table offset:" << this->externalReferenceSymbolOffset_
<< std::setw(WIDTH) << "External reference table offset:" << this->external_reference_symbol_offset()
<< std::endl
<< std::setw(36) << "Number of external reference:" << this->nbExternalReferenceSymbols_
<< std::setw(WIDTH) << "Number of external reference:" << this->nb_external_reference_symbols()
<< std::endl
<< std::setw(36) << "Indirect symbols offset:" << this->indirectSymOffset_
<< std::setw(WIDTH) << "Indirect symbols offset:" << this->indirect_symbol_offset()
<< std::endl
<< std::setw(36) << "Number of indirect symbols:" << this->nbIndirectSymbols_
<< std::setw(WIDTH) << "Number of indirect symbols:" << this->nb_indirect_symbols()
<< std::endl
<< std::setw(36) << "External relocation offset:" << this->externalRelocationOffset_
<< std::setw(WIDTH) << "External relocation offset:" << this->external_relocation_offset()
<< std::endl
<< std::setw(36) << "Local relocation offset:" << this->localRelocationOffset_
<< std::setw(WIDTH) << "Number of external relocations:" << this->nb_external_relocations()
<< std::endl
<< std::setw(36) << "Number of local relocations:" << this->nbLocRelocation_
<< std::setw(WIDTH) << "Local relocation offset:" << this->local_relocation_offset()
<< std::endl
<< std::setw(WIDTH) << "Number of local relocations:" << this->nb_local_relocations()
<< std::endl;
return os;

View File

@ -109,8 +109,32 @@ void Hash::visit(const MainCommand& maincmd) {
}
void Hash::visit(const DynamicSymbolCommand& dynamic_symbol) {
//TODO
this->process(reinterpret_cast<size_t>(&dynamic_symbol));
this->process(dynamic_symbol.idx_local_symbol());
this->process(dynamic_symbol.nb_local_symbols());
this->process(dynamic_symbol.idx_external_define_symbol());
this->process(dynamic_symbol.nb_external_define_symbols());
this->process(dynamic_symbol.idx_undefined_symbol());
this->process(dynamic_symbol.nb_undefined_symbols());
this->process(dynamic_symbol.toc_offset());
this->process(dynamic_symbol.nb_toc());
this->process(dynamic_symbol.module_table_offset());
this->process(dynamic_symbol.nb_module_table());
this->process(dynamic_symbol.external_reference_symbol_offset());
this->process(dynamic_symbol.nb_external_reference_symbols());
this->process(dynamic_symbol.indirect_symbol_offset());
this->process(dynamic_symbol.nb_indirect_symbols());
this->process(dynamic_symbol.external_relocation_offset());
this->process(dynamic_symbol.nb_external_relocations());
this->process(dynamic_symbol.local_relocation_offset());
this->process(dynamic_symbol.nb_local_relocations());
}
void Hash::visit(const DylinkerCommand& dylinker) {