Add security hardening, Ghidra, recreate skill, checkpoints, shells, web search and themes
- Sandbox (bubblewrap) for non-admin shell/git, MCP per-user rights, hard budgets and quotas, login rate limiting, audit log and backups - Ghidra headless decompilation (ARM64 natives built from source), binary_info tool, clean room / deep workflow per session - Recreate skill and commands for analysing and re-building old software - File checkpoints with rewind/restore, background shells (bash_output, kill_shell) - web_search tool (DuckDuckGo, SearXNG, Brave, Tavily) - In-app dialogs and toasts instead of browser dialogs - 15 base themes (trilium-themes palettes plus Nord, VS Code, GitHub, Catppuccin, One, Dracula, Rose Pine, Everforest, Kanagawa) with light/dark/auto switcher and license notes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fab9add5d5
commit
5b569b6835
108 files changed
+6785
-279
No files matched your search
@@ -0,0 +1,111 @@
|
||||
// Exports a Ghidra analysis for CodeCraft: program info, function index,
|
||||
// pseudo-C per function, strings, imports and exports.
|
||||
// Usage: analyzeHeadless ... -postScript CodeCraftExport.java <output dir> [max functions]
|
||||
//@category CodeCraft
|
||||
|
||||
import ghidra.app.decompiler.DecompInterface;
|
||||
import ghidra.app.decompiler.DecompileResults;
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.address.AddressIterator;
|
||||
import ghidra.program.model.listing.Data;
|
||||
import ghidra.program.model.listing.Function;
|
||||
import ghidra.program.model.listing.FunctionIterator;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.model.symbol.Symbol;
|
||||
import ghidra.program.model.symbol.SymbolIterator;
|
||||
import ghidra.program.util.DefinedStringIterator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class CodeCraftExport extends GhidraScript {
|
||||
|
||||
private static String clean(String s) {
|
||||
return s.replace("\\", "\\\\").replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
String[] args = getScriptArgs();
|
||||
File out = new File(args[0]);
|
||||
int maxFunctions = args.length > 1 ? Integer.parseInt(args[1]) : Integer.MAX_VALUE;
|
||||
File funcDir = new File(out, "functions");
|
||||
funcDir.mkdirs();
|
||||
Program p = currentProgram;
|
||||
|
||||
try (PrintWriter info = new PrintWriter(new File(out, "info.txt"), StandardCharsets.UTF_8)) {
|
||||
info.println("name: " + p.getName());
|
||||
info.println("format: " + p.getExecutableFormat());
|
||||
info.println("language: " + p.getLanguageID());
|
||||
info.println("compiler: " + p.getCompilerSpec().getCompilerSpecID());
|
||||
info.println("image_base: " + p.getImageBase());
|
||||
info.println("functions: " + p.getFunctionManager().getFunctionCount());
|
||||
}
|
||||
|
||||
DecompInterface di = new DecompInterface();
|
||||
di.openProgram(p);
|
||||
int n = 0;
|
||||
try (PrintWriter idx = new PrintWriter(new File(out, "functions.tsv"), StandardCharsets.UTF_8)) {
|
||||
idx.println("address\tname\tsize\tfile\tsignature");
|
||||
FunctionIterator it = p.getFunctionManager().getFunctions(true);
|
||||
while (it.hasNext() && !monitor.isCancelled() && n < maxFunctions) {
|
||||
Function f = it.next();
|
||||
if (f.isThunk() || f.isExternal()) {
|
||||
continue;
|
||||
}
|
||||
String base = f.getEntryPoint().toString() + "_" + f.getName().replaceAll("[^A-Za-z0-9_]", "_");
|
||||
if (base.length() > 120) {
|
||||
base = base.substring(0, 120);
|
||||
}
|
||||
DecompileResults r = di.decompileFunction(f, 60, monitor);
|
||||
String code = (r != null && r.decompileCompleted())
|
||||
? r.getDecompiledFunction().getC()
|
||||
: "/* decompilation failed: " + (r == null ? "no result" : r.getErrorMessage()) + " */\n";
|
||||
Files.writeString(new File(funcDir, base + ".c").toPath(),
|
||||
"// " + f.getName() + " @ " + f.getEntryPoint() + "\n" + code, StandardCharsets.UTF_8);
|
||||
idx.println(f.getEntryPoint() + "\t" + f.getName() + "\t" + f.getBody().getNumAddresses()
|
||||
+ "\tfunctions/" + base + ".c\t" + clean(f.getSignature().getPrototypeString()));
|
||||
n++;
|
||||
if (n % 200 == 0) {
|
||||
println("CodeCraft: decompiled " + n + " functions");
|
||||
}
|
||||
}
|
||||
}
|
||||
di.dispose();
|
||||
|
||||
try (PrintWriter sw = new PrintWriter(new File(out, "strings.tsv"), StandardCharsets.UTF_8)) {
|
||||
sw.println("address\tstring");
|
||||
for (Data d : DefinedStringIterator.forProgram(p)) {
|
||||
Object v = d.getValue();
|
||||
if (v != null) {
|
||||
sw.println(d.getAddress() + "\t" + clean(v.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try (PrintWriter iw = new PrintWriter(new File(out, "imports.tsv"), StandardCharsets.UTF_8)) {
|
||||
iw.println("library\tname");
|
||||
SymbolIterator si = p.getSymbolTable().getExternalSymbols();
|
||||
while (si.hasNext()) {
|
||||
Symbol s = si.next();
|
||||
iw.println(s.getParentNamespace().getName() + "\t" + s.getName());
|
||||
}
|
||||
}
|
||||
|
||||
try (PrintWriter ew = new PrintWriter(new File(out, "exports.tsv"), StandardCharsets.UTF_8)) {
|
||||
ew.println("name\taddress");
|
||||
AddressIterator ai = p.getSymbolTable().getExternalEntryPointIterator();
|
||||
while (ai.hasNext()) {
|
||||
Address a = ai.next();
|
||||
Symbol s = p.getSymbolTable().getPrimarySymbol(a);
|
||||
ew.println((s == null ? "?" : s.getName()) + "\t" + a);
|
||||
}
|
||||
}
|
||||
|
||||
Files.writeString(new File(out, ".done").toPath(), String.valueOf(n), StandardCharsets.UTF_8);
|
||||
println("CodeCraft: export complete, " + n + " functions");
|
||||
}
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
# Installs Temurin JDK 25 and Ghidra into $1 (default /data/tools). Idempotent.
|
||||
# On architectures without prebuilt decompiler binaries (e.g. ARM64) the
|
||||
# native decompiler is built from the sources shipped with Ghidra.
|
||||
set -eu
|
||||
DEST="${1:-/data/tools}"
|
||||
GHIDRA_URL="${GHIDRA_URL:-https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_12.2_build/ghidra_12.2_PUBLIC_20261016.zip}"
|
||||
case "$(uname -m)" in
|
||||
x86_64) ARCH=x64 ;;
|
||||
aarch64|arm64) ARCH=aarch64 ;;
|
||||
*) echo "unsupported architecture $(uname -m)"; exit 1 ;;
|
||||
esac
|
||||
mkdir -p "$DEST"
|
||||
cd "$DEST"
|
||||
if ! jdk/bin/java -version 2>&1 | grep -q '"25'; then
|
||||
echo "Downloading JDK 25 ($ARCH)..."
|
||||
curl -fsSL "https://api.adoptium.net/v3/binary/latest/25/ga/linux/$ARCH/jdk/hotspot/normal/eclipse" -o jdk.tar.gz
|
||||
rm -rf jdk jdk.tmp && mkdir jdk.tmp && tar -xzf jdk.tar.gz -C jdk.tmp --strip-components=1 && mv jdk.tmp jdk && rm jdk.tar.gz
|
||||
fi
|
||||
if [ ! -x ghidra/support/analyzeHeadless ]; then
|
||||
echo "Downloading Ghidra..."
|
||||
curl -fsSL "$GHIDRA_URL" -o ghidra.zip
|
||||
rm -rf ghidra ghidra.tmp && mkdir ghidra.tmp && unzip -q ghidra.zip -d ghidra.tmp && mv ghidra.tmp/ghidra_* ghidra && rmdir ghidra.tmp && rm ghidra.zip
|
||||
fi
|
||||
# Use our JDK without asking.
|
||||
sed -i "s#^JAVA_HOME_OVERRIDE=.*#JAVA_HOME_OVERRIDE=$DEST/jdk#" ghidra/support/launch.properties
|
||||
|
||||
# Native decompiler for this platform.
|
||||
OSDIR=linux_x86_64
|
||||
[ "$ARCH" = aarch64 ] && OSDIR=linux_arm_64
|
||||
NATIVE="ghidra/Ghidra/Features/Decompiler/os/$OSDIR"
|
||||
if [ ! -x "$NATIVE/decompile" ]; then
|
||||
echo "Building the native decompiler for $OSDIR (a few minutes)..."
|
||||
SRC="ghidra/Ghidra/Features/Decompiler/src/decompile/cpp"
|
||||
( cd "$SRC" && mkdir -p ghi_opt sla_opt com_opt && make -j"$(nproc)" ARCH_TYPE= ghidra_opt sleigh_opt >/tmp/ghidra-native.log 2>&1 ) || { tail -20 /tmp/ghidra-native.log; exit 1; }
|
||||
mkdir -p "$NATIVE"
|
||||
cp "$SRC/ghidra_opt" "$NATIVE/decompile"
|
||||
cp "$SRC/sleigh_opt" "$NATIVE/sleigh"
|
||||
( cd "$SRC" && make clean >/dev/null 2>&1 || true )
|
||||
fi
|
||||
"$DEST/jdk/bin/java" -version 2>&1 | head -1
|
||||
echo "Ghidra installed in $DEST/ghidra ($OSDIR)"
|
||||
Reference in new issue
Block a user