Skip to content

Instantly share code, notes, and snippets.

@mahmoudimus
Last active January 14, 2023 23:13
Show Gist options
  • Save mahmoudimus/4c7459ad9282cc8595c211277b07b23b to your computer and use it in GitHub Desktop.
Save mahmoudimus/4c7459ad9282cc8595c211277b07b23b to your computer and use it in GitHub Desktop.
Ghidra Launch Properties (using ZGC)

Setting up Ghidra.

Setting up Debugger

Install llvm (brew install llvm), and gradle (brew install gradle).

Clone Ghidra source. Open terminal at this directory, type in gradle -I gradle/support/fetchDependencies.gradle init

Edit the ghidra/Ghirda/Debug/Debugger-swig-lldb/buildNatives.gradle file with VSCode. Replace all $llvm_dir/lldb/include with $llvm_dir/include. Save and close.

Go back to your Terminal and use the following commands:

cd ghidra/Ghidra/Debug/Debugger-swig-lldb
export JAVA_HOME=$(/usr/libexec/java_home)
export LLVM_HOME=$(brew --prefix llvm)
export LLVM_BUILD=$(brew --prefix llvm)
gradle build

Open your build/os/mac_arm_64 directory and copy libldb-java.dylib. I placed mine in /Users/(YOUR_NAME_HERE)/Library/Java/Extensions. If the directory path doesn't exist, just create it.

# Force Ghidra's Java home instead of trying to figure it out automatically.
# If the provided path does not point to a supported Java home that Ghidra
# supports, this property is ignored.
# NOTE: Ghidra requires a JDK to launch.
JAVA_HOME_OVERRIDE=
# GC tuning
VMARGS=-XX:+UnlockExperimentalVMOptions
VMARGS=-XX:+UseZGC
VMARGS=-XX:ParallelGCThreads=20
VMARGS=-XX:ConcGCThreads=6
# VMARGS=-XX:-ZUncommit
VMARGS=-XX:+UseLargePages
VMARGS=-XX:+IgnoreUnrecognizedVMOptions
VMARGS=-XX:+TieredCompilation
VMARGS=-XX:+UseDynamicNumberOfGCThreads
VMARGS=-XX:+HeapDumpOnOutOfMemoryError
VMARGS=-XX:-OmitStackTraceInFastThrow
VMARGS=-XX:ReservedCodeCacheSize=512m
VMARGS=-XX:SoftRefLRUPolicyMSPerMB=50
VMARGS=-XX:+UseStringCache
VMARGS=-XX:+UseStringDeduplication
VMARGS=-XX:+AggressiveOpts
VMARGS=-XX:+AlwaysPreTouch
VMARGS=-XX:+OptimizeStringConcat
VMARGS=-XX:+UseFastAccessorMethods
# Required Ghidra class loader
VMARGS=-Djava.system.class.loader=ghidra.GhidraClassLoader
# Set default encoding to UTF8
VMARGS=-Dfile.encoding=UTF8
# Set locale (only en_US is supported)
VMARGS=-Duser.country=US
VMARGS=-Duser.language=en
VMARGS=-Duser.variant=
# The following options affect rendering on different platforms. It may be necessary to play
# with these settings to get Ghidra to display and perform optimally on HiDPI monitors or in VM's.
VMARGS=-Dsun.java2d.opengl=false
VMARGS_LINUX=-Dsun.java2d.pmoffscreen=false
VMARGS_LINUX=-Dsun.java2d.xrender=true
VMARGS_LINUX=-Dsun.java2d.uiScale=1
VMARGS_LINUX=-Dawt.useSystemAAFontSettings=on
VMARGS_WINDOWS=-Dsun.java2d.d3d=false
# MacOS enhancements
VMARGS_MACOS=-Djava.net.preferIPv4Stack=true
VMARGS_MACOS=-Djdk.attach.allowAttachSelf=true
VMARGS_MACOS=-Dsun.io.useCanonCaches=false
VMARGS_MACOS=-Dsun.java2d.metal=true
VMARGS_MACOS=-Dsun.tools.attach.tmp.only=true
VMARGS_MACOS=-Dsun.awt.mac.a11y.enabled=false
# The Ghidra application establishes the default SSLContext for all
# secure client connections based upon Java's default TLS protocol enablement.
# Setting this property will restrict the enabled TLS protocol versions for
# all secure network connections. Specifying multiple protocols must be
# comma-separated (e.g., TLSv1.2,TLSv1.3). See https://java.com/en/configure_crypto.html
# for details on configuring Java's cryptographic algorithms.
VMARGS=-Djdk.tls.client.protocols=TLSv1.2,TLSv1.3
# Force PKI server authentication of all HTTPS and Ghidra Server connections by
# specifying path to installed CA certificates file.
# VMARGS=-Dghidra.cacerts=
# The following property will limit the number of processor cores that Ghidra
# will use for thread pools. If not specified, it will use the default number
# of processors returned from Runtime.getRuntime().getAvailableProcessors().
# Otherwise, it will use the min of the value returned from Runtime and the
# value specified by the following property.
VMARGS=-Dcpu.core.limit=
# The following property is a way to exactly specify the number of processor
# cores that Ghidra will use for thread pools. Note: this will supersede the
# above 'cpu.core.limit' value if it is set.
VMARGS=-Dcpu.core.override=
# Default font size for many java swing elements.
VMARGS=-Dfont.size.override=
# Set Jython console encoding (prevents a console error)
VMARGS=-Dpython.console.encoding=UTF-8
# Eclipse on macOS can have file locking issues if the user home directory is networked. Therefore,
# we will disable file locking by default for macOS. Comment the following line out if Eclipse file
# locking is needed and known to work.
VMARGS_MACOS=-Declipse.filelock.disable=true
# Where the menu bar is displayed on macOS
VMARGS_MACOS=-Dapple.laf.useScreenMenuBar=false
# Prevent log4j from using the Jansi DLL on Windows.
VMARGS_WINDOWS=-Dlog4j.skipJansi=true
# Custom class loader usage forces class data sharing to be disabled which produces a warning.
# Ghidra does not use class data sharing, so explicitly turn it off to avoid the warning.
VMARGS=-Xshare:off
# Permit "illegal reflective accesses" to enable JDK compatibility with Ghidra and 3rd party jars.
VMARGS=--add-opens=java.base/java.lang=ALL-UNNAMED
VMARGS=--add-opens=java.base/java.util=ALL-UNNAMED
VMARGS=--add-opens=java.base/java.net=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/sun.awt.image=ALL-UNNAMED
# Extras
VMARGS=--add-exports=java.desktop/com.apple.eawt.event=ALL-UNNAMED
VMARGS=--add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED
VMARGS=--add-exports=java.desktop/com.apple.laf=ALL-UNNAMED
VMARGS=--add-exports=java.desktop/sun.awt.image=ALL-UNNAMED
VMARGS=--add-exports=java.desktop/sun.font=ALL-UNNAMED
VMARGS=--add-opens=java.base/java.io=ALL-UNNAMED
VMARGS=--add-opens=java.base/java.lang.reflect=ALL-UNNAMED
VMARGS=--add-opens=java.base/java.nio.charset=ALL-UNNAMED
VMARGS=--add-opens=java.base/java.text=ALL-UNNAMED
VMARGS=--add-opens=java.base/java.time=ALL-UNNAMED
VMARGS=--add-opens=java.base/java.util.concurrent=ALL-UNNAMED
VMARGS=--add-opens=java.base/jdk.internal.org.objectweb.asm.tree=ALL-UNNAMED
VMARGS=--add-opens=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED
VMARGS=--add-opens=java.base/jdk.internal.vm=ALL-UNNAMED
VMARGS=--add-opens=java.base/sun.nio.ch=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/com.apple.eawt.event=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/com.apple.eawt=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/com.apple.laf=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/java.awt.dnd.peer=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/java.awt.event=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/java.awt.image=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/java.awt.peer=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/java.awt=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/javax.swing=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/sun.awt.datatransfer=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/sun.awt.windows=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/sun.awt=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/sun.font=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/sun.java2d=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/sun.lwawt.macosx=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/sun.lwawt=ALL-UNNAMED
VMARGS=--add-opens=java.desktop/sun.swing=ALL-UNNAMED
VMARGS=--add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED
VMARGS=--add-opens=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED
VMARGS=--add-opens=jdk.jdi/com.sun.tools.jdi=ALL-UNNAMED
# Persistent cache directory used by the application. This directory will be used to store
# persistent application caches for all users. The default location for Mac/Linux is the same as
# specified by java.io.tmpdir property. The default location for Windows corresponds to the
# application local settings directory for the user (e.g., %LOCALAPPDATA%). If you wish to use a
# directory with more storage or avoid system cleanups, it may be desirable to override the default
# location.
#VMARGS=-Dapplication.cachedir=
# Temporary directory used by the application. This directory will be used for all temporary files
# and may also be used for the persistent user cache directory <java.io.tmpdir>/<username>-Ghidra.
# The specified directory must exist and have appropriate read/write/execute permissions
#VMARGS=-Djava.io.tmpdir=
# Disable alternating row colors in tables
#VMARGS=-Ddisable.alternating.row.colors=true
# The ContinuesInterceptor allows the import process to proceed if parsing corrupted headers
# generates uncaught exceptions. Its usage has been deprecated and will be removed in a future
# release of Ghidra. It is disabled by default.
#VMARGS=-DContinuesInterceptor.enabled=true
# Limit on XML parsing. See https://docs.oracle.com/javase/tutorial/jaxp/limits/limits.html
#VMARGS=-Djdk.xml.totalEntitySizeLimit=50000000
# Enables Pdb debug logging during import and analysis to .ghidra/.ghidra_ver/pdb.analyzer.log
#VMARGS=-Dpdb.logging=true
# FlatDarkLaf theme
# https://github.com/JFormDesigner/FlatLaf/tree/main/flatlaf-intellij-themes#how-to-use
VMARGS=-Dswing.systemlaf=com.formdev.flatlaf.FlatIntelliJLaf
# VMARGS=-Dswing.metalTheme=steel
# VMARGS=-Dswing.boldMetal=false
# LLDBInterface Debug
VMARGS_MACOS=-Djava.library.path=/usr/local/opt/llvm/lib:/Users/mahmoud/Library/Java/Extensions
# from: https://github.com/NationalSecurityAgency/ghidra/issues/13#issuecomment-470003790
# Sets SUPPORT_DIR to the directory that contains this file (launch.sh)
SUPPORT_DIR="${0%/*}"
# Ensure Ghidra path doesn't contain illegal characters
if [[ "$SUPPORT_DIR" = *"!"* ]]; then
echo "Ghidra path cannot contain a \"!\" character."
exit 1
fi
if [ -f "${SUPPORT_DIR}/launch.properties" ]; then
# Production Environment
INSTALL_DIR="${SUPPORT_DIR}/.."
CPATH="${INSTALL_DIR}/Ghidra/Framework/Utility/lib/Utility.jar:${HOME}/.ghidra/flatlaf-2.6.jar:${HOME}/.ghidra"
LS_CPATH="${SUPPORT_DIR}/LaunchSupport.jar"
DEBUG_LOG4J="${SUPPORT_DIR}/debug.log4j.xml"
else
# Development Environment
INSTALL_DIR="${SUPPORT_DIR}/../../../.."
CPATH="${INSTALL_DIR}/Ghidra/Framework/Utility/bin/main:${HOME}/.ghidra/flatlaf-2.6.jar:${HOME}/.ghidra"
LS_CPATH="${INSTALL_DIR}/GhidraBuild/LaunchSupport/bin/main"
DEBUG_LOG4J="${INSTALL_DIR}/Ghidra/RuntimeScripts/Common/support/debug.log4j.xml"
if ! [ -d "${LS_CPATH}" ]; then
echo "Ghidra cannot launch in development mode because Eclipse has not compiled its class files."
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment