Skip to content

Commit

Permalink
Refactor and clean code in LIEF's abstract layer
Browse files Browse the repository at this point in the history
Resolve #1119
  • Loading branch information
romainthomas committed Oct 26, 2024
1 parent 8784fb5 commit 4cc1dd2
Show file tree
Hide file tree
Showing 39 changed files with 838 additions and 1,227 deletions.
195 changes: 96 additions & 99 deletions api/python/lief/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,12 @@ import lief.Binary # type: ignore
import lief.DebugInfo # type: ignore
import lief.ELF # type: ignore
import lief.Function # type: ignore
import lief.Header # type: ignore
import lief.MachO # type: ignore
import lief.PE # type: ignore
import lief.logging # type: ignore
import os

class ARCHITECTURES:
ARM: ClassVar[ARCHITECTURES] = ...
ARM64: ClassVar[ARCHITECTURES] = ...
INTEL: ClassVar[ARCHITECTURES] = ...
LOONGARCH: ClassVar[ARCHITECTURES] = ...
MIPS: ClassVar[ARCHITECTURES] = ...
NONE: ClassVar[ARCHITECTURES] = ...
PPC: ClassVar[ARCHITECTURES] = ...
RISCV: ClassVar[ARCHITECTURES] = ...
SPARC: ClassVar[ARCHITECTURES] = ...
SYSZ: ClassVar[ARCHITECTURES] = ...
X86: ClassVar[ARCHITECTURES] = ...
XCORE: ClassVar[ARCHITECTURES] = ...
__name__: str
def __init__(self, *args, **kwargs) -> None: ...
@staticmethod
def from_value(arg: int, /) -> lief.ARCHITECTURES: ...
def __ge__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __hash__(self) -> int: ...
def __index__(self) -> Any: ...
def __int__(self) -> int: ...
def __le__(self, other) -> bool: ...
def __lt__(self, other) -> bool: ...
@property
def value(self) -> int: ...

class Binary(Object):
class FORMATS:
ELF: ClassVar[Binary.FORMATS] = ...
Expand Down Expand Up @@ -161,24 +135,6 @@ class DebugInfo:
@property
def format(self) -> lief.DebugInfo.FORMAT: ...

class ENDIANNESS:
BIG: ClassVar[ENDIANNESS] = ...
LITTLE: ClassVar[ENDIANNESS] = ...
NONE: ClassVar[ENDIANNESS] = ...
__name__: str
def __init__(self, *args, **kwargs) -> None: ...
@staticmethod
def from_value(arg: int, /) -> lief.ENDIANNESS: ...
def __ge__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __hash__(self) -> int: ...
def __index__(self) -> Any: ...
def __int__(self) -> int: ...
def __le__(self, other) -> bool: ...
def __lt__(self, other) -> bool: ...
@property
def value(self) -> int: ...

class Function(Symbol):
class FLAGS:
CONSTRUCTOR: ClassVar[Function.FLAGS] = ...
Expand Down Expand Up @@ -247,66 +203,107 @@ class Function(Symbol):
def flags_list(self) -> list[lief.Function.FLAGS]: ...

class Header(Object):
architecture: lief.ARCHITECTURES
endianness: lief.ENDIANNESS
entrypoint: int
modes: set[lief.MODES]
object_type: lief.OBJECT_TYPES
def __init__(self) -> None: ...
class ARCHITECTURES:
ARM: ClassVar[Header.ARCHITECTURES] = ...
ARM64: ClassVar[Header.ARCHITECTURES] = ...
LOONGARCH: ClassVar[Header.ARCHITECTURES] = ...
MIPS: ClassVar[Header.ARCHITECTURES] = ...
PPC: ClassVar[Header.ARCHITECTURES] = ...
RISCV: ClassVar[Header.ARCHITECTURES] = ...
SPARC: ClassVar[Header.ARCHITECTURES] = ...
SYSZ: ClassVar[Header.ARCHITECTURES] = ...
UNKNOWN: ClassVar[Header.ARCHITECTURES] = ...
X86: ClassVar[Header.ARCHITECTURES] = ...
X86_64: ClassVar[Header.ARCHITECTURES] = ...
XCORE: ClassVar[Header.ARCHITECTURES] = ...
__name__: str
def __init__(self, *args, **kwargs) -> None: ...
@staticmethod
def from_value(arg: int, /) -> lief.Header.ARCHITECTURES: ...
def __ge__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __hash__(self) -> int: ...
def __index__(self) -> Any: ...
def __int__(self) -> int: ...
def __le__(self, other) -> bool: ...
def __lt__(self, other) -> bool: ...
@property
def value(self) -> int: ...

class ENDIANNESS:
BIG: ClassVar[Header.ENDIANNESS] = ...
LITTLE: ClassVar[Header.ENDIANNESS] = ...
UNKNOWN: ClassVar[Header.ENDIANNESS] = ...
__name__: str
def __init__(self, *args, **kwargs) -> None: ...
@staticmethod
def from_value(arg: int, /) -> lief.Header.ENDIANNESS: ...
def __ge__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __hash__(self) -> int: ...
def __index__(self) -> Any: ...
def __int__(self) -> int: ...
def __le__(self, other) -> bool: ...
def __lt__(self, other) -> bool: ...
@property
def value(self) -> int: ...

class MODES:
ARM64E: ClassVar[Header.MODES] = ...
BITS_16: ClassVar[Header.MODES] = ...
BITS_32: ClassVar[Header.MODES] = ...
BITS_64: ClassVar[Header.MODES] = ...
NONE: ClassVar[Header.MODES] = ...
THUMB: ClassVar[Header.MODES] = ...
__name__: str
def __init__(self, *args, **kwargs) -> None: ...
@staticmethod
def from_value(arg: int, /) -> lief.Header.MODES: ...
def __ge__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __hash__(self) -> int: ...
def __index__(self) -> Any: ...
def __int__(self) -> int: ...
def __le__(self, other) -> bool: ...
def __lt__(self, other) -> bool: ...
@property
def value(self) -> int: ...

class OBJECT_TYPES:
EXECUTABLE: ClassVar[Header.OBJECT_TYPES] = ...
LIBRARY: ClassVar[Header.OBJECT_TYPES] = ...
OBJECT: ClassVar[Header.OBJECT_TYPES] = ...
UNKNOWN: ClassVar[Header.OBJECT_TYPES] = ...
__name__: str
def __init__(self, *args, **kwargs) -> None: ...
@staticmethod
def from_value(arg: int, /) -> lief.Header.OBJECT_TYPES: ...
def __ge__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __hash__(self) -> int: ...
def __index__(self) -> Any: ...
def __int__(self) -> int: ...
def __le__(self, other) -> bool: ...
def __lt__(self, other) -> bool: ...
@property
def value(self) -> int: ...
def __init__(self, *args, **kwargs) -> None: ...
@property
def architecture(self) -> lief.Header.ARCHITECTURES: ...
@property
def endianness(self) -> lief.Header.ENDIANNESS: ...
@property
def entrypoint(self) -> int: ...
@property
def is_32(self) -> bool: ...
@property
def is_64(self) -> bool: ...

class MODES:
ARM: ClassVar[MODES] = ...
M16: ClassVar[MODES] = ...
M32: ClassVar[MODES] = ...
M64: ClassVar[MODES] = ...
MCLASS: ClassVar[MODES] = ...
MIPS3: ClassVar[MODES] = ...
MIPS32: ClassVar[MODES] = ...
MIPS32R6: ClassVar[MODES] = ...
MIPS64: ClassVar[MODES] = ...
MIPSGP64: ClassVar[MODES] = ...
NONE: ClassVar[MODES] = ...
THUMB: ClassVar[MODES] = ...
UNDEFINED: ClassVar[MODES] = ...
V7: ClassVar[MODES] = ...
V8: ClassVar[MODES] = ...
V9: ClassVar[MODES] = ...
__name__: str
def __init__(self, *args, **kwargs) -> None: ...
@staticmethod
def from_value(arg: int, /) -> lief.MODES: ...
def __ge__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __hash__(self) -> int: ...
def __index__(self) -> Any: ...
def __int__(self) -> int: ...
def __le__(self, other) -> bool: ...
def __lt__(self, other) -> bool: ...
@property
def value(self) -> int: ...

class OBJECT_TYPES:
EXECUTABLE: ClassVar[OBJECT_TYPES] = ...
LIBRARY: ClassVar[OBJECT_TYPES] = ...
NONE: ClassVar[OBJECT_TYPES] = ...
OBJECT: ClassVar[OBJECT_TYPES] = ...
__name__: str
def __init__(self, *args, **kwargs) -> None: ...
@staticmethod
def from_value(arg: int, /) -> lief.OBJECT_TYPES: ...
def __ge__(self, other) -> bool: ...
def __gt__(self, other) -> bool: ...
def __hash__(self) -> int: ...
def __index__(self) -> Any: ...
def __int__(self) -> int: ...
def __le__(self, other) -> bool: ...
def __lt__(self, other) -> bool: ...
def modes(self) -> lief.Header.MODES: ...
@property
def value(self) -> int: ...
def modes_list(self) -> list[lief.Header.MODES]: ...
@property
def object_type(self) -> lief.Header.OBJECT_TYPES: ...

class Object:
def __init__(self, *args, **kwargs) -> None: ...
Expand Down
1 change: 0 additions & 1 deletion api/python/src/Abstract/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
target_sources(pyLIEF PRIVATE
init.cpp
enums.cpp
pyParser.cpp
pyHeader.cpp
pySymbol.cpp
Expand Down
69 changes: 0 additions & 69 deletions api/python/src/Abstract/enums.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions api/python/src/Abstract/enums.hpp

This file was deleted.

2 changes: 0 additions & 2 deletions api/python/src/Abstract/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
#include "pyLIEF.hpp"
#include "Abstract/init.hpp"
#include "Abstract/enums.hpp"

#include "LIEF/Abstract/Header.hpp"
#include "LIEF/Abstract/Binary.hpp"
Expand All @@ -41,7 +40,6 @@ void init_objects(nb::module_& m) {
CREATE(DebugInfo, m);
}
void init_abstract(nb::module_& m) {
init_enums(m);
init_objects(m);
}
}
1 change: 0 additions & 1 deletion api/python/src/Abstract/pyBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "LIEF/Abstract/Symbol.hpp"
#include "LIEF/Abstract/Section.hpp"
#include "LIEF/Abstract/Header.hpp"
#include "LIEF/Abstract/EnumToString.hpp"

#include "LIEF/Abstract/DebugInfo.hpp"

Expand Down
Loading

0 comments on commit 4cc1dd2

Please sign in to comment.