summaryrefslogtreecommitdiff
path: root/nsis/find_dlls.sh
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-05-08 17:58:28 -0400
committerLouie S <louie@example.com>2024-05-08 17:58:28 -0400
commitdbcb9aa93028db869f46fe1ce3639840a4e8f07b (patch)
treed4cfbf27ae0f09b0392c4f3e5040b2abc6d06aea /nsis/find_dlls.sh
parent6fbda841a690ad046a3005d43e349915cf8e0810 (diff)
Script to help find dlls
Diffstat (limited to 'nsis/find_dlls.sh')
-rwxr-xr-xnsis/find_dlls.sh82
1 files changed, 82 insertions, 0 deletions
diff --git a/nsis/find_dlls.sh b/nsis/find_dlls.sh
new file mode 100755
index 0000000..6e02688
--- /dev/null
+++ b/nsis/find_dlls.sh
@@ -0,0 +1,82 @@
+#!/usr/bin/env sh
+
+###############################################################################
+# Script to determine dll dependencies of a Windows executable file. #
+# This should help automate the process of locating dlls to include as part #
+# of an installer. #
+# #
+# This script is licensed under the GPLv3+ #
+# Written by Louie Shprung <lshprung@tutanota.com> #
+###############################################################################
+
+help() {
+ echo "Usage: $0 [OPTION]... BINARY..."
+ echo "Determine dlls required by BINARY (an .exe or .dll file)"
+ echo
+ echo "Options:"
+ echo " -h display this help message and exit"
+ echo " -q hide warnings"
+ echo " -s PATH set a path to search for dlls on. Default is \$PATH"
+}
+
+get_dll_path() {
+ (
+ IFS=':'
+ for path in $SEARCHPATH; do
+ if [ -e "$path/$1" ]; then
+ echo "$path/$1"
+ return 0
+ fi
+ done
+ echo "Warning: Could not locate '$1' on system"
+ return 1
+ )
+}
+
+print_dlls() {
+ while [ -n "$1" ]; do
+ DLL_NAMES=$(objdump -x "$1" | grep "DLL Name: " | sed 's/^[^D]*DLL Name: //')
+ for file in $DLL_NAMES; do
+ if DLL_PATH="$(get_dll_path "$file")"; then
+ echo "$DLL_PATH"
+ print_dlls "$DLL_PATH"
+ elif [ "$WARNINGS" -eq 1 ]; then
+ echo "$DLL_PATH"
+ fi
+ done
+ shift
+ done
+}
+
+SEARCHPATH="$PATH"
+WARNINGS=1
+
+# Check args
+while getopts "hqs:" flag; do
+ case "$flag" in
+ h)
+ help
+ exit
+ ;;
+ q)
+ WARNINGS=0
+ ;;
+ s)
+ SEARCHPATH="${OPTARG}"
+ ;;
+ *)
+ break
+ esac
+done
+shift $((OPTIND-1))
+
+if [ -z "$1" ]; then
+ help
+ exit 1
+fi
+
+if [ ! -e "$1" ]; then
+ >&2 echo "Error: '$1' does not exist - skipping"
+fi
+
+print_dlls "$@"