-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from mlocati/check-bits
Check bitness of generated binaries
- Loading branch information
Showing
4 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/bin/bash | ||
# | ||
# Script that checks if the binary files in a directory (and its sub-directoroes) | ||
# have the correct bitness | ||
# | ||
# Arguments: | ||
# $1: the number of bits (32, 64) | ||
# $2: the directory to be checked, or the path to a file | ||
# | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
BITS="${1:-}" | ||
case "$BITS" in | ||
32 | 64) | ||
;; | ||
'') | ||
echo 'Missing bitness' | ||
exit 1 | ||
;; | ||
*) | ||
printf 'Invalid bitness: %s\n' "$BITS" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
CHECK_ME="${2:-}" | ||
if [ -z "$CHECK_ME" ]; then | ||
echo 'Missing file/directory to be checked' | ||
exit 1 | ||
fi | ||
|
||
# Arguments: | ||
# $1: the file | ||
checkBits() | ||
{ | ||
local checkMe="$1" | ||
printf 'Checking %s... ' "$checkMe" | ||
local info="$(file -bEh -- "$checkMe" | head -n1)" | ||
case "$info" in | ||
PE32\ executable\ \(console\)\ Intel\ 80386*) | ||
printf '32-bit exe (console): ' | ||
if [ $BITS -ne 32 ]; then | ||
echo 'INVALID' | ||
return 1 | ||
fi | ||
echo 'OK' | ||
;; | ||
PE32\ executable\ \(GUI\)\ Intel\ 80386*) | ||
printf '32-bit exe (GUI): ' | ||
if [ $BITS -ne 32 ]; then | ||
echo 'INVALID' | ||
return 1 | ||
fi | ||
echo 'OK' | ||
;; | ||
PE32\ executable\ \(DLL\)\ \(console\)\ Intel\ 80386*) | ||
printf '32-bit dll: ' | ||
if [ $BITS -ne 32 ]; then | ||
echo 'INVALID' | ||
return 1 | ||
fi | ||
echo 'OK' | ||
;; | ||
PE32\+\ executable\ \(console\)\ x86-64*) | ||
printf '64-bit exe (console): ' | ||
if [ $BITS -ne 64 ]; then | ||
echo 'INVALID' | ||
return 1 | ||
fi | ||
echo 'OK' | ||
;; | ||
PE32\+\ executable\ \(GUI\)\ x86-64*) | ||
printf '64-bit exe (GUI): ' | ||
if [ $BITS -ne 64 ]; then | ||
echo 'INVALID' | ||
return 1 | ||
fi | ||
echo 'OK' | ||
;; | ||
PE32+\ executable\ \(DLL\)\ \(console\)\ x86-64*) | ||
printf '64-bit dll: ' | ||
if [ $BITS -ne 64 ]; then | ||
echo 'INVALID' | ||
return 1 | ||
fi | ||
echo 'OK' | ||
;; | ||
*) | ||
printf 'UNRECOGNISED INFO: %s\n' "$info" | ||
return 1 | ||
;; | ||
esac | ||
} | ||
|
||
if [ -d "$CHECK_ME" ]; then | ||
allOk=1 | ||
for f in $(find "$CHECK_ME" -type f -name *.dll -o -name *.exe); do | ||
if ! checkBits "$f"; then | ||
allOk=0 | ||
fi | ||
done | ||
if [ $allOk -ne 1 ]; then | ||
echo 'FAILURE!' | ||
exit 1 | ||
fi | ||
elif [ -f "$CHECK_ME" ]; then | ||
if ! checkBits "$CHECK_ME"; then | ||
echo 'FAILURE!' | ||
exit 1 | ||
fi | ||
else | ||
printf 'Unable to find the file or directory %s\n' "$CHECK_ME" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters