setup.sh introduce isELFExec, isELFDyn

These can be used to determine whether a ELF file with ELF header is an
executable or shared library.

We can't implement it in pure bash, as bash has problems with null
bytes.
This commit is contained in:
Florian Klink 2019-08-16 15:48:11 +02:00
parent d6ab8baa1b
commit e1b80a5a99

View File

@ -212,6 +212,18 @@ isELF() {
if [ "$magic" = $'\177ELF' ]; then return 0; else return 1; fi
}
# Return success if the specified file is an ELF object
# and its e_type is ET_EXEC (executable file)
isELFExec() {
grep -ao -P '^\177ELF.{11}\x00\x02' "$1" >/dev/null
}
# Return success if the specified file is an ELF object
# and its e_type is ET_DYN (shared object file)
isELFDyn() {
grep -ao -P '^\177ELF.{11}\x00\x03' "$1" >/dev/null
}
# Return success if the specified file is a script (i.e. starts with
# "#!").
isScript() {