From 0f4ce649ae5e0ddbc1307aed3a270588936d1b49 Mon Sep 17 00:00:00 2001 From: charadon Date: Tue, 27 Sep 2022 17:39:48 -0400 Subject: Initial Commit --- otool-tree | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 otool-tree 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" -- cgit 1.4.1-2-gfad0