Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lief to 0.15.1 #137

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading