Skip to content

Instantly share code, notes, and snippets.

@shannah
Created February 17, 2024 15:18
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 shannah/ee01ab9024b9166510b00bcd7f248e31 to your computer and use it in GitHub Desktop.
Save shannah/ee01ab9024b9166510b00bcd7f248e31 to your computer and use it in GitHub Desktop.
Script to list all dylibs in an .app bundle that depend on JavaNativeFoundation
#!/bin/bash
# Usage message
usage() {
echo "Usage: $0 [-v] <directory>"
echo " -v Verbose mode. Display files and their JavaNativeFoundation dependencies."
}
# Check for verbose flag
VERBOSE=0
while getopts ":v" opt; do
case ${opt} in
v )
VERBOSE=1
;;
\? )
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
# Check if a directory was provided
if [ -z "$1" ]; then
usage
exit 1
fi
# Directory to search
SEARCH_DIR=$1
# Function to check and optionally display dependency
check_file() {
local file="$1"
local deps=$(otool -L "$file" 2>/dev/null | grep 'JavaNativeFoundation' || true)
if [[ ! -z "$deps" ]]; then
if [ "$VERBOSE" -eq 1 ]; then
echo "$file depends on:"
echo "$deps"
echo # empty line for better readability
else
echo "$file"
fi
fi
}
export -f check_file
export VERBOSE
# Find all dylibs and executables, then check each one
find "$SEARCH_DIR" \( -name "*.dylib" -o -perm +111 \) -type f -exec bash -c 'check_file "$0"' {} \;
# Example usage
bash check_jnf_linkage.sh /path/to/MyApp.app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment