Skip to content

Commit

Permalink
Merge pull request #137 from tecknicaltom/lief-0.15.1
Browse files Browse the repository at this point in the history
Update lief to 0.15.1
  • Loading branch information
Wenzel authored Sep 17, 2024
2 parents f604f67 + 976d530 commit fe0aede
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 58 deletions.
37 changes: 15 additions & 22 deletions checksec/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import FrozenSet, List, Optional

import lief
from lief.ELF import E_TYPE

from .binary import BinarySecurity
from .errors import ErrorParsingFailed
Expand Down Expand Up @@ -118,20 +117,20 @@ def set_dyn_syms(self) -> FrozenSet[str]:

@property
def relro(self) -> RelroType:
if self.bin.get(lief.ELF.SEGMENT_TYPES.GNU_RELRO) is None:
if self.bin.get(lief.ELF.Segment.TYPE.GNU_RELRO) is None:
return RelroType.No

flags = self.bin.get(lief.ELF.DYNAMIC_TAGS.FLAGS)
flags = self.bin.get(lief.ELF.DynamicEntry.TAG.FLAGS)
if flags is None:
bind_now = False
else:
bind_now = lief.ELF.DYNAMIC_FLAGS.BIND_NOW in flags
bind_now = flags.has(lief.ELF.DynamicEntryFlags.FLAG.BIND_NOW)

flags_1 = self.bin.get(lief.ELF.DYNAMIC_TAGS.FLAGS_1)
flags_1 = self.bin.get(lief.ELF.DynamicEntry.TAG.FLAGS_1)
if flags_1 is None:
now = False
else:
now = lief.ELF.DYNAMIC_FLAGS_1.NOW in flags_1
now = flags_1.has(lief.ELF.DynamicEntryFlags.FLAG.NOW)

if bind_now or now:
return RelroType.Full
Expand All @@ -151,44 +150,38 @@ def has_canary(self) -> bool:

@property
def pie(self) -> PIEType:
if self.bin.header.file_type == E_TYPE.DYNAMIC:
if self.bin.has(lief.ELF.DYNAMIC_TAGS.DEBUG):
if self.bin.header.file_type == lief.ELF.Header.FILE_TYPE.DYN:
if self.bin.has(lief.ELF.DynamicEntry.TAG.DEBUG_TAG):
return PIEType.PIE
else:
return PIEType.DSO
elif self.bin.header.file_type == E_TYPE.RELOCATABLE:
elif self.bin.header.file_type == lief.ELF.Header.FILE_TYPE.REL:
return PIEType.REL
return PIEType.No

@property
def has_rpath(self) -> bool:
try:
if self.bin.get(lief.ELF.DYNAMIC_TAGS.RPATH):
return True
except lief.not_found:
pass
if self.bin.get(lief.ELF.DynamicEntry.TAG.RPATH):
return True
return False

@property
def has_runpath(self) -> bool:
try:
if self.bin.get(lief.ELF.DYNAMIC_TAGS.RUNPATH):
return True
except lief.not_found:
pass
if self.bin.get(lief.ELF.DynamicEntry.TAG.RUNPATH):
return True
return False

@property
@lru_cache()
def symbols(self) -> List[str]:
return [symbol.name for symbol in self.bin.static_symbols]
return [symbol.name for symbol in self.bin.symtab_symbols]

@property
def is_stripped(self) -> bool:
# TODO: hwo to reset static_symbols iterator for the next call to symbols() ?
# TODO: how to reset symtab_symbols iterator for the next call to symbols() ?
# consumes only the first symbol from iterator, saving CPU cycles
try:
next(self.bin.static_symbols)
next(self.bin.symtab_symbols)
except StopIteration:
return True
else:
Expand Down
4 changes: 2 additions & 2 deletions checksec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# cannot use is_elf because of circular dependency
import lief
from lief.logging import LOGGING_LEVEL as lief_loglvl
from lief.logging import LEVEL as lief_loglvl


class LibcNotFoundError(Exception):
Expand All @@ -33,7 +33,7 @@ class LibcNotFoundError(Exception):
0: lief_loglvl.TRACE,
logging.DEBUG: lief_loglvl.DEBUG,
logging.INFO: lief_loglvl.INFO,
logging.WARNING: lief_loglvl.WARNING,
logging.WARNING: lief_loglvl.WARN,
logging.ERROR: lief_loglvl.ERROR,
logging.CRITICAL: lief_loglvl.CRITICAL,
}
Expand Down
76 changes: 43 additions & 33 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ checksec = 'checksec.__main__:entrypoint'

[tool.poetry.dependencies]
python = ">=3.10,<3.13"
lief = "0.14.1"
lief = "0.15.1"
docopt = "0.6.2"
rich = "^13.4"
pylddwrap = "^1.0"
Expand Down

0 comments on commit fe0aede

Please sign in to comment.