Skip to content

Instantly share code, notes, and snippets.

@mu578
Created June 10, 2023 04:44
Show Gist options
  • Save mu578/52459df250e1f0c45698974583a52d50 to your computer and use it in GitHub Desktop.
Save mu578/52459df250e1f0c45698974583a52d50 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# # -*- coding: utf-8, tab-width: 3 -*-
# #
# ____ _____ ___ #
# | __|___ ) \ #
# _ _ _ _| |__ _/ /\ O / #
# | | | | | | |___ \( _)/ _ \ #
# | |_| | |_| |___) ) / ( (_) ) #
# | ._,_|\___/(____/_/ \___/ #
# | | #
# |_| #
# otweak.sh
#
# Copyright (C) 2023 mu578. All rights reserved.
#
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
otweak_binary_arch ()
{
if [ -z "{1}" ]; then
echo "<null:argument>"
else
local arch_=''
if [ ${platform} = "linux" ]; then
arch_=$(objdump -a "${1}" | grep "file format " | cut -d " " -f8)
fi
if [ ${platform} = "darwin" ]; then
arch_=$(lipo -info "${1}" | cut -d ":" -f3)
fi
if [ $? -eq 0 ]; then
echo "${arch_}"
else
echo "<null:command>"
fi
fi
}
otweak_binary_link ()
{
if [ -z "{1}" ]; then
echo "<null:argument>"
else
local link_=''
if [ ${platform} = "linux" ]; then
link_=$(ldd "${1}" | grep " => " | cut -d " " -f3)
if [ $? -eq 0 ]; then
echo "${link_}"
else
echo "<null:command>"
fi
elif [ ${platform} = "darwin" ]; then
link_=$(otool -L "${1}" | tr -d '\t' | cut -d ":" -f2)
item_=""
for i in ${link_}; do
if [ "${i##*.}" = "dylib" ]; then
item_="${item_}${i}\012"
fi
done
link_=$(echo ${item_} | sort -u)
if [ $? -eq 0 ]; then
echo "${link_:1}"
else
echo "<null:command>"
fi
fi
fi
}
r=$(otweak_binary_arch ${1})
echo ${r}
r=$(otweak_binary_link ${1})
echo "${r}"
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment