@henols/c64-re-tools 2.6.0-rc.6 → 2.6.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/c64-knowledge/SKILL.md +1 -1
- package/skills/c64-knowledge/scripts/knowledge.ts +2 -0
- package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
- package/skills/c64-reverse-engineering/SKILL.md +1 -1
- package/skills/c64-source/SKILL.md +5 -5
- package/skills/c64-source/scripts/source.ts +22 -20
- package/skills/c64-static-analysis/SKILL.md +3 -3
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
- package/skills/c64-static-analysis/scripts/static-analysis.ts +1 -8
- package/skills/c64-testing/SKILL.md +1 -0
- package/skills/c64-testing/references/recording-format.md +8 -0
- package/skills/c64-testing/scripts/lib/keys.ts +36 -0
- package/skills/c64-testing/scripts/lib/play.ts +2 -6
- package/skills/c64-testing/scripts/lib/recording.ts +13 -4
- package/skills/emulator/SKILL.md +6 -8
- package/src/cli/main.ts +3 -29
- package/src/host/main.ts +1 -1
- package/src/host/tools/index.ts +1 -6
- package/src/host/vice/session.ts +1 -1
- package/src/host-client/tools.ts +2 -7
- package/src/knowledge/read.ts +16 -1
- package/src/mcp/server.ts +0 -1
- package/src/mcp/tools/machine.ts +3 -42
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/dxa.ts +12 -1
- package/src/native/ghidra/analyze.ts +74 -63
- package/src/native/ghidra/c64rt-wasm.ts +4 -0
- package/src/native/ghidra/language/c64rt_6510.sla +0 -0
- package/src/native/ghidra/pcode.ts +222 -0
- package/src/native/ghidra/walk.ts +205 -0
- package/src/native/ghidra/wasm.ts +98 -0
- package/src/native/processes.ts +1 -1
- package/src/native/types.ts +2 -2
- package/src/project.ts +4 -3
- package/src/protocol/tools.ts +1 -45
- package/src/script.ts +1 -1
- package/tools/install-container.sh +1 -2
- package/src/cli/status.ts +0 -127
- package/src/host/tools/status.ts +0 -47
- package/src/native/ghidra/index.ts +0 -170
- package/src/native/ghidra/scripts/C64Export.java +0 -274
- package/src/native/ghidra/scripts/C64Prepare.java +0 -66
- package/src/native/status.ts +0 -135
- package/tools/install-ghidra.sh +0 -40
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Runs before Ghidra's analysis. Arguments: <seeds.json>.
|
|
2
|
-
//
|
|
3
|
-
// Fills the rest of the 64 KiB address space with uninitialized memory, so
|
|
4
|
-
// references to I/O and other RAM resolve, then applies the knowledge seeds:
|
|
5
|
-
// labels (user-defined names), data ranges (defined bytes that analysis does
|
|
6
|
-
// not disassemble), entry points (disassembled functions) and code starts
|
|
7
|
-
// (disassembled code without a function: a branch target is no routine).
|
|
8
|
-
//@category c64-re-tools
|
|
9
|
-
|
|
10
|
-
import java.io.FileReader;
|
|
11
|
-
|
|
12
|
-
import com.google.gson.Gson;
|
|
13
|
-
import com.google.gson.JsonElement;
|
|
14
|
-
import com.google.gson.JsonObject;
|
|
15
|
-
|
|
16
|
-
import ghidra.app.script.GhidraScript;
|
|
17
|
-
import ghidra.program.model.address.Address;
|
|
18
|
-
import ghidra.program.model.data.ArrayDataType;
|
|
19
|
-
import ghidra.program.model.data.ByteDataType;
|
|
20
|
-
import ghidra.program.model.mem.Memory;
|
|
21
|
-
import ghidra.program.model.symbol.SourceType;
|
|
22
|
-
|
|
23
|
-
public class C64Prepare extends GhidraScript {
|
|
24
|
-
@Override
|
|
25
|
-
public void run() throws Exception {
|
|
26
|
-
JsonObject seeds;
|
|
27
|
-
try (FileReader reader = new FileReader(getScriptArgs()[0])) {
|
|
28
|
-
seeds = new Gson().fromJson(reader, JsonObject.class);
|
|
29
|
-
}
|
|
30
|
-
long start = seeds.get("start").getAsLong();
|
|
31
|
-
long end = seeds.get("end").getAsLong();
|
|
32
|
-
Memory memory = currentProgram.getMemory();
|
|
33
|
-
if (start > 0) {
|
|
34
|
-
memory.createUninitializedBlock("RAM_LOW", toAddr(0), start, false);
|
|
35
|
-
}
|
|
36
|
-
if (end < 0xffff) {
|
|
37
|
-
memory.createUninitializedBlock("RAM_HIGH", toAddr(end + 1), 0xffff - end, false);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
for (JsonElement element : seeds.getAsJsonArray("labels")) {
|
|
41
|
-
JsonObject label = element.getAsJsonObject();
|
|
42
|
-
createLabel(toAddr(label.get("address").getAsLong()), label.get("name").getAsString(), true, SourceType.USER_DEFINED);
|
|
43
|
-
}
|
|
44
|
-
for (JsonElement element : seeds.getAsJsonArray("dataRanges")) {
|
|
45
|
-
JsonObject range = element.getAsJsonObject();
|
|
46
|
-
Address first = toAddr(range.get("start").getAsLong());
|
|
47
|
-
Address last = toAddr(range.get("end").getAsLong());
|
|
48
|
-
int length = (int) (last.getOffset() - first.getOffset() + 1);
|
|
49
|
-
currentProgram.getListing().clearCodeUnits(first, last, false);
|
|
50
|
-
currentProgram.getListing().createData(first, new ArrayDataType(ByteDataType.dataType, length, 1));
|
|
51
|
-
}
|
|
52
|
-
for (JsonElement element : seeds.getAsJsonArray("entryPoints")) {
|
|
53
|
-
Address entry = toAddr(element.getAsLong());
|
|
54
|
-
addEntryPoint(entry);
|
|
55
|
-
disassemble(entry);
|
|
56
|
-
if (getFunctionAt(entry) == null) {
|
|
57
|
-
createFunction(entry, null);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (seeds.has("codeStarts")) {
|
|
61
|
-
for (JsonElement element : seeds.getAsJsonArray("codeStarts")) {
|
|
62
|
-
disassemble(toAddr(element.getAsLong()));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
package/src/native/status.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// Tool status: finds each native tool the way its operations do and runs it
|
|
2
|
-
// once with a version option, so a user can see in advance which tools work.
|
|
3
|
-
// The Host Runtime reports VICE and its tools (host.status); the CLI reports
|
|
4
|
-
// the tools that skill scripts run themselves (ACME, DXA, Exomizer, Ghidra).
|
|
5
|
-
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
import { stripVTControlCharacters } from "node:util";
|
|
8
|
-
|
|
9
|
-
import { isRefusal } from "../errors.ts";
|
|
10
|
-
import { type ToolStatus } from "../protocol/tools.ts";
|
|
11
|
-
import { ACME, C64RUN, DXA, EXOMIZER, findTool, INSTALL_STEPS } from "./discover.ts";
|
|
12
|
-
import { findGhidra, ghidraVersion, NO_USABLE_JDK, noJdk } from "./ghidra/index.ts";
|
|
13
|
-
import { runTool, type ToolContext } from "./run.ts";
|
|
14
|
-
import { Workspace } from "./staging.ts";
|
|
15
|
-
|
|
16
|
-
const PROBE_TIMEOUT_MS = 20_000;
|
|
17
|
-
|
|
18
|
-
export interface Probe {
|
|
19
|
-
name: string;
|
|
20
|
-
/** The executable; throws WireFailure(installation-incomplete) when missing. */
|
|
21
|
-
find: (env: NodeJS.ProcessEnv) => string;
|
|
22
|
-
args: string[];
|
|
23
|
-
/** The version line; no such line means the tool did not run correctly. */
|
|
24
|
-
pattern: RegExp;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** dxa's version line, also as "D:\\tools\\dxa.exe v0.1.5 -- symbolic 65xx disassembler" on Windows. */
|
|
28
|
-
export const DXA_VERSION = /^(?:.*[\\/])?dxa(?:\.exe)? v\d/i;
|
|
29
|
-
|
|
30
|
-
/** The first output line that matches, without terminal color codes (c1541 colors an OpenCBM notice). */
|
|
31
|
-
export function versionLine(output: string, pattern: RegExp): string | undefined {
|
|
32
|
-
return stripVTControlCharacters(output)
|
|
33
|
-
.split(/\r?\n/)
|
|
34
|
-
.map((line) => line.trim())
|
|
35
|
-
.find((line) => pattern.test(line));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function run(
|
|
39
|
-
name: string,
|
|
40
|
-
path: string,
|
|
41
|
-
args: string[],
|
|
42
|
-
version: (output: string) => string | undefined,
|
|
43
|
-
context: ToolContext,
|
|
44
|
-
/** A known cause in the output, said in place of the exit status. */
|
|
45
|
-
cause?: (output: string) => string | undefined,
|
|
46
|
-
): Promise<ToolStatus> {
|
|
47
|
-
const result = await runTool({ argv: [path, ...args], cwd: tmpdir(), supervisor: context.supervisor, signal: context.signal, timeoutMs: PROBE_TIMEOUT_MS, env: context.env });
|
|
48
|
-
const output = `${result.stdout}\n${result.stderr}`;
|
|
49
|
-
const found = version(output);
|
|
50
|
-
if (found !== undefined) return { name, found: true, path, version: found, runs: true };
|
|
51
|
-
const known = cause?.(output);
|
|
52
|
-
if (known !== undefined) return { name, found: true, path, runs: false, problem: known };
|
|
53
|
-
const problem = result.timedOut ? "It did not answer in time." : result.spawnError !== undefined ? `It did not start (${result.spawnError}).` : `It did not run correctly (exit ${result.code ?? result.signal}).`;
|
|
54
|
-
return { name, found: true, path, runs: false, problem };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function missing(name: string, error: unknown): ToolStatus {
|
|
58
|
-
if (!isRefusal(error)) throw error;
|
|
59
|
-
return { name, found: false, runs: false, problem: error.message };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Finds and runs each probed tool once. */
|
|
63
|
-
export function probeTools(probes: Probe[], context: ToolContext): Promise<ToolStatus[]> {
|
|
64
|
-
const env = context.env ?? process.env;
|
|
65
|
-
return Promise.all(
|
|
66
|
-
probes.map(async (probe) => {
|
|
67
|
-
let path: string;
|
|
68
|
-
try {
|
|
69
|
-
path = probe.find(env);
|
|
70
|
-
} catch (error) {
|
|
71
|
-
return missing(probe.name, error);
|
|
72
|
-
}
|
|
73
|
-
return run(probe.name, path, probe.args, (output) => versionLine(output, probe.pattern), context);
|
|
74
|
-
}),
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Ghidra: without arguments analyzeHeadless starts Java and prints its usage, which proves that it runs. */
|
|
79
|
-
export async function probeGhidra(context: ToolContext): Promise<ToolStatus> {
|
|
80
|
-
const env = context.env ?? process.env;
|
|
81
|
-
try {
|
|
82
|
-
const ghidra = findGhidra(env);
|
|
83
|
-
// Its own settings directory keeps the user's Ghidra settings and logs untouched.
|
|
84
|
-
const workspace = Workspace.create(context.supervisor, "c64-re-tools-ghidra-status-");
|
|
85
|
-
const settings = workspace.root;
|
|
86
|
-
try {
|
|
87
|
-
const status = await run(
|
|
88
|
-
"Ghidra",
|
|
89
|
-
ghidra.analyzeHeadless,
|
|
90
|
-
[],
|
|
91
|
-
(output) => (/Headless Analyzer Usage/.test(output) ? ghidraVersion(ghidra) : undefined),
|
|
92
|
-
{ ...context, env: { ...env, XDG_CONFIG_HOME: settings, XDG_CACHE_HOME: settings } },
|
|
93
|
-
(output) => (NO_USABLE_JDK.test(output) ? noJdk(ghidra).message : undefined),
|
|
94
|
-
);
|
|
95
|
-
return { ...status, path: ghidra.root };
|
|
96
|
-
} finally {
|
|
97
|
-
workspace.remove();
|
|
98
|
-
}
|
|
99
|
-
} catch (error) {
|
|
100
|
-
return missing("Ghidra", error);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** c64run: --version prints its version and whether its ROM folder has the three C64 ROMs. */
|
|
105
|
-
export async function probeC64run(context: ToolContext): Promise<ToolStatus> {
|
|
106
|
-
const env = context.env ?? process.env;
|
|
107
|
-
try {
|
|
108
|
-
const path = findTool(C64RUN, env);
|
|
109
|
-
return await run(
|
|
110
|
-
"c64run",
|
|
111
|
-
path,
|
|
112
|
-
["--version"],
|
|
113
|
-
(output) => (/^roms=ok /m.test(output) ? versionLine(output, /^c64run protocol=/) : undefined),
|
|
114
|
-
context,
|
|
115
|
-
(output) => {
|
|
116
|
-
const missing = /^roms=missing (.*)$/m.exec(output)?.[1];
|
|
117
|
-
return missing === undefined ? undefined : `It has no C64 ROMs: ${missing}. ${INSTALL_STEPS}`;
|
|
118
|
-
},
|
|
119
|
-
);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
return missing("c64run", error);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** The tools that skill scripts run themselves, on this machine. */
|
|
126
|
-
export async function localToolStatus(context: ToolContext): Promise<ToolStatus[]> {
|
|
127
|
-
const probes: Probe[] = [
|
|
128
|
-
{ name: "ACME", find: (env) => findTool(ACME, env), args: ["--version"], pattern: /^This is ACME, release / },
|
|
129
|
-
// dxa -V prints its version and exits with status 1. It names itself by argv[0], without the
|
|
130
|
-
// directory only where that uses "/": on Windows the line starts with the full path.
|
|
131
|
-
{ name: "dxa", find: (env) => findTool(DXA, env), args: ["-V"], pattern: DXA_VERSION },
|
|
132
|
-
{ name: "Exomizer", find: (env) => findTool(EXOMIZER, env), args: ["-v"], pattern: /^Exomizer v\d/ },
|
|
133
|
-
];
|
|
134
|
-
return [...(await probeTools(probes, context)), await probeGhidra(context), await probeC64run(context)];
|
|
135
|
-
}
|
package/tools/install-ghidra.sh
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Installs Ghidra in /opt/ghidra_<version>_PUBLIC and points /opt/ghidra at
|
|
3
|
-
# it, so that C64RT_GHIDRA=/opt/ghidra stays the same when the version
|
|
4
|
-
# changes. Removes the Ghidra versions that it installed before. Ghidra needs
|
|
5
|
-
# Java 21. install-container.sh runs it as root.
|
|
6
|
-
|
|
7
|
-
set -Eeuo pipefail
|
|
8
|
-
|
|
9
|
-
GHIDRA_VERSION="12.1.3"
|
|
10
|
-
GHIDRA_ZIP="ghidra_${GHIDRA_VERSION}_PUBLIC_20260817.zip"
|
|
11
|
-
GHIDRA_URL="https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_${GHIDRA_VERSION}_build/${GHIDRA_ZIP}"
|
|
12
|
-
GHIDRA_SHA256="93a5d11a9ad510622acaaf908c556a7b9b764d338e78a7567f3689bf5081fd54"
|
|
13
|
-
DEST="/opt"
|
|
14
|
-
GHIDRA_DIR="${DEST}/ghidra_${GHIDRA_VERSION}_PUBLIC"
|
|
15
|
-
|
|
16
|
-
fail() {
|
|
17
|
-
printf 'Ghidra: %s\n' "$*" >&2
|
|
18
|
-
exit 1
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
[[ "$(id -u)" -eq 0 ]] || fail "run as root."
|
|
22
|
-
|
|
23
|
-
if [[ ! -d "${GHIDRA_DIR}" ]]; then
|
|
24
|
-
BUILD_DIR="$(mktemp -d -t ghidra-XXXXXXXX)"
|
|
25
|
-
trap 'rm -rf "${BUILD_DIR}"' EXIT
|
|
26
|
-
curl -fsSL --retry 3 -o "${BUILD_DIR}/${GHIDRA_ZIP}" "${GHIDRA_URL}"
|
|
27
|
-
echo "${GHIDRA_SHA256} ${BUILD_DIR}/${GHIDRA_ZIP}" | sha256sum -c - > /dev/null || fail "the archive has the wrong checksum."
|
|
28
|
-
unzip -q "${BUILD_DIR}/${GHIDRA_ZIP}" -d "${BUILD_DIR}/unpacked"
|
|
29
|
-
# Ghidra ships its decompiler only for x86-64; on arm64 its own Gradle wrapper builds it.
|
|
30
|
-
if [[ "$(uname -m)" == aarch64 || "$(uname -m)" == arm64 ]]; then
|
|
31
|
-
(cd "${BUILD_DIR}/unpacked/ghidra_${GHIDRA_VERSION}_PUBLIC/support/gradle" && GRADLE_USER_HOME="${BUILD_DIR}/gradle" ./gradlew --no-daemon buildNatives)
|
|
32
|
-
fi
|
|
33
|
-
mv "${BUILD_DIR}/unpacked/ghidra_${GHIDRA_VERSION}_PUBLIC" "${GHIDRA_DIR}"
|
|
34
|
-
fi
|
|
35
|
-
|
|
36
|
-
ln -sfn "${GHIDRA_DIR}" "${DEST}/ghidra"
|
|
37
|
-
for old in "${DEST}"/ghidra_*_PUBLIC; do
|
|
38
|
-
[[ "${old}" == "${GHIDRA_DIR}" || ! -d "${old}" ]] || rm -rf "${old}"
|
|
39
|
-
done
|
|
40
|
-
echo "Ghidra ${GHIDRA_VERSION} is installed in ${GHIDRA_DIR}, and ${DEST}/ghidra points at it."
|