about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorcharadon <charadon@charadons-MacBook-Pro.local>2022-09-27 17:39:48 -0400
committercharadon <charadon@charadons-MacBook-Pro.local>2022-09-27 17:39:48 -0400
commit0f4ce649ae5e0ddbc1307aed3a270588936d1b49 (patch)
tree8767d09ba788de3dd529f2034b092fea45d0fea5
downloadotool-tree-0f4ce649ae5e0ddbc1307aed3a270588936d1b49.tar.gz
Initial Commit
-rwxr-xr-xotool-tree65
1 files changed, 65 insertions, 0 deletions
diff --git a/otool-tree b/otool-tree
new file mode 100755
index 0000000..ed2f453
--- /dev/null
+++ b/otool-tree
@@ -0,0 +1,65 @@
+#!/bin/sh -eu
+
+export LIBRARY_LIST=""
+
+
+show_help() {
+	echo "USAGE: otool-tree (-l|-h) /path/to/binary"
+	echo "======================================================================"
+	echo "-l: Show License."
+	echo "-h: Show this screen"
+}
+
+show_license() {
+echo 'Copyright 2022 Charadon
+
+Licensed under the Apache License, Version 2.0 (the "License"); 
+you may not use this file except in compliance with the License. 
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software 
+distributed under the License is distributed on an "AS IS" BASIS, 
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+See the License for the specific language governing permissions and 
+limitations under the License.'
+}
+
+scan_lib() {
+	SCANLIB="$(otool -L "$1" | sed '1d' | awk '{print $1}')"
+	for i in $SCANLIB; do
+		if ! echo "$LIBRARY_LIST" | grep "$i" >/dev/null;
+		then
+			LIBRARY_LIST="$LIBRARY_LIST\n$i"
+			scan_lib "$i"
+		fi
+	done
+}
+
+while getopts "lh" options; do
+	case ${options} in
+		l)
+			show_license
+			exit 0
+			;;
+		*)
+			show_help
+			exit 0
+			;;
+	esac
+done
+
+# Make sure what we're looking at is a binary.
+if ! file "$1" | grep "bit executable" > /dev/null;
+then
+	if ! file "$1" | grep "shared library" > /dev/null;
+	then
+		echo "Not a valid binary. Exiting..."
+		exit 1
+	fi
+fi
+
+
+scan_lib "$1"
+echo "$LIBRARY_LIST"