Skip to content

Instantly share code, notes, and snippets.

@starkindustries
Forked from fuzyll/make_ghidra_app.sh
Created March 30, 2021 05:06
Show Gist options
  • Save starkindustries/85ed50c51317e3576c9c28827b1f3d47 to your computer and use it in GitHub Desktop.
Save starkindustries/85ed50c51317e3576c9c28827b1f3d47 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";
CFBundleIndentifier = "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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment