Skip to content

Commit

Permalink
Merge pull request #27 from quarkslab/feature/upgrade-lief
Browse files Browse the repository at this point in the history
Add support for LIEF >= v0.14.0
  • Loading branch information
cnheitman authored May 9, 2024
2 parents c3674da + 3211017 commit e3c1757
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
23 changes: 15 additions & 8 deletions tritondse/loaders/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
# third-party imports
import lief

try:
# LIEF <= v0.13.2
EXE_FORMATS = lief.EXE_FORMATS
except AttributeError:
# LIEF >= v0.14.0
EXE_FORMATS = lief.Binary.FORMATS

# local imports
from tritondse.types import PathLike, Addr, Architecture, Platform, ArchMode, Perm, Endian
from tritondse.loaders.loader import Loader, LoadableSegment
Expand All @@ -20,9 +27,9 @@
}

_plfm_mapper = {
lief.EXE_FORMATS.ELF: Platform.LINUX,
lief.EXE_FORMATS.PE: Platform.WINDOWS,
lief.EXE_FORMATS.MACHO: Platform.MACOS
EXE_FORMATS.ELF: Platform.LINUX,
EXE_FORMATS.PE: Platform.WINDOWS,
EXE_FORMATS.MACHO: Platform.MACOS
}


Expand Down Expand Up @@ -107,11 +114,11 @@ def platform(self) -> Optional[Platform]:
return self._plfm

@property
def format(self) -> lief.EXE_FORMATS:
def format(self) -> EXE_FORMATS:
"""
Binary format. Supported formats by lief are: ELF, PE, MachO
:rtype: lief.EXE_FORMATS
:rtype: lief.EXE_FORMATS / lief.Binary.FORMATS
"""
return self._binary.format

Expand Down Expand Up @@ -171,7 +178,7 @@ def memory_segments(self) -> Generator[LoadableSegment, None, None]:
:return: Generator of tuples addrs and content
:raise NotImplementedError: if the binary format cannot be loaded
"""
if self.format == lief.EXE_FORMATS.ELF:
if self.format == EXE_FORMATS.ELF:
for i, seg in enumerate(self._binary.concrete.segments):
if seg.type == lief.ELF.SEGMENT_TYPES.LOAD:
content = bytearray(seg.content)
Expand All @@ -193,7 +200,7 @@ def imported_functions_relocations(self) -> Generator[Tuple[str, Addr], None, No
:return: Generator of tuples function name and relocation address
"""
if self.format == lief.EXE_FORMATS.ELF:
if self.format == EXE_FORMATS.ELF:
try:
# Iterate functions imported through PLT
for rel in self._binary.concrete.pltgot_relocations:
Expand All @@ -216,7 +223,7 @@ def imported_variable_symbols_relocations(self) -> Generator[Tuple[str, Addr], N
:return: Generator of tuples with symbol name, relocation address
"""
if self.format == lief.EXE_FORMATS.ELF:
if self.format == EXE_FORMATS.ELF:
rel_enum = self.relocation_enum
# Iterate imported symbols
for rel in self._binary.dynamic_relocations:
Expand Down
9 changes: 8 additions & 1 deletion tritondse/loaders/quokkaprogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import networkx
import lief

try:
# LIEF <= v0.13.2
EXE_FORMATS = lief.EXE_FORMATS
except AttributeError:
# LIEF >= v0.14.0
EXE_FORMATS = lief.Binary.FORMATS

# local imports
from tritondse.loaders import Program, LoadableSegment
from tritondse.coverage import CoverageSingleRun
Expand Down Expand Up @@ -100,7 +107,7 @@ def endianness(self) -> Endian:
return self.program.endianness

@property
def format(self) -> lief.EXE_FORMATS:
def format(self) -> EXE_FORMATS:
return self.program.format

@property
Expand Down

0 comments on commit e3c1757

Please sign in to comment.