mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-09 03:21:51 +00:00
binman: Add a way to check for a valid ELF file
Add a function which checks whether data is in ELF format or not. This will be used by binman to check this for entries. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
c8c9f3108a
commit
39f4a85bb2
2 changed files with 25 additions and 0 deletions
|
@ -518,3 +518,18 @@ def read_loadable_segments(data):
|
|||
rend = start + segment['p_filesz']
|
||||
segments.append((i, segment['p_paddr'], data[start:rend]))
|
||||
return segments, entry
|
||||
|
||||
def is_valid(data):
|
||||
"""Check if some binary data is a valid ELF file
|
||||
|
||||
Args:
|
||||
data (bytes): Bytes to check
|
||||
|
||||
Returns:
|
||||
bool: True if a valid Elf file, False if not
|
||||
"""
|
||||
try:
|
||||
DecodeElf(data, 0)
|
||||
return True
|
||||
except ELFError:
|
||||
return False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue