Skip to content

Instantly share code, notes, and snippets.

@fuzyll
Last active December 4, 2023 21:09
Show Gist options
  • Save fuzyll/4db8aa6e6a00cb1a60630370236aab4b to your computer and use it in GitHub Desktop.
Save fuzyll/4db8aa6e6a00cb1a60630370236aab4b to your computer and use it in GitHub Desktop.
Script to automatically create a MacOS Application Bundle out of a Ghidra release archive.
#!/usr/bin/env bash
# make_ghidra_app.sh | MacOS App Bundle Creator Script
#
# Copyright (c) 2019 Alexander Taylor <[email protected]>
#
# 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.
# this script is intended to be run from the same dir as the ghidra archive:
# ./make_ghidra_app.sh ghidra_9.1_PUBLIC_20191023.zip
SCRIPT=`basename "$0"`
# check for proper usage
if [ $# -ne 1 -o -z "$1" ]; then
echo "Usage: $SCRIPT <ghidra.zip>"
exit -1
fi
ARCHIVE="${1##*/}"
RELEASE="${ARCHIVE%_*}"
VERSION="${RELEASE#*_}"
ICON="$RELEASE/docs/GhidraClass/Beginner/Images/GhidraLogo64.png"
ICONSET="Ghidra.iconset"
# unpack Ghidra release
unzip -q "$ARCHIVE"
# create icon file
mkdir Ghidra.iconset
sips -z 16 16 "$ICON" --out "$ICONSET"/icon_16x16.png
sips -z 32 32 "$ICON" --out "$ICONSET"/[email protected]
sips -z 32 32 "$ICON" --out "$ICONSET"/icon_32x32.png
sips -z 64 64 "$ICON" --out "$ICONSET"/[email protected]
sips -z 128 128 "$ICON" --out "$ICONSET"/icon_128x128.png
sips -z 256 256 "$ICON" --out "$ICONSET"/[email protected]
sips -z 256 256 "$ICON" --out "$ICONSET"/icon_256x256.png
sips -z 512 512 "$ICON" --out "$ICONSET"/[email protected]
sips -z 512 512 "$ICON" --out "$ICONSET"/icon_512x512.png
cp "$ICON" "$ICONSET"/[email protected]
iconutil -c icns "$ICONSET"
rm -r "$ICONSET"
# create application bundle
mkdir -p Ghidra.app/Contents/{MacOS,Resources}
mv Ghidra.icns Ghidra.app/Contents/Resources/logo.icns
mv "$RELEASE"/* Ghidra.app/Contents/MacOS/
cat > Ghidra.app/Contents/Info.plist << EOF
{
CFBundleName = "ghidra";
CFBundleDisplayName = "Ghidra";
CFBundleIdentifier = "org.ghidra-sre";
CFBundleVersion = "$VERSION";
CFBundleShortVersionString = "${VERSION%%_*}";
CFBundleInfoDictionaryVersion = "6.0";
CFBundlePackageType = "APPL";
CFBundleExecutable = "ghidraRun";
CFBundleIconFile = "logo.icns";
}
EOF
rmdir "$RELEASE"
# running our app causes MacOS to put garbage on the CLI, which makes Ghidra
# think we're trying to open a project...so we'll remove that feature from the
# launcher since we can't actually access it anyway through the GUI
sed 's/"$@"//g' Ghidra.app/Contents/MacOS/ghidraRun > ghidraRun
chmod +x ghidraRun
mv -- ghidraRun Ghidra.app/Contents/MacOS/ghidraRun
@fuzyll
Copy link
Author

fuzyll commented Oct 7, 2023

Good catch. Fixed. Thanks!

@mahaloz
Copy link

mahaloz commented Dec 4, 2023

For anyone using subprocess.Popen("python3 ...") inside Ghidra, encountering strange errors about machine type for python packages and such (caused by some environment variables being dropped), you can fix it by making the entry point a new script:

#!/bin/bash
osascript -e 'tell app "Terminal" to do script "nohup ./ghidraRun & sleep 2 && exit"'

Then change CFBundleExecutable to the name of that new script. This will allow you to keep your env intact when you launch Ghidra from Spotlight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment