Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed May 8, 2024
1 parent 217f284 commit 275ea0c
Show file tree
Hide file tree
Showing 62 changed files with 471 additions and 817 deletions.
2 changes: 1 addition & 1 deletion api/python/src/Abstract/pySection.cpp
Expand Up @@ -51,7 +51,7 @@ void create<Section>(nb::module_& m) {
[] (const Section& obj) {
return safe_string(obj.name());
},
nb::overload_cast<const std::string&>(&Section::name),
nb::overload_cast<std::string>(&Section::name),
"Section's name"_doc)

.def_prop_ro("fullname",
Expand Down
2 changes: 1 addition & 1 deletion api/python/src/Abstract/pySymbol.cpp
Expand Up @@ -35,7 +35,7 @@ void create<Symbol>(nb::module_& m) {
[] (const Symbol& obj) {
return safe_string(obj.name());
},
nb::overload_cast<const std::string&>(&Symbol::name),
nb::overload_cast<std::string>(&Symbol::name),
"Symbol's name"_doc)

.def_prop_rw("value",
Expand Down
2 changes: 1 addition & 1 deletion api/python/src/PE/objects/pyDelayImportEntry.cpp
Expand Up @@ -43,7 +43,7 @@ void create<DelayImportEntry>(nb::module_& m) {
[] (const DelayImportEntry& obj) {
return LIEF::py::safe_string(obj.name());
},
nb::overload_cast<const std::string&>(&DelayImportEntry::name),
nb::overload_cast<std::string>(&DelayImportEntry::name),
"Delay import name if not ordinal"_doc)

.def_prop_rw("data",
Expand Down
2 changes: 1 addition & 1 deletion api/python/src/PE/objects/pyExportEntry.cpp
Expand Up @@ -43,7 +43,7 @@ void create<ExportEntry>(nb::module_& m) {
[] (const ExportEntry& obj) {
return LIEF::py::safe_string(obj.name());
},
nb::overload_cast<const std::string&>(&ExportEntry::name))
nb::overload_cast<std::string>(&ExportEntry::name))

.def_prop_rw("ordinal",
nb::overload_cast<>(&ExportEntry::ordinal, nb::const_),
Expand Down
2 changes: 1 addition & 1 deletion api/python/src/PE/objects/pyImportEntry.cpp
Expand Up @@ -56,7 +56,7 @@ void create<ImportEntry>(nb::module_& m) {
[] (const ImportEntry& obj) {
return LIEF::py::safe_string(obj.name());
},
nb::overload_cast<const std::string&>(&ImportEntry::name),
nb::overload_cast<std::string>(&ImportEntry::name),
"Import name if not ordinal"_doc)

.def_prop_rw("data",
Expand Down
2 changes: 1 addition & 1 deletion api/python/src/PE/objects/pySymbol.cpp
Expand Up @@ -33,7 +33,7 @@ void create<Symbol>(nb::module_& m) {

.def_prop_rw("name",
nb::overload_cast<>(&Symbol::wname, nb::const_),
nb::overload_cast<const std::string&>(&Symbol::name))
nb::overload_cast<std::string>(&Symbol::name))

.def_prop_ro("section_number",
&Symbol::section_number)
Expand Down
57 changes: 38 additions & 19 deletions include/LIEF/Abstract/Section.hpp
Expand Up @@ -20,7 +20,6 @@
#include <vector>
#include <ostream>

#include "LIEF/types.hpp"
#include "LIEF/span.hpp"
#include "LIEF/Object.hpp"
#include "LIEF/visibility.h"
Expand All @@ -31,45 +30,67 @@ class LIEF_API Section : public Object {
public:
static constexpr size_t npos = -1;

Section();
Section(std::string name);
Section() = default;
Section(std::string name) :
name_(std::move(name))
{}

~Section() override;
~Section() override = default;

Section& operator=(const Section&);
Section(const Section&);
Section& operator=(const Section&) = default;
Section(const Section&) = default;

//! section's name
virtual std::string name() const;
virtual std::string name() const {
return name_.c_str();
}

//! Return the **complete** section's name which might
//! trailing (``0``) bytes
virtual const std::string& fullname() const;
virtual const std::string& fullname() const {
return name_;
}

//! section's content
virtual span<const uint8_t> content() const;
virtual span<const uint8_t> content() const {
return {};
}

//! Change the section size
virtual void size(uint64_t size);
virtual void size(uint64_t size) {
size_ = size;
}

//! section's size (size in the binary, not the virtual size)
virtual uint64_t size() const;
virtual uint64_t size() const {
return size_;
}

//! Offset in the binary
virtual uint64_t offset() const;
virtual uint64_t offset() const {
return offset_;
}

//! Address where the section should be mapped
virtual uint64_t virtual_address() const;
virtual uint64_t virtual_address() const {
return virtual_address_;
}

virtual void virtual_address(uint64_t virtual_address);
virtual void virtual_address(uint64_t virtual_address) {
virtual_address_ = virtual_address;
}

//! Change the section's name
virtual void name(const std::string& name);
virtual void name(std::string name) {
name_ = std::move(name);
}

//! Change section content
virtual void content(const std::vector<uint8_t>& data);
virtual void content(const std::vector<uint8_t>&) {}

virtual void offset(uint64_t offset);
virtual void offset(uint64_t offset) {
offset_ = offset;
}

//! Section's entropy
double entropy() const;
Expand Down Expand Up @@ -104,8 +125,6 @@ class LIEF_API Section : public Object {
private:
template<typename T>
std::vector<size_t> search_all_(const T& v) const;


};
}

Expand Down
55 changes: 40 additions & 15 deletions include/LIEF/Abstract/Symbol.hpp
Expand Up @@ -27,30 +27,55 @@ namespace LIEF {
//! This class represents a symbol in an executable format.
class LIEF_API Symbol : public Object {
public:
Symbol();
Symbol(std::string name);
Symbol(std::string name, uint64_t value);
Symbol(std::string name, uint64_t value, uint64_t size);
Symbol(const Symbol&);
Symbol& operator=(const Symbol&);
~Symbol() override;
Symbol() = default;
Symbol(std::string name) :
name_(std::move(name))
{}
Symbol(std::string name, uint64_t value) :
name_(std::move(name)),
value_(value)
{}
Symbol(std::string name, uint64_t value, uint64_t size) :
name_(std::move(name)),
value_(value),
size_(size)
{}

void swap(Symbol& other);
Symbol(const Symbol&) = default;
Symbol& operator=(const Symbol&) = default;
~Symbol() override = default;

void swap(Symbol& other) noexcept;

//! Return the symbol's name
virtual const std::string& name() const;
virtual std::string& name();
virtual const std::string& name() const {
return name_;
}
virtual std::string& name() {
return name_;
}

//! Set symbol name
virtual void name(const std::string& name);
virtual void name(std::string name) {
name_ = std::move(name);
}

// Symbol's value which is usually the **address** of the symbol
virtual uint64_t value() const;
virtual void value(uint64_t value);
virtual uint64_t value() const {
return value_;
}
virtual void value(uint64_t value) {
value_ = value;
}

//! This size of the symbol (when applicable)
virtual uint64_t size() const;
virtual void size(uint64_t value);
virtual uint64_t size() const {
return size_;
}

virtual void size(uint64_t value) {
size_ = value;
}

//! Method so that the ``visitor`` can visit us
void accept(Visitor& visitor) const override;
Expand Down
8 changes: 5 additions & 3 deletions include/LIEF/ELF/Section.hpp
Expand Up @@ -154,7 +154,6 @@ class LIEF_API Section : public LIEF::Section {
return static_cast<uint64_t>(type) & TYPE_MASK;
}


Section(const std::string& name, TYPE type = TYPE::PROGBITS) :
LIEF::Section(name),
type_{type}
Expand All @@ -163,9 +162,12 @@ class LIEF_API Section : public LIEF::Section {
Section() = default;
~Section() override = default;

Section& operator=(Section other);
Section& operator=(Section other) {
swap(other);
return *this;
}
Section(const Section& other);
void swap(Section& other);
void swap(Section& other) noexcept;

TYPE type() const {
return type_;
Expand Down
4 changes: 1 addition & 3 deletions include/LIEF/MachO/BindingInfo.hpp
Expand Up @@ -16,13 +16,11 @@
#ifndef LIEF_MACHO_BINDING_INFO_H
#define LIEF_MACHO_BINDING_INFO_H
#include <ostream>
#include <cstdint>

#include "LIEF/visibility.h"
#include "LIEF/types.hpp"
#include "LIEF/Object.hpp"

#include "LIEF/MachO/enums.hpp"

namespace LIEF {
namespace MachO {
class DylibCommand;
Expand Down
6 changes: 5 additions & 1 deletion include/LIEF/MachO/ChainedBindingInfo.hpp
Expand Up @@ -102,7 +102,11 @@ class LIEF_API ChainedBindingInfo : public BindingInfo {

void accept(Visitor& visitor) const override;

LIEF_API friend std::ostream& operator<<(std::ostream& os, const ChainedBindingInfo& info);
LIEF_API friend
std::ostream& operator<<(std::ostream& os, const ChainedBindingInfo& info) {
os << static_cast<const BindingInfo&>(info);
return os;
}

private:
void clear();
Expand Down
6 changes: 5 additions & 1 deletion include/LIEF/MachO/DyldBindingInfo.hpp
Expand Up @@ -104,7 +104,11 @@ class LIEF_API DyldBindingInfo : public BindingInfo {

void accept(Visitor& visitor) const override;

LIEF_API friend std::ostream& operator<<(std::ostream& os, const DyldBindingInfo& binding_info);
LIEF_API friend
std::ostream& operator<<(std::ostream& os, const DyldBindingInfo& info) {
os << static_cast<const BindingInfo&>(info);
return os;
}

private:
CLASS class_ = CLASS::STANDARD;
Expand Down
2 changes: 1 addition & 1 deletion include/LIEF/MachO/Header.hpp
Expand Up @@ -130,7 +130,7 @@ class LIEF_API Header : public Object {
return filetype_;
}

//! Return the HEADER_FLAGS as a std::set
//! Return the FLAGS as a list
std::vector<FLAGS> flags_list() const;

//! Check if the given HEADER_FLAGS is present in the header's flags
Expand Down
5 changes: 4 additions & 1 deletion include/LIEF/MachO/LoadCommand.hpp
Expand Up @@ -158,7 +158,10 @@ class LIEF_API LoadCommand : public Object {

static bool is_linkedit_data(const LoadCommand& cmd);

LIEF_API friend std::ostream& operator<<(std::ostream& os, const LoadCommand& cmd);
LIEF_API friend
std::ostream& operator<<(std::ostream& os, const LoadCommand& cmd) {
return cmd.print(os);
}

protected:
raw_t original_data_;
Expand Down
43 changes: 29 additions & 14 deletions include/LIEF/PE/DelayImportEntry.hpp
Expand Up @@ -41,41 +41,56 @@ class LIEF_API DelayImportEntry : public LIEF::Symbol {
friend class Builder;

public:
DelayImportEntry();
DelayImportEntry(uint64_t data, PE_TYPE type);
DelayImportEntry() = default;
DelayImportEntry(uint64_t data, PE_TYPE type) :
data_(data),
type_(type)
{}

DelayImportEntry(const DelayImportEntry&);
DelayImportEntry& operator=(const DelayImportEntry&);
DelayImportEntry(const DelayImportEntry&) = default;
DelayImportEntry& operator=(const DelayImportEntry&) = default;

DelayImportEntry(DelayImportEntry&&);
DelayImportEntry& operator=(DelayImportEntry&&);
DelayImportEntry(DelayImportEntry&&) noexcept = default;
DelayImportEntry& operator=(DelayImportEntry&&) noexcept = default;

~DelayImportEntry() override;
~DelayImportEntry() override = default;

//!``True`` if it is an import by ordinal
bool is_ordinal() const;

//! The ordinal value
uint16_t ordinal() const;
uint16_t ordinal() const {
static constexpr auto MASK = 0xFFFF;
return data_ & MASK;
}

//! @see DelayImportEntry::data
uint64_t hint_name_rva() const;
uint64_t hint_name_rva() const {
return data();
}

//! Index into the Export::entries that is used to speed-up
//! the symbol resolution.
uint16_t hint() const;
uint16_t hint() const {
return hint_;
}

//! Value of the current entry in the Import Address Table.
uint64_t iat_value() const;
uint64_t iat_value() const {
return iat_value_;
}

//! Raw value
uint64_t data() const;
uint64_t data() const {
return data_;
}

void data(uint64_t data);
void data(uint64_t data) {
data_ = data;
}

void accept(Visitor& visitor) const override;


LIEF_API friend std::ostream& operator<<(std::ostream& os, const DelayImportEntry& entry);

private:
Expand Down

0 comments on commit 275ea0c

Please sign in to comment.