@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
package/src/host/tools/index.ts
CHANGED
|
@@ -3,14 +3,12 @@
|
|
|
3
3
|
// ACME, DXA and Ghidra themselves. One entry per operation, never a
|
|
4
4
|
// generic executable route.
|
|
5
5
|
|
|
6
|
-
import type { ViceVersion } from "../../native/discover.ts";
|
|
7
6
|
import type { ProcessSupervisor } from "../../native/processes.ts";
|
|
8
7
|
import type { ToolContext } from "../../native/run.ts";
|
|
9
8
|
import type { ToolOperation, ToolOperations } from "../../protocol/tools.ts";
|
|
10
9
|
import type { ToolDispatcher } from "../server.ts";
|
|
11
10
|
import { inspect } from "./c1541.ts";
|
|
12
11
|
import { decode } from "./petcat.ts";
|
|
13
|
-
import { hostStatus } from "./status.ts";
|
|
14
12
|
|
|
15
13
|
/** Runs one operation with its validated parameters and attachments. */
|
|
16
14
|
type Adapter<O extends ToolOperation> = (
|
|
@@ -20,16 +18,13 @@ type Adapter<O extends ToolOperation> = (
|
|
|
20
18
|
) => Promise<{ result: ToolOperations[O]["result"]; attachments?: Buffer[] }>;
|
|
21
19
|
|
|
22
20
|
const ADAPTERS: { [O in ToolOperation]: Adapter<O> } = {
|
|
23
|
-
"host.status": (_params, _attachments, context) => hostStatus(context),
|
|
24
21
|
"c1541.inspect": (params, attachments, context) => inspect(params, attachments[0]!, context),
|
|
25
22
|
"petcat.decode": (_params, attachments, context) => decode(attachments[0]!, context),
|
|
26
23
|
};
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
export function createToolDispatcher(options: { supervisor: ProcessSupervisor; env?: NodeJS.ProcessEnv; log?: (line: string) => void; vice?: ViceVersion }): ToolDispatcher {
|
|
25
|
+
export function createToolDispatcher(options: { supervisor: ProcessSupervisor; env?: NodeJS.ProcessEnv; log?: (line: string) => void }): ToolDispatcher {
|
|
30
26
|
return (op, params, attachments, signal) => {
|
|
31
27
|
const context = { supervisor: options.supervisor, signal, env: options.env, log: options.log };
|
|
32
|
-
if (op === "host.status") return hostStatus(context, options.vice) as ReturnType<ToolDispatcher>;
|
|
33
28
|
return ADAPTERS[op](params, attachments, context);
|
|
34
29
|
};
|
|
35
30
|
}
|
package/src/host/vice/session.ts
CHANGED
|
@@ -476,7 +476,7 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
476
476
|
if (this.#autostarting && !this.#userWarp && (await this.#observe(() => this.#machine.warp()))) {
|
|
477
477
|
throw new WireFailure(
|
|
478
478
|
"operation-failed",
|
|
479
|
-
"The autostart still loads the program, and a key now stops it before RUN. Run frames with c64_execution advance-frames
|
|
479
|
+
"The autostart still loads the program, and a key now stops it before RUN. Run frames with c64_execution advance-frames, then type again.",
|
|
480
480
|
);
|
|
481
481
|
}
|
|
482
482
|
await this.#observe(() => this.#machine.feedKeyboard(bytes));
|
package/src/host-client/tools.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Short-lived typed requests to the Host Runtime for skill scripts:
|
|
2
2
|
// VICE's own tools (c1541, petcat) and the host tool status. Each request
|
|
3
3
|
// opens its own "tool" connection, sends bytes, and closes. Skill scripts run
|
|
4
|
-
// ACME, DXA and Ghidra themselves through src/native.
|
|
4
|
+
// ACME, DXA and Ghidra themselves through src/native (Ghidra in process).
|
|
5
5
|
|
|
6
6
|
import { ProtocolError, WireFailure } from "../protocol/messages.ts";
|
|
7
|
-
import { DISK_IMAGE_TYPES, validateToolResult, type C1541Result, type DiskAction, type DiskImageType, type DiskSector, type PetcatResult, type ToolOperation, type ToolOperations
|
|
7
|
+
import { DISK_IMAGE_TYPES, validateToolResult, type C1541Result, type DiskAction, type DiskImageType, type DiskSector, type PetcatResult, type ToolOperation, type ToolOperations } from "../protocol/tools.ts";
|
|
8
8
|
import { HostConnection } from "./connect.ts";
|
|
9
9
|
import { readPrg } from "./image.ts";
|
|
10
10
|
import { readProjectFile } from "./transfer.ts";
|
|
@@ -84,11 +84,6 @@ export async function decodeBasic(request: { program: string }, options: ToolCal
|
|
|
84
84
|
return (await callTool("petcat.decode", {}, [bytes], options)).result;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
/** host.status: the Host Runtime, and each native tool on the host, found and run once. */
|
|
88
|
-
export async function hostTools(options: ToolCallOptions = {}): Promise<{ host: HostInfo; tools: ToolStatus[] }> {
|
|
89
|
-
return (await callTool("host.status", {}, [], options)).result;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
87
|
/** Skill scripts see failures and wire limits through the host-client, never the private protocol module. */
|
|
93
88
|
export { WireFailure } from "../protocol/messages.ts";
|
|
94
89
|
export { DISK_ACTIONS, DISK_BLOCK_BYTES, DISK_IMAGE_TYPES, MAX_DISK_SECTORS } from "../protocol/tools.ts";
|
package/src/knowledge/read.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { DatabaseSync } from "node:sqlite";
|
|
|
7
7
|
import type { AddressRange } from "../c64.ts";
|
|
8
8
|
import { Refusal } from "../errors.ts";
|
|
9
9
|
import { DEFAULT_SPACE, type CommentPlacement, type OperandSelect, type Origin, type ReferenceKind, type RegionType, type Space, type StartScreenMode, type SuppressionEntity, type SwitchKind, type SymbolKind } from "./schema.ts";
|
|
10
|
-
import { NO_REVISION } from "./text.ts";
|
|
10
|
+
import { compareText, NO_REVISION, sqlName, TABLES } from "./text.ts";
|
|
11
11
|
|
|
12
12
|
export interface SymbolRow {
|
|
13
13
|
space: Space;
|
|
@@ -352,6 +352,21 @@ export function currentRevision(db: DatabaseSync | undefined): string {
|
|
|
352
352
|
return (db.prepare("SELECT max(id) AS id FROM revisions").get() as { id: string | null }).id ?? "0";
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
+
/**
|
|
356
|
+
* The newest revision that changed a row in one of `spaces`, or the revision
|
|
357
|
+
* of no knowledge when none did. A change in another space does not change it.
|
|
358
|
+
*/
|
|
359
|
+
export function spacesRevision(db: DatabaseSync | undefined, spaces: readonly Space[]): string {
|
|
360
|
+
if (db === undefined || spaces.length === 0) return NO_REVISION;
|
|
361
|
+
const marks = spaces.map(() => "?").join(", ");
|
|
362
|
+
let newest = NO_REVISION;
|
|
363
|
+
for (const spec of TABLES) {
|
|
364
|
+
const row = db.prepare(`SELECT max(valid_from_revision) AS added, max(valid_to_revision) AS closed FROM ${sqlName(spec.table)} WHERE space IN (${marks})`).get(...spaces) as { added: string | null; closed: string | null };
|
|
365
|
+
for (const id of [row.added, row.closed]) if (id !== null && compareText(id, newest) > 0) newest = id;
|
|
366
|
+
}
|
|
367
|
+
return newest;
|
|
368
|
+
}
|
|
369
|
+
|
|
355
370
|
/** One import of a coverage map: its project path, its SHA-256, the space it went into and the revision. */
|
|
356
371
|
export interface CoverageRun {
|
|
357
372
|
name: string;
|
package/src/mcp/server.ts
CHANGED
package/src/mcp/tools/machine.ts
CHANGED
|
@@ -1,50 +1,11 @@
|
|
|
1
|
-
// Machine tools:
|
|
1
|
+
// Machine tools: c64_reset, c64_warp and c64_window.
|
|
2
2
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
5
|
import { formatC64Address } from "../../c64.ts";
|
|
6
|
-
import {
|
|
7
|
-
import { POINT_STOP_REASONS, RESET_MODES, RUN_STATES, SPACES, WINDOW_ACTIONS } from "../../protocol/vice.ts";
|
|
6
|
+
import { RESET_MODES, RUN_STATES, WINDOW_ACTIONS } from "../../protocol/vice.ts";
|
|
8
7
|
import { AddressOutput, defineTool } from "../server.ts";
|
|
9
8
|
|
|
10
|
-
export const c64Status = defineTool({
|
|
11
|
-
name: "c64_status",
|
|
12
|
-
title: "C64 status",
|
|
13
|
-
description:
|
|
14
|
-
"Get the state of the C64. The result tells if the CPU runs or has stopped, the video standard (pal or ntsc), " +
|
|
15
|
-
"and if warp mode is on. It also tells if the emulator window is open (window). " +
|
|
16
|
-
"When the CPU has stopped, the result also gives the program counter (pc). " +
|
|
17
|
-
"When a breakpoint, a watchpoint or a JAM opcode stopped the CPU, stopReason tells which, and pointId gives the id of the breakpoint or watchpoint. " +
|
|
18
|
-
"cartridge is true while a cartridge from c64_autostart is attached: a reset keeps it, and an autostart of another file detaches it.",
|
|
19
|
-
inputSchema: z.object({}).strict(),
|
|
20
|
-
outputSchema: z.object({
|
|
21
|
-
state: z.enum(RUN_STATES),
|
|
22
|
-
videoStandard: z.enum(VIDEO_STANDARDS),
|
|
23
|
-
warp: z.boolean(),
|
|
24
|
-
window: z.boolean().describe("true when the emulator window is open (c64_window)"),
|
|
25
|
-
pc: AddressOutput.optional().describe("program counter. Only when the CPU is stopped"),
|
|
26
|
-
stopReason: z.enum(POINT_STOP_REASONS).optional().describe("what stopped the CPU. Only when a breakpoint, a watchpoint or a JAM opcode stopped it"),
|
|
27
|
-
pointId: z.number().int().min(1).optional().describe("the id of the breakpoint or watchpoint that stopped the CPU"),
|
|
28
|
-
space: z.enum(SPACES).optional().describe("with pc: c64, or drive8 when a breakpoint or watchpoint in the disk drive stopped the CPU. pc is the address in that space"),
|
|
29
|
-
cartridge: z.boolean().describe("true while a cartridge from c64_autostart is attached"),
|
|
30
|
-
}),
|
|
31
|
-
readOnly: true,
|
|
32
|
-
async run(_input, session) {
|
|
33
|
-
const status = await session.status();
|
|
34
|
-
return {
|
|
35
|
-
state: status.state,
|
|
36
|
-
videoStandard: status.videoStandard,
|
|
37
|
-
warp: status.warp,
|
|
38
|
-
window: status.window,
|
|
39
|
-
cartridge: status.cartridge,
|
|
40
|
-
...(status.pc === undefined ? {} : { pc: formatC64Address(status.pc) }),
|
|
41
|
-
...(status.stopReason === undefined ? {} : { stopReason: status.stopReason }),
|
|
42
|
-
...(status.pointId === undefined ? {} : { pointId: status.pointId }),
|
|
43
|
-
...(status.space === undefined ? {} : { space: status.space }),
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
|
|
48
9
|
export const c64Window = defineTool({
|
|
49
10
|
name: "c64_window",
|
|
50
11
|
title: "Emulator window",
|
|
@@ -104,4 +65,4 @@ export const c64Warp = defineTool({
|
|
|
104
65
|
},
|
|
105
66
|
});
|
|
106
67
|
|
|
107
|
-
export const machineTools = [
|
|
68
|
+
export const machineTools = [c64Reset, c64Warp, c64Window];
|
package/src/mcp/tools/media.ts
CHANGED
|
@@ -30,7 +30,7 @@ export const c64Autostart = defineTool({
|
|
|
30
30
|
"Without index, a disk image loads like LOAD\"*\",8,1. index selects one directory entry by its number in the directory list of the disk (0 is the first entry). " +
|
|
31
31
|
"The tool refuses an index of a DEL entry, or an index after the last entry. " +
|
|
32
32
|
"The machine runs when this tool returns, and the load continues. The emulator keeps warp mode on until it types RUN. " +
|
|
33
|
-
"A key in that time stops the autostart, so c64_keyboard refuses keys until then. Run frames with c64_execution advance-frames
|
|
33
|
+
"A key in that time stops the autostart, so c64_keyboard refuses keys until then. Run frames with c64_execution advance-frames, then type again. " +
|
|
34
34
|
"The c64_timing stopwatch starts again from zero.",
|
|
35
35
|
inputSchema: z
|
|
36
36
|
.object({
|
package/src/native/dxa.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// changed listing is refused instead of half imported.
|
|
7
7
|
|
|
8
8
|
import { writeFileSync } from "node:fs";
|
|
9
|
+
import { stripVTControlCharacters } from "node:util";
|
|
9
10
|
|
|
10
11
|
import { Refusal } from "../errors.ts";
|
|
11
12
|
import { SYMBOL_NAME } from "../c64.ts";
|
|
@@ -14,7 +15,17 @@ import { checkDxaResult, checkRequestBounds, imageRange, seedsInside, type DxaPa
|
|
|
14
15
|
import { Workspace } from "./staging.ts";
|
|
15
16
|
import { DXA, findTool } from "./discover.ts";
|
|
16
17
|
import { outputTail, runTool, runToolOrFail, type ToolContext } from "./run.ts";
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
/** dxa's version line, also as "D:\\tools\\dxa.exe v0.1.5 -- symbolic 65xx disassembler" on Windows. */
|
|
20
|
+
export const DXA_VERSION = /^(?:.*[\\/])?dxa(?:\.exe)? v\d/i;
|
|
21
|
+
|
|
22
|
+
/** The first output line that matches, without terminal color codes. */
|
|
23
|
+
export function versionLine(output: string, pattern: RegExp): string | undefined {
|
|
24
|
+
return stripVTControlCharacters(output)
|
|
25
|
+
.split(/\r?\n/)
|
|
26
|
+
.map((line) => line.trim())
|
|
27
|
+
.find((line) => pattern.test(line));
|
|
28
|
+
}
|
|
18
29
|
|
|
19
30
|
const TIMEOUT_MS = 120_000;
|
|
20
31
|
/** The listing is returned as an attachment; larger output is refused. */
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
// The Ghidra analysis:
|
|
2
|
-
// 6510 language,
|
|
3
|
-
//
|
|
1
|
+
// The Ghidra analysis: the Ghidra SLEIGH decoder and decompiler with the NMOS
|
|
2
|
+
// 6510 language, in this process as a WebAssembly module. Knowledge seeds go
|
|
3
|
+
// in, the structural result comes out, and the result is checked completely
|
|
4
|
+
// before the script imports it.
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { Refusal } from "../../errors.ts";
|
|
8
|
-
import { describeError, isObject, WireFailure } from "../../protocol/messages.ts";
|
|
6
|
+
import { describeError, WireFailure } from "../../protocol/messages.ts";
|
|
9
7
|
import { checkGhidraResult, checkRequestBounds, GHIDRA_LIMITS, imageRange, seedsInside, type GhidraParams, type GhidraResult } from "../types.ts";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import type { ToolContext } from "../run.ts";
|
|
9
|
+
import { walk } from "./walk.ts";
|
|
10
|
+
import { decompile, loadImage, setName, SLEIGH_VERSION } from "./wasm.ts";
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const AFTER_DECOMPILE_MS = 30_000;
|
|
12
|
+
/** The longest reason that the result check accepts. */
|
|
13
|
+
const MAX_REASON = 1000;
|
|
17
14
|
|
|
18
15
|
export async function analyze(
|
|
19
16
|
params: GhidraParams,
|
|
@@ -21,67 +18,81 @@ export async function analyze(
|
|
|
21
18
|
context: ToolContext,
|
|
22
19
|
): Promise<{ result: GhidraResult }> {
|
|
23
20
|
checkRequestBounds(params);
|
|
24
|
-
const ghidra = findGhidra(context.env);
|
|
25
21
|
const { start, end, body } = imageRange(params.imageKind, image);
|
|
26
|
-
const base = start;
|
|
27
22
|
|
|
28
|
-
//
|
|
23
|
+
// The decoder sees only the loaded bytes; labels may name any address.
|
|
29
24
|
const { entryPoints, codeStarts, dataRanges } = seedsInside(params, start, end);
|
|
30
25
|
if (entryPoints.length === 0) {
|
|
31
26
|
throw new WireFailure("invalid-input", "Give at least one entry point inside the program, for example the SYS address of its BASIC loader.");
|
|
32
27
|
}
|
|
28
|
+
context.signal.throwIfAborted();
|
|
33
29
|
|
|
34
|
-
|
|
30
|
+
let walked: ReturnType<typeof walk>;
|
|
35
31
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
32
|
+
loadImage(body, start);
|
|
33
|
+
walked = walk(body, start, end, { entryPoints, codeStarts, dataRanges, labels: params.labels });
|
|
34
|
+
} catch (error) {
|
|
35
|
+
context.log?.(`The Ghidra decoder failed: ${describeError(error)}`);
|
|
36
|
+
throw new WireFailure("operation-failed", `The Ghidra decoder failed: ${describeError(error)}. Nothing was imported.`);
|
|
37
|
+
}
|
|
38
|
+
const { decompilations, notDecompiled } = decompileRoutines(params, walked.functions, body, start, context);
|
|
39
|
+
|
|
40
|
+
let result: GhidraResult;
|
|
41
|
+
try {
|
|
42
|
+
result = checkGhidraResult({ ...walked, decompilations, notDecompiled, completeness: { functions: true, regions: true, references: true }, toolVersion: SLEIGH_VERSION });
|
|
43
|
+
} catch (error) {
|
|
44
|
+
context.log?.(`Ghidra result rejected: ${describeError(error)}`);
|
|
45
|
+
throw new WireFailure("operation-failed", `Ghidra returned an incomplete or inconsistent result. Nothing was imported. The check found: ${describeError(error)}.`);
|
|
46
|
+
}
|
|
47
|
+
return { result };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The requested routines as C text, within the character bounds; the labels name routines and data. */
|
|
51
|
+
function decompileRoutines(params: GhidraParams, functions: GhidraResult["functions"], body: Uint8Array, start: number, context: ToolContext): Pick<GhidraResult, "decompilations" | "notDecompiled"> {
|
|
52
|
+
const decompilations: GhidraResult["decompilations"] = [];
|
|
53
|
+
const notDecompiled: NonNullable<GhidraResult["notDecompiled"]> = [];
|
|
54
|
+
if (params.decompile.length === 0) return { decompilations, notDecompiled };
|
|
55
|
+
const entries = new Set(functions.map((fn) => fn.entry));
|
|
56
|
+
// A trap in the decompiler drops its image: the next routine loads it again.
|
|
57
|
+
let prepared = false;
|
|
58
|
+
const prepare = () => {
|
|
59
|
+
if (prepared) return;
|
|
60
|
+
loadImage(body, start);
|
|
61
|
+
for (const label of params.labels) {
|
|
62
|
+
try {
|
|
63
|
+
setName(label.address, label.name, entries.has(label.address) ? "function" : "data");
|
|
64
|
+
} catch (error) {
|
|
65
|
+
// The decompiler then prints its own name for the address.
|
|
66
|
+
context.log?.(`The Ghidra decompiler refused the name ${label.name}: ${describeError(error)}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
prepared = true;
|
|
70
|
+
};
|
|
71
|
+
let remaining = GHIDRA_LIMITS.decompiledTotalChars;
|
|
72
|
+
for (const entry of params.decompile) {
|
|
73
|
+
if (!entries.has(entry)) {
|
|
74
|
+
notDecompiled.push({ entry, reason: "no function starts at this address" });
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (remaining <= 0) {
|
|
78
|
+
notDecompiled.push({ entry, reason: "the decompiled text of the other routines used the whole limit" });
|
|
79
|
+
continue;
|
|
71
80
|
}
|
|
72
|
-
let
|
|
81
|
+
let text: string;
|
|
73
82
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
result = checkGhidraResult(isObject(exported) ? { ...exported, toolVersion: ghidraVersion(ghidra) } : exported);
|
|
77
|
-
const [range] = result.coverage;
|
|
78
|
-
if (result.coverage.length !== 1 || range === undefined || range.start !== start || range.end !== end) throw new Refusal("operation-failed", "the coverage is not the loaded program");
|
|
83
|
+
prepare();
|
|
84
|
+
text = decompile(entry);
|
|
79
85
|
} catch (error) {
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
prepared = false;
|
|
87
|
+
context.log?.(`The Ghidra decompiler failed at ${entry}: ${describeError(error)}`);
|
|
88
|
+
notDecompiled.push({ entry, reason: describeError(error).slice(0, MAX_REASON) || "the decompiler gave no reason" });
|
|
89
|
+
continue;
|
|
82
90
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
91
|
+
const limit = Math.min(GHIDRA_LIMITS.decompiledChars, remaining);
|
|
92
|
+
const truncated = text.length > limit;
|
|
93
|
+
if (truncated) text = text.slice(0, limit);
|
|
94
|
+
remaining -= text.length;
|
|
95
|
+
decompilations.push({ entry, text, truncated });
|
|
86
96
|
}
|
|
97
|
+
return { decompilations, notDecompiled };
|
|
87
98
|
}
|