#!/bin/bash # SPDX-License-Identifier: BSD-3-Clause # # ########################################################################### # # WARNING: DEPRECATED - DO NOT USE FOR NEW ANALYSIS (kept for history). # # # # # # It passes a FILE virtual address straight to 570.144/ghidra/ # # # DecompileAt.java, but Ghidra loads these binaries at image base # # # 0x100000: the script resolves (and decompiles) the function 0x100000 # # # bytes too low. It also depends on a project produced by the broken # # # ghidra_analyze.sh above. # # # # # # Replacement: tools/ghidra_decompile_at.sh, which translates the file # # # vaddr with tools/ghidra/DecompileAt.java (file-vaddr aware). # # ########################################################################### # # ghidra_decompile_project.sh - decompile a function from an already-analyzed # Ghidra project (run scripts/ghidra_analyze.sh once first). No re-import and # no analysis, so this takes seconds. # # Usage: scripts/ghidra_decompile_project.sh [outfile] [program] # env: GHIDRA_HOME, PROJECT_DIR, PROJECT_NAME (same as ghidra_analyze.sh) set -e HERE="$(cd "$(dirname "$0")" && pwd)" ROOT="$(cd "$HERE/.." && pwd)" RUN="$ROOT/run" VADDR="${1:?usage: $0 [outfile] [program]}" OUT="${2:-$RUN/fn_$VADDR.c}" PROGRAM="${3:-libcuda.so.570.144}" 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}" [ -d "$PROJECT_DIR" ] || { echo "no project at $PROJECT_DIR (run ghidra_analyze.sh)"; exit 1; } mkdir -p "$RUN" echo "[*] decompiling $PROGRAM at $VADDR (project) -> $OUT" "$ANALYZE" "$PROJECT_DIR" "$PROJECT_NAME" \ -process "$PROGRAM" \ -noanalysis \ -scriptPath "$ROOT/ghidra" \ -postScript DecompileAt.java "$VADDR" "$OUT" \ 2>&1 | tail -3 [ -f "$OUT" ] || { echo "[FAIL] no output"; exit 1; } echo "[ok] $OUT"