File indexing completed on 2024-05-26 04:59:21

0001 #!/bin/bash
0002 
0003 set -e
0004 
0005 arch="$1"
0006 files=("${@:2}")
0007 
0008 _usage="Usage: nsi-installer.sh <arch> <exe>\n"
0009 [[ -z "$files" || -z "$arch" ]] && echo -e "$_usage" 1>&2 && exit 1
0010 for f in "${files[@]}"; do [[ ! -f "$f" ]] && echo -e "ERROR: File '$f' doesn't exist!\n" 1>&2 && exit 1 ; done
0011 
0012 processed=()
0013 exclude=(
0014         advapi32.dll
0015         avicap32.dll
0016         avrt.dll
0017         bcrypt.dll
0018         comdlg32.dll
0019         crypt32.dll
0020         dnsapi.dll
0021         dsound.dll
0022         dwmapi.dll
0023         gdi32.dll
0024         imm32.dll
0025         iphlpapi.dll
0026         kernel32.dll
0027         mpr.dll
0028         msimg32.dll
0029         msvcrt.dll
0030         netapi32.dll
0031         ole32.dll
0032         oleaut32.dll
0033         opengl32.dll
0034         secur32.dll
0035         setupapi.dll
0036         shell32.dll
0037         shlwapi.dll
0038         user32.dll
0039         userenv.dll
0040         uxtheme.dll
0041         usp10.dll
0042         version.dll
0043         winmm.dll
0044         winspool.drv
0045         ws2_32.dll
0046         wtsapi32.dll
0047 )
0048 
0049 debug() {
0050         echo -e "$@" | sed -Ee 's|(/.+)$|\x1b[1;39m\1\x1b[m|;s|(WARNING.+)$|\x1b[1;33m\1\x1b[m|;s|(ERROR.+)$|\x1b[1;31m\1\x1b[m|' 1>&2
0051 }
0052 
0053 finddeps() {
0054         deps=(`objdump -p "$1" | grep 'DLL Name' | sed -Ee 's|^.*DLL Name:\s([[:alnum:]].*[[:alnum:]])\s*$|\1|'`)
0055         for dll in "${deps[@]}"; do
0056                 dll="${dll,,}"
0057                 debug -n "$2'$dll'... "
0058                 # skip dlls we have already processed
0059                 [[ " ${processed[@]} " == *" $dll "* ]] && debug 'processed' && continue
0060                 # skip dlls we don't want
0061                 [[ " ${exclude[@]} " == *" $dll "* ]] && debug 'excluded' && continue
0062                 
0063                 # find full dll path
0064                 _dll=$(find "$(dirname "$1")/" "/usr/$arch/" -iname "$dll" 2>/dev/null | sort -u)
0065                 processed+=("$dll")
0066                 [[ -z "$_dll" ]] && debug "WARNING: Dependency '$dll' was not found." && continue
0067                 echo "$_dll"
0068                 debug "$_dll"
0069                 finddeps "$_dll" "\t$2"
0070         done
0071 }
0072 
0073 for f in "${files[@]}"; do finddeps "$f" ; done