#!/bin/bash # SPDX-License-Identifier: BSD-3-Clause # # ########################################################################### # # WARNING: DEPRECATED - DO NOT USE FOR NEW ANALYSIS (kept for history). # # # # # # Two bugs make its output unusable: # # # 1. It passes FILE virtual addresses to Ghidra, which loads these # # # binaries at image base 0x100000. Every address is 0x100000 too low, # # # so the decompiled "functions" are the wrong ones. # # # 2. `-analysisTimeoutPerFile 0` does not mean "no timeout" in this # # # Ghidra build: it aborts auto-analysis immediately, producing an # # # analysed-looking project with no analysis at all. # # # # # # Replacement: tools/ghidra_full_analysis.sh (plus # # # tools/ghidra/ConfigureAnalysis.java). # # ########################################################################### # # ghidra_analyze.sh - import a library into a Ghidra project and run the full # auto-analysis once. The project is kept, so later decompilations are cheap: # # scripts/ghidra_decompile_project.sh [outfile] # # Full analysis of a ~70 MB library can take a long time; run it in the # background and log to run/ghidra-analyze.log. # # Usage: scripts/ghidra_analyze.sh # env: GHIDRA_HOME (default /snap/ghidra/current/ghidra) # PROJECT_DIR (default ../run/ghidra-proj) # PROJECT_NAME (default cuda-analysis) set -e HERE="$(cd "$(dirname "$0")" && pwd)" ROOT="$(cd "$HERE/.." && pwd)" RUN="$ROOT/run" BIN="${1:?usage: $0 }" GHIDRA_HOME="${GHIDRA_HOME:-/snap/ghidra/current/ghidra}" ANALYZE="$GHIDRA_HOME/support/analyzeHeadless" PROJECT_DIR="${PROJECT_DIR:-$RUN/ghidra-proj}" PROJECT_NAME="${PROJECT_NAME:-cuda-analysis}" [ -x "$ANALYZE" ] || { echo "analyzeHeadless not found at $ANALYZE"; exit 1; } mkdir -p "$PROJECT_DIR" echo "[*] importing + analyzing $BIN (this can take a long time)" "$ANALYZE" "$PROJECT_DIR" "$PROJECT_NAME" \ -import "$BIN" \ -overwrite \ -scriptPath "$ROOT/ghidra" \ -analysisTimeoutPerFile 0 echo "[ok] analysis complete"