Skip to content

Instantly share code, notes, and snippets.

@NullDev
Created January 16, 2020 14:42
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 NullDev/bc84c39d9c105f390e49098053f4cd73 to your computer and use it in GitHub Desktop.
Save NullDev/bc84c39d9c105f390e49098053f4cd73 to your computer and use it in GitHub Desktop.
Check if a windows binary (.exe) was compiled for 32 Bit or 64 Bit (useful for wine)

About

This script checks whether a windows binary (.exe file) was compiled ro 32 Bit or 64 Bit. If you mess around with Wine / PlayOnLinux a lot, this could be useful.

Usage

Making the script executable

chmod +x ./bincheck.sh

Using the Sript:

./bincheck.sh ./path/to/binary.exe
#!/bin/bash
if [[ $# -eq 0 ]]; then
echo "No file provided"
exit 1
fi
DATA=$(head "$1" | tr -d '\0')
echo "$DATA" | grep -E '(PE)(\s*)(L)' >> /dev/null
LOBIT=$?
echo "$DATA" | grep -E '(PE)(\s*)(d†)' >> /dev/null
HIBIT=$?
if [[ "$LOBIT" == 0 ]]; then
echo "This Binary is 32 Bit"
exit 0
elif [[ "$HIBIT" == 0 ]]; then
echo "This Binary is 64 Bit"
exit 0
else
echo "Couldn't determine wordlength"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment