@henols/c64-re-tools 2.2.0-rc.1 → 2.2.0-rc.3
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/README.md +30 -41
- package/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +1 -0
- package/skills/c64-assembler/scripts/assembler.ts +2 -9
- package/skills/c64-development/SKILL.md +180 -0
- package/skills/c64-export/SKILL.md +87 -0
- package/skills/c64-provenance/scripts/lib/leftovers.ts +1 -1
- package/skills/c64-provenance/scripts/provenance.ts +1 -1
- package/skills/c64-reverse-engineering/SKILL.md +4 -0
- package/skills/c64-source/SKILL.md +88 -1
- package/skills/c64-source/scripts/lib/export.ts +471 -0
- package/skills/c64-source/scripts/source.ts +432 -64
- package/skills/c64-testing/SKILL.md +5 -3
- package/skills/c64-testing/references/scenario-format.md +34 -2
- package/skills/c64-testing/scripts/lib/runs.ts +122 -12
- package/skills/c64-testing/scripts/testing.ts +1 -1
- package/src/cli/main.ts +7 -7
- package/src/knowledge/program.ts +1 -1
- package/{skills/c64-provenance/scripts/lib → src/knowledge}/separate.ts +35 -21
- package/src/native/acme.ts +11 -0
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +5 -5
- package/src/native/ghidra/index.ts +5 -9
- package/src/native/status.ts +1 -1
- package/src/project.ts +25 -1
- package/src/zip.ts +89 -0
- package/tools/install-chips.sh +10 -19
- package/tools/install-dxa.sh +9 -51
- package/tools/install-ghidra.sh +6 -6
package/src/project.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { Refusal } from "./errors.ts";
|
|
8
8
|
import { accessSync, constants, existsSync, lstatSync, mkdirSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
9
9
|
import { homedir } from "node:os";
|
|
10
|
-
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
10
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
11
11
|
|
|
12
12
|
/** The folder that marks a project and holds its knowledge. */
|
|
13
13
|
export const PROJECT_DIRECTORY = ".c64-re-tools";
|
|
@@ -130,6 +130,30 @@ export function namedProject(folder: string, cwd: string = process.cwd()): strin
|
|
|
130
130
|
return path;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* The folder of a new project that `folder` names, relative to the project
|
|
135
|
+
* `currentRoot` or absolute, and the zip file beside it (`<folder>.zip`). The
|
|
136
|
+
* folder must not exist or be empty. It must be outside the current project
|
|
137
|
+
* and must not hold it, and no folder above it is a project: then the new
|
|
138
|
+
* project is a project of its own.
|
|
139
|
+
*/
|
|
140
|
+
export function newProjectFolder(folder: string, currentRoot: string): { root: string; zip: string } {
|
|
141
|
+
if (folder.length === 0) throw new Refusal("invalid-input", "The folder of the new project must not be empty.");
|
|
142
|
+
const root = resolve(currentRoot, folder);
|
|
143
|
+
const zip = `${root}.zip`;
|
|
144
|
+
if (dirname(root) === root) throw new Refusal("invalid-input", `${folder} is the root of a file system. Give a folder for the new project.`);
|
|
145
|
+
if (root === homedir()) throw new Refusal("invalid-input", "The home folder cannot be the folder of a new project.");
|
|
146
|
+
if (isInside(currentRoot, root)) throw new Refusal("invalid-input", `${folder} is inside the project ${currentRoot}. Give a folder outside it, for example ../${basename(root)}.`);
|
|
147
|
+
if (isInside(root, currentRoot)) throw new Refusal("invalid-input", `${folder} holds the project ${currentRoot}. Give a folder outside it.`);
|
|
148
|
+
const outer = foldersUpFrom(root).slice(1).find(isProject);
|
|
149
|
+
if (outer !== undefined) throw new Refusal("invalid-input", `${folder} is inside the project ${outer}. Give a folder that is in no project.`);
|
|
150
|
+
const stat = statSync(root, { throwIfNoEntry: false });
|
|
151
|
+
if (stat !== undefined && !stat.isDirectory()) throw new Refusal("invalid-input", `${folder} is not a folder.`);
|
|
152
|
+
if (stat !== undefined && readdirSync(root).length > 0) throw new Refusal("conflict", `${folder} is not empty. Give a new or empty folder, or remove the folder of an earlier export.`);
|
|
153
|
+
if (existsSync(zip)) throw new Refusal("conflict", `${zip} exists. Remove the zip file of an earlier export, or give another folder.`);
|
|
154
|
+
return { root, zip };
|
|
155
|
+
}
|
|
156
|
+
|
|
133
157
|
/**
|
|
134
158
|
* Makes .c64-re-tools/local/ with its .gitignore when the project has
|
|
135
159
|
* .c64-re-tools/ and local/ has no .gitignore yet. A folder that is not
|
package/src/zip.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// A zip archive of files given as bytes. The same files give the same bytes:
|
|
2
|
+
// the entries are in path order, each has the time 1980-01-01 00:00, and no
|
|
3
|
+
// field depends on the machine. Each file is deflated, or stored when deflate
|
|
4
|
+
// does not make it smaller. No ZIP64: an archive that needs it is refused.
|
|
5
|
+
|
|
6
|
+
import { crc32, deflateRawSync } from "node:zlib";
|
|
7
|
+
|
|
8
|
+
import { Refusal } from "./errors.ts";
|
|
9
|
+
|
|
10
|
+
export interface ZipEntry {
|
|
11
|
+
/** The path in the archive, with / between the parts. */
|
|
12
|
+
path: string;
|
|
13
|
+
bytes: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const LOCAL_SIGNATURE = 0x04034b50;
|
|
17
|
+
const CENTRAL_SIGNATURE = 0x02014b50;
|
|
18
|
+
const END_SIGNATURE = 0x06054b50;
|
|
19
|
+
/** Version 2.0: deflate. */
|
|
20
|
+
const VERSION = 20;
|
|
21
|
+
/** Bit 11: the path is UTF-8. */
|
|
22
|
+
const UTF8_FLAG = 0x0800;
|
|
23
|
+
const STORED = 0;
|
|
24
|
+
const DEFLATED = 8;
|
|
25
|
+
/** 1980-01-01 in MS-DOS date format; the time is 00:00. */
|
|
26
|
+
const DOS_DATE = (1 << 5) | 1;
|
|
27
|
+
const LIMIT = 0xffffffff;
|
|
28
|
+
const MAX_ENTRIES = 0xffff;
|
|
29
|
+
|
|
30
|
+
/** The archive of the entries, sorted by path. Refuses a duplicate or an unsafe path, and an archive that needs ZIP64. */
|
|
31
|
+
export function zipFiles(entries: readonly ZipEntry[]): Buffer {
|
|
32
|
+
const sorted = [...entries].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
33
|
+
if (sorted.length > MAX_ENTRIES) throw new Refusal("invalid-input", `A zip archive holds at most ${MAX_ENTRIES} files without ZIP64; this one has ${sorted.length}.`);
|
|
34
|
+
const locals: Buffer[] = [];
|
|
35
|
+
const centrals: Buffer[] = [];
|
|
36
|
+
let offset = 0;
|
|
37
|
+
sorted.forEach((entry, index) => {
|
|
38
|
+
const path = entry.path;
|
|
39
|
+
if (path === "" || path.startsWith("/") || path.includes("\\") || path.split("/").some((part) => part === "" || part === "." || part === "..")) {
|
|
40
|
+
throw new Refusal("invalid-input", `${JSON.stringify(path)} is not a relative path with / between its parts.`);
|
|
41
|
+
}
|
|
42
|
+
if (index > 0 && sorted[index - 1]!.path === path) throw new Refusal("invalid-input", `The zip archive has ${path} two times.`);
|
|
43
|
+
const name = Buffer.from(path, "utf8");
|
|
44
|
+
const deflated = deflateRawSync(entry.bytes, { level: 9 });
|
|
45
|
+
const method = deflated.length < entry.bytes.length ? DEFLATED : STORED;
|
|
46
|
+
const data = method === DEFLATED ? deflated : Buffer.from(entry.bytes);
|
|
47
|
+
if (entry.bytes.length > LIMIT || offset > LIMIT) throw new Refusal("invalid-input", `${path} is too large for a zip archive without ZIP64.`);
|
|
48
|
+
const crc = crc32(entry.bytes);
|
|
49
|
+
|
|
50
|
+
const local = Buffer.alloc(30);
|
|
51
|
+
local.writeUInt32LE(LOCAL_SIGNATURE, 0);
|
|
52
|
+
local.writeUInt16LE(VERSION, 4);
|
|
53
|
+
local.writeUInt16LE(UTF8_FLAG, 6);
|
|
54
|
+
local.writeUInt16LE(method, 8);
|
|
55
|
+
local.writeUInt16LE(0, 10);
|
|
56
|
+
local.writeUInt16LE(DOS_DATE, 12);
|
|
57
|
+
local.writeUInt32LE(crc, 14);
|
|
58
|
+
local.writeUInt32LE(data.length, 18);
|
|
59
|
+
local.writeUInt32LE(entry.bytes.length, 22);
|
|
60
|
+
local.writeUInt16LE(name.length, 26);
|
|
61
|
+
local.writeUInt16LE(0, 28);
|
|
62
|
+
locals.push(local, name, data);
|
|
63
|
+
|
|
64
|
+
const central = Buffer.alloc(46);
|
|
65
|
+
central.writeUInt32LE(CENTRAL_SIGNATURE, 0);
|
|
66
|
+
central.writeUInt16LE(VERSION, 4);
|
|
67
|
+
central.writeUInt16LE(VERSION, 6);
|
|
68
|
+
central.writeUInt16LE(UTF8_FLAG, 8);
|
|
69
|
+
central.writeUInt16LE(method, 10);
|
|
70
|
+
central.writeUInt16LE(0, 12);
|
|
71
|
+
central.writeUInt16LE(DOS_DATE, 14);
|
|
72
|
+
central.writeUInt32LE(crc, 16);
|
|
73
|
+
central.writeUInt32LE(data.length, 20);
|
|
74
|
+
central.writeUInt32LE(entry.bytes.length, 24);
|
|
75
|
+
central.writeUInt16LE(name.length, 28);
|
|
76
|
+
central.writeUInt32LE(offset, 42);
|
|
77
|
+
centrals.push(central, name);
|
|
78
|
+
offset += local.length + name.length + data.length;
|
|
79
|
+
});
|
|
80
|
+
const directory = Buffer.concat(centrals);
|
|
81
|
+
if (offset > LIMIT || directory.length > LIMIT) throw new Refusal("invalid-input", "The files are too large for a zip archive without ZIP64.");
|
|
82
|
+
const end = Buffer.alloc(22);
|
|
83
|
+
end.writeUInt32LE(END_SIGNATURE, 0);
|
|
84
|
+
end.writeUInt16LE(sorted.length, 8);
|
|
85
|
+
end.writeUInt16LE(sorted.length, 10);
|
|
86
|
+
end.writeUInt32LE(directory.length, 12);
|
|
87
|
+
end.writeUInt32LE(offset, 16);
|
|
88
|
+
return Buffer.concat([...locals, directory, end]);
|
|
89
|
+
}
|
package/tools/install-chips.sh
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Builds c64run, the replay core of c64-testing: floooh/chips c64.h at a pinned
|
|
3
3
|
# commit with the line-command harness c64run.c next to this script. Installs
|
|
4
|
-
#
|
|
5
|
-
#
|
|
4
|
+
# /usr/local/bin/c64run and the three C64 ROMs that it loads to
|
|
5
|
+
# /usr/local/share/c64-re-tools/roms. install-container.sh runs it as root,
|
|
6
|
+
# with a C compiler and curl.
|
|
6
7
|
|
|
7
8
|
set -Eeuo pipefail
|
|
8
9
|
|
|
@@ -17,7 +18,7 @@ ROMS=(
|
|
|
17
18
|
"basic.901226-01.bin basic-901226-01.bin 89878cea0a268734696de11c4bae593eaaa506465d2029d619c0e0cbccdfa62d"
|
|
18
19
|
"characters.901225-01.bin chargen-901225-01.bin fd0d53b8480e86163ac98998976c72cc58d5dd8eb824ed7b829774e74213b420"
|
|
19
20
|
)
|
|
20
|
-
PREFIX="
|
|
21
|
+
PREFIX="/usr/local"
|
|
21
22
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
22
23
|
|
|
23
24
|
fail() {
|
|
@@ -25,20 +26,10 @@ fail() {
|
|
|
25
26
|
exit 1
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
CC="${CC:-$(command -v gcc || command -v cc || true)}"
|
|
31
|
-
if [[ -z "${CC}" ]] || ! command -v curl >/dev/null 2>&1; then
|
|
32
|
-
command -v apt-get >/dev/null 2>&1 || fail "a C compiler and curl are needed."
|
|
33
|
-
${SUDO} apt-get update
|
|
34
|
-
${SUDO} apt-get install -y --no-install-recommends build-essential ca-certificates curl
|
|
35
|
-
CC=gcc
|
|
36
|
-
fi
|
|
29
|
+
[[ "$(id -u)" -eq 0 ]] || fail "run as root."
|
|
37
30
|
|
|
38
31
|
check() {
|
|
39
|
-
|
|
40
|
-
if command -v sha256sum >/dev/null 2>&1; then sum="$(sha256sum "$2" | cut -d' ' -f1)"; else sum="$(shasum -a 256 "$2" | cut -d' ' -f1)"; fi
|
|
41
|
-
[[ "${sum}" == "$1" ]]
|
|
32
|
+
[[ "$(sha256sum "$2" | cut -d' ' -f1)" == "$1" ]]
|
|
42
33
|
}
|
|
43
34
|
|
|
44
35
|
BUILD_DIR="$(mktemp -d -t c64run-build-XXXXXXXX)"
|
|
@@ -55,12 +46,12 @@ for rom in "${ROMS[@]}"; do
|
|
|
55
46
|
check "${sha}" "${BUILD_DIR}/roms/${name}" || fail "the ROM ${name} has the wrong checksum."
|
|
56
47
|
done
|
|
57
48
|
|
|
58
|
-
|
|
49
|
+
gcc -O2 -Wall -Wno-unused-function -DCHIPS_COMMIT="\"${CHIPS_COMMIT:0:12}\"" \
|
|
59
50
|
-I "${BUILD_DIR}/chips-${CHIPS_COMMIT}" -o "${BUILD_DIR}/c64run" "${HERE}/c64run.c"
|
|
60
51
|
started="$(printf 'init %s\nquit\n' "${BUILD_DIR}/roms" | "${BUILD_DIR}/c64run")"
|
|
61
52
|
[[ "${started}" == ok*pc=fce2* ]] || fail "the compiled c64run does not reach the reset vector: ${started}"
|
|
62
53
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
54
|
+
install -d -m 0755 "${PREFIX}/bin" "${PREFIX}/share/c64-re-tools/roms"
|
|
55
|
+
install -m 0755 "${BUILD_DIR}/c64run" "${PREFIX}/bin/c64run"
|
|
56
|
+
install -m 0644 "${BUILD_DIR}"/roms/*.bin "${PREFIX}/share/c64-re-tools/roms/"
|
|
66
57
|
echo "c64run (chips ${CHIPS_COMMIT:0:12}) is installed in ${PREFIX}/bin/c64run, its ROMs in ${PREFIX}/share/c64-re-tools/roms."
|
package/tools/install-dxa.sh
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
set -Eeuo pipefail
|
|
4
4
|
|
|
5
5
|
# ------------------------------------------------------------
|
|
6
|
-
# dxa installer
|
|
6
|
+
# dxa installer. install-container.sh runs it as root, with build-essential
|
|
7
|
+
# and curl.
|
|
7
8
|
#
|
|
8
9
|
# Installs:
|
|
9
10
|
# /usr/local/bin/dxa
|
|
@@ -59,39 +60,10 @@ trap cleanup EXIT
|
|
|
59
60
|
|
|
60
61
|
|
|
61
62
|
# ------------------------------------------------------------
|
|
62
|
-
# Check
|
|
63
|
+
# Check user
|
|
63
64
|
# ------------------------------------------------------------
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
error "This script is intended for Debian/Ubuntu-style Linux systems."
|
|
67
|
-
fi
|
|
68
|
-
|
|
69
|
-
# shellcheck disable=SC1091
|
|
70
|
-
source /etc/os-release
|
|
71
|
-
|
|
72
|
-
case "${ID:-}" in
|
|
73
|
-
debian|ubuntu)
|
|
74
|
-
;;
|
|
75
|
-
*)
|
|
76
|
-
if [[ "${ID_LIKE:-}" != *debian* ]]; then
|
|
77
|
-
error "Unsupported distribution: ${ID:-unknown}. This script expects Debian or Ubuntu."
|
|
78
|
-
fi
|
|
79
|
-
;;
|
|
80
|
-
esac
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
# ------------------------------------------------------------
|
|
84
|
-
# Determine sudo command
|
|
85
|
-
# ------------------------------------------------------------
|
|
86
|
-
|
|
87
|
-
if [[ "$(id -u)" -eq 0 ]]; then
|
|
88
|
-
SUDO=""
|
|
89
|
-
else
|
|
90
|
-
command -v sudo >/dev/null 2>&1 ||
|
|
91
|
-
error "sudo is required when the script is not run as root."
|
|
92
|
-
|
|
93
|
-
SUDO="sudo"
|
|
94
|
-
fi
|
|
66
|
+
[[ "$(id -u)" -eq 0 ]] || error "Run as root."
|
|
95
67
|
|
|
96
68
|
|
|
97
69
|
# ------------------------------------------------------------
|
|
@@ -112,20 +84,6 @@ It will NOT install xa or xa65.
|
|
|
112
84
|
EOF
|
|
113
85
|
|
|
114
86
|
|
|
115
|
-
# ------------------------------------------------------------
|
|
116
|
-
# Install build requirements
|
|
117
|
-
# ------------------------------------------------------------
|
|
118
|
-
|
|
119
|
-
info "Installing build requirements"
|
|
120
|
-
|
|
121
|
-
${SUDO} apt-get update
|
|
122
|
-
|
|
123
|
-
${SUDO} apt-get install -y --no-install-recommends \
|
|
124
|
-
build-essential \
|
|
125
|
-
ca-certificates \
|
|
126
|
-
curl
|
|
127
|
-
|
|
128
|
-
|
|
129
87
|
# ------------------------------------------------------------
|
|
130
88
|
# Create temporary build directory
|
|
131
89
|
# ------------------------------------------------------------
|
|
@@ -260,9 +218,9 @@ echo "Compiled dxa binary runs."
|
|
|
260
218
|
|
|
261
219
|
info "Installing dxa"
|
|
262
220
|
|
|
263
|
-
|
|
221
|
+
install -d -m 0755 "${BIN_DIR}"
|
|
264
222
|
|
|
265
|
-
|
|
223
|
+
install \
|
|
266
224
|
-m 0755 \
|
|
267
225
|
"${DXA_BINARY}" \
|
|
268
226
|
"${BIN_DIR}/dxa"
|
|
@@ -284,15 +242,15 @@ if [[ -n "${DXA_MANPAGE}" ]]; then
|
|
|
284
242
|
|
|
285
243
|
info "Installing dxa manual page"
|
|
286
244
|
|
|
287
|
-
|
|
245
|
+
install -d -m 0755 "${MAN_DIR}"
|
|
288
246
|
|
|
289
|
-
|
|
247
|
+
install \
|
|
290
248
|
-m 0644 \
|
|
291
249
|
"${DXA_MANPAGE}" \
|
|
292
250
|
"${MAN_DIR}/dxa.1"
|
|
293
251
|
|
|
294
252
|
if command -v mandb >/dev/null 2>&1; then
|
|
295
|
-
|
|
253
|
+
mandb -q || true
|
|
296
254
|
fi
|
|
297
255
|
else
|
|
298
256
|
echo
|
package/tools/install-ghidra.sh
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Installs Ghidra in
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
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
6
|
|
|
7
7
|
set -Eeuo pipefail
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ GHIDRA_VERSION="12.1.3"
|
|
|
10
10
|
GHIDRA_ZIP="ghidra_${GHIDRA_VERSION}_PUBLIC_20260817.zip"
|
|
11
11
|
GHIDRA_URL="https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_${GHIDRA_VERSION}_build/${GHIDRA_ZIP}"
|
|
12
12
|
GHIDRA_SHA256="93a5d11a9ad510622acaaf908c556a7b9b764d338e78a7567f3689bf5081fd54"
|
|
13
|
-
DEST="
|
|
13
|
+
DEST="/opt"
|
|
14
14
|
GHIDRA_DIR="${DEST}/ghidra_${GHIDRA_VERSION}_PUBLIC"
|
|
15
15
|
|
|
16
16
|
fail() {
|
|
@@ -18,7 +18,7 @@ fail() {
|
|
|
18
18
|
exit 1
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
[[ "$(id -u)" -eq 0
|
|
21
|
+
[[ "$(id -u)" -eq 0 ]] || fail "run as root."
|
|
22
22
|
|
|
23
23
|
if [[ ! -d "${GHIDRA_DIR}" ]]; then
|
|
24
24
|
BUILD_DIR="$(mktemp -d -t ghidra-XXXXXXXX)"
|