Skip to content

Commit 2e2f289

Browse files
committed
Identify ELF files using pyelftools
1 parent 52b48e0 commit 2e2f289

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/gardenlinux/build/exporter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import subprocess
88
from os import PathLike
99

10+
from elftools.common.exceptions import ELFError
1011
from elftools.elf.elffile import ELFFile
1112

1213
from ..logger import LoggerSetup
@@ -29,7 +30,11 @@ def _isElf(path: str) -> bool:
2930
"""
3031

3132
with open(path, "rb") as f:
32-
return f.read(4) == b"\x7f\x45\x4c\x46"
33+
try:
34+
ELFFile(f)
35+
return True
36+
except ELFError:
37+
return False
3338

3439

3540
def _getInterpreter(path: str, logger) -> str:

0 commit comments

Comments
 (0)