chore(re): per-DLL Ghidra projects import script for companions

This commit is contained in:
ulw-execute committed 2026-11-28 05:04:47 -05:00
1 parent 29aa4b7ecf
commit 16f2556b23
1 file changed
+101
+101
View File
@@ -0,0 +1,101 @@
#!/usr/bin/env bash
# Import each in-scope Konami companion DLL into its own persistent Ghidra
# project under /home/athapa/ghidra, mirroring the existing gkproj
# (gamekdm.dll) / afpproj (libafp-win32.dll) layout.
#
# One-time `-import` per DLL (full default analysis runs during import, no
# extra `-process`/`-postScript` re-analysis pass afterwards). Idempotent:
# a DLL whose <name>proj.rep already exists is skipped.
#
# Usage:
# tools/ghidra/import_companions.sh [dll-name ...]
#
# With no arguments, imports the full in-scope companion set (in dependency
# order, AVS2 base first) that does not already have a project. gamekdm.dll
# (gkproj) and libafp-win32.dll (afpproj) are intentionally excluded: they
# already exist.
set -euo pipefail
GHIDRA_HOME="${GHIDRA_HOME:-/home/athapa/ghidra/ghidra_11.3.1_PUBLIC}"
ANALYZE_HEADLESS="${GHIDRA_HOME}/support/analyzeHeadless"
export JAVA_HOME="${JAVA_HOME:-$(echo ~/jdk/jdk-21.* 2>/dev/null | head -1)}"
PROJECT_DIR="/home/athapa/ghidra"
# Source DLL directory (owner's legally-possessed KDM-2016021900 copy).
SRC_DIR="${KDM_SRC_DIR:-/mnt/f/Users/Aaron Thapa/Downloads/KDM-2016021900/contents}"
# In-scope companion DLLs from docs/companion-inventory.md's "IN-SCOPE
# reconstruct set", minus gamekdm.dll (gkproj) and libafp-win32.dll
# (afpproj) which already have projects, and minus modules/libacio.dll
# (byte-identical duplicate of libacio.dll -- one project covers both).
# Ordered per the inventory's topological reconstruction order.
#
# Each entry is "dll-filename:project-name".
DEFAULT_DLLS=(
"libavs-win32.dll:avsproj"
"libavs-win32-ea3.dll:avsea3proj"
"ess.dll:essproj"
"libacio.dll:libacioproj"
"arkkdm.dll:arkkdmproj"
"arkkdmtest.dll:arkkdmtestproj"
"deahook.dll:deahookproj"
"libafputils-win32.dll:libafputilsproj"
"kmd.dll:kmdproj"
"ksm.dll:ksmproj"
"kuc.dll:kucproj"
"libinput.dll:libinputproj"
"libacio_mbr.dll:libaciombrproj"
)
if [[ $# -gt 0 ]]; then
DLLS=()
for name in "$@"; do
found=0
for entry in "${DEFAULT_DLLS[@]}"; do
if [[ "${entry%%:*}" == "$name" ]]; then
DLLS+=("$entry")
found=1
break
fi
done
if [[ "$found" -eq 0 ]]; then
echo "error: unknown DLL '$name' (not in in-scope companion list)" >&2
exit 1
fi
done
else
DLLS=("${DEFAULT_DLLS[@]}")
fi
echo "GHIDRA_HOME=${GHIDRA_HOME}"
echo "JAVA_HOME=${JAVA_HOME}"
echo "PROJECT_DIR=${PROJECT_DIR}"
echo "SRC_DIR=${SRC_DIR}"
echo
for entry in "${DLLS[@]}"; do
dll="${entry%%:*}"
proj="${entry##*:}"
src="${SRC_DIR}/${dll}"
rep="${PROJECT_DIR}/${proj}.rep"
if [[ -d "${rep}" ]] && [[ -n "$(ls -A "${rep}" 2>/dev/null)" ]]; then
echo "== ${proj}: already exists (${rep}), skipping =="
continue
fi
if [[ ! -f "${src}" ]]; then
echo "== ${proj}: source DLL not found at ${src}, skipping ==" >&2
continue
fi
echo "== ${proj}: importing ${src} =="
"${ANALYZE_HEADLESS}" "${PROJECT_DIR}" "${proj}" \
-import "${src}" \
-overwrite
echo "== ${proj}: import complete =="
echo
done
echo "Done. Projects present:"
ls -d "${PROJECT_DIR}"/*proj.rep 2>/dev/null || true