mirror of
https://github.com/QuasarApp/LIEF.git
synced 2025-05-12 19:39:32 +00:00
Add ELF dtor functions
This commit is contained in:
parent
31a4b19c54
commit
957384cd36
api/python/ELF/objects
include/LIEF
src
@ -477,6 +477,11 @@ void create<Binary>(py::module& m) {
|
||||
py::return_value_policy::reference)
|
||||
|
||||
|
||||
.def_property_readonly("dtor_functions",
|
||||
&Binary::dtor_functions,
|
||||
"Destuctor functions that are called the main execution")
|
||||
|
||||
|
||||
|
||||
.def(py::self += Segment())
|
||||
.def(py::self += Section())
|
||||
|
@ -44,7 +44,7 @@ class LIEF_API Binary : public Object {
|
||||
VA = 2, ///< Absolute
|
||||
};
|
||||
|
||||
using ctor_t = std::vector<uint64_t>;
|
||||
using functions_t = std::vector<uint64_t>;
|
||||
|
||||
public:
|
||||
Binary(void);
|
||||
@ -140,7 +140,7 @@ class LIEF_API Binary : public Object {
|
||||
virtual bool has_nx(void) const = 0;
|
||||
|
||||
//! Constructor functions that are called prior any other functions
|
||||
virtual LIEF::Binary::ctor_t ctor_functions(void) const = 0;
|
||||
virtual LIEF::Binary::functions_t ctor_functions(void) const = 0;
|
||||
|
||||
virtual std::ostream& print(std::ostream& os) const;
|
||||
|
||||
|
@ -460,7 +460,8 @@ class LIEF_API Binary : public LIEF::Binary {
|
||||
//! to ``true``
|
||||
void permute_dynamic_symbols(const std::vector<size_t>& permutation);
|
||||
|
||||
virtual LIEF::Binary::ctor_t ctor_functions(void) const override;
|
||||
virtual LIEF::Binary::functions_t ctor_functions(void) const override;
|
||||
LIEF::Binary::functions_t dtor_functions(void) const;
|
||||
|
||||
//! @brief ``true`` if the binary embed notes
|
||||
bool has_notes(void) const;
|
||||
@ -540,7 +541,7 @@ class LIEF_API Binary : public LIEF::Binary {
|
||||
Section& add_section(const Section& section);
|
||||
symbols_t static_dyn_symbols(void) const;
|
||||
|
||||
LIEF::Binary::ctor_t ctor_functions(DYNAMIC_TAGS tag) const;
|
||||
LIEF::Binary::functions_t tor_functions(DYNAMIC_TAGS tag) const;
|
||||
|
||||
//! The binary type
|
||||
//! (i.e. `ELF32` or `ELF64`)
|
||||
|
@ -416,7 +416,7 @@ class LIEF_API Binary : public LIEF::Binary {
|
||||
LoadCommand& operator[](LOAD_COMMAND_TYPES type);
|
||||
const LoadCommand& operator[](LOAD_COMMAND_TYPES type) const;
|
||||
|
||||
virtual LIEF::Binary::ctor_t ctor_functions(void) const override;
|
||||
virtual LIEF::Binary::functions_t ctor_functions(void) const override;
|
||||
|
||||
private:
|
||||
//! Default constructor
|
||||
|
@ -371,7 +371,7 @@ class LIEF_API Binary : public LIEF::Binary {
|
||||
//! @brief Check if the binary uses ``NX`` protection
|
||||
virtual bool has_nx(void) const override;
|
||||
|
||||
virtual LIEF::Binary::ctor_t ctor_functions(void) const override;
|
||||
virtual LIEF::Binary::functions_t ctor_functions(void) const override;
|
||||
|
||||
bool operator==(const Binary& rhs) const;
|
||||
bool operator!=(const Binary& rhs) const;
|
||||
|
@ -2084,42 +2084,34 @@ bool Binary::has_library(const std::string& name) const {
|
||||
}
|
||||
|
||||
|
||||
LIEF::Binary::ctor_t Binary::ctor_functions(DYNAMIC_TAGS tag) const {
|
||||
LIEF::Binary::ctor_t functions;
|
||||
LIEF::Binary::functions_t Binary::tor_functions(DYNAMIC_TAGS tag) const {
|
||||
LIEF::Binary::functions_t functions;
|
||||
if (this->has(tag)) {
|
||||
const DynamicEntryArray::array_t& array = this->get(tag).as<DynamicEntryArray>()->array();
|
||||
|
||||
//const uint64_t address = this->get(tag).value();
|
||||
//for (size_t i = 0; i < array.size(); ++i) {
|
||||
// const uint64_t entry_addr = address + i * sizeof(uint64_t);
|
||||
// std::cout << std::hex << entry_addr << std::endl;
|
||||
// const Relocation* relocation = this->get_relocation(entry_addr);
|
||||
// if (relocation != nullptr and relocation->addend() > 0) {
|
||||
// functions.push_back(entry_addr + relocation->addend());
|
||||
// } else {
|
||||
// functions.push_back(array[i]);
|
||||
// }
|
||||
//}
|
||||
std::move(
|
||||
std::begin(array),
|
||||
std::end(array),
|
||||
std::back_inserter(functions));
|
||||
|
||||
functions.reserve(array.size());
|
||||
for (uint64_t x : array) {
|
||||
if (x != 0 and
|
||||
static_cast<uint32_t>(x) != static_cast<uint32_t>(-1) and
|
||||
x != static_cast<uint64_t>(-1)
|
||||
) {
|
||||
functions.push_back(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
return functions;
|
||||
}
|
||||
|
||||
// Ctor
|
||||
LIEF::Binary::ctor_t Binary::ctor_functions(void) const {
|
||||
LIEF::Binary::ctor_t functions;
|
||||
LIEF::Binary::functions_t Binary::ctor_functions(void) const {
|
||||
LIEF::Binary::functions_t functions;
|
||||
|
||||
LIEF::Binary::ctor_t init = this->ctor_functions(DYNAMIC_TAGS::DT_INIT_ARRAY);
|
||||
LIEF::Binary::functions_t init = this->tor_functions(DYNAMIC_TAGS::DT_INIT_ARRAY);
|
||||
std::move(
|
||||
std::begin(init),
|
||||
std::end(init),
|
||||
std::back_inserter(functions));
|
||||
|
||||
LIEF::Binary::ctor_t preinit = this->ctor_functions(DYNAMIC_TAGS::DT_PREINIT_ARRAY);
|
||||
LIEF::Binary::functions_t preinit = this->tor_functions(DYNAMIC_TAGS::DT_PREINIT_ARRAY);
|
||||
std::move(
|
||||
std::begin(preinit),
|
||||
std::end(preinit),
|
||||
@ -2132,6 +2124,24 @@ LIEF::Binary::ctor_t Binary::ctor_functions(void) const {
|
||||
}
|
||||
|
||||
|
||||
LIEF::Binary::functions_t Binary::dtor_functions(void) const {
|
||||
|
||||
LIEF::Binary::functions_t functions;
|
||||
|
||||
LIEF::Binary::functions_t fini = this->tor_functions(DYNAMIC_TAGS::DT_FINI_ARRAY);
|
||||
std::move(
|
||||
std::begin(fini),
|
||||
std::end(fini),
|
||||
std::back_inserter(functions));
|
||||
|
||||
if (this->has(DYNAMIC_TAGS::DT_FINI)) {
|
||||
functions.push_back(this->get(DYNAMIC_TAGS::DT_FINI).value());
|
||||
}
|
||||
return functions;
|
||||
|
||||
}
|
||||
|
||||
|
||||
const Relocation* Binary::get_relocation(uint64_t address) const {
|
||||
auto&& it = std::find_if(
|
||||
std::begin(this->relocations_),
|
||||
|
@ -1371,8 +1371,8 @@ LIEF::Header Binary::get_abstract_header(void) const {
|
||||
}
|
||||
|
||||
|
||||
LIEF::Binary::ctor_t Binary::ctor_functions(void) const {
|
||||
LIEF::Binary::ctor_t functions;
|
||||
LIEF::Binary::functions_t Binary::ctor_functions(void) const {
|
||||
LIEF::Binary::functions_t functions;
|
||||
for (const Section& section : this->sections()) {
|
||||
if (section.type() != MACHO_SECTION_TYPES::S_MOD_INIT_FUNC_POINTERS) {
|
||||
continue;
|
||||
|
@ -1192,8 +1192,8 @@ const ResourcesManager Binary::resources_manager(void) const {
|
||||
}
|
||||
|
||||
|
||||
LIEF::Binary::ctor_t Binary::ctor_functions(void) const {
|
||||
LIEF::Binary::ctor_t functions;
|
||||
LIEF::Binary::functions_t Binary::ctor_functions(void) const {
|
||||
LIEF::Binary::functions_t functions;
|
||||
|
||||
if (this->has_tls()) {
|
||||
const std::vector<uint64_t>& clbs = this->tls().callbacks();
|
||||
|
Loading…
x
Reference in New Issue
Block a user