Skip to content

Instantly share code, notes, and snippets.

@rcoup
Created April 24, 2023 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcoup/2e742a8792907c41c39938ceb9a4f036 to your computer and use it in GitHub Desktop.
Save rcoup/2e742a8792907c41c39938ceb9a4f036 to your computer and use it in GitHub Desktop.
ELF binary validation script
#!/bin/bash
set -eu
command -v eu-elflint >/dev/null || (echo "eu-elflint not found, install elfutils"; exit 1)
command -v scanelf >/dev/null || (echo "scanelf not found, install pax-utils"; exit 1)
BINARIES=$(scanelf -EET_EXEC -RBF %F "${1-.}")
ERRS=0
for BINARY in $BINARIES; do
echo -e "\n$BINARY"
if [[ "$(scanelf -k '.go.buildinfo' "$BINARY" -q)" == .go.buildinfo* ]]; then
# go binary
echo "... is a Golang binary. elflint will return errors"
fi
if ! eu-elflint --gnu-ld "$BINARY"; then
ERRS=$((ERRS+1))
fi
done
if [ "$ERRS" -gt 0 ]; then
echo -e "\n$ERRS errors encountered during ELF binary validation"
exit 1
else
echo -e "\nELF binaries validated ok"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment