Created
June 17, 2021 07:34
-
-
Save philip-lamb/73841f37227e226e435fddadda7bb48c to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
# | |
# Script to collect Windows dependent dynamic libraries. | |
# Run under a Cygwin or Windows Subsystem for Linux bash shell. | |
# | |
# Author(s): Philip Lamb | |
# | |
# Get our location. | |
OURDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
function usage { | |
echo "Usage: $(basename $0) [-v|--verbose] [--debug] path_to_dll [path_to_dll2 ...]" | |
exit 1 | |
} | |
# -e = exit on errors | |
set -e | |
# -x = debug | |
#set -x | |
# Parse parameters | |
while test $# -gt 0 | |
do | |
case "$1" in | |
--help) usage | |
;; | |
-h) usage | |
;; | |
--debug) DEBUG= | |
;; | |
--verbose) VERBOSE=1 | |
;; | |
-v) VERBOSE=1 | |
;; | |
--*) echo "bad option $1" | |
usage | |
;; | |
*) TARGETS="$TARGETS $1" | |
;; | |
esac | |
shift | |
done | |
if [ -z "$TARGETS" ]; then | |
echo "No target dll(s) specified." | |
exit 1; | |
fi | |
IGNORE_LIBS='\ | |
KERNEL32.dll \ | |
USER32.dll \ | |
SHELL32.dll \ | |
ADVAPI32.dll \ | |
WINMM.dll \ | |
WS2_32.dll \ | |
DNSAPI.dll \ | |
IPHLPAPI.DLL \ | |
ole32.dll \ | |
d3d11.dll \ | |
D3DCOMPILER_47.dll \ | |
dbghelp.dll \ | |
d3d9.dll \ | |
bcrypt.dll \ | |
api-ms-win-crt-string-l1-1-0.dll \ | |
api-ms-win-crt-heap-l1-1-0.dll \ | |
api-ms-win-crt-stdio-l1-1-0.dll \ | |
api-ms-win-crt-time-l1-1-0.dll \ | |
api-ms-win-crt-math-l1-1-0.dll \ | |
api-ms-win-crt-convert-l1-1-0.dll \ | |
api-ms-win-crt-utility-l1-1-0.dll \ | |
api-ms-win-crt-environment-l1-1-0.dll \ | |
api-ms-win-crt-locale-l1-1-0.dll \ | |
api-ms-win-crt-filesystem-l1-1-0.dll \ | |
api-ms-win-crt-process-l1-1-0.dll \ | |
api-ms-win-crt-conio-l1-1-0.dll \ | |
api-ms-win-crt-runtime-l1-1-0.dll \ | |
' | |
for ((i = 1; i <= $(echo -n $TARGETS | wc -w) ; i++)); do | |
target=$(echo -n $TARGETS | cut -d' ' -f$i) | |
deps_raw=$(objdump -p $target | grep "DLL Name: " | cut -d' ' -f3) | |
while IFS= read -r line; do | |
dep=$(echo -n $line) | |
# Don't bother if it's an ignored lib. | |
for ignore_lib in $IGNORE_LIBS | |
do | |
if [[ $dep == $ignore_lib ]]; then | |
continue 2; | |
fi | |
done | |
# We didn't match any of the system prefixes, so it's a user lib | |
# but is it already in the list of processed deps? | |
if ! [[ " $TARGETS " =~ " $dep " ]]; then | |
# Append to deps list if unique. | |
TARGETS="$TARGETS $dep" | |
fi | |
done <<< "$deps_raw" | |
done | |
echo $TARGETS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment