mirror of
https://github.com/QuasarApp/LIEF.git
synced 2025-05-07 17:29:34 +00:00
parent
d18074c840
commit
a4c69f7868
api
examples/cpp
include/LIEF
src
Abstract
MachO
PE
visitors
tests/pe
@ -19,7 +19,7 @@ namespace LIEF {
|
||||
namespace PE {
|
||||
void init_c_sections(Pe_Binary_t* c_binary, Binary* binary) {
|
||||
|
||||
it_sections sections = binary->get_sections();
|
||||
it_sections sections = binary->sections();
|
||||
|
||||
c_binary->sections = static_cast<Pe_Section_t**>(
|
||||
malloc((sections.size() + 1) * sizeof(Pe_Section_t**)));
|
||||
|
@ -54,7 +54,7 @@ void init_LIEF_Binary_class(py::module& m) {
|
||||
"Binary's name")
|
||||
|
||||
.def_property_readonly("header",
|
||||
&Binary::get_header,
|
||||
&Binary::header,
|
||||
"Binary's header")
|
||||
|
||||
.def_property_readonly("entrypoint",
|
||||
@ -62,7 +62,7 @@ void init_LIEF_Binary_class(py::module& m) {
|
||||
"Binary's entrypoint")
|
||||
|
||||
.def_property_readonly("sections",
|
||||
static_cast<it_t<it_sections>>(&Binary::get_sections),
|
||||
static_cast<it_t<it_sections>>(&Binary::sections),
|
||||
"Return a list in **read only** of binary's abstract " RST_CLASS_REF(lief.Section) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
@ -73,7 +73,7 @@ void init_LIEF_Binary_class(py::module& m) {
|
||||
|
||||
.def_property_readonly("exported_functions",
|
||||
[] (const Binary& binary) {
|
||||
const std::vector<std::string>& exported_functions = binary.get_exported_functions();
|
||||
const std::vector<std::string>& exported_functions = binary.exported_functions();
|
||||
std::vector<py::object> exported_functions_encoded;
|
||||
exported_functions_encoded.reserve(exported_functions.size());
|
||||
|
||||
@ -89,7 +89,7 @@ void init_LIEF_Binary_class(py::module& m) {
|
||||
|
||||
.def_property_readonly("imported_functions",
|
||||
[] (const Binary& binary) {
|
||||
const std::vector<std::string>& imported_functions = binary.get_imported_functions();
|
||||
const std::vector<std::string>& imported_functions = binary.imported_functions();
|
||||
std::vector<py::object> imported_functions_encoded;
|
||||
imported_functions_encoded.reserve(imported_functions.size());
|
||||
|
||||
@ -104,7 +104,7 @@ void init_LIEF_Binary_class(py::module& m) {
|
||||
|
||||
.def_property_readonly("libraries",
|
||||
[] (const Binary& binary) {
|
||||
const std::vector<std::string>& imported_libraries = binary.get_imported_libraries();
|
||||
const std::vector<std::string>& imported_libraries = binary.imported_libraries();
|
||||
std::vector<py::object> imported_libraries_encoded;
|
||||
imported_libraries_encoded.reserve(imported_libraries.size());
|
||||
|
||||
@ -118,7 +118,7 @@ void init_LIEF_Binary_class(py::module& m) {
|
||||
"Return binary's imported libraries (name)")
|
||||
|
||||
.def_property_readonly("symbols",
|
||||
static_cast<it_t<it_symbols>>(&Binary::get_symbols),
|
||||
static_cast<it_t<it_symbols>>(&Binary::symbols),
|
||||
"Return a list in **read only** of binary's abstract " RST_CLASS_REF(lief.Symbol) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
|
@ -72,12 +72,12 @@ void init_MachO_Binary_class(py::module& m) {
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def_property_readonly("imported_symbols",
|
||||
static_cast<no_const_getter<it_imported_symbols>>(&Binary::get_imported_symbols),
|
||||
static_cast<no_const_getter<it_imported_symbols>>(&Binary::imported_symbols),
|
||||
"Return binary's " RST_CLASS_REF(lief.MachO.Symbol) " which are imported",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("exported_symbols",
|
||||
static_cast<no_const_getter<it_exported_symbols>>(&Binary::get_exported_symbols),
|
||||
static_cast<no_const_getter<it_exported_symbols>>(&Binary::exported_symbols),
|
||||
"Return binary's " RST_CLASS_REF(lief.MachO.Symbol) " which are exported",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
|
@ -38,7 +38,7 @@ void init_PE_Binary_class(py::module& m) {
|
||||
.def(py::init<const std::string &, PE_TYPE>())
|
||||
|
||||
.def_property_readonly("sections",
|
||||
static_cast<no_const_getter<it_sections>>(&Binary::get_sections),
|
||||
static_cast<no_const_getter<it_sections>>(&Binary::sections),
|
||||
"Return binary's " RST_CLASS_REF(lief.PE.Section) " sections",
|
||||
py::return_value_policy::reference)
|
||||
|
||||
@ -58,12 +58,12 @@ void init_PE_Binary_class(py::module& m) {
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def_property_readonly("virtual_size",
|
||||
&Binary::get_virtual_size,
|
||||
&Binary::virtual_size,
|
||||
"Binary size when mapped in memory.\n\n"
|
||||
"This value should matches :attr:`~lief.PE.OptionalHeader.sizeof_image`")
|
||||
|
||||
.def_property_readonly("sizeof_headers",
|
||||
&Binary::get_sizeof_headers,
|
||||
&Binary::sizeof_headers,
|
||||
"Size of all PE headers")
|
||||
|
||||
.def("rva_to_offset",
|
||||
@ -141,7 +141,7 @@ void init_PE_Binary_class(py::module& m) {
|
||||
|
||||
|
||||
.def_property_readonly("debug",
|
||||
static_cast<Debug& (Binary::*)(void)>(&Binary::get_debug),
|
||||
static_cast<Debug& (Binary::*)(void)>(&Binary::debug),
|
||||
"Return the " RST_CLASS_REF(lief.PE.Debug) " object",
|
||||
py::return_value_policy::reference)
|
||||
|
||||
@ -212,11 +212,11 @@ void init_PE_Binary_class(py::module& m) {
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def_property_readonly("resources_manager",
|
||||
static_cast<no_const_getter<ResourcesManager>>(&Binary::get_resources_manager),
|
||||
static_cast<no_const_getter<ResourcesManager>>(&Binary::resources_manager),
|
||||
"Return the " RST_CLASS_REF(lief.PE.ResourcesManager) " to manage resources")
|
||||
|
||||
.def_property_readonly("resources",
|
||||
static_cast<no_const_getter<ResourceNode&>>(&Binary::get_resources),
|
||||
static_cast<no_const_getter<ResourceNode&>>(&Binary::resources),
|
||||
"Return the " RST_CLASS_REF(lief.PE.ResourceNode) " tree",
|
||||
py::return_value_policy::reference)
|
||||
|
||||
|
@ -29,30 +29,30 @@ int main(int argc, char **argv) {
|
||||
std::unique_ptr<const LIEF::Binary> binary{LIEF::Parser::parse(argv[1])};
|
||||
|
||||
std::cout << "== Header ==" << std::endl;
|
||||
std::cout << binary->get_header() << std::endl;
|
||||
std::cout << binary->header() << std::endl;
|
||||
|
||||
std::cout << "== Sections ==" << std::endl;
|
||||
for (const LIEF::Section& s : binary->get_sections()) {
|
||||
for (const LIEF::Section& s : binary->sections()) {
|
||||
std::cout << s << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "== Symbols ==" << std::endl;
|
||||
for (const LIEF::Symbol& s : binary->get_symbols()) {
|
||||
for (const LIEF::Symbol& s : binary->symbols()) {
|
||||
std::cout << s << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "== Exported functions ==" << std::endl;
|
||||
for(const std::string& name : binary->get_exported_functions()) {
|
||||
for(const std::string& name : binary->exported_functions()) {
|
||||
std::cout << name << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "== Imported functions ==" << std::endl;
|
||||
for(const std::string& name : binary->get_imported_functions()) {
|
||||
for(const std::string& name : binary->imported_functions()) {
|
||||
std::cout << name << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "== Imported Libraries ==" << std::endl;
|
||||
for(const std::string& name : binary->get_imported_libraries()) {
|
||||
for(const std::string& name : binary->imported_libraries()) {
|
||||
std::cout << name << std::endl;
|
||||
}
|
||||
|
||||
|
@ -74,12 +74,12 @@ void print_binary(const Binary* binary) {
|
||||
|
||||
|
||||
std::cout << "== Exported symbols ==" << std::endl;
|
||||
for (const Symbol& symbol : binary->get_exported_symbols()) {
|
||||
for (const Symbol& symbol : binary->exported_symbols()) {
|
||||
std::cout << symbol << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "== Imported symbols ==" << std::endl;
|
||||
for (const Symbol& symbol : binary->get_imported_symbols()) {
|
||||
for (const Symbol& symbol : binary->imported_symbols()) {
|
||||
std::cout << symbol << std::endl;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
std::cout << "== Sections ==" << std::endl;
|
||||
for (const Section& section : binary->get_sections()) {
|
||||
for (const Section& section : binary->sections()) {
|
||||
std::cout << section << std::endl;
|
||||
}
|
||||
|
||||
@ -87,13 +87,13 @@ int main(int argc, char **argv) {
|
||||
|
||||
if (binary->has_debug()) {
|
||||
std::cout << "== Debug ==" << std::endl;
|
||||
std::cout << binary->get_debug() << std::endl;
|
||||
std::cout << binary->debug() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
if (binary->has_resources()) {
|
||||
std::cout << "== Resources ==" << std::endl;
|
||||
std::cout << binary->get_resources_manager() << std::endl;
|
||||
std::cout << binary->resources_manager() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,13 +46,13 @@ class DLL_PUBLIC Binary : public Visitable {
|
||||
EXE_FORMATS format(void) const;
|
||||
|
||||
//! @brief Return the abstract header of the binary
|
||||
Header get_header(void) const;
|
||||
Header header(void) const;
|
||||
|
||||
//! @brief Return list of symbols whose elements **can** be modified
|
||||
it_symbols get_symbols(void);
|
||||
it_symbols symbols(void);
|
||||
|
||||
//! @brief Return list of symbols whose elements **can't** be modified
|
||||
it_const_symbols get_symbols(void) const;
|
||||
it_const_symbols symbols(void) const;
|
||||
|
||||
//! @brief Check if a Symbol with the given name exists
|
||||
bool has_symbol(const std::string& name) const;
|
||||
@ -63,8 +63,8 @@ class DLL_PUBLIC Binary : public Visitable {
|
||||
Symbol& get_symbol(const std::string& name);
|
||||
|
||||
//! @brief Returns binary's sections
|
||||
it_sections get_sections(void);
|
||||
it_const_sections get_sections(void) const;
|
||||
it_sections sections(void);
|
||||
it_const_sections sections(void) const;
|
||||
|
||||
//! @brief Returns binary's relocations
|
||||
it_relocations relocations(void);
|
||||
@ -80,13 +80,13 @@ class DLL_PUBLIC Binary : public Visitable {
|
||||
uint64_t original_size(void) const;
|
||||
|
||||
//! @brief Return functions's name exported by the binary
|
||||
std::vector<std::string> get_exported_functions(void) const;
|
||||
std::vector<std::string> exported_functions(void) const;
|
||||
|
||||
//! @brief Return libraries which are imported by the binary
|
||||
std::vector<std::string> get_imported_libraries(void) const;
|
||||
std::vector<std::string> imported_libraries(void) const;
|
||||
|
||||
//! @brief Return functions's name imported by the binary
|
||||
std::vector<std::string> get_imported_functions(void) const;
|
||||
std::vector<std::string> imported_functions(void) const;
|
||||
|
||||
//! @brief Return the address of the given function name
|
||||
virtual uint64_t get_function_address(const std::string& func_name) const;
|
||||
|
@ -78,15 +78,15 @@ class DLL_PUBLIC Binary : public LIEF::Binary {
|
||||
static bool is_exported(const Symbol& symbol);
|
||||
|
||||
//! @brief Return binary's exported symbols
|
||||
it_exported_symbols get_exported_symbols(void);
|
||||
it_const_exported_symbols get_exported_symbols(void) const;
|
||||
it_exported_symbols exported_symbols(void);
|
||||
it_const_exported_symbols exported_symbols(void) const;
|
||||
|
||||
//! @brief Check if the given symbol is an imported one
|
||||
static bool is_imported(const Symbol& symbol);
|
||||
|
||||
//! @brief Return binary's imported symbols
|
||||
it_imported_symbols get_imported_symbols(void);
|
||||
it_const_imported_symbols get_imported_symbols(void) const;
|
||||
it_imported_symbols imported_symbols(void);
|
||||
it_const_imported_symbols imported_symbols(void) const;
|
||||
|
||||
//! @brief Return binary imported libraries (MachO::DylibCommand)
|
||||
it_libraries libraries(void);
|
||||
@ -121,7 +121,7 @@ class DLL_PUBLIC Binary : public LIEF::Binary {
|
||||
uint64_t imagebase(void) const;
|
||||
|
||||
//! @brief Return binary's loader (e.g. ``/usr/lib/dyld``)
|
||||
const std::string& get_loader(void) const;
|
||||
const std::string& loader(void) const;
|
||||
|
||||
//! @brief Check if a section with the given name exists
|
||||
bool has_section(const std::string& name) const;
|
||||
@ -251,10 +251,10 @@ class DLL_PUBLIC Binary : public LIEF::Binary {
|
||||
bool has_command(void) const;
|
||||
|
||||
template<class T>
|
||||
T& get_command(void);
|
||||
T& command(void);
|
||||
|
||||
template<class T>
|
||||
const T& get_command(void) const;
|
||||
const T& command(void) const;
|
||||
|
||||
template<class T>
|
||||
size_t count_commands(void) const;
|
||||
|
@ -77,8 +77,8 @@ class DLL_PUBLIC Binary : public LIEF::Binary {
|
||||
const Section& section_from_rva(uint64_t virtual_address) const;
|
||||
|
||||
//! @brief Return binary's sections
|
||||
it_sections get_sections(void);
|
||||
it_const_sections get_sections(void) const;
|
||||
it_sections sections(void);
|
||||
it_const_sections sections(void) const;
|
||||
|
||||
// =======
|
||||
// Headers
|
||||
@ -98,10 +98,10 @@ class DLL_PUBLIC Binary : public LIEF::Binary {
|
||||
|
||||
//! @brief Compute the binary's virtual size.
|
||||
//! It should match with OptionalHeader::sizeof_image
|
||||
uint64_t get_virtual_size(void) const;
|
||||
uint64_t virtual_size(void) const;
|
||||
|
||||
//! @brief Compute the size of all headers
|
||||
uint32_t get_sizeof_headers(void) const;
|
||||
uint32_t sizeof_headers(void) const;
|
||||
|
||||
//! @brief Return a reference to the TLS object
|
||||
TLS& tls(void);
|
||||
@ -169,8 +169,8 @@ class DLL_PUBLIC Binary : public LIEF::Binary {
|
||||
const std::vector<Symbol>& symbols(void) const;
|
||||
|
||||
//! @brief Return resources as a tree
|
||||
ResourceNode& get_resources(void);
|
||||
const ResourceNode& get_resources(void) const;
|
||||
ResourceNode& resources(void);
|
||||
const ResourceNode& resources(void) const;
|
||||
|
||||
//! @brief Set a new resource tree
|
||||
void set_resources(const ResourceDirectory& resource);
|
||||
@ -179,8 +179,8 @@ class DLL_PUBLIC Binary : public LIEF::Binary {
|
||||
void set_resources(const ResourceData& resource);
|
||||
|
||||
//! @brief Return the ResourcesManager (class to manage resources more easily than the tree one)
|
||||
ResourcesManager get_resources_manager(void);
|
||||
const ResourcesManager get_resources_manager(void) const;
|
||||
ResourcesManager resources_manager(void);
|
||||
const ResourcesManager resources_manager(void) const;
|
||||
|
||||
// ==========================
|
||||
// Methods to manage sections
|
||||
@ -193,8 +193,8 @@ class DLL_PUBLIC Binary : public LIEF::Binary {
|
||||
const Section& get_section(const std::string& name) const;
|
||||
|
||||
//! @brief Return the section associated with import table
|
||||
const Section& get_import_section(void) const;
|
||||
Section& get_import_section(void);
|
||||
const Section& import_section(void) const;
|
||||
Section& import_section(void);
|
||||
|
||||
//! @brief Delete the section with the given name
|
||||
//!
|
||||
@ -232,8 +232,8 @@ class DLL_PUBLIC Binary : public LIEF::Binary {
|
||||
const DataDirectory& data_directory(DATA_DIRECTORY index) const;
|
||||
|
||||
//! @brief Return the Debug object
|
||||
Debug& get_debug(void);
|
||||
const Debug& get_debug(void) const;
|
||||
Debug& debug(void);
|
||||
const Debug& debug(void) const;
|
||||
|
||||
// =======
|
||||
// Overlay
|
||||
|
@ -46,16 +46,16 @@ EXE_FORMATS Binary::format(void) const {
|
||||
return EXE_FORMATS::FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
Header Binary::get_header(void) const {
|
||||
Header Binary::header(void) const {
|
||||
return this->get_abstract_header();
|
||||
}
|
||||
|
||||
it_symbols Binary::get_symbols(void) {
|
||||
return it_symbols{this->get_abstract_symbols()};
|
||||
it_symbols Binary::symbols(void) {
|
||||
return this->get_abstract_symbols();
|
||||
}
|
||||
|
||||
it_const_symbols Binary::get_symbols(void) const {
|
||||
return it_const_symbols{const_cast<Binary*>(this)->get_abstract_symbols()};
|
||||
it_const_symbols Binary::symbols(void) const {
|
||||
return const_cast<Binary*>(this)->get_abstract_symbols();
|
||||
}
|
||||
|
||||
|
||||
@ -92,13 +92,13 @@ Symbol& Binary::get_symbol(const std::string& name) {
|
||||
return const_cast<Symbol&>(static_cast<const Binary*>(this)->get_symbol(name));
|
||||
}
|
||||
|
||||
it_sections Binary::get_sections(void) {
|
||||
return it_sections{this->get_abstract_sections()};
|
||||
it_sections Binary::sections(void) {
|
||||
return this->get_abstract_sections();
|
||||
}
|
||||
|
||||
|
||||
it_const_sections Binary::get_sections(void) const {
|
||||
return it_const_sections{const_cast<Binary*>(this)->get_abstract_sections()};
|
||||
it_const_sections Binary::sections(void) const {
|
||||
return const_cast<Binary*>(this)->get_abstract_sections();
|
||||
}
|
||||
|
||||
|
||||
@ -111,16 +111,16 @@ it_const_relocations Binary::relocations(void) const {
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> Binary::get_exported_functions(void) const {
|
||||
std::vector<std::string> Binary::exported_functions(void) const {
|
||||
return this->get_abstract_exported_functions();
|
||||
}
|
||||
|
||||
std::vector<std::string> Binary::get_imported_functions(void) const {
|
||||
std::vector<std::string> Binary::imported_functions(void) const {
|
||||
return this->get_abstract_imported_functions();
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> Binary::get_imported_libraries(void) const {
|
||||
std::vector<std::string> Binary::imported_libraries(void) const {
|
||||
return this->get_abstract_imported_libraries();
|
||||
}
|
||||
|
||||
@ -142,13 +142,13 @@ std::vector<uint64_t> Binary::xref(uint64_t address) const {
|
||||
}
|
||||
|
||||
void Binary::accept(Visitor& visitor) const {
|
||||
visitor(this->get_header());
|
||||
for (const Section& section : const_cast<Binary*>(this)->get_sections()) {
|
||||
visitor(this->header());
|
||||
for (const Section& section : this->sections()) {
|
||||
visitor(section);
|
||||
}
|
||||
|
||||
|
||||
for (const Symbol& symbol : const_cast<Binary*>(this)->get_symbols()) {
|
||||
for (const Symbol& symbol : this->symbols()) {
|
||||
visitor(symbol);
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ LIEF::symbols_t Binary::get_abstract_symbols(void) {
|
||||
|
||||
std::vector<std::string> Binary::get_abstract_exported_functions(void) const {
|
||||
std::vector<std::string> result;
|
||||
it_const_exported_symbols syms = this->get_exported_symbols();
|
||||
it_const_exported_symbols syms = this->exported_symbols();
|
||||
std::transform(
|
||||
std::begin(syms),
|
||||
std::end(syms),
|
||||
@ -157,7 +157,7 @@ std::vector<std::string> Binary::get_abstract_exported_functions(void) const {
|
||||
|
||||
std::vector<std::string> Binary::get_abstract_imported_functions(void) const {
|
||||
std::vector<std::string> result;
|
||||
it_const_imported_symbols syms = this->get_imported_symbols();
|
||||
it_const_imported_symbols syms = this->imported_symbols();
|
||||
std::transform(
|
||||
std::begin(syms),
|
||||
std::end(syms),
|
||||
@ -330,14 +330,14 @@ bool Binary::is_exported(const Symbol& symbol) {
|
||||
return not symbol.is_external() and symbol.has_export_info();
|
||||
}
|
||||
|
||||
it_exported_symbols Binary::get_exported_symbols(void) {
|
||||
it_exported_symbols Binary::exported_symbols(void) {
|
||||
return filter_iterator<symbols_t>{std::ref(this->symbols_),
|
||||
[] (const Symbol* symbol) { return is_exported(*symbol); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
it_const_exported_symbols Binary::get_exported_symbols(void) const {
|
||||
it_const_exported_symbols Binary::exported_symbols(void) const {
|
||||
return const_filter_iterator<symbols_t>{std::cref(this->symbols_),
|
||||
[] (const Symbol* symbol) { return is_exported(*symbol); }
|
||||
};
|
||||
@ -348,14 +348,14 @@ bool Binary::is_imported(const Symbol& symbol) {
|
||||
return symbol.is_external() and not symbol.has_export_info();
|
||||
}
|
||||
|
||||
it_imported_symbols Binary::get_imported_symbols(void) {
|
||||
it_imported_symbols Binary::imported_symbols(void) {
|
||||
return filter_iterator<symbols_t>{std::ref(this->symbols_),
|
||||
[] (const Symbol* symbol) { return is_imported(*symbol); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
it_const_imported_symbols Binary::get_imported_symbols(void) const {
|
||||
it_const_imported_symbols Binary::imported_symbols(void) const {
|
||||
return const_filter_iterator<symbols_t>{std::cref(this->symbols_),
|
||||
[] (const Symbol* symbol) { return is_imported(*symbol); }
|
||||
};
|
||||
@ -576,7 +576,7 @@ uint64_t Binary::imagebase(void) const {
|
||||
}
|
||||
|
||||
|
||||
const std::string& Binary::get_loader(void) const {
|
||||
const std::string& Binary::loader(void) const {
|
||||
return this->dylinker().name();
|
||||
}
|
||||
|
||||
@ -609,11 +609,11 @@ bool Binary::has_uuid(void) const {
|
||||
}
|
||||
|
||||
UUIDCommand& Binary::uuid(void) {
|
||||
return this->get_command<UUIDCommand>();
|
||||
return this->command<UUIDCommand>();
|
||||
}
|
||||
|
||||
const UUIDCommand& Binary::uuid(void) const {
|
||||
return this->get_command<UUIDCommand>();
|
||||
return this->command<UUIDCommand>();
|
||||
}
|
||||
|
||||
// MainCommand
|
||||
@ -623,11 +623,11 @@ bool Binary::has_main_command(void) const {
|
||||
}
|
||||
|
||||
MainCommand& Binary::main_command(void) {
|
||||
return this->get_command<MainCommand>();
|
||||
return this->command<MainCommand>();
|
||||
}
|
||||
|
||||
const MainCommand& Binary::main_command(void) const {
|
||||
return this->get_command<MainCommand>();
|
||||
return this->command<MainCommand>();
|
||||
}
|
||||
|
||||
// DylinkerCommand
|
||||
@ -637,11 +637,11 @@ bool Binary::has_dylinker(void) const {
|
||||
}
|
||||
|
||||
DylinkerCommand& Binary::dylinker(void) {
|
||||
return this->get_command<DylinkerCommand>();
|
||||
return this->command<DylinkerCommand>();
|
||||
}
|
||||
|
||||
const DylinkerCommand& Binary::dylinker(void) const {
|
||||
return this->get_command<DylinkerCommand>();
|
||||
return this->command<DylinkerCommand>();
|
||||
}
|
||||
|
||||
// DyldInfo
|
||||
@ -651,11 +651,11 @@ bool Binary::has_dyld_info(void) const {
|
||||
}
|
||||
|
||||
DyldInfo& Binary::dyld_info(void) {
|
||||
return this->get_command<DyldInfo>();
|
||||
return this->command<DyldInfo>();
|
||||
}
|
||||
|
||||
const DyldInfo& Binary::dyld_info(void) const {
|
||||
return this->get_command<DyldInfo>();
|
||||
return this->command<DyldInfo>();
|
||||
}
|
||||
|
||||
// Function Starts
|
||||
@ -665,11 +665,11 @@ bool Binary::has_function_starts(void) const {
|
||||
}
|
||||
|
||||
FunctionStarts& Binary::function_starts(void) {
|
||||
return this->get_command<FunctionStarts>();
|
||||
return this->command<FunctionStarts>();
|
||||
}
|
||||
|
||||
const FunctionStarts& Binary::function_starts(void) const {
|
||||
return this->get_command<FunctionStarts>();
|
||||
return this->command<FunctionStarts>();
|
||||
}
|
||||
|
||||
// Source Version
|
||||
@ -679,11 +679,11 @@ bool Binary::has_source_version(void) const {
|
||||
}
|
||||
|
||||
SourceVersion& Binary::source_version(void) {
|
||||
return this->get_command<SourceVersion>();
|
||||
return this->command<SourceVersion>();
|
||||
}
|
||||
|
||||
const SourceVersion& Binary::source_version(void) const {
|
||||
return this->get_command<SourceVersion>();
|
||||
return this->command<SourceVersion>();
|
||||
}
|
||||
|
||||
// Version Min
|
||||
@ -693,11 +693,11 @@ bool Binary::has_version_min(void) const {
|
||||
}
|
||||
|
||||
VersionMin& Binary::version_min(void) {
|
||||
return this->get_command<VersionMin>();
|
||||
return this->command<VersionMin>();
|
||||
}
|
||||
|
||||
const VersionMin& Binary::version_min(void) const {
|
||||
return this->get_command<VersionMin>();
|
||||
return this->command<VersionMin>();
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,13 +31,13 @@ bool Binary::has_command(void) const {
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& Binary::get_command(void) {
|
||||
T& Binary::command(void) {
|
||||
static_assert(std::is_base_of<LoadCommand, T>::value, "Require inheritance of 'LoadCommand'");
|
||||
return const_cast<T&>(static_cast<const Binary*>(this)->get_command<T>());
|
||||
return const_cast<T&>(static_cast<const Binary*>(this)->command<T>());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T& Binary::get_command(void) const {
|
||||
const T& Binary::command(void) const {
|
||||
static_assert(std::is_base_of<LoadCommand, T>::value, "Require inheritance of 'LoadCommand'");
|
||||
if (not this->has_command<T>()) {
|
||||
throw not_found("Unable to find the " + std::string(typeid(T).name()));
|
||||
|
@ -164,8 +164,8 @@ Binary::Binary(const std::string& name, PE_TYPE type) :
|
||||
this->data_directories_.emplace_back(new DataDirectory{DATA_DIRECTORY::DELAY_IMPORT_DESCRIPTOR});
|
||||
this->data_directories_.emplace_back(new DataDirectory{DATA_DIRECTORY::CLR_RUNTIME_HEADER});
|
||||
|
||||
this->optional_header().sizeof_headers(this->get_sizeof_headers());
|
||||
this->optional_header().sizeof_image(this->get_virtual_size());
|
||||
this->optional_header().sizeof_headers(this->sizeof_headers());
|
||||
this->optional_header().sizeof_image(this->virtual_size());
|
||||
}
|
||||
|
||||
void Binary::write(const std::string& filename) {
|
||||
@ -358,13 +358,13 @@ LIEF::symbols_t Binary::get_abstract_symbols(void) {
|
||||
// Sections
|
||||
// ========
|
||||
|
||||
it_sections Binary::get_sections(void) {
|
||||
return it_sections{this->sections_};
|
||||
it_sections Binary::sections(void) {
|
||||
return this->sections_;
|
||||
}
|
||||
|
||||
|
||||
it_const_sections Binary::get_sections(void) const {
|
||||
return it_const_sections{this->sections_};
|
||||
it_const_sections Binary::sections(void) const {
|
||||
return this->sections_;
|
||||
}
|
||||
|
||||
LIEF::sections_t Binary::get_abstract_sections(void) {
|
||||
@ -392,7 +392,7 @@ const Section& Binary::get_section(const std::string& name) const {
|
||||
}
|
||||
|
||||
|
||||
const Section& Binary::get_import_section(void) const {
|
||||
const Section& Binary::import_section(void) const {
|
||||
if (not this->has_imports()) {
|
||||
throw not_found("Current binary doesn't have Import directory");
|
||||
}
|
||||
@ -401,8 +401,8 @@ const Section& Binary::get_import_section(void) const {
|
||||
}
|
||||
|
||||
|
||||
Section& Binary::get_import_section(void) {
|
||||
return const_cast<Section&>(static_cast<const Binary*>(this)->get_import_section());
|
||||
Section& Binary::import_section(void) {
|
||||
return const_cast<Section&>(static_cast<const Binary*>(this)->import_section());
|
||||
}
|
||||
|
||||
// Headers
|
||||
@ -445,7 +445,7 @@ OptionalHeader& Binary::optional_header(void) {
|
||||
|
||||
|
||||
|
||||
uint64_t Binary::get_virtual_size(void) const {
|
||||
uint64_t Binary::virtual_size(void) const {
|
||||
uint64_t size = 0;
|
||||
size += this->dos_header().addressof_new_exeheader();
|
||||
size += sizeof(pe_header);
|
||||
@ -462,7 +462,7 @@ uint64_t Binary::get_virtual_size(void) const {
|
||||
}
|
||||
|
||||
|
||||
uint32_t Binary::get_sizeof_headers(void) const {
|
||||
uint32_t Binary::sizeof_headers(void) const {
|
||||
uint32_t size = 0;
|
||||
size += this->dos_header().addressof_new_exeheader();
|
||||
size += sizeof(pe_header);
|
||||
@ -484,8 +484,8 @@ void Binary::delete_section(const std::string& name) {
|
||||
|
||||
this->header().numberof_sections(this->header().numberof_sections() - 1);
|
||||
|
||||
this->optional_header().sizeof_headers(this->get_sizeof_headers());
|
||||
this->optional_header().sizeof_image(static_cast<uint32_t>(this->get_virtual_size()));
|
||||
this->optional_header().sizeof_headers(this->sizeof_headers());
|
||||
this->optional_header().sizeof_image(static_cast<uint32_t>(this->virtual_size()));
|
||||
|
||||
this->sections_.erase(
|
||||
std::remove_if(
|
||||
@ -525,7 +525,7 @@ Section& Binary::add_section(const Section& section, PE_SECTION_TYPES type) {
|
||||
// Compute new section offset
|
||||
uint64_t new_section_offset = align(std::accumulate(
|
||||
std::begin(this->sections_),
|
||||
std::end(this->sections_), this->get_sizeof_headers(),
|
||||
std::end(this->sections_), this->sizeof_headers(),
|
||||
[] (uint64_t offset, const Section* s) {
|
||||
return std::max<uint64_t>(s->pointerto_raw_data() + s->sizeof_raw_data(), offset);
|
||||
}), this->optional_header().file_alignment());
|
||||
@ -621,8 +621,8 @@ Section& Binary::add_section(const Section& section, PE_SECTION_TYPES type) {
|
||||
// Update headers
|
||||
this->header().numberof_sections(static_cast<uint16_t>(this->sections_.size()));
|
||||
|
||||
this->optional_header().sizeof_image(this->get_virtual_size());
|
||||
this->optional_header().sizeof_headers(this->get_sizeof_headers());
|
||||
this->optional_header().sizeof_image(this->virtual_size());
|
||||
this->optional_header().sizeof_headers(this->sizeof_headers());
|
||||
|
||||
return *(this->sections_.back());
|
||||
}
|
||||
@ -866,11 +866,11 @@ void Binary::set_resources(const ResourceData& resource) {
|
||||
this->resources_ = new ResourceData{resource};
|
||||
}
|
||||
|
||||
ResourceNode& Binary::get_resources(void) {
|
||||
return const_cast<ResourceNode&>(static_cast<const Binary*>(this)->get_resources());
|
||||
ResourceNode& Binary::resources(void) {
|
||||
return const_cast<ResourceNode&>(static_cast<const Binary*>(this)->resources());
|
||||
}
|
||||
|
||||
const ResourceNode& Binary::get_resources(void) const {
|
||||
const ResourceNode& Binary::resources(void) const {
|
||||
if (this->resources_ != nullptr) {
|
||||
return *this->resources_;
|
||||
} else {
|
||||
@ -893,12 +893,12 @@ it_const_data_directories Binary::data_directories(void) const {
|
||||
}
|
||||
|
||||
|
||||
Debug& Binary::get_debug(void) {
|
||||
return const_cast<Debug&>(static_cast<const Binary*>(this)->get_debug());
|
||||
Debug& Binary::debug(void) {
|
||||
return const_cast<Debug&>(static_cast<const Binary*>(this)->debug());
|
||||
}
|
||||
|
||||
|
||||
const Debug& Binary::get_debug(void) const {
|
||||
const Debug& Binary::debug(void) const {
|
||||
return this->debug_;
|
||||
}
|
||||
|
||||
@ -1123,14 +1123,14 @@ void Binary::rich_header(const RichHeader& rich_header) {
|
||||
// Resource manager
|
||||
// ===============
|
||||
|
||||
ResourcesManager Binary::get_resources_manager(void) {
|
||||
ResourcesManager Binary::resources_manager(void) {
|
||||
if (this->resources_ == nullptr or not this->has_resources()) {
|
||||
throw not_found("There is no resources in the binary");
|
||||
}
|
||||
return ResourcesManager{this->resources_};
|
||||
}
|
||||
|
||||
const ResourcesManager Binary::get_resources_manager(void) const {
|
||||
const ResourcesManager Binary::resources_manager(void) const {
|
||||
if (this->resources_ == nullptr or not this->has_resources()) {
|
||||
throw not_found("There is no resources in the binary");
|
||||
}
|
||||
@ -1147,7 +1147,7 @@ void Binary::accept(Visitor& visitor) const {
|
||||
visitor(data_directory);
|
||||
}
|
||||
|
||||
for (const Section& section : this->get_sections()) {
|
||||
for (const Section& section : this->sections()) {
|
||||
visitor(section);
|
||||
}
|
||||
|
||||
@ -1164,7 +1164,7 @@ void Binary::accept(Visitor& visitor) const {
|
||||
}
|
||||
|
||||
if (this->has_debug()) {
|
||||
visitor(this->get_debug());
|
||||
visitor(this->debug());
|
||||
}
|
||||
|
||||
|
||||
@ -1241,7 +1241,7 @@ std::ostream& Binary::print(std::ostream& os) const {
|
||||
os << "Sections" << std::endl;
|
||||
os << "========" << std::endl;
|
||||
|
||||
for (const Section& section : this->get_sections()) {
|
||||
for (const Section& section : this->sections()) {
|
||||
os << section << std::endl;;
|
||||
}
|
||||
os << std::endl;
|
||||
@ -1276,7 +1276,7 @@ std::ostream& Binary::print(std::ostream& os) const {
|
||||
if (this->has_debug()) {
|
||||
os << "Debug" << std::endl;
|
||||
os << "=====" << std::endl;
|
||||
os << this->get_debug() << std::endl;
|
||||
os << this->debug() << std::endl;
|
||||
os << std::endl;
|
||||
}
|
||||
|
||||
@ -1302,7 +1302,7 @@ std::ostream& Binary::print(std::ostream& os) const {
|
||||
if (this->has_resources()) {
|
||||
os << "Resources" << std::endl;
|
||||
os << "=========" << std::endl;
|
||||
os << this->get_resources_manager() << std::endl;
|
||||
os << this->resources_manager() << std::endl;
|
||||
os << std::endl;
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ void Builder::build(void) {
|
||||
|
||||
VLOG(VDEBUG) << "[+] Rebuilding sections" << std::endl;
|
||||
|
||||
for (const Section& section : this->binary_->get_sections()) {
|
||||
for (const Section& section : this->binary_->sections()) {
|
||||
VLOG(VDEBUG) << "Building section " << section.name();
|
||||
*this << section;
|
||||
}
|
||||
@ -235,7 +235,7 @@ void Builder::build_relocation(void) {
|
||||
//
|
||||
void Builder::build_resources(void) {
|
||||
VLOG(VDEBUG) << "Building RSRC" << std::endl;
|
||||
ResourceNode& node = this->binary_->get_resources();
|
||||
ResourceNode& node = this->binary_->resources();
|
||||
//std::cout << ResourcesManager{this->binary_->resources_} << std::endl;
|
||||
|
||||
|
||||
|
@ -350,8 +350,8 @@ void Builder::build_optional_header(const OptionalHeader& optional_header) {
|
||||
using pe_optional_header = typename PE_T::pe_optional_header;
|
||||
|
||||
// Build optional header
|
||||
this->binary_->optional_header().sizeof_image(static_cast<uint32_t>(this->binary_->get_virtual_size()));
|
||||
this->binary_->optional_header().sizeof_headers(static_cast<uint32_t>(this->binary_->get_sizeof_headers()));
|
||||
this->binary_->optional_header().sizeof_image(static_cast<uint32_t>(this->binary_->virtual_size()));
|
||||
this->binary_->optional_header().sizeof_headers(static_cast<uint32_t>(this->binary_->sizeof_headers()));
|
||||
|
||||
pe_optional_header optional_header_raw;
|
||||
optional_header_raw.Magic = static_cast<uint16_t>(optional_header.magic());
|
||||
|
@ -36,17 +36,17 @@ JsonVisitor& JsonVisitor::operator=(const JsonVisitor&) = default;
|
||||
|
||||
void JsonVisitor::visit(const Binary& binary) {
|
||||
JsonVisitor header_visitor;
|
||||
header_visitor(binary.get_header());
|
||||
header_visitor(binary.header());
|
||||
std::vector<json> sections_json, symbols_json;
|
||||
|
||||
for (const Section& section : const_cast<Binary*>(&binary)->get_sections()) {
|
||||
for (const Section& section : binary.sections()) {
|
||||
JsonVisitor section_visitor;
|
||||
section_visitor(section);
|
||||
sections_json.emplace_back(section_visitor.get());
|
||||
}
|
||||
|
||||
|
||||
for (const Symbol& symbol : const_cast<Binary*>(&binary)->get_symbols()) {
|
||||
for (const Symbol& symbol : binary.symbols()) {
|
||||
JsonVisitor visitor;
|
||||
visitor(symbol);
|
||||
symbols_json.emplace_back(visitor.get());
|
||||
@ -57,9 +57,9 @@ void JsonVisitor::visit(const Binary& binary) {
|
||||
this->node_["entrypoint"] = binary.entrypoint();
|
||||
this->node_["format"] = to_string(binary.format());
|
||||
this->node_["original_size"] = binary.original_size();
|
||||
this->node_["exported_functions"] = binary.get_exported_functions();
|
||||
this->node_["imported_libraries"] = binary.get_imported_libraries();
|
||||
this->node_["imported_functions"] = binary.get_imported_functions();
|
||||
this->node_["exported_functions"] = binary.exported_functions();
|
||||
this->node_["imported_libraries"] = binary.imported_libraries();
|
||||
this->node_["imported_functions"] = binary.imported_functions();
|
||||
this->node_["header"] = header_visitor.get();
|
||||
this->node_["sections"] = sections_json;
|
||||
this->node_["symbols"] = symbols_json;
|
||||
|
@ -28,7 +28,7 @@ void JsonVisitor::visit(const Binary& binary) {
|
||||
|
||||
this->node_["name"] = binary.name();
|
||||
this->node_["entrypoint"] = binary.entrypoint();
|
||||
this->node_["virtual_size"] = binary.get_virtual_size();
|
||||
this->node_["virtual_size"] = binary.virtual_size();
|
||||
|
||||
// DOS Header
|
||||
JsonVisitor dos_header_visitor;
|
||||
@ -65,7 +65,7 @@ void JsonVisitor::visit(const Binary& binary) {
|
||||
|
||||
// Section
|
||||
std::vector<json> sections;
|
||||
for (const Section& section : binary.get_sections()) {
|
||||
for (const Section& section : binary.sections()) {
|
||||
JsonVisitor visitor;
|
||||
visitor(section);
|
||||
sections.emplace_back(visitor.get());
|
||||
@ -102,7 +102,7 @@ void JsonVisitor::visit(const Binary& binary) {
|
||||
// Debug
|
||||
if (binary.has_debug()) {
|
||||
JsonVisitor visitor;
|
||||
visitor(binary.get_debug());
|
||||
visitor(binary.debug());
|
||||
this->node_["debug"] = visitor.get();
|
||||
}
|
||||
|
||||
@ -120,10 +120,10 @@ void JsonVisitor::visit(const Binary& binary) {
|
||||
// Resources
|
||||
if (binary.has_resources()) {
|
||||
JsonVisitor visitor;
|
||||
binary.get_resources().accept(visitor);
|
||||
binary.resources().accept(visitor);
|
||||
|
||||
JsonVisitor manager_visitor;
|
||||
binary.get_resources_manager().accept(manager_visitor);
|
||||
binary.resources_manager().accept(manager_visitor);
|
||||
|
||||
this->node_["resources_tree"] = visitor.get();
|
||||
this->node_["resources_manager"] = manager_visitor.get();
|
||||
|
@ -133,7 +133,7 @@ TEST_CASE("Test parse", "[pe][builder]")
|
||||
|
||||
SECTION("Section") {
|
||||
|
||||
for (const Section& section_lhs : binary_original->get_sections()) {
|
||||
for (const Section& section_lhs : binary_original->sections()) {
|
||||
|
||||
INFO("Section " << section_lhs.name());
|
||||
const Section& section_rhs = binary_built->get_section(section_lhs.name());
|
||||
@ -166,7 +166,7 @@ TEST_CASE("Test parse", "[pe][builder]")
|
||||
|
||||
|
||||
SECTION("Debug") {
|
||||
REQUIRE(binary_original->get_debug() == binary_built->get_debug());
|
||||
REQUIRE(binary_original->debug() == binary_built->debug());
|
||||
}
|
||||
|
||||
|
||||
@ -174,10 +174,10 @@ TEST_CASE("Test parse", "[pe][builder]")
|
||||
if (not binary_original->has_resources()) {
|
||||
return;
|
||||
}
|
||||
const ResourceNode& root_lhs = binary_original->get_resources();
|
||||
const ResourceNode& root_rhs = binary_built->get_resources();
|
||||
INFO("LHS: " << binary_original->get_resources_manager());
|
||||
INFO("RHS: " << binary_built->get_resources_manager());
|
||||
const ResourceNode& root_lhs = binary_original->resources();
|
||||
const ResourceNode& root_rhs = binary_built->resources();
|
||||
INFO("LHS: " << binary_original->resources_manager());
|
||||
INFO("RHS: " << binary_built->resources_manager());
|
||||
//REQUIRE(root_lhs == root_rhs);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ TEST_CASE("Test operator== and operator!=", "[pe][internal]") {
|
||||
}
|
||||
|
||||
SECTION("Sections") {
|
||||
for (const Section& section_lhs : binary_lhs->get_sections()) {
|
||||
for (const Section& section_lhs : binary_lhs->sections()) {
|
||||
Section section_rhs = section_lhs;
|
||||
REQUIRE(section_lhs == section_rhs);
|
||||
|
||||
|
@ -220,7 +220,7 @@ TEST_CASE("Test parse", "[pe][parser]")
|
||||
// Sections
|
||||
// ========
|
||||
SECTION("Section") {
|
||||
it_const_sections sections = binary->get_sections();
|
||||
it_const_sections sections = binary->sections();
|
||||
|
||||
REQUIRE(
|
||||
sections.size() ==
|
||||
|
Loading…
x
Reference in New Issue
Block a user