Created
April 22, 2021 18:10
-
-
Save ccawley2011/279294f4c23cdbcb876b6c7ee59ed770 to your computer and use it in GitHub Desktop.
Bash script to copy all DLLs needed by an application
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
#!/bin/sh | |
SKIP_DLLS= | |
DLL_PATH=/mingw/bin | |
OUTDIR=. | |
scan_executable() { | |
for i in `objdump -p $1 | grep 'DLL Name:' | cut -d ' ' -f 3`; do | |
if [[ ! "$SKIP_DLLS" =~ "$i" ]]; then | |
echo $1: $i | |
SKIP_DLLS="$SKIP_DLLS $i" | |
if [ -e $DLL_PATH/$i ]; then | |
cp $DLL_PATH/$i $OUTDIR/$i | |
scan_executable $OUTDIR/$i | |
fi | |
fi | |
done | |
} | |
for i in $@; do | |
case "$i" in | |
--output-dir=*) | |
OUTDIR=`echo $i | cut -d '=' -f 2` | |
;; | |
--search-path=*) | |
DLL_PATH=`echo $i | cut -d '=' -f 2` | |
;; | |
--help) | |
echo "Usage: $0 [OPTION]... [FILE]..." | |
echo "Copy all DLLs used by an application to the specified directory" | |
exit 1 | |
;; | |
--*) | |
echo "Unrecognised option: $i" | |
echo "Try '$0 --help' for more information" | |
exit 1 | |
;; | |
*) | |
scan_executable $i | |
;; | |
esac | |
done | |
if [[ "$@" == "" ]]; then | |
echo "No arguments provided" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment