mirror of
https://github.com/QuasarApp/LIEF.git
synced 2025-04-28 05:14:33 +00:00
Resolve #119 and enhance ELF Python bindings
This commit is contained in:
parent
163cd3bcc9
commit
cd1cc457cf
@ -63,7 +63,7 @@ void init_c_binary(Elf_Binary_t* c_binary, Binary* binary) {
|
||||
}
|
||||
|
||||
Elf_Binary_t* elf_parse(const char *file) {
|
||||
Binary* binary = Parser::parse(file);
|
||||
Binary* binary = Parser::parse(file).release();
|
||||
Elf_Binary_t* c_binary = static_cast<Elf_Binary_t*>(malloc(sizeof(Elf_Binary_t)));
|
||||
memset(c_binary, 0, sizeof(Elf_Binary_t));
|
||||
init_c_binary(c_binary, binary);
|
||||
|
@ -23,7 +23,7 @@
|
||||
using namespace LIEF::MachO;
|
||||
|
||||
Macho_Binary_t** macho_parse(const char *file) {
|
||||
FatBinary* macho_binaries = Parser::parse(file);
|
||||
FatBinary* macho_binaries = Parser::parse(file).release();
|
||||
|
||||
Macho_Binary_t** c_macho_binaries = static_cast<Macho_Binary_t**>(
|
||||
malloc((macho_binaries->size() + 1) * sizeof(Macho_Binary_t**)));
|
||||
|
@ -50,7 +50,7 @@ void init_c_binary(Pe_Binary_t* c_binary, Binary* binary) {
|
||||
}
|
||||
|
||||
Pe_Binary_t* pe_parse(const char *file) {
|
||||
Binary* binary = Parser::parse(file);
|
||||
Binary* binary = Parser::parse(file).release();
|
||||
Pe_Binary_t* c_binary = static_cast<Pe_Binary_t*>(malloc(sizeof(Pe_Binary_t)));
|
||||
std::memset(c_binary, 0, sizeof(Pe_Binary_t));
|
||||
init_c_binary(c_binary, binary);
|
||||
|
@ -27,13 +27,13 @@ void create<Parser>(py::module& m) {
|
||||
|
||||
// Parser (Parser)
|
||||
m.def("parse",
|
||||
static_cast<File* (*) (const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<File> (*) (const std::string&)>(&Parser::parse),
|
||||
"Parse the given filename and return an " RST_CLASS_REF(lief.ART.File) " object"
|
||||
"filename"_a,
|
||||
py::return_value_policy::take_ownership);
|
||||
|
||||
m.def("parse",
|
||||
static_cast<File* (*) (const std::vector<uint8_t>&, const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<File> (*) (const std::vector<uint8_t>&, const std::string&)>(&Parser::parse),
|
||||
"Parse the given raw data and return an " RST_CLASS_REF(lief.ART.File) " object\n\n"
|
||||
"raw"_a, py::arg("name") = "",
|
||||
py::return_value_policy::take_ownership);
|
||||
|
@ -22,13 +22,13 @@
|
||||
void init_LIEF_Parser_class(py::module& m) {
|
||||
|
||||
m.def("parse",
|
||||
static_cast<LIEF::Binary* (*) (const std::string&)>(&LIEF::Parser::parse),
|
||||
static_cast<std::unique_ptr<LIEF::Binary> (*) (const std::string&)>(&LIEF::Parser::parse),
|
||||
"Parse the given binary and return a " RST_CLASS_REF(lief.Binary) " object",
|
||||
"filepath"_a,
|
||||
py::return_value_policy::take_ownership);
|
||||
|
||||
m.def("parse",
|
||||
static_cast<LIEF::Binary* (*) (const std::vector<uint8_t>&, const std::string&)>(&LIEF::Parser::parse),
|
||||
static_cast<std::unique_ptr<LIEF::Binary> (*) (const std::vector<uint8_t>&, const std::string&)>(&LIEF::Parser::parse),
|
||||
"Parse the given binary and return a " RST_CLASS_REF(lief.Binary) " object",
|
||||
"raw"_a, "name"_a = "",
|
||||
py::return_value_policy::take_ownership);
|
||||
|
@ -26,13 +26,13 @@ template<>
|
||||
void create<Parser>(py::module& m) {
|
||||
|
||||
m.def("parse",
|
||||
static_cast<File* (*) (const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<File> (*) (const std::string&)>(&Parser::parse),
|
||||
"Parse the given filename and return a " RST_CLASS_REF(lief.DEX.File) " object"
|
||||
"filename"_a,
|
||||
py::return_value_policy::take_ownership);
|
||||
|
||||
m.def("parse",
|
||||
static_cast<File* (*) (const std::vector<uint8_t>&, const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<File> (*) (const std::vector<uint8_t>&, const std::string&)>(&Parser::parse),
|
||||
"Parse the given raw data and return a " RST_CLASS_REF(lief.DEX.File) " object\n\n"
|
||||
"raw"_a, py::arg("name") = "",
|
||||
py::return_value_policy::take_ownership);
|
||||
|
@ -22,7 +22,7 @@ set(LIEF_PYTHON_ELF_SRC
|
||||
"${CMAKE_CURRENT_LIST_DIR}/objects/pyGnuHash.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/objects/pySysvHash.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/objects/pyBuilder.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/pyELFStructures.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/pyEnums.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/pySizes.cpp"
|
||||
)
|
||||
|
||||
|
@ -21,13 +21,17 @@
|
||||
#include "LIEF/ELF/hash.hpp"
|
||||
#include "LIEF/ELF/AndroidNote.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (AndroidNote::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (AndroidNote::*)(T);
|
||||
|
||||
void init_ELF_AndroidNote_class(py::module& m) {
|
||||
template<>
|
||||
void create<AndroidNote>(py::module& m) {
|
||||
|
||||
py::class_<AndroidNote, Note>(m, "AndroidNote")
|
||||
|
||||
@ -65,3 +69,6 @@ void init_ELF_AndroidNote_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,9 @@
|
||||
|
||||
#include "pyELF.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using no_const_getter = T (Binary::*)(void);
|
||||
|
||||
@ -33,7 +36,9 @@ using getter_t = T (Binary::*)(void) const;
|
||||
template<class T>
|
||||
using setter_t = void (Binary::*)(T);
|
||||
|
||||
void init_ELF_Binary_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<Binary>(py::module& m) {
|
||||
|
||||
// Binary object
|
||||
py::class_<Binary, LIEF::Binary>(m, "Binary", "ELF binary representation")
|
||||
@ -518,3 +523,5 @@ void init_ELF_Binary_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,11 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_ELF_Builder_class(py::module& m) {
|
||||
template<>
|
||||
void create<Builder>(py::module& m) {
|
||||
py::class_<Builder>(m, "Builder")
|
||||
.def(py::init<Binary*>(),
|
||||
"Constructor that takes a " RST_CLASS_REF(lief.ELF.Binary) "",
|
||||
@ -47,3 +50,5 @@ void init_ELF_Builder_class(py::module& m) {
|
||||
py::return_value_policy::reference_internal);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,13 +21,18 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (DynamicEntry::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (DynamicEntry::*)(T);
|
||||
|
||||
void init_ELF_DynamicEntry_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<DynamicEntry>(py::module& m) {
|
||||
|
||||
// DynamicEntry object
|
||||
py::class_<DynamicEntry, LIEF::Object>(m, "DynamicEntry")
|
||||
@ -64,3 +69,6 @@ void init_ELF_DynamicEntry_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,18 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (DynamicEntryArray::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (DynamicEntryArray::*)(T);
|
||||
|
||||
void init_ELF_DynamicEntryArray_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<DynamicEntryArray>(py::module& m) {
|
||||
|
||||
// Dynamic Entry Array object
|
||||
py::class_<DynamicEntryArray, DynamicEntry>(m, "DynamicEntryArray")
|
||||
@ -92,3 +97,6 @@ void init_ELF_DynamicEntryArray_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,18 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (DynamicEntryFlags::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (DynamicEntryFlags::*)(T);
|
||||
|
||||
void init_ELF_DynamicEntryFlags_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<DynamicEntryFlags>(py::module& m) {
|
||||
|
||||
py::class_<DynamicEntryFlags, DynamicEntry>(m, "DynamicEntryFlags")
|
||||
.def(py::init<>())
|
||||
@ -96,3 +101,6 @@ void init_ELF_DynamicEntryFlags_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,18 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (DynamicEntryLibrary::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (DynamicEntryLibrary::*)(T);
|
||||
|
||||
void init_ELF_DynamicEntryLibrary_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<DynamicEntryLibrary>(py::module& m) {
|
||||
|
||||
//
|
||||
// Dynamic Entry Library object
|
||||
@ -63,3 +68,6 @@ void init_ELF_DynamicEntryLibrary_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,18 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (DynamicEntryRpath::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (DynamicEntryRpath::*)(T);
|
||||
|
||||
void init_ELF_DynamicEntryRpath_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<DynamicEntryRpath>(py::module& m) {
|
||||
|
||||
//
|
||||
// Dynamic Entry RPATH object
|
||||
@ -102,3 +107,6 @@ void init_ELF_DynamicEntryRpath_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,18 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (DynamicEntryRunPath::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (DynamicEntryRunPath::*)(T);
|
||||
|
||||
void init_ELF_DynamicEntryRunPath_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<DynamicEntryRunPath>(py::module& m) {
|
||||
|
||||
//
|
||||
// Dynamic Entry RUNPATH object
|
||||
@ -101,3 +106,6 @@ void init_ELF_DynamicEntryRunPath_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,18 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (DynamicSharedObject::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (DynamicSharedObject::*)(T);
|
||||
|
||||
void init_ELF_DynamicSharedObject_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<DynamicSharedObject>(py::module& m) {
|
||||
|
||||
//
|
||||
// Dynamic Shared Object object
|
||||
@ -62,3 +67,6 @@ void init_ELF_DynamicSharedObject_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include "LIEF/ELF/hash.hpp"
|
||||
#include "LIEF/ELF/GnuHash.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (GnuHash::*)(void) const;
|
||||
@ -28,7 +30,9 @@ using getter_t = T (GnuHash::*)(void) const;
|
||||
template<class T>
|
||||
using setter_t = void (GnuHash::*)(T);
|
||||
|
||||
void init_ELF_GnuHash_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<GnuHash>(py::module& m) {
|
||||
|
||||
py::class_<GnuHash, LIEF::Object>(m, "GnuHash")
|
||||
.def(py::init<>())
|
||||
@ -106,8 +110,8 @@ void init_ELF_GnuHash_class(py::module& m) {
|
||||
std::string str = stream.str();
|
||||
return str;
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,17 +21,19 @@
|
||||
#include "LIEF/ELF/hash.hpp"
|
||||
#include "LIEF/ELF/Header.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (Header::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (Header::*)(T);
|
||||
|
||||
void init_ELF_Header_class(py::module& m) {
|
||||
|
||||
//
|
||||
// Header object
|
||||
//
|
||||
template<>
|
||||
void create<Header>(py::module& m) {
|
||||
|
||||
py::class_<Header, LIEF::Object>(m, "Header")
|
||||
.def(py::init<>())
|
||||
|
||||
@ -194,3 +196,6 @@ void init_ELF_Header_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,13 +21,18 @@
|
||||
#include "LIEF/ELF/hash.hpp"
|
||||
#include "LIEF/ELF/Note.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (Note::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (Note::*)(T);
|
||||
|
||||
void init_ELF_Note_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<Note>(py::module& m) {
|
||||
|
||||
py::class_<Note, LIEF::Object>(m, "Note")
|
||||
.def(py::init<>(),
|
||||
@ -81,3 +86,6 @@ void init_ELF_Note_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,15 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
void init_ELF_Parser_class(py::module& m) {
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<>
|
||||
void create<Parser>(py::module& m) {
|
||||
|
||||
// Parser (Parser)
|
||||
m.def("parse",
|
||||
static_cast<Binary* (*) (const std::string&, DYNSYM_COUNT_METHODS)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<Binary> (*) (const std::string&, DYNSYM_COUNT_METHODS)>(&Parser::parse),
|
||||
"Parse the given binary and return a " RST_CLASS_REF(lief.ELF.Binary) " object\n\n"
|
||||
"For *weird* binaries (e.g sectionless) you can choose the method to use to count dynamic symbols "
|
||||
" (" RST_CLASS_REF(lief.ELF.DYNSYM_COUNT_METHODS) ")",
|
||||
@ -31,7 +35,7 @@ void init_ELF_Parser_class(py::module& m) {
|
||||
py::return_value_policy::take_ownership);
|
||||
|
||||
m.def("parse",
|
||||
static_cast<Binary* (*) (const std::vector<uint8_t>&, const std::string&, DYNSYM_COUNT_METHODS)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<Binary> (*) (const std::vector<uint8_t>&, const std::string&, DYNSYM_COUNT_METHODS)>(&Parser::parse),
|
||||
"Parse the given binary and return a " RST_CLASS_REF(lief.ELF.Binary) " object\n\n"
|
||||
"For *weird* binaries (e.g sectionless) you can choose the method to use to count dynamic symbols "
|
||||
" (" RST_CLASS_REF(lief.ELF.DYNSYM_COUNT_METHODS) ")",
|
||||
@ -76,3 +80,5 @@ void init_ELF_Parser_class(py::module& m) {
|
||||
"name"_a = "",
|
||||
py::return_value_policy::take_ownership);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,13 +21,19 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (Relocation::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (Relocation::*)(T);
|
||||
|
||||
void init_ELF_Relocation_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<Relocation>(py::module& m) {
|
||||
|
||||
// Relocation object
|
||||
py::class_<Relocation, LIEF::Relocation>(m, "Relocation")
|
||||
.def(py::init<>())
|
||||
@ -100,3 +106,6 @@ void init_ELF_Relocation_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (Section::*)(void) const;
|
||||
|
||||
@ -31,7 +34,9 @@ using setter_t = void (Section::*)(T);
|
||||
template<class T>
|
||||
using no_const_getter = T (Section::*)(void);
|
||||
|
||||
void init_ELF_Section_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<Section>(py::module& m) {
|
||||
|
||||
// Section object
|
||||
py::class_<Section, LIEF::Section>(m, "Section")
|
||||
@ -172,3 +177,6 @@ void init_ELF_Section_class(py::module& m) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,9 @@
|
||||
|
||||
#include "pyELF.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (Segment::*)(void) const;
|
||||
|
||||
@ -32,7 +35,8 @@ template<class T>
|
||||
using no_const_getter = T (Segment::*)(void);
|
||||
|
||||
|
||||
void init_ELF_Segment_class(py::module& m) {
|
||||
template<>
|
||||
void create<Segment>(py::module& m) {
|
||||
py::class_<Segment, LIEF::Object>(m, "Segment")
|
||||
|
||||
.def(py::init<>())
|
||||
@ -158,3 +162,6 @@ void init_ELF_Segment_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,18 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (Symbol::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (Symbol::*)(T);
|
||||
|
||||
void init_ELF_Symbol_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<Symbol>(py::module& m) {
|
||||
|
||||
py::class_<Symbol, LIEF::Symbol>(m, "Symbol")
|
||||
.def(py::init<>())
|
||||
@ -140,3 +145,6 @@ void init_ELF_Symbol_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,13 +21,18 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (SymbolVersion::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (SymbolVersion::*)(T);
|
||||
|
||||
void init_ELF_SymbolVersion_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<SymbolVersion>(py::module& m) {
|
||||
|
||||
py::class_<SymbolVersion, LIEF::Object>(m, "SymbolVersion")
|
||||
.def(py::init<>(),"Default constructor")
|
||||
@ -81,3 +86,6 @@ void init_ELF_SymbolVersion_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,13 +21,17 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (SymbolVersionAux::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (SymbolVersionAux::*)(T);
|
||||
|
||||
void init_ELF_SymbolVersionAux_class(py::module& m) {
|
||||
template<>
|
||||
void create<SymbolVersionAux>(py::module& m) {
|
||||
|
||||
// Symbol Version Auxiliary object
|
||||
py::class_<SymbolVersionAux, LIEF::Object>(m, "SymbolVersionAux",
|
||||
@ -56,3 +60,6 @@ void init_ELF_SymbolVersionAux_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,13 +21,18 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (SymbolVersionAuxRequirement::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (SymbolVersionAuxRequirement::*)(T);
|
||||
|
||||
void init_ELF_SymbolVersionAuxRequirement_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<SymbolVersionAuxRequirement>(py::module& m) {
|
||||
//
|
||||
// Symbol Version Requirement Auxiliary object
|
||||
//
|
||||
@ -61,3 +66,6 @@ void init_ELF_SymbolVersionAuxRequirement_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,9 @@
|
||||
#include "LIEF/ELF/hash.hpp"
|
||||
#include "LIEF/ELF/SymbolVersionDefinition.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (SymbolVersionDefinition::*)(void) const;
|
||||
|
||||
@ -30,7 +33,9 @@ using setter_t = void (SymbolVersionDefinition::*)(T);
|
||||
template<class T>
|
||||
using no_const_getter = T (SymbolVersionDefinition::*)(void);
|
||||
|
||||
void init_ELF_SymbolVersionDefinition_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<SymbolVersionDefinition>(py::module& m) {
|
||||
|
||||
py::class_<SymbolVersionDefinition, LIEF::Object>(m, "SymbolVersionDefinition",
|
||||
"Class which modelization of an entry defined in ``DT_VERDEF`` (or ``.gnu.version_d``)")
|
||||
@ -68,3 +73,6 @@ void init_ELF_SymbolVersionDefinition_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,9 @@
|
||||
|
||||
#include "pyELF.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (SymbolVersionRequirement::*)(void) const;
|
||||
|
||||
@ -30,7 +33,9 @@ using setter_t = void (SymbolVersionRequirement::*)(T);
|
||||
template<class T>
|
||||
using no_const_getter = T (SymbolVersionRequirement::*)(void);
|
||||
|
||||
void init_ELF_SymbolVersionRequirement_class(py::module& m) {
|
||||
|
||||
template<>
|
||||
void create<SymbolVersionRequirement>(py::module& m) {
|
||||
|
||||
// Symbol Version Requirement object
|
||||
py::class_<SymbolVersionRequirement, LIEF::Object>(m, "SymbolVersionRequirement",
|
||||
@ -66,3 +71,6 @@ void init_ELF_SymbolVersionRequirement_class(py::module& m) {
|
||||
return str;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include "LIEF/ELF/hash.hpp"
|
||||
#include "LIEF/ELF/SysvHash.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (SysvHash::*)(void) const;
|
||||
@ -28,7 +30,8 @@ using getter_t = T (SysvHash::*)(void) const;
|
||||
template<class T>
|
||||
using setter_t = void (SysvHash::*)(T);
|
||||
|
||||
void init_ELF_SysvHash_class(py::module& m) {
|
||||
template<>
|
||||
void create<SysvHash>(py::module& m) {
|
||||
|
||||
py::class_<SysvHash, LIEF::Object>(m, "SysvHash")
|
||||
.def(py::init<>())
|
||||
@ -72,3 +75,5 @@ void init_ELF_SysvHash_class(py::module& m) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,39 +15,14 @@
|
||||
*/
|
||||
#include "pyELF.hpp"
|
||||
|
||||
//
|
||||
// ELF modules
|
||||
//
|
||||
void init_ELF_module(py::module& m) {
|
||||
py::module LIEF_ELF_module = m.def_submodule("ELF", "Python API for ELF");
|
||||
// Enums
|
||||
init_ELF_Structures_enum(LIEF_ELF_module);
|
||||
|
||||
// Objects
|
||||
init_ELF_Parser_class(LIEF_ELF_module);
|
||||
init_ELF_SymbolVersion_class(LIEF_ELF_module);
|
||||
init_ELF_Binary_class(LIEF_ELF_module);
|
||||
init_ELF_Header_class(LIEF_ELF_module);
|
||||
init_ELF_Section_class(LIEF_ELF_module);
|
||||
init_ELF_Segment_class(LIEF_ELF_module);
|
||||
init_ELF_Symbol_class(LIEF_ELF_module);
|
||||
init_ELF_Relocation_class(LIEF_ELF_module);
|
||||
init_ELF_SymbolVersionAux_class(LIEF_ELF_module);
|
||||
init_ELF_SymbolVersionAuxRequirement_class(LIEF_ELF_module);
|
||||
init_ELF_SymbolVersionDefinition_class(LIEF_ELF_module);
|
||||
init_ELF_SymbolVersionRequirement_class(LIEF_ELF_module);
|
||||
init_ELF_DynamicEntry_class(LIEF_ELF_module);
|
||||
init_ELF_DynamicEntryLibrary_class(LIEF_ELF_module);
|
||||
init_ELF_DynamicSharedObject_class(LIEF_ELF_module);
|
||||
init_ELF_DynamicEntryArray_class(LIEF_ELF_module);
|
||||
init_ELF_DynamicEntryRpath_class(LIEF_ELF_module);
|
||||
init_ELF_DynamicEntryRunPath_class(LIEF_ELF_module);
|
||||
init_ELF_DynamicEntryFlags_class(LIEF_ELF_module);
|
||||
init_ELF_GnuHash_class(LIEF_ELF_module);
|
||||
init_ELF_SysvHash_class(LIEF_ELF_module);
|
||||
init_ELF_Builder_class(LIEF_ELF_module);
|
||||
init_ELF_Note_class(LIEF_ELF_module);
|
||||
init_ELF_AndroidNote_class(LIEF_ELF_module);
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
void init_python_module(py::module& m) {
|
||||
py::module LIEF_ELF_module = m.def_submodule("ELF", "Python API for ELF format");
|
||||
|
||||
init_enums(LIEF_ELF_module);
|
||||
init_objects(LIEF_ELF_module);
|
||||
|
||||
py::module LIEF_ELF32_module = LIEF_ELF_module.def_submodule("ELF32", "");
|
||||
init_ELF32_sizes(LIEF_ELF32_module);
|
||||
@ -55,3 +30,33 @@ void init_ELF_module(py::module& m) {
|
||||
py::module LIEF_ELF64_module = LIEF_ELF_module.def_submodule("ELF64", "");
|
||||
init_ELF64_sizes(LIEF_ELF64_module);
|
||||
}
|
||||
|
||||
void init_objects(py::module& m) {
|
||||
CREATE(Parser, m);
|
||||
CREATE(SymbolVersion, m);
|
||||
CREATE(Binary, m);
|
||||
CREATE(Header, m);
|
||||
CREATE(Section, m);
|
||||
CREATE(Segment, m);
|
||||
CREATE(Symbol, m);
|
||||
CREATE(Relocation, m);
|
||||
CREATE(SymbolVersionAux, m);
|
||||
CREATE(SymbolVersionAuxRequirement, m);
|
||||
CREATE(SymbolVersionDefinition,m );
|
||||
CREATE(SymbolVersionRequirement, m);
|
||||
CREATE(DynamicEntry, m);
|
||||
CREATE(DynamicEntryLibrary, m);
|
||||
CREATE(DynamicSharedObject, m);
|
||||
CREATE(DynamicEntryArray, m);
|
||||
CREATE(DynamicEntryRpath, m);
|
||||
CREATE(DynamicEntryRunPath, m);
|
||||
CREATE(DynamicEntryFlags, m);
|
||||
CREATE(GnuHash, m);
|
||||
CREATE(SysvHash, m);
|
||||
CREATE(Builder, m);
|
||||
CREATE(Note, m);
|
||||
CREATE(AndroidNote, m);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,39 +21,57 @@
|
||||
#include "LIEF/ELF/Builder.hpp"
|
||||
|
||||
#include "pyLIEF.hpp"
|
||||
using namespace LIEF::ELF;
|
||||
|
||||
void init_ELF_Parser_class(py::module&);
|
||||
void init_ELF_Binary_class(py::module&);
|
||||
void init_ELF_Header_class(py::module&);
|
||||
void init_ELF_Section_class(py::module&);
|
||||
void init_ELF_Segment_class(py::module&);
|
||||
void init_ELF_Symbol_class(py::module&);
|
||||
void init_ELF_Relocation_class(py::module&);
|
||||
void init_ELF_SymbolVersion_class(py::module&);
|
||||
void init_ELF_SymbolVersionAux_class(py::module&);
|
||||
void init_ELF_SymbolVersionRequirement_class(py::module&);
|
||||
void init_ELF_SymbolVersionDefinition_class(py::module&);
|
||||
void init_ELF_SymbolVersionAuxRequirement_class(py::module&);
|
||||
void init_ELF_DynamicEntry_class(py::module&);
|
||||
void init_ELF_DynamicEntryLibrary_class(py::module&);
|
||||
void init_ELF_DynamicSharedObject_class(py::module&);
|
||||
void init_ELF_DynamicEntryArray_class(py::module&);
|
||||
void init_ELF_DynamicEntryRpath_class(py::module&);
|
||||
void init_ELF_DynamicEntryRunPath_class(py::module&);
|
||||
void init_ELF_DynamicEntryFlags_class(py::module&);
|
||||
void init_ELF_GnuHash_class(py::module&);
|
||||
void init_ELF_SysvHash_class(py::module&);
|
||||
void init_ELF_Builder_class(py::module&);
|
||||
void init_ELF_Note_class(py::module&);
|
||||
void init_ELF_AndroidNote_class(py::module&);
|
||||
|
||||
// Enums
|
||||
void init_ELF_Structures_enum(py::module&);
|
||||
#define SPECIALIZE_CREATE(X) \
|
||||
template<> \
|
||||
void create<X>(py::module&)
|
||||
|
||||
#define CREATE(X,Y) create<X>(Y)
|
||||
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
template<class T>
|
||||
void create(py::module&);
|
||||
|
||||
void init_python_module(py::module& m);
|
||||
void init_objects(py::module&);
|
||||
void init_enums(py::module&);
|
||||
|
||||
void init_ELF32_sizes(py::module&);
|
||||
void init_ELF64_sizes(py::module&);
|
||||
|
||||
SPECIALIZE_CREATE(Parser);
|
||||
SPECIALIZE_CREATE(Binary);
|
||||
SPECIALIZE_CREATE(Header);
|
||||
SPECIALIZE_CREATE(Section);
|
||||
SPECIALIZE_CREATE(Segment);
|
||||
SPECIALIZE_CREATE(Symbol);
|
||||
SPECIALIZE_CREATE(Relocation);
|
||||
SPECIALIZE_CREATE(SymbolVersion);
|
||||
SPECIALIZE_CREATE(SymbolVersionAux);
|
||||
SPECIALIZE_CREATE(SymbolVersionRequirement);
|
||||
SPECIALIZE_CREATE(SymbolVersionDefinition);
|
||||
SPECIALIZE_CREATE(SymbolVersionAuxRequirement);
|
||||
SPECIALIZE_CREATE(DynamicEntry);
|
||||
SPECIALIZE_CREATE(DynamicEntryLibrary);
|
||||
SPECIALIZE_CREATE(DynamicSharedObject);
|
||||
SPECIALIZE_CREATE(DynamicEntryArray);
|
||||
SPECIALIZE_CREATE(DynamicEntryRpath);
|
||||
SPECIALIZE_CREATE(DynamicEntryRunPath);
|
||||
SPECIALIZE_CREATE(DynamicEntryFlags);
|
||||
SPECIALIZE_CREATE(GnuHash);
|
||||
SPECIALIZE_CREATE(SysvHash);
|
||||
SPECIALIZE_CREATE(Builder);
|
||||
SPECIALIZE_CREATE(Note);
|
||||
SPECIALIZE_CREATE(AndroidNote);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -21,7 +21,10 @@
|
||||
|
||||
#define PY_ENUM(x) to_string(x), x
|
||||
|
||||
void init_ELF_Structures_enum(py::module& m) {
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_enums(py::module& m) {
|
||||
|
||||
LIEF::enum_<ELF_CLASS>(m, "ELF_CLASS")
|
||||
.value(PY_ENUM(ELF_CLASS::ELFCLASSNONE))
|
||||
@ -1157,3 +1160,6 @@ void init_ELF_Structures_enum(py::module& m) {
|
||||
.value(PY_ENUM(ELF_SYMBOL_VISIBILITY::STV_PROTECTED));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
#include "pyELF.hpp"
|
||||
#include "LIEF/ELF/Structures.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
void init_ELF32_sizes(py::module& m) {
|
||||
enum SIZES : size_t {};
|
||||
py::enum_<SIZES>(m, "SIZES")
|
||||
@ -49,3 +51,6 @@ void init_ELF64_sizes(py::module& m) {
|
||||
.value("VERDAUX", static_cast<SIZES>(sizeof(Elf64_Verdaux)))
|
||||
.export_values();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ void init_MachO_Parser_class(py::module& m) {
|
||||
|
||||
// Parser (Parser)
|
||||
m.def("parse",
|
||||
static_cast<FatBinary* (*) (const std::string&, const ParserConfig&)>(&LIEF::MachO::Parser::parse),
|
||||
static_cast<std::unique_ptr<FatBinary> (*) (const std::string&, const ParserConfig&)>(&LIEF::MachO::Parser::parse),
|
||||
"Parse the given binary and return a " RST_CLASS_REF(lief.MachO.FatBinary) " object\n\n"
|
||||
|
||||
"One can configure the parsing with the ``config`` parameter. See " RST_CLASS_REF(lief.MachO.ParserConfig) "",
|
||||
@ -34,7 +34,7 @@ void init_MachO_Parser_class(py::module& m) {
|
||||
|
||||
|
||||
m.def("parse",
|
||||
static_cast<FatBinary* (*) (const std::vector<uint8_t>&, const std::string&, const ParserConfig&)>(&LIEF::MachO::Parser::parse),
|
||||
static_cast<std::unique_ptr<FatBinary> (*) (const std::vector<uint8_t>&, const std::string&, const ParserConfig&)>(&LIEF::MachO::Parser::parse),
|
||||
"Parse the given binary (from raw) and return a " RST_CLASS_REF(lief.MachO.FatBinary) " objects\n\n"
|
||||
|
||||
"One can configure the parsing with the ``config`` parameter. See " RST_CLASS_REF(lief.MachO.ParserConfig) "",
|
||||
|
@ -27,19 +27,19 @@ void create<Parser>(py::module& m) {
|
||||
|
||||
// Parser (Parser)
|
||||
m.def("parse",
|
||||
static_cast<Binary* (*) (const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<Binary> (*) (const std::string&)>(&Parser::parse),
|
||||
"Parse the given OAT file and return a " RST_CLASS_REF(lief.OAT.Binary) " object"
|
||||
"oat_file"_a,
|
||||
py::return_value_policy::take_ownership);
|
||||
|
||||
m.def("parse",
|
||||
static_cast<Binary* (*) (const std::string&, const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<Binary> (*) (const std::string&, const std::string&)>(&Parser::parse),
|
||||
"Parse the given OAT with its VDEX file and return a " RST_CLASS_REF(lief.OAT.Binary) " object"
|
||||
"oat_file"_a, "vdex_file"_a,
|
||||
py::return_value_policy::take_ownership);
|
||||
|
||||
m.def("parse",
|
||||
static_cast<Binary* (*) (const std::vector<uint8_t>&, const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<Binary> (*) (const std::vector<uint8_t>&, const std::string&)>(&Parser::parse),
|
||||
"Parse the given raw data and return a " RST_CLASS_REF(lief.OAT.Binary) " object\n\n"
|
||||
"raw"_a, py::arg("name") = "",
|
||||
py::return_value_policy::take_ownership);
|
||||
|
@ -22,13 +22,13 @@
|
||||
void init_PE_Parser_class(py::module& m) {
|
||||
|
||||
m.def("parse",
|
||||
static_cast<Binary* (*) (const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<Binary> (*) (const std::string&)>(&Parser::parse),
|
||||
"Parse the given binary and return a " RST_CLASS_REF(lief.PE.Binary) " object",
|
||||
py::arg("filename"),
|
||||
py::return_value_policy::take_ownership);
|
||||
|
||||
m.def("parse",
|
||||
static_cast<Binary* (*) (const std::vector<uint8_t>&, const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<Binary> (*) (const std::vector<uint8_t>&, const std::string&)>(&Parser::parse),
|
||||
"Parse the given binary and return a " RST_CLASS_REF(lief.PE.Binary) " object",
|
||||
py::arg("raw"), py::arg("name") = "",
|
||||
py::return_value_policy::take_ownership);
|
||||
|
@ -27,13 +27,13 @@ void create<Parser>(py::module& m) {
|
||||
|
||||
// Parser (Parser)
|
||||
m.def("parse",
|
||||
static_cast<File* (*) (const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<File> (*) (const std::string&)>(&Parser::parse),
|
||||
"Parse the given filename and return a " RST_CLASS_REF(lief.VDEX.File) " object"
|
||||
"filename"_a,
|
||||
py::return_value_policy::take_ownership);
|
||||
|
||||
m.def("parse",
|
||||
static_cast<File* (*) (const std::vector<uint8_t>&, const std::string&)>(&Parser::parse),
|
||||
static_cast<std::unique_ptr<File> (*) (const std::vector<uint8_t>&, const std::string&)>(&Parser::parse),
|
||||
"Parse the given raw data and return a " RST_CLASS_REF(lief.VDEX.File) " object\n\n"
|
||||
"raw"_a, py::arg("name") = "",
|
||||
py::return_value_policy::take_ownership);
|
||||
|
@ -17,6 +17,10 @@
|
||||
#include "LIEF/version.h"
|
||||
#include "pyLIEF.hpp"
|
||||
|
||||
#if defined(LIEF_ELF_SUPPORT)
|
||||
#include "ELF/pyELF.hpp"
|
||||
#endif
|
||||
|
||||
#if defined(LIEF_OAT_SUPPORT)
|
||||
#include "OAT/pyOAT.hpp"
|
||||
#endif
|
||||
@ -59,7 +63,7 @@ PYBIND11_MODULE(_pylief, LIEF_module) {
|
||||
|
||||
// Init the ELF module
|
||||
#if defined(LIEF_ELF_SUPPORT)
|
||||
init_ELF_module(LIEF_module);
|
||||
LIEF::ELF::init_python_module(LIEF_module);
|
||||
#endif
|
||||
|
||||
// Init the PE module
|
||||
|
@ -43,10 +43,6 @@ void init_LIEF_exceptions(py::module&);
|
||||
void init_LIEF_module(py::module&);
|
||||
void init_hash_functions(py::module&);
|
||||
|
||||
#if defined(LIEF_ELF_SUPPORT)
|
||||
void init_ELF_module(py::module&);
|
||||
#endif
|
||||
|
||||
#if defined(LIEF_PE_SUPPORT)
|
||||
void init_PE_module(py::module&);
|
||||
#endif
|
||||
|
@ -7,7 +7,6 @@ int main(int argc, char** argv) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
LIEF::Binary* binary = LIEF::Parser::parse(argv[1]);
|
||||
std::unique_ptr<LIEF::Binary> binary = LIEF::Parser::parse(argv[1]);
|
||||
std::cout << *binary << std::endl;
|
||||
delete binary;
|
||||
}
|
||||
|
@ -29,11 +29,10 @@ int main(int argc, char **argv) {
|
||||
std::chrono::time_point<std::chrono::system_clock> start, end;
|
||||
start = std::chrono::system_clock::now();
|
||||
|
||||
const LIEF::Binary* binary = LIEF::Parser::parse(argv[1]);
|
||||
std::unique_ptr<const LIEF::Binary> binary = LIEF::Parser::parse(argv[1]);
|
||||
|
||||
end = std::chrono::system_clock::now();
|
||||
|
||||
delete binary;
|
||||
|
||||
size_t elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
|
||||
std::cout << "[Parser] Time: " << std::dec << elapsed_seconds << "s" << std::endl;
|
||||
|
@ -32,8 +32,8 @@ namespace ART {
|
||||
//! @brief Class which parse an ART file and transform into a ART::File object
|
||||
class LIEF_API Parser {
|
||||
public:
|
||||
static File* parse(const std::string& file);
|
||||
static File* parse(const std::vector<uint8_t>& data, const std::string& name = "");
|
||||
static std::unique_ptr<File> parse(const std::string& file);
|
||||
static std::unique_ptr<File> parse(const std::vector<uint8_t>& data, const std::string& name = "");
|
||||
|
||||
Parser& operator=(const Parser& copy) = delete;
|
||||
Parser(const Parser& copy) = delete;
|
||||
|
@ -32,7 +32,7 @@ class LIEF_API Parser
|
||||
//! @warning If the target file is a FAT Mach0, it will
|
||||
//! return the **last** one
|
||||
//! @see LIEF::MachO::Parser::parse
|
||||
static Binary* parse(const std::string& filename);
|
||||
static std::unique_ptr<Binary> parse(const std::string& filename);
|
||||
|
||||
|
||||
//! @brief Construct an LIEF::Binary from the given raw data
|
||||
@ -40,7 +40,7 @@ class LIEF_API Parser
|
||||
//! @warning If the target file is a FAT Mach0, it will
|
||||
//! return the **last** one
|
||||
//! @see LIEF::MachO::Parser::parse
|
||||
static Binary* parse(const std::vector<uint8_t>& raw, const std::string& name = "");
|
||||
static std::unique_ptr<Binary> parse(const std::vector<uint8_t>& raw, const std::string& name = "");
|
||||
|
||||
protected:
|
||||
Parser(const std::string& file);
|
||||
|
@ -33,8 +33,8 @@ class Method;
|
||||
//! @brief Class which parse a DEX file and transform into a DEX::File object
|
||||
class LIEF_API Parser {
|
||||
public:
|
||||
static File* parse(const std::string& file);
|
||||
static File* parse(const std::vector<uint8_t>& data, const std::string& name = "");
|
||||
static std::unique_ptr<File> parse(const std::string& file);
|
||||
static std::unique_ptr<File> parse(const std::vector<uint8_t>& data, const std::string& name = "");
|
||||
|
||||
Parser& operator=(const Parser& copy) = delete;
|
||||
Parser(const Parser& copy) = delete;
|
||||
|
@ -73,7 +73,7 @@ class LIEF_API Parser : public LIEF::Parser {
|
||||
//! @param[in] file Path to the ELF binary
|
||||
//! @param[in] count_mtd Method used to count dynamic symbols. Default: LIEF::ELF::DYNSYM_COUNT_METHODS::COUNT_AUTO
|
||||
//! @Return LIEF::ELF::Binary
|
||||
static Binary* parse(const std::string& file, DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO);
|
||||
static std::unique_ptr<Binary> parse(const std::string& file, DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO);
|
||||
|
||||
//! @brief Parse the given raw data as an ELF binary and return a LIEF::ELF::Binary object
|
||||
//!
|
||||
@ -83,7 +83,7 @@ class LIEF_API Parser : public LIEF::Parser {
|
||||
//! @param[in] name Binary name (optional)
|
||||
//! @param[in] count_mtd Method used to count dynamic symbols. Default: LIEF::ELF::DYNSYM_COUNT_METHODS::COUNT_AUTO
|
||||
//! @Return LIEF::ELF::Binary
|
||||
static Binary* parse(const std::vector<uint8_t>& data, const std::string& name = "", DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO);
|
||||
static std::unique_ptr<Binary> parse(const std::vector<uint8_t>& data, const std::string& name = "", DYNSYM_COUNT_METHODS count_mtd = DYNSYM_COUNT_METHODS::COUNT_AUTO);
|
||||
|
||||
Parser& operator=(const Parser& copy) = delete;
|
||||
Parser(const Parser& copy) = delete;
|
||||
|
@ -39,8 +39,8 @@ class LIEF_API Parser : public LIEF::Parser {
|
||||
|
||||
~Parser(void);
|
||||
|
||||
static FatBinary* parse(const std::string& filename, const ParserConfig& conf = ParserConfig::deep());
|
||||
static FatBinary* parse(const std::vector<uint8_t>& data, const std::string& name = "", const ParserConfig& conf = ParserConfig::deep());
|
||||
static std::unique_ptr<FatBinary> parse(const std::string& filename, const ParserConfig& conf = ParserConfig::deep());
|
||||
static std::unique_ptr<FatBinary> parse(const std::vector<uint8_t>& data, const std::string& name = "", const ParserConfig& conf = ParserConfig::deep());
|
||||
|
||||
private:
|
||||
Parser(const std::string& file, const ParserConfig& conf);
|
||||
|
@ -40,10 +40,10 @@ namespace OAT {
|
||||
class LIEF_API Parser : public LIEF::Parser {
|
||||
public:
|
||||
//! Parse an OAT file
|
||||
static Binary* parse(const std::string& oat_file);
|
||||
static Binary* parse(const std::string& oat_file, const std::string& vdex_file);
|
||||
static std::unique_ptr<Binary> parse(const std::string& oat_file);
|
||||
static std::unique_ptr<Binary> parse(const std::string& oat_file, const std::string& vdex_file);
|
||||
|
||||
static Binary* parse(const std::vector<uint8_t>& data, const std::string& name = "");
|
||||
static std::unique_ptr<Binary> parse(const std::vector<uint8_t>& data, const std::string& name = "");
|
||||
|
||||
Parser& operator=(const Parser& copy) = delete;
|
||||
Parser(const Parser& copy) = delete;
|
||||
|
@ -51,8 +51,8 @@ class LIEF_API Parser : public LIEF::Parser {
|
||||
|
||||
|
||||
public:
|
||||
static Binary* parse(const std::string& filename);
|
||||
static Binary* parse(const std::vector<uint8_t>& data, const std::string& name = "");
|
||||
static std::unique_ptr<Binary> parse(const std::string& filename);
|
||||
static std::unique_ptr<Binary> parse(const std::vector<uint8_t>& data, const std::string& name = "");
|
||||
|
||||
Parser& operator=(const Parser& copy) = delete;
|
||||
Parser(const Parser& copy) = delete;
|
||||
|
@ -32,8 +32,8 @@ namespace VDEX {
|
||||
//! @brief Class which parse an VDEX file and transform into a VDEX::File object
|
||||
class LIEF_API Parser {
|
||||
public:
|
||||
static File* parse(const std::string& file);
|
||||
static File* parse(const std::vector<uint8_t>& data, const std::string& name = "");
|
||||
static std::unique_ptr<File> parse(const std::string& file);
|
||||
static std::unique_ptr<File> parse(const std::vector<uint8_t>& data, const std::string& name = "");
|
||||
|
||||
Parser& operator=(const Parser& copy) = delete;
|
||||
Parser(const Parser& copy) = delete;
|
||||
|
@ -30,14 +30,14 @@ namespace ART {
|
||||
Parser::~Parser(void) = default;
|
||||
Parser::Parser(void) = default;
|
||||
|
||||
File* Parser::parse(const std::string& filename) {
|
||||
std::unique_ptr<File> Parser::parse(const std::string& filename) {
|
||||
Parser parser{filename};
|
||||
return parser.file_;
|
||||
return std::unique_ptr<File>{parser.file_};
|
||||
}
|
||||
|
||||
File* Parser::parse(const std::vector<uint8_t>& data, const std::string& name) {
|
||||
std::unique_ptr<File> Parser::parse(const std::vector<uint8_t>& data, const std::string& name) {
|
||||
Parser parser{data, name};
|
||||
return parser.file_;
|
||||
return std::unique_ptr<File>{parser.file_};
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ namespace ART {
|
||||
template<typename ART_T>
|
||||
void Parser::parse_file(void) {
|
||||
VLOG(VDEBUG) << "Parsing ART version " << std::dec << ART_T::art_version;
|
||||
const size_t ptr_size = this->parse_header<ART_T>();
|
||||
/* const size_t ptr_size = */ this->parse_header<ART_T>();
|
||||
}
|
||||
|
||||
template<typename ART_T>
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "LIEF/logging++.hpp"
|
||||
#include "LIEF/Abstract/Parser.hpp"
|
||||
|
||||
#include "LIEF/OAT.hpp"
|
||||
@ -35,7 +36,7 @@ Parser::Parser(void) :
|
||||
binary_name_{""}
|
||||
{}
|
||||
|
||||
Binary* Parser::parse(const std::string& filename) {
|
||||
std::unique_ptr<Binary> Parser::parse(const std::string& filename) {
|
||||
|
||||
#if defined(LIEF_OAT_SUPPORT)
|
||||
if (OAT::is_oat(filename)) {
|
||||
@ -59,21 +60,22 @@ Binary* Parser::parse(const std::string& filename) {
|
||||
#if defined(LIEF_MACHO_SUPPORT)
|
||||
if (MachO::is_macho(filename)) {
|
||||
// For fat binary we take the last one...
|
||||
MachO::FatBinary* fat = MachO::Parser::parse(filename);
|
||||
MachO::FatBinary* fat = MachO::Parser::parse(filename).release();
|
||||
MachO::Binary* binary_return = nullptr;
|
||||
if (fat) {
|
||||
binary_return = fat->pop_back();
|
||||
delete fat;
|
||||
}
|
||||
return binary_return;
|
||||
return std::unique_ptr<Binary>{binary_return};
|
||||
}
|
||||
#endif
|
||||
|
||||
throw bad_file("Unknown format");
|
||||
LOG(ERROR) << "Unknown format";
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
Binary* Parser::parse(const std::vector<uint8_t>& raw, const std::string& name) {
|
||||
std::unique_ptr<Binary> Parser::parse(const std::vector<uint8_t>& raw, const std::string& name) {
|
||||
|
||||
#if defined(LIEF_OAT_SUPPORT)
|
||||
if (OAT::is_oat(raw)) {
|
||||
@ -97,14 +99,19 @@ Binary* Parser::parse(const std::vector<uint8_t>& raw, const std::string& name)
|
||||
#if defined(LIEF_MACHO_SUPPORT)
|
||||
if (MachO::is_macho(raw)) {
|
||||
// For fat binary we take the last one...
|
||||
MachO::FatBinary* fat = MachO::Parser::parse(raw, name);
|
||||
MachO::Binary* binary_return = fat->pop_back();
|
||||
delete fat;
|
||||
return binary_return;
|
||||
MachO::FatBinary* fat = MachO::Parser::parse(raw, name).release();
|
||||
MachO::Binary* binary_return = nullptr;
|
||||
|
||||
if (fat) {
|
||||
binary_return = fat->pop_back();
|
||||
delete fat;
|
||||
}
|
||||
return std::unique_ptr<Binary>{binary_return};
|
||||
}
|
||||
#endif
|
||||
|
||||
throw bad_file("Unknown format");
|
||||
LOG(ERROR) << "Unknown format";
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,14 @@ namespace DEX {
|
||||
Parser::~Parser(void) = default;
|
||||
Parser::Parser(void) = default;
|
||||
|
||||
File* Parser::parse(const std::string& filename) {
|
||||
std::unique_ptr<File> Parser::parse(const std::string& filename) {
|
||||
Parser parser{filename};
|
||||
return parser.file_;
|
||||
return std::unique_ptr<File>{parser.file_};
|
||||
}
|
||||
|
||||
File* Parser::parse(const std::vector<uint8_t>& data, const std::string& name) {
|
||||
std::unique_ptr<File> Parser::parse(const std::vector<uint8_t>& data, const std::string& name) {
|
||||
Parser parser{data, name};
|
||||
return parser.file_;
|
||||
return std::unique_ptr<File>{parser.file_};
|
||||
}
|
||||
|
||||
|
||||
|
@ -370,14 +370,14 @@ void Parser::parse_class_data(uint32_t offset, Class* cls) {
|
||||
// =============
|
||||
for (size_t field_idx = 0, i = 0; i < static_fields_size; ++i) {
|
||||
field_idx += this->stream_->read_uleb128();
|
||||
uint64_t access_flags = this->stream_->read_uleb128();
|
||||
/* uint64_t access_flags = */ this->stream_->read_uleb128();
|
||||
}
|
||||
|
||||
// Instances
|
||||
// =========
|
||||
for (size_t field_idx = 0, i = 0; i < instance_fields_size; ++i) {
|
||||
field_idx += this->stream_->read_uleb128();
|
||||
uint64_t access_flags = this->stream_->read_uleb128();
|
||||
/* uint64_t access_flags = */ this->stream_->read_uleb128();
|
||||
}
|
||||
|
||||
// Direct Methods
|
||||
|
@ -146,17 +146,17 @@ void Parser::init(const std::string& name) {
|
||||
}
|
||||
}
|
||||
|
||||
Binary* Parser::parse(const std::string& filename, DYNSYM_COUNT_METHODS count_mtd) {
|
||||
std::unique_ptr<Binary> Parser::parse(const std::string& filename, DYNSYM_COUNT_METHODS count_mtd) {
|
||||
if (not is_elf(filename)) {
|
||||
LOG(ERROR) << filename << " is not an ELF";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Parser parser{filename, count_mtd};
|
||||
return parser.binary_;
|
||||
return std::unique_ptr<Binary>{parser.binary_};
|
||||
}
|
||||
|
||||
Binary* Parser::parse(
|
||||
std::unique_ptr<Binary> Parser::parse(
|
||||
const std::vector<uint8_t>& data,
|
||||
const std::string& name,
|
||||
DYNSYM_COUNT_METHODS count_mtd) {
|
||||
@ -167,7 +167,7 @@ Binary* Parser::parse(
|
||||
}
|
||||
|
||||
Parser parser{data, name, count_mtd};
|
||||
return parser.binary_;
|
||||
return std::unique_ptr<Binary>{parser.binary_};
|
||||
}
|
||||
|
||||
|
||||
|
@ -86,6 +86,15 @@ bool DataCodeEntry::operator!=(const DataCodeEntry& rhs) const {
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const DataCodeEntry& entry) {
|
||||
os << std::hex;
|
||||
os << std::left
|
||||
<< std::showbase
|
||||
|
||||
<< entry.offset() << " "
|
||||
<< entry.length() << " "
|
||||
<< to_string(entry.type());
|
||||
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
|
@ -52,13 +52,13 @@ Parser::Parser(const std::string& file, const ParserConfig& conf) :
|
||||
}
|
||||
|
||||
|
||||
FatBinary* Parser::parse(const std::string& filename, const ParserConfig& conf) {
|
||||
std::unique_ptr<FatBinary> Parser::parse(const std::string& filename, const ParserConfig& conf) {
|
||||
if (not is_macho(filename)) {
|
||||
throw bad_file("'" + filename + "' is not a MachO binary");
|
||||
}
|
||||
|
||||
Parser parser{filename, conf};
|
||||
return new FatBinary{parser.binaries_};
|
||||
return std::unique_ptr<FatBinary>{new FatBinary{parser.binaries_}};
|
||||
}
|
||||
|
||||
// From Vector
|
||||
@ -75,13 +75,13 @@ Parser::Parser(const std::vector<uint8_t>& data, const std::string& name, const
|
||||
}
|
||||
|
||||
|
||||
FatBinary* Parser::parse(const std::vector<uint8_t>& data, const std::string& name, const ParserConfig& conf) {
|
||||
std::unique_ptr<FatBinary> Parser::parse(const std::vector<uint8_t>& data, const std::string& name, const ParserConfig& conf) {
|
||||
if (not is_macho(data)) {
|
||||
throw bad_file("'" + name + "' is not a MachO binary");
|
||||
}
|
||||
|
||||
Parser parser{data, name, conf};
|
||||
return new FatBinary{parser.binaries_};
|
||||
return std::unique_ptr<FatBinary>{new FatBinary{parser.binaries_}};
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,7 +17,7 @@ Parser::~Parser(void) = default;
|
||||
Parser::Parser(void) = default;
|
||||
|
||||
|
||||
Binary* Parser::parse(const std::string& oat_file) {
|
||||
std::unique_ptr<Binary> Parser::parse(const std::string& oat_file) {
|
||||
if (not is_oat(oat_file)) {
|
||||
LOG(FATAL) << "'" + oat_file + "' is not an OAT";
|
||||
return nullptr;
|
||||
@ -25,11 +25,11 @@ Binary* Parser::parse(const std::string& oat_file) {
|
||||
|
||||
Parser parser{oat_file};
|
||||
parser.init(oat_file);
|
||||
return parser.oat_binary_;
|
||||
return std::unique_ptr<Binary>{parser.oat_binary_};
|
||||
}
|
||||
|
||||
|
||||
Binary* Parser::parse(const std::string& oat_file, const std::string& vdex_file) {
|
||||
std::unique_ptr<Binary> Parser::parse(const std::string& oat_file, const std::string& vdex_file) {
|
||||
if (not is_oat(oat_file)) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -38,16 +38,16 @@ Binary* Parser::parse(const std::string& oat_file, const std::string& vdex_file)
|
||||
return nullptr;
|
||||
}
|
||||
Parser parser{oat_file};
|
||||
parser.set_vdex(VDEX::Parser::parse(vdex_file));
|
||||
parser.set_vdex(VDEX::Parser::parse(vdex_file).release());
|
||||
parser.init(oat_file);
|
||||
return parser.oat_binary_;
|
||||
return std::unique_ptr<Binary>{parser.oat_binary_};
|
||||
|
||||
}
|
||||
|
||||
Binary* Parser::parse(const std::vector<uint8_t>& data, const std::string& name) {
|
||||
std::unique_ptr<Binary> Parser::parse(const std::vector<uint8_t>& data, const std::string& name) {
|
||||
Parser parser{data, name};
|
||||
parser.init(name);
|
||||
return parser.oat_binary_;
|
||||
return std::unique_ptr<Binary>{parser.oat_binary_};
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,9 +71,9 @@ void Parser::parse_dex_files<OAT131_t>(void) {
|
||||
|
||||
dex_file->lookup_table_offset(type_lookup_offset);
|
||||
|
||||
uint32_t dex_sections_layout_offset = this->stream_->read<uint32_t>();
|
||||
/* uint32_t dex_sections_layout_offset = */ this->stream_->read<uint32_t>();
|
||||
|
||||
uint32_t method_bss_mapping_offset = this->stream_->read<uint32_t>();
|
||||
/* uint32_t method_bss_mapping_offset = */ this->stream_->read<uint32_t>();
|
||||
|
||||
this->oat_binary_->oat_dex_files_.push_back(dex_file.release());
|
||||
}
|
||||
|
@ -782,15 +782,15 @@ void Parser::parse_overlay(void) {
|
||||
//
|
||||
// Return the Binary constructed
|
||||
//
|
||||
Binary* Parser::parse(const std::string& filename) {
|
||||
std::unique_ptr<Binary> Parser::parse(const std::string& filename) {
|
||||
Parser parser{filename};
|
||||
return parser.binary_;
|
||||
return std::unique_ptr<Binary>{parser.binary_};
|
||||
}
|
||||
|
||||
|
||||
Binary* Parser::parse(const std::vector<uint8_t>& data, const std::string& name) {
|
||||
std::unique_ptr<Binary> Parser::parse(const std::vector<uint8_t>& data, const std::string& name) {
|
||||
Parser parser{data, name};
|
||||
return parser.binary_;
|
||||
return std::unique_ptr<Binary>{parser.binary_};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,14 +30,14 @@ namespace VDEX {
|
||||
Parser::~Parser(void) = default;
|
||||
Parser::Parser(void) = default;
|
||||
|
||||
File* Parser::parse(const std::string& filename) {
|
||||
std::unique_ptr<File> Parser::parse(const std::string& filename) {
|
||||
Parser parser{filename};
|
||||
return parser.file_;
|
||||
return std::unique_ptr<File>{parser.file_};
|
||||
}
|
||||
|
||||
File* Parser::parse(const std::vector<uint8_t>& data, const std::string& name) {
|
||||
std::unique_ptr<File> Parser::parse(const std::vector<uint8_t>& data, const std::string& name) {
|
||||
Parser parser{data, name};
|
||||
return parser.file_;
|
||||
return std::unique_ptr<File>{parser.file_};
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user