Skip to content

Commit

Permalink
Refactor the ELF Note support
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Nov 9, 2023
1 parent a7270ae commit 78c3196
Show file tree
Hide file tree
Showing 84 changed files with 3,859 additions and 4,015 deletions.
5 changes: 2 additions & 3 deletions api/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ message(STATUS "Python interpreter: ${Python_EXECUTABLE}")
nanobind_add_module(
pyLIEF
NB_STATIC

${CMAKE_CURRENT_SOURCE_DIR}/src/pyLIEF.cpp

# Do not default to -Os
NOMINSIZE

${CMAKE_CURRENT_SOURCE_DIR}/src/pyLIEF.cpp
)

add_subdirectory(src)
Expand Down
627 changes: 359 additions & 268 deletions api/python/lief/ELF.pyi

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions api/python/lief/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,18 @@ class lief_errors:
__name__: Any
def __init__(self, *args, **kwargs) -> None: ...

class ok_error_t:
def __init__(self, *args, **kwargs) -> None: ...
def __bool__(self) -> bool: ...
@property
def error(self) -> lief_errors: ...
@property
def is_error(self) -> bool: ...
@property
def is_value(self) -> bool: ...
@property
def value(self) -> lief.ok_t: ...

class ok_t:
def __init__(self, *args, **kwargs) -> None: ...
def __bool__(self) -> bool: ...
Expand Down
2 changes: 1 addition & 1 deletion api/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ homepage = "https://lief-project.github.io/"
documentation = "https://lief-project.github.io/doc/latest/"
repository = "https://github.com/lief-project/LIEF"
changelog = "https://lief-project.github.io/doc/latest/changelog.html"
Funding = "https://lief-project.github.io/about"
Funding = "https://github.com/sponsors/lief-project"
Tracker = "https://github.com/lief-project/LIEF/issues"
44 changes: 0 additions & 44 deletions api/python/src/ELF/enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1177,50 +1177,6 @@ void init_enums(nb::module_& m) {
.value(PY_ENUM(DYNSYM_COUNT_METHODS::COUNT_RELOCATIONS));


enum_<NOTE_TYPES>(m, "NOTE_TYPES")
.value(PY_ENUM(NOTE_TYPES::NT_UNKNOWN))
.value(PY_ENUM(NOTE_TYPES::NT_GNU_ABI_TAG))
.value(PY_ENUM(NOTE_TYPES::NT_GNU_HWCAP))
.value(PY_ENUM(NOTE_TYPES::NT_GNU_BUILD_ID))
.value(PY_ENUM(NOTE_TYPES::NT_GNU_GOLD_VERSION))
.value(PY_ENUM(NOTE_TYPES::NT_GNU_PROPERTY_TYPE_0))
.value(PY_ENUM(NOTE_TYPES::NT_GNU_BUILD_ATTRIBUTE_OPEN))
.value(PY_ENUM(NOTE_TYPES::NT_GNU_BUILD_ATTRIBUTE_FUNC))
.value(PY_ENUM(NOTE_TYPES::NT_CRASHPAD));


enum_<NOTE_TYPES_CORE>(m, "NOTE_TYPES_CORE")
.value(PY_ENUM(NOTE_TYPES_CORE::NT_CORE_UNKNOWN))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_PRSTATUS))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_PRFPREG))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_PRPSINFO))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_TASKSTRUCT))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_AUXV))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_SIGINFO))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_FILE))

.value(PY_ENUM(NOTE_TYPES_CORE::NT_ARM_VFP))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_ARM_TLS))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_ARM_HW_BREAK))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_ARM_HW_WATCH))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_ARM_SYSTEM_CALL))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_ARM_SVE))

.value(PY_ENUM(NOTE_TYPES_CORE::NT_386_TLS))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_386_IOPERM))
.value(PY_ENUM(NOTE_TYPES_CORE::NT_386_XSTATE));


enum_<NOTE_ABIS>(m, "NOTE_ABIS")
.value(PY_ENUM(NOTE_ABIS::ELF_NOTE_UNKNOWN))
.value(PY_ENUM(NOTE_ABIS::ELF_NOTE_OS_LINUX))
.value(PY_ENUM(NOTE_ABIS::ELF_NOTE_OS_GNU))
.value(PY_ENUM(NOTE_ABIS::ELF_NOTE_OS_SOLARIS2))
.value(PY_ENUM(NOTE_ABIS::ELF_NOTE_OS_FREEBSD))
.value(PY_ENUM(NOTE_ABIS::ELF_NOTE_OS_NETBSD))
.value(PY_ENUM(NOTE_ABIS::ELF_NOTE_OS_SYLLABLE));


enum_<RELOCATION_PURPOSES>(m, "RELOCATION_PURPOSES")
.value(PY_ENUM(RELOCATION_PURPOSES::RELOC_PURPOSE_NONE))
.value(PY_ENUM(RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT))
Expand Down
41 changes: 22 additions & 19 deletions api/python/src/ELF/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@
#include "LIEF/ELF/DynamicSharedObject.hpp"
#include "LIEF/ELF/GnuHash.hpp"
#include "LIEF/ELF/Header.hpp"
#include "LIEF/ELF/Note.hpp"
#include "LIEF/ELF/NoteDetails.hpp"
#include "LIEF/ELF/NoteDetails/AndroidNote.hpp"
#include "LIEF/ELF/NoteDetails/NoteAbi.hpp"
#include "LIEF/ELF/NoteDetails/core/CoreAuxv.hpp"
#include "LIEF/ELF/NoteDetails/core/CoreFile.hpp"
#include "LIEF/ELF/NoteDetails/core/CorePrPsInfo.hpp"
#include "LIEF/ELF/NoteDetails/core/CorePrStatus.hpp"
#include "LIEF/ELF/NoteDetails/core/CoreSigInfo.hpp"
#include "LIEF/ELF/Parser.hpp"
#include "LIEF/ELF/Relocation.hpp"
#include "LIEF/ELF/Section.hpp"
Expand All @@ -51,10 +42,30 @@
#include "LIEF/ELF/SysvHash.hpp"
#include "LIEF/ELF/utils.hpp"

#include "LIEF/ELF/Note.hpp"
#include "LIEF/ELF/NoteDetails/AndroidIdent.hpp"
#include "LIEF/ELF/NoteDetails/NoteAbi.hpp"
#include "LIEF/ELF/NoteDetails/core/CoreAuxv.hpp"
#include "LIEF/ELF/NoteDetails/core/CoreFile.hpp"
#include "LIEF/ELF/NoteDetails/core/CorePrPsInfo.hpp"
#include "LIEF/ELF/NoteDetails/core/CoreSigInfo.hpp"
#include "LIEF/ELF/NoteDetails/core/CorePrStatus.hpp"

#define CREATE(X,Y) create<X>(Y)

namespace LIEF::ELF::py {

void init_notes(nb::module_& m) {
CREATE(Note, m);
CREATE(AndroidIdent, m);
CREATE(NoteAbi, m);
CREATE(CoreAuxv, m);
CREATE(CoreFile, m);
CREATE(CorePrPsInfo, m);
CREATE(CoreSigInfo, m);
CREATE(CorePrStatus, m);
}

void init_objects(nb::module_& m) {
CREATE(ParserConfig, m);
CREATE(Parser, m);
Expand All @@ -79,16 +90,8 @@ void init_objects(nb::module_& m) {
CREATE(GnuHash, m);
CREATE(SysvHash, m);
CREATE(Builder, m);
CREATE(Note, m);
CREATE(NoteDetails, m);
CREATE(AndroidNote, m);
CREATE(NoteAbi, m);
CREATE(CorePrPsInfo, m);
CREATE(CoreFile, m);
CREATE(CoreFileEntry, m);
CREATE(CorePrStatus, m);
CREATE(CoreAuxv, m);
CREATE(CoreSigInfo, m);

init_notes(m);
}

inline void init_utils(nb::module_&) {
Expand Down
54 changes: 25 additions & 29 deletions api/python/src/ELF/objects/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
set(LIEF_PYTHON_ELF_OBJECT_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/pyParser.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyBinary.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyBuilder.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyDynamicEntry.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyDynamicEntryArray.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyDynamicEntryFlags.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyDynamicEntryLibrary.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyDynamicEntryRpath.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyDynamicEntryRunPath.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyDynamicSharedObject.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyGnuHash.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyHeader.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyParserConfig.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyNote.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyNoteDetails.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyRelocation.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pySection.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pySegment.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pySymbol.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pySymbolVersion.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pySymbolVersionAux.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pySymbolVersionAuxRequirement.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pySymbolVersionRequirement.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pySymbolVersionDefinition.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pySysvHash.cpp"
target_sources(pyLIEF PRIVATE
pyParser.cpp
pyBinary.cpp
pyBuilder.cpp
pyDynamicEntry.cpp
pyDynamicEntryArray.cpp
pyDynamicEntryFlags.cpp
pyDynamicEntryLibrary.cpp
pyDynamicEntryRpath.cpp
pyDynamicEntryRunPath.cpp
pyDynamicSharedObject.cpp
pyGnuHash.cpp
pyHeader.cpp
pyParserConfig.cpp
pyNote.cpp
pyRelocation.cpp
pySection.cpp
pySegment.cpp
pySymbol.cpp
pySymbolVersion.cpp
pySymbolVersionAux.cpp
pySymbolVersionAuxRequirement.cpp
pySymbolVersionRequirement.cpp
pySymbolVersionDefinition.cpp
pySysvHash.cpp
)

target_sources(pyLIEF PRIVATE ${LIEF_PYTHON_ELF_OBJECT_SRC})

add_subdirectory(NoteDetails)

8 changes: 3 additions & 5 deletions api/python/src/ELF/objects/NoteDetails/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
set(LIEF_PYTHON_ELF_NOTE_DETAILS_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/pyAndroidNote.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyNoteAbi.cpp"
target_sources(pyLIEF PRIVATE
pyAndroidIdent.cpp
pyNoteAbi.cpp
)

target_sources(pyLIEF PRIVATE "${LIEF_PYTHON_ELF_NOTE_DETAILS_SRC}")

add_subdirectory(core)

17 changes: 6 additions & 11 deletions api/python/src/ELF/objects/NoteDetails/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
set(LIEF_PYTHON_ELF_NOTE_DETAILS_CORE
"${CMAKE_CURRENT_SOURCE_DIR}/pyCorePrPsInfo.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyCoreFile.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyCoreFileEntry.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyCorePrStatus.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyCoreAuxv.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pyCoreSigInfo.cpp"
target_sources(pyLIEF PRIVATE
pyCorePrPsInfo.cpp
pyCoreFile.cpp
pyCorePrStatus.cpp
pyCoreAuxv.cpp
pyCoreSigInfo.cpp
)
target_sources(pyLIEF PRIVATE "${LIEF_PYTHON_ELF_NOTE_DETAILS_CORE}")



Loading

0 comments on commit 78c3196

Please sign in to comment.