Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e65a13f54d | ||
|
|
c11a75cbe9 | ||
|
|
22326e8199 | ||
|
|
3f6dcbc096 | ||
|
|
89a7ca8486 | ||
|
|
15cc7ce6a6 | ||
|
|
d0b60a97ab | ||
|
|
e3d4ac12b3 | ||
|
|
b5e4920823 |
@@ -2,7 +2,7 @@
|
||||
name: reverse-engineer-anything
|
||||
description: Reverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.
|
||||
metadata:
|
||||
version: "39"
|
||||
version: "38"
|
||||
---
|
||||
|
||||
# REA
|
||||
|
||||
@@ -150,13 +150,6 @@ For headerless DOS COM, explicitly open with `format: "dos-com"` (CLI
|
||||
analysis: the entry is `0x10100`, file offset zero, with imposed real-mode segment
|
||||
context. PSP/stack/device state remains unmodeled. See [DOS guide](https://github.com/morluto/rea/blob/main/docs/ghidra-dos.md).
|
||||
|
||||
For other headerless images (embedded firmware without ELF/Mach-O/PE/MZ
|
||||
headers), open with `format: "raw-binary"`, `architecture` (`x86`, `x86_64`,
|
||||
`arm`, or `arm64`), and `entry_point` (`0x` hex). File offset 0 is mapped at
|
||||
that address. Hopper and IDA refuse this interpretation; Ghidra uses
|
||||
`BinaryLoader` with a little-endian generic language. Big-endian, Thumb-only,
|
||||
and Cortex-M variants are unsupported. See [raw binary guide](https://github.com/morluto/rea/blob/main/docs/raw-binary.md).
|
||||
|
||||
### Function annotations in Ghidra
|
||||
|
||||
Use `annotate_native_function` for one function name and/or entry comments, with at least one explicit change. Review its annotation readback and refreshed dossier inline. Changes are atomic and session-scoped; empty comments clear them, omitted fields preserve them. Later MCP calls observe edits until close. CLI `annotate-native-function` returns the updated analysis before discarding the session. Original executable bytes are unchanged; edits invalidate immutable snapshots. Windows P0 does not admit database mutations. For naming only, `set_address_name` / `set_addresses_names` also work with Ghidra: they name function entries or data addresses (primary labels) and return compact per-address success booleans instead of a dossier.
|
||||
|
||||
@@ -126,20 +126,6 @@ class ReaJadxBridge {
|
||||
return result;
|
||||
}
|
||||
|
||||
private JadxSession.SmartCode methodBody(JadxSession current, ClassSnapshot cls,
|
||||
MethodSnapshot selected, JavaMethod method) {
|
||||
if (!selected.shortId().equals("<clinit>()V"))
|
||||
return current.getMethodBodySmart(method, current.getMaxSourceBytes(), true);
|
||||
// Java code generation can fold all or part of <clinit> into field declarations.
|
||||
// Its method text cannot establish coverage, even when a static block remains.
|
||||
JadxSession.MethodSmali smali = current.getMethodSmali(cls.node(), method.getName());
|
||||
if (!smali.getFound() || smali.getBlocks().size() != 1)
|
||||
throw new IllegalArgumentException("Static initializer disassembly requires one exact method: " + selected.shortId());
|
||||
return new JadxSession.SmartCode(
|
||||
TextUtilKt.truncateToBytes(smali.getBlocks().get(0), current.getMaxSourceBytes()),
|
||||
"smali", true, List.of("static_initializer_disassembly"));
|
||||
}
|
||||
|
||||
private CallToolResult handle(String name, JsonObject args) {
|
||||
if (name.equals("rea_jvm_status")) return json(Map.of(
|
||||
"engine_reported_version", BuildInfo.VERSION,
|
||||
@@ -164,7 +150,7 @@ class ReaJadxBridge {
|
||||
int index = integer(args, "overload_index", 0);
|
||||
if (index >= overloads.size()) throw new InputFailure("overload_index", "overload_index out of range: " + index);
|
||||
JavaMethod method = method(cls, overloads.get(index));
|
||||
JadxSession.SmartCode code = methodBody(current, cls, overloads.get(index), method);
|
||||
JadxSession.SmartCode code = current.getMethodBodySmart(method, current.getMaxSourceBytes(), true);
|
||||
return json(Map.of("class_name", cls.summary().get("full_name"),
|
||||
"method_name", overloads.get(index).name(), "full_name", method.getFullName(),
|
||||
"overload_index", index, "overload_count", overloads.size(),
|
||||
@@ -225,7 +211,7 @@ class ReaJadxBridge {
|
||||
String description = switch (name) {
|
||||
case "list_classes" -> "Indexed pages of all top-level class names, with offset and limit.";
|
||||
case "get_class_summary" -> "Parsed member metadata for one exact class name; no source generation.";
|
||||
case "get_method_body" -> "Source for an exact class and stable same-name overload index; static initializers use smali to preserve folded field initialization.";
|
||||
case "get_method_body" -> "Source for an exact class and stable same-name overload index, with smali fallback.";
|
||||
default -> "Complete static references to an exact class or unique method; source lines are unresolved.";
|
||||
};
|
||||
Tool narrowed = new Tool(name, new ToolSchema(null, new JsonObject(properties),
|
||||
|
||||
@@ -182,17 +182,10 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
||||
}
|
||||
sessionDefaultAddressSpace =
|
||||
currentProgram.getAddressFactory().getDefaultAddressSpace();
|
||||
if (currentProgram.getExecutableFormat().equals("Raw Binary")) {
|
||||
boolean dosCom = currentProgram.getLanguageID().getIdAsString()
|
||||
.equals("x86:LE:16:Real Mode");
|
||||
String preparation = dosCom ? "REA DOS COM prepared" : "REA raw binary prepared";
|
||||
if (!currentProgram.getOptions(ghidra.program.model.listing.Program.PROGRAM_INFO)
|
||||
.getBoolean(preparation, false)) {
|
||||
throw new IllegalStateException(
|
||||
dosCom ? "REA DOS COM entry/context preparation failed" :
|
||||
"REA raw binary entry preparation failed"
|
||||
);
|
||||
}
|
||||
if (currentProgram.getExecutableFormat().equals("Raw Binary") &&
|
||||
!currentProgram.getOptions(ghidra.program.model.listing.Program.PROGRAM_INFO)
|
||||
.getBoolean("REA DOS COM prepared", false)) {
|
||||
throw new IllegalStateException("REA DOS COM entry/context preparation failed");
|
||||
}
|
||||
if (!Application.getApplicationVersion().equals(descriptor.providerVersion)) {
|
||||
throw new IllegalStateException("Ghidra provider version does not match the session");
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.listing.Program;
|
||||
|
||||
/** Seed the caller-supplied raw-binary entry before default auto-analysis. */
|
||||
public final class ReaGhidraPrepareRaw extends GhidraScript {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
String[] arguments = getScriptArgs();
|
||||
if (arguments.length != 2) {
|
||||
throw new IllegalArgumentException(
|
||||
"Raw binary preparation requires the committed language and entry address"
|
||||
);
|
||||
}
|
||||
String expectedLanguage = arguments[0];
|
||||
String entryHex = arguments[1];
|
||||
if (!currentProgram.getLanguageID().getIdAsString().equals(expectedLanguage) ||
|
||||
!currentProgram.getExecutableFormat().equals("Raw Binary")) {
|
||||
throw new IllegalArgumentException(
|
||||
"Raw binary preparation requires the committed language and BinaryLoader import"
|
||||
);
|
||||
}
|
||||
Address entry = currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(entryHex);
|
||||
Address start = currentProgram.getMinAddress();
|
||||
if (entry == null || !entry.equals(start)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Raw binary import must map file offset 0 at the caller-supplied entry"
|
||||
);
|
||||
}
|
||||
addEntryPoint(entry);
|
||||
if (!disassemble(entry) || createFunction(entry, "entry") == null) {
|
||||
throw new IllegalStateException("Raw binary entry cannot be decoded as a function");
|
||||
}
|
||||
currentProgram.getOptions(Program.PROGRAM_INFO).setBoolean("REA raw binary prepared", true);
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,6 @@ export default defineConfig({
|
||||
{ text: "IDA", link: "/ida-provider" },
|
||||
{ text: "Ghidra on Windows", link: "/windows-ghidra-p0" },
|
||||
{ text: "Ghidra DOS analysis", link: "/ghidra-dos" },
|
||||
{ text: "Ghidra raw binary", link: "/raw-binary" },
|
||||
{ text: "Ghidra NativeAOT", link: "/ghidra-nativeaot" },
|
||||
{ text: "Ghidra semantics", link: "/ghidra-provider" },
|
||||
],
|
||||
|
||||
@@ -94,12 +94,6 @@ fallback for an overloaded method instead of attributing all bodies to one
|
||||
selected overload. Native/abstract methods with no decompiled body report
|
||||
`body_status: "not_available"` without inferring which implementation flag caused it.
|
||||
|
||||
Static initializers (`<clinit>`) return smali with the
|
||||
`static_initializer_disassembly` marker. Java decompilation can move their
|
||||
instructions into field declarations, leaving an empty or incomplete method
|
||||
body. The selected method's disassembly preserves those instructions and retains
|
||||
the same source byte limit and explicit truncation reporting.
|
||||
|
||||
## Interpret the result
|
||||
|
||||
- Package inspection retains decoded manifest XML, summary declarations,
|
||||
|
||||
+1
-2
@@ -59,8 +59,7 @@ alone, use `rea instructions`. A macOS `.app` bundle can be supplied directly.
|
||||
Run `rea --help` or a command's `--help` for arguments and output options.
|
||||
The [generated catalog](product-catalog.json) lists all CLI commands and MCP
|
||||
tools. Provider-specific target support is described in the
|
||||
[native guide](native-investigation.md), [DOS guide](ghidra-dos.md),
|
||||
[raw binary guide](raw-binary.md), and
|
||||
[native guide](native-investigation.md), [DOS guide](ghidra-dos.md), and
|
||||
[Windows Ghidra guide](windows-ghidra-p0.md).
|
||||
|
||||
## Choose a provider
|
||||
|
||||
@@ -323,44 +323,15 @@ substitute version-dependent Electron defaults for omitted `webPreferences`.
|
||||
Dynamic option objects, bridge keys, API objects, and IPC channel expressions
|
||||
remain unknown and make coverage partial.
|
||||
|
||||
Electron API identity follows proven lexical module aliases. Namespace interop
|
||||
also preserves identity when the complete Rolldown helper operations, lexical
|
||||
roles, live getters, and captured intrinsic origins match, or when a stable
|
||||
helper simply returns its module parameter. Harmless single-statement control
|
||||
blocks preserve recognition; added operations still require proof. Literal
|
||||
member and destructuring projections are retained from proven results.
|
||||
Omitted or literal node-mode arguments preserve named exports; a module-valued
|
||||
default projection requires a truthy literal node mode. Computed or extra
|
||||
arguments remain unresolved.
|
||||
Recognition uses structure rather than emitted names; other helper bodies and ambiguous
|
||||
runtime fallbacks remain unresolved. Captured function identities survive later global-property
|
||||
replacement, including copies through initialized aliases. Reads before an
|
||||
alias initializer remain unresolved. Visible intrinsic writes before capture or
|
||||
conversion are checked in their owning callable scope, including identifier leaves in nested/default/rest
|
||||
destructuring and loop targets. Property keys and shadowed local bindings do not
|
||||
overwrite the global intrinsic identity. Cross-call side effects, including
|
||||
writes inside directly invoked local functions, are not evaluated. Other
|
||||
reassignments, dynamic selections, and visibly overwritten namespace members
|
||||
are unresolved.
|
||||
Known Object/Reflect mutators remain recognizable through literal destructuring
|
||||
of intrinsic objects and stable bound-function aliases. Calls retain bound
|
||||
argument prefixes and the original bound receiver through `call`, `apply`, and
|
||||
`Reflect.apply`, including generic `Function.prototype` invocation and binding
|
||||
creation. Arguments follow each actual callable invocation rather than property
|
||||
chain depth; rebinding retains the original bound receiver.
|
||||
Visibly replaced invocation intrinsics produce unknown effects instead
|
||||
of using their former call semantics; captured function aliases retain their
|
||||
earlier identity. Unexamined targets remain unresolved. `Reflect.set` examines
|
||||
its explicit receiver as well as its target, retaining unknown receiver effects.
|
||||
Creating an unused binding does not itself mutate an intrinsic. Variable
|
||||
redeclarations retain a single unconditional initializer
|
||||
when they introduce no assignment or second initializer.
|
||||
Stable identifier chains to fresh object, array, function,
|
||||
undecorated class or RegExp syntax keep those targets separate from intrinsic
|
||||
objects when initialized before use; opaque, decorated, reassigned or
|
||||
not-yet-initialized targets remain unresolved. Writes during class initialization
|
||||
are still retained. Function declarations are available before their textual
|
||||
position; variable and class initializers must precede use.
|
||||
Electron API identity follows proven lexical module aliases. Bundled CommonJS
|
||||
namespace imports are also followed through the interop helpers that bundlers
|
||||
and compilers emit (`__toESM`, `__importStar`, `_interopRequireWildcard`),
|
||||
including the `electron = __toESM(electron)` rewrap that Rolldown emits. This
|
||||
step is inferred: a helper is recognized by its emitted name and a single
|
||||
program-scope function definition, and its body is not evaluated, so a local
|
||||
function that reuses one of these names is trusted to pass the module through.
|
||||
Other reassigned bindings, dynamic selections, and visibly overwritten namespace
|
||||
members are unresolved.
|
||||
Direct and destructuring assignment, loop, update, and delete targets are checked
|
||||
through namespace aliases; unrelated member writes do not discard observed API
|
||||
identity. This static check does
|
||||
|
||||
+8
-23
@@ -150,15 +150,13 @@ structured data and matching text projection. Oversized errors are retained
|
||||
as Evidence before delivery of a bounded diagnostic with an export reference;
|
||||
if retention is unavailable or fails, the diagnostic reports that reason.
|
||||
|
||||
REA accepts ordinary `tools/call` progress tokens. The numeric `progress` counts
|
||||
emitted status observations and strictly increases, including when a waiting
|
||||
phase has completed no additional work. Updates are rate-bounded to at most one
|
||||
intermediate update per 100 ms and always allow a terminal update. `total` is
|
||||
omitted because the number of future status observations is unknown. Read
|
||||
`message` for the phase and observed work; REA does not fabricate percentages.
|
||||
REA accepts ordinary `tools/call` progress tokens. Updates are monotonic,
|
||||
rate-bounded to at most one intermediate update per 100 ms, and always allow a
|
||||
terminal update. Unknown totals are omitted; REA does not fabricate percentages.
|
||||
`capture_process_scenario` uses that boundary only when the client supplies a
|
||||
progress token. Notifications put the lifecycle phase, elapsed time, and final
|
||||
cleanup status in `message`. A client
|
||||
progress token. Notifications set `progress` to the count of collected terminal
|
||||
frames, process samples, and interaction events, omit `total`, and put the
|
||||
lifecycle phase, elapsed time, and final cleanup status in `message`. A client
|
||||
that does not send a progress token receives no progress notifications. The
|
||||
tool result is unchanged either way.
|
||||
Provider calls receive the request cancellation signal. Artifact traversal,
|
||||
@@ -232,18 +230,6 @@ engine readiness or a percentage of Ghidra auto-analysis. A longer server
|
||||
startup allowance does not extend the client's deadline; progress also does not
|
||||
extend it unless the client explicitly implements that policy.
|
||||
|
||||
While Ghidra startup is pending, REA sends a waiting notification every ten
|
||||
seconds when the request has a progress token. Its message gives elapsed waiting
|
||||
time; import, auto-analysis and bridge readiness may all still be pending.
|
||||
Waiting notifications stop when startup settles or the caller cancels. They do
|
||||
not measure engine work completed.
|
||||
|
||||
The pinned SDK can reset the request's inactivity timeout on progress with
|
||||
`resetTimeoutOnProgress: true`. Also set `maxTotalTimeout` to bound the complete
|
||||
request; the provider's startup deadline still applies. These options belong in
|
||||
the same second argument of `callTool`. Without that explicit client policy, the
|
||||
default 60-second request deadline still expires despite waiting notifications.
|
||||
|
||||
The 240-second setting is a measured example, not a universal timeout: a
|
||||
controlled Linux x64/WSL2 fixture took about 64 seconds for its first overview
|
||||
with Ghidra 12.1.4 on a mounted NTFS installation, native JDK 21, two CPUs, and a
|
||||
@@ -279,10 +265,9 @@ observed process-family member remained after final close. This was a small
|
||||
1,024-byte fixture, so the longer request setting remains an example, not a
|
||||
guarantee for larger targets. No macOS cold-start recovery was exercised.
|
||||
|
||||
With a supplied progress token, that earlier Windows run received an operation-start
|
||||
With a supplied progress token, the Windows run received an operation-start
|
||||
notification before timeout and start/completion notifications for the
|
||||
successful retry, before startup waiting notifications were added. It received
|
||||
no intermediate import or auto-analysis progress.
|
||||
successful retry. It received no intermediate import or auto-analysis progress.
|
||||
These operation markers do not measure analysis work completed or extend the
|
||||
client's deadline. Each new provider session still imports the target into a
|
||||
fresh temporary project.
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
# Headerless raw-binary analysis with Ghidra
|
||||
|
||||
REA admits a headerless executable when the caller supplies the CPU family and
|
||||
the address where file offset 0 should be mapped. That interpretation is not
|
||||
inferred from a `.bin` suffix or from unrecognized bytes.
|
||||
|
||||
## Open and inspect
|
||||
|
||||
```bash
|
||||
rea inspect /absolute/path/to/ecu.bin --target-format raw-binary --architecture arm --entry-point 0x8000000 --provider ghidra --json
|
||||
rea function /absolute/path/to/ecu.bin 0x8000000 --target-format raw-binary --architecture arm --entry-point 0x8000000 --provider ghidra --json
|
||||
rea inspect-native-load-image /absolute/path/to/ecu.bin --target-format raw-binary --architecture arm --entry-point 0x8000000 --provider ghidra --json
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "open_binary",
|
||||
"arguments": {
|
||||
"path": "/absolute/path/to/ecu.bin",
|
||||
"format": "raw-binary",
|
||||
"architecture": "arm",
|
||||
"entry_point": "0x8000000",
|
||||
"provider_id": "ghidra"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`architecture` is one of `x86`, `x86_64`, `arm`, or `arm64`. `entry_point` is a
|
||||
hexadecimal address of the form `0x…`. The complete file is mapped starting at
|
||||
that address, and Ghidra seeds an `entry` function there before auto-analysis.
|
||||
ARM and AArch64 entries must be 4-byte aligned; x86 entries may be byte-aligned.
|
||||
`open_binary` and an open `binary_session` return the canonical `entry_point`
|
||||
for raw targets so callers can verify the selected mapping directly.
|
||||
Omitted `format` keeps header-based detection; architecture and entry without
|
||||
`format=raw-binary` are rejected.
|
||||
|
||||
Ghidra imports a private snapshot with `BinaryLoader` and these little-endian
|
||||
generic languages:
|
||||
|
||||
| architecture | language_id |
|
||||
| ------------ | ------------------- |
|
||||
| x86 | `x86:LE:32:default` |
|
||||
| x86_64 | `x86:LE:64:default` |
|
||||
| arm | `ARM:LE:32:v7` |
|
||||
| arm64 | `AARCH64:LE:64:v8A` |
|
||||
|
||||
Those settings, the caller-supplied entry, and `language_selection:
|
||||
caller-supplied-v1` are committed in the analysis profile. A different entry
|
||||
or architecture is a different profile; snapshots from header-detected targets
|
||||
do not replay.
|
||||
|
||||
The mapped start is independent of Ghidra's program image base, which remains
|
||||
`0x0` for BinaryLoader. Ghidra may report additional language-defined entry
|
||||
points, including unmapped ARM vectors. Load-image verification requires the
|
||||
caller-supplied entry and preserves those other entries as observations.
|
||||
Independent raw verification streams the complete private snapshot digest and
|
||||
extent with bounded memory and supports cancellation during the read.
|
||||
|
||||
Hopper and IDA refuse raw-binary targets. Windows Ghidra P0 continues to admit
|
||||
PE applications only.
|
||||
|
||||
## Limitations
|
||||
|
||||
- Headers are not discovered from file bytes. This increment does not guess
|
||||
load addresses, vector tables, or memory maps.
|
||||
- Big-endian, Thumb-only, Cortex-M, and other Ghidra processor variants are
|
||||
unsupported.
|
||||
- Reset vectors, memory-mapped I/O, and firmware boot sequences are not
|
||||
emulated.
|
||||
- Independent load-image verification covers source identity, mapped file
|
||||
bytes, the bound language, and the caller-supplied entry. Original bytes
|
||||
stay unchanged.
|
||||
@@ -793,14 +793,6 @@ truncation constraint, while leading-zero coordinates still resolve correctly.
|
||||
It has the same Ghidra/JDK prerequisites as the MZ lane. Neither lane claims DOS
|
||||
runtime or PC-98 device execution.
|
||||
|
||||
`npm run verify:ghidra:raw` uses a generated ARM little-endian headerless image
|
||||
through the compiled CLI and stdio MCP server. With the same Ghidra/JDK
|
||||
prerequisites, it checks preparation and bridge startup, verified load mappings,
|
||||
instruction and byte readback, canonical-entry session reuse, replacement when
|
||||
the entry changes without `provider_id`, unchanged source bytes, and owned
|
||||
cleanup. Other raw CPU families remain covered by deterministic tests rather
|
||||
than this real-provider lane. See [raw binary analysis](raw-binary.md).
|
||||
|
||||
## Apple Interface Builder archives
|
||||
|
||||
`npm run verify:interface-builder` compiles the source-owned AppKit XIB into a
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
# REA Code Mode experiment
|
||||
|
||||
Frozen baseline: `fb94d9dde0ccda83ae520ac6fb22b1d283562cf3`, fetched from
|
||||
`origin/main` on 2026-10-11. Branch: `experiment/codemode-bridge-20261011`.
|
||||
This is a local experiment, not a change to the published CLI or MCP API.
|
||||
|
||||
The analyst question is whether composing REA's existing named tools in code
|
||||
improves investigation efficiency enough to justify an optional bridge. Existing
|
||||
users must keep their current names, input schemas, Evidence and session behavior.
|
||||
Provider analysis settings must stay identical between comparison profiles.
|
||||
|
||||
The bridge owns one upstream stdio MCP connection and discovers its complete live
|
||||
catalog. Only discovery and JavaScript execution are exposed downstream. Code
|
||||
calls `tools.<original_name>(original_arguments)` and receives the original MCP
|
||||
result envelope. REA still validates input, chooses providers, retains Evidence,
|
||||
and owns analysis resources. There is no second tool implementation or schema
|
||||
catalog to keep synchronized. A fresh QuickJS WASM context exposes only those
|
||||
tool calls, JSON helpers and explicit output; it has no host filesystem, network,
|
||||
process or module loader.
|
||||
|
||||
Start the bridge without changing an existing registration:
|
||||
|
||||
```bash
|
||||
node bridge.mjs /absolute/path/to/node /absolute/path/to/rea/scripts/rea.mjs mcp
|
||||
```
|
||||
|
||||
Register that command as a separate, temporary MCP server for a trial. Existing
|
||||
REA registrations keep their original tools. `rea_search` accepts a query or exact
|
||||
names; use `schemas: false` for the complete lightweight name/description list.
|
||||
Query discovery returns names/descriptions by default; exact-name discovery
|
||||
returns original input schemas and derived input/output TypeScript declarations.
|
||||
These declarations help write code; they do not replace JSON validation contracts.
|
||||
`schemas` explicitly overrides that choice.
|
||||
Start with one domain word and request all selected exact names in one call.
|
||||
Request `output_schemas: true` when a
|
||||
result contract is needed; the original output schema is then returned unchanged.
|
||||
`catalog_sha256` identifies the SDK catalog; it must not be substituted for REA's
|
||||
`server_identity.catalog.digests` fields.
|
||||
`rea_execute` accepts a JavaScript async function body. For example:
|
||||
|
||||
```js
|
||||
const session = json(await tools.binary_session({})).result;
|
||||
return { open: session.open, identity: session.server_identity };
|
||||
```
|
||||
|
||||
The returned projection is not a new Evidence record. `calls` preserves operation,
|
||||
argument/result digests, upstream errors and actual producer Evidence IDs when
|
||||
provided, including original `evidence_links`. The upstream ledger retains complete original Evidence for later views
|
||||
and exports. Non-Evidence session responses have no invented Evidence ID.
|
||||
Calls and executions sharing one active target are serialized; `Promise.all`
|
||||
currently provides composition rather than parallel provider execution.
|
||||
|
||||
`npm test` runs actual upstream and downstream stdio MCP against this checkout's
|
||||
compiled runtime. The standalone experiment's twelve tests cover discovery parity,
|
||||
original results/errors, bulk promise settlement, host capability absence, CPU
|
||||
deadline recovery, retained Evidence after an error or provider timeout,
|
||||
queued-call cancellation, unresolved promises and the
|
||||
two-tool downstream boundary, guest heap exhaustion/reuse, and SDK-converted
|
||||
schemas validated as [JSON Schema 2020-12](https://modelcontextprotocol.io/specification/2025-11-25/basic/index#schema-dialect).
|
||||
Execution rejects delays above Node's signed 32-bit timer range instead of
|
||||
allowing Node to coerce them to 1 ms. These tests do not establish real native/Android/
|
||||
firmware provider behavior. A lifecycle regression revealed that the QuickJS job
|
||||
pump can allocate an additional context: the execution scope now owns every
|
||||
context at creation and releases them before the runtime. Increasing memory did
|
||||
not fix that regression.
|
||||
|
||||
Install experimental dependencies separately with `npm ci` in this directory.
|
||||
They do not change the production package or lockfile. Use the repository's pinned
|
||||
Node and npm versions. No binary, provider database or raw third-party source is
|
||||
committed. Corpus identities and upstream download locations are in `corpus.json`.
|
||||
|
||||
Measure three baselines: normal full-catalog MCP, discovery-only MCP, and Code
|
||||
Mode. Count discovery, input code, intermediate results, final output, errors and
|
||||
retries. Report actual wall time separately from model-facing turns and local
|
||||
token estimates. Existing summary/page/workflow tools are fair alternatives;
|
||||
do not manufacture a gain by forcing full output on the direct-tool baseline.
|
||||
Replay measurements establish mechanism costs, not model task accuracy or
|
||||
inference latency. Real-agent trials must additionally verify supported facts,
|
||||
source identity, omissions and preserved Evidence references.
|
||||
|
||||
`benchmark.mjs` replays a fixed question against real providers with identical
|
||||
original arguments. For example:
|
||||
|
||||
```bash
|
||||
python3 resource-run.py -- node benchmark.mjs --artifact newpipe.apk \
|
||||
--mode bridge --artifact-root /absolute/path/artifacts \
|
||||
--providers /absolute/path/selected-provider-settings.json \
|
||||
--output /absolute/path/new-result-directory
|
||||
```
|
||||
|
||||
Modes are `direct`, `discovery` and `bridge`. The discovery mode isolates catalog
|
||||
cost while retaining original results; it is not a new production MCP client.
|
||||
Raw responses remain outside Git. Result summaries separate complete envelopes
|
||||
from single text content and count code explicitly. Measured findings and failures
|
||||
are recorded in [results.md](results.md).
|
||||
|
||||
`--artifact obsidian.asar --workflow obsidian-inventory` asks a distinct package
|
||||
inventory question using existing tools. It must not be compared as an equivalent
|
||||
completion of the JavaScript AST question. Workflow names and original arguments
|
||||
are retained in replay summaries.
|
||||
|
||||
`agent-trial.py` runs a real local Codex CLI with a disposable account/config and
|
||||
one MCP registration. It copies authentication only, removes the profile on normal
|
||||
completion, timeout and handled termination, and retains JSONL events, the answer
|
||||
and measured API usage outside the repo.
|
||||
It defaults to `gpt-5.6-terra` with high reasoning, as requested. Run one task under
|
||||
the resource wrapper:
|
||||
|
||||
```bash
|
||||
python3 resource-run.py -- python3 agent-trial.py \
|
||||
--mode direct --prompt /absolute/path/question.txt \
|
||||
--output /absolute/path/new-trial-directory
|
||||
```
|
||||
|
||||
Reproducible questions are in [questions/](questions/). Supply a template with
|
||||
`--prompt questions/android.txt --artifact-path /absolute/path/NewPipe_v0.29.1.apk`
|
||||
(or another matching corpus target). The runner preserves the supplied path in
|
||||
the rendered prompt and records template and rendered-prompt digests. Native's
|
||||
entry-address seed is derived from this corpus's jq header and is not reusable
|
||||
for another build. Run comparisons serially with the same question and provider
|
||||
settings; retain failures as well as successful repetitions.
|
||||
|
||||
Use `--mode bridge` for the experimental server; `--mode client-code` requests
|
||||
Codex's own Code Mode. Optional `--providers` selects a JSON object of explicit
|
||||
provider settings. No ambient environment snapshot is retained. A configured flag
|
||||
or a model's `tool_mode` does not prove the model actually composed tools or
|
||||
filtered an intermediate result. Inspect the transcript, and mark accuracy as
|
||||
unassessed until the requested facts and source support have been reviewed.
|
||||
`grade-trial.py` checks Android (default), managed, native, firmware or
|
||||
electron-inventory (`--task NAME`) against a successful
|
||||
real-provider replay and verifies cited IDs in producer values, their original
|
||||
Evidence links or the bridge audit. This verifies references observed in the
|
||||
transcript; the grader does not resolve every cited payload. It accepts
|
||||
JSON or one complete JSON fence, without repairing prose or partial values. This
|
||||
checks requested producer facts and reference existence, not runtime behavior or
|
||||
independent decompiler correctness. Unparseable result text is reported explicitly;
|
||||
IDs in a truncated JSON fragment cannot satisfy the automated reference check.
|
||||
The Android projection includes the provider's overload index, so a supported
|
||||
signature with that field omitted fails this stronger assertion.
|
||||
An omitted DEX descriptor differs from an explicit null, and booleans differ from
|
||||
numeric counts. Native containing-procedure reports compare resolved identity;
|
||||
the full analyzed procedure is verified separately.
|
||||
Firmware's run-local region UUIDs remain in answers but are excluded from parity
|
||||
against an independently acquired report. Classification evidence, explicit
|
||||
unknowns and coverage remain part of the requested fact checks.
|
||||
The question comparison accepts grouped original path records, extra known
|
||||
coverage counts and explicitly named firmware length/coverage report fields.
|
||||
Derived extent ends must agree with offset plus reported length. It verifies
|
||||
engine version and executable digest rather than display capitalization; a manual
|
||||
review is still needed for limitations and claims beyond these assertions.
|
||||
Grades record the grader source digest, and earlier strict grades are retained
|
||||
when the comparison changes. These are report parsers, not REA API aliases.
|
||||
|
||||
The completed serial cohort is in [agent-results.json](agent-results.json), with
|
||||
source/configuration fingerprints, measured API usage and sampled cgroup stats.
|
||||
The recommendation and migration boundaries are in [decision.md](decision.md).
|
||||
Raw transcripts and original replay replies remain outside Git.
|
||||
|
||||
The supplied feedback is a research lead. Its Ghidra timing claim also changed
|
||||
auto-analysis options, so it does not isolate Code Mode's effect. Relevant primary
|
||||
sources: [Cloudflare Code Mode](https://blog.cloudflare.com/code-mode/),
|
||||
[MCP patterns](https://developers.cloudflare.com/agents/model-context-protocol/codemode/),
|
||||
[Anthropic code execution](https://www.anthropic.com/engineering/code-execution-with-mcp),
|
||||
and [QuickJS WASM](https://github.com/justjake/quickjs-emscripten).
|
||||
|
||||
Run expensive commands with `python3 resource-run.py -- COMMAND ARGS...` on Linux
|
||||
with a user systemd manager. It uses a transient scope with one CPU, a 4 GiB hard
|
||||
memory ceiling, a 3 GiB early-stop threshold, no swap, and a task ceiling. It
|
||||
refuses to start when less than 8 GiB is available and stops if host available
|
||||
memory drops below 4 GiB. These limits protect the host; a resource abort is a
|
||||
failed measurement, never a successful benchmark. Also cap Node and Java heaps.
|
||||
The task ceiling is 192. The wrapper records observed memory/task events and
|
||||
stops a trial that touches the task limit. A limit event invalidates a measurement
|
||||
even when the application later returns successfully.
|
||||
@@ -0,0 +1,995 @@
|
||||
{
|
||||
"baseline_sha": "fb94d9dde0ccda83ae520ac6fb22b1d283562cf3",
|
||||
"scope": "real_cli_requested_fact_parity_and_observed_references_not_independent_runtime_truth",
|
||||
"runtime_source_commit": "22326e8199975f31d8b7c99aaf5fd64140fbe00e",
|
||||
"artifact_ids": "corpus.json",
|
||||
"resource_limits": {
|
||||
"cpu_affinity": [15],
|
||||
"cpu_quota_percent": 100,
|
||||
"hard_memory_bytes": 4294967296,
|
||||
"early_stop_bytes": 3221225472,
|
||||
"tasks_max": 192
|
||||
},
|
||||
"notes": [
|
||||
"Profiles differ in required mode-specific instructions; original model-selected arguments may differ.",
|
||||
"Two Android/managed repetitions are descriptive samples, without confidence intervals or a causal speed claim.",
|
||||
"Managed classification container omissions fail a stronger complete-object assertion; remaining requested facts match.",
|
||||
"Normal-MCP managed JSONL truncation leaves one ID unavailable to the complete-envelope reference parser.",
|
||||
"Uncached input is input minus cached input, not a currency cost estimate."
|
||||
],
|
||||
"trials": [
|
||||
{
|
||||
"trial": "android-direct-5",
|
||||
"task": "android",
|
||||
"mode": "direct",
|
||||
"artifact": "newpipe.apk",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 67.329,
|
||||
"input_tokens": 107007,
|
||||
"cached_input_tokens": 83712,
|
||||
"uncached_input_tokens": 23295,
|
||||
"output_tokens": 1670,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class"
|
||||
],
|
||||
"fact_assertions": 6,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "7129418f2d4428d86cc737124b53636ba4a46de522e702e8861180fc175acb23",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "3424dd6ba375f96d88fd0ac38102998948fa0fc46e08af8fae414572ba97a62f",
|
||||
"peak_memory_bytes_sampled": 1336168448,
|
||||
"peak_tasks_sampled": 108,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 23974584,
|
||||
"user_usec": 21485565,
|
||||
"system_usec": 2489019,
|
||||
"nr_periods": 636,
|
||||
"nr_throttled": 45,
|
||||
"throttled_usec": 67840,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "android-bridge-7",
|
||||
"task": "android",
|
||||
"mode": "bridge",
|
||||
"artifact": "newpipe.apk",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 48.231,
|
||||
"input_tokens": 113256,
|
||||
"cached_input_tokens": 91648,
|
||||
"uncached_input_tokens": 21608,
|
||||
"output_tokens": 1456,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class"
|
||||
],
|
||||
"fact_assertions": 6,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "7129418f2d4428d86cc737124b53636ba4a46de522e702e8861180fc175acb23",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "27e234285e493b50929c0f98938284771d0d4a3787045872f2f517b2297aefeb",
|
||||
"peak_memory_bytes_sampled": 1659629568,
|
||||
"peak_tasks_sampled": 126,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 27717810,
|
||||
"user_usec": 25042151,
|
||||
"system_usec": 2675658,
|
||||
"nr_periods": 458,
|
||||
"nr_throttled": 50,
|
||||
"throttled_usec": 73614,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "managed-bridge-2",
|
||||
"task": "managed",
|
||||
"mode": "bridge",
|
||||
"artifact": "sharex.dll",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 73.145,
|
||||
"input_tokens": 116974,
|
||||
"cached_input_tokens": 92672,
|
||||
"uncached_input_tokens": 24302,
|
||||
"output_tokens": 2065,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_native_boundaries"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": ["classification"],
|
||||
"strict_grade_passed": false,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "fe5a74687126fca7aee78b3ba51f03401983ffeae593924b7c738d50d0f04e61",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "06cbdda60ac930d00ade7e115cd4ba234527e297e6cfd931eedc175e00efa1c7",
|
||||
"peak_memory_bytes_sampled": 939290624,
|
||||
"peak_tasks_sampled": 103,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 12114716,
|
||||
"user_usec": 9701516,
|
||||
"system_usec": 2413200,
|
||||
"nr_periods": 630,
|
||||
"nr_throttled": 16,
|
||||
"throttled_usec": 15944,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "managed-direct-2",
|
||||
"task": "managed",
|
||||
"mode": "direct",
|
||||
"artifact": "sharex.dll",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 33.15,
|
||||
"input_tokens": 108096,
|
||||
"cached_input_tokens": 75776,
|
||||
"uncached_input_tokens": 32320,
|
||||
"output_tokens": 2315,
|
||||
"completed_mcp_calls": 2,
|
||||
"original_operations": [
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_native_boundaries"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": false,
|
||||
"cited_ids_observed": false,
|
||||
"unreadable_result_texts": 1,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "fe5a74687126fca7aee78b3ba51f03401983ffeae593924b7c738d50d0f04e61",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "5d6957541bd979252d019817e631f5d889ff2dc3efb7f03b9de1033fe34d8430",
|
||||
"peak_memory_bytes_sampled": 688373760,
|
||||
"peak_tasks_sampled": 108,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 5863642,
|
||||
"user_usec": 4359666,
|
||||
"system_usec": 1503976,
|
||||
"nr_periods": 282,
|
||||
"nr_throttled": 4,
|
||||
"throttled_usec": 6216,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "electron-inventory-direct-1",
|
||||
"task": "electron-inventory",
|
||||
"mode": "direct",
|
||||
"artifact": "obsidian.asar",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 89.494,
|
||||
"input_tokens": 266121,
|
||||
"cached_input_tokens": 238848,
|
||||
"uncached_input_tokens": 27273,
|
||||
"output_tokens": 3215,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"inspect_artifact",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "22941dc5d77ce06824e40b01abd3f725aa773d131648d7bba2e607b410ccbef9",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "fcd0df1a3ae0b5103143addaa4922323354ddee7ba3d0e3020de64f05b6fe3d3",
|
||||
"peak_memory_bytes_sampled": 703275008,
|
||||
"peak_tasks_sampled": 115,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 7720494,
|
||||
"user_usec": 5691854,
|
||||
"system_usec": 2028640,
|
||||
"nr_periods": 782,
|
||||
"nr_throttled": 7,
|
||||
"throttled_usec": 15453,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "electron-inventory-bridge-1",
|
||||
"task": "electron-inventory",
|
||||
"mode": "bridge",
|
||||
"artifact": "obsidian.asar",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 145.577,
|
||||
"input_tokens": 462809,
|
||||
"cached_input_tokens": 407040,
|
||||
"uncached_input_tokens": 55769,
|
||||
"output_tokens": 5624,
|
||||
"completed_mcp_calls": 8,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"inspect_artifact",
|
||||
"close_binary",
|
||||
"open_binary",
|
||||
"inspect_artifact",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "22941dc5d77ce06824e40b01abd3f725aa773d131648d7bba2e607b410ccbef9",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "ab7e25e4345a0e9bba6a06bb0a79aa39e1bf1308b6a66f8173a62bbc9e2d9fc9",
|
||||
"peak_memory_bytes_sampled": 1029238784,
|
||||
"peak_tasks_sampled": 112,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 14650718,
|
||||
"user_usec": 12106416,
|
||||
"system_usec": 2544302,
|
||||
"nr_periods": 1224,
|
||||
"nr_throttled": 24,
|
||||
"throttled_usec": 30318,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "firmware-bridge-1",
|
||||
"task": "firmware",
|
||||
"mode": "bridge",
|
||||
"artifact": "openwrt.bin",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 81.944,
|
||||
"input_tokens": 152886,
|
||||
"cached_input_tokens": 126976,
|
||||
"uncached_input_tokens": 25910,
|
||||
"output_tokens": 2192,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": ["inspect_firmware_regions"],
|
||||
"fact_assertions": 5,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "93c94e26dc4a4b1985b3f8c4246ca5aff886f75dc2349a717ee940243dc73b80",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "a5604d0d3140f6232851a81a952e51daf43c8e7f12ba062fac68a8fae0bef708",
|
||||
"peak_memory_bytes_sampled": 927666176,
|
||||
"peak_tasks_sampled": 104,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 11575373,
|
||||
"user_usec": 9366624,
|
||||
"system_usec": 2208749,
|
||||
"nr_periods": 744,
|
||||
"nr_throttled": 18,
|
||||
"throttled_usec": 26000,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "firmware-direct-1",
|
||||
"task": "firmware",
|
||||
"mode": "direct",
|
||||
"artifact": "openwrt.bin",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 30.161,
|
||||
"input_tokens": 103224,
|
||||
"cached_input_tokens": 74752,
|
||||
"uncached_input_tokens": 28472,
|
||||
"output_tokens": 1761,
|
||||
"completed_mcp_calls": 1,
|
||||
"original_operations": ["inspect_firmware_regions"],
|
||||
"fact_assertions": 5,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "93c94e26dc4a4b1985b3f8c4246ca5aff886f75dc2349a717ee940243dc73b80",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "c0bbd1aec08c9c30061f92064355c3213f680fab545a050271096e85db771a71",
|
||||
"peak_memory_bytes_sampled": 686739456,
|
||||
"peak_tasks_sampled": 109,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 5700866,
|
||||
"user_usec": 4167696,
|
||||
"system_usec": 1533169,
|
||||
"nr_periods": 266,
|
||||
"nr_throttled": 6,
|
||||
"throttled_usec": 3978,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "native-direct-1",
|
||||
"task": "native",
|
||||
"mode": "direct",
|
||||
"artifact": "jq",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 327.15,
|
||||
"input_tokens": 151343,
|
||||
"cached_input_tokens": 122368,
|
||||
"uncached_input_tokens": 28975,
|
||||
"output_tokens": 2458,
|
||||
"completed_mcp_calls": 4,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"resolve_containing_procedure",
|
||||
"analyze_function",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "234bfe93d09f9c76c1a64383c11cf7c174eafa4e4ad563124f705a7d5c8920aa",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "681f38e4ba9b441e7816e868b30e347005fe074907349cd0022fc44302c5b14a",
|
||||
"peak_memory_bytes_sampled": 1328496640,
|
||||
"peak_tasks_sampled": 109,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 263737951,
|
||||
"user_usec": 256864795,
|
||||
"system_usec": 6873156,
|
||||
"nr_periods": 3192,
|
||||
"nr_throttled": 456,
|
||||
"throttled_usec": 756678,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "native-bridge-1",
|
||||
"task": "native",
|
||||
"mode": "bridge",
|
||||
"artifact": "jq",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 334.642,
|
||||
"input_tokens": 285961,
|
||||
"cached_input_tokens": 245504,
|
||||
"uncached_input_tokens": 40457,
|
||||
"output_tokens": 2129,
|
||||
"completed_mcp_calls": 4,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"analyze_function",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "234bfe93d09f9c76c1a64383c11cf7c174eafa4e4ad563124f705a7d5c8920aa",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "6c64953708df4a06b69fb57e5d70141147e4495adabd7340e87e727fcd340742",
|
||||
"peak_memory_bytes_sampled": 1441775616,
|
||||
"peak_tasks_sampled": 123,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 271095966,
|
||||
"user_usec": 263888347,
|
||||
"system_usec": 7207618,
|
||||
"nr_periods": 3267,
|
||||
"nr_throttled": 450,
|
||||
"throttled_usec": 784719,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "android-bridge-8",
|
||||
"task": "android",
|
||||
"mode": "bridge",
|
||||
"artifact": "newpipe.apk",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 134.555,
|
||||
"input_tokens": 159370,
|
||||
"cached_input_tokens": 134400,
|
||||
"uncached_input_tokens": 24970,
|
||||
"output_tokens": 3250,
|
||||
"completed_mcp_calls": 7,
|
||||
"original_operations": [
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class",
|
||||
"inspect_android_package",
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class"
|
||||
],
|
||||
"fact_assertions": 6,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "7129418f2d4428d86cc737124b53636ba4a46de522e702e8861180fc175acb23",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "f1743a341d334bd41760b54980aa70d5f3c8c1aed57c3ae9e470be63449c594d",
|
||||
"peak_memory_bytes_sampled": 1659744256,
|
||||
"peak_tasks_sampled": 115,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 29619173,
|
||||
"user_usec": 26495167,
|
||||
"system_usec": 3124005,
|
||||
"nr_periods": 1229,
|
||||
"nr_throttled": 60,
|
||||
"throttled_usec": 84762,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "android-direct-6",
|
||||
"task": "android",
|
||||
"mode": "direct",
|
||||
"artifact": "newpipe.apk",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 71.624,
|
||||
"input_tokens": 153031,
|
||||
"cached_input_tokens": 117504,
|
||||
"uncached_input_tokens": 35527,
|
||||
"output_tokens": 1501,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class"
|
||||
],
|
||||
"fact_assertions": 6,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "7129418f2d4428d86cc737124b53636ba4a46de522e702e8861180fc175acb23",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "b8d0422eec6bfd31a9a6ed79ac29e9487c2e68c47ff200904ec239daee9720c3",
|
||||
"peak_memory_bytes_sampled": 1348767744,
|
||||
"peak_tasks_sampled": 115,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 23033331,
|
||||
"user_usec": 20566262,
|
||||
"system_usec": 2467069,
|
||||
"nr_periods": 674,
|
||||
"nr_throttled": 40,
|
||||
"throttled_usec": 61573,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "managed-direct-3",
|
||||
"task": "managed",
|
||||
"mode": "direct",
|
||||
"artifact": "sharex.dll",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 75.229,
|
||||
"input_tokens": 108593,
|
||||
"cached_input_tokens": 75776,
|
||||
"uncached_input_tokens": 32817,
|
||||
"output_tokens": 2774,
|
||||
"completed_mcp_calls": 2,
|
||||
"original_operations": [
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_native_boundaries"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": false,
|
||||
"cited_ids_observed": false,
|
||||
"unreadable_result_texts": 1,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "fe5a74687126fca7aee78b3ba51f03401983ffeae593924b7c738d50d0f04e61",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "64f0769b7ad83f8d86c005a48de7a0cf397043d77378983fabfaa226dcb70f87",
|
||||
"peak_memory_bytes_sampled": 651026432,
|
||||
"peak_tasks_sampled": 110,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 6252846,
|
||||
"user_usec": 4688766,
|
||||
"system_usec": 1564079,
|
||||
"nr_periods": 635,
|
||||
"nr_throttled": 7,
|
||||
"throttled_usec": 11469,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "managed-bridge-3",
|
||||
"task": "managed",
|
||||
"mode": "bridge",
|
||||
"artifact": "sharex.dll",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 40.609,
|
||||
"input_tokens": 125519,
|
||||
"cached_input_tokens": 96000,
|
||||
"uncached_input_tokens": 29519,
|
||||
"output_tokens": 2274,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_native_boundaries"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": ["classification"],
|
||||
"strict_grade_passed": false,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "fe5a74687126fca7aee78b3ba51f03401983ffeae593924b7c738d50d0f04e61",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "5fbc3cf0b41224f2ef44ab996b174c8a48fe07a818ac2ad334ef59e5ddf26de6",
|
||||
"peak_memory_bytes_sampled": 1005625344,
|
||||
"peak_tasks_sampled": 113,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 11185145,
|
||||
"user_usec": 9300437,
|
||||
"system_usec": 1884707,
|
||||
"nr_periods": 366,
|
||||
"nr_throttled": 21,
|
||||
"throttled_usec": 24147,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "electron-inventory-guided-bridge-1",
|
||||
"task": "electron-inventory",
|
||||
"mode": "bridge",
|
||||
"artifact": "obsidian.asar",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 85.909,
|
||||
"input_tokens": 101994,
|
||||
"cached_input_tokens": 61440,
|
||||
"uncached_input_tokens": 40554,
|
||||
"output_tokens": 2563,
|
||||
"completed_mcp_calls": 3,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"inspect_artifact",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "f070cdf721805d590c1bd5255ecf1f647ea165885cd5052af35c30ba531da815",
|
||||
"developer_instructions_sha256": "247ca3314340f748d1479cc1a0a1f33a234231f17b5768044034bdfe517299c6",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "566391b8a6db73228fec00dc7cbf0eaf56ed899178a405d5d8f0c8002fb05d89",
|
||||
"peak_memory_bytes_sampled": 1007996928,
|
||||
"peak_tasks_sampled": 109,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 13304542,
|
||||
"user_usec": 10842042,
|
||||
"system_usec": 2462499,
|
||||
"nr_periods": 787,
|
||||
"nr_throttled": 19,
|
||||
"throttled_usec": 27407,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"trial": "electron-inventory-guided-direct-1",
|
||||
"task": "electron-inventory",
|
||||
"mode": "direct",
|
||||
"artifact": "obsidian.asar",
|
||||
"requested_model": "gpt-5.6-terra",
|
||||
"reasoning": "high",
|
||||
"codex_version": "codex-cli 0.161.0",
|
||||
"wall_seconds": 67.54,
|
||||
"input_tokens": 263484,
|
||||
"cached_input_tokens": 221952,
|
||||
"uncached_input_tokens": 41532,
|
||||
"output_tokens": 2499,
|
||||
"completed_mcp_calls": 4,
|
||||
"original_operations": [
|
||||
"open_binary",
|
||||
"inspect_artifact",
|
||||
"inspect_artifact",
|
||||
"close_binary"
|
||||
],
|
||||
"fact_assertions": 7,
|
||||
"fact_mismatches": [],
|
||||
"strict_grade_passed": true,
|
||||
"cited_ids_observed": true,
|
||||
"unreadable_result_texts": 0,
|
||||
"grader_sha256": "707e4eef05634db5075ac64382500b9eea03b38f828358315e54381f9d4a8979",
|
||||
"prompt_sha256": "f070cdf721805d590c1bd5255ecf1f647ea165885cd5052af35c30ba531da815",
|
||||
"developer_instructions_sha256": "eaddc85aa5b141538ec280d640c62db799231b394679a17f2e6cc6bc2146a95c",
|
||||
"provider_settings_sha256": "1db4e19adcb32bb64a3baad58a1b4ef04b52ba648bab29678693f9ab8dbdabb4",
|
||||
"experiment_sources_sha256": {
|
||||
"agent-trial.py": "3c96d0f7b4b3dd02d168258d8aedd79049bb8647f1ebb174b056bd8eaa582502",
|
||||
"bridge.mjs": "c1afb88a3045f233006826ffd466590b33027cc7b95f9c6c551ba1aa93fa4727",
|
||||
"package-lock.json": "6dab2b2dba5101992e9a881ce1820475bd304511dc44362bb1614b08e9b37a87"
|
||||
},
|
||||
"events_sha256": "564711cf28211bb7059a04b919f1b6925a816ded3e2dbeb9678382568f700e58",
|
||||
"peak_memory_bytes_sampled": 728817664,
|
||||
"peak_tasks_sampled": 114,
|
||||
"cpu_stat_last_observed": {
|
||||
"usage_usec": 8708686,
|
||||
"user_usec": 6609914,
|
||||
"system_usec": 2098771,
|
||||
"nr_periods": 597,
|
||||
"nr_throttled": 12,
|
||||
"throttled_usec": 19564,
|
||||
"nr_bursts": 0,
|
||||
"burst_usec": 0
|
||||
},
|
||||
"resource_abort": null,
|
||||
"resource_events_last_observed": {
|
||||
"memory.events": {
|
||||
"low": 0,
|
||||
"high": 0,
|
||||
"max": 0,
|
||||
"oom": 0,
|
||||
"oom_kill": 0,
|
||||
"oom_group_kill": 0
|
||||
},
|
||||
"pids.events": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
"""Evaluate one real Codex CLI task with an isolated REA MCP registration."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--mode', choices=['direct', 'client-code', 'bridge'], required=True)
|
||||
parser.add_argument('--prompt', type=Path, required=True)
|
||||
parser.add_argument('--artifact-path', help='Replace {{artifact_path}} in a question template')
|
||||
parser.add_argument('--output', type=Path, required=True)
|
||||
parser.add_argument('--model', default='gpt-5.6-terra')
|
||||
parser.add_argument('--reasoning', default='high')
|
||||
parser.add_argument('--timeout', type=int, default=900)
|
||||
parser.add_argument('--codex', default='/usr/bin/codex')
|
||||
parser.add_argument('--providers', type=Path)
|
||||
args = parser.parse_args()
|
||||
def terminate(signum, _frame):
|
||||
# The outer resource scope terminates descendants together. Ensure the
|
||||
# runner's copied credentials are also removed on a resource abort.
|
||||
raise SystemExit(128 + signum)
|
||||
signal.signal(signal.SIGTERM, terminate)
|
||||
repository = Path(__file__).resolve().parents[2]
|
||||
experiment = Path(__file__).resolve().parent
|
||||
node = shutil.which('node')
|
||||
if subprocess.check_output([node, '--version'], text=True).strip() != 'v24.18.0':
|
||||
raise SystemExit('Use pinned Node 24.18.0 on PATH')
|
||||
args.output.mkdir(parents=True, exist_ok=False, mode=0o700)
|
||||
profile = Path(tempfile.mkdtemp(prefix='profile-', dir=args.output))
|
||||
trial_codex_home = profile / 'codex'
|
||||
account = profile / 'account'
|
||||
workspace = profile / 'workspace'
|
||||
for directory in [trial_codex_home, account, workspace]:
|
||||
directory.mkdir(mode=0o700)
|
||||
source_auth = Path(os.environ.get('CODEX_HOME', str(Path.home() / '.codex'))) / 'auth.json'
|
||||
auth = trial_codex_home / 'auth.json'
|
||||
started = time.monotonic()
|
||||
timeout = False
|
||||
exit_code = None
|
||||
environment = dict(os.environ)
|
||||
environment.update({
|
||||
'CODEX_HOME': str(trial_codex_home), 'HOME': str(account),
|
||||
'XDG_CONFIG_HOME': str(account / '.config'),
|
||||
'XDG_CACHE_HOME': str(account / '.cache'),
|
||||
'XDG_DATA_HOME': str(account / '.local/share'),
|
||||
'NODE_OPTIONS': '--max-old-space-size=512',
|
||||
})
|
||||
provider_env = {'REA_LOG_LEVEL': 'silent', 'NODE_OPTIONS': '--max-old-space-size=512'}
|
||||
if args.providers:
|
||||
# This explicit caller file supplies only selected provider settings.
|
||||
provider_env.update(json.loads(args.providers.read_text()))
|
||||
command_args = [str(repository / 'scripts/rea.mjs'), 'mcp']
|
||||
if args.mode == 'bridge':
|
||||
command_args = [str(experiment / 'bridge.mjs'), node, *command_args]
|
||||
instruction = (
|
||||
'Use the registered REA MCP server for this investigation. Static analysis '
|
||||
'only: do not execute target code, fetch URLs, launch a GUI, or modify targets. '
|
||||
'Preserve observations, derivations, inferences, limitations, and real Evidence IDs. '
|
||||
'An Evidence value has evidence_id, normalized_result and limitations; '
|
||||
'non-Evidence session values have result. '
|
||||
'The analyzed target digest is Evidence.subject.digest.sha256. '
|
||||
'normalized_result.engine.artifact_sha256 identifies the analysis engine '
|
||||
'artifact and must never be substituted for the target digest. '
|
||||
'Prefer summary/focused views where appropriate. Do not invent successful facts '
|
||||
'after a tool error. No other agents. Stop once the requested facts are supported.'
|
||||
)
|
||||
if args.mode == 'bridge':
|
||||
instruction += (
|
||||
' Original REA operations are available through rea_search and rea_execute. '
|
||||
'Discover tool names/schemas on demand. Execute JavaScript bodies using '
|
||||
'tools.<original_name>(original_arguments), json(reply) to parse the original '
|
||||
'MCP result, and return only the needed facts plus their Evidence IDs and '
|
||||
'limitations. Compose known dependent calls in one script when useful. '
|
||||
'Select needed fields from normalized_result inside the script; do not '
|
||||
'return entire Evidence, raw_result or full method/class inventories when '
|
||||
'the question requests a subset. '
|
||||
'Await every call; the upstream session persists across scripts.'
|
||||
)
|
||||
if args.mode == 'client-code':
|
||||
instruction += (
|
||||
' Use the client JavaScript executor to compose registered MCP calls when '
|
||||
'possible and select the requested normalized_result fields before returning '
|
||||
'intermediate output to model context. Keep real Evidence IDs and limitations.'
|
||||
)
|
||||
quote = json.dumps
|
||||
config = '\n'.join([
|
||||
'approval_policy = "never"', 'sandbox_mode = "read-only"',
|
||||
'web_search = "disabled"', 'model = ' + quote(args.model),
|
||||
'model_reasoning_effort = ' + quote(args.reasoning),
|
||||
'developer_instructions = ' + quote(instruction),
|
||||
'[features]', 'multi_agent = false', 'shell_snapshot = false',
|
||||
'shell_tool = false', 'unified_exec = false',
|
||||
'code_mode = ' + ('true' if args.mode == 'client-code' else 'false'),
|
||||
'code_mode_only = ' + ('true' if args.mode == 'client-code' else 'false'),
|
||||
'[history]', 'persistence = "none"',
|
||||
'[mcp_servers.rea]', 'command = ' + quote(node),
|
||||
'args = ' + quote(command_args), 'startup_timeout_sec = 60',
|
||||
'tool_timeout_sec = 600', '[mcp_servers.rea.env]',
|
||||
*[key + ' = ' + quote(value) for key, value in provider_env.items()],
|
||||
'[mcp_servers.rea.tools.rea_execute]', 'approval_mode = "approve"',
|
||||
]) + '\n'
|
||||
# MCP read-only hints cover normal static tools. Explicitly authorize only
|
||||
# the session-opening primitive needed by the requested native tasks.
|
||||
config += '[mcp_servers.rea.tools.open_binary]\napproval_mode = "approve"\n'
|
||||
for tool in ['analyze_javascript_application', 'inspect_analysis_view',
|
||||
'inspect_android_package', 'search_android_classes',
|
||||
'inspect_android_class', 'inspect_android_method',
|
||||
'inspect_firmware_regions', 'inspect_managed_artifact',
|
||||
'inspect_managed_members', 'inspect_managed_native_boundaries',
|
||||
'inspect_artifact', 'inspect_wasm_artifact',
|
||||
'resolve_containing_procedure', 'analyze_function', 'close_binary']:
|
||||
config += '[mcp_servers.rea.tools.' + tool + ']\napproval_mode = "approve"\n'
|
||||
try:
|
||||
if source_auth.exists():
|
||||
shutil.copyfile(source_auth, auth)
|
||||
auth.chmod(0o600)
|
||||
(trial_codex_home / 'config.toml').write_text(config)
|
||||
(trial_codex_home / 'config.toml').chmod(0o600)
|
||||
prompt = args.prompt.read_text()
|
||||
template_digest = hashlib.sha256(prompt.encode()).hexdigest()
|
||||
if '{{artifact_path}}' in prompt:
|
||||
if not args.artifact_path or not os.path.isabs(args.artifact_path):
|
||||
raise ValueError('A question template requires an absolute --artifact-path')
|
||||
prompt = prompt.replace('{{artifact_path}}', args.artifact_path)
|
||||
elif args.artifact_path:
|
||||
raise ValueError('--artifact-path requires the literal template marker')
|
||||
(args.output / 'prompt.txt').write_text(prompt)
|
||||
(args.output / 'trial-settings.json').write_text(json.dumps({
|
||||
'mode': args.mode, 'model': args.model, 'reasoning': args.reasoning,
|
||||
'experiment_commit': subprocess.check_output(
|
||||
['git', 'rev-parse', 'HEAD'], cwd=repository, text=True).strip(),
|
||||
'experiment_sources_sha256': {
|
||||
name: hashlib.sha256((experiment / name).read_bytes()).hexdigest()
|
||||
for name in ['agent-trial.py', 'bridge.mjs', 'package-lock.json']
|
||||
},
|
||||
'developer_instructions': instruction,
|
||||
'developer_instructions_sha256': hashlib.sha256(instruction.encode()).hexdigest(),
|
||||
'prompt_sha256': hashlib.sha256(prompt.encode()).hexdigest(),
|
||||
'question_template_sha256': template_digest,
|
||||
'provider_settings_sha256': hashlib.sha256(
|
||||
json.dumps(provider_env, sort_keys=True).encode()).hexdigest(),
|
||||
'features': {'shell_tool': False, 'unified_exec': False,
|
||||
'multi_agent': False, 'code_mode': args.mode == 'client-code',
|
||||
'code_mode_only': args.mode == 'client-code'},
|
||||
}, indent=2) + '\n')
|
||||
invocation = [args.codex, '--no-daemon', 'exec', '--ephemeral',
|
||||
'--skip-git-repo-check', '--ignore-rules', '--json',
|
||||
'--color', 'never', '-C', str(workspace),
|
||||
'--output-last-message', str(args.output.resolve() / 'answer.txt'), '-']
|
||||
with (args.output / 'events.jsonl').open('w') as events, (args.output / 'stderr.log').open('w') as errors:
|
||||
child = subprocess.Popen(invocation, env=environment, cwd=workspace,
|
||||
stdin=subprocess.PIPE, stdout=events, stderr=errors, text=True)
|
||||
child.stdin.write(prompt)
|
||||
child.stdin.close()
|
||||
try:
|
||||
exit_code = child.wait(timeout=args.timeout)
|
||||
except subprocess.TimeoutExpired:
|
||||
timeout = True
|
||||
child.terminate()
|
||||
try:
|
||||
exit_code = child.wait(timeout=10)
|
||||
except subprocess.TimeoutExpired:
|
||||
child.kill()
|
||||
exit_code = child.wait()
|
||||
usage = []
|
||||
tools = []
|
||||
event_types = {}
|
||||
for line in (args.output / 'events.jsonl').read_text().splitlines():
|
||||
event = json.loads(line)
|
||||
kind = event.get('type', 'unknown')
|
||||
event_types[kind] = event_types.get(kind, 0) + 1
|
||||
if 'usage' in event:
|
||||
usage.append(event['usage'])
|
||||
item = event.get('item', {})
|
||||
if item.get('type') == 'mcp_tool_call' and kind == 'item.completed':
|
||||
tools.append({k: item.get(k) for k in ['server', 'tool', 'arguments', 'status', 'error']})
|
||||
summary = {
|
||||
'mode': args.mode, 'requested_model': args.model, 'reasoning': args.reasoning,
|
||||
'baseline_sha': 'fb94d9dde0ccda83ae520ac6fb22b1d283562cf3',
|
||||
'codex_version': subprocess.check_output([args.codex, '--version'], text=True).strip(),
|
||||
'exit_code': exit_code, 'timeout': timeout,
|
||||
'wall_seconds': round(time.monotonic() - started, 3),
|
||||
'usage': usage, 'completed_mcp_calls': tools, 'event_types': event_types,
|
||||
'factual_correctness': 'not_assessed',
|
||||
'scope': 'real_cli_trial_requires_transcript_and_fact_review',
|
||||
}
|
||||
(args.output / 'summary.json').write_text(json.dumps(summary, indent=2) + '\n')
|
||||
print(json.dumps(summary))
|
||||
finally:
|
||||
# Always remove copied credentials, config, caches and profile state.
|
||||
shutil.rmtree(profile)
|
||||
raise SystemExit(124 if timeout else exit_code)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,369 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { parseArgs } from "node:util";
|
||||
import { getEncoding } from "js-tiktoken";
|
||||
import { CodeModeBridge, connectUpstream, json } from "./bridge.mjs";
|
||||
|
||||
// Replay isolates transport/discovery costs. It does not simulate model reasoning.
|
||||
const workflows = {
|
||||
"sharex.dll": {
|
||||
tools: ["inspect_managed_artifact", "inspect_managed_native_boundaries"],
|
||||
question:
|
||||
"Report assembly/module identity, target framework and declared P/Invoke libraries with their uncertainty.",
|
||||
code: `
|
||||
const artifact = await call("inspect_managed_artifact", {path: input.path});
|
||||
const boundaries = await call("inspect_managed_native_boundaries", {});
|
||||
const n = artifact.normalized_result;
|
||||
return {artifact_sha256: artifact.subject?.digest.sha256,
|
||||
classification: n.classification, assembly: n.assembly, module: n.module,
|
||||
target_frameworks: n.target_frameworks, coverage: n.coverage,
|
||||
native_boundaries: boundaries.normalized_result,
|
||||
evidence_ids: [artifact.evidence_id, boundaries.evidence_id],
|
||||
limitations: [...artifact.limitations, ...boundaries.limitations]};`,
|
||||
},
|
||||
"sqlite.wasm": {
|
||||
tools: ["inspect_wasm_artifact"],
|
||||
question:
|
||||
"Report exact WASM validation, all exported names and runtime/network observation states without executing it.",
|
||||
code: `
|
||||
const wasm = await call("inspect_wasm_artifact", {path: input.path});
|
||||
const n = wasm.normalized_result;
|
||||
return {artifact_sha256: wasm.subject?.digest.sha256,
|
||||
validation: n.validation, sections: n.sections, exports: n.exports,
|
||||
runtime_execution: n.runtime_execution, network_fetch: n.network_fetch,
|
||||
evidence_ids: [wasm.evidence_id], limitations: [...wasm.limitations, ...n.limitations]};`,
|
||||
},
|
||||
"obsidian.asar": {
|
||||
tools: ["analyze_javascript_application", "inspect_analysis_view"],
|
||||
question:
|
||||
"Report application identity, analysis coverage/counts and the first eight module identities.",
|
||||
code: `
|
||||
const summary = await call("analyze_javascript_application", {
|
||||
input_path: input.path, detail: "summary", max_heap_mb: 1024,
|
||||
analysis_timeout_ms: 300000, integrity_policy: "fail"
|
||||
});
|
||||
const parent = summary.normalized_result.parent_evidence_id;
|
||||
const page = await call("inspect_analysis_view", {
|
||||
source: {kind: "retained-evidence", evidence_id: parent},
|
||||
view: {kind: "page", collection: "modules", offset: 0, limit: 8}
|
||||
});
|
||||
return {artifact_sha256: summary.subject?.digest.sha256,
|
||||
summary: summary.normalized_result, modules: page.normalized_result,
|
||||
evidence_ids: [summary.evidence_id, parent, page.evidence_id],
|
||||
limitations: [...summary.limitations, ...page.limitations]};`,
|
||||
},
|
||||
"obsidian-inventory": {
|
||||
artifact: "obsidian.asar",
|
||||
tools: ["open_binary", "inspect_artifact", "close_binary"],
|
||||
question:
|
||||
"Report ASAR identity, complete inventory manifest, entry-kind counts, root package/main/preload occurrences, integrity contradictions and inventory coverage; do not claim AST or runtime analysis.",
|
||||
code: `
|
||||
await call("open_binary", {path: input.path});
|
||||
try {
|
||||
const inspected = await call("inspect_artifact", {integrity_policy: "fail"});
|
||||
const n = inspected.normalized_result;
|
||||
const inventory = n.substeps.find(x => x.operation === "inventory_artifact").evidence;
|
||||
const graph = inventory.normalized_result;
|
||||
const counts = {};
|
||||
for (const row of graph.occurrences)
|
||||
counts[row.entry_kind] = (counts[row.entry_kind] ?? 0) + 1;
|
||||
return {artifact_sha256: inspected.subject.digest.sha256,
|
||||
manifest: graph.manifest, entry_kind_counts: counts,
|
||||
requested_paths: graph.occurrences.filter(x => ["package.json", "main.js", "preload.js"].includes(x.logical_path)),
|
||||
integrity_contradictions: graph.integrity_contradictions,
|
||||
coverage: n.coverage, unexplored_branches: n.unexplored_branches,
|
||||
evidence_ids: [inspected.evidence_id, inventory.evidence_id],
|
||||
limitations: [...inspected.limitations, ...n.limitations, ...inventory.limitations]};
|
||||
} finally { await call("close_binary", {}); }`,
|
||||
},
|
||||
"newpipe.apk": {
|
||||
tools: [
|
||||
"inspect_android_package",
|
||||
"search_android_classes",
|
||||
"inspect_android_class",
|
||||
],
|
||||
question:
|
||||
"Report package/version, exact MainActivity matches and its onCreate method descriptors.",
|
||||
code: `
|
||||
const pkg = await call("inspect_android_package", {path: input.path});
|
||||
const found = await call("search_android_classes", {path: input.path, query: "MainActivity"});
|
||||
if (!found.normalized_result.matches.includes("org.schabi.newpipe.MainActivity"))
|
||||
throw new Error("Requested shipped MainActivity was not found");
|
||||
const cls = await call("inspect_android_class", {
|
||||
path: input.path, class_name: "org.schabi.newpipe.MainActivity"
|
||||
});
|
||||
return {artifact_sha256: pkg.subject?.digest.sha256,
|
||||
package_name: pkg.normalized_result.package_name,
|
||||
version_name: pkg.normalized_result.version_name,
|
||||
version_code: pkg.normalized_result.version_code,
|
||||
matches: found.normalized_result.matches, coverage: found.normalized_result.coverage,
|
||||
onCreate: cls.normalized_result.methods.filter(x => x.name === "onCreate"),
|
||||
evidence_ids: [pkg.evidence_id, found.evidence_id, cls.evidence_id],
|
||||
limitations: [...pkg.limitations, ...found.limitations, ...cls.limitations]};`,
|
||||
},
|
||||
"openwrt.bin": {
|
||||
tools: ["inspect_firmware_regions"],
|
||||
question:
|
||||
"Report firmware identity, every reported region offset/signature and examined coverage.",
|
||||
code: `
|
||||
const inspected = await call("inspect_firmware_regions", {path: input.path});
|
||||
return {artifact_sha256: inspected.subject?.digest.sha256,
|
||||
result: inspected.normalized_result, evidence_ids: [inspected.evidence_id],
|
||||
limitations: inspected.limitations};`,
|
||||
},
|
||||
jq: {
|
||||
tools: [
|
||||
"open_binary",
|
||||
"resolve_containing_procedure",
|
||||
"analyze_function",
|
||||
"close_binary",
|
||||
],
|
||||
question:
|
||||
"Resolve the observed ELF entry address and report the recovered function's first 512 pseudocode units and caller/callee counts.",
|
||||
code: `
|
||||
await call("open_binary", {path: input.path, provider_id: "ghidra"});
|
||||
try {
|
||||
const found = await call("resolve_containing_procedure", {address: input.entry_address});
|
||||
const fn = await call("analyze_function", {procedure: input.entry_address});
|
||||
const n = fn.normalized_result;
|
||||
return {artifact_sha256: fn.subject?.digest.sha256,
|
||||
entry_address: input.entry_address, containing_procedure: found.normalized_result, procedure: n.procedure,
|
||||
pseudocode_prefix: n.pseudocode.slice(0, 512),
|
||||
caller_count: n.callers.length, callee_count: n.callees.length,
|
||||
evidence_ids: [found.evidence_id, fn.evidence_id],
|
||||
limitations: [...found.limitations, ...fn.limitations, ...n.limitations]};
|
||||
} finally { await call("close_binary", {}); }`,
|
||||
},
|
||||
};
|
||||
|
||||
const { values } = parseArgs({
|
||||
options: {
|
||||
artifact: { type: "string" },
|
||||
workflow: { type: "string" },
|
||||
mode: { type: "string", default: "direct" },
|
||||
"artifact-root": { type: "string" },
|
||||
providers: { type: "string" },
|
||||
output: { type: "string" },
|
||||
},
|
||||
});
|
||||
if (
|
||||
!workflows[values.workflow ?? values.artifact] ||
|
||||
!["direct", "discovery", "bridge"].includes(values.mode) ||
|
||||
!values["artifact-root"] ||
|
||||
!values.output
|
||||
)
|
||||
throw new Error(
|
||||
"Use --artifact ID [--workflow NAME] --mode direct|discovery|bridge --artifact-root ABS --output NEW_DIR [--providers JSON]",
|
||||
);
|
||||
const experiment = dirname(fileURLToPath(import.meta.url));
|
||||
const repository = resolve(experiment, "../..");
|
||||
const corpus = JSON.parse(
|
||||
await readFile(resolve(experiment, "corpus.json"), "utf8"),
|
||||
);
|
||||
const artifact = corpus.artifacts.find((x) => x.id === values.artifact);
|
||||
const workflowName = values.workflow ?? values.artifact;
|
||||
const workflow = workflows[workflowName];
|
||||
if (!artifact || artifact.id !== (workflow.artifact ?? workflowName))
|
||||
throw new Error(
|
||||
"Selected workflow does not match the frozen corpus artifact",
|
||||
);
|
||||
const artifactPath = resolve(values["artifact-root"], artifact.file);
|
||||
const bytes = await readFile(artifactPath);
|
||||
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
||||
if (sha256 !== artifact.sha256 || bytes.length !== artifact.bytes)
|
||||
throw new Error("Artifact identity differs from frozen corpus");
|
||||
await mkdir(values.output, { recursive: false, mode: 0o700 });
|
||||
const encoding = getEncoding("cl100k_base");
|
||||
const measure = (value) => {
|
||||
const text = typeof value === "string" ? value : JSON.stringify(value);
|
||||
return {
|
||||
bytes: Buffer.byteLength(text),
|
||||
cl100k_estimated_tokens: encoding.encode(text).length,
|
||||
};
|
||||
};
|
||||
const modelText = (reply) =>
|
||||
reply.content
|
||||
.filter((item) => item.type === "text")
|
||||
.map((item) => item.text)
|
||||
.join("\n");
|
||||
const environment = values.providers
|
||||
? JSON.parse(await readFile(values.providers, "utf8"))
|
||||
: {};
|
||||
const started = performance.now();
|
||||
const upstream = await connectUpstream({
|
||||
command: process.execPath,
|
||||
args: [resolve(repository, "scripts/rea.mjs"), "mcp"],
|
||||
env: environment,
|
||||
});
|
||||
const connected = performance.now();
|
||||
const records = [];
|
||||
const realCall = upstream.call;
|
||||
upstream.call = async (name, args, options) => {
|
||||
const began = performance.now();
|
||||
try {
|
||||
const reply = await realCall(name, args, { timeout: 600_000, ...options });
|
||||
const parsed = json(reply);
|
||||
records.push({
|
||||
name,
|
||||
arguments: args,
|
||||
elapsed_ms: performance.now() - began,
|
||||
is_error: reply.isError === true,
|
||||
input: measure(args),
|
||||
output: measure(reply),
|
||||
text_output: measure(modelText(reply)),
|
||||
evidence_id: parsed.evidence_id,
|
||||
reply,
|
||||
});
|
||||
return reply;
|
||||
} catch (error) {
|
||||
records.push({
|
||||
name,
|
||||
arguments: args,
|
||||
elapsed_ms: performance.now() - began,
|
||||
failure: String(error),
|
||||
input: measure(args),
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
const bridge = new CodeModeBridge(upstream);
|
||||
const input = { path: artifactPath };
|
||||
if (artifact.id === "jq") {
|
||||
if (bytes.subarray(0, 6).toString("hex") !== "7f454c460201")
|
||||
throw new Error("Expected ELF64 little-endian header for entry seed");
|
||||
input.entry_address = `0x${bytes.readBigUInt64LE(24).toString(16)}`;
|
||||
}
|
||||
const code = `const input = ${JSON.stringify(input)};
|
||||
async function call(name, args) {
|
||||
const reply = await tools[name](args);
|
||||
const parsed = json(reply);
|
||||
if (reply.isError) throw new Error(JSON.stringify(parsed));
|
||||
return parsed;
|
||||
}
|
||||
${workflow.code}`;
|
||||
let discovery;
|
||||
let value;
|
||||
let failure;
|
||||
let bridgeReply;
|
||||
const recovery = [];
|
||||
const operationStarted = performance.now();
|
||||
try {
|
||||
if (values.mode !== "direct")
|
||||
discovery = await bridge.search({ names: workflow.tools });
|
||||
if (values.mode === "bridge") {
|
||||
bridgeReply = await bridge.execute({ code, timeout_ms: 900_000 });
|
||||
value = bridgeReply.value;
|
||||
failure = bridgeReply.bridge_error;
|
||||
} else {
|
||||
const tools = Object.fromEntries(
|
||||
upstream.catalog.map((tool) => [
|
||||
tool.name,
|
||||
(args) => upstream.call(tool.name, args),
|
||||
]),
|
||||
);
|
||||
const AsyncFunction = Object.getPrototypeOf(
|
||||
async function () {},
|
||||
).constructor;
|
||||
value = await new AsyncFunction("tools", "json", code)(tools, json);
|
||||
}
|
||||
} catch (error) {
|
||||
failure = String(error);
|
||||
} finally {
|
||||
const partials = new Set(
|
||||
records.flatMap((record) => {
|
||||
if (!record.reply?.isError) return [];
|
||||
try {
|
||||
const partial = json(record.reply).error?.details?.partial_observation;
|
||||
return partial?.kind === "retained-evidence"
|
||||
? [partial.evidence_id]
|
||||
: [];
|
||||
} catch {
|
||||
return []; // Preserve non-JSON failures in calls.json, without inventing IDs.
|
||||
}
|
||||
}),
|
||||
);
|
||||
for (const evidence_id of partials) {
|
||||
// Capture already retained partial facts before disposing the replay session.
|
||||
// Recovery is not a successful completion of the failed analyst workflow.
|
||||
try {
|
||||
const reply = await realCall(
|
||||
"inspect_analysis_view",
|
||||
{
|
||||
source: { kind: "retained-evidence", evidence_id },
|
||||
view: { kind: "summary" },
|
||||
},
|
||||
{ timeout: 60_000 },
|
||||
);
|
||||
recovery.push({ parent_evidence_id: evidence_id, reply });
|
||||
} catch (error) {
|
||||
recovery.push({
|
||||
parent_evidence_id: evidence_id,
|
||||
failure: String(error),
|
||||
});
|
||||
}
|
||||
}
|
||||
await upstream.close();
|
||||
}
|
||||
const catalogExposure = values.mode === "direct" ? upstream.catalog : discovery;
|
||||
const summary = {
|
||||
scope: "deterministic_real_provider_replay_not_model_accuracy",
|
||||
baseline_sha: "fb94d9dde0ccda83ae520ac6fb22b1d283562cf3",
|
||||
artifact: artifact.id,
|
||||
workflow: workflowName,
|
||||
artifact_sha256: sha256,
|
||||
mode: values.mode,
|
||||
question: workflow.question,
|
||||
startup_ms: connected - started,
|
||||
operation_ms: performance.now() - operationStarted,
|
||||
original_calls: records.map(({ reply: _reply, ...metadata }) => metadata),
|
||||
exposed_catalog: catalogExposure ? measure(catalogExposure) : null,
|
||||
direct_input_definitions: measure(
|
||||
upstream.catalog.map((tool) => ({
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
inputSchema: tool.inputSchema,
|
||||
})),
|
||||
),
|
||||
execution_code: values.mode === "bridge" ? measure(code) : null,
|
||||
exposed_tool_results:
|
||||
values.mode === "bridge"
|
||||
? [measure(bridgeReply)]
|
||||
: records.filter((x) => x.output).map((x) => x.output),
|
||||
exposed_text_results:
|
||||
values.mode === "bridge"
|
||||
? [measure(bridgeReply)]
|
||||
: records.filter((x) => x.text_output).map((x) => x.text_output),
|
||||
projection: value,
|
||||
failure: failure ?? null,
|
||||
partial_recovery: recovery,
|
||||
correctness: failure
|
||||
? "failed_workflow"
|
||||
: "requires_cross_profile_fact_review",
|
||||
estimator:
|
||||
"cl100k_base_compact_MCP_JSON_including_envelope_not_actual_model_tokens",
|
||||
};
|
||||
await writeFile(
|
||||
resolve(values.output, "summary.json"),
|
||||
JSON.stringify(summary, null, 2),
|
||||
);
|
||||
await writeFile(resolve(values.output, "calls.json"), JSON.stringify(records));
|
||||
await writeFile(resolve(values.output, "code.js"), code);
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
artifact: artifact.id,
|
||||
mode: values.mode,
|
||||
calls: records.length,
|
||||
startup_ms: summary.startup_ms,
|
||||
operation_ms: summary.operation_ms,
|
||||
failure: summary.failure
|
||||
? String(
|
||||
typeof summary.failure === "object"
|
||||
? summary.failure.message
|
||||
: summary.failure,
|
||||
).slice(0, 1000)
|
||||
: null,
|
||||
}),
|
||||
);
|
||||
if (failure) process.exitCode = 1;
|
||||
@@ -0,0 +1,426 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { McpServer } from "@modelcontextprotocol/server";
|
||||
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
||||
import { compile } from "json-schema-to-typescript";
|
||||
import { newQuickJSWASMModule, Scope } from "quickjs-emscripten";
|
||||
import { z } from "zod";
|
||||
|
||||
// Node maps larger delays to 1 ms. Reject them before creating a timer.
|
||||
const executeInputSchema = z.strictObject({
|
||||
code: z.string(),
|
||||
timeout_ms: z.number().int().positive().max(2_147_483_647).optional(),
|
||||
memory_bytes: z
|
||||
.number()
|
||||
.int()
|
||||
.positive()
|
||||
.max(128 * 1024 * 1024)
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const digest = (value) =>
|
||||
createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
||||
|
||||
export const json = (reply) => {
|
||||
if (reply.structuredContent !== undefined) return reply.structuredContent;
|
||||
const texts = reply.content.filter((item) => item.type === "text");
|
||||
if (texts.length !== 1) throw new Error("Expected one REA JSON text block");
|
||||
return JSON.parse(texts[0].text);
|
||||
};
|
||||
|
||||
/** One upstream session, original tool names, complete live catalog. */
|
||||
export async function connectUpstream({
|
||||
command,
|
||||
args,
|
||||
env,
|
||||
stderr = "inherit",
|
||||
}) {
|
||||
const transport = new StdioClientTransport({ command, args, env, stderr });
|
||||
const client = new Client({
|
||||
name: "rea-codemode-experiment",
|
||||
version: "0.0.0",
|
||||
});
|
||||
try {
|
||||
await client.connect(transport, { timeout: 60_000 });
|
||||
const catalog = [];
|
||||
let cursor;
|
||||
do {
|
||||
const page = await client.listTools(cursor ? { cursor } : undefined);
|
||||
catalog.push(...page.tools);
|
||||
cursor = page.nextCursor;
|
||||
} while (cursor !== undefined);
|
||||
if (new Set(catalog.map((tool) => tool.name)).size !== catalog.length)
|
||||
throw new Error("Duplicate upstream tool names");
|
||||
return {
|
||||
client,
|
||||
catalog,
|
||||
call: (name, args, options) =>
|
||||
client.callTool({ name, arguments: args }, options),
|
||||
close: () => client.close(),
|
||||
};
|
||||
} catch (error) {
|
||||
await client.close();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export class CodeModeBridge {
|
||||
constructor(upstream) {
|
||||
this.upstream = upstream;
|
||||
this.byName = new Map(upstream.catalog.map((tool) => [tool.name, tool]));
|
||||
this.catalogDigest = digest(upstream.catalog);
|
||||
this.declarations = new Map();
|
||||
this.queue = Promise.resolve();
|
||||
}
|
||||
|
||||
/** The live catalog is immutable for this connection; derive each type once. */
|
||||
declarationsFor(tool) {
|
||||
if (!this.declarations.has(tool.name)) {
|
||||
const options = { bannerComment: "", format: false, unknownAny: true };
|
||||
const pending = Promise.all([
|
||||
compile(tool.inputSchema, `${tool.name}_Input`, options),
|
||||
tool.outputSchema
|
||||
? compile(
|
||||
{ ...tool.outputSchema, title: `${tool.name}_Output` },
|
||||
`${tool.name}_Output`,
|
||||
options,
|
||||
)
|
||||
: undefined,
|
||||
]);
|
||||
this.declarations.set(tool.name, pending);
|
||||
}
|
||||
return this.declarations.get(tool.name);
|
||||
}
|
||||
|
||||
/** Search exposes original schemas and generated input types on demand. */
|
||||
async search({ query = "", names = [], schemas, output_schemas = false }) {
|
||||
const includeSchemas = schemas ?? (names.length > 0 || output_schemas);
|
||||
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
||||
const selected = this.upstream.catalog.filter((tool) =>
|
||||
names.length
|
||||
? names.includes(tool.name)
|
||||
: terms.every((term) =>
|
||||
`${tool.name} ${tool.description ?? ""}`
|
||||
.toLowerCase()
|
||||
.includes(term),
|
||||
),
|
||||
);
|
||||
// Failed all-word searches keep their original semantics. Offer only the
|
||||
// best positive lexical matches as names, without expanding their schemas.
|
||||
const ranked =
|
||||
selected.length || !terms.length || names.length
|
||||
? []
|
||||
: this.upstream.catalog.map((tool) => ({
|
||||
tool,
|
||||
score: terms.filter((term) =>
|
||||
`${tool.name} ${tool.description ?? ""}`
|
||||
.toLowerCase()
|
||||
.includes(term),
|
||||
).length,
|
||||
}));
|
||||
const bestScore = Math.max(0, ...ranked.map((row) => row.score));
|
||||
const suggestions = ranked
|
||||
.filter((row) => row.score === bestScore && bestScore > 0)
|
||||
.map(({ tool }) => ({ name: tool.name, description: tool.description }));
|
||||
const tools = [];
|
||||
for (const tool of selected) {
|
||||
const [inputType, outputType] = includeSchemas
|
||||
? await this.declarationsFor(tool)
|
||||
: [];
|
||||
tools.push(
|
||||
includeSchemas
|
||||
? {
|
||||
...tool,
|
||||
...(!output_schemas ? { outputSchema: undefined } : {}),
|
||||
typescript: inputType,
|
||||
output_typescript: outputType,
|
||||
}
|
||||
: {
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
annotations: tool.annotations,
|
||||
},
|
||||
);
|
||||
}
|
||||
return {
|
||||
catalog_sha256: this.catalogDigest,
|
||||
total_tools: this.byName.size,
|
||||
matched_tools: tools.length,
|
||||
tools,
|
||||
...(suggestions.length ? { suggestions } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/** Serialize scripts sharing the active target; no implicit batch races. */
|
||||
execute(input, options = {}) {
|
||||
const parsed = executeInputSchema.parse(input);
|
||||
const work = this.queue.then(() => this.run(parsed, options));
|
||||
this.queue = work.catch(() => undefined);
|
||||
return work;
|
||||
}
|
||||
|
||||
async run(
|
||||
{ code, timeout_ms = 120_000, memory_bytes = 128 * 1024 * 1024 },
|
||||
options,
|
||||
) {
|
||||
const controller = new AbortController();
|
||||
const signal = options.signal
|
||||
? AbortSignal.any([controller.signal, options.signal])
|
||||
: controller.signal;
|
||||
signal.throwIfAborted();
|
||||
const deadline = Date.now() + timeout_ms;
|
||||
const timer = setTimeout(
|
||||
() => controller.abort(new Error("Code Mode deadline exceeded")),
|
||||
timeout_ms,
|
||||
);
|
||||
const QuickJS = await newQuickJSWASMModule();
|
||||
const runtime = QuickJS.newRuntime();
|
||||
// Pending-job execution can create another context in the runtime.
|
||||
// Own contexts at creation, including those allocated by the job pump.
|
||||
const contexts = new Scope();
|
||||
const newContext = runtime.newContext.bind(runtime);
|
||||
runtime.newContext = (options) => contexts.manage(newContext(options));
|
||||
runtime.setMemoryLimit(memory_bytes);
|
||||
runtime.setMaxStackSize(1024 * 1024);
|
||||
runtime.setInterruptHandler(() => signal.aborted || Date.now() > deadline);
|
||||
const vm = runtime.newContext();
|
||||
const pending = new Set();
|
||||
const calls = [];
|
||||
let toolQueue = Promise.resolve();
|
||||
let finished = false;
|
||||
let promise;
|
||||
let value;
|
||||
let failure;
|
||||
const checkedEval = (source) => {
|
||||
const result = vm.evalCode(source);
|
||||
if (result.error) {
|
||||
const error = vm.dump(result.error);
|
||||
result.error.dispose();
|
||||
throw new Error(JSON.stringify(error));
|
||||
}
|
||||
return result.value;
|
||||
};
|
||||
const pump = () => {
|
||||
const result = runtime.executePendingJobs();
|
||||
if (result.error) {
|
||||
failure = vm.dump(result.error);
|
||||
result.error.dispose();
|
||||
finished = true;
|
||||
}
|
||||
};
|
||||
const fromJson = (data) =>
|
||||
checkedEval(`JSON.parse(${JSON.stringify(JSON.stringify(data))})`);
|
||||
const callHandle = vm.newFunction("call", (nameHandle, argumentsHandle) => {
|
||||
const name = vm.getString(nameHandle);
|
||||
const args = JSON.parse(vm.getString(argumentsHandle));
|
||||
if (!this.byName.has(name))
|
||||
throw new Error(`Unknown upstream tool: ${name}`);
|
||||
signal.throwIfAborted();
|
||||
const deferred = vm.newPromise();
|
||||
const audit = { name, arguments_sha256: digest(args) };
|
||||
calls.push(audit);
|
||||
const work = toolQueue.then(async () => {
|
||||
const started = performance.now();
|
||||
try {
|
||||
signal.throwIfAborted();
|
||||
const reply = await this.upstream.call(name, args, {
|
||||
signal,
|
||||
timeout: Math.max(1, deadline - Date.now()),
|
||||
onprogress: options.onprogress,
|
||||
});
|
||||
audit.elapsed_ms = performance.now() - started;
|
||||
audit.result_sha256 = digest(reply);
|
||||
audit.is_error = reply.isError === true;
|
||||
try {
|
||||
const record = json(reply);
|
||||
if (record.evidence_id) audit.evidence_id = record.evidence_id;
|
||||
if (Array.isArray(record.evidence_links))
|
||||
audit.evidence_links = record.evidence_links;
|
||||
const partial = record.error?.details?.partial_observation;
|
||||
if (partial?.kind === "retained-evidence")
|
||||
audit.partial_evidence_id = partial.evidence_id;
|
||||
} catch {
|
||||
/* Non-JSON MCP content is still preserved in reply. */
|
||||
}
|
||||
const handle = fromJson(reply);
|
||||
deferred.resolve(handle);
|
||||
handle.dispose();
|
||||
} catch (error) {
|
||||
audit.transport_error = error.message;
|
||||
const handle = fromJson({ name: error.name, message: error.message });
|
||||
deferred.reject(handle);
|
||||
handle.dispose();
|
||||
} finally {
|
||||
deferred.dispose();
|
||||
pump();
|
||||
}
|
||||
});
|
||||
const settled = work.catch((error) => {
|
||||
failure = { message: error.message };
|
||||
finished = true;
|
||||
});
|
||||
toolQueue = settled;
|
||||
pending.add(settled);
|
||||
void settled.then(() => pending.delete(settled));
|
||||
// The callback transfers its returned handle to QuickJS. Keep the
|
||||
// deferred's original host handle until settlement, with a separate
|
||||
// guest handle; otherwise bulk promise cleanup shares one lifetime.
|
||||
return deferred.handle.dup();
|
||||
});
|
||||
const doneHandle = vm.newFunction("done", (data) => {
|
||||
value = JSON.parse(vm.getString(data));
|
||||
finished = true;
|
||||
});
|
||||
const failHandle = vm.newFunction("fail", (error) => {
|
||||
failure = vm.dump(error);
|
||||
finished = true;
|
||||
});
|
||||
try {
|
||||
vm.setProp(vm.global, "__call", callHandle);
|
||||
vm.setProp(vm.global, "__done", doneHandle);
|
||||
vm.setProp(vm.global, "__fail", failHandle);
|
||||
checkedEval(`
|
||||
const tools = Object.freeze(Object.fromEntries(${JSON.stringify([...this.byName.keys()])}.map(
|
||||
name => [name, args => __call(name, JSON.stringify(args))]
|
||||
)));
|
||||
const json = reply => {
|
||||
if (reply.structuredContent !== undefined) return reply.structuredContent;
|
||||
const texts = reply.content.filter(item => item.type === 'text');
|
||||
if (texts.length !== 1) throw new Error('Expected one REA JSON text block');
|
||||
return JSON.parse(texts[0].text);
|
||||
};
|
||||
`).dispose();
|
||||
promise = checkedEval(`(async () => {\n${code}\n})().then(
|
||||
value => __done(JSON.stringify(value === undefined ? null : value)),
|
||||
error => __fail({name: error?.name, message: error?.message ?? String(error)})
|
||||
)`);
|
||||
pump();
|
||||
while (!finished && !signal.aborted) {
|
||||
if (pending.size) await Promise.race(pending);
|
||||
else
|
||||
throw new Error(
|
||||
"Guest promise cannot progress: no pending tool calls",
|
||||
);
|
||||
pump();
|
||||
}
|
||||
signal.throwIfAborted();
|
||||
if (calls.some((call) => !call.result_sha256 && !call.transport_error)) {
|
||||
controller.abort(
|
||||
new Error("Code returned before awaiting all tool calls"),
|
||||
);
|
||||
await Promise.allSettled(pending);
|
||||
failure = {
|
||||
message:
|
||||
"Code returned before awaiting all tool calls; calls were cancelled",
|
||||
};
|
||||
} else await Promise.allSettled(pending);
|
||||
} catch (error) {
|
||||
failure = { name: error.name, message: error.message };
|
||||
controller.abort(error);
|
||||
await Promise.allSettled(pending);
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
promise?.dispose();
|
||||
callHandle.dispose();
|
||||
doneHandle.dispose();
|
||||
failHandle.dispose();
|
||||
contexts.dispose();
|
||||
runtime.dispose();
|
||||
}
|
||||
return {
|
||||
catalog_sha256: this.catalogDigest,
|
||||
calls,
|
||||
...(failure ? { bridge_error: failure } : { value }),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function createBridgeServer(bridge) {
|
||||
const server = new McpServer({
|
||||
name: "rea-codemode-experiment",
|
||||
version: "0.0.0",
|
||||
});
|
||||
const reply = (result) => ({
|
||||
content: [{ type: "text", text: JSON.stringify(result) }],
|
||||
...(result.bridge_error ? { isError: true } : {}),
|
||||
});
|
||||
server.registerTool(
|
||||
"rea_search",
|
||||
{
|
||||
description:
|
||||
"Discover original upstream REA tools. Start with one domain word, e.g. query=android; query words must all occur. Query/empty discovery defaults to names and descriptions. Then supply all selected exact names together to obtain exact input schemas plus derived input/output TypeScript for code authoring. schemas=true/false overrides this choice. Request output_schemas=true only for original JSON validation contracts. rea_search and rea_execute are already declared bridge tools, not upstream catalog entries. catalog_sha256 hashes the SDK catalog, not REA server_identity.catalog.digests. Code calls tools.<name>(original_arguments); json(reply) parses the original MCP value.",
|
||||
inputSchema: z.strictObject({
|
||||
query: z.string().default(""),
|
||||
names: z.array(z.string()).default([]),
|
||||
schemas: z.boolean().optional(),
|
||||
output_schemas: z.boolean().default(false),
|
||||
}),
|
||||
annotations: {
|
||||
readOnlyHint: true,
|
||||
destructiveHint: false,
|
||||
idempotentHint: true,
|
||||
openWorldHint: false,
|
||||
},
|
||||
},
|
||||
async (input) => reply(await bridge.search(input)),
|
||||
);
|
||||
server.registerTool(
|
||||
"rea_execute",
|
||||
{
|
||||
description:
|
||||
"Run a JavaScript async function body with tools.<original_REA_name>(original_arguments), json(reply) and return. Await every call. json(reply) returns the original REA value: Evidence has normalized_result, evidence_id and limitations; session values have result. Select the needed normalized_result fields inside code before returning them with Evidence IDs and limitations. One upstream session persists. Calls run in order, including Promise.all. All original REA effects, validation and retention apply; projections are caller selections, not new Evidence. No host IO or imports. Call audit and Evidence IDs survive script errors. Default deadline 120s and guest memory 128 MiB; use longer deadline for native analysis.",
|
||||
inputSchema: executeInputSchema,
|
||||
annotations: {
|
||||
readOnlyHint: false,
|
||||
destructiveHint: true,
|
||||
idempotentHint: false,
|
||||
openWorldHint: true,
|
||||
},
|
||||
},
|
||||
async (input, context) =>
|
||||
reply(
|
||||
await bridge.execute(input, {
|
||||
signal: context.mcpReq.signal,
|
||||
onprogress:
|
||||
context.mcpReq._meta?.progressToken === undefined
|
||||
? undefined
|
||||
: (progress) =>
|
||||
context.mcpReq.notify({
|
||||
method: "notifications/progress",
|
||||
params: {
|
||||
...progress,
|
||||
progressToken: context.mcpReq._meta.progressToken,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
),
|
||||
);
|
||||
return server;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const [command, ...args] = process.argv.slice(2);
|
||||
if (!command) throw new Error("Usage: node bridge.mjs COMMAND [ARG...]");
|
||||
const upstream = await connectUpstream({ command, args, env: process.env });
|
||||
const server = createBridgeServer(new CodeModeBridge(upstream));
|
||||
let closing = false;
|
||||
const close = async () => {
|
||||
if (closing) return;
|
||||
closing = true;
|
||||
await server.close();
|
||||
await upstream.close();
|
||||
};
|
||||
process.once("SIGINT", () => void close());
|
||||
process.once("SIGTERM", () => void close());
|
||||
const transport = new StdioServerTransport();
|
||||
transport.onclose = () => void close();
|
||||
await server.connect(transport);
|
||||
}
|
||||
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
@@ -0,0 +1,313 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { after, before, test } from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import Ajv2020 from "ajv/dist/2020.js";
|
||||
import { CodeModeBridge, connectUpstream, json } from "./bridge.mjs";
|
||||
|
||||
const entrypoint = fileURLToPath(
|
||||
new URL("../../scripts/rea.mjs", import.meta.url),
|
||||
);
|
||||
const fixture = fileURLToPath(
|
||||
new URL("../../tests/conformance/readiness/javascript-cli", import.meta.url),
|
||||
);
|
||||
const analysisArgs = {
|
||||
input_path: fixture,
|
||||
detail: "summary",
|
||||
max_heap_mb: 128,
|
||||
};
|
||||
let upstream;
|
||||
let bridge;
|
||||
before(async () => {
|
||||
upstream = await connectUpstream({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env: { ...process.env, REA_LOG_LEVEL: "silent" },
|
||||
});
|
||||
bridge = new CodeModeBridge(upstream);
|
||||
});
|
||||
after(async () => {
|
||||
await upstream?.close();
|
||||
});
|
||||
|
||||
test("discovery preserves exact current REA schemas and names", async () => {
|
||||
const result = await bridge.search({
|
||||
names: ["binary_session"],
|
||||
output_schemas: true,
|
||||
});
|
||||
assert.equal(result.total_tools, upstream.catalog.length);
|
||||
const original = upstream.catalog.find(
|
||||
(tool) => tool.name === "binary_session",
|
||||
);
|
||||
const { typescript, output_typescript, ...discovered } = result.tools[0];
|
||||
assert.deepEqual(discovered, original);
|
||||
assert.match(typescript, /export interface BinarySession_Input/);
|
||||
assert.match(output_typescript, /export interface BinarySession_Output/);
|
||||
const inputOnly = await bridge.search({ names: ["binary_session"] });
|
||||
assert.deepEqual(inputOnly.tools[0].inputSchema, original.inputSchema);
|
||||
assert.equal(inputOnly.tools[0].outputSchema, undefined);
|
||||
assert.equal(inputOnly.tools[0].output_typescript, output_typescript);
|
||||
const all = await bridge.search({ schemas: false });
|
||||
assert.deepEqual(
|
||||
all.tools.map((tool) => tool.name),
|
||||
upstream.catalog.map((tool) => tool.name),
|
||||
);
|
||||
const query = await bridge.search({ query: "android" });
|
||||
assert.ok(query.tools.length > 0);
|
||||
assert.ok(query.tools.every((tool) => tool.inputSchema === undefined));
|
||||
const querySchemas = await bridge.search({ query: "android", schemas: true });
|
||||
assert.ok(querySchemas.tools.every((tool) => tool.inputSchema !== undefined));
|
||||
const outputRequested = await bridge.search({
|
||||
query: "android",
|
||||
output_schemas: true,
|
||||
});
|
||||
assert.ok(
|
||||
outputRequested.tools.every((tool) => tool.outputSchema !== undefined),
|
||||
);
|
||||
const missed = await bridge.search({
|
||||
query: "android impossible_query_word",
|
||||
});
|
||||
assert.equal(missed.matched_tools, 0);
|
||||
assert.ok(
|
||||
missed.suggestions.some((tool) => tool.name === "inspect_android_package"),
|
||||
);
|
||||
assert.ok(missed.suggestions.every((tool) => tool.inputSchema === undefined));
|
||||
});
|
||||
|
||||
test("raw original result and parsed result survive a real MCP call", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "const r = await tools.binary_session({}); return {raw:r, parsed:json(r)};",
|
||||
});
|
||||
assert.equal(result.bridge_error, undefined);
|
||||
assert.deepEqual(json(result.value.raw), result.value.parsed);
|
||||
assert.equal(result.calls[0].name, "binary_session");
|
||||
assert.match(result.calls[0].result_sha256, /^[a-f0-9]{64}$/);
|
||||
assert.equal(result.calls[0].is_error, false);
|
||||
});
|
||||
|
||||
test("Promise.all calls settle in order without losing pending work", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "return await Promise.all([tools.binary_session({}), tools.binary_session({}), tools.binary_session({})]);",
|
||||
});
|
||||
assert.equal(result.bridge_error, undefined);
|
||||
assert.equal(result.value.length, 3);
|
||||
assert.equal(result.calls.length, 3);
|
||||
assert.ok(result.calls.every((call) => call.result_sha256));
|
||||
});
|
||||
|
||||
test("upstream invalid-input result remains an original MCP error envelope", async () => {
|
||||
const args = {
|
||||
input_path: "/nonexistent/rea-codemode-artifact",
|
||||
detail: "summary",
|
||||
};
|
||||
const direct = await upstream.call("analyze_javascript_application", args);
|
||||
const result = await bridge.execute({
|
||||
code: `return await tools.analyze_javascript_application(${JSON.stringify(args)});`,
|
||||
});
|
||||
assert.equal(result.bridge_error, undefined);
|
||||
assert.equal(result.value.isError, true);
|
||||
assert.deepEqual(json(result.value).error, json(direct).error);
|
||||
assert.equal(result.calls[0].is_error, true);
|
||||
});
|
||||
|
||||
test("guest has no Node, filesystem, fetch or module-loading capabilities", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "return [typeof process,typeof require,typeof fetch,typeof Deno,Function('return typeof process')()];",
|
||||
});
|
||||
assert.deepEqual(result.value, Array(5).fill("undefined"));
|
||||
const imported = await bridge.execute({
|
||||
code: "return await import('node:fs');",
|
||||
});
|
||||
assert.ok(imported.bridge_error);
|
||||
});
|
||||
|
||||
test("CPU deadline interrupts runaway code and the next execution works", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "while(true) {}",
|
||||
timeout_ms: 20,
|
||||
});
|
||||
assert.ok(result.bridge_error);
|
||||
assert.deepEqual(result.calls, []);
|
||||
assert.equal((await bridge.execute({ code: "return 42;" })).value, 42);
|
||||
});
|
||||
|
||||
test("guest allocation pressure fails within its heap budget and permits reuse", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "return new Array(1_000_000).fill('x');",
|
||||
memory_bytes: 2 * 1024 * 1024,
|
||||
});
|
||||
assert.match(result.bridge_error.message, /memory/i);
|
||||
assert.deepEqual(result.calls, []);
|
||||
assert.equal((await bridge.execute({ code: "return 42;" })).value, 42);
|
||||
assert.throws(() =>
|
||||
bridge.execute({ code: "return 1;", timeout_ms: 2_147_483_648 }),
|
||||
);
|
||||
});
|
||||
|
||||
test("error after successful call preserves original Evidence reference", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: `await tools.analyze_javascript_application(${JSON.stringify(analysisArgs)}); throw new Error('after-call');`,
|
||||
});
|
||||
assert.match(result.bridge_error.message, /after-call/);
|
||||
assert.ok(result.calls[0].evidence_id);
|
||||
assert.ok(result.calls[0].evidence_links.length > 0);
|
||||
const readback = await upstream.call("get_evidence_bundle", {
|
||||
detail: "summary",
|
||||
});
|
||||
assert.equal(readback.isError, undefined);
|
||||
assert.ok(
|
||||
JSON.stringify(json(readback)).includes(result.calls[0].evidence_id),
|
||||
);
|
||||
for (const evidence_id of result.calls[0].evidence_links) {
|
||||
const view = json(
|
||||
await upstream.call("inspect_analysis_view", {
|
||||
source: { kind: "retained-evidence", evidence_id },
|
||||
view: { kind: "summary" },
|
||||
}),
|
||||
);
|
||||
assert.equal(view.normalized_result.parent_evidence_id, evidence_id);
|
||||
}
|
||||
});
|
||||
|
||||
test("provider timeout retains its actual partial Evidence reference", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: `const reply = await tools.analyze_javascript_application(${JSON.stringify({ ...analysisArgs, analysis_timeout_ms: 1 })}); return json(reply);`,
|
||||
});
|
||||
const partial = result.value.error.details.partial_observation;
|
||||
assert.equal(partial.kind, "retained-evidence");
|
||||
assert.equal(result.calls[0].is_error, true);
|
||||
assert.equal(result.calls[0].partial_evidence_id, partial.evidence_id);
|
||||
const view = json(
|
||||
await upstream.call("inspect_analysis_view", {
|
||||
source: partial,
|
||||
view: { kind: "summary" },
|
||||
}),
|
||||
);
|
||||
assert.equal(view.normalized_result.parent_evidence_id, partial.evidence_id);
|
||||
});
|
||||
|
||||
test("cancelling queued calls releases deferred handles and permits reuse", async () => {
|
||||
let callStarted;
|
||||
const started = new Promise((resolve) => {
|
||||
callStarted = resolve;
|
||||
});
|
||||
const cancelled = new AbortController();
|
||||
const controlled = new CodeModeBridge({
|
||||
catalog: upstream.catalog,
|
||||
async call(name, args, options) {
|
||||
const reply = await upstream.call(name, args, options);
|
||||
callStarted();
|
||||
// A controlled delivery delay after a real result makes the queued
|
||||
// cancellation deterministic, without simulating provider behavior.
|
||||
await new Promise((resolve) => setTimeout(resolve, 50));
|
||||
return reply;
|
||||
},
|
||||
});
|
||||
const execution = controlled.execute(
|
||||
{
|
||||
code: "return await Promise.all([tools.binary_session({}), tools.binary_session({})]);",
|
||||
},
|
||||
{ signal: cancelled.signal },
|
||||
);
|
||||
await started;
|
||||
cancelled.abort(new Error("controlled queued cancellation"));
|
||||
const result = await execution;
|
||||
assert.ok(result.bridge_error);
|
||||
assert.equal(result.calls.length, 2);
|
||||
assert.match(
|
||||
result.calls[1].transport_error,
|
||||
/controlled queued cancellation/,
|
||||
);
|
||||
assert.equal((await controlled.execute({ code: "return 42;" })).value, 42);
|
||||
});
|
||||
|
||||
test("a guest promise without any producer fails without hanging", async () => {
|
||||
const result = await bridge.execute({
|
||||
code: "return await new Promise(() => {});",
|
||||
});
|
||||
assert.match(result.bridge_error.message, /cannot progress/);
|
||||
});
|
||||
|
||||
test("bridge's two tools are usable through actual downstream stdio MCP", async () => {
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [
|
||||
fileURLToPath(new URL("./bridge.mjs", import.meta.url)),
|
||||
process.execPath,
|
||||
entrypoint,
|
||||
"mcp",
|
||||
],
|
||||
env: { ...process.env, REA_LOG_LEVEL: "silent" },
|
||||
stderr: "inherit",
|
||||
});
|
||||
const client = new Client({ name: "codemode-boundary-test", version: "1" });
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const catalog = await client.listTools();
|
||||
assert.deepEqual(
|
||||
catalog.tools.map((tool) => tool.name),
|
||||
["rea_search", "rea_execute"],
|
||||
);
|
||||
const ajv = new Ajv2020({ strict: true });
|
||||
const byName = new Map(catalog.tools.map((tool) => [tool.name, tool]));
|
||||
for (const tool of catalog.tools) {
|
||||
assert.equal(
|
||||
tool.inputSchema.$schema ??
|
||||
"https://json-schema.org/draft/2020-12/schema",
|
||||
"https://json-schema.org/draft/2020-12/schema",
|
||||
);
|
||||
assert.equal(
|
||||
ajv.validateSchema(tool.inputSchema),
|
||||
true,
|
||||
ajv.errorsText(),
|
||||
);
|
||||
}
|
||||
const validate = ajv.compile(byName.get("rea_execute").inputSchema);
|
||||
assert.equal(
|
||||
validate({ code: "return 1;", timeout_ms: 2_147_483_647 }),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
validate({ code: "return 1;", timeout_ms: 2_147_483_648 }),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
validate({ code: "return 1;", memory_bytes: 128 * 1024 * 1024 + 1 }),
|
||||
false,
|
||||
);
|
||||
const found = json(
|
||||
await client.callTool({
|
||||
name: "rea_search",
|
||||
arguments: { names: ["binary_session"] },
|
||||
}),
|
||||
);
|
||||
assert.equal(found.matched_tools, 1);
|
||||
const result = json(
|
||||
await client.callTool({
|
||||
name: "rea_execute",
|
||||
arguments: {
|
||||
code: "return json(await tools.binary_session({}));",
|
||||
},
|
||||
}),
|
||||
);
|
||||
assert.equal(result.value.result.open, false);
|
||||
const invalid = await client.callTool({
|
||||
name: "rea_execute",
|
||||
arguments: { code: 7 },
|
||||
});
|
||||
assert.equal(invalid.isError, true);
|
||||
const oversized = await client.callTool({
|
||||
name: "rea_execute",
|
||||
arguments: { code: "return 1;", timeout_ms: 2_147_483_648 },
|
||||
});
|
||||
assert.equal(oversized.isError, true);
|
||||
const oversizedMemory = await client.callTool({
|
||||
name: "rea_execute",
|
||||
arguments: { code: "return 1;", memory_bytes: 128 * 1024 * 1024 + 1 },
|
||||
});
|
||||
assert.equal(oversizedMemory.isError, true);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"schema_version": 1,
|
||||
"artifacts": [
|
||||
{
|
||||
"id": "sharex.dll",
|
||||
"file": "ShareX.dll",
|
||||
"bytes": 2162688,
|
||||
"sha256": "191a191be964e434daf0f9d76d1e0d8ddce90d7e248cba2a6b5ac9577f288d53",
|
||||
"provenance": {
|
||||
"project": "ShareX",
|
||||
"version": "19.0.2",
|
||||
"upstreamFile": "ShareX-19.0.2-portable.zip",
|
||||
"url": "https://github.com/ShareX/ShareX/releases/download/v19.0.2/ShareX-19.0.2-portable.zip",
|
||||
"transport_sha256": "967b5d838df5ce25fb5fd7cbd16f1bd797427e2df16907b022b74a4bc0fb9d54",
|
||||
"transport_bytes": 168796487,
|
||||
"derivation": "selected regular ZIP member ShareX.dll"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "sqlite.wasm",
|
||||
"file": "sqlite3.wasm",
|
||||
"bytes": 868907,
|
||||
"sha256": "2ee8f3dab694532afc8840e07703127287662d08b74e6ff50491ce63f00d5752",
|
||||
"provenance": {
|
||||
"project": "SQLite Wasm",
|
||||
"version": "3.53.4-build1",
|
||||
"upstreamFile": "sqlite-wasm-3.53.4-build1.tgz",
|
||||
"url": "https://registry.npmjs.org/@sqlite.org/sqlite-wasm/-/sqlite-wasm-3.53.4-build1.tgz",
|
||||
"transport_sha256": "24f46db4ce5248fa8f8f24b67e81909ab1a9c152f42a4796a32c6d385a6fb62b",
|
||||
"transport_bytes": 977616,
|
||||
"transport_integrity": "sha512-U8pvL0patYHMgieD8JxxYJTlh9m1LUX8+BDYb7MiKQzBI89f2qbdmdcG/PvnPaLm9wsBbv4VlVG453ixnxBOnA==",
|
||||
"derivation": "selected regular tar member package/dist/sqlite3.wasm"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "obsidian.asar",
|
||||
"file": "obsidian-1.14.4.asar",
|
||||
"bytes": 27477966,
|
||||
"sha256": "146ef8470d8cbb4a6db209bdc19bf2bad13350444186c0fd93c31087b142b92f",
|
||||
"provenance": {
|
||||
"project": "Obsidian",
|
||||
"version": "1.14.4",
|
||||
"upstreamFile": "obsidian-1.14.4.asar",
|
||||
"transport": {
|
||||
"file": "obsidian-1.14.4.asar.gz",
|
||||
"url": "https://github.com/obsidianmd/obsidian-releases/releases/download/v1.14.4/obsidian-1.14.4.asar.gz",
|
||||
"sha256": "d1ed428c363968774f0f3906e67d8a53a058ece0b6cdd924b07865977b2ada21",
|
||||
"bytes": 9200670
|
||||
},
|
||||
"derivation": "gzip decompression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "newpipe.apk",
|
||||
"file": "NewPipe_v0.29.1.apk",
|
||||
"bytes": 11507122,
|
||||
"sha256": "18447bfb1e06d113edc88df93f471827280de06f6f3d4dc42f56f28b9c1bab79",
|
||||
"provenance": {
|
||||
"project": "NewPipe",
|
||||
"version": "0.29.1",
|
||||
"upstreamFile": "NewPipe_v0.29.1.apk",
|
||||
"url": "https://github.com/TeamNewPipe/NewPipe/releases/download/v0.29.1/NewPipe_v0.29.1.apk"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "jq",
|
||||
"file": "jq-linux-amd64",
|
||||
"bytes": 2267912,
|
||||
"sha256": "b1c22172dd303f3be49e935aa56aa48a8b7a46e0bc838b4997d3bb451495870f",
|
||||
"provenance": {
|
||||
"project": "jq",
|
||||
"version": "1.8.2",
|
||||
"upstreamFile": "jq-linux-amd64",
|
||||
"url": "https://github.com/jqlang/jq/releases/download/jq-1.8.2/jq-linux-amd64"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "openwrt.bin",
|
||||
"file": "openwrt-25.12.5-ath79-generic-tplink_archer-c7-v5-squashfs-sysupgrade.bin",
|
||||
"bytes": 7405862,
|
||||
"sha256": "f15b16b36df7fce8a5cf1302320fdb428c3bb6fbc2949a4858afa257f4f364a2",
|
||||
"provenance": {
|
||||
"project": "OpenWrt Archer C7 v5",
|
||||
"version": "25.12.5",
|
||||
"upstreamFile": "openwrt-25.12.5-ath79-generic-tplink_archer-c7-v5-squashfs-sysupgrade.bin",
|
||||
"url": "https://downloads.openwrt.org/releases/25.12.5/targets/ath79/generic/openwrt-25.12.5-ath79-generic-tplink_archer-c7-v5-squashfs-sysupgrade.bin"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
# Decision from the frozen Code Mode experiment
|
||||
|
||||
Keep REA's existing CLI/MCP contracts as the default. Improve Evidence-aware
|
||||
workflow guidance and retain this two-tool bridge as an optional experiment.
|
||||
The measured Codex profiles do not justify a broad API refactor or a default
|
||||
switch to the external executor.
|
||||
|
||||
## What supports that choice
|
||||
|
||||
The [serial cohort](agent-results.json) contains sixteen real Codex CLI trials,
|
||||
configured with `gpt-5.6-terra` high, across Android, managed PE/CLI, Electron ASAR
|
||||
inventory, firmware and native Ghidra analysis. Twelve pass the strict requested
|
||||
fact/reference checks. Two bridge managed answers omit the classification's
|
||||
container field; two normal-MCP managed transcripts truncate a large producer
|
||||
envelope, preventing complete-envelope verification of one cited ID. Their
|
||||
remaining requested facts match the real-provider oracle. The complete-container
|
||||
assertion is stronger than the question's general classification wording.
|
||||
|
||||
The bridge's Android repetitions take 48.231 and 134.555 seconds, compared with
|
||||
67.329 and 71.624 for normal MCP. The faster bridge trial composes three original
|
||||
operations once; the slower one performs seven original calls across five scripts.
|
||||
The faster trial uses typed discovery; this does not make the model reliably
|
||||
choose that workflow. Uncached input is lower in both bridge repetitions;
|
||||
output and latency vary. This is not a stable overall efficiency win.
|
||||
|
||||
Managed bridge latency also varies, and its two answers omit the same field.
|
||||
Firmware's one-operation question takes 81.944 seconds with the bridge versus
|
||||
30.161 directly. Ghidra takes 334.642 versus 327.150 seconds, with sampled aggregate
|
||||
CPU times of 271.096 and 263.738 seconds. The bridge performs three original
|
||||
operations versus four directly, deriving containing identity from the analyzed
|
||||
procedure. Native analysis cost remains dominant with unchanged default settings.
|
||||
|
||||
Obsidian inventory exposes a useful contract boundary: nested Evidence types leave
|
||||
their normalized payload generic. The model initially returns the whole inventory
|
||||
and repeats analysis. Giving both profiles the concrete manifest/occurrences
|
||||
layout yields a single focused bridge workflow: 101994 total input tokens versus
|
||||
263484 directly, but 40554 versus 41532 uncached tokens and 85.909 versus 67.540
|
||||
seconds. Clear producer/layout guidance matters; total context compression alone
|
||||
does not establish lower cost or latency. Cache pricing is not estimated here.
|
||||
|
||||
Deterministic replays demonstrate large projection savings across real providers.
|
||||
They measure a known script, not the model's ability to discover and write it.
|
||||
SQLite WASM fails the frozen WABT parser on an unpadded DataCount row; Obsidian's
|
||||
full AST analysis times out with a retained partial reference. Inventory does not
|
||||
replace AST analysis. Neither failure is counted as a Code Mode success.
|
||||
|
||||
## Migration scope
|
||||
|
||||
Current users retain original operation names, arguments, provider choices,
|
||||
Evidence and session behavior. A client with equivalent execution support can use
|
||||
the existing registration and focused workflows. The installed Codex transcript
|
||||
does not expose its executor source, so its exact internal composition is unknown.
|
||||
|
||||
For clients that need the bridge, use a separate opt-in profile for an investigation.
|
||||
The bridge owns one original REA connection and looks up live contracts by name.
|
||||
Its session and Evidence ledger are separate from another REA registration; do
|
||||
not mix target lifecycle calls or same-session IDs across those registrations.
|
||||
Derived TypeScript assists code authoring; original JSON schemas remain available.
|
||||
Original producer IDs, links, errors and partial-reference IDs survive auditing;
|
||||
caller projections do not become new Evidence records.
|
||||
|
||||
The outer execution tool combines original effects and client requirements.
|
||||
This prototype has not forwarded roots/elicitation/sampling or preserved a client's
|
||||
per-original-operation approval flow. That capability boundary must be addressed
|
||||
before offering it as a production replacement. The guest's lack of host IO does
|
||||
not remove effects reachable through original REA tools.
|
||||
|
||||
An additive producer-description improvement explaining nested payload layout is
|
||||
a smaller next candidate than changing names or inventing another workflow API.
|
||||
Original inputs and output defaults should remain intact. Provider analysis
|
||||
settings must be evaluated separately from discovery and projection improvements.
|
||||
|
||||
## Verification limits
|
||||
|
||||
These are descriptive samples with matching questions/provider settings per pair,
|
||||
mode-specific instructions and model-selected arguments. They do not provide
|
||||
confidence intervals, independent decompiler truth, Android/.NET runtime behavior,
|
||||
full native-function coverage, complete firmware reconstruction or Windows/IDA
|
||||
provider verification. Citations are checked against observed producer values and
|
||||
links, not resolved individually after session exit.
|
||||
|
||||
Sixteen trials finish without sampled memory/task-limit events or resource aborts.
|
||||
Their maximum sampled memory is 1659744256 bytes (about 1.55 GiB), with at most
|
||||
126 tasks, under one CPU and a 4 GiB hard ceiling/3 GiB early stop. Copied profiles
|
||||
are removed. Twelve actual stdio tests additionally cover cancellation, partial
|
||||
Evidence readback, guest allocation failure/recovery, and advertised schema
|
||||
validation. The earlier 2 GiB build-scope kill remains a documented failed build.
|
||||
@@ -0,0 +1,249 @@
|
||||
"""Check requested JSON facts and real Evidence references against a replay oracle."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def required_field(row, key):
|
||||
return row[key] if key in row else {'missing_field': key}
|
||||
|
||||
|
||||
def same_fact(actual, expected):
|
||||
if isinstance(actual, bool) or isinstance(expected, bool):
|
||||
return type(actual) is type(expected) and actual == expected
|
||||
if isinstance(expected, dict):
|
||||
return isinstance(actual, dict) and actual.keys() == expected.keys() and all(
|
||||
same_fact(actual[key], value) for key, value in expected.items())
|
||||
if isinstance(expected, list):
|
||||
return isinstance(actual, list) and len(actual) == len(expected) and all(
|
||||
same_fact(a, b) for a, b in zip(actual, expected))
|
||||
return actual == expected
|
||||
|
||||
|
||||
def evidence_ids(value):
|
||||
if isinstance(value, str):
|
||||
return {value} if value.startswith('ev_') and len(value) == 67 else set()
|
||||
if isinstance(value, dict):
|
||||
return set().union(*(evidence_ids(v) for v in value.values()))
|
||||
if isinstance(value, list):
|
||||
return set().union(*(evidence_ids(v) for v in value))
|
||||
return set()
|
||||
|
||||
|
||||
def read_answer(path):
|
||||
source = path.read_text().strip()
|
||||
lines = source.splitlines()
|
||||
# Accept a single complete JSON fence, never repair prose or partial JSON.
|
||||
if len(lines) >= 3 and lines[0] == '```json' and lines[-1] == '```':
|
||||
source = '\n'.join(lines[1:-1])
|
||||
answer_format = 'markdown_json'
|
||||
else:
|
||||
answer_format = 'json'
|
||||
answer = json.loads(source)
|
||||
if not isinstance(answer, dict):
|
||||
raise ValueError('Answer is not a JSON object')
|
||||
return answer, answer_format
|
||||
|
||||
|
||||
def requested_facts(value, task):
|
||||
if task == 'native':
|
||||
facts = {field: value.get(field) for field in [
|
||||
'artifact_sha256', 'entry_address', 'containing_procedure',
|
||||
'procedure', 'pseudocode_prefix', 'caller_count', 'callee_count']}
|
||||
containing = facts['containing_procedure']
|
||||
if isinstance(containing, dict) and containing.get('found', True) is True and \
|
||||
containing.get('query_address', facts['entry_address']) == facts['entry_address']:
|
||||
identity = containing.get('procedure', containing)
|
||||
if isinstance(identity, dict):
|
||||
facts['containing_procedure'] = {key: identity.get(key) for key in ['address', 'name']}
|
||||
return facts
|
||||
if task == 'electron-inventory':
|
||||
facts = {field: value.get(field) for field in [
|
||||
'artifact_sha256', 'manifest', 'entry_kind_counts', 'requested_paths',
|
||||
'integrity_contradictions', 'coverage', 'unexplored_branches']}
|
||||
paths = facts['requested_paths']
|
||||
if isinstance(paths, dict) and set(paths) == {'package.json', 'main.js', 'preload.js'}:
|
||||
if all(isinstance(rows, list) and all(isinstance(row, dict) and
|
||||
row.get('logical_path') == name for row in rows)
|
||||
for name, rows in paths.items()):
|
||||
paths = [row for rows in paths.values() for row in rows]
|
||||
if isinstance(paths, list) and all(isinstance(row, dict) and
|
||||
isinstance(row.get('logical_path'), str) for row in paths):
|
||||
paths = sorted(paths, key=lambda row: row['logical_path'])
|
||||
facts['requested_paths'] = paths
|
||||
contradictions = facts['integrity_contradictions']
|
||||
if isinstance(contradictions, dict) and set(contradictions) == {'inspection', 'inventory'}:
|
||||
if all(rows == [] for rows in contradictions.values()):
|
||||
facts['integrity_contradictions'] = []
|
||||
branches = facts['unexplored_branches']
|
||||
if isinstance(branches, list) and all(isinstance(row, dict) for row in branches):
|
||||
# Branch identity includes the source Evidence identity. Compare its
|
||||
# reported meaning here and verify its actual source reference below.
|
||||
facts['unexplored_branches'] = [{key: row.get(key) for key in [
|
||||
'reason', 'detail', 'next_probe']} for row in branches]
|
||||
return facts
|
||||
if task == 'firmware':
|
||||
result = value.get('result')
|
||||
if not isinstance(result, dict):
|
||||
result = {}
|
||||
engine = result.get('engine', result.get('provider'))
|
||||
if isinstance(engine, dict):
|
||||
engine = {'version': engine.get('version'),
|
||||
'executable_sha256': engine.get('executable_sha256',
|
||||
engine.get('engine_artifact_sha256'))}
|
||||
regions = result.get('regions')
|
||||
if isinstance(regions, list) and all(isinstance(row, dict) for row in regions):
|
||||
# Binwalk's UUID is run-local; preserve it in the answer but do not
|
||||
# compare it with the independent replay's different occurrence ID.
|
||||
selected_regions = []
|
||||
for row in regions:
|
||||
selected = {key: row.get(key) for key in [
|
||||
'offset', 'signature', 'description', 'reported_confidence']}
|
||||
if 'reported_size' in row:
|
||||
size = row['reported_size']
|
||||
elif 'reported_extent_bytes' in row:
|
||||
size = row['reported_extent_bytes']
|
||||
else:
|
||||
extent = row.get('reported_extent')
|
||||
size = None
|
||||
if isinstance(extent, dict) and extent.get('offset') == row.get('offset'):
|
||||
length = extent.get('length')
|
||||
offset = row.get('offset')
|
||||
if isinstance(length, int) and isinstance(offset, int) and \
|
||||
extent.get('end_exclusive') == offset + length:
|
||||
size = length
|
||||
selected['reported_size'] = size
|
||||
selected_regions.append(selected)
|
||||
regions = selected_regions
|
||||
return {'artifact_sha256': value.get('artifact_sha256'),
|
||||
'engine': engine, 'input_size': result.get('input_size', result.get('input_size_bytes')),
|
||||
'regions': regions, 'coverage': result.get('coverage', result.get('examined_coverage'))}
|
||||
if task == 'managed':
|
||||
def selected(field, keys):
|
||||
row = value.get(field)
|
||||
return {key: required_field(row, key) for key in keys} if isinstance(row, dict) else row
|
||||
coverage = value.get('coverage')
|
||||
if isinstance(coverage, dict):
|
||||
coverage = {'managed_artifact': coverage.get('managed_artifact'),
|
||||
'native_boundaries': coverage.get('native_boundaries',
|
||||
coverage.get('managed_native_boundaries'))}
|
||||
coverage = {key: {field: row.get(field) for field in ['state', 'issues']}
|
||||
if isinstance(row, dict) else row
|
||||
for key, row in coverage.items() if key in ['managed_artifact', 'native_boundaries']}
|
||||
return {
|
||||
'artifact_sha256': value.get('artifact_sha256'),
|
||||
'assembly': selected('assembly', ['name', 'version']),
|
||||
'module': selected('module', ['name', 'mvid']),
|
||||
'classification': value.get('classification'),
|
||||
'target_frameworks': value.get('target_frameworks'),
|
||||
'native_boundaries': selected('native_boundaries', ['module_refs', 'pinvoke_imports']),
|
||||
'coverage': coverage,
|
||||
}
|
||||
facts = {field: value.get(field) for field in [
|
||||
'artifact_sha256', 'package_name', 'version_name', 'version_code', 'matches', 'onCreate']}
|
||||
methods = facts['onCreate']
|
||||
if isinstance(methods, list) and all(isinstance(row, dict) for row in methods):
|
||||
facts['onCreate'] = [{key: required_field(row, key) for key in [
|
||||
'reported_signature', 'overload_index', 'dex_descriptor']} for row in methods]
|
||||
return facts
|
||||
|
||||
|
||||
def producer_ids(reply):
|
||||
if not isinstance(reply, dict):
|
||||
return set(), 0
|
||||
ids = evidence_ids(reply.get('evidence_id'))
|
||||
ids |= evidence_ids(reply.get('evidence_links'))
|
||||
for call in reply.get('calls', []):
|
||||
ids |= evidence_ids(call.get('evidence_id'))
|
||||
ids |= evidence_ids(call.get('evidence_links'))
|
||||
ids |= evidence_ids(call.get('partial_evidence_id'))
|
||||
unreadable = 0
|
||||
# SDK envelopes and Codex JSONL use distinct declared field spellings.
|
||||
for field in ['structuredContent', 'structured_content']:
|
||||
nested_ids, nested_unreadable = producer_ids(reply.get(field))
|
||||
ids |= nested_ids
|
||||
unreadable += nested_unreadable
|
||||
for content in reply.get('content', []):
|
||||
if content.get('type') != 'text':
|
||||
continue
|
||||
try:
|
||||
value = json.loads(content['text'])
|
||||
except ValueError:
|
||||
unreadable += 1
|
||||
continue
|
||||
nested_ids, nested_unreadable = producer_ids(value)
|
||||
ids |= nested_ids
|
||||
unreadable += nested_unreadable
|
||||
return ids, unreadable
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--trial', type=Path, required=True)
|
||||
parser.add_argument('--oracle', type=Path, required=True)
|
||||
parser.add_argument('--task', choices=[
|
||||
'android', 'managed', 'native', 'firmware', 'electron-inventory'], default='android')
|
||||
args = parser.parse_args()
|
||||
oracle = json.loads(args.oracle.read_text())
|
||||
if oracle.get('failure') or not oracle.get('projection'):
|
||||
raise SystemExit('A failed replay is not a factual oracle')
|
||||
projection = oracle['projection']
|
||||
if args.task == 'managed':
|
||||
projection = {**projection, 'coverage': {
|
||||
'managed_artifact': projection['coverage'],
|
||||
'native_boundaries': projection['native_boundaries']['coverage'],
|
||||
}}
|
||||
expected = requested_facts(projection, args.task)
|
||||
# A task explicitly chooses these assertions; do not grade unrequested fields.
|
||||
if any(value is None for value in expected.values()):
|
||||
raise SystemExit('Replay does not contain the selected task facts')
|
||||
failures = []
|
||||
answer_format = None
|
||||
answer_path = args.trial / 'answer.txt'
|
||||
try:
|
||||
answer, answer_format = read_answer(answer_path)
|
||||
except (FileNotFoundError, ValueError) as error:
|
||||
answer = {}
|
||||
failures.append({'kind': 'answer_parse_failure', 'reason': str(error)})
|
||||
actual_facts = requested_facts(answer, args.task)
|
||||
for field, wanted in expected.items():
|
||||
actual = actual_facts[field]
|
||||
if not same_fact(actual, wanted):
|
||||
failures.append({'kind': 'fact_mismatch', 'field': field,
|
||||
'expected': wanted, 'actual': actual})
|
||||
observed = set()
|
||||
unreadable = 0
|
||||
for line in (args.trial / 'events.jsonl').read_text().splitlines():
|
||||
event = json.loads(line)
|
||||
item = event.get('item', {})
|
||||
if event.get('type') != 'item.completed' or item.get('type') != 'mcp_tool_call':
|
||||
continue
|
||||
# Only producer envelopes and bridge audit IDs establish retention.
|
||||
ids, skipped = producer_ids(item.get('result') or {})
|
||||
observed |= ids
|
||||
unreadable += skipped
|
||||
cited = evidence_ids(answer.get('evidence_ids'))
|
||||
if args.task == 'electron-inventory':
|
||||
for branch in answer.get('unexplored_branches', []):
|
||||
if isinstance(branch, dict):
|
||||
cited |= evidence_ids(branch.get('evidence_id'))
|
||||
if not cited:
|
||||
failures.append({'kind': 'missing_evidence_references'})
|
||||
if cited - observed:
|
||||
failures.append({'kind': 'unobserved_evidence_ids', 'ids': sorted(cited - observed)})
|
||||
result = {'task': args.task,
|
||||
'grader_sha256': hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
|
||||
'scope': 'producer_fact_parity_and_reference_existence_not_runtime_accuracy',
|
||||
'passed': not failures, 'fact_assertions': len(expected),
|
||||
'answer_format': answer_format,
|
||||
'unreadable_result_texts': unreadable,
|
||||
'cited_evidence_ids': sorted(cited), 'failures': failures}
|
||||
(args.trial / 'grade.json').write_text(json.dumps(result, indent=2) + '\n')
|
||||
print(json.dumps(result))
|
||||
raise SystemExit(0 if result['passed'] else 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Generated
+518
@@ -0,0 +1,518 @@
|
||||
{
|
||||
"name": "rea-codemode-experiment",
|
||||
"version": "0.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "rea-codemode-experiment",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/client": "2.3.1",
|
||||
"@modelcontextprotocol/server": "2.3.1",
|
||||
"js-tiktoken": "1.0.21",
|
||||
"json-schema-to-typescript": "16.0.0",
|
||||
"quickjs-emscripten": "0.32.0",
|
||||
"zod": "4.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ajv": "8.20.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "24.18.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@apidevtools/json-schema-ref-parser": {
|
||||
"version": "11.9.3",
|
||||
"resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-11.9.3.tgz",
|
||||
"integrity": "sha512-60vepv88RwcJtSHrD6MjIL6Ta3SOYbgfnkHb+ppAVK+o9mXprRtulx7VlRl3lN3bbvysAfCS7WMVfhUYemB0IQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jsdevtools/ono": "^7.1.3",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"js-yaml": "^4.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 16"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/philsturgeon"
|
||||
}
|
||||
},
|
||||
"node_modules/@apidevtools/json-schema-ref-parser/node_modules/js-yaml": {
|
||||
"version": "4.3.2",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.2.tgz",
|
||||
"integrity": "sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/puzrin"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/nodeca"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"argparse": "^2.0.1"
|
||||
},
|
||||
"bin": {
|
||||
"js-yaml": "bin/js-yaml.js"
|
||||
}
|
||||
},
|
||||
"node_modules/@jitl/quickjs-ffi-types": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/@jitl/quickjs-ffi-types/-/quickjs-ffi-types-0.32.0.tgz",
|
||||
"integrity": "sha512-v9T+GQpmk43VDJ7d72sf0Nexhk+ArvtUihW27dy7lqAl0zBObFKtSBBIm5RBjwIhE8VwsPPm9PNuvPvNqLWUEg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@jitl/quickjs-wasmfile-debug-asyncify": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/@jitl/quickjs-wasmfile-debug-asyncify/-/quickjs-wasmfile-debug-asyncify-0.32.0.tgz",
|
||||
"integrity": "sha512-EX8zbXwGqCgAE764M+qvkHtyXDi/FUoMBea0JnES7vCM3P7a2+EOZOjGv85wtZ2sJhI1oJ+nekmqpOODFDY+hw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-ffi-types": "0.32.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jitl/quickjs-wasmfile-debug-sync": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/@jitl/quickjs-wasmfile-debug-sync/-/quickjs-wasmfile-debug-sync-0.32.0.tgz",
|
||||
"integrity": "sha512-LeYWrPGC1uNCTBWvibo3ZLJj0CSVNYUXvJpXMCmuQ5Sap2cCACc3uvGvYV4homHHBAzfw5akoTqMMS4YFRtw+Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-ffi-types": "0.32.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jitl/quickjs-wasmfile-release-asyncify": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/@jitl/quickjs-wasmfile-release-asyncify/-/quickjs-wasmfile-release-asyncify-0.32.0.tgz",
|
||||
"integrity": "sha512-3oSwPfja12ICz4aIblB58cuY8JlEq5Txt8Cut4VLo+LH47QN+mzCnSgnbB03hWzg1LBcc+VyyI9UOag7a1NF+Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-ffi-types": "0.32.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jitl/quickjs-wasmfile-release-sync": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/@jitl/quickjs-wasmfile-release-sync/-/quickjs-wasmfile-release-sync-0.32.0.tgz",
|
||||
"integrity": "sha512-BKNDI/TPBfGlLNGYpLrhcDGXmIk4xHm4MRAisOBnOzpXVn9HZWsfmMAc9WMBrAHjvvds6HOikKeaOBKdPdpVrg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-ffi-types": "0.32.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@jsdevtools/ono": {
|
||||
"version": "7.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz",
|
||||
"integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@modelcontextprotocol/client": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/client/-/client-2.3.1.tgz",
|
||||
"integrity": "sha512-mIGZXpHsjnZ6lD+gD/WCMpR5k8yVQQ8nNFH1N0Srf7AvnwTUMYD6pvTY8ng2+He5FfV7YMZLmrjL7cLa/cc3dQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/core": "2.3.1",
|
||||
"cross-spawn": "^7.0.5",
|
||||
"eventsource": "^3.0.2",
|
||||
"eventsource-parser": "^3.0.8",
|
||||
"jose": "^6.1.3",
|
||||
"pkce-challenge": "^5.0.0",
|
||||
"zod": "^4.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@modelcontextprotocol/core": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/core/-/core-2.3.1.tgz",
|
||||
"integrity": "sha512-laVmIhPGpWi7rG9q+0UigblRN0Hws/Yjlb6qLFtVqryXVLkc4h+yN8z731POD2LnAGQlFe7/tXhUm7Bi0YB91g==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"zod": "^4.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@modelcontextprotocol/server": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/server/-/server-2.3.1.tgz",
|
||||
"integrity": "sha512-e59MfWuSssj6DoQ96JCTqdW1AXT5/XtnTl0WWd6MU1Ka434fFUGGosCLJbGNySDhHGvxQWoRWK137FXYFkYNWw==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/core": "2.3.1",
|
||||
"zod": "^4.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/json-schema": {
|
||||
"version": "7.0.15",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
|
||||
"integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/lodash": {
|
||||
"version": "4.17.26",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.26.tgz",
|
||||
"integrity": "sha512-48NWfiY6oNcKOh47Z4h+sIvwcQR91h6KPhaYKgeMIrkT2jV82Gy90SErj60vW8jQbeMSOSbhIv3bZ7JoqPPVhA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/ajv": {
|
||||
"version": "8.20.0",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz",
|
||||
"integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"fast-uri": "^3.0.1",
|
||||
"json-schema-traverse": "^1.0.0",
|
||||
"require-from-string": "^2.0.2"
|
||||
},
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/epoberezkin"
|
||||
}
|
||||
},
|
||||
"node_modules/argparse": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
|
||||
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
|
||||
"license": "Python-2.0"
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/cross-spawn": {
|
||||
"version": "7.0.6",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"path-key": "^3.1.0",
|
||||
"shebang-command": "^2.0.0",
|
||||
"which": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/eventsource": {
|
||||
"version": "3.0.7",
|
||||
"resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz",
|
||||
"integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"eventsource-parser": "^3.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/eventsource-parser": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.1.1.tgz",
|
||||
"integrity": "sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fast-deep-equal": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
||||
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/fast-uri": {
|
||||
"version": "3.1.8",
|
||||
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.8.tgz",
|
||||
"integrity": "sha512-GZMtZUTNRpOVIECoXwLNZS5xUGE+mVNbTB8h/7Rwh2TFWcBQiPzTgyZi05BF9UMZKkLJv8XBRJTlU7zg8+ZfMg==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/fastify"
|
||||
},
|
||||
{
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/fastify"
|
||||
}
|
||||
],
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/fdir": {
|
||||
"version": "6.5.0",
|
||||
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
|
||||
"integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"picomatch": "^3 || ^4"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"picomatch": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/isexe": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/jose": {
|
||||
"version": "6.2.12",
|
||||
"resolved": "https://registry.npmjs.org/jose/-/jose-6.2.12.tgz",
|
||||
"integrity": "sha512-9NiFmJEex0sy2Dk58j2UGBSHgUs2ypF9eZSu4L6vjOX3Dp96Sw1F3uL+H+D1sx02jZZdzUT0HgvCy59CuvXcWw==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/panva"
|
||||
}
|
||||
},
|
||||
"node_modules/js-tiktoken": {
|
||||
"version": "1.0.21",
|
||||
"resolved": "https://registry.npmjs.org/js-tiktoken/-/js-tiktoken-1.0.21.tgz",
|
||||
"integrity": "sha512-biOj/6M5qdgx5TKjDnFT1ymSpM5tbd3ylwDtrQvFQSu0Z7bBYko2dF+W/aUkXUPuk6IVpRxk/3Q2sHOzGlS36g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.5.1"
|
||||
}
|
||||
},
|
||||
"node_modules/js-yaml": {
|
||||
"version": "5.4.3",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-5.4.3.tgz",
|
||||
"integrity": "sha512-yzzNtgczwgoVHNigCyKTXcQJU4Y8t/ikU4UxXW0BvrLfHTGWZhsNcOT2s/a7vn81/4KqVnNmHjaUEPlvWnNwVw==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/puzrin"
|
||||
},
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/nodeca"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"argparse": "^2.0.1"
|
||||
},
|
||||
"bin": {
|
||||
"js-yaml": "bin/js-yaml.mjs"
|
||||
}
|
||||
},
|
||||
"node_modules/json-schema-to-typescript": {
|
||||
"version": "16.0.0",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-to-typescript/-/json-schema-to-typescript-16.0.0.tgz",
|
||||
"integrity": "sha512-Ah6kK4q6SjlMzWBH1eNOQkdRh5Qhr5T/RCFwfjQqWZA7UDW+N47A8wfyoiN0L884s4L4bAEI54IjIuN3/u0B/A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@apidevtools/json-schema-ref-parser": "^11.9.3",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"@types/lodash": "^4.17.25",
|
||||
"js-yaml": "^5.2.3",
|
||||
"lodash": "^4.18.1",
|
||||
"minimist": "^1.2.8",
|
||||
"prettier": "^3.9.6",
|
||||
"tinyglobby": "^0.2.17"
|
||||
},
|
||||
"bin": {
|
||||
"json2ts": "dist/src/cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/json-schema-traverse": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
|
||||
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash": {
|
||||
"version": "4.18.1",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz",
|
||||
"integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/minimist": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/path-key": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
|
||||
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/picomatch": {
|
||||
"version": "4.0.7",
|
||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz",
|
||||
"integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/jonschlinkert"
|
||||
}
|
||||
},
|
||||
"node_modules/pkce-challenge": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.1.tgz",
|
||||
"integrity": "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=16.20.0"
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.9.10",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.10.tgz",
|
||||
"integrity": "sha512-skGHTH1Yb9QvaTC4hWnRTzEYtCpApF0UMBPz+t/0ZPzP8ihefo/btKd+QA7pUE0fEwA1SbS/NmhyEcstdXOIdA==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/quickjs-emscripten": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/quickjs-emscripten/-/quickjs-emscripten-0.32.0.tgz",
|
||||
"integrity": "sha512-So0Sqw869y/S2oE3Nuc0uT3Dhqgvsj8FSrwBdsuTosVsG8ME5/OcudU1GxsrIFdFABgy17GHnTVO9TYV/bLQcA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-wasmfile-debug-asyncify": "0.32.0",
|
||||
"@jitl/quickjs-wasmfile-debug-sync": "0.32.0",
|
||||
"@jitl/quickjs-wasmfile-release-asyncify": "0.32.0",
|
||||
"@jitl/quickjs-wasmfile-release-sync": "0.32.0",
|
||||
"quickjs-emscripten-core": "0.32.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/quickjs-emscripten-core": {
|
||||
"version": "0.32.0",
|
||||
"resolved": "https://registry.npmjs.org/quickjs-emscripten-core/-/quickjs-emscripten-core-0.32.0.tgz",
|
||||
"integrity": "sha512-QFnPfjFey8EqknSrSxe1hZrf1/8z7/6s1QzGOmKo6++02r7QRRX7ZoyNaZh7JuVjWsVW87KnQrbZqnHkOAzUyg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jitl/quickjs-ffi-types": "0.32.0"
|
||||
}
|
||||
},
|
||||
"node_modules/require-from-string": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
||||
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/shebang-command": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"shebang-regex": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/shebang-regex": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
|
||||
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyglobby": {
|
||||
"version": "0.2.17",
|
||||
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",
|
||||
"integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fdir": "^6.5.0",
|
||||
"picomatch": "^4.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"isexe": "^2.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"node-which": "bin/node-which"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/zod": {
|
||||
"version": "4.3.6",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-4.3.6.tgz",
|
||||
"integrity": "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "rea-codemode-experiment",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": "24.18.0"
|
||||
},
|
||||
"packageManager": "npm@11.16.0",
|
||||
"scripts": {
|
||||
"test": "node --test bridge.test.mjs",
|
||||
"start": "node bridge.mjs",
|
||||
"bench": "node benchmark.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@modelcontextprotocol/client": "2.3.1",
|
||||
"@modelcontextprotocol/server": "2.3.1",
|
||||
"js-tiktoken": "1.0.21",
|
||||
"json-schema-to-typescript": "16.0.0",
|
||||
"quickjs-emscripten": "0.32.0",
|
||||
"zod": "4.3.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ajv": "8.20.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Statically investigate the actual shipped APK at {{artifact_path}} using only the registered REA tools. Report the exact artifact SHA-256, package name, version name/code, every class-name match for the case-sensitive substring MainActivity, and all onCreate method descriptors reported for org.schabi.newpipe.MainActivity. Preserve reported signatures and explicit unknowns. For each onCreate entry include reported_signature, overload_index and dex_descriptor exactly as reported, preserving null. Final answer must be JSON with artifact_sha256, package_name, version_name, version_code, matches, onCreate, evidence_ids, limitations. Include real Evidence IDs supporting each result. Do not execute the APK or use shell, host file tools, network or other agents. Stop once these facts are supported.
|
||||
|
||||
When a client JavaScript executor is available, compose the required REA calls in one execution and return only selected facts from normalized_result, real Evidence IDs, target identity from subject.digest.sha256 and limitations. Parse original MCP text content if necessary. Do not return raw_result, whole Evidence or unrelated inventories. All matching classes and onCreate overloads must still be included.
|
||||
@@ -0,0 +1 @@
|
||||
Statically inventory {{artifact_path}} using only the registered REA tools. Open this ASAR as an archive, inspect its artifact inventory, and close the session. Report exact target SHA-256, the complete inventory manifest, counts of every entry_kind across all occurrences, the original occurrence records for root paths package.json, main.js and preload.js if present, all integrity contradictions, inspection coverage, unexplored branches, real Evidence IDs and limitations. This question asks about package bytes and inventory, not AST interpretation or runtime behavior. Do not execute target code, analyze all JavaScript, extract files, launch a GUI, use shell/file tools/network or other agents. When a client JavaScript executor is available, compose original calls in dependency order and return only requested fields from normalized_result; the full inventory is the Evidence nested in the inspect_artifact inventory_artifact substep. Use Evidence.subject.digest.sha256 for the target identity and retain both inspection and inventory Evidence IDs. Final JSON fields: artifact_sha256, manifest, entry_kind_counts, requested_paths, integrity_contradictions, coverage, unexplored_branches, evidence_ids, limitations. Stop when these facts and cleanup are supported. Use the original open_binary, inspect_artifact and close_binary operations, with integrity_policy=fail. The inventory Evidence has normalized_result.manifest and normalized_result.occurrences; each occurrence has entry_kind and logical_path. Count the complete occurrences array and filter those three exact root logical_path values. Keep the complete inventory inside the executor when one is available; return the requested projection.
|
||||
@@ -0,0 +1 @@
|
||||
Statically inventory {{artifact_path}} using only the registered REA tools. Open this ASAR as an archive, inspect its artifact inventory, and close the session. Report exact target SHA-256, the complete inventory manifest, counts of every entry_kind across all occurrences, the original occurrence records for root paths package.json, main.js and preload.js if present, all integrity contradictions, inspection coverage, unexplored branches, real Evidence IDs and limitations. This question asks about package bytes and inventory, not AST interpretation or runtime behavior. Do not execute target code, analyze all JavaScript, extract files, launch a GUI, use shell/file tools/network or other agents. When a client JavaScript executor is available, compose original calls in dependency order and return only requested fields from normalized_result; the full inventory is the Evidence nested in the inspect_artifact inventory_artifact substep. Use Evidence.subject.digest.sha256 for the target identity and retain both inspection and inventory Evidence IDs. Final JSON fields: artifact_sha256, manifest, entry_kind_counts, requested_paths, integrity_contradictions, coverage, unexplored_branches, evidence_ids, limitations. Stop when these facts and cleanup are supported.
|
||||
@@ -0,0 +1 @@
|
||||
Statically inspect {{artifact_path}} using only the registered REA tools. Report exact target SHA-256 and every reported firmware region with offsets, signatures, reported extents, provider provenance and examined coverage. Preserve unknowns and limitations; a signature scan does not prove partition boundaries or boot/runtime validity. Do not execute target code, extract files, launch a GUI, use shell/file tools/network or other agents. When a client JavaScript executor is available, select the requested normalized_result fields, Evidence.subject.digest.sha256 and real Evidence IDs before returning output. Final JSON fields: artifact_sha256, result, evidence_ids, limitations. Stop when the requested facts are supported.
|
||||
@@ -0,0 +1 @@
|
||||
Statically inspect {{artifact_path}} using only the registered REA tools. Report exact target SHA-256, assembly name/version, module name/MVID, managed classification and architecture with its evidence, every reported target framework, and all declared native ModuleRef/PInvoke boundaries with coverage and limitations. Do not load or execute the assembly, launch a GUI, use shell/file tools/network or other agents. When a client JavaScript executor is available, compose the required original MCP calls and return only requested normalized_result fields, target identity from subject.digest.sha256 and real Evidence IDs. Do not return whole Evidence, raw_result or unrelated resources/custom-attribute inventories. Preserve dependency order for operations sharing the selected managed target. Final JSON fields: artifact_sha256, assembly, module, classification, target_frameworks, native_boundaries, coverage, evidence_ids, limitations. Stop when these facts are supported.
|
||||
@@ -0,0 +1 @@
|
||||
Statically inspect {{artifact_path}} using only the registered REA tools and Ghidra. The pinned ELF header was independently observed to report entry address 0x403a50; treat that address as the analyst's seed, not as a function-name assumption. Keep default auto-analysis enabled and allow at least 600 seconds for native analysis (including the script deadline if using a bridge). Open the target with provider_id ghidra, resolve the containing procedure for that address, analyze it, and close the ephemeral session in a finally block or a subsequent cleanup call. Report exact target SHA-256, the entry_address, containing_procedure, procedure metadata, the first 512 UTF-16 units of pseudocode, caller_count, callee_count, real Evidence IDs and limitations. Do not execute target code, launch a GUI, use shell/file tools/network or other agents. When a client JavaScript executor is available, compose the original calls in dependency order and select requested fields before returning output; use Evidence.subject.digest.sha256 for the target identity. Final JSON fields: artifact_sha256, entry_address, containing_procedure, procedure, pseudocode_prefix, caller_count, callee_count, evidence_ids, limitations. The address seed applies only to the pinned jq artifact in corpus.json. Stop when these facts and cleanup are supported.
|
||||
@@ -0,0 +1,127 @@
|
||||
"""Run one owned experiment in a bounded, transient Linux systemd scope."""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
|
||||
|
||||
def available_bytes():
|
||||
for line in Path('/proc/meminfo').read_text().splitlines():
|
||||
if line.startswith('MemAvailable:'):
|
||||
return int(line.split()[1]) * 1024
|
||||
raise RuntimeError('MemAvailable unavailable')
|
||||
|
||||
|
||||
def scope_has_processes(group):
|
||||
if group is None:
|
||||
return False
|
||||
try:
|
||||
return bool((group / 'cgroup.procs').read_text().strip())
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
|
||||
|
||||
def stop_owned_scope(unit, process, group):
|
||||
subprocess.run(['systemctl', '--user', 'stop', '--no-block', unit],
|
||||
check=False, timeout=5)
|
||||
for attempt in range(2):
|
||||
deadline = time.monotonic() + 10
|
||||
while process.poll() is None or scope_has_processes(group):
|
||||
if time.monotonic() >= deadline:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
else:
|
||||
return
|
||||
if attempt == 1:
|
||||
raise RuntimeError('Cleanup unverified; retain owned scope ' + unit)
|
||||
subprocess.run(['systemctl', '--user', 'kill', '--kill-who=all',
|
||||
'--signal=SIGKILL', unit], check=False, timeout=5)
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv[1:]
|
||||
if args and args[0] == '--':
|
||||
args = args[1:]
|
||||
if not args:
|
||||
raise SystemExit('Usage: resource-run.py -- COMMAND ARGS...')
|
||||
gib = 1024 ** 3
|
||||
if available_bytes() < 8 * gib:
|
||||
raise SystemExit('Refusing experiment: less than 8 GiB available')
|
||||
unit = 'rea-codemode-' + uuid.uuid4().hex + '.scope'
|
||||
cpu = max(os.sched_getaffinity(0))
|
||||
command = [
|
||||
'systemd-run', '--user', '--scope', '--unit=' + unit,
|
||||
'-p', 'MemoryMax=4G', '-p', 'MemoryHigh=3G', '-p', 'MemorySwapMax=0',
|
||||
'-p', 'CPUQuota=100%', '-p', 'TasksMax=192',
|
||||
'taskset', '-c', str(cpu), *args,
|
||||
]
|
||||
process = subprocess.Popen(command)
|
||||
peak = 0
|
||||
peak_tasks = 0
|
||||
events = {}
|
||||
cpu_stats = {}
|
||||
abort = None
|
||||
started = time.monotonic()
|
||||
try:
|
||||
group = None
|
||||
while process.poll() is None:
|
||||
if group is None:
|
||||
reply = subprocess.run(
|
||||
['systemctl', '--user', 'show', unit, '--value',
|
||||
'--property=ControlGroup'],
|
||||
capture_output=True, text=True, check=False,
|
||||
)
|
||||
path = reply.stdout.strip()
|
||||
if path:
|
||||
group = Path('/sys/fs/cgroup') / path.lstrip('/')
|
||||
current = group / 'memory.current' if group else None
|
||||
if current and current.exists():
|
||||
try:
|
||||
peak = max(peak, int(current.read_text()))
|
||||
peak_tasks = max(peak_tasks, int((group / 'pids.current').read_text()))
|
||||
cpu_stats = dict((key, int(value)) for key, value in
|
||||
(line.split() for line in (group / 'cpu.stat').read_text().splitlines()))
|
||||
for event_file in ['memory.events', 'pids.events']:
|
||||
events[event_file] = dict(
|
||||
(key, int(value)) for key, value in
|
||||
(line.split() for line in (group / event_file).read_text().splitlines())
|
||||
)
|
||||
except FileNotFoundError:
|
||||
# A completed transient scope can disappear between reads.
|
||||
pass
|
||||
if peak > 3 * gib:
|
||||
abort = 'scope_memory_early_stop'
|
||||
elif available_bytes() < 4 * gib:
|
||||
abort = 'host_available_memory_early_stop'
|
||||
elif events.get('pids.events', {}).get('max', 0):
|
||||
abort = 'scope_task_limit_observed'
|
||||
if abort:
|
||||
stop_owned_scope(unit, process, group)
|
||||
break
|
||||
time.sleep(0.1)
|
||||
code = process.wait()
|
||||
except BaseException:
|
||||
stop_owned_scope(unit, process, group)
|
||||
raise
|
||||
finally:
|
||||
if scope_has_processes(group):
|
||||
stop_owned_scope(unit, process, group)
|
||||
print(json.dumps({
|
||||
'resource_scope': unit, 'peak_cgroup_bytes_sampled': peak,
|
||||
'elapsed_seconds': round(time.monotonic() - started, 3),
|
||||
'abort': abort, 'hard_memory_bytes': 4 * gib,
|
||||
'early_stop_bytes': 3 * gib, 'cpu_quota_percent': 100,
|
||||
'cpu_affinity': [cpu],
|
||||
'task_ceiling': 192, 'peak_tasks_sampled': peak_tasks,
|
||||
'resource_events_last_observed': events,
|
||||
'cpu_stat_last_observed': cpu_stats,
|
||||
}), file=sys.stderr)
|
||||
raise SystemExit(125 if abort else code)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,367 @@
|
||||
# Preliminary measurements
|
||||
|
||||
These are real Codex CLI 0.161.0 trials on the frozen checkout, using
|
||||
`gpt-5.6-terra`, high reasoning, one CPU and a guarded memory scope. The task
|
||||
called `binary_session` once and requested open state and server identity. This
|
||||
is a health probe, not an investigation benchmark. API input tokens are cumulative
|
||||
across model steps; cached tokens are a subset, not an additional cost.
|
||||
|
||||
| Profile | Seconds | Input tokens | Cached input | Output tokens | Outcome |
|
||||
| ---------------------------------- | ------: | -----------: | -----------: | ------------: | --------------------------------------------------------------- |
|
||||
| Direct MCP | 47.635 | 103154 | 70656 | 940 | Correct closed state; identity omitted after preview truncation |
|
||||
| Client Code Mode flag | 67.345 | 197315 | 157696 | 1458 | Correct closed state; extra failed resource lookup |
|
||||
| Client Code Mode only flag | 54.276 | 126609 | 84992 | 939 | Correct closed state; identity omitted |
|
||||
| Bridge, original prompt | 300.173 | unavailable | unavailable | unavailable | Timeout before any completed tool call |
|
||||
| Bridge, explicit projection prompt | 84.790 | 209248 | 175616 | 2125 | Correct closed state/version; conflated catalog identities |
|
||||
|
||||
These prompts and flags do not establish a controlled comparison. The projection
|
||||
trial used a more explicit prompt. The client trials expose nested original MCP
|
||||
calls in their transcripts; the flags alone do not establish code composition or
|
||||
intermediate-result filtering. The timeout is retained as a failed trial without
|
||||
an attributed root cause.
|
||||
|
||||
The direct tool delivered the original session result, including package version
|
||||
6.4.0 and REA's catalog digests. In the bridge projection trial the script selected
|
||||
the nonexistent `server_identity.catalog.digest`, which JavaScript omitted. The
|
||||
answer instead used the bridge's SDK catalog hash. That is not the requested REA
|
||||
identity and must fail that factual check. No unsupported digest is used as an
|
||||
oracle for subsequent trials.
|
||||
|
||||
Discovery was unnecessarily returning entire output schemas. For example, the
|
||||
live `binary_session` output schema occupies 18039 compact JSON bytes, compared
|
||||
with 859 for its input schema. `analyze_javascript_application` uses 41662 and
|
||||
2863 bytes respectively. The complete SDK catalog contains 172 tools and 1986857
|
||||
compact JSON bytes. The bridge now defaults to input schemas and makes unchanged
|
||||
output schemas available explicitly. Actual model savings from this change remain
|
||||
unmeasured.
|
||||
|
||||
The upstream/downstream stdio boundary suite passed all nine tests. The repository
|
||||
typecheck and lint passed under a one-CPU resource scope with a sampled peak of
|
||||
2934038528 bytes. A 2 GiB soft limit caused heavy reclaim during native TypeScript
|
||||
checking; the wrapper's soft limit is now aligned with its 3 GiB early-stop
|
||||
threshold. Its 4 GiB hard ceiling and host-available-memory checks remain in force.
|
||||
An earlier cached-build attempt was killed inside its 2 GiB scope; that is a
|
||||
failed build attempt, not evidence of a host OOM or a benchmark result.
|
||||
|
||||
## Real shipped artifacts
|
||||
|
||||
All acquired bytes match `corpus.json`; ShareX's archive also matches the GitHub
|
||||
asset digest and SQLite's npm archive matches its published SHA-512 integrity.
|
||||
No target was executed. These measurements use real REA providers and SDK stdio,
|
||||
with the same analysis arguments in each compared profile.
|
||||
|
||||
NewPipe's direct, discovery-only replay and bridge replay produce equal selected
|
||||
facts, including exact target digest, package/version, two MainActivity matches,
|
||||
reported `onCreate` signature, overload index and unavailable DEX descriptor. The
|
||||
bridge retains all three real producer IDs. Discovery-only here is a replay cost
|
||||
decomposition, not an implemented new MCP client protocol.
|
||||
|
||||
| Replay delivery | Discovery estimate | Intermediate/final result estimate |
|
||||
| -------------------------------------------------- | -----------------: | ---------------------------------: |
|
||||
| Direct: input definitions only, text content once | 107076 | 94945 |
|
||||
| On-demand input definitions, original text content | 877 | 94945 |
|
||||
| On-demand definitions, one composed projection | 877 | 1057 |
|
||||
|
||||
The bridge also sends 290 estimated tokens of code. Estimates use `cl100k_base`;
|
||||
they are not Terra API tokens, latency or model task success. The direct baseline
|
||||
uses input definitions and single text content, avoiding an inflated comparison
|
||||
against duplicated MCP envelopes or unused output schemas. The full SDK envelope
|
||||
figures, where useful for local transport, are recorded separately.
|
||||
|
||||
ShareX's real PE/CLI metadata and native-boundary workflows agree across direct
|
||||
and bridge: assembly ShareX 19.0.2.0, modern .NET, x86_64, framework
|
||||
`.NETCoreApp,Version=v9.0`, declared native boundaries and explicit coverage.
|
||||
Single text-content estimates are 204766 tokens for the two original results and
|
||||
4148 for the bridge projection. No .NET runtime behavior was verified.
|
||||
|
||||
jq's original trial failed because the stripped shipped executable has no
|
||||
`jq_compile` symbol. The corrected direct trial uses the observed ELF entry
|
||||
`0x403a50`, resolves it to Ghidra's `entry` function and analyzes that function.
|
||||
It succeeds with retained Evidence and a closed ephemeral provider session.
|
||||
The corrected bridge returns identical selected facts and limitations. Its final
|
||||
result estimate is 1544 tokens versus 10189 for direct single-text results, plus
|
||||
1610 for discovery and 267 for code. This small entry function
|
||||
does not establish large-function or complete native-analysis coverage.
|
||||
|
||||
OpenWrt's original direct trial returned `unreadable_output` without the expected
|
||||
report. Twelve independent bounded Binwalk invocations produced reports. An
|
||||
observer launcher and a subsequent unchanged real Binwalk bridge trial succeeded,
|
||||
reporting uImage at offset 0 and SquashFS at 2741985 with `signature_scan` coverage.
|
||||
The observer is a diagnostic with a different launcher identity, not a benchmark
|
||||
baseline. The original failure remains unexplained. Subsequent direct and bridge
|
||||
workflows agree on all region facts and coverage; random upstream region IDs vary
|
||||
and are preserved. Single-text estimates are 1387 tokens direct and 827 projected,
|
||||
so this one-operation task provides much less composition benefit than Android.
|
||||
|
||||
SQLite's actual WASM fails the frozen REA WABT output parser with `Unrecognized
|
||||
WABT section row`. WABT 1.0.42 prints the nine-character DataCount label without
|
||||
leading padding; the owning parser currently requires leading whitespace. No
|
||||
downstream shim is used, and no successful WASM provider claim is made.
|
||||
Obsidian's initial real-model analysis ended without Evidence after Codex's host
|
||||
closed stdout. Its standalone SDK replay returns a real provider timeout with a
|
||||
retained partial Evidence ID. This was observed before automatic partial-summary
|
||||
recovery was added, so the transcript retains that reference but does not export
|
||||
its payload. A source-fixture production-boundary test now verifies that provider
|
||||
timeout IDs survive auditing and resolve through the retained-evidence view.
|
||||
Neither failure is a Code Mode speedup.
|
||||
|
||||
## Real Android agents
|
||||
|
||||
After raising the task ceiling, a direct Terra trial completes in 107.478 seconds
|
||||
with 348556 API input tokens (292608 cached), 1815 output tokens and five completed
|
||||
MCP calls. All six strict producer-fact assertions and cited-ID checks pass. Its
|
||||
sampled peak is 1349251072 bytes and 127 tasks, with zero observed limit events.
|
||||
|
||||
A client Code Mode trial passes the same assertions in 183.361 seconds with
|
||||
414869 input tokens (372480 cached), 3618 output tokens. The transcript must still
|
||||
be inspected before attributing native composition or filtering to that flag.
|
||||
|
||||
The bridge trial before explicit projection guidance takes 84.754 seconds,
|
||||
292063 input tokens (244992 cached) and 1661 output tokens. It returns whole
|
||||
Evidence instead of filtering most intermediates. Requested facts and IDs are
|
||||
supported, but its stronger exact-projection check fails because overload index
|
||||
was omitted. A clarified question explicitly requires that index in later trials.
|
||||
|
||||
The next bridge trial composes three calls and filters their results, but selects
|
||||
`normalized_result.engine.artifact_sha256` as the target hash. This is the Jadx
|
||||
bridge JAR identity, not the APK identity. The strict hash check fails. It takes
|
||||
166.411 seconds and 324417 input tokens (279040 cached), 2362 output tokens.
|
||||
This confirms a real provenance risk in model-written projections. Trial
|
||||
instructions now identify `Evidence.subject.digest.sha256` explicitly. This
|
||||
change has not yet established a reliable repeated model efficiency gain.
|
||||
|
||||
The following bridge trial passes all six assertions and cited-ID checks, using
|
||||
one execution script for all three original operations. It takes 137.966 seconds,
|
||||
190313 input tokens (156672 cached) and 1695 output tokens. Four discovery calls
|
||||
precede the script. This is an encouraging token result, but its revised prompt,
|
||||
instructions and concurrent host workload prevent a controlled speed comparison.
|
||||
Instructions and prompt digests are now retained without authentication or an
|
||||
ambient environment snapshot, so future equal-task repetitions can be audited.
|
||||
|
||||
The 6.1 sol diagnostic touched the 96-task limit; it is invalid as a comparison
|
||||
and was interrupted, with its copied profile removed. The wrapper now allows 192
|
||||
tasks, records task/memory limit events and rejects capacity-limited trials. A
|
||||
real thread-creation probe hit exactly 192 tasks, was stopped with exit 125 and
|
||||
retained its limit reason; it used about 12 MiB and caused no memory-limit event.
|
||||
The nine actual stdio boundary tests pass after discovery changes.
|
||||
|
||||
Wall times above include contention on the same pinned CPU during exploratory
|
||||
work and differing prompts/instructions. They cannot support a controlled speed
|
||||
ratio. A reproducible efficiency conclusion requires successful equal-task trials
|
||||
and serial repetitions with the strongest existing-client baseline.
|
||||
|
||||
The stronger client trial uses an explicit instruction to compose and project the
|
||||
existing operations, and passes all six checks: 72.341 seconds, 161370 input
|
||||
tokens (120576 cached), 1664 output tokens and three completed MCP calls. An
|
||||
equivalent question with the bridge passes in 115.962 seconds, 321295 input tokens
|
||||
(283648 cached), 2274 output tokens, five discovery calls and one execution. The
|
||||
native transcript does not expose executor source, so exact internal composition
|
||||
is unverified. Nevertheless, this measured client profile is a materially stronger
|
||||
baseline than the original repeated-call trial. Total input, uncached input,
|
||||
output and wall time must be considered separately; cached-token differences make
|
||||
total input an incomplete cost metric.
|
||||
|
||||
This reverses the preliminary temptation to equate replay compression with the
|
||||
best Codex experience. Existing client support with explicit Evidence-aware
|
||||
recipes may be enough. An optional bridge needs to justify discovery overhead and
|
||||
remains useful to test for clients without equivalent execution support.
|
||||
|
||||
Eleven actual SDK/stdio tests pass, including a controlled delivery delay after a
|
||||
real upstream result to exercise queued cancellation. Both the delayed call and
|
||||
its queued successor release deferred guest handles before runtime disposal.
|
||||
This test does not simulate or establish new provider behavior.
|
||||
|
||||
The bridge remains an experiment and has not changed any published REA contract.
|
||||
|
||||
## Existing-client and managed follow-up
|
||||
|
||||
The same Android v3 question with normal MCP, without the experimental Code Mode
|
||||
feature flags, passes all six fact assertions and reference checks: 75.117 seconds,
|
||||
103471 API input tokens (73728 cached), 1538 output tokens and three original MCP
|
||||
calls. This is the strongest measured Android baseline so far. Its wall time also
|
||||
includes a short boundary-test overlap, so it is not a controlled latency ratio.
|
||||
The installed model catalog requests code-mode-only tool delivery; flag settings
|
||||
and nested MCP events alone cannot establish the internal executor's behavior.
|
||||
|
||||
The first real ShareX managed-agent comparison uses the same question with Terra
|
||||
high and identical provider settings. Normal MCP takes 81.578 seconds, 217573 input
|
||||
tokens (186368 cached), 2647 output tokens and two original calls. The bridge takes
|
||||
96.930 seconds, 218089 input tokens (155904 cached), 3247 output tokens, four
|
||||
searches and two executions. Its first script uses an expression instead of the
|
||||
required async-body `return`, yielding no projection; it repeats both operations.
|
||||
Query discovery now defaults to lightweight names/descriptions, while exact-name
|
||||
discovery supplies input schemas. This run still requested full output schemas
|
||||
individually and therefore does not establish an efficiency gain from that change.
|
||||
|
||||
Both answers match all seven requested managed fact groups, including exact target
|
||||
SHA-256, assembly/module identities, classification evidence, framework, declared
|
||||
ModuleRef/PInvoke arrays and coverage. Those empty arrays concern ShareX.dll only.
|
||||
The bridge passes cited-reference verification. Codex truncated the original
|
||||
managed-artifact response in its normal-MCP JSONL at roughly one MiB, leaving an
|
||||
invalid JSON fragment; the automated grader cannot validate that one reference
|
||||
from a complete producer envelope. Its reference-failure result is retained,
|
||||
despite the matching ID being visible in the transcript prefix and replay. This
|
||||
is a verification limitation, not a demonstrated fabricated ID.
|
||||
|
||||
The runner now handles SIGTERM so copied trial credentials are removed during a
|
||||
resource abort. A controlled non-model launcher received owned-scope SIGTERM,
|
||||
exited 143 and left no trial profile while preserving the dummy source auth file.
|
||||
This verifies credential cleanup only. The eleven actual stdio tests pass after
|
||||
the adaptive discovery change, with a sampled peak of 1365106688 bytes, 42 tasks
|
||||
and zero observed memory/task limit events.
|
||||
|
||||
## Serial comparison and package inventory
|
||||
|
||||
A serial Android v3 pair, without concurrent provider/build work, passes every
|
||||
fact and cited-reference check. Normal MCP uses 56.962 seconds, 105861 input
|
||||
(75776 cached, 30085 uncached), 1106 output tokens and three original calls. The
|
||||
adaptive-discovery bridge uses 106.134 seconds, 200537 input (175872 cached,
|
||||
24665 uncached), 2177 output tokens, four searches and one execution. Its smaller
|
||||
uncached input does not imply lower overall cost: output, cache rates and latency
|
||||
also matter. It still requests original output schemas and mistakenly searches
|
||||
for the already exposed bridge executor. Sampled memory peaks are 1333710848 and
|
||||
1656098816 bytes respectively; neither run touches memory/task limits. One pair
|
||||
is insufficient for a statistical latency or reliability claim.
|
||||
|
||||
A separate Obsidian package-inventory replay succeeds with existing REA tools.
|
||||
Direct and bridge return byte-for-byte equal selected facts: 397 graph nodes and
|
||||
occurrences, 369 files, 28 directories, root main.js/package.json occurrences,
|
||||
no root preload.js, no observed integrity contradiction, complete-within-substeps
|
||||
coverage and an explicit unexplored JavaScript analysis branch. Both original
|
||||
Evidence IDs are preserved. Direct/bridge operations take 6.267/6.618 seconds;
|
||||
original single-text results total 178958 estimated tokens versus a 1404-token
|
||||
bridge result, 1305 for discovery and 322 for code. These are replay estimates,
|
||||
not model latency or success. Inventory does not complete the timed-out AST task.
|
||||
|
||||
An output-type discovery probe compiles seven real SDK schemas successfully.
|
||||
Derived TypeScript estimates are 784/719/751 tokens for Android package/search/
|
||||
class, 1558/1420 for managed artifact/native boundaries, 1264 for artifact inventory
|
||||
and 2289 for function analysis. Their original JSON schemas use 1666/1480/1576,
|
||||
3524/2932, 2812 and 5091 respectively. These declarations describe code values;
|
||||
they do not preserve every JSON Schema validation rule. Exact-name discovery now
|
||||
includes them without replacing explicitly requested original JSON schemas. Real
|
||||
model benefit from this addition remains to be tested. The audit also carries
|
||||
original Evidence links; a real retained-view readback verifies linked IDs rather
|
||||
than trusting references invented by a projection.
|
||||
|
||||
The output-declaration boundary suite first failed its type-name assertion because
|
||||
the compiler preferred the schema's URN identity as a display name. The derived
|
||||
compilation now supplies a descriptive title while returning the original schema
|
||||
unchanged. All eleven tests then pass, including original-link readback, at a
|
||||
sampled peak of 1399996416 bytes and zero observed limit events. Declarations are
|
||||
cached per exact tool name for this immutable live-catalog connection; repeated
|
||||
discovery does not regenerate them. No provider implementation or published
|
||||
REA API has changed.
|
||||
|
||||
## Typed-discovery serial agent checkpoint
|
||||
|
||||
All rows below use real Codex CLI 0.161.0, Terra high, the same rendered question
|
||||
within each pair, and the same provider settings. The bridge/runtime/runner source
|
||||
fingerprints match commit `22326e819`; model-written original arguments can differ.
|
||||
Comparisons include required mode-specific instructions and are not a controlled
|
||||
causal decomposition of inference, caching and provider time.
|
||||
|
||||
| Case | Profile | Wall seconds | Input | Cached | Uncached | Output | MCP calls | Fact/reference check |
|
||||
| ------------------ | ------- | -----------: | -----: | -----: | -------: | -----: | --------: | --------------------------------- |
|
||||
| android | direct | 67.329 | 107007 | 83712 | 23295 | 1670 | 3 | pass |
|
||||
| android | bridge | 48.231 | 113256 | 91648 | 21608 | 1456 | 3 | pass |
|
||||
| managed | bridge | 73.145 | 116974 | 92672 | 24302 | 2065 | 3 | classification field omitted |
|
||||
| managed | direct | 33.15 | 108096 | 75776 | 32320 | 2315 | 2 | facts match; reference unverified |
|
||||
| electron-inventory | direct | 89.494 | 266121 | 238848 | 27273 | 3215 | 3 | pass |
|
||||
| electron-inventory | bridge | 145.577 | 462809 | 407040 | 55769 | 5624 | 8 | pass |
|
||||
| firmware | bridge | 81.944 | 152886 | 126976 | 25910 | 2192 | 3 | pass |
|
||||
| firmware | direct | 30.161 | 103224 | 74752 | 28472 | 1761 | 1 | pass |
|
||||
|
||||
The managed bridge omits the producer classification container field (`pe`) while
|
||||
preserving status/runtime/implementation/architecture and all classification
|
||||
evidence. Its strict complete-classification assertion fails; this is an omission,
|
||||
not an incorrect architecture claim. Normal MCP matches requested facts but its
|
||||
large-result JSONL truncation again prevents automated verification of one ID.
|
||||
|
||||
The initial grader treated grouped path records, extra known coverage counts and
|
||||
an empty per-source contradiction object as mismatches. Task-specific comparison
|
||||
now accepts those lossless report forms. Firmware compares observed offset/length
|
||||
facts, checks any supplied derived end arithmetically, and verifies engine version
|
||||
and executable digest. Run-local UUIDs and differently named display fields are
|
||||
not compared as if they were stable source identity. Original strict grades and
|
||||
pre-equivalence grades remain outside Git, and new grades include a grader digest.
|
||||
These report-format comparisons do not add aliases to any REA tool contract.
|
||||
|
||||
Obsidian bridge discovery takes six searches and two executions. The first returns
|
||||
the entire nested inventory; the second repeats it and computes a focused answer.
|
||||
The live nested Evidence schema describes normalized_result as generic JSON, so
|
||||
derived types alone cannot teach its concrete manifest/occurrences layout. Its
|
||||
recursive record walk happens to match this corpus, but format-specific field
|
||||
selection is the stronger recipe. Both model profiles choose record-and-continue
|
||||
for integrity; deterministic inventory replays used fail. No contradictions were
|
||||
observed, and the exact caller-selected arguments are retained.
|
||||
|
||||
## Completed serial cohort
|
||||
|
||||
The final sixteen-row cohort, raw-event digests, exact runner/bridge/lockfile
|
||||
fingerprints, prompt/instruction/provider digests and sampled resource stats are
|
||||
in [agent-results.json](agent-results.json). The requested model configuration is
|
||||
Terra high. Two managed bridge answers omit the classification container field
|
||||
under the stronger full-object check; two normal-MCP managed logs have a truncated
|
||||
producer envelope. The twelve other rows pass requested fact and observed-reference
|
||||
checks. This is producer parity, not independent runtime truth or a per-fact
|
||||
citation-association proof. Earlier stricter report-form grades remain retained.
|
||||
|
||||
| Trial | Wall seconds | Input | Cached | Uncached | Output | MCP calls | Check |
|
||||
| ---------------------------------- | -----------: | -----: | -----: | -------: | -----: | --------: | --------------------------------- |
|
||||
| android-direct-5 | 67.329 | 107007 | 83712 | 23295 | 1670 | 3 | pass |
|
||||
| android-bridge-7 | 48.231 | 113256 | 91648 | 21608 | 1456 | 3 | pass |
|
||||
| managed-bridge-2 | 73.145 | 116974 | 92672 | 24302 | 2065 | 3 | classification container omitted |
|
||||
| managed-direct-2 | 33.150 | 108096 | 75776 | 32320 | 2315 | 2 | facts match; reference unverified |
|
||||
| electron-inventory-direct-1 | 89.494 | 266121 | 238848 | 27273 | 3215 | 3 | pass |
|
||||
| electron-inventory-bridge-1 | 145.577 | 462809 | 407040 | 55769 | 5624 | 8 | pass |
|
||||
| firmware-bridge-1 | 81.944 | 152886 | 126976 | 25910 | 2192 | 3 | pass |
|
||||
| firmware-direct-1 | 30.161 | 103224 | 74752 | 28472 | 1761 | 1 | pass |
|
||||
| native-direct-1 | 327.150 | 151343 | 122368 | 28975 | 2458 | 4 | pass |
|
||||
| native-bridge-1 | 334.642 | 285961 | 245504 | 40457 | 2129 | 4 | pass |
|
||||
| android-bridge-8 | 134.555 | 159370 | 134400 | 24970 | 3250 | 7 | pass |
|
||||
| android-direct-6 | 71.624 | 153031 | 117504 | 35527 | 1501 | 3 | pass |
|
||||
| managed-direct-3 | 75.229 | 108593 | 75776 | 32817 | 2774 | 2 | facts match; reference unverified |
|
||||
| managed-bridge-3 | 40.609 | 125519 | 96000 | 29519 | 2274 | 3 | classification container omitted |
|
||||
| electron-inventory-guided-bridge-1 | 85.909 | 101994 | 61440 | 40554 | 2563 | 3 | pass |
|
||||
| electron-inventory-guided-direct-1 | 67.540 | 263484 | 221952 | 41532 | 2499 | 4 | pass |
|
||||
|
||||
Ghidra's aggregate sampled CPU time is 263.738 seconds directly and 271.096 with
|
||||
the bridge. The bridge uses three original operations versus four directly,
|
||||
obtaining containing identity from the analyzed procedure. Both close the session
|
||||
successfully. The native comparison uses the same default analysis settings;
|
||||
these data do not establish a meaningful native speedup.
|
||||
|
||||
The second Android bridge repetition completes seven original calls across five
|
||||
scripts, without tool errors, before its final composed answer. Its 134.555-second
|
||||
result reverses the first repetition's latency advantage. The model did not
|
||||
reliably choose one composed execution even with explicit guidance. Uncached
|
||||
input is lower in both bridge repetitions, while output and latency vary.
|
||||
|
||||
The guided Electron question explicitly names the existing operations and the
|
||||
nested inventory's manifest/occurrences layout for both profiles. Both pass, with
|
||||
integrity_policy=fail. The bridge composes open/inspect/close once; the normal-MCP
|
||||
profile repeats inspect_artifact. The total-input reduction from 263484 to 101994
|
||||
is large, but uncached input differs by only 978 tokens and bridge latency is
|
||||
higher. Earlier non-guided profiles are a different question and cannot support
|
||||
a causal prompt-improvement ratio. Unknown nested payload types remain an observed
|
||||
contract-discovery problem; caller-selected values and identities are preserved.
|
||||
|
||||
All sixteen runs stay below memory/task ceilings, with maximum sampled memory
|
||||
1659744256 bytes and 126 tasks; no observed memory/task limit event or resource
|
||||
abort occurs. Copied profile count is zero at completion. Runtime measurements
|
||||
belong to the recorded source fingerprint at 22326e819; subsequent timer-range
|
||||
validation and test-only Ajv installation are not new model measurements.
|
||||
|
||||
Final boundary verification passes twelve actual SDK/stdio tests. A 2 MiB guest
|
||||
budget rejects allocation pressure and the next execution succeeds. This is a
|
||||
guest-budget failure, not an OS OOM or provider behavior claim. A local pinned-Node
|
||||
probe shows a 2147483648-ms timeout becomes 1 ms; the owning named execution
|
||||
contract now rejects that range before allocation. After SDK conversion, both
|
||||
advertised bridge input schemas validate under JSON Schema 2020-12, and the actual
|
||||
stdio client rejects invalid code, oversized memory and timer values. Sampled
|
||||
suite memory peaks at 1387433984 bytes, with zero observed memory/task limit events.
|
||||
|
||||
See [decision.md](decision.md) for the recommendation: keep current REA contracts,
|
||||
improve focused Evidence-aware workflow guidance, and retain the bridge as an
|
||||
opt-in candidate. A broad default switch is not justified by these samples.
|
||||
@@ -55,7 +55,6 @@
|
||||
"bridge/ghidra/ReaGhidraPrepareCom.java",
|
||||
"bridge/ghidra/ReaGhidraApplySeeds.java",
|
||||
"bridge/ghidra/ReaGhidraNoReturnFix.java",
|
||||
"bridge/ghidra/ReaGhidraPrepareRaw.java",
|
||||
"bridge/android/ReaJadxBridge.java",
|
||||
"bridge/mitmproxy/capture.py",
|
||||
"scripts/rea.mjs",
|
||||
@@ -167,7 +166,6 @@
|
||||
"verify:ghidra:switch": "npm run build:cached && node scripts/verify-real-ghidra-switch.mjs",
|
||||
"verify:ghidra:dos": "npm run build:cached && node scripts/verify-real-ghidra-dos.mjs",
|
||||
"verify:ghidra:com": "npm run build:cached && node scripts/verify-real-ghidra-com.mjs",
|
||||
"verify:ghidra:raw": "npm run build:cached && node scripts/verify-real-ghidra-raw.mjs",
|
||||
"verify:ghidra:aarch64-jump-table": "npm run build:cached && node scripts/verify-real-ghidra.mjs --aarch64-jump-table",
|
||||
"verify:interface-builder": "npm run build:cached && node scripts/verify/apple/interface-builder.mjs",
|
||||
"verify:ghidra:cross-format": "npm run build:cached && node scripts/verify-real-ghidra.mjs --cross-format",
|
||||
|
||||
@@ -177,7 +177,6 @@ const scriptCollisions = [
|
||||
"ReaGhidraPrepareCom.java",
|
||||
"ReaGhidraApplySeeds.java",
|
||||
"ReaGhidraNoReturnFix.java",
|
||||
"ReaGhidraPrepareRaw.java",
|
||||
];
|
||||
await mkdir(callerDirectory);
|
||||
for (const name of scriptCollisions) await mkdir(join(callerDirectory, name));
|
||||
@@ -395,15 +394,15 @@ try {
|
||||
return evidence.normalized_result;
|
||||
},
|
||||
);
|
||||
const { GHIDRA_MUTATING_OPERATIONS, GHIDRA_SESSION_CAPABILITIES } =
|
||||
const expected = (
|
||||
await import(
|
||||
pathToFileURL(join(packageRoot, "dist/ghidra/GhidraSessionValues.js"))
|
||||
);
|
||||
const expected = GHIDRA_SESSION_CAPABILITIES.filter(
|
||||
)
|
||||
).GHIDRA_SESSION_CAPABILITIES.filter(
|
||||
(name) =>
|
||||
name !== "ping" &&
|
||||
name !== "shutdown" &&
|
||||
!GHIDRA_MUTATING_OPERATIONS.has(name),
|
||||
name !== "annotate_native_function",
|
||||
);
|
||||
assert.ok(
|
||||
expected.every((name) => report.mcpOperations.includes(name)),
|
||||
@@ -441,10 +440,7 @@ try {
|
||||
token,
|
||||
"Analysis changed caller token authority.",
|
||||
);
|
||||
assert.deepEqual(
|
||||
(await readdir(callerDirectory)).sort(),
|
||||
[...scriptCollisions].sort(),
|
||||
);
|
||||
assert.deepEqual((await readdir(callerDirectory)).sort(), scriptCollisions);
|
||||
for (const name of scriptCollisions)
|
||||
assert.deepEqual(await readdir(join(callerDirectory, name)), []);
|
||||
report.callerScriptCollisionsPreserved = true;
|
||||
|
||||
@@ -1,219 +0,0 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
|
||||
import { parseEvidence } from "../dist/domain/evidence.js";
|
||||
import { inspectGhidraInstallation } from "../dist/ghidra/GhidraInstallation.js";
|
||||
import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs";
|
||||
import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
if (process.argv.length !== 2)
|
||||
throw new Error("Usage: node scripts/verify-real-ghidra-raw.mjs");
|
||||
if (!["linux", "darwin"].includes(process.platform))
|
||||
throw new Error(
|
||||
"Raw-binary verification requires a Linux or macOS Ghidra host.",
|
||||
);
|
||||
if (process.env.GHIDRA_INSTALL_DIR === undefined)
|
||||
throw new Error(
|
||||
"Set GHIDRA_INSTALL_DIR to a bring-your-own Ghidra installation.",
|
||||
);
|
||||
const installation = inspectGhidraInstallation({
|
||||
environment: process.env,
|
||||
installDir: process.env.GHIDRA_INSTALL_DIR,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
: { javaHome: process.env.JAVA_HOME }),
|
||||
});
|
||||
assert.equal(installation.status, "available", JSON.stringify(installation));
|
||||
|
||||
const run = createVerifierRun();
|
||||
const workspace = await mkdtemp(join(tmpdir(), "rea-raw-proof-"));
|
||||
const runtime = join(workspace, "runtime");
|
||||
await mkdir(runtime);
|
||||
const bytes = Buffer.from("1eff2fe1", "hex"); // ARM little-endian bx lr.
|
||||
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
||||
const path = join(workspace, "image.bin");
|
||||
await writeFile(path, bytes);
|
||||
const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url));
|
||||
const env = {
|
||||
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
||||
TMPDIR: runtime,
|
||||
REA_LOG_LEVEL: "silent",
|
||||
REA_ANALYSIS_PROVIDER: "ghidra",
|
||||
REA_PROCESS_RUN_ID: run.run_id,
|
||||
GHIDRA_INSTALL_DIR: process.env.GHIDRA_INSTALL_DIR,
|
||||
...(process.env.JAVA_HOME === undefined
|
||||
? {}
|
||||
: { JAVA_HOME: process.env.JAVA_HOME }),
|
||||
};
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
env,
|
||||
stderr: "pipe",
|
||||
});
|
||||
const client = new Client({ name: "rea-real-raw-proof", version: "1" });
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", (chunk) => {
|
||||
stderr = (stderr + chunk.toString()).slice(-65536);
|
||||
});
|
||||
let report;
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const profiles = [];
|
||||
const sessions = [];
|
||||
for (const entryPoint of ["0x08000000", "0x8000000", "0x09000000"]) {
|
||||
// Omit provider_id to exercise reuse of the current provider route.
|
||||
const opened = await call("open_binary", {
|
||||
path,
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
entry_point: entryPoint,
|
||||
});
|
||||
const entry = `0x${BigInt(entryPoint).toString(16)}`;
|
||||
assert.equal(opened.entry_point, entry);
|
||||
const image = await call("inspect_native_load_image");
|
||||
assert.equal(
|
||||
image.normalized_result.status,
|
||||
"verified",
|
||||
JSON.stringify(image),
|
||||
);
|
||||
assert.equal(image.normalized_result.base_address, entry);
|
||||
assert.equal(image.normalized_result.entry.address, entry);
|
||||
assert.equal(
|
||||
image.normalized_result.observations.language_id,
|
||||
"ARM:LE:32:v7",
|
||||
);
|
||||
assert.ok(
|
||||
image.normalized_result.observations.entry_points.includes(entry),
|
||||
);
|
||||
assert.equal(image.analysis_profile.parameters.entry_point, entry);
|
||||
profiles.push(image.analysis_profile.digest);
|
||||
const status = await call("binary_session");
|
||||
assert.equal(status.entry_point, entry);
|
||||
sessions.push(status.analysis_run.run_id);
|
||||
const memory = await call("read_bytes", {
|
||||
address: entry,
|
||||
length: bytes.length,
|
||||
});
|
||||
assert.equal(memory.normalized_result.bytes_hex, bytes.toString("hex"));
|
||||
const procedures = await call("list_procedures");
|
||||
assert.ok(
|
||||
procedures.normalized_result.some(
|
||||
(procedure) => procedure.address === entry,
|
||||
),
|
||||
);
|
||||
const instruction = await call("inspect_native_instruction", {
|
||||
address: entry,
|
||||
});
|
||||
assert.equal(instruction.normalized_result.address, entry);
|
||||
}
|
||||
assert.equal(profiles[0], profiles[1]);
|
||||
assert.notEqual(profiles[1], profiles[2]);
|
||||
assert.equal(sessions[0], sessions[1]);
|
||||
assert.notEqual(sessions[1], sessions[2]);
|
||||
const rejected = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: {
|
||||
path,
|
||||
format: "raw-binary",
|
||||
architecture: "arm64",
|
||||
entry_point: "0x8000001",
|
||||
},
|
||||
});
|
||||
assert.equal(rejected.isError, true);
|
||||
assert.match(JSON.stringify(rejected.content), /must be 4-byte aligned/);
|
||||
const unchanged = await call("binary_session");
|
||||
assert.equal(unchanged.analysis_run.run_id, sessions[2]);
|
||||
assert.equal(unchanged.entry_point, "0x9000000");
|
||||
await call("close_binary");
|
||||
|
||||
const { stdout } = await promisify(execFile)(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"inspect-native-load-image",
|
||||
path,
|
||||
"--target-format",
|
||||
"raw-binary",
|
||||
"--architecture",
|
||||
"arm",
|
||||
"--entry-point",
|
||||
"0x08000000",
|
||||
"--provider",
|
||||
"ghidra",
|
||||
"--json",
|
||||
],
|
||||
{ env, timeout: 240000, maxBuffer: 16 * 1024 * 1024 },
|
||||
);
|
||||
const cli = parseEvidence(JSON.parse(stdout));
|
||||
assert.equal(cli.subject.digest.sha256, sha256);
|
||||
assert.equal(cli.normalized_result.status, "verified");
|
||||
assert.equal(cli.normalized_result.base_address, "0x8000000");
|
||||
assert.equal(cli.analysis_profile.digest, profiles[0]);
|
||||
assert.deepEqual(await readFile(path), bytes);
|
||||
report = {
|
||||
ok: true,
|
||||
mocked: false,
|
||||
lane: "ghidra-raw",
|
||||
host: process.platform,
|
||||
provider: { id: "ghidra", version: installation.providerVersion },
|
||||
target: {
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
sha256,
|
||||
bytes: bytes.length,
|
||||
},
|
||||
transport: { cli: true, stdio_mcp: true },
|
||||
canonical_entry_reuses_session: true,
|
||||
changed_entry_replaces_session: true,
|
||||
lifecycle_entry_preserved: true,
|
||||
invalid_entry_preserves_active_session: true,
|
||||
load_images_verified: true,
|
||||
original_unchanged: true,
|
||||
};
|
||||
} catch (error) {
|
||||
if (stderr.trim()) process.stderr.write(stderr);
|
||||
throw error;
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
await rm(workspace, { recursive: true, force: true });
|
||||
}
|
||||
const verifierRun = await completeVerifierRun(run);
|
||||
assert.equal(verifierRun.process_lineage.status, "verified");
|
||||
assert.deepEqual(verifierRun.process_lineage.descendants, []);
|
||||
process.stdout.write(
|
||||
JSON.stringify({
|
||||
verifier_run: verifierRun,
|
||||
...report,
|
||||
cleanup: "complete",
|
||||
}) + "\n",
|
||||
);
|
||||
|
||||
async function call(name, args = {}) {
|
||||
const result = await client.callTool(
|
||||
{ name, arguments: args },
|
||||
{ timeout: 240000 },
|
||||
);
|
||||
assert.notEqual(result.isError, true, JSON.stringify(result));
|
||||
const projected = requireMcpOperationResult(result, name);
|
||||
if (
|
||||
name === "open_binary" ||
|
||||
name === "close_binary" ||
|
||||
name === "binary_session"
|
||||
)
|
||||
return projected;
|
||||
const evidence = parseEvidence(result.structuredContent);
|
||||
assert.equal(evidence.subject.digest.sha256, sha256);
|
||||
assert.equal(evidence.subject.format, "raw-binary");
|
||||
return evidence;
|
||||
}
|
||||
@@ -21,17 +21,14 @@ import { SUPPORTED_GHIDRA_VERSION } from "../dist/ghidra/GhidraInstallationPolic
|
||||
import { GhidraHeadlessLauncher } from "../dist/ghidra/GhidraLauncher.js";
|
||||
import { GHIDRA_PROVIDER_IDENTITY } from "../dist/ghidra/GhidraProviderCapabilities.js";
|
||||
import { windowsP0Capabilities } from "../dist/ghidra/GhidraProviderCapabilities.js";
|
||||
import {
|
||||
GHIDRA_MUTATING_OPERATIONS,
|
||||
GHIDRA_SESSION_CAPABILITIES,
|
||||
} from "../dist/ghidra/GhidraSessionValues.js";
|
||||
import { GHIDRA_SESSION_CAPABILITIES } from "../dist/ghidra/GhidraSessionValues.js";
|
||||
import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js";
|
||||
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
|
||||
import { verifyGhidraCompactReferences } from "./lib/real-ghidra-compact-references.mjs";
|
||||
|
||||
const verifierRun = createVerifierRun();
|
||||
const SESSION_CAPABILITIES = GHIDRA_SESSION_CAPABILITIES.filter(
|
||||
(name) => !GHIDRA_MUTATING_OPERATIONS.has(name),
|
||||
(name) => name !== "annotate_native_function",
|
||||
);
|
||||
|
||||
if (process.platform !== "win32" || process.arch !== "x64")
|
||||
@@ -239,8 +236,10 @@ try {
|
||||
|
||||
const expected = [
|
||||
...GHIDRA_INVENTORY_OPERATIONS,
|
||||
...GHIDRA_FUNCTION_OPERATIONS,
|
||||
].filter((name) => !GHIDRA_MUTATING_OPERATIONS.has(name));
|
||||
...GHIDRA_FUNCTION_OPERATIONS.filter(
|
||||
(name) => name !== "annotate_native_function",
|
||||
),
|
||||
];
|
||||
if (
|
||||
observed.size !== expected.length ||
|
||||
expected.some((operation) => !observed.has(operation))
|
||||
|
||||
@@ -7,16 +7,13 @@ import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { parseEvidence } from "../../../dist/domain/evidence.js";
|
||||
import { hashAndroidFile } from "./digest.mjs";
|
||||
import { hashAndroidFile } from "../../../dist/android/AndroidTargetSnapshot.js";
|
||||
import { JADX_RELEASE } from "../../../dist/android/JadxRelease.js";
|
||||
import fixture from "../../fixtures/android/apidemos.json" with { type: "json" };
|
||||
import { verifyAndroidCliCancellation } from "./cli-cancellation.mjs";
|
||||
import { verifyAndroidMetadata } from "./metadata.mjs";
|
||||
import { verifyAndroidFailureRecovery } from "./failure-recovery.mjs";
|
||||
import {
|
||||
resolveJadxConfigurationInputs,
|
||||
validateJadxConfiguration,
|
||||
} from "../../../dist/android/JadxConfiguration.js";
|
||||
import { resolveJadxConfiguration } from "../../../dist/android/JadxConfiguration.js";
|
||||
import { verifyWindowsAndroidLifecycle } from "./windows-lifecycle.mjs";
|
||||
|
||||
const repository = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
|
||||
@@ -38,16 +35,10 @@ assert.equal(
|
||||
JADX_RELEASE.sha256,
|
||||
"Real Android lane requires the audited headless JADX release JAR",
|
||||
);
|
||||
const configuration = await resolveJadxConfigurationInputs(
|
||||
const { java, jvmArguments } = await resolveJadxConfiguration(
|
||||
process.env,
|
||||
"inspect_android_package",
|
||||
);
|
||||
await validateJadxConfiguration(
|
||||
configuration,
|
||||
process.env,
|
||||
"inspect_android_package",
|
||||
);
|
||||
const { java, jvmArguments } = configuration;
|
||||
const execute = promisify(execFile);
|
||||
await execute(java, ["-version"], { timeout: 10_000 });
|
||||
const entrypoint =
|
||||
@@ -61,8 +52,6 @@ await verifyAndroidMetadata({
|
||||
repository,
|
||||
execute,
|
||||
jvmArguments,
|
||||
entrypoint,
|
||||
environment,
|
||||
bridge: resolve(dirname(entrypoint), "../bridge/android/ReaJadxBridge.java"),
|
||||
});
|
||||
const tasks = [
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { createReadStream } from "node:fs";
|
||||
|
||||
/** Verify artifact identity without depending on private runtime snapshot helpers. */
|
||||
export const hashAndroidFile = async (path) => {
|
||||
const hash = createHash("sha256");
|
||||
for await (const bytes of createReadStream(path)) hash.update(bytes);
|
||||
return hash.digest("hex");
|
||||
};
|
||||
@@ -1,130 +0,0 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { parseEvidence } from "../../../dist/domain/evidence.js";
|
||||
import { hashAndroidFile } from "./digest.mjs";
|
||||
|
||||
/** Verify folded field assignments and remaining static-block calls through both public adapters. */
|
||||
export const verifyAndroidInitializers = async ({
|
||||
apk,
|
||||
repository,
|
||||
entrypoint,
|
||||
environment,
|
||||
execute,
|
||||
}) => {
|
||||
const digest = await hashAndroidFile(apk);
|
||||
const cases = [
|
||||
{
|
||||
class_name: "fixture.InitializationPolicy",
|
||||
witnesses: [
|
||||
"declared-policy",
|
||||
"->singletonList",
|
||||
"->POLICY:Ljava/util/List;",
|
||||
],
|
||||
},
|
||||
{
|
||||
class_name: "fixture.MixedInitialization",
|
||||
witnesses: ["field-value", "->LABEL:Ljava/lang/String;", "->touch()V"],
|
||||
},
|
||||
];
|
||||
const check = (value, scenario) => {
|
||||
const evidence = parseEvidence(value);
|
||||
assert.equal(evidence.subject.digest.sha256, digest);
|
||||
const result = evidence.normalized_result;
|
||||
assert.equal(result.class_name, scenario.class_name);
|
||||
assert.equal(result.method.name, "<clinit>");
|
||||
assert.equal(result.overload_count, 1);
|
||||
assert.equal(result.body_status, "available");
|
||||
assert.equal(result.representation, "smali");
|
||||
assert.equal(result.fell_back, true);
|
||||
assert.ok(result.markers.includes("static_initializer_disassembly"));
|
||||
assert.equal(result.source.status, "complete");
|
||||
for (const witness of scenario.witnesses)
|
||||
assert.ok(
|
||||
result.source.text.includes(witness),
|
||||
`Missing initializer evidence: ${witness}`,
|
||||
);
|
||||
return evidence;
|
||||
};
|
||||
const cli = new Map();
|
||||
for (const scenario of cases) {
|
||||
const response = await execute(
|
||||
process.execPath,
|
||||
[
|
||||
entrypoint,
|
||||
"inspect-android-method",
|
||||
apk,
|
||||
scenario.class_name,
|
||||
"<clinit>",
|
||||
"--format",
|
||||
"json",
|
||||
],
|
||||
{
|
||||
cwd: repository,
|
||||
env: environment,
|
||||
timeout: 150_000,
|
||||
maxBuffer: 8 * 1024 * 1024,
|
||||
},
|
||||
);
|
||||
cli.set(scenario.class_name, check(JSON.parse(response.stdout), scenario));
|
||||
}
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [entrypoint, "mcp"],
|
||||
cwd: repository,
|
||||
env: environment,
|
||||
stderr: "pipe",
|
||||
});
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", (chunk) => {
|
||||
stderr += chunk.toString();
|
||||
});
|
||||
const client = new Client({
|
||||
name: "rea-real-android-initializers",
|
||||
version: "1",
|
||||
});
|
||||
try {
|
||||
await client.connect(transport, { timeout: 30_000 });
|
||||
for (const scenario of cases) {
|
||||
const response = await client.callTool(
|
||||
{
|
||||
name: "inspect_android_method",
|
||||
arguments: {
|
||||
path: apk,
|
||||
class_name: scenario.class_name,
|
||||
method_name: "<clinit>",
|
||||
},
|
||||
},
|
||||
{ timeout: 150_000 },
|
||||
);
|
||||
assert.notEqual(response.isError, true, JSON.stringify(response));
|
||||
const evidence = check(response.structuredContent, scenario);
|
||||
assert.deepEqual(
|
||||
evidence.normalized_result,
|
||||
cli.get(scenario.class_name).normalized_result,
|
||||
);
|
||||
assert.deepEqual(
|
||||
evidence.parameters,
|
||||
cli.get(scenario.class_name).parameters,
|
||||
);
|
||||
assert.deepEqual(
|
||||
evidence.provider,
|
||||
cli.get(scenario.class_name).provider,
|
||||
);
|
||||
}
|
||||
await client.ping();
|
||||
} catch (cause) {
|
||||
process.stderr.write(stderr);
|
||||
throw cause;
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
assert.equal(
|
||||
await hashAndroidFile(apk),
|
||||
digest,
|
||||
"Static inspection changed fixture bytes",
|
||||
);
|
||||
console.log(
|
||||
"PASS real CLI/MCP static initializer evidence, identity, parity and unchanged APK",
|
||||
);
|
||||
};
|
||||
@@ -2,7 +2,6 @@ import assert from "node:assert/strict";
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { delimiter, join, resolve } from "node:path";
|
||||
import { verifyAndroidInitializers } from "./initializers.mjs";
|
||||
|
||||
/** Prove cold metadata stays unmaterialized and overload identities survive code generation. */
|
||||
export const verifyAndroidMetadata = async ({
|
||||
@@ -12,8 +11,6 @@ export const verifyAndroidMetadata = async ({
|
||||
bridge,
|
||||
repository,
|
||||
execute,
|
||||
entrypoint,
|
||||
environment,
|
||||
jvmArguments = [],
|
||||
}) => {
|
||||
const javac =
|
||||
@@ -58,8 +55,6 @@ export const verifyAndroidMetadata = async ({
|
||||
`${classes}${delimiter}${jar}`,
|
||||
"ReaJadxMetadataRegression",
|
||||
apk,
|
||||
resolve(repository, "tests/fixtures/android/static-initializers"),
|
||||
classes,
|
||||
],
|
||||
{ timeout: 120_000, maxBuffer: 8 * 1024 * 1024 },
|
||||
);
|
||||
@@ -67,23 +62,9 @@ export const verifyAndroidMetadata = async ({
|
||||
result.stdout,
|
||||
/METADATA_REGRESSION_PASS classes=\d+ overloads=3/u,
|
||||
);
|
||||
assert.match(
|
||||
result.stdout,
|
||||
/INITIALIZER_REGRESSION_PASS folded=2 bounded=true/u,
|
||||
);
|
||||
console.log(
|
||||
"PASS real cold metadata, full generic types and stable overloaded method selection",
|
||||
);
|
||||
console.log(
|
||||
"PASS real folded and mixed static initializers, absent bodies and bounded smali",
|
||||
);
|
||||
await verifyAndroidInitializers({
|
||||
apk: resolve(classes, "initializers.apk"),
|
||||
repository,
|
||||
entrypoint,
|
||||
environment,
|
||||
execute,
|
||||
});
|
||||
} finally {
|
||||
await rm(classes, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ import { dirname, join } from "node:path";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import {
|
||||
resolveJadxConfigurationInputs,
|
||||
validateJadxConfiguration,
|
||||
} from "../../../dist/android/JadxConfiguration.js";
|
||||
import { resolveJadxConfiguration } from "../../../dist/android/JadxConfiguration.js";
|
||||
|
||||
/** Verify real Windows cancellation, disconnect and abrupt CLI owner exit. */
|
||||
export async function verifyWindowsAndroidLifecycle(options) {
|
||||
@@ -39,12 +36,7 @@ export async function verifyWindowsAndroidLifecycle(options) {
|
||||
}
|
||||
|
||||
async function verifyJavaSelection(environment) {
|
||||
const selected = await resolveJadxConfigurationInputs(
|
||||
environment,
|
||||
"inspect_android_package",
|
||||
);
|
||||
await validateJadxConfiguration(
|
||||
selected,
|
||||
const selected = await resolveJadxConfiguration(
|
||||
environment,
|
||||
"inspect_android_package",
|
||||
);
|
||||
@@ -59,12 +51,7 @@ async function verifyJavaSelection(environment) {
|
||||
// The owned junction borrows the selected JDK directory without copying it.
|
||||
await symlink(dirname(selected.java), alias, "junction");
|
||||
pathEnvironment.Path = `"${alias}"`;
|
||||
const onPath = await resolveJadxConfigurationInputs(
|
||||
pathEnvironment,
|
||||
"inspect_android_package",
|
||||
);
|
||||
await validateJadxConfiguration(
|
||||
onPath,
|
||||
const onPath = await resolveJadxConfiguration(
|
||||
pathEnvironment,
|
||||
"inspect_android_package",
|
||||
);
|
||||
|
||||
@@ -26,8 +26,6 @@ import {
|
||||
validateDosComLength,
|
||||
type ExecutableFormatHint,
|
||||
} from "../domain/dosCom.js";
|
||||
import { admitRawBinary } from "../domain/rawBinary.js";
|
||||
import type { BinaryArchitecture } from "../domain/binaryTargetTypes.js";
|
||||
import { mzWindowsHeaderOffset } from "../domain/dosMz.js";
|
||||
import {
|
||||
hasZipSignature,
|
||||
@@ -47,8 +45,6 @@ export interface BinaryTargetResolverOptions {
|
||||
readonly hostArchitecture?: NodeJS.Architecture;
|
||||
readonly targetKind?: BinaryTarget["kind"];
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
readonly signal?: AbortSignal;
|
||||
}
|
||||
|
||||
@@ -65,7 +61,7 @@ export const parseBinaryTarget = async (
|
||||
> => {
|
||||
const cwd = options.cwd ?? process.cwd();
|
||||
const hostArchitecture = options.hostArchitecture ?? process.arch;
|
||||
const { targetKind, formatHint, signal, architecture, entryPoint } = options;
|
||||
const { targetKind, formatHint, signal } = options;
|
||||
const candidate = isAbsolute(input) ? input : resolve(cwd, input);
|
||||
try {
|
||||
throwIfTargetResolutionCancelled(signal);
|
||||
@@ -87,40 +83,6 @@ export const parseBinaryTarget = async (
|
||||
throwIfTargetResolutionCancelled(signal);
|
||||
const metadata = await handle.stat();
|
||||
throwIfTargetResolutionCancelled(signal);
|
||||
if (formatHint === "raw-binary") {
|
||||
if (targetKind !== undefined && targetKind !== "executable")
|
||||
return err(
|
||||
new BinaryTargetError(
|
||||
path,
|
||||
"raw-binary format requires an executable target kind",
|
||||
),
|
||||
);
|
||||
const admitted = admitRawBinary({
|
||||
architecture,
|
||||
entryPoint,
|
||||
fileBytes: metadata.size,
|
||||
});
|
||||
if (!admitted.ok)
|
||||
return err(new BinaryTargetError(path, admitted.error));
|
||||
return ok({
|
||||
path,
|
||||
sourcePath: canonical,
|
||||
sha256: await sha256Handle(handle, path, metadata, signal),
|
||||
kind: "executable",
|
||||
format: "raw-binary",
|
||||
architecture: admitted.value.architecture,
|
||||
availableArchitectures: [admitted.value.architecture],
|
||||
entryPoint: admitted.value.entryPoint,
|
||||
entryPointSource: admitted.value.entryPointSource,
|
||||
});
|
||||
}
|
||||
if (architecture !== undefined || entryPoint !== undefined)
|
||||
return err(
|
||||
new BinaryTargetError(
|
||||
path,
|
||||
"architecture and entry_point apply only with format=raw-binary",
|
||||
),
|
||||
);
|
||||
if (formatHint === "dos-com") {
|
||||
if (targetKind !== undefined && targetKind !== "executable")
|
||||
return err(
|
||||
@@ -232,13 +194,7 @@ const detectArtifactFormat = async (
|
||||
): Promise<
|
||||
| Exclude<
|
||||
BinaryTarget["format"],
|
||||
| "analysis-database"
|
||||
| "mach-o"
|
||||
| "elf"
|
||||
| "pe"
|
||||
| "dos-mz"
|
||||
| "dos-com"
|
||||
| "raw-binary"
|
||||
"analysis-database" | "mach-o" | "elf" | "pe" | "dos-mz" | "dos-com"
|
||||
>
|
||||
| undefined
|
||||
> => {
|
||||
@@ -288,13 +244,7 @@ const namedArtifactFormat = (
|
||||
const isArchiveFormat = (
|
||||
format: Exclude<
|
||||
BinaryTarget["format"],
|
||||
| "analysis-database"
|
||||
| "mach-o"
|
||||
| "elf"
|
||||
| "pe"
|
||||
| "dos-mz"
|
||||
| "dos-com"
|
||||
| "raw-binary"
|
||||
"analysis-database" | "mach-o" | "elf" | "pe" | "dos-mz" | "dos-com"
|
||||
>,
|
||||
): format is Extract<BinaryTarget, { kind: "archive" }>["format"] =>
|
||||
isZipPackageFormat(format) || ["asar", "dmg", "pkg"].includes(format);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { ExecutableFormatHint } from "../domain/dosCom.js";
|
||||
import type { BinaryArchitecture } from "../domain/binaryTargetTypes.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import type { DirectAnalysisDependencies } from "./DirectAnalysisDependencies.js";
|
||||
import type { BinarySession } from "./binary/BinarySession.js";
|
||||
@@ -92,8 +91,6 @@ export const runDirectAnalysis = async (
|
||||
readonly signal?: AbortSignal;
|
||||
readonly providerId?: AnalysisProviderSelector;
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
} = {},
|
||||
): Promise<JsonValue> =>
|
||||
withProcessCancellation(options.signal, (signal) =>
|
||||
@@ -104,12 +101,6 @@ export const runDirectAnalysis = async (
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
...(options.providerId === undefined
|
||||
? {}
|
||||
: { providerId: options.providerId }),
|
||||
@@ -196,8 +187,6 @@ const runAnalysis = async (
|
||||
readonly signal: AbortSignal;
|
||||
readonly providerId?: AnalysisProviderSelector;
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
},
|
||||
): Promise<JsonValue> => {
|
||||
const { logger, signal, snapshotPath } = options;
|
||||
@@ -214,12 +203,6 @@ const runAnalysis = async (
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
});
|
||||
if (!prepared.ok) return cliError(prepared.error);
|
||||
const { snapshot } = prepared.value;
|
||||
@@ -231,12 +214,6 @@ const runAnalysis = async (
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
...(options.providerId === undefined
|
||||
? {}
|
||||
: { providerId: options.providerId }),
|
||||
@@ -269,12 +246,6 @@ const runAnalysis = async (
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
...(snapshot === undefined ? {} : { snapshot }),
|
||||
...(options.providerId === undefined
|
||||
? {}
|
||||
@@ -469,8 +440,6 @@ const withProcessCancellation = async <Value>(
|
||||
const prepareSnapshot = async (options: {
|
||||
readonly path: string;
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
readonly snapshotPath: string | undefined;
|
||||
readonly signal: AbortSignal;
|
||||
}): Promise<
|
||||
@@ -489,12 +458,6 @@ const prepareSnapshot = async (options: {
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
});
|
||||
if (!target.ok) return target;
|
||||
if (!snapshotMatchesTarget(loaded.value.target, target.value))
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { ExecutableFormatHint } from "../../domain/dosCom.js";
|
||||
import type { BinaryArchitecture } from "../../domain/binaryTargetTypes.js";
|
||||
import type { AnalysisProviderSelector } from "../../contracts/providerSelection.js";
|
||||
import type { AnalysisProfileCommitment } from "../../domain/analysisProfile.js";
|
||||
import {
|
||||
@@ -23,8 +22,6 @@ export interface BinarySessionOpenOptions {
|
||||
readonly signal?: AbortSignal;
|
||||
readonly targetKind?: BinaryTarget["kind"];
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
readonly snapshot?: AnalysisSnapshot;
|
||||
readonly providerId?: AnalysisProviderSelector;
|
||||
}
|
||||
@@ -75,12 +72,6 @@ export const resolveSessionOpen = async (
|
||||
...(options.formatHint === undefined
|
||||
? {}
|
||||
: { formatHint: options.formatHint }),
|
||||
...(options.architecture === undefined
|
||||
? {}
|
||||
: { architecture: options.architecture }),
|
||||
...(options.entryPoint === undefined
|
||||
? {}
|
||||
: { entryPoint: options.entryPoint }),
|
||||
...(options.signal === undefined ? {} : { signal: options.signal }),
|
||||
});
|
||||
if (!parsed.ok) return parsed;
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import type { InvestigationRecordPort } from "../investigation/InvestigationRecordPort.js";
|
||||
import type { ExecutableFormatHint } from "../../domain/dosCom.js";
|
||||
import type {
|
||||
BinaryArchitecture,
|
||||
BinaryTarget,
|
||||
} from "../../domain/binaryTargetTypes.js";
|
||||
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
||||
import type { AnalysisSnapshot } from "../../domain/analysisSnapshot.js";
|
||||
import type { AnalysisProfileCommitment } from "../../domain/analysisProfile.js";
|
||||
@@ -47,8 +44,6 @@ export interface BinarySessionPort
|
||||
readonly signal?: AbortSignal;
|
||||
readonly targetKind?: BinaryTarget["kind"];
|
||||
readonly formatHint?: ExecutableFormatHint;
|
||||
readonly architecture?: BinaryArchitecture;
|
||||
readonly entryPoint?: string;
|
||||
readonly snapshot?: AnalysisSnapshot;
|
||||
readonly providerId?: AnalysisProviderSelector;
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
||||
import { binaryTargetSummary } from "./BinaryTargetSummary.js";
|
||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
||||
import type { ProviderOperationHealth } from "../../domain/providerOperationHealth.js";
|
||||
import type {
|
||||
@@ -93,7 +92,11 @@ export const binarySessionStatus = ({
|
||||
: {
|
||||
open: true,
|
||||
...common,
|
||||
...binaryTargetSummary(target),
|
||||
path: target.path,
|
||||
sha256: target.sha256,
|
||||
format: target.format,
|
||||
kind: target.kind,
|
||||
architecture: target.architecture ?? null,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
||||
|
||||
/** Preserve the admitted target interpretation in public lifecycle results. */
|
||||
export const binaryTargetSummary = (target: BinaryTarget) => ({
|
||||
path: target.path,
|
||||
format: target.format,
|
||||
kind: target.kind,
|
||||
sha256: target.sha256,
|
||||
architecture: target.architecture ?? null,
|
||||
...(target.format === "raw-binary" ? { entry_point: target.entryPoint } : {}),
|
||||
});
|
||||
@@ -8,8 +8,9 @@ import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||
import { logCliCommand } from "../cliLogging.js";
|
||||
import type { Logger } from "pino";
|
||||
import {
|
||||
directAnalysisOptionsFromCli,
|
||||
nativeOpenOptionFields,
|
||||
directAnalysisOptions,
|
||||
formatSelectionOption,
|
||||
providerSelectionOption,
|
||||
} from "./options.js";
|
||||
import type { CliInstance } from "./types.js";
|
||||
import { runCliJavaScriptApplicationAnalysis } from "./javascriptApplicationAnalysis.js";
|
||||
@@ -42,7 +43,8 @@ const registerOverviewCommands = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
});
|
||||
cli.command(CLI_COMMANDS.analyze, {
|
||||
description: "Get an overview of an app",
|
||||
@@ -73,7 +75,12 @@ const registerOverviewCommands = (
|
||||
args.path,
|
||||
"binary_overview",
|
||||
{},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -90,7 +97,12 @@ const registerOverviewCommands = (
|
||||
args.path,
|
||||
"binary_overview",
|
||||
{},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -124,7 +136,8 @@ const registerDecompileCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "decompile", () =>
|
||||
@@ -139,7 +152,12 @@ const registerDecompileCommand = (
|
||||
"procedure_pseudo_code",
|
||||
),
|
||||
},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -150,17 +168,13 @@ const routesToJavaScriptAnalysis = async (
|
||||
path: string,
|
||||
options: {
|
||||
readonly snapshot?: string | undefined;
|
||||
readonly "target-format"?: "dos-com" | "raw-binary" | undefined;
|
||||
readonly architecture?: string | undefined;
|
||||
readonly "entry-point"?: string | undefined;
|
||||
readonly "target-format"?: "dos-com" | undefined;
|
||||
readonly provider?: string | undefined;
|
||||
},
|
||||
): Promise<boolean> =>
|
||||
options.provider === undefined &&
|
||||
options.snapshot === undefined &&
|
||||
options["target-format"] === undefined &&
|
||||
options.architecture === undefined &&
|
||||
options["entry-point"] === undefined &&
|
||||
(await isJavaScriptApplicationPath(path));
|
||||
|
||||
const isJavaScriptApplicationPath = async (path: string): Promise<boolean> => {
|
||||
@@ -201,7 +215,8 @@ const registerXrefsCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "xrefs", () =>
|
||||
@@ -216,7 +231,12 @@ const registerXrefsCommand = (
|
||||
"xrefs",
|
||||
),
|
||||
},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -250,7 +270,8 @@ const registerTraceCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "trace", () =>
|
||||
@@ -266,7 +287,12 @@ const registerTraceCommand = (
|
||||
),
|
||||
case_sensitive: options.caseSensitive,
|
||||
},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -300,7 +326,8 @@ const registerFunctionCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "function", () =>
|
||||
@@ -315,7 +342,12 @@ const registerFunctionCommand = (
|
||||
"analyze_function",
|
||||
),
|
||||
},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -349,7 +381,8 @@ const registerInstructionsCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.instructions, () =>
|
||||
@@ -364,7 +397,12 @@ const registerInstructionsCommand = (
|
||||
"read_function_instructions",
|
||||
),
|
||||
},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -410,7 +448,8 @@ const registerSearchCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "search", () =>
|
||||
@@ -429,7 +468,12 @@ const registerSearchCommand = (
|
||||
mode: options.mode,
|
||||
case_sensitive: options.caseSensitive,
|
||||
},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
|
||||
@@ -5,8 +5,9 @@ import { CLI_COMMANDS } from "../cliCommandNames.js";
|
||||
import { logCliCommand } from "../cliLogging.js";
|
||||
import type { Logger } from "pino";
|
||||
import {
|
||||
directAnalysisOptionsFromCli,
|
||||
nativeOpenOptionFields,
|
||||
directAnalysisOptions,
|
||||
formatSelectionOption,
|
||||
providerSelectionOption,
|
||||
} from "./options.js";
|
||||
import type { CliInstance } from "./types.js";
|
||||
|
||||
@@ -22,7 +23,8 @@ export const registerCoreNativeCommands = (
|
||||
"Verify loaded native bytes, source mappings, relocations and entry",
|
||||
args: z.object({ path: z.string().describe("Local executable path") }),
|
||||
options: z.object({
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.inspectNativeLoadImage, () =>
|
||||
@@ -30,7 +32,12 @@ export const registerCoreNativeCommands = (
|
||||
args.path,
|
||||
"inspect_native_load_image",
|
||||
{},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -47,7 +54,8 @@ export const registerCoreNativeCommands = (
|
||||
.min(1)
|
||||
.default(256)
|
||||
.describe("Requested byte count"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.readBytes, () =>
|
||||
@@ -55,7 +63,12 @@ export const registerCoreNativeCommands = (
|
||||
args.path,
|
||||
"read_bytes",
|
||||
{ address: args.address, length: options.length },
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -66,7 +79,8 @@ export const registerCoreNativeCommands = (
|
||||
address: z.string().describe("Exact provider memory address"),
|
||||
}),
|
||||
options: z.object({
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.addressToFileOffset, () =>
|
||||
@@ -74,7 +88,12 @@ export const registerCoreNativeCommands = (
|
||||
args.path,
|
||||
"address_to_file_offset",
|
||||
{ address: args.address },
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -135,7 +154,8 @@ export const registerCoreNativeCommands = (
|
||||
.max(5000)
|
||||
.default(1000)
|
||||
.describe("Maximum nodes on this page"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.traceNativeValues, () =>
|
||||
@@ -152,7 +172,12 @@ export const registerCoreNativeCommands = (
|
||||
offset: options.offset,
|
||||
limit: options.limit,
|
||||
},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -164,7 +189,8 @@ export const registerCoreNativeCommands = (
|
||||
options: z.object({
|
||||
type: z.string().optional().describe("Exact database type category path"),
|
||||
address: z.string().optional().describe("Exact native address"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.inspectNativeDataType, () =>
|
||||
@@ -177,7 +203,12 @@ export const registerCoreNativeCommands = (
|
||||
? {}
|
||||
: { address: options.address }),
|
||||
},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -195,7 +226,8 @@ export const registerCoreNativeCommands = (
|
||||
address: z.string().describe("Exact native address"),
|
||||
}),
|
||||
options: z.object({
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, command, () =>
|
||||
@@ -203,7 +235,12 @@ export const registerCoreNativeCommands = (
|
||||
args.path,
|
||||
operation,
|
||||
{ address: args.address },
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -236,7 +273,8 @@ const registerNativeDispatchMetadataCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load or update the local analysis snapshot"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: async ({ args, options }) =>
|
||||
logCliCommand(logger, "inspect-native-dispatch-metadata", () =>
|
||||
@@ -244,7 +282,12 @@ const registerNativeDispatchMetadataCommand = (
|
||||
args.path,
|
||||
"inspect_native_dispatch_metadata",
|
||||
{ max_records: options.maxRecords },
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -289,7 +332,8 @@ const registerNativeUiActionCommand = (
|
||||
.max(5_000)
|
||||
.default(500)
|
||||
.describe("Maximum returned graph edges"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: async ({ args, options }) =>
|
||||
logCliCommand(logger, "trace-native-ui-action", () =>
|
||||
@@ -302,7 +346,12 @@ const registerNativeUiActionCommand = (
|
||||
max_nodes: options.maxNodes,
|
||||
max_edges: options.maxEdges,
|
||||
},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -325,7 +374,8 @@ const registerNativeApiCommand = (
|
||||
.min(1)
|
||||
.optional()
|
||||
.describe("Load and update a local analysis snapshot"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, "inspect-native-api", () =>
|
||||
@@ -333,7 +383,12 @@ const registerNativeApiCommand = (
|
||||
args.path,
|
||||
"inspect_native_api",
|
||||
{ procedure: args.address },
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
@@ -362,7 +417,8 @@ const registerAnnotationCommand = (
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Inline entry comment; empty text clears it"),
|
||||
...nativeOpenOptionFields,
|
||||
"target-format": formatSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
}),
|
||||
run: ({ args, options }) =>
|
||||
logCliCommand(logger, CLI_COMMANDS.annotateNativeFunction, () =>
|
||||
@@ -379,7 +435,12 @@ const registerAnnotationCommand = (
|
||||
? {}
|
||||
: { inline_comment: options["inline-comment"] }),
|
||||
},
|
||||
directAnalysisOptionsFromCli(logger, options),
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
undefined,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
),
|
||||
),
|
||||
),
|
||||
});
|
||||
|
||||
+1
-55
@@ -2,11 +2,6 @@ import {
|
||||
executableFormatHintSchema,
|
||||
type ExecutableFormatHint,
|
||||
} from "../domain/dosCom.js";
|
||||
import type { BinaryArchitecture } from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
binaryArchitectureSchema,
|
||||
rawBinaryEntryPointSchema,
|
||||
} from "../domain/rawBinary.js";
|
||||
import { analysisProviderSelectorSchema } from "../contracts/providerSelection.js";
|
||||
import type { AnalysisProviderSelector } from "../contracts/providerSelection.js";
|
||||
import type { Logger } from "pino";
|
||||
@@ -20,65 +15,16 @@ export const providerSelectionOption = analysisProviderSelectorSchema
|
||||
/** Explicit interpretation for headerless native executable formats. */
|
||||
export const formatSelectionOption = executableFormatHintSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Explicit headerless interpretation (dos-com or raw-binary); omission preserves header-based detection",
|
||||
);
|
||||
|
||||
export const architectureSelectionOption = binaryArchitectureSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Caller-supplied CPU family; required with --target-format raw-binary",
|
||||
);
|
||||
|
||||
export const entryPointSelectionOption = rawBinaryEntryPointSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Caller-supplied load and entry address (0xhex); required with --target-format raw-binary",
|
||||
);
|
||||
|
||||
/** Shared CLI flags that bind a native target interpretation. */
|
||||
export const nativeOpenOptionFields = {
|
||||
"target-format": formatSelectionOption,
|
||||
architecture: architectureSelectionOption,
|
||||
"entry-point": entryPointSelectionOption,
|
||||
provider: providerSelectionOption,
|
||||
};
|
||||
|
||||
/** Native CLI flags consumed when opening a target for one-shot analysis. */
|
||||
export interface NativeOpenCliFlags {
|
||||
readonly snapshot?: string | undefined;
|
||||
readonly provider?: AnalysisProviderSelector | undefined;
|
||||
readonly "target-format"?: ExecutableFormatHint | undefined;
|
||||
readonly architecture?: BinaryArchitecture | undefined;
|
||||
readonly "entry-point"?: string | undefined;
|
||||
}
|
||||
.describe("Explicit headerless DOS COM interpretation");
|
||||
|
||||
export const directAnalysisOptions = (
|
||||
logger: Logger,
|
||||
snapshotPath: string | undefined,
|
||||
providerId: AnalysisProviderSelector | undefined,
|
||||
formatHint?: ExecutableFormatHint,
|
||||
architecture?: BinaryArchitecture,
|
||||
entryPoint?: string,
|
||||
) => ({
|
||||
logger,
|
||||
snapshotPath,
|
||||
...(formatHint === undefined ? {} : { formatHint }),
|
||||
...(architecture === undefined ? {} : { architecture }),
|
||||
...(entryPoint === undefined ? {} : { entryPoint }),
|
||||
...(providerId === undefined ? {} : { providerId }),
|
||||
});
|
||||
|
||||
/** Map native CLI flags onto the shared one-shot analysis options. */
|
||||
export const directAnalysisOptionsFromCli = (
|
||||
logger: Logger,
|
||||
options: NativeOpenCliFlags,
|
||||
) =>
|
||||
directAnalysisOptions(
|
||||
logger,
|
||||
options.snapshot,
|
||||
options.provider,
|
||||
options["target-format"],
|
||||
options.architecture,
|
||||
options["entry-point"],
|
||||
);
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { openBinaryInputSchema } from "./sessionLifecycleInputs.js";
|
||||
|
||||
describe("open_binary raw-binary input contract", () => {
|
||||
it("accepts header detection without architecture", () => {
|
||||
expect(
|
||||
openBinaryInputSchema.safeParse({ path: "/tmp/fixture.bin" }).success,
|
||||
).toBe(true);
|
||||
expect(
|
||||
openBinaryInputSchema.safeParse({
|
||||
path: "/tmp/legacy.com",
|
||||
format: "dos-com",
|
||||
}).success,
|
||||
).toBe(true);
|
||||
});
|
||||
it("accepts raw-binary with architecture and entry", () => {
|
||||
expect(
|
||||
openBinaryInputSchema.safeParse({
|
||||
path: "/tmp/ecu.bin",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
entry_point: "0x8000000",
|
||||
}).success,
|
||||
).toBe(true);
|
||||
});
|
||||
it("rejects raw-binary without architecture or entry", () => {
|
||||
const parsed = openBinaryInputSchema.safeParse({
|
||||
path: "/tmp/ecu.bin",
|
||||
format: "raw-binary",
|
||||
});
|
||||
expect(parsed.success).toBe(false);
|
||||
expect(
|
||||
openBinaryInputSchema.safeParse({
|
||||
path: "/tmp/ecu.bin",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
it("rejects architecture without format=raw-binary", () => {
|
||||
expect(
|
||||
openBinaryInputSchema.safeParse({
|
||||
path: "/tmp/ecu.bin",
|
||||
architecture: "arm",
|
||||
entry_point: "0x8000000",
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,6 @@
|
||||
import { isAbsolute } from "node:path";
|
||||
import { executableFormatHintSchema } from "../domain/dosCom.js";
|
||||
import { localPathStringSchema } from "../domain/localPath.js";
|
||||
import {
|
||||
binaryArchitectureSchema,
|
||||
rawBinaryEntryPointSchema,
|
||||
rawBinarySelectionError,
|
||||
} from "../domain/rawBinary.js";
|
||||
import { z } from "zod";
|
||||
import { analysisProviderSelectorSchema } from "./providerSelection.js";
|
||||
|
||||
@@ -30,51 +25,16 @@ const binaryTargetPathSchema = localPathStringSchema
|
||||
);
|
||||
|
||||
/** Input contract for opening a target with an optional staged snapshot. */
|
||||
export const openBinaryInputSchema = z
|
||||
.strictObject({
|
||||
path: binaryTargetPathSchema,
|
||||
format: executableFormatHintSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Explicit headerless interpretation: dos-com or raw-binary. Omission preserves header-based detection.",
|
||||
),
|
||||
architecture: binaryArchitectureSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Caller-supplied CPU family. Required with format=raw-binary; rejected otherwise.",
|
||||
),
|
||||
entry_point: rawBinaryEntryPointSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Caller-supplied load and entry address (0xhex). File offset 0 is mapped here. Required with format=raw-binary; rejected otherwise.",
|
||||
),
|
||||
provider_id: analysisProviderSelectorSchema.optional(),
|
||||
snapshot_path: snapshotPathSchema.optional(),
|
||||
})
|
||||
.superRefine((value, context) => {
|
||||
const pairing = rawBinarySelectionError({
|
||||
...(value.format === undefined ? {} : { format: value.format }),
|
||||
...(value.architecture === undefined
|
||||
? {}
|
||||
: { architecture: value.architecture }),
|
||||
...(value.entry_point === undefined
|
||||
? {}
|
||||
: { entryPoint: value.entry_point }),
|
||||
});
|
||||
if (pairing === undefined) return;
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path:
|
||||
value.format === "raw-binary"
|
||||
? value.architecture === undefined
|
||||
? ["architecture"]
|
||||
: ["entry_point"]
|
||||
: value.architecture === undefined
|
||||
? ["entry_point"]
|
||||
: ["architecture"],
|
||||
message: pairing,
|
||||
});
|
||||
});
|
||||
export const openBinaryInputSchema = z.strictObject({
|
||||
path: binaryTargetPathSchema,
|
||||
format: executableFormatHintSchema
|
||||
.optional()
|
||||
.describe(
|
||||
"Explicit headerless DOS COM interpretation; omission preserves header-based detection",
|
||||
),
|
||||
provider_id: analysisProviderSelectorSchema.optional(),
|
||||
snapshot_path: snapshotPathSchema.optional(),
|
||||
});
|
||||
|
||||
/** Input contract for closing a target after an optional atomic snapshot. */
|
||||
export const closeBinaryInputSchema = z.strictObject({
|
||||
|
||||
@@ -69,7 +69,7 @@ export const exportEvidenceBundleInputSchema = z.strictObject({
|
||||
export const SESSION_TOOL_CONTRACTS = [
|
||||
session(
|
||||
"open_binary",
|
||||
"Open a local executable, application bundle, archive, JavaScript, source map, plist, or analysis database after validation. format=dos-com explicitly interprets 1..65280 headerless bytes as a DOS COM analysis image. format=raw-binary interprets headerless bytes with a required architecture and entry_point; file offset 0 maps at that address. Omission preserves header-based detection. provider_id selects one deep provider or deterministic auto selection; the binding remains stable until close or an explicit switch, with no failure fallback. Reopening the same target and profile retains its active database and metadata edits. An optional analysis snapshot is imported atomically and must match the binary identity, concrete provider, and canonical analysis profile exactly; importing into a session with metadata mutations requires closing and reopening it first.",
|
||||
"Open a local executable, application bundle, archive, JavaScript, source map, plist, or analysis database after validation. format=dos-com explicitly interprets 1..65280 headerless bytes as a DOS COM analysis image; omission preserves header-based detection. provider_id selects one deep provider or deterministic auto selection; the binding remains stable until close or an explicit switch, with no failure fallback. Reopening the same target and profile retains its active database and metadata edits. An optional analysis snapshot is imported atomically and must match the binary identity, concrete provider, and canonical analysis profile exactly; importing into a session with metadata mutations requires closing and reopening it first.",
|
||||
openBinaryInputSchema,
|
||||
),
|
||||
session(
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { z } from "zod";
|
||||
import { evidenceBundleSummarySchema } from "../domain/evidenceRecordSummary.js";
|
||||
import { BINARY_ARCHITECTURES } from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
binaryArchitectureSchema,
|
||||
rawBinaryEntryPointSchema,
|
||||
} from "../domain/rawBinary.js";
|
||||
import { nativeFunctionAnnotationsSchema } from "../domain/native/nativeFunctionAnnotations.js";
|
||||
import { nativeLoadImageSchema } from "../domain/native/nativeLoadImage.js";
|
||||
import { nativeUiResultSchema } from "../domain/native/nativeUiObservation.js";
|
||||
@@ -413,33 +409,16 @@ export const managedWorkflowOutputSchemas: Readonly<
|
||||
),
|
||||
};
|
||||
|
||||
const lifecycleTargetFields = {
|
||||
path: z.string(),
|
||||
kind: targetKindSchema,
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
architecture: z.enum(BINARY_ARCHITECTURES).nullable(),
|
||||
};
|
||||
const detectedLifecycleTargetSchema = z.object({
|
||||
...lifecycleTargetFields,
|
||||
format: targetFormatSchema.exclude(["raw-binary"]),
|
||||
});
|
||||
const rawLifecycleTargetSchema = z.object({
|
||||
...lifecycleTargetFields,
|
||||
format: z.literal("raw-binary"),
|
||||
kind: z.literal("executable"),
|
||||
architecture: binaryArchitectureSchema,
|
||||
entry_point: rawBinaryEntryPointSchema.describe(
|
||||
"Canonical caller-selected address where raw file offset 0 is mapped and execution is seeded.",
|
||||
),
|
||||
});
|
||||
|
||||
/** Exact structured-content schemas for target lifecycle operations. */
|
||||
export const sessionOutputSchemas = {
|
||||
open_binary: lifecycleResultOf(
|
||||
z.discriminatedUnion("format", [
|
||||
detectedLifecycleTargetSchema,
|
||||
rawLifecycleTargetSchema,
|
||||
]),
|
||||
z.object({
|
||||
path: z.string(),
|
||||
format: targetFormatSchema,
|
||||
kind: targetKindSchema,
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
architecture: z.enum(BINARY_ARCHITECTURES).nullable(),
|
||||
}),
|
||||
),
|
||||
close_binary: lifecycleResultOf(
|
||||
z.union([
|
||||
@@ -469,15 +448,19 @@ export const sessionOutputSchemas = {
|
||||
),
|
||||
binary_session: lifecycleResultOf(
|
||||
z.union([
|
||||
sessionProvider.extend({ open: z.literal(false) }),
|
||||
sessionProvider.extend({
|
||||
open: z.literal(true),
|
||||
...detectedLifecycleTargetSchema.shape,
|
||||
}),
|
||||
sessionProvider.extend({
|
||||
open: z.literal(true),
|
||||
...rawLifecycleTargetSchema.shape,
|
||||
}),
|
||||
z.union([
|
||||
sessionProvider.extend({
|
||||
open: z.literal(false),
|
||||
}),
|
||||
sessionProvider.extend({
|
||||
open: z.literal(true),
|
||||
path: z.string(),
|
||||
format: targetFormatSchema,
|
||||
kind: targetKindSchema,
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
architecture: z.enum(BINARY_ARCHITECTURES).nullable(),
|
||||
}),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
export_evidence_bundle: lifecycleResultOf(
|
||||
|
||||
@@ -56,7 +56,6 @@ export const targetFormatSchema = z.enum([
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"raw-binary",
|
||||
"zip",
|
||||
"ipa",
|
||||
"apk",
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
snapshotBinding,
|
||||
snapshotEvidenceForQuery,
|
||||
snapshotTarget,
|
||||
snapshotMatchesTarget,
|
||||
} from "./analysisSnapshot.js";
|
||||
import {
|
||||
ANALYSIS_SNAPSHOT_PROFILE,
|
||||
@@ -17,7 +16,6 @@ import {
|
||||
} from "./analysisSnapshot.fixture.js";
|
||||
import { createEvidence } from "./evidence.js";
|
||||
import { createEvidenceBundle } from "./evidenceBundle.js";
|
||||
import type { BinaryTarget } from "./binaryTargetTypes.js";
|
||||
|
||||
const snapshotWithHistoricalEvidence = () => {
|
||||
const target = snapshotTarget(ANALYSIS_SNAPSHOT_TARGET);
|
||||
@@ -70,54 +68,6 @@ const snapshotWithHistoricalEvidence = () => {
|
||||
};
|
||||
|
||||
describe("analysis snapshot contract", () => {
|
||||
it("partitions raw snapshots and query identities by the canonical entry", () => {
|
||||
const target: BinaryTarget = {
|
||||
path: "/fixture/image.bin",
|
||||
sha256: ANALYSIS_SNAPSHOT_TARGET.sha256,
|
||||
kind: "executable",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
availableArchitectures: ["arm"],
|
||||
entryPoint: "0x8000000",
|
||||
entryPointSource: "0x08000000",
|
||||
};
|
||||
const snapshot = snapshotTarget(target);
|
||||
const binding = snapshotBinding(ANALYSIS_SNAPSHOT_PROFILE);
|
||||
const changed = {
|
||||
...target,
|
||||
entryPoint: "0x9000000",
|
||||
entryPointSource: "0x09000000",
|
||||
};
|
||||
expect(
|
||||
snapshotMatchesTarget(snapshot, {
|
||||
...target,
|
||||
entryPointSource: "0x8000000",
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(snapshotMatchesTarget(snapshot, changed)).toBe(false);
|
||||
expect(analysisQueryId(snapshot, binding, "list_procedures", {})).not.toBe(
|
||||
analysisQueryId(snapshotTarget(changed), binding, "list_procedures", {}),
|
||||
);
|
||||
const parsed = analysisSnapshotSchema.parse({
|
||||
target: snapshot,
|
||||
binding,
|
||||
entries: [],
|
||||
workflow_entries: [],
|
||||
evidence_bundle: createEvidenceBundle([]),
|
||||
});
|
||||
expect(parsed.target).toHaveProperty("entry_point", target.entryPoint);
|
||||
const { entry_point: _entry, ...legacy } = {
|
||||
...snapshot,
|
||||
entry_point: target.entryPoint,
|
||||
};
|
||||
expect(
|
||||
analysisSnapshotSchema.safeParse({ ...parsed, target: legacy }).success,
|
||||
).toBe(false);
|
||||
expect(snapshotTarget(ANALYSIS_SNAPSHOT_TARGET)).not.toHaveProperty(
|
||||
"entry_point",
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves DOS MZ target and subject formats with the x86 family", () => {
|
||||
const target = {
|
||||
path: ANALYSIS_SNAPSHOT_TARGET.path,
|
||||
@@ -163,37 +113,6 @@ describe("analysis snapshot contract", () => {
|
||||
expect(parsed.evidence_bundle.records[0]?.subject?.format).toBe("dos-mz");
|
||||
});
|
||||
|
||||
it("rejects a snapshot subject path containing NUL", () => {
|
||||
const binding = snapshotBinding(ANALYSIS_SNAPSHOT_PROFILE);
|
||||
const entry = {
|
||||
query_id: `query_${"0".repeat(64)}`,
|
||||
operation: "analyze_function",
|
||||
parameters: {},
|
||||
execution: {
|
||||
result: null,
|
||||
raw_result: null,
|
||||
provider: binding.provider,
|
||||
limitations: [],
|
||||
locations: [],
|
||||
subject: {
|
||||
path: "a\u0000b",
|
||||
sha256: "a".repeat(64),
|
||||
format: "elf" as const,
|
||||
architecture: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(
|
||||
analysisSnapshotSchema.safeParse({
|
||||
target: snapshotTarget(ANALYSIS_SNAPSHOT_TARGET),
|
||||
binding,
|
||||
entries: [entry],
|
||||
workflow_entries: [],
|
||||
evidence_bundle: createEvidenceBundle([]),
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts snapshots with more than ten thousand analysis entries", () => {
|
||||
const binding = snapshotBinding(ANALYSIS_SNAPSHOT_PROFILE);
|
||||
const entry = {
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
compareUnicodeCodePoints,
|
||||
compositeKey,
|
||||
} from "./unicodeCodePointOrder.js";
|
||||
import { localPathStringSchema } from "./localPath.js";
|
||||
|
||||
import {
|
||||
analysisProfileSchema,
|
||||
@@ -40,7 +39,6 @@ import { digestSchema } from "./../domain/digests.js";
|
||||
import { prefixedDigestSchema } from "./../domain/digests.js";
|
||||
import { canonicalJsonDigestSteps } from "./canonicalJsonDigestSteps.js";
|
||||
import { freezeJsonSnapshot } from "./immutableJson.js";
|
||||
import { rawBinaryEntryPointSchema } from "./rawBinary.js";
|
||||
|
||||
const architectureSchema = z.enum(BINARY_ARCHITECTURES);
|
||||
const formatSchema = z.enum([
|
||||
@@ -50,7 +48,6 @@ const formatSchema = z.enum([
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"raw-binary",
|
||||
"zip",
|
||||
"ipa",
|
||||
"apk",
|
||||
@@ -68,7 +65,7 @@ const formatSchema = z.enum([
|
||||
]);
|
||||
const kindSchema = z.enum(["executable", "database", "archive", "artifact"]);
|
||||
const subjectSchema = z.object({
|
||||
path: localPathStringSchema,
|
||||
path: z.string().min(1),
|
||||
sha256: digestSchema,
|
||||
format: z.enum([
|
||||
...formatSchema.options,
|
||||
@@ -82,22 +79,12 @@ const subjectSchema = z.object({
|
||||
]),
|
||||
architecture: architectureSchema.nullable(),
|
||||
});
|
||||
const targetIdentitySchema = z.object({
|
||||
const targetSchema = z.object({
|
||||
sha256: digestSchema,
|
||||
kind: kindSchema,
|
||||
format: formatSchema,
|
||||
architecture: architectureSchema.nullable(),
|
||||
});
|
||||
const targetSchema = z.discriminatedUnion("format", [
|
||||
targetIdentitySchema.extend({
|
||||
format: z.enum(
|
||||
formatSchema.options.filter((format) => format !== "raw-binary"),
|
||||
),
|
||||
}),
|
||||
targetIdentitySchema.extend({
|
||||
format: z.literal("raw-binary"),
|
||||
entry_point: rawBinaryEntryPointSchema,
|
||||
}),
|
||||
]);
|
||||
const bindingSchema = z
|
||||
.object({
|
||||
provider: committedProviderSchema,
|
||||
@@ -323,16 +310,12 @@ const canonicalJson = (value: unknown): string => {
|
||||
/** Project a binary into the path-free identity used for cache invalidation. */
|
||||
export const snapshotTarget = (
|
||||
target: BinaryTarget,
|
||||
): AnalysisSnapshotTarget => {
|
||||
const identity = {
|
||||
sha256: target.sha256,
|
||||
kind: target.kind,
|
||||
architecture: target.architecture ?? null,
|
||||
};
|
||||
return target.format === "raw-binary"
|
||||
? { ...identity, format: target.format, entry_point: target.entryPoint }
|
||||
: { ...identity, format: target.format };
|
||||
};
|
||||
): AnalysisSnapshotTarget => ({
|
||||
sha256: target.sha256,
|
||||
kind: target.kind,
|
||||
format: target.format,
|
||||
architecture: target.architecture ?? null,
|
||||
});
|
||||
|
||||
/** Build the immutable provider/profile binding used by a cached snapshot. */
|
||||
export const snapshotBinding = (
|
||||
@@ -351,10 +334,7 @@ export const snapshotMatchesTarget = (
|
||||
snapshot.sha256 === target.sha256 &&
|
||||
snapshot.kind === target.kind &&
|
||||
snapshot.format === target.format &&
|
||||
snapshot.architecture === (target.architecture ?? null) &&
|
||||
(snapshot.format !== "raw-binary" ||
|
||||
(target.format === "raw-binary" &&
|
||||
snapshot.entry_point === target.entryPoint));
|
||||
snapshot.architecture === (target.architecture ?? null);
|
||||
|
||||
/** Compare a snapshot binding with the selected concrete analysis profile. */
|
||||
export const snapshotMatchesProfile = (
|
||||
|
||||
@@ -50,7 +50,6 @@ const artifactFormatSchema = z.enum([
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"raw-binary",
|
||||
"hopper",
|
||||
"analysis-database",
|
||||
"ipa",
|
||||
|
||||
@@ -78,13 +78,6 @@ export type BinaryTarget =
|
||||
readonly executableRole?: never;
|
||||
readonly managed?: never;
|
||||
})
|
||||
| (ExecutableTarget & {
|
||||
readonly format: "raw-binary";
|
||||
readonly entryPoint: string;
|
||||
readonly entryPointSource: string;
|
||||
readonly executableRole?: never;
|
||||
readonly managed?: never;
|
||||
})
|
||||
| (ExecutableTarget & {
|
||||
readonly format: "pe";
|
||||
/** Provider-neutral PE image role observed from COFF characteristics. */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { z } from "zod";
|
||||
import { err, ok, type Result } from "./result.js";
|
||||
|
||||
/** Headerless executable interpretation explicitly selected by the caller. */
|
||||
export const executableFormatHintSchema = z.enum(["dos-com", "raw-binary"]);
|
||||
/** Headerless DOS COM interpretation explicitly selected by the caller. */
|
||||
export const executableFormatHintSchema = z.literal("dos-com");
|
||||
/** Explicit executable interpretation for formats with no identifying header. */
|
||||
export type ExecutableFormatHint = z.infer<typeof executableFormatHintSchema>;
|
||||
|
||||
|
||||
@@ -291,22 +291,6 @@ describe("analysis evidence identity", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a subject local path containing NUL while admitting an empty path", () => {
|
||||
const evidence = createEvidence(TARGET, PROVIDER, {
|
||||
operation: "health",
|
||||
parameters: {},
|
||||
result: true,
|
||||
});
|
||||
expect(evidence.subject).not.toBeNull();
|
||||
const withPath = (path: string) => ({
|
||||
...evidence,
|
||||
subject: { ...evidence.subject, local_path: path },
|
||||
});
|
||||
expect(evidenceSchema.safeParse(withPath("/tmp/fixture")).success).toBe(true);
|
||||
expect(evidenceSchema.safeParse(withPath("")).success).toBe(true);
|
||||
expect(evidenceSchema.safeParse(withPath("a\u0000b")).success).toBe(false);
|
||||
});
|
||||
|
||||
it("binds an explicit unknown-subject reason into the semantic Evidence identity", () => {
|
||||
const reason = "Caller excluded the observed digest.";
|
||||
const observation = { operation: "health", parameters: {}, result: true };
|
||||
|
||||
@@ -2,7 +2,6 @@ import { z } from "zod";
|
||||
|
||||
import { digestCanonicalValue } from "./canonicalDigest.js";
|
||||
import { canonicalJsonDigestSteps } from "./canonicalJsonDigestSteps.js";
|
||||
import { nulFreeStringSchema } from "./localPath.js";
|
||||
|
||||
import {
|
||||
analysisProfileSchema,
|
||||
@@ -44,7 +43,6 @@ const subjectSchema = z.object({
|
||||
"pe",
|
||||
"dos-mz",
|
||||
"dos-com",
|
||||
"raw-binary",
|
||||
"zip",
|
||||
"ipa",
|
||||
"apk",
|
||||
@@ -67,7 +65,7 @@ const subjectSchema = z.object({
|
||||
"entitlements",
|
||||
]),
|
||||
architecture: z.enum(BINARY_ARCHITECTURES).nullable(),
|
||||
local_path: nulFreeStringSchema,
|
||||
local_path: z.string(),
|
||||
});
|
||||
/** Source location attached to an evidence observation. */
|
||||
/** Source-location schema shared by evidence-bearing persistence formats. */
|
||||
|
||||
@@ -1,664 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
||||
import { ROLLDOWN_MODULE_INTEROP } from "./javascriptModuleInterop.fixture.js";
|
||||
|
||||
const WINDOW =
|
||||
'new electron.BrowserWindow({webPreferences:{preload:"./preload.js"}});';
|
||||
const IMPORT = 'let electron = require("electron");';
|
||||
const WRAP = "electron = __toESM(electron, 1);";
|
||||
// The upstream runtime uses control-body braces that its bundled printer omits.
|
||||
// https://github.com/rolldown/rolldown/blob/22a0ab13732d81f2559ad2b7064b688699324889/crates/rolldown/src/runtime/runtime-base.js
|
||||
const BLOCK_MODULE_INTEROP = ROLLDOWN_MODULE_INTEROP.replace(
|
||||
'if (from && typeof from === "object" || typeof from === "function") for',
|
||||
'if (from && typeof from === "object" || typeof from === "function") { for',
|
||||
)
|
||||
.replace(
|
||||
"if (!__hasOwnProp.call(to, key) && key !== except) __defProp",
|
||||
"if (!__hasOwnProp.call(to, key) && key !== except) { __defProp",
|
||||
)
|
||||
.replace(" });", " });\n }")
|
||||
.replace(" return to;", " }\n return to;");
|
||||
|
||||
describe("Electron module interop identity", () => {
|
||||
it("preserves named APIs through the released Rolldown namespace conversion", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
new electron.BrowserWindow({webPreferences:{preload:runtimePath}});
|
||||
electron.ipcMain.handle("ping", () => "pong");
|
||||
electron.contextBridge.exposeInMainWorld("api", {ping:true});
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toMatchObject([
|
||||
{ preload_path: "./preload.js" },
|
||||
{ preload_path: null },
|
||||
]);
|
||||
expect(analysis.electron.ipc).toMatchObject([
|
||||
{ channel: "ping", side: "main" },
|
||||
]);
|
||||
expect(analysis.electron.context_bridge_apis).toMatchObject([
|
||||
{ api_key: "api" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("follows lexical identities when helper and parameter names change", () => {
|
||||
const source = `${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`
|
||||
.replaceAll("__toESM", "namespaceOf")
|
||||
.replaceAll("__copyProps", "copyNamed")
|
||||
.replaceAll("mod", "inputModule")
|
||||
.replaceAll("isNodeMode", "nodeMode")
|
||||
.replaceAll("target", "namespaceTarget")
|
||||
.replaceAll("from", "sourceObject");
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(source).electron.browser_windows,
|
||||
).toMatchObject([{ preload_path: "./preload.js" }]);
|
||||
});
|
||||
|
||||
it("preserves the same operations through control-body braces", () => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(
|
||||
`${BLOCK_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`,
|
||||
).electron.browser_windows,
|
||||
).toMatchObject([{ preload_path: "./preload.js" }]);
|
||||
});
|
||||
|
||||
it("keeps additional operations inside a control block unresolved", () => {
|
||||
const altered = BLOCK_MODULE_INTEROP.replace(
|
||||
"{ __defProp",
|
||||
"{ from = unrelated; __defProp",
|
||||
);
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(`${altered}\n${IMPORT} ${WRAP} ${WINDOW}`)
|
||||
.electron.browser_windows,
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
const BOUND_INTRINSIC_MUTATIONS: [string, string][] = [
|
||||
[
|
||||
"intrinsic changed through aliased prebound arguments",
|
||||
`const objectAlias = Object; const key = "create"; const define = Object.defineProperty; const mutate = define.bind(null, objectAlias, key); mutate({value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed through nested prebinding",
|
||||
`const first = Object.defineProperty.bind(null, Object); const second = first.bind(null, "create"); second({value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"a replaced bound mutator bind method is unknown",
|
||||
`const first = Object.defineProperty.bind(null, Object); first.bind = customBind; const second = first.bind(null, "create"); second({value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed through a computed prebound call",
|
||||
`const mutate = Object.defineProperty.bind(null, Object, "create"); mutate["call"](null, {value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed through a computed prebound apply",
|
||||
`const mutate = Object.defineProperty.bind(null, Object, "create"); mutate["apply"](null, [{value:customCreate}]); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"a replaced bind intrinsic makes a prebound mutator unknown",
|
||||
`Function.prototype.bind = customBind; const mutate = Object.defineProperty.bind(null, Object, "create"); mutate({value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
];
|
||||
|
||||
describe("Electron module interop uncertainty", () => {
|
||||
it.each([
|
||||
...BOUND_INTRINSIC_MUTATIONS,
|
||||
[
|
||||
"intrinsic changed through an unresolved mutator target",
|
||||
`Object.defineProperty(getTarget(), "create", {value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via dynamic apply",
|
||||
`const args = [Object, "getOwnPropertyNames", {value:() => []}]; Object.defineProperty.apply(null, args); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via spread call",
|
||||
`const args = [Object, "getOwnPropertyNames", {value:() => []}]; Object.defineProperty.call(null, ...args); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via Reflect.apply",
|
||||
`const args = [Object, "getOwnPropertyNames", {value:() => []}]; Reflect.apply(Object.defineProperty, null, args); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via spread Reflect.apply",
|
||||
`const args = [null, [Object, "create", {value:customCreate}]]; Reflect.apply(Object.defineProperty, ...args); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via call",
|
||||
`Object.defineProperty.call(null, Object, "getOwnPropertyNames", {value:() => []}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed via apply",
|
||||
`Object.defineProperty.apply(null, [Object, "getOwnPropertyNames", {value:() => []}]); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed with defineProperty",
|
||||
`Object.defineProperty(Object, "getOwnPropertyNames", {value:() => []}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed with Reflect.set",
|
||||
`Reflect.set(Object, "getOwnPropertyNames", () => []); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed with an aliased mutator",
|
||||
`const change = Object.defineProperty; change(Object, "create", {value:customCreate}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed with assign",
|
||||
`Object.assign(Object, {getOwnPropertyNames:() => []}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"intrinsic changed with defineProperties",
|
||||
`Object.defineProperties(Function.prototype, {bind:{value:customBind}}); ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten Object global",
|
||||
`Object = customObject; ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten intrinsic through an alias",
|
||||
`const objectAlias = Object; objectAlias.create = customCreate; ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten intrinsic through globalThis",
|
||||
`globalThis.Object.create = customCreate; ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"helper called before initialization",
|
||||
`${IMPORT} ${WRAP} ${ROLLDOWN_MODULE_INTEROP}`,
|
||||
],
|
||||
[
|
||||
"fake helper",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n__toESM = (mod) => ({BrowserWindow:Fake}); ${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"changed getter",
|
||||
`${ROLLDOWN_MODULE_INTEROP.replace("from[k]", "to[k]")}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"replaced copy helper",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n__copyProps = () => ({}); ${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"replaced intrinsic alias",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n__defProp = () => ({}); ${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"shadowed Object",
|
||||
`const Object = customObject; ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten intrinsic",
|
||||
`Object.create = customCreate; ${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten alias call",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n__hasOwnProp.call = customCall; ${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"overwritten Function bind",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\nFunction.prototype.bind = customBind; ${IMPORT} ${WRAP}`,
|
||||
],
|
||||
[
|
||||
"conditional conversion",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} if (flag) { ${WRAP} }`,
|
||||
],
|
||||
[
|
||||
"compound assignment",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} electron ||= __toESM(electron, 1);`,
|
||||
],
|
||||
[
|
||||
"other input",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} electron = __toESM(other, 1);`,
|
||||
],
|
||||
[
|
||||
"later overwrite",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} electron = unrelated;`,
|
||||
],
|
||||
[
|
||||
"overwritten constructor",
|
||||
`${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} electron.BrowserWindow = Fake;`,
|
||||
],
|
||||
])("does not infer Electron identity after %s", (_name, setup) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(`${setup}\n${WINDOW}`).electron
|
||||
.browser_windows,
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop helper results", () => {
|
||||
it.each([
|
||||
'const {BrowserWindow} = __toESM(require("electron"), 1); new BrowserWindow({});',
|
||||
'const {BrowserWindow: Window} = __toESM(require("electron"), 1); new Window({});',
|
||||
'const {default: {BrowserWindow}} = __toESM(require("electron"), 1); new BrowserWindow({});',
|
||||
'const Window = __toESM(require("electron"), 1).BrowserWindow; new Window({});',
|
||||
])("preserves a proven result projection: %s", (source) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}\n${source}`)
|
||||
.electron.browser_windows,
|
||||
).toHaveLength(1);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'const {[key]: Window} = __toESM(require("electron"), 1); new Window({});',
|
||||
'const {...electron} = __toESM(require("electron"), 1); new electron.BrowserWindow({});',
|
||||
'let {BrowserWindow} = __toESM(require("electron"), 1); BrowserWindow = Fake; new BrowserWindow({});',
|
||||
])("keeps an uncertain result projection unresolved: %s", (source) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}\n${source}`)
|
||||
.electron.browser_windows,
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"",
|
||||
", 0",
|
||||
", false",
|
||||
", true",
|
||||
", 1",
|
||||
', "node"',
|
||||
', ""',
|
||||
", null",
|
||||
])("preserves named exports with a literal node mode: %s", (mode) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
const fresh = __toESM(require("electron")${mode});
|
||||
new fresh.BrowserWindow({});
|
||||
const {BrowserWindow} = __toESM(require("electron")${mode});
|
||||
new BrowserWindow({});
|
||||
let electron = require("electron");
|
||||
electron = __toESM(electron${mode}); ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(3);
|
||||
});
|
||||
|
||||
it.each(["", ", 0", ", false"])(
|
||||
"does not assume a module-valued default with node mode: %s",
|
||||
(mode) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
const original = require("electron");
|
||||
original.__esModule = true;
|
||||
original.default = {BrowserWindow: Fake};
|
||||
const {default: {BrowserWindow}} = __toESM(require("electron")${mode});
|
||||
new BrowserWindow({});
|
||||
const other = __toESM(require("electron")${mode}).default;
|
||||
new other.BrowserWindow({});
|
||||
new (__toESM(require("electron")${mode}).default.BrowserWindow)({});
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["__toESM", "identity"])(
|
||||
"rejects side-effecting extra arguments to %s",
|
||||
(helper) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
function identity(mod) { return mod; }
|
||||
const electron = ${helper}(require("electron"), mutate()); ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"const __toESM = () => ({BrowserWindow:FakeWindow});",
|
||||
"const __toESM = async (mod) => mod;",
|
||||
"function* __toESM(mod) { return mod; }",
|
||||
"const __toESM = (this && this.__toESM) || ((mod) => mod);",
|
||||
])("keeps an unproven fresh result unresolved: %s", (helper) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${helper}
|
||||
const electron = __toESM(require("electron"), 1); ${WINDOW}
|
||||
new (__toESM(require("electron"), 1)).BrowserWindow({});
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves a proven fresh namespace and a pure identity helper", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
const electron = __toESM(require("electron"), 1); ${WINDOW}
|
||||
new (__toESM(require("electron"), 1)).BrowserWindow({});
|
||||
function passthrough(value) {return value;}
|
||||
const plain = passthrough(require("electron"));
|
||||
new plain.BrowserWindow({});
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop pattern writes", () => {
|
||||
it.each([
|
||||
"({Object} = replacements);",
|
||||
"[Function] = replacements;",
|
||||
"({nested:{Object}} = replacements);",
|
||||
"({replacement:Object = customObject} = replacements);",
|
||||
"({...Object} = replacements);",
|
||||
"[...Function] = replacements;",
|
||||
"for ({Object} of replacements) {}",
|
||||
"for ([Function] in replacements) {}",
|
||||
])("rejects an intrinsic replaced through %s", (write) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${write} ${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.parse_error_count).toBe(0);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"({Object:unrelated} = replacements);",
|
||||
"function decoy(Object) {({Object} = replacements);}",
|
||||
])("preserves intrinsic identity for an unrelated target: %s", (write) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${write} ${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.parse_error_count).toBe(0);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("preserves captured operations after later property destructuring", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${ROLLDOWN_MODULE_INTEROP} ({create:Object.create} = replacements);
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop intrinsic captures", () => {
|
||||
it.each([
|
||||
"var captured = Object.defineProperty;",
|
||||
"const {defineProperty:captured} = Object;",
|
||||
"var first = Object.defineProperty; const captured = first;",
|
||||
])("retains the original function capture through %s", (capture) => {
|
||||
const runtime = ROLLDOWN_MODULE_INTEROP.replace(
|
||||
"__defProp = Object.defineProperty",
|
||||
"__defProp = captured",
|
||||
);
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${capture} Object.defineProperty = custom;
|
||||
${runtime} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it.each(["var", "const"])(
|
||||
"keeps an intrinsic alias read before its %s initializer unresolved",
|
||||
(kind) => {
|
||||
const runtime = ROLLDOWN_MODULE_INTEROP.replace(
|
||||
"__defProp = Object.defineProperty",
|
||||
"__defProp = later",
|
||||
);
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${runtime} ${kind} later = Object.defineProperty;
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
},
|
||||
);
|
||||
|
||||
it("requires the helper's intrinsic binding to initialize before conversion", () => {
|
||||
const runtime = ROLLDOWN_MODULE_INTEROP.replace(
|
||||
"var __defProp = Object.defineProperty;",
|
||||
"",
|
||||
);
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
var captured = Object.defineProperty;
|
||||
${runtime} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
var __defProp = captured;
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop capture and scope", () => {
|
||||
it.each(["metadata", "alias"])(
|
||||
"recognizes a hoisted function target through %s",
|
||||
(target) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
const alias = metadata;
|
||||
Object.defineProperty(${target}, "x", {value:1});
|
||||
function metadata() {}
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"var metadata = function () {};",
|
||||
"const metadata = () => {};",
|
||||
"class metadata {}",
|
||||
])("does not hoist fresh targets from %s", (declaration) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
Object.defineProperty(metadata, "x", {value:1});
|
||||
${declaration}
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'const {defineProperty:change} = Object; change(Object,"create",{value:customCreate});',
|
||||
"const objectAlias = Object; const {assign:change} = objectAlias; change(Object,{create:customCreate});",
|
||||
'const {set:change} = Reflect; change(Object,"create",customCreate);',
|
||||
'const {Object:{defineProperty:change}} = globalThis; change(Object,"create",{value:customCreate});',
|
||||
])("rejects a projected intrinsic mutator alias: %s", (write) => {
|
||||
const source = `${write} ${ROLLDOWN_MODULE_INTEROP}
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
`.replaceAll("__toESM", "namespaceOf");
|
||||
const analysis = analyzeJavaScriptStaticSource(source);
|
||||
expect(analysis.parse_error_count).toBe(0);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"const metadata = {};",
|
||||
"const metadata = [];",
|
||||
"const initial = {}; const metadata = initial;",
|
||||
"const metadata = () => {};",
|
||||
"const metadata = function () {};",
|
||||
"const metadata = async () => {};",
|
||||
"const metadata = function* () {};",
|
||||
"const metadata = class {};",
|
||||
"const metadata = /local/;",
|
||||
"function metadata() {}",
|
||||
"class metadata {}",
|
||||
])(
|
||||
"keeps a fresh mutator target separate from intrinsic identity: %s",
|
||||
(setup) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${setup} Object.defineProperty(metadata,"x",{value:1});
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"const metadata = getMetadata();",
|
||||
"let metadata = {}; metadata = Object;",
|
||||
"Object.defineProperty(metadata,'x',{value:1}); const metadata = {};",
|
||||
"const metadata = {intrinsic:Object}; Object.defineProperty(metadata.intrinsic,'create',{value:customCreate});",
|
||||
"const metadata = class {static {Object.create = customCreate;}};",
|
||||
"@(() => Object) class metadata {}",
|
||||
])("keeps an unproven mutator target unresolved: %s", (setup) => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
${setup} Object.defineProperty(metadata,"x",{value:1});
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it("does not reject unrelated intrinsic property definitions", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
Object.defineProperty(Object, "unrelated", {value:1});
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps opaque targets in a generic helper separate from outer module identity", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
function genericAssign() { Object.assign.apply(null, arguments); }
|
||||
${ROLLDOWN_MODULE_INTEROP} ${IMPORT} ${WRAP} ${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("rejects an opaque intrinsic mutation in the namespace's own callable", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
function openWindow(args) {
|
||||
Object.defineProperty.apply(null, args);
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it("preserves captured intrinsics across later vendor polyfills and callable writes", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
Object.create = customCreate;
|
||||
${IMPORT} ${WRAP}
|
||||
function runLoop(key) { globalThis[key] = this; }
|
||||
function polyfill() { Object.create = customCreate; }
|
||||
${WINDOW}
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("keeps a shadowed namespace separate from the converted module", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`${ROLLDOWN_MODULE_INTEROP}
|
||||
${IMPORT} ${WRAP} ${WINDOW}
|
||||
function decoy(electron) { ${WINDOW} }
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop generic invocations", () => {
|
||||
it.each([
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty); change(null,Object,"create",{value:customCreate});',
|
||||
'const call = Function.prototype.call; const change = call.bind(Object.defineProperty); change(null,Object,"create",{value:customCreate});',
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null,Object,"create"); change({value:customCreate});',
|
||||
'Function.prototype.call.call(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'Function.prototype.call.apply(Object.defineProperty,[null,Object,"create",{value:customCreate}]);',
|
||||
'Reflect.apply(Function.prototype.call,Object.defineProperty,[null,Object,"create",{value:customCreate}]);',
|
||||
'const change = Function.prototype.apply.bind(Object.defineProperty); change(null,[Object,"create",{value:customCreate}]);',
|
||||
'Function.prototype.apply.call(Object.defineProperty,null,[Object,"create",{value:customCreate}]);',
|
||||
'Reflect.apply(Function.prototype.apply,Object.defineProperty,[null,[Object,"create",{value:customCreate}]]);',
|
||||
'const first = Function.prototype.call.bind(Object.defineProperty,null,Object,"create"); const change = first.bind(fake); change({value:customCreate});',
|
||||
"const change = Function.prototype.call.bind(Object.defineProperty); change(null,...args);",
|
||||
"const change = Function.prototype.apply.bind(Object.defineProperty); change(null,args);",
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null,...args); change(metadata,"x",{value:1});',
|
||||
'Function.prototype.call.call.call(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'Object.defineProperty.call.call(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'Function.prototype.apply.apply(Object.defineProperty,[null,[Object,"create",{value:customCreate}]]);',
|
||||
'const change = Object.defineProperty.call.bind(Object.defineProperty); change(null,Object,"create",{value:customCreate});',
|
||||
'const change = Function.prototype.call.call.bind(Object.defineProperty,null,Object,"create"); change({value:customCreate});',
|
||||
])("follows the callable receiver of a generic invocation: %s", (write) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(
|
||||
`${write}\n${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`,
|
||||
).electron.browser_windows,
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty); change(null,metadata,"x",{value:1});',
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null,metadata,"x"); change({value:1});',
|
||||
'Function.prototype.call.call(Object.defineProperty,null,metadata,"x",{value:1});',
|
||||
'const change = Function.prototype.apply.bind(Object.defineProperty); change(null,[metadata,"x",{value:1}]);',
|
||||
'Reflect.apply(Function.prototype.apply,Object.defineProperty,[null,[metadata,"x",{value:1}]]);',
|
||||
'Function.prototype.call.call.call(Object.defineProperty,null,metadata,"x",{value:1});',
|
||||
'Function.prototype.apply.apply(Object.defineProperty,[null,[metadata,"x",{value:1}]]);',
|
||||
'const change = Object.defineProperty.call.bind(Object.defineProperty); change(null,metadata,"x",{value:1});',
|
||||
])("preserves fresh targets through a generic invocation: %s", (write) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(
|
||||
`const metadata = {}; ${write}\n${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`,
|
||||
).electron.browser_windows,
|
||||
).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Electron module interop bound mutators", () => {
|
||||
it.each([
|
||||
'const change = Object.defineProperty.bind(null); change(Object,"create",{value:customCreate});',
|
||||
'const change = Object.defineProperty.bind(null,Object,"create"); change({value:customCreate});',
|
||||
'const first = Object.defineProperty.bind(null,Object); const change = first; change("create",{value:customCreate});',
|
||||
'const change = Object.defineProperty.bind(null,Object); change.call(null,"create",{value:customCreate});',
|
||||
'const change = Object.defineProperty.bind(null,Object); change.apply(null,["create",{value:customCreate}]);',
|
||||
'const change = Object.defineProperty.bind(null,Object); Reflect.apply(change,null,["create",{value:customCreate}]);',
|
||||
'Object.defineProperty.bind(null,Object,"create")({value:customCreate});',
|
||||
'const change = Object.defineProperty.bind(null,...args); change(Object,"create",{value:customCreate});',
|
||||
'const metadata = {}; Object.defineProperty.call(...args,metadata,"x",{value:1});',
|
||||
'const metadata = {}; Object.defineProperty.apply(...args,[metadata,"x",{value:1}]);',
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null); change(Object,"create",{value:customCreate});',
|
||||
'const first = Function.prototype.call.bind(Object.defineProperty,null); const change = first.bind(customReceiver,Object,"create"); change({value:customCreate});',
|
||||
'const change = Function.prototype.apply.bind(Object.defineProperty,null); change([Object,"create",{value:customCreate}]);',
|
||||
'Function.prototype.call.call(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'Function.prototype.apply.call(Object.defineProperty,null,[Object,"create",{value:customCreate}]);',
|
||||
'const uncurry = Function.prototype.call.bind(Function.prototype.call); uncurry(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'const change = Function.prototype.bind.call(Object.defineProperty,null); change(Object,"create",{value:customCreate});',
|
||||
'const bind = Function.prototype.call.bind(Function.prototype.bind); const change = bind(Object.defineProperty,null); change(Object,"create",{value:customCreate});',
|
||||
'const change = Function.prototype.bind.apply(Object.defineProperty,[null,Object,"create"]); change({value:customCreate});',
|
||||
'const change = Reflect.apply(Function.prototype.bind,Object.defineProperty,[null,Object,"create"]); change({value:customCreate});',
|
||||
'const first = Object.defineProperty.bind(null,Object); const change = Function.prototype.bind.call(first,null,"create"); change({value:customCreate});',
|
||||
'Reflect.apply = Object.defineProperty; Reflect.apply(Object,"create",{value:customCreate});',
|
||||
'const apply = Reflect.apply; Reflect.apply = Object.defineProperty; Reflect.apply(Object,"create",{value:customCreate});',
|
||||
'const change = Reflect.set.bind(null,Object,"create"); change(customCreate);',
|
||||
'const change = Object.defineProperty.call; change.call(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
'const {apply:change} = Object.defineProperty; change.call(Object.defineProperty,null,[Object,"create",{value:customCreate}]);',
|
||||
'const change = Reflect.apply.call; change.call(Reflect.apply,null,Object.defineProperty,null,[Object,"create",{value:customCreate}]);',
|
||||
'Reflect.set({},"create",customCreate,Object);',
|
||||
'const metadata = {}; Reflect.set(metadata,"create",customCreate,Object);',
|
||||
'const change = Reflect.set.bind(null,{},"create",customCreate); change(Object);',
|
||||
'Reflect.apply(Reflect.set,null,[{},"create",customCreate,Object]);',
|
||||
'Reflect.set({},"create",customCreate,...receivers);',
|
||||
'Reflect.set({},"create",...valuesAndReceivers);',
|
||||
"Reflect.set({},...keysValuesAndReceivers);",
|
||||
'Reflect.set({},"create",customCreate,receiver);',
|
||||
])("rejects intrinsic writes through a bound mutator: %s", (write) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(
|
||||
`${write}\n${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`,
|
||||
).electron.browser_windows,
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'const change = Object.defineProperty.bind(null); change(metadata,"x",{value:1});',
|
||||
'const change = Object.defineProperty.bind(null,metadata,"x"); change({value:1});',
|
||||
'const first = Object.defineProperty.bind(null,metadata); const change = first.bind(null,"x"); change({value:1});',
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null); change(metadata,"x",{value:1});',
|
||||
'const change = Function.prototype.apply.bind(Object.defineProperty,null); change([metadata,"x",{value:1}]);',
|
||||
'const change = Function.prototype.bind.call(Object.defineProperty,null,metadata,"x"); change({value:1});',
|
||||
'const bind = Function.prototype.call.bind(Function.prototype.bind); const change = bind(Object.defineProperty,null,metadata,"x"); change({value:1});',
|
||||
'const change = Function.prototype.bind.apply(Object.defineProperty,[null,metadata,"x"]); change({value:1});',
|
||||
'const change = Reflect.apply(Function.prototype.bind,Object.defineProperty,[null,metadata,"x"]); change({value:1});',
|
||||
'const apply = Reflect.apply; Reflect.apply = replacement; apply(Object.defineProperty,null,[metadata,"x",{value:1}]);',
|
||||
'const change = Object.defineProperty.bind(null,Object,"create");',
|
||||
'Object.defineProperty.call(null,metadata,"x",{value:1});',
|
||||
'Object.defineProperty.apply(null,[metadata,"x",{value:1}]);',
|
||||
'const change = Object.defineProperty.call; change.call(Object.defineProperty,null,metadata,"x",{value:1});',
|
||||
'const {apply:change} = Object.defineProperty; change.call(Object.defineProperty,null,[metadata,"x",{value:1}]);',
|
||||
'Reflect.set(metadata,"x",1,{});',
|
||||
'const receiver = {}; Reflect.set({},"x",1,receiver);',
|
||||
])("keeps a fresh bound target or unused binding separate: %s", (write) => {
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(
|
||||
`const metadata = {}; ${write}\n${ROLLDOWN_MODULE_INTEROP}\n${IMPORT} ${WRAP} ${WINDOW}`,
|
||||
).electron.browser_windows,
|
||||
).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps unrelated exports after an aliased prebound key write", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
const electron = require("electron");
|
||||
const key = "Unrelated";
|
||||
const mutate = Object.defineProperty.bind(null, electron, key);
|
||||
mutate({value: custom});
|
||||
new electron.BrowserWindow({});
|
||||
`);
|
||||
expect(analysis.electron.browser_windows).toHaveLength(1);
|
||||
});
|
||||
@@ -77,7 +77,7 @@ describe("Electron API identity", () => {
|
||||
it("follows bundler namespace interop helpers without accepting other writes", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
var __toESM = (mod) => mod;
|
||||
var __importStar = (mod) => mod;
|
||||
var __importStar = (this && this.__importStar) || ((mod) => mod);
|
||||
let electron = require("electron");
|
||||
electron = __toESM(electron);
|
||||
new electron.BrowserWindow({ webPreferences: { preload: "./rolldown.js" } });
|
||||
@@ -120,53 +120,4 @@ describe("Electron API identity", () => {
|
||||
|
||||
expect(analysis.electron.browser_windows).toEqual([]);
|
||||
});
|
||||
|
||||
it("follows stable declaration aliases but not an assigned default parameter", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
const direct = require("electron");
|
||||
const constAlias = direct;
|
||||
new constAlias.BrowserWindow({webPreferences:{preload:"./const.js"}});
|
||||
|
||||
let letAlias = require("electron");
|
||||
new letAlias.BrowserWindow({webPreferences:{preload:"./let.js"}});
|
||||
|
||||
const { BrowserWindow } = require("electron");
|
||||
new BrowserWindow({webPreferences:{preload:"./destructured.js"}});
|
||||
|
||||
function withDefault(electron = require("./not-electron")) {
|
||||
if (flag) electron = require("electron");
|
||||
new electron.BrowserWindow({webPreferences:{preload:"./default.js"}});
|
||||
}
|
||||
`);
|
||||
|
||||
expect(
|
||||
analysis.electron.browser_windows.map(({ preload_path }) => preload_path),
|
||||
).toEqual(["./const.js", "./let.js", "./destructured.js"]);
|
||||
});
|
||||
|
||||
it("preserves one initializer across variable redeclarations without accepting writes", () => {
|
||||
const analysis = analyzeJavaScriptStaticSource(`
|
||||
var electron;
|
||||
var electron = require("electron");
|
||||
var electron;
|
||||
new electron.BrowserWindow({webPreferences:{preload:"./redeclared.js"}});
|
||||
|
||||
var replaced;
|
||||
var replaced = require("electron");
|
||||
replaced = fake;
|
||||
new replaced.BrowserWindow({webPreferences:{preload:"./replaced.js"}});
|
||||
|
||||
var initializedTwice = require("electron");
|
||||
var initializedTwice = fake;
|
||||
new initializedTwice.BrowserWindow({});
|
||||
|
||||
var conditional;
|
||||
if (flag) { var conditional = require("electron"); }
|
||||
new conditional.BrowserWindow({});
|
||||
`);
|
||||
|
||||
expect(
|
||||
analysis.electron.browser_windows.map(({ preload_path }) => preload_path),
|
||||
).toEqual(["./redeclared.js"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,20 +86,16 @@ export const semanticObjectPatternKeys = (
|
||||
return key === null ? [] : [key];
|
||||
});
|
||||
|
||||
/** Visit binding and member leaves in direct and destructuring write targets. */
|
||||
export function* semanticWriteTargets(
|
||||
/** Visit member write targets in direct and destructuring assignment forms. */
|
||||
export function* semanticMemberWriteTargets(
|
||||
root: t.Node,
|
||||
): Generator<t.Identifier | t.MemberExpression | t.OptionalMemberExpression> {
|
||||
): Generator<t.MemberExpression | t.OptionalMemberExpression> {
|
||||
const pending = [root];
|
||||
while (pending.length > 0) {
|
||||
const next = pending.pop();
|
||||
if (next === undefined) break;
|
||||
const node = unwrapJavaScriptExpression(next).node;
|
||||
if (
|
||||
t.isIdentifier(node) ||
|
||||
t.isMemberExpression(node) ||
|
||||
t.isOptionalMemberExpression(node)
|
||||
)
|
||||
if (t.isMemberExpression(node) || t.isOptionalMemberExpression(node))
|
||||
yield node;
|
||||
else if (t.isRestElement(node)) pending.push(node.argument);
|
||||
else if (t.isAssignmentPattern(node)) pending.push(node.left);
|
||||
|
||||
@@ -2,9 +2,10 @@ import * as t from "@babel/types";
|
||||
|
||||
import {
|
||||
semanticStaticPropertyKey,
|
||||
semanticWriteTargets,
|
||||
semanticMemberWriteTargets,
|
||||
unwrapJavaScriptExpression,
|
||||
} from "./javascriptAstValues.js";
|
||||
import { SemanticPropertyPathCoverage } from "./javascriptSemanticPropertyPaths.js";
|
||||
import { traverseJavaScriptAstSteps } from "./javascriptSemanticTraversal.js";
|
||||
|
||||
/** Match Electron's supported module entry points. */
|
||||
@@ -23,7 +24,7 @@ export const electronExportPath = (
|
||||
|
||||
/** Static identity recovery cannot establish the absence of Electron usage. */
|
||||
export const ELECTRON_IDENTITY_LIMITATION =
|
||||
"Electron API identity follows proven lexical module aliases and structurally verified module-namespace interop. Other reassignments, dynamic selections, and visibly overwritten namespace members are unresolved; missing findings do not establish absence. Arbitrary call side effects and runtime registration are not evaluated.";
|
||||
"Electron API identity follows proven lexical module aliases, including results of namespace interop helpers (__toESM, __importStar, _interopRequireWildcard) recognized by name and a single program-scope function definition; helper bodies are not evaluated. Other reassigned bindings, dynamic selections, and visibly overwritten namespace members are unresolved; missing findings do not establish absence. Arbitrary call side effects and runtime registration are not evaluated.";
|
||||
|
||||
/** Preserve exact property segments instead of flattening literal dotted keys. */
|
||||
export const electronMemberPath = (
|
||||
@@ -41,98 +42,14 @@ export const electronMemberPath = (
|
||||
return { root, members: members.toReversed() };
|
||||
};
|
||||
|
||||
/** A known intrinsic callable and its examined positional arguments. */
|
||||
export interface JavaScriptIntrinsicInvocation {
|
||||
readonly kind: "known" | "opaque";
|
||||
/** The original bound receiver; rebinding cannot replace it. */
|
||||
readonly receiver?: t.Node;
|
||||
readonly path: readonly string[];
|
||||
readonly arguments:
|
||||
| readonly t.CallExpression["arguments"][number][]
|
||||
| undefined;
|
||||
}
|
||||
|
||||
/** Index member and binding writes through caller-proven lexical identities. */
|
||||
export function* collectJavaScriptIdentityWritesSteps(
|
||||
/** Index visible writes through proven Electron aliases, without executing them. */
|
||||
export function* collectElectronMemberWritesSteps(
|
||||
program: t.Program,
|
||||
origin: (
|
||||
root: t.Node,
|
||||
kind: "binding" | "member" | "opaque-call",
|
||||
) => readonly string[] | undefined,
|
||||
intrinsicInvocation: (
|
||||
node: t.CallExpression | t.OptionalCallExpression,
|
||||
) => JavaScriptIntrinsicInvocation | undefined,
|
||||
staticString: (node: t.Node | undefined) => string | undefined,
|
||||
freshObject: (node: t.Node) => boolean,
|
||||
retain: (node: t.Node, path: readonly (string | null)[]) => void,
|
||||
): Generator<void> {
|
||||
const objectMutators = new Set([
|
||||
"defineProperty",
|
||||
"defineProperties",
|
||||
"assign",
|
||||
"setPrototypeOf",
|
||||
]);
|
||||
const reflectMutators = new Set([
|
||||
"set",
|
||||
"deleteProperty",
|
||||
"defineProperty",
|
||||
"setPrototypeOf",
|
||||
]);
|
||||
const keyedMutators = new Set(["set", "deleteProperty", "defineProperty"]);
|
||||
origin: (root: t.Node) => readonly string[] | undefined,
|
||||
): Generator<void, SemanticPropertyPathCoverage> {
|
||||
const writes = new SemanticPropertyPathCoverage();
|
||||
yield* traverseJavaScriptAstSteps(program, {
|
||||
enter: (node) => {
|
||||
if (t.isCallExpression(node) || t.isOptionalCallExpression(node)) {
|
||||
const invocation = intrinsicInvocation(node);
|
||||
if (invocation?.kind === "opaque") {
|
||||
const scope = origin(node, "opaque-call");
|
||||
if (scope !== undefined) retain(node, scope);
|
||||
return;
|
||||
}
|
||||
const callee = invocation?.path;
|
||||
const arguments_ = invocation?.arguments;
|
||||
const method = callee?.at(-1);
|
||||
const owner = callee?.length === 3 ? callee[1] : undefined;
|
||||
if (
|
||||
(owner === "Object" && objectMutators.has(method ?? "")) ||
|
||||
(owner === "Reflect" && reflectMutators.has(method ?? ""))
|
||||
) {
|
||||
// Reflect.set can write through its explicit receiver as well as
|
||||
// dispatching through its target. Both identities need examination.
|
||||
const targets =
|
||||
owner === "Reflect" &&
|
||||
method === "set" &&
|
||||
arguments_ !== undefined &&
|
||||
(arguments_.length >= 4 || arguments_.some(t.isSpreadElement))
|
||||
? [
|
||||
arguments_[0],
|
||||
arguments_.some(t.isSpreadElement)
|
||||
? undefined
|
||||
: arguments_[3],
|
||||
]
|
||||
: [arguments_?.[0]];
|
||||
for (const target of targets) {
|
||||
// A known mutator with an opaque argument list can overwrite any
|
||||
// captured intrinsic. Do not turn an unexamined target into proof.
|
||||
if (target === undefined || t.isSpreadElement(target)) {
|
||||
const scope = origin(node, "opaque-call");
|
||||
if (scope !== undefined) retain(node, scope);
|
||||
}
|
||||
if (t.isNode(target) && !t.isSpreadElement(target)) {
|
||||
const { root, members } = electronMemberPath(target);
|
||||
const exported = origin(root, "member");
|
||||
if (exported !== undefined) {
|
||||
const key = keyedMutators.has(method ?? "")
|
||||
? [staticString(arguments_?.[1]) ?? null]
|
||||
: [];
|
||||
retain(node, [...exported, ...members, ...key]);
|
||||
} else if (!freshObject(target)) {
|
||||
const scope = origin(node, "opaque-call");
|
||||
if (scope !== undefined) retain(node, scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const target = t.isAssignmentExpression(node)
|
||||
? node.left
|
||||
: t.isUpdateExpression(node)
|
||||
@@ -143,16 +60,12 @@ export function* collectJavaScriptIdentityWritesSteps(
|
||||
? node.left
|
||||
: undefined;
|
||||
if (target === undefined) return;
|
||||
for (const leaf of semanticWriteTargets(target)) {
|
||||
if (t.isIdentifier(leaf)) {
|
||||
const exported = origin(leaf, "binding");
|
||||
if (exported !== undefined) retain(node, exported);
|
||||
continue;
|
||||
}
|
||||
const { root, members } = electronMemberPath(leaf);
|
||||
const exported = origin(root, "member");
|
||||
if (exported !== undefined) retain(node, [...exported, ...members]);
|
||||
for (const member of semanticMemberWriteTargets(target)) {
|
||||
const { root, members } = electronMemberPath(member);
|
||||
const exported = origin(root);
|
||||
if (exported !== undefined) writes.retain([...exported, ...members]);
|
||||
}
|
||||
},
|
||||
});
|
||||
return writes;
|
||||
}
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
import * as t from "@babel/types";
|
||||
|
||||
import type { JavaScriptIntrinsicInvocation } from "./javascriptElectronMemberWrites.js";
|
||||
import {
|
||||
semanticStaticPropertyKey,
|
||||
unwrapJavaScriptExpression,
|
||||
} from "./javascriptAstValues.js";
|
||||
|
||||
const arrayArguments = (array: t.Node | undefined) =>
|
||||
t.isArrayExpression(array) &&
|
||||
array.elements.every((element) => t.isExpression(element))
|
||||
? array.elements.filter((element): element is t.Expression =>
|
||||
t.isExpression(element),
|
||||
)
|
||||
: undefined;
|
||||
|
||||
const invocationArguments = (
|
||||
method: "call" | "apply",
|
||||
arguments_: JavaScriptIntrinsicInvocation["arguments"],
|
||||
) =>
|
||||
t.isSpreadElement(arguments_?.[0])
|
||||
? undefined
|
||||
: method === "apply"
|
||||
? arrayArguments(arguments_?.[1])
|
||||
: arguments_?.slice(1);
|
||||
|
||||
/**
|
||||
* Normalize known invocation syntax once, retaining bound argument prefixes.
|
||||
* Binding a function alone is not a write; only its eventual call is examined.
|
||||
*/
|
||||
export const resolveJavaScriptIntrinsicInvocation = (
|
||||
node: t.CallExpression | t.OptionalCallExpression,
|
||||
intrinsicPath: (node: t.Node) => readonly string[] | undefined,
|
||||
boundIntrinsic: (node: t.Node) => JavaScriptIntrinsicInvocation | undefined,
|
||||
intrinsicReadChanged: (node: t.Node, path: readonly string[]) => boolean,
|
||||
): JavaScriptIntrinsicInvocation | undefined => {
|
||||
const visited = new Set<t.Node>();
|
||||
let callee: t.Node = node.callee;
|
||||
let arguments_: JavaScriptIntrinsicInvocation["arguments"] = node.arguments;
|
||||
let receiver: t.Node | undefined;
|
||||
let explicitReceiver = false;
|
||||
for (;;) {
|
||||
callee = unwrapJavaScriptExpression(callee).node;
|
||||
if (visited.has(callee)) return undefined;
|
||||
visited.add(callee);
|
||||
let path = intrinsicPath(callee);
|
||||
if (path !== undefined && intrinsicReadChanged(callee, path))
|
||||
return { kind: "opaque", path, arguments: undefined };
|
||||
if (path === undefined) {
|
||||
if (
|
||||
t.isMemberExpression(callee) ||
|
||||
t.isOptionalMemberExpression(callee)
|
||||
) {
|
||||
const method = semanticStaticPropertyKey(
|
||||
callee.property,
|
||||
callee.computed,
|
||||
);
|
||||
if (method === "call" || method === "apply") {
|
||||
const bound = boundIntrinsic(callee.object);
|
||||
if (
|
||||
bound !== undefined &&
|
||||
intrinsicReadChanged(callee, [...bound.path, method])
|
||||
)
|
||||
return { kind: "opaque", path: bound.path, arguments: undefined };
|
||||
receiver = arguments_?.[0];
|
||||
explicitReceiver = true;
|
||||
callee = callee.object;
|
||||
arguments_ = invocationArguments(method, arguments_);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const bound = boundIntrinsic(callee);
|
||||
if (bound === undefined) return undefined;
|
||||
if (bound.kind === "opaque") return bound;
|
||||
path = bound.path;
|
||||
receiver = bound.receiver;
|
||||
explicitReceiver = true;
|
||||
arguments_ =
|
||||
bound.arguments === undefined
|
||||
? undefined
|
||||
: [...bound.arguments, ...(arguments_ ?? [])];
|
||||
}
|
||||
const method = path.length > 3 ? path.at(-1) : undefined;
|
||||
if (method === "call" || method === "apply") {
|
||||
// These properties hold generic function values. Their receiver selects
|
||||
// the callable; property-chain depth does not consume more arguments.
|
||||
const callable: t.Node | undefined = explicitReceiver
|
||||
? receiver
|
||||
: t.isMemberExpression(callee) || t.isOptionalMemberExpression(callee)
|
||||
? callee.object
|
||||
: undefined;
|
||||
if (!t.isExpression(callable)) return undefined;
|
||||
callee = callable;
|
||||
receiver = arguments_?.[0];
|
||||
explicitReceiver = true;
|
||||
arguments_ = invocationArguments(method, arguments_);
|
||||
continue;
|
||||
}
|
||||
if (path.join(".") === "intrinsic.Reflect.apply") {
|
||||
const callable = arguments_?.[0];
|
||||
if (!t.isExpression(callable)) return undefined;
|
||||
callee = callable;
|
||||
receiver = arguments_?.[1];
|
||||
explicitReceiver = true;
|
||||
arguments_ = arrayArguments(arguments_?.[2]);
|
||||
continue;
|
||||
}
|
||||
return {
|
||||
kind: "known",
|
||||
path,
|
||||
arguments: arguments_,
|
||||
...(receiver === undefined ? {} : { receiver }),
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
// Rolldown runtime from the public T3 Code nightly 20261011.2967 main.cjs.
|
||||
// The input is inert source: none of these helpers or Electron APIs is executed.
|
||||
export const ROLLDOWN_MODULE_INTEROP = `
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
||||
value: mod,
|
||||
enumerable: true
|
||||
}) : target, mod));
|
||||
`;
|
||||
@@ -1,774 +0,0 @@
|
||||
import { parseExpression } from "@babel/parser";
|
||||
import * as t from "@babel/types";
|
||||
|
||||
import type { JavaScriptModuleOrigin } from "./javascriptSemanticIr.js";
|
||||
import {
|
||||
isUnshadowedGlobal,
|
||||
resolveSemanticBindingState,
|
||||
semanticScopeId,
|
||||
semanticStableInitializer,
|
||||
type JavaScriptSemanticAnalysisState,
|
||||
type JavaScriptSemanticBindingState,
|
||||
} from "./javascriptSemanticState.js";
|
||||
import { semanticRequireOrigin } from "./javascriptSemanticRequireOrigin.js";
|
||||
import {
|
||||
childNodes,
|
||||
javaScriptAstChildKeys,
|
||||
} from "./javascriptSemanticTraversal.js";
|
||||
import {
|
||||
electronMemberPath,
|
||||
type JavaScriptIntrinsicInvocation,
|
||||
} from "./javascriptElectronMemberWrites.js";
|
||||
import { resolveJavaScriptIntrinsicInvocation } from "./javascriptIntrinsicInvocation.js";
|
||||
import { SemanticPropertyPathCoverage } from "./javascriptSemanticPropertyPaths.js";
|
||||
import {
|
||||
readExactJavaScriptLiteral,
|
||||
unwrapJavaScriptExpression,
|
||||
} from "./javascriptAstValues.js";
|
||||
|
||||
// Match the complete Rolldown runtime operations, including its live getters.
|
||||
// Names and formatting are irrelevant; lexical roles, operators and keys are not.
|
||||
const TO_ESM = parseExpression(`(mod, isNodeMode, target) => (
|
||||
target = mod != null ? __create(__getProtoOf(mod)) : {},
|
||||
__copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default")
|
||||
? __defProp(target, "default", {value: mod, enumerable: true}) : target, mod)
|
||||
)`);
|
||||
const COPY_PROPS = parseExpression(`(to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function")
|
||||
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
return to;
|
||||
}`);
|
||||
const INTRINSICS: Readonly<Record<string, readonly string[]>> = {
|
||||
__create: ["Object", "create"],
|
||||
__getProtoOf: ["Object", "getPrototypeOf"],
|
||||
__defProp: ["Object", "defineProperty"],
|
||||
__getOwnPropNames: ["Object", "getOwnPropertyNames"],
|
||||
__getOwnPropDesc: ["Object", "getOwnPropertyDescriptor"],
|
||||
__hasOwnProp: ["Object", "prototype", "hasOwnProperty"],
|
||||
};
|
||||
|
||||
interface IntrinsicDependency {
|
||||
readonly path: readonly string[];
|
||||
readonly capturedAt?: t.Node;
|
||||
}
|
||||
|
||||
interface InteropOrigin {
|
||||
readonly origin: JavaScriptModuleOrigin;
|
||||
readonly dependencies: readonly IntrinsicDependency[];
|
||||
readonly defaultIsModule: boolean;
|
||||
}
|
||||
|
||||
interface InteropHelper {
|
||||
readonly dependencies: readonly IntrinsicDependency[];
|
||||
readonly readyAfter: number;
|
||||
readonly identity: boolean;
|
||||
}
|
||||
|
||||
/** Prove one inert namespace conversion without relaxing general assignment semantics. */
|
||||
export const createSemanticModuleInterop = (
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
) => {
|
||||
const helpers = new Map<string, InteropHelper | null>();
|
||||
const origins = new Map<string, InteropOrigin>();
|
||||
const calls = new WeakMap<t.Node, InteropOrigin>();
|
||||
const intrinsicBindings = new Map<string, readonly string[] | null>();
|
||||
const writes: {
|
||||
readonly scope: string;
|
||||
readonly offset: number;
|
||||
readonly coverage: SemanticPropertyPathCoverage;
|
||||
}[] = [];
|
||||
const invalidatedBindings = new Map<string, boolean>();
|
||||
const invalidatedCalls = new WeakMap<t.Node, boolean>();
|
||||
const opaqueMutationPath = (node: t.Node): readonly string[] => {
|
||||
let current: t.Node | undefined = node;
|
||||
while (current !== undefined) {
|
||||
if (t.isFunction(current))
|
||||
return ["opaque-intrinsic", semanticScopeId("function", current)];
|
||||
current = state.parentsByNode.get(current);
|
||||
}
|
||||
return ["intrinsic"];
|
||||
};
|
||||
|
||||
const intrinsicPath = (node: t.Node): readonly string[] | undefined => {
|
||||
let current = node;
|
||||
const visited = new Set<string>();
|
||||
const pending: { id: string; suffixLength: number }[] = [];
|
||||
let suffix: readonly string[] = [];
|
||||
const finish = (
|
||||
path: readonly string[] | undefined,
|
||||
): readonly string[] | undefined => {
|
||||
for (const binding of pending)
|
||||
intrinsicBindings.set(
|
||||
binding.id,
|
||||
path === undefined
|
||||
? null
|
||||
: path.slice(0, path.length - binding.suffixLength),
|
||||
);
|
||||
return path;
|
||||
};
|
||||
for (;;) {
|
||||
const { root, members } = electronMemberPath(current);
|
||||
if (members.some((member) => member === null)) return finish(undefined);
|
||||
suffix = [...(members as readonly string[]), ...suffix];
|
||||
for (const global of ["Object", "Function", "Reflect"])
|
||||
if (isUnshadowedGlobal(root, state, global))
|
||||
return finish(["intrinsic", global, ...suffix]);
|
||||
for (const global of ["globalThis", "global", "window", "self"])
|
||||
if (isUnshadowedGlobal(root, state, global))
|
||||
return finish(["intrinsic", ...suffix]);
|
||||
if (!t.isIdentifier(root)) return finish(undefined);
|
||||
const binding = resolveSemanticBindingState(state, root, root.name);
|
||||
const cached =
|
||||
binding === undefined
|
||||
? undefined
|
||||
: intrinsicBindings.get(binding.bindingId);
|
||||
if (cached !== undefined)
|
||||
return finish(cached === null ? undefined : [...cached, ...suffix]);
|
||||
const initializer = semanticStableInitializer(binding, state);
|
||||
if (
|
||||
binding === undefined ||
|
||||
initializer === undefined ||
|
||||
initializer.projection.some((segment) => segment === null) ||
|
||||
visited.has(binding.bindingId)
|
||||
)
|
||||
return finish(undefined);
|
||||
visited.add(binding.bindingId);
|
||||
pending.push({ id: binding.bindingId, suffixLength: suffix.length });
|
||||
suffix = [...initializer.projection.map(String), ...suffix];
|
||||
current = initializer.node;
|
||||
}
|
||||
};
|
||||
|
||||
// A nominal alias path is sufficient for conservative mutation lookup, but
|
||||
// helper proof also needs each read to follow initialization. An alias copy
|
||||
// retains the earlier function capture; a member read captures it anew.
|
||||
const capturedIntrinsic = (node: t.Node): IntrinsicDependency | undefined => {
|
||||
const path = intrinsicPath(node);
|
||||
if (path === undefined) return undefined;
|
||||
const visited = new Set<string>();
|
||||
let current = node;
|
||||
let capturedAt = node;
|
||||
let suffixLength = 0;
|
||||
for (;;) {
|
||||
const { root, members } = electronMemberPath(current);
|
||||
suffixLength += members.length;
|
||||
if (!t.isIdentifier(root)) return undefined;
|
||||
const binding = resolveSemanticBindingState(state, root, root.name);
|
||||
if (binding === undefined) return { path, capturedAt };
|
||||
const initializer = semanticStableInitializer(binding, state);
|
||||
if (
|
||||
initializer === undefined ||
|
||||
(initializer.node.end ?? Infinity) >= (root.start ?? -1) ||
|
||||
visited.has(binding.bindingId)
|
||||
)
|
||||
return undefined;
|
||||
visited.add(binding.bindingId);
|
||||
if (suffixLength === 0) capturedAt = initializer.node;
|
||||
suffixLength += initializer.projection.length;
|
||||
current = initializer.node;
|
||||
}
|
||||
};
|
||||
|
||||
const staticString = (node: t.Node | undefined): string | undefined => {
|
||||
if (node === undefined) return undefined;
|
||||
const visited = new Set<string>();
|
||||
let current = node;
|
||||
for (;;) {
|
||||
const literal = readExactJavaScriptLiteral(current);
|
||||
if (literal.found)
|
||||
return typeof literal.value === "string" ? literal.value : undefined;
|
||||
const expression = unwrapJavaScriptExpression(current).node;
|
||||
if (!t.isIdentifier(expression)) return undefined;
|
||||
const binding = resolveSemanticBindingState(
|
||||
state,
|
||||
expression,
|
||||
expression.name,
|
||||
);
|
||||
const initializer = semanticStableInitializer(binding, state);
|
||||
if (
|
||||
binding === undefined ||
|
||||
initializer === undefined ||
|
||||
initializer.projection.length !== 0 ||
|
||||
(initializer.node.end ?? Infinity) >= (expression.start ?? -1) ||
|
||||
visited.has(binding.bindingId)
|
||||
)
|
||||
return undefined;
|
||||
visited.add(binding.bindingId);
|
||||
current = initializer.node;
|
||||
}
|
||||
};
|
||||
|
||||
const intrinsicReadChanged = (
|
||||
node: t.Node,
|
||||
path: readonly string[],
|
||||
): boolean => {
|
||||
const capture = capturedIntrinsic(node)?.capturedAt ?? node;
|
||||
const scope = opaqueMutationPath(capture).join(".");
|
||||
const method = path.at(-1);
|
||||
const invocationMethod =
|
||||
method === "bind" || method === "call" || method === "apply";
|
||||
return writes.some(
|
||||
(write) =>
|
||||
(write.scope === scope || write.scope === "intrinsic") &&
|
||||
write.offset < (capture.start ?? -1) &&
|
||||
(write.coverage.covers(path) ||
|
||||
(invocationMethod &&
|
||||
write.coverage.covers([
|
||||
"intrinsic",
|
||||
"Function",
|
||||
"prototype",
|
||||
method,
|
||||
]))),
|
||||
);
|
||||
};
|
||||
|
||||
const resolveBoundIntrinsic = (
|
||||
node: t.Node,
|
||||
): JavaScriptIntrinsicInvocation | undefined => {
|
||||
const visited = new Set<string>();
|
||||
const argumentGroups: t.CallExpression["arguments"][] = [];
|
||||
const bindReads: t.Node[] = [];
|
||||
let opaqueArguments = false;
|
||||
let receiver: t.Node | undefined;
|
||||
let current = node;
|
||||
for (;;) {
|
||||
current = unwrapJavaScriptExpression(current).node;
|
||||
if (t.isIdentifier(current)) {
|
||||
const binding = resolveSemanticBindingState(
|
||||
state,
|
||||
current,
|
||||
current.name,
|
||||
);
|
||||
const initializer = semanticStableInitializer(binding, state);
|
||||
if (
|
||||
binding === undefined ||
|
||||
initializer === undefined ||
|
||||
initializer.projection.length !== 0 ||
|
||||
(initializer.node.end ?? Infinity) >= (current.start ?? -1) ||
|
||||
visited.has(binding.bindingId)
|
||||
)
|
||||
return undefined;
|
||||
visited.add(binding.bindingId);
|
||||
current = initializer.node;
|
||||
continue;
|
||||
}
|
||||
if (!t.isCallExpression(current)) return undefined;
|
||||
const { root, members } = electronMemberPath(current.callee);
|
||||
let bindTarget = root;
|
||||
let bindingArguments: JavaScriptIntrinsicInvocation["arguments"] =
|
||||
current.arguments;
|
||||
let captured = capturedIntrinsic(current.callee);
|
||||
let terminal = captured?.path.at(-1) === "bind";
|
||||
let path: readonly string[] | undefined = captured?.path.slice(0, -1);
|
||||
if (members.at(-1) === "bind") {
|
||||
// A direct .bind may continue a bound callable, without discarding members.
|
||||
if (!terminal && members.length !== 1) return undefined;
|
||||
bindReads.push(captured?.capturedAt ?? current.callee);
|
||||
} else {
|
||||
// Reuse the invocation owner for generic call/apply/Reflect.apply of bind.
|
||||
const invocation = resolveJavaScriptIntrinsicInvocation(
|
||||
current,
|
||||
intrinsicPath,
|
||||
boundIntrinsic,
|
||||
intrinsicReadChanged,
|
||||
);
|
||||
if (
|
||||
invocation?.kind !== "known" ||
|
||||
invocation.path.join(".") !== "intrinsic.Function.prototype.bind" ||
|
||||
invocation.receiver === undefined
|
||||
)
|
||||
return undefined;
|
||||
bindTarget = invocation.receiver;
|
||||
bindingArguments = invocation.arguments;
|
||||
captured = capturedIntrinsic(bindTarget);
|
||||
terminal = captured !== undefined;
|
||||
path = captured?.path;
|
||||
}
|
||||
receiver = bindingArguments?.[0];
|
||||
const ownArguments = bindingArguments?.slice(1) ?? [];
|
||||
opaqueArguments ||=
|
||||
bindingArguments === undefined || t.isSpreadElement(receiver);
|
||||
opaqueArguments ||= ownArguments.some((argument) =>
|
||||
t.isSpreadElement(argument),
|
||||
);
|
||||
argumentGroups.push(ownArguments);
|
||||
if (!terminal || path === undefined) {
|
||||
current = bindTarget;
|
||||
continue;
|
||||
}
|
||||
const boundPath = [...path, "bind"];
|
||||
const functionBind = ["intrinsic", "Function", "prototype", "bind"];
|
||||
opaqueArguments ||= bindReads.some((capture) => {
|
||||
const scope = opaqueMutationPath(capture).join(".");
|
||||
return writes.some(
|
||||
(write) =>
|
||||
(write.scope === scope || write.scope === "intrinsic") &&
|
||||
write.offset < (capture.start ?? -1) &&
|
||||
(write.coverage.covers(boundPath) ||
|
||||
write.coverage.covers(functionBind)),
|
||||
);
|
||||
});
|
||||
return {
|
||||
kind: opaqueArguments ? "opaque" : "known",
|
||||
path,
|
||||
...(receiver === undefined ? {} : { receiver }),
|
||||
// Rebinding appends arguments to the earlier bound argument list.
|
||||
arguments: opaqueArguments
|
||||
? undefined
|
||||
: argumentGroups.toReversed().flat(),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const activeBoundValues = new WeakSet<t.Node>();
|
||||
const boundIntrinsic = (
|
||||
node: t.Node,
|
||||
): JavaScriptIntrinsicInvocation | undefined => {
|
||||
if (activeBoundValues.has(node)) return undefined;
|
||||
activeBoundValues.add(node);
|
||||
try {
|
||||
return resolveBoundIntrinsic(node);
|
||||
} finally {
|
||||
activeBoundValues.delete(node);
|
||||
}
|
||||
};
|
||||
|
||||
const isFreshObject = (node: t.Node): boolean => {
|
||||
const visited = new Set<string>();
|
||||
let current = node;
|
||||
for (;;) {
|
||||
current = unwrapJavaScriptExpression(current).node;
|
||||
if (
|
||||
t.isObjectExpression(current) ||
|
||||
t.isArrayExpression(current) ||
|
||||
t.isFunction(current) ||
|
||||
(t.isClass(current) && !current.decorators?.length) ||
|
||||
t.isRegExpLiteral(current)
|
||||
)
|
||||
return true;
|
||||
if (!t.isIdentifier(current)) return false;
|
||||
const binding = resolveSemanticBindingState(state, current, current.name);
|
||||
const initializer = unprojectedInitializer(binding, state);
|
||||
if (
|
||||
binding === undefined ||
|
||||
initializer === undefined ||
|
||||
(!t.isFunctionDeclaration(initializer) &&
|
||||
(initializer.end ?? Infinity) >= (current.start ?? -1)) ||
|
||||
visited.has(binding.bindingId)
|
||||
)
|
||||
return false;
|
||||
visited.add(binding.bindingId);
|
||||
current = initializer;
|
||||
}
|
||||
};
|
||||
|
||||
const helperProof = (
|
||||
binding: JavaScriptSemanticBindingState,
|
||||
): InteropHelper | undefined => {
|
||||
const cached = helpers.get(binding.bindingId);
|
||||
if (cached !== undefined) return cached ?? undefined;
|
||||
helpers.set(binding.bindingId, null);
|
||||
if (state.scopesById.get(binding.scopeId)?.kind !== "program")
|
||||
return undefined;
|
||||
const wrapper = unprojectedInitializer(binding, state);
|
||||
if (wrapper === undefined) return undefined;
|
||||
if (identityFunction(wrapper, state)) {
|
||||
const proof = {
|
||||
dependencies: [],
|
||||
readyAfter: t.isFunctionDeclaration(wrapper)
|
||||
? -1
|
||||
: (wrapper.end ?? Infinity),
|
||||
identity: true,
|
||||
};
|
||||
helpers.set(binding.bindingId, proof);
|
||||
return proof;
|
||||
}
|
||||
const wrapperRoles = canonicalRoles(wrapper, TO_ESM, state);
|
||||
const copyBinding = wrapperRoles?.get("__copyProps");
|
||||
const copy = unprojectedInitializer(copyBinding, state);
|
||||
const copyRoles =
|
||||
copy === undefined ? undefined : canonicalRoles(copy, COPY_PROPS, state);
|
||||
if (
|
||||
wrapperRoles === undefined ||
|
||||
copyRoles === undefined ||
|
||||
copy === undefined
|
||||
)
|
||||
return undefined;
|
||||
const dependencies: IntrinsicDependency[] = [];
|
||||
let readyAfter = Math.max(wrapper.end ?? Infinity, copy.end ?? Infinity);
|
||||
for (const roles of [wrapperRoles, copyRoles])
|
||||
for (const [role, dependency] of roles) {
|
||||
const expected = INTRINSICS[role];
|
||||
if (expected === undefined) continue;
|
||||
const initializer = unprojectedInitializer(dependency, state);
|
||||
const captured =
|
||||
initializer === undefined
|
||||
? undefined
|
||||
: capturedIntrinsic(initializer);
|
||||
if (
|
||||
initializer === undefined ||
|
||||
captured === undefined ||
|
||||
JSON.stringify(captured.path) !==
|
||||
JSON.stringify(["intrinsic", ...expected])
|
||||
)
|
||||
return undefined;
|
||||
readyAfter = Math.max(readyAfter, initializer.end ?? Infinity);
|
||||
dependencies.push(captured);
|
||||
if (role === "__hasOwnProp")
|
||||
dependencies.push({ path: [...captured.path, "call"] });
|
||||
}
|
||||
dependencies.push(
|
||||
{ path: ["intrinsic", "Function", "prototype", "bind"] },
|
||||
{ path: ["intrinsic", "Function", "prototype", "call"] },
|
||||
);
|
||||
const proof = {
|
||||
dependencies,
|
||||
identity: false,
|
||||
readyAfter,
|
||||
};
|
||||
helpers.set(binding.bindingId, proof);
|
||||
return proof;
|
||||
};
|
||||
|
||||
const provenCall = (node: t.Node) => {
|
||||
if (!t.isCallExpression(node) || !t.isIdentifier(node.callee))
|
||||
return undefined;
|
||||
const helper = resolveSemanticBindingState(
|
||||
state,
|
||||
node.callee,
|
||||
node.callee.name,
|
||||
);
|
||||
const proof = helper === undefined ? undefined : helperProof(helper);
|
||||
const input = node.arguments[0];
|
||||
const mode = node.arguments[1];
|
||||
const literalMode =
|
||||
mode === undefined
|
||||
? { found: true, value: false }
|
||||
: t.isExpression(mode)
|
||||
? readExactJavaScriptLiteral(mode)
|
||||
: { found: false };
|
||||
if (
|
||||
proof === undefined ||
|
||||
proof.readyAfter >= (node.start ?? -1) ||
|
||||
!t.isExpression(input) ||
|
||||
node.arguments.length > 2 ||
|
||||
!literalMode.found
|
||||
)
|
||||
return undefined;
|
||||
return {
|
||||
input,
|
||||
// A truthy node mode forces the module-valued default. Other modes
|
||||
// preserve named exports without proving the source's default property.
|
||||
defaultIsModule: !proof.identity && Boolean(literalMode.value),
|
||||
dependencies: proof.dependencies.map((dependency) => ({
|
||||
...dependency,
|
||||
capturedAt: dependency.capturedAt ?? node,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
const callOrigin = (node: t.Node): InteropOrigin | undefined => {
|
||||
const cached = calls.get(node);
|
||||
if (cached !== undefined) return cached;
|
||||
const { root, members } = electronMemberPath(node);
|
||||
if (!members.every((member): member is string => member !== null))
|
||||
return undefined;
|
||||
const converted = provenCall(root);
|
||||
const required =
|
||||
converted === undefined
|
||||
? undefined
|
||||
: semanticRequireOrigin(converted.input, state)?.origin;
|
||||
if (
|
||||
converted === undefined ||
|
||||
required === undefined ||
|
||||
required.importedPath.length !== 0 ||
|
||||
(members[0] === "default" && !converted.defaultIsModule)
|
||||
)
|
||||
return undefined;
|
||||
const result = {
|
||||
origin: { ...required, importedPath: members },
|
||||
dependencies: converted.dependencies,
|
||||
defaultIsModule: converted.defaultIsModule,
|
||||
};
|
||||
calls.set(node, result);
|
||||
return result;
|
||||
};
|
||||
|
||||
const origin = (
|
||||
binding: JavaScriptSemanticBindingState,
|
||||
): InteropOrigin | undefined => {
|
||||
const single = semanticStableInitializer(binding, state);
|
||||
if (single !== undefined) {
|
||||
if (
|
||||
!single.projection.every(
|
||||
(key): key is string => typeof key === "string",
|
||||
)
|
||||
)
|
||||
return undefined;
|
||||
const converted = callOrigin(single.node);
|
||||
if (
|
||||
converted?.origin.importedPath.length === 0 &&
|
||||
single.projection[0] === "default" &&
|
||||
!converted.defaultIsModule
|
||||
)
|
||||
return undefined;
|
||||
const result =
|
||||
converted === undefined
|
||||
? undefined
|
||||
: {
|
||||
...converted,
|
||||
origin: {
|
||||
...converted.origin,
|
||||
importedPath: [
|
||||
...converted.origin.importedPath,
|
||||
...single.projection,
|
||||
],
|
||||
},
|
||||
};
|
||||
if (result !== undefined) origins.set(binding.bindingId, result);
|
||||
return result;
|
||||
}
|
||||
const [initial, converted] = binding.initializers;
|
||||
if (
|
||||
binding.definitions.length !== 2 ||
|
||||
binding.definitions[0]?.kind !== "variable" ||
|
||||
binding.definitions[1]?.kind !== "assignment" ||
|
||||
binding.initializers.length !== 2 ||
|
||||
initial === undefined ||
|
||||
converted === undefined ||
|
||||
initial.projection.length !== 0 ||
|
||||
converted.projection.length !== 0 ||
|
||||
state.conditionalInitializers.has(initial.node)
|
||||
)
|
||||
return undefined;
|
||||
const call = converted.node;
|
||||
const assignment = state.parentsByNode.get(call);
|
||||
const statement =
|
||||
assignment === undefined
|
||||
? undefined
|
||||
: state.parentsByNode.get(assignment);
|
||||
const declaration = state.parentsByNode.get(initial.node);
|
||||
const declarationStatement =
|
||||
declaration === undefined
|
||||
? undefined
|
||||
: state.parentsByNode.get(declaration);
|
||||
if (
|
||||
!t.isCallExpression(call) ||
|
||||
!t.isIdentifier(call.callee) ||
|
||||
!t.isAssignmentExpression(assignment, { operator: "=" }) ||
|
||||
assignment.right !== call ||
|
||||
!t.isIdentifier(assignment.left, { name: binding.name }) ||
|
||||
!t.isExpressionStatement(statement) ||
|
||||
!t.isVariableDeclarator(declaration) ||
|
||||
!t.isVariableDeclaration(declarationStatement) ||
|
||||
state.parentsByNode.get(statement) !==
|
||||
state.parentsByNode.get(declarationStatement) ||
|
||||
(initial.node.start ?? Infinity) >= (call.start ?? -1)
|
||||
)
|
||||
return undefined;
|
||||
const convertedCall = provenCall(call);
|
||||
const input = convertedCall?.input;
|
||||
if (
|
||||
!t.isIdentifier(input) ||
|
||||
resolveSemanticBindingState(state, input, input.name) !== binding
|
||||
)
|
||||
return undefined;
|
||||
const required = semanticRequireOrigin(initial.node, state)?.origin;
|
||||
if (required === undefined || required.importedPath.length !== 0)
|
||||
return undefined;
|
||||
if (convertedCall === undefined) return undefined;
|
||||
const result = {
|
||||
origin: required,
|
||||
dependencies: convertedCall.dependencies,
|
||||
defaultIsModule: convertedCall.defaultIsModule,
|
||||
};
|
||||
origins.set(binding.bindingId, result);
|
||||
return result;
|
||||
};
|
||||
const invalidatedOrigin = (record: InteropOrigin | undefined): boolean =>
|
||||
record?.dependencies.some(({ path, capturedAt }) => {
|
||||
if (capturedAt === undefined) return true;
|
||||
const scope = opaqueMutationPath(capturedAt).join(".");
|
||||
// Captured function values survive later replacement of global
|
||||
// properties. Other callable bodies are not execution evidence.
|
||||
return writes.some(
|
||||
(write) =>
|
||||
(write.scope === scope || write.scope === "intrinsic") &&
|
||||
write.offset < (capturedAt.start ?? -1) &&
|
||||
write.coverage.covers(path),
|
||||
);
|
||||
}) ?? false;
|
||||
return {
|
||||
origin,
|
||||
callOrigin,
|
||||
intrinsicPath,
|
||||
intrinsicInvocation: (node: t.CallExpression | t.OptionalCallExpression) =>
|
||||
resolveJavaScriptIntrinsicInvocation(
|
||||
node,
|
||||
intrinsicPath,
|
||||
boundIntrinsic,
|
||||
intrinsicReadChanged,
|
||||
),
|
||||
boundIntrinsic,
|
||||
staticString,
|
||||
isFreshObject,
|
||||
opaqueMutationPath,
|
||||
retainWrite: (node: t.Node, path: readonly (string | null)[]) => {
|
||||
const coverage = new SemanticPropertyPathCoverage();
|
||||
coverage.retain(path[0] === "opaque-intrinsic" ? ["intrinsic"] : path);
|
||||
writes.push({
|
||||
scope: opaqueMutationPath(node).join("."),
|
||||
offset: node.start ?? Infinity,
|
||||
coverage,
|
||||
});
|
||||
},
|
||||
invalidated: (binding: JavaScriptSemanticBindingState): boolean => {
|
||||
const cached = invalidatedBindings.get(binding.bindingId);
|
||||
if (cached !== undefined) return cached;
|
||||
const result = invalidatedOrigin(origins.get(binding.bindingId));
|
||||
invalidatedBindings.set(binding.bindingId, result);
|
||||
return result;
|
||||
},
|
||||
invalidatedCall: (node: t.Node): boolean => {
|
||||
const cached = invalidatedCalls.get(node);
|
||||
if (cached !== undefined) return cached;
|
||||
const result = invalidatedOrigin(calls.get(node));
|
||||
invalidatedCalls.set(node, result);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const identityFunction = (
|
||||
node: t.Node,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): boolean => {
|
||||
if (
|
||||
!t.isFunction(node) ||
|
||||
node.async ||
|
||||
node.generator ||
|
||||
node.params.length !== 1
|
||||
)
|
||||
return false;
|
||||
const parameter = node.params[0];
|
||||
const result = t.isBlockStatement(node.body)
|
||||
? node.body.body.length === 1 && t.isReturnStatement(node.body.body[0])
|
||||
? node.body.body[0].argument
|
||||
: undefined
|
||||
: node.body;
|
||||
return (
|
||||
t.isIdentifier(parameter) &&
|
||||
t.isIdentifier(result) &&
|
||||
resolveSemanticBindingState(state, parameter, parameter.name) !==
|
||||
undefined &&
|
||||
resolveSemanticBindingState(state, parameter, parameter.name) ===
|
||||
resolveSemanticBindingState(state, result, result.name)
|
||||
);
|
||||
};
|
||||
|
||||
const unprojectedInitializer = (
|
||||
binding: JavaScriptSemanticBindingState | undefined,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): t.Node | undefined => {
|
||||
const initializer = semanticStableInitializer(binding, state);
|
||||
return initializer?.projection.length === 0 ? initializer.node : undefined;
|
||||
};
|
||||
|
||||
/** Match operations and lexical roles, allowing single-statement control blocks. */
|
||||
const canonicalRoles = (
|
||||
actual: t.Node,
|
||||
pattern: t.Node,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): ReadonlyMap<string, JavaScriptSemanticBindingState> | undefined => {
|
||||
const roles = new Map<string, JavaScriptSemanticBindingState>();
|
||||
const used = new Map<string, string>();
|
||||
const pending: { actual: t.Node; pattern: t.Node; parent: t.Node | null }[] =
|
||||
[{ actual, pattern, parent: null }];
|
||||
while (pending.length !== 0) {
|
||||
const pair = pending.pop();
|
||||
if (pair === undefined) return undefined;
|
||||
const { parent } = pair;
|
||||
const controlBody =
|
||||
(t.isIfStatement(parent) &&
|
||||
(parent.consequent === pair.pattern ||
|
||||
parent.alternate === pair.pattern)) ||
|
||||
(t.isForStatement(parent) && parent.body === pair.pattern);
|
||||
const node = controlBody ? controlBodyOperation(pair.actual) : pair.actual;
|
||||
const expected = controlBody
|
||||
? controlBodyOperation(pair.pattern)
|
||||
: pair.pattern;
|
||||
if (node.type !== expected.type) return undefined;
|
||||
const literalKey =
|
||||
parent !== null &&
|
||||
((t.isMemberExpression(parent) &&
|
||||
!parent.computed &&
|
||||
parent.property === expected) ||
|
||||
(t.isObjectProperty(parent) &&
|
||||
!parent.computed &&
|
||||
parent.key === expected));
|
||||
if (t.isIdentifier(expected) && t.isIdentifier(node) && !literalKey) {
|
||||
const binding = resolveSemanticBindingState(state, node, node.name);
|
||||
if (
|
||||
binding === undefined ||
|
||||
(roles.has(expected.name) && roles.get(expected.name) !== binding) ||
|
||||
(used.has(binding.bindingId) &&
|
||||
used.get(binding.bindingId) !== expected.name)
|
||||
)
|
||||
return undefined;
|
||||
roles.set(expected.name, binding);
|
||||
used.set(binding.bindingId, expected.name);
|
||||
}
|
||||
const visitorKeys = javaScriptAstChildKeys(expected);
|
||||
for (const [key, field] of Object.entries(
|
||||
t.NODE_FIELDS[expected.type] ?? {},
|
||||
)) {
|
||||
if (
|
||||
visitorKeys.includes(key) ||
|
||||
(t.isIdentifier(expected) && key === "name" && !literalKey)
|
||||
)
|
||||
continue;
|
||||
const fallback: unknown = Reflect.get(field, "default");
|
||||
if (
|
||||
JSON.stringify(Reflect.get(node, key) ?? fallback) !==
|
||||
JSON.stringify(Reflect.get(expected, key) ?? fallback)
|
||||
)
|
||||
return undefined;
|
||||
}
|
||||
const children = childNodes(node),
|
||||
expectedChildren = childNodes(expected);
|
||||
if (children.length !== expectedChildren.length) return undefined;
|
||||
for (const [index, child] of children.entries()) {
|
||||
const expectedChild = expectedChildren[index];
|
||||
if (expectedChild !== undefined)
|
||||
pending.push({
|
||||
actual: child,
|
||||
pattern: expectedChild,
|
||||
parent: expected,
|
||||
});
|
||||
}
|
||||
}
|
||||
return roles;
|
||||
};
|
||||
|
||||
// Braces around one control-body statement do not add operations. Keep other
|
||||
// blocks, directives and extra statements intact; their semantics need proof.
|
||||
// Lexical declarations/references still pass through canonicalRoles' bijection.
|
||||
const controlBodyOperation = (node: t.Node): t.Node => {
|
||||
while (
|
||||
t.isBlockStatement(node) &&
|
||||
node.directives.length === 0 &&
|
||||
node.body.length === 1
|
||||
) {
|
||||
const statement = node.body[0];
|
||||
if (statement === undefined) break;
|
||||
node = statement;
|
||||
}
|
||||
return node;
|
||||
};
|
||||
@@ -195,32 +195,6 @@ describe("tRPC binding identity and bundled syntax", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("retains one client initializer across variable redeclarations", () => {
|
||||
expect(
|
||||
rpcEndpoints(`
|
||||
var c;
|
||||
var c = createTRPCClient({});
|
||||
var c;
|
||||
c.users.query();
|
||||
|
||||
var replaced;
|
||||
var replaced = createTRPCClient({});
|
||||
replaced = pool;
|
||||
replaced.posts.query();
|
||||
|
||||
var initializedTwice = createTRPCClient({});
|
||||
var initializedTwice = pool;
|
||||
initializedTwice.comments.query();
|
||||
|
||||
var conditional;
|
||||
if (flag) { var conditional = createTRPCClient({}); }
|
||||
conditional.groups.query();
|
||||
`),
|
||||
).toEqual([
|
||||
{ kind: "network", value: "users", mechanism: "trpc:procedure:query" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("recognizes surviving factory names inside bundled call wrappers", () => {
|
||||
expect(
|
||||
rpcEndpoints(`
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
import {
|
||||
semanticObjectPatternKeys,
|
||||
semanticStaticPropertyKey,
|
||||
semanticWriteTargets,
|
||||
} from "./javascriptAstValues.js";
|
||||
import type {
|
||||
JavaScriptSemanticAnalysisState,
|
||||
@@ -32,14 +31,16 @@ import {
|
||||
resolveSemanticBindingFromScope,
|
||||
semanticBindingId,
|
||||
semanticScopeId,
|
||||
semanticStableInitializer,
|
||||
semanticVariableScope,
|
||||
} from "./javascriptSemanticState.js";
|
||||
import {
|
||||
completeSemanticSteps,
|
||||
traverseJavaScriptAstSteps,
|
||||
} from "./javascriptSemanticTraversal.js";
|
||||
import { semanticRequireOrigin } from "./javascriptSemanticRequireOrigin.js";
|
||||
import {
|
||||
semanticNamespaceInteropOperand,
|
||||
semanticRequireOrigin,
|
||||
} from "./javascriptSemanticRequireOrigin.js";
|
||||
import { collectSemanticMemberMutationsSteps } from "./javascriptSemanticMemberMutations.js";
|
||||
import {
|
||||
collectSemanticReturns,
|
||||
@@ -48,7 +49,7 @@ import {
|
||||
import { collectJavaScriptDerivedSemanticsSteps } from "./javascriptSemanticDerivedAnalysis.js";
|
||||
import { evaluateSemanticProvenance } from "./javascriptSemanticValues.js";
|
||||
import {
|
||||
collectJavaScriptIdentityWritesSteps,
|
||||
collectElectronMemberWritesSteps,
|
||||
electronExportPath,
|
||||
electronMemberPath,
|
||||
ELECTRON_MODULE,
|
||||
@@ -63,8 +64,6 @@ import {
|
||||
} from "./javascriptSourceParser.js";
|
||||
|
||||
import { isJavaScriptRpcClientFactory } from "./javascriptRpcEndpoints.js";
|
||||
import { createSemanticModuleInterop } from "./javascriptModuleInterop.js";
|
||||
import { SemanticPropertyPathCoverage } from "./javascriptSemanticPropertyPaths.js";
|
||||
|
||||
interface BindPatternInput {
|
||||
readonly pattern: t.Node;
|
||||
@@ -206,10 +205,13 @@ export function* classifyParsedJavaScriptRpcClientRootsSteps(
|
||||
if (binding === undefined) return;
|
||||
let client = clients.get(binding.bindingId);
|
||||
if (client === undefined) {
|
||||
const initializer = semanticStableInitializer(binding, state);
|
||||
const [initializer] = binding.initializers;
|
||||
client =
|
||||
initializer !== undefined &&
|
||||
initializer.projection.length === 0 &&
|
||||
binding.initializers.length === 1 &&
|
||||
!binding.definitions.some(({ kind }) => kind === "assignment") &&
|
||||
!state.conditionalInitializers.has(initializer.node) &&
|
||||
isJavaScriptRpcClientFactory(initializer.node);
|
||||
clients.set(binding.bindingId, client);
|
||||
}
|
||||
@@ -372,9 +374,6 @@ export function* classifyParsedJavaScriptElectronBindingsSteps(
|
||||
const facts = new Map<number, readonly string[]>();
|
||||
const state = createState(file.program);
|
||||
yield* collectDefinitionsSteps(file.program, state);
|
||||
const interop = createSemanticModuleInterop(state);
|
||||
const writes = new SemanticPropertyPathCoverage();
|
||||
let collectedWrites = false;
|
||||
const exportsByBinding = new Map<string, readonly string[] | null>();
|
||||
const rootExport = (root: t.Node): readonly string[] | undefined => {
|
||||
if (t.isIdentifier(root)) {
|
||||
@@ -383,45 +382,23 @@ export function* classifyParsedJavaScriptElectronBindingsSteps(
|
||||
if (binding === undefined) return undefined;
|
||||
let exported = exportsByBinding.get(binding.bindingId);
|
||||
if (exported === undefined) {
|
||||
exported = electronExport(binding, state, interop);
|
||||
exported = electronExport(binding, state);
|
||||
exportsByBinding.set(binding.bindingId, exported);
|
||||
}
|
||||
return collectedWrites && interop.invalidated(binding)
|
||||
? undefined
|
||||
: (exported ?? undefined);
|
||||
return exported ?? undefined;
|
||||
}
|
||||
const wrapped = interop.callOrigin(root);
|
||||
const origin =
|
||||
wrapped === undefined
|
||||
? semanticRequireOrigin(root, state)?.origin
|
||||
: collectedWrites && interop.invalidatedCall(root)
|
||||
? undefined
|
||||
: wrapped.origin;
|
||||
const origin = semanticRequireOrigin(
|
||||
semanticNamespaceInteropOperand(root, state) ?? root,
|
||||
state,
|
||||
)?.origin;
|
||||
return origin !== undefined && ELECTRON_MODULE.test(origin.specifier)
|
||||
? electronExportPath(origin.importedPath)
|
||||
: undefined;
|
||||
};
|
||||
yield* collectJavaScriptIdentityWritesSteps(
|
||||
const writes = yield* collectElectronMemberWritesSteps(
|
||||
file.program,
|
||||
(root, kind) => {
|
||||
if (kind === "opaque-call") return interop.opaqueMutationPath(root);
|
||||
const exported = kind === "binding" ? undefined : rootExport(root);
|
||||
return exported === undefined
|
||||
? (interop.intrinsicPath(root) ??
|
||||
(kind === "member"
|
||||
? interop.boundIntrinsic(root)?.path
|
||||
: undefined))
|
||||
: ["electron", ...exported];
|
||||
},
|
||||
interop.intrinsicInvocation,
|
||||
interop.staticString,
|
||||
interop.isFreshObject,
|
||||
(node, path) => {
|
||||
if (path[0] === "electron") writes.retain(path);
|
||||
else interop.retainWrite(node, path);
|
||||
},
|
||||
rootExport,
|
||||
);
|
||||
collectedWrites = true;
|
||||
yield* traverseJavaScriptAstSteps(file.program, {
|
||||
enter: (node) => {
|
||||
if (
|
||||
@@ -432,10 +409,7 @@ export function* classifyParsedJavaScriptElectronBindingsSteps(
|
||||
return;
|
||||
const { root, members } = electronMemberPath(node.callee);
|
||||
const exported = rootExport(root);
|
||||
if (
|
||||
exported !== undefined &&
|
||||
!writes.covers(["electron", ...exported, ...members])
|
||||
)
|
||||
if (exported !== undefined && !writes.covers([...exported, ...members]))
|
||||
facts.set(root.start ?? -1, exported);
|
||||
},
|
||||
});
|
||||
@@ -447,16 +421,19 @@ export function* classifyParsedJavaScriptElectronBindingsSteps(
|
||||
const electronExport = (
|
||||
binding: JavaScriptSemanticBindingState,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
interop: ReturnType<typeof createSemanticModuleInterop>,
|
||||
): readonly string[] | null => {
|
||||
const reassigned = binding.definitions.some(
|
||||
({ kind }) => kind === "assignment",
|
||||
);
|
||||
const converted = interop.origin(binding);
|
||||
if (reassigned && converted === undefined) return null;
|
||||
const directOrigin = converted?.origin ?? bindingOrigin(binding, state);
|
||||
const initializer = semanticStableInitializer(binding, state);
|
||||
if (directOrigin === undefined && initializer === undefined) return null;
|
||||
const initializers = namespacePreservingInitializers(binding, state);
|
||||
if (initializers === undefined) return null;
|
||||
const directOrigin = bindingOrigin(binding, initializers, state);
|
||||
const [initializer] = initializers;
|
||||
if (
|
||||
directOrigin === undefined &&
|
||||
(initializer === undefined ||
|
||||
initializers.length !== 1 ||
|
||||
initializers.length !== binding.initializers.length ||
|
||||
state.conditionalInitializers.has(initializer.node))
|
||||
)
|
||||
return null;
|
||||
const provenance =
|
||||
directOrigin === undefined
|
||||
? evaluateSemanticProvenance(binding, state)
|
||||
@@ -471,17 +448,66 @@ const electronExport = (
|
||||
: null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the initializers that can change which module a binding names.
|
||||
* Bundlers emit `name = __toESM(name)` after a CommonJS require; rewrapping
|
||||
* the binding's own value keeps every member, so it is not a reassignment.
|
||||
*/
|
||||
const namespacePreservingInitializers = (
|
||||
binding: JavaScriptSemanticBindingState,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): JavaScriptSemanticBindingState["initializers"] | undefined => {
|
||||
const initializers = binding.initializers.filter(
|
||||
({ node }) => !rewrapsOwnNamespace(binding, node, state),
|
||||
);
|
||||
const rewraps = binding.initializers.length - initializers.length;
|
||||
const assignments = binding.definitions.filter(
|
||||
({ kind }) => kind === "assignment",
|
||||
).length;
|
||||
return assignments === rewraps ? initializers : undefined;
|
||||
};
|
||||
|
||||
const rewrapsOwnNamespace = (
|
||||
binding: JavaScriptSemanticBindingState,
|
||||
node: t.Node,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): boolean => {
|
||||
const assignment = state.parentsByNode.get(node);
|
||||
const operand = semanticNamespaceInteropOperand(node, state);
|
||||
return (
|
||||
t.isAssignmentExpression(assignment) &&
|
||||
assignment.operator === "=" &&
|
||||
assignment.right === node &&
|
||||
t.isIdentifier(assignment.left, { name: binding.name }) &&
|
||||
t.isIdentifier(operand, { name: binding.name }) &&
|
||||
!semanticResolutionBlocked(state, operand, operand.name) &&
|
||||
resolveSemanticBindingState(state, operand, operand.name) === binding
|
||||
);
|
||||
};
|
||||
|
||||
const bindingOrigin = (
|
||||
binding: JavaScriptSemanticBindingState,
|
||||
initializers: JavaScriptSemanticBindingState["initializers"],
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): JavaScriptModuleOrigin | undefined => {
|
||||
if (binding.directOrigins.length > 0)
|
||||
return binding.directOrigins.length === 1
|
||||
? binding.directOrigins[0]
|
||||
: undefined;
|
||||
const initializer = semanticStableInitializer(binding, state);
|
||||
if (initializer === undefined) return undefined;
|
||||
const origin = semanticRequireOrigin(initializer.node, state)?.origin;
|
||||
const [initializer] = initializers;
|
||||
// A var/let declaration permits writes without proving one occurred.
|
||||
// Require one unconditional initializer and no actual binding writes.
|
||||
if (
|
||||
initializer === undefined ||
|
||||
initializers.length !== 1 ||
|
||||
state.conditionalInitializers.has(initializer.node)
|
||||
)
|
||||
return undefined;
|
||||
const origin = semanticRequireOrigin(
|
||||
semanticNamespaceInteropOperand(initializer.node, state) ??
|
||||
initializer.node,
|
||||
state,
|
||||
)?.origin;
|
||||
const projection = initializer.projection;
|
||||
return origin === undefined ||
|
||||
!projection.every((key): key is string => typeof key === "string")
|
||||
@@ -624,11 +650,10 @@ function* collectDefinitionsSteps(
|
||||
for (const [index, { body, scope, parameters }] of functionBodies.entries()) {
|
||||
if (index % 64 === 0) yield;
|
||||
for (const parameter of parameters)
|
||||
for (const identifier of semanticWriteTargets(
|
||||
for (const identifier of assignedPatternIdentifiers(
|
||||
t.isTSParameterProperty(parameter) ? parameter.parameter : parameter,
|
||||
))
|
||||
if (t.isIdentifier(identifier))
|
||||
copyParameterToBody({ identifier, body, scope, state });
|
||||
copyParameterToBody({ identifier, body, scope, state });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -776,18 +801,16 @@ const bindAssignment = (
|
||||
state,
|
||||
);
|
||||
else
|
||||
for (const identifier of semanticWriteTargets(node.left))
|
||||
if (t.isIdentifier(identifier))
|
||||
addAssignment(identifier, node, scope, state);
|
||||
for (const identifier of assignedPatternIdentifiers(node.left))
|
||||
addAssignment(identifier, node, scope, state);
|
||||
} else if (t.isUpdateExpression(node) && t.isIdentifier(node.argument))
|
||||
addAssignment(node.argument, node, scope, state);
|
||||
else if (t.isForOfStatement(node) || t.isForInStatement(node))
|
||||
for (const pattern of t.isVariableDeclaration(node.left)
|
||||
? node.left.declarations.map(({ id }) => id)
|
||||
: [node.left]) {
|
||||
for (const identifier of semanticWriteTargets(pattern))
|
||||
if (t.isIdentifier(identifier))
|
||||
addAssignment(identifier, node, scope, state);
|
||||
for (const identifier of assignedPatternIdentifiers(pattern))
|
||||
addAssignment(identifier, node, scope, state);
|
||||
if (t.isForOfStatement(node))
|
||||
// Keep the loop value unknown, but preserve references yielded into
|
||||
// each bound slot so writes/escapes can reach their iterable origins.
|
||||
@@ -802,6 +825,30 @@ const bindAssignment = (
|
||||
}
|
||||
};
|
||||
|
||||
const assignedPatternIdentifiers = (
|
||||
pattern: t.Node,
|
||||
): readonly t.Identifier[] => {
|
||||
const identifiers: t.Identifier[] = [];
|
||||
const pending = [pattern];
|
||||
while (pending.length > 0) {
|
||||
const node = pending.pop();
|
||||
if (node === undefined) continue;
|
||||
if (t.isIdentifier(node)) identifiers.push(node);
|
||||
else if (t.isRestElement(node)) pending.push(node.argument);
|
||||
else if (t.isAssignmentPattern(node)) pending.push(node.left);
|
||||
else if (t.isArrayPattern(node)) {
|
||||
for (const element of node.elements)
|
||||
if (element !== null) pending.push(element);
|
||||
} else if (t.isObjectPattern(node)) {
|
||||
for (const property of node.properties)
|
||||
pending.push(
|
||||
t.isRestElement(property) ? property.argument : property.value,
|
||||
);
|
||||
}
|
||||
}
|
||||
return identifiers;
|
||||
};
|
||||
|
||||
const nestedScope = (
|
||||
node: t.Node,
|
||||
parent: t.Node | null,
|
||||
|
||||
@@ -33,7 +33,7 @@ import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { traverseJavaScriptAstSteps } from "./javascriptSemanticTraversal.js";
|
||||
import {
|
||||
semanticStaticPropertyKey,
|
||||
semanticWriteTargets,
|
||||
semanticMemberWriteTargets,
|
||||
unwrapJavaScriptExpression,
|
||||
} from "./javascriptAstValues.js";
|
||||
|
||||
@@ -401,15 +401,14 @@ export function* collectSemanticMemberMutationsSteps(
|
||||
markEscaped(expression.object, mutation);
|
||||
};
|
||||
const markTarget = (node: t.Node, mutation: t.Node): void => {
|
||||
for (const target of semanticWriteTargets(node))
|
||||
if (!t.isIdentifier(target))
|
||||
markValue(
|
||||
target.object,
|
||||
[semanticStaticPropertyKey(target.property, target.computed)],
|
||||
new Set(),
|
||||
"write",
|
||||
mutation,
|
||||
);
|
||||
for (const target of semanticMemberWriteTargets(node))
|
||||
markValue(
|
||||
target.object,
|
||||
[semanticStaticPropertyKey(target.property, target.computed)],
|
||||
new Set(),
|
||||
"write",
|
||||
mutation,
|
||||
);
|
||||
};
|
||||
yield* traverseJavaScriptAstSteps(program, {
|
||||
enter: (node, parent) => {
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
resolveSemanticBindingState,
|
||||
semanticResolutionBlocked,
|
||||
type JavaScriptSemanticAnalysisState,
|
||||
type JavaScriptSemanticBindingState,
|
||||
} from "./javascriptSemanticState.js";
|
||||
import {
|
||||
semanticStaticPropertyKey,
|
||||
@@ -58,3 +59,73 @@ export const semanticRequireOrigin = (
|
||||
call: current,
|
||||
};
|
||||
};
|
||||
|
||||
// esbuild/Rolldown, TypeScript, and Babel emit these helpers for namespace
|
||||
// imports of CommonJS modules; each returns an object exposing every own
|
||||
// member of its operand, so member paths through the result are unchanged.
|
||||
// Helper bodies are not evaluated: recognition trusts a single program-scope
|
||||
// function definition under one of these emitted names.
|
||||
const NAMESPACE_INTEROP_HELPERS = new Set([
|
||||
"__importStar",
|
||||
"__toESM",
|
||||
"_interopRequireWildcard",
|
||||
]);
|
||||
|
||||
/** Return the module operand of a locally declared namespace interop helper. */
|
||||
export const semanticNamespaceInteropOperand = (
|
||||
node: t.Node,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): t.Expression | undefined => {
|
||||
const call = unwrapJavaScriptExpression(node).node;
|
||||
if (
|
||||
!t.isCallExpression(call) ||
|
||||
!t.isIdentifier(call.callee) ||
|
||||
!NAMESPACE_INTEROP_HELPERS.has(call.callee.name) ||
|
||||
semanticResolutionBlocked(state, call.callee, call.callee.name)
|
||||
)
|
||||
return undefined;
|
||||
const helper = resolveSemanticBindingState(
|
||||
state,
|
||||
call.callee,
|
||||
call.callee.name,
|
||||
);
|
||||
const [operand] = call.arguments;
|
||||
return helper !== undefined &&
|
||||
emittedInteropHelper(helper, state) &&
|
||||
t.isExpression(operand)
|
||||
? operand
|
||||
: undefined;
|
||||
};
|
||||
|
||||
// Emitters declare each helper once at program scope as a function, an
|
||||
// arrow/function expression, or `(this && this.name) || <function>`.
|
||||
const emittedInteropHelper = (
|
||||
helper: JavaScriptSemanticBindingState,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): boolean => {
|
||||
const [initializer] = helper.initializers;
|
||||
if (
|
||||
initializer === undefined ||
|
||||
helper.initializers.length !== 1 ||
|
||||
helper.definitions.length !== 1 ||
|
||||
(helper.kind !== "function" && helper.kind !== "variable") ||
|
||||
state.scopesById.get(helper.scopeId)?.kind !== "program"
|
||||
)
|
||||
return false;
|
||||
const value = unwrapJavaScriptExpression(initializer.node).node;
|
||||
const emitted =
|
||||
t.isLogicalExpression(value, { operator: "||" }) &&
|
||||
t.isLogicalExpression(unwrapJavaScriptExpression(value.left).node, {
|
||||
operator: "&&",
|
||||
})
|
||||
? unwrapJavaScriptExpression(value.right).node
|
||||
: value;
|
||||
return (
|
||||
t.isFunctionDeclaration(emitted) ||
|
||||
t.isFunctionExpression(emitted) ||
|
||||
t.isArrowFunctionExpression(emitted) ||
|
||||
(t.isCallExpression(emitted) &&
|
||||
(t.isFunctionExpression(emitted.callee) ||
|
||||
t.isArrowFunctionExpression(emitted.callee)))
|
||||
);
|
||||
};
|
||||
|
||||
@@ -75,30 +75,6 @@ export interface JavaScriptSemanticAnalysisState {
|
||||
readonly conditionalInitializers: WeakSet<t.Node>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return one unconditional source initializer for a declared lexical binding.
|
||||
* Repeated variable declarations without another initializer do not write it.
|
||||
* This establishes a stable source fact only; it does not prove immutability or
|
||||
* that the declaration has executed at a particular program point.
|
||||
*/
|
||||
export const semanticStableInitializer = (
|
||||
binding: JavaScriptSemanticBindingState | undefined,
|
||||
state: JavaScriptSemanticAnalysisState,
|
||||
): JavaScriptSemanticBindingState["initializers"][number] | undefined => {
|
||||
const [initializer] = binding?.initializers ?? [];
|
||||
const [definition] = binding?.definitions ?? [];
|
||||
return binding !== undefined &&
|
||||
((definition?.kind === "variable" &&
|
||||
binding.definitions.every(({ kind }) => kind === "variable")) ||
|
||||
(binding.definitions.length === 1 &&
|
||||
(definition?.kind === "function" || definition?.kind === "class"))) &&
|
||||
binding.initializers.length === 1 &&
|
||||
initializer !== undefined &&
|
||||
!state.conditionalInitializers.has(initializer.node)
|
||||
? initializer
|
||||
: undefined;
|
||||
};
|
||||
|
||||
/** Return the active scope from a non-empty construction stack. */
|
||||
export const currentSemanticScope = (
|
||||
stack: readonly JavaScriptSemanticScopeState[],
|
||||
|
||||
@@ -82,7 +82,8 @@ interface TraversalFrame {
|
||||
* not be reintroduced (they diverge on loc/comment fields and ordering).
|
||||
*/
|
||||
export const childNodes = (node: t.Node): t.Node[] => {
|
||||
const keys = javaScriptAstChildKeys(node);
|
||||
const keys = t.VISITOR_KEYS[node.type];
|
||||
if (keys === undefined) return [];
|
||||
const children: t.Node[] = [];
|
||||
for (const key of keys) {
|
||||
const value: unknown = Reflect.get(node, key);
|
||||
@@ -97,7 +98,3 @@ export const childNodes = (node: t.Node): t.Node[] => {
|
||||
}
|
||||
return children;
|
||||
};
|
||||
|
||||
/** Child-bearing fields; shared by traversal and structural AST comparison. */
|
||||
export const javaScriptAstChildKeys = (node: t.Node): readonly string[] =>
|
||||
t.VISITOR_KEYS[node.type] ?? [];
|
||||
|
||||
@@ -2,9 +2,7 @@ import { isAbsolute, relative, sep } from "node:path";
|
||||
import { z } from "zod";
|
||||
|
||||
/**
|
||||
* Reject OS-invalid NUL bytes in a local filesystem name. This is not a path
|
||||
* shape check: an empty or relative value is admitted here and narrowed by the
|
||||
* callers that need a nonempty or absolute path.
|
||||
* Preserve selected filesystem names while rejecting OS-invalid NUL bytes.
|
||||
*
|
||||
* The pattern spells NUL as `\x00` rather than `\u0000`. Both accept exactly the
|
||||
* same strings. The hex form also avoids the short `\0` spelling rejected by
|
||||
@@ -12,13 +10,11 @@ import { z } from "zod";
|
||||
* one advertised pattern cannot compile. See `offsetDateTimeSchema` for the
|
||||
* same hex-escape convention.
|
||||
*/
|
||||
export const nulFreeStringSchema = z
|
||||
export const localPathStringSchema = z
|
||||
.string()
|
||||
.min(1)
|
||||
.regex(/^[^\x00]*$/u, "Local filesystem paths cannot contain NUL");
|
||||
|
||||
/** A selected local filesystem path: nonempty and free of NUL bytes. */
|
||||
export const localPathStringSchema = nulFreeStringSchema.min(1);
|
||||
|
||||
/** Test lexical containment on the host platform; callers must resolve symlinks first. */
|
||||
export const isPathWithinRoot = (root: string, path: string): boolean => {
|
||||
const value = relative(root, path);
|
||||
|
||||
@@ -84,7 +84,7 @@ export const nativeLoadImageCheckSchema = z.strictObject({
|
||||
});
|
||||
|
||||
/** Read-only native image verification; verified applies only to declared coverage. */
|
||||
export const nativeLoadImageSchema = z.union([
|
||||
export const nativeLoadImageSchema = z.discriminatedUnion("status", [
|
||||
z.strictObject({
|
||||
status: z.literal("unsupported"),
|
||||
reason: z.string().min(1),
|
||||
@@ -108,23 +108,6 @@ export const nativeLoadImageSchema = z.union([
|
||||
checks: z.array(nativeLoadImageCheckSchema),
|
||||
limitations: z.array(z.string().min(1)),
|
||||
}),
|
||||
z.strictObject({
|
||||
status: z.enum(["verified", "mismatch"]),
|
||||
format: z.literal("raw-binary"),
|
||||
target_sha256: digest,
|
||||
architecture: z.enum(["x86", "x86_64", "arm", "arm64"]),
|
||||
language_id: z.string().min(1),
|
||||
compiler_spec_id: z.string().min(1),
|
||||
base_address: address,
|
||||
file_bytes: integer.min(1),
|
||||
entry: z.strictObject({
|
||||
address: address,
|
||||
file_offset: z.literal(0),
|
||||
}),
|
||||
observations: nativeLoadImageObservationSchema,
|
||||
checks: z.array(nativeLoadImageCheckSchema),
|
||||
limitations: z.array(z.string().min(1)),
|
||||
}),
|
||||
]);
|
||||
|
||||
/** Provider-neutral native load-image result. */
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { executableFormatHintSchema } from "./dosCom.js";
|
||||
import {
|
||||
admitRawBinary,
|
||||
parseRawBinaryEntryPoint,
|
||||
rawBinarySelectionError,
|
||||
validateRawBinaryLength,
|
||||
} from "./rawBinary.js";
|
||||
|
||||
describe("headerless format hints", () => {
|
||||
it("admits dos-com and raw-binary names only", () => {
|
||||
expect(executableFormatHintSchema.safeParse("dos-com").success).toBe(true);
|
||||
expect(executableFormatHintSchema.safeParse("raw-binary").success).toBe(
|
||||
true,
|
||||
);
|
||||
expect(executableFormatHintSchema.safeParse("raw").success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("raw-binary entry addresses", () => {
|
||||
it("canonicalizes equivalent hex spellings without dropping the source", () => {
|
||||
const parsed = parseRawBinaryEntryPoint("0x08000000");
|
||||
expect(parsed).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
source: "0x08000000",
|
||||
canonical: "0x8000000",
|
||||
value: 0x8000000n,
|
||||
},
|
||||
});
|
||||
});
|
||||
it.each(["8000000", "0x", "0xgg", "0X8000000", ""])(
|
||||
"rejects malformed entry %s",
|
||||
(value) => {
|
||||
expect(parseRawBinaryEntryPoint(value).ok).toBe(false);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("raw-binary admission", () => {
|
||||
it("admits a little-endian ARM image mapped at the caller entry", () => {
|
||||
expect(
|
||||
admitRawBinary({
|
||||
architecture: "arm",
|
||||
entryPoint: "0x8000000",
|
||||
fileBytes: 4,
|
||||
}),
|
||||
).toEqual({
|
||||
ok: true,
|
||||
value: {
|
||||
architecture: "arm",
|
||||
entryPoint: "0x8000000",
|
||||
entryPointSource: "0x8000000",
|
||||
},
|
||||
});
|
||||
});
|
||||
it("rejects an empty file", () => {
|
||||
expect(validateRawBinaryLength(0).ok).toBe(false);
|
||||
expect(
|
||||
admitRawBinary({
|
||||
architecture: "x86",
|
||||
entryPoint: "0x1000",
|
||||
fileBytes: 0,
|
||||
}).ok,
|
||||
).toBe(false);
|
||||
});
|
||||
it("rejects a 32-bit mapping that exceeds the architecture width", () => {
|
||||
const result = admitRawBinary({
|
||||
architecture: "arm",
|
||||
entryPoint: "0xfffffffc",
|
||||
fileBytes: 8,
|
||||
});
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) throw new Error("expected overflow rejection");
|
||||
expect(result.error).toContain("arm address width");
|
||||
});
|
||||
it("allows a 64-bit mapping that would overflow 32-bit ARM", () => {
|
||||
expect(
|
||||
admitRawBinary({
|
||||
architecture: "arm64",
|
||||
entryPoint: "0xfffffffc",
|
||||
fileBytes: 8,
|
||||
}).ok,
|
||||
).toBe(true);
|
||||
});
|
||||
it.each(["arm", "arm64"])(
|
||||
"rejects unaligned %s entries before provider selection",
|
||||
(architecture) => {
|
||||
for (const entryPoint of ["0x8000001", "0x8000002", "0x8000003"]) {
|
||||
expect(
|
||||
admitRawBinary({ architecture, entryPoint, fileBytes: 4 }),
|
||||
).toEqual({
|
||||
ok: false,
|
||||
error: `raw-binary ${architecture} entry_point ${entryPoint} must be 4-byte aligned`,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
it.each(["x86", "x86_64"])(
|
||||
"admits byte-aligned %s entries",
|
||||
(architecture) => {
|
||||
const admitted = admitRawBinary({
|
||||
architecture,
|
||||
entryPoint: "0x1001",
|
||||
fileBytes: 1,
|
||||
});
|
||||
if (!admitted.ok) throw new Error(admitted.error);
|
||||
expect(admitted.value.entryPoint).toBe("0x1001");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("raw-binary selection pairing", () => {
|
||||
it("requires architecture and entry with format=raw-binary", () => {
|
||||
expect(rawBinarySelectionError({ format: "raw-binary" })).toBe(
|
||||
"format=raw-binary requires architecture and entry_point",
|
||||
);
|
||||
expect(
|
||||
rawBinarySelectionError({
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
entryPoint: "0x8000000",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
it("rejects architecture or entry without format=raw-binary", () => {
|
||||
expect(
|
||||
rawBinarySelectionError({ architecture: "arm", entryPoint: "0x1" }),
|
||||
).toBe("architecture and entry_point apply only with format=raw-binary");
|
||||
expect(
|
||||
rawBinarySelectionError({ format: "dos-com", architecture: "x86" }),
|
||||
).toBe("architecture and entry_point apply only with format=raw-binary");
|
||||
});
|
||||
});
|
||||
@@ -1,123 +0,0 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import type { BinaryArchitecture } from "./binaryTargetTypes.js";
|
||||
import type { ExecutableFormatHint } from "./dosCom.js";
|
||||
import { err, ok, type Result } from "./result.js";
|
||||
|
||||
/** Caller-visible CPU families admitted for headerless raw binaries. */
|
||||
export const BINARY_ARCHITECTURES = [
|
||||
"x86",
|
||||
"x86_64",
|
||||
"arm",
|
||||
"arm64",
|
||||
] as const satisfies readonly BinaryArchitecture[];
|
||||
|
||||
/** Provider-neutral CPU family for a caller-supplied raw-binary load. */
|
||||
export const binaryArchitectureSchema = z.enum(BINARY_ARCHITECTURES);
|
||||
|
||||
const RAW_BINARY_ENTRY_POINT = /^0x[0-9A-Fa-f]{1,16}$/u;
|
||||
|
||||
/** Hexadecimal load and entry address; file offset 0 is mapped here. */
|
||||
export const rawBinaryEntryPointSchema = z
|
||||
.string()
|
||||
.regex(RAW_BINARY_ENTRY_POINT, {
|
||||
message: "entry_point must be a hexadecimal address of the form 0x…",
|
||||
});
|
||||
|
||||
/** Canonicalized caller-supplied raw-binary entry with the original spelling. */
|
||||
export interface CanonicalRawBinaryEntry {
|
||||
readonly source: string;
|
||||
readonly canonical: string;
|
||||
readonly value: bigint;
|
||||
}
|
||||
|
||||
/** Parse a caller-supplied hex entry while preserving the source spelling. */
|
||||
export const parseRawBinaryEntryPoint = (
|
||||
value: string,
|
||||
): Result<CanonicalRawBinaryEntry, string> => {
|
||||
if (!RAW_BINARY_ENTRY_POINT.test(value))
|
||||
return err("entry_point must be a hexadecimal address of the form 0x…");
|
||||
const parsed = BigInt(value);
|
||||
return ok({
|
||||
source: value,
|
||||
canonical: `0x${parsed.toString(16)}`,
|
||||
value: parsed,
|
||||
});
|
||||
};
|
||||
|
||||
/** Reject empty or non-integral file extents for a headerless image. */
|
||||
export const validateRawBinaryLength = (
|
||||
length: number,
|
||||
): Result<null, string> =>
|
||||
Number.isSafeInteger(length) && length >= 1
|
||||
? ok(null)
|
||||
: err("raw-binary requires at least one file byte");
|
||||
|
||||
/** Admitted headerless load identity used by target resolution and profiles. */
|
||||
export interface RawBinaryAdmission {
|
||||
readonly architecture: Exclude<BinaryArchitecture, "mips">;
|
||||
readonly entryPoint: string;
|
||||
readonly entryPointSource: string;
|
||||
}
|
||||
|
||||
const addressWidth = (architecture: BinaryArchitecture): bigint =>
|
||||
architecture === "x86" || architecture === "arm"
|
||||
? 0xffffffffn
|
||||
: 0xffffffffffffffffn;
|
||||
|
||||
/** Validate architecture, entry, and that the mapped image fits the CPU width. */
|
||||
export const admitRawBinary = (input: {
|
||||
readonly architecture: unknown;
|
||||
readonly entryPoint: unknown;
|
||||
readonly fileBytes: number;
|
||||
}): Result<RawBinaryAdmission, string> => {
|
||||
const architecture = binaryArchitectureSchema.safeParse(input.architecture);
|
||||
if (!architecture.success)
|
||||
return err(
|
||||
"raw-binary format requires architecture (x86, x86_64, arm, or arm64)",
|
||||
);
|
||||
if (typeof input.entryPoint !== "string")
|
||||
return err(
|
||||
"raw-binary format requires entry_point as a hexadecimal address of the form 0x…",
|
||||
);
|
||||
const entry = parseRawBinaryEntryPoint(input.entryPoint);
|
||||
if (!entry.ok) return entry;
|
||||
if (
|
||||
(architecture.data === "arm" || architecture.data === "arm64") &&
|
||||
entry.value.value % 4n !== 0n
|
||||
)
|
||||
return err(
|
||||
`raw-binary ${architecture.data} entry_point ${entry.value.canonical} must be 4-byte aligned`,
|
||||
);
|
||||
const length = validateRawBinaryLength(input.fileBytes);
|
||||
if (!length.ok) return length;
|
||||
const last = entry.value.value + BigInt(input.fileBytes) - 1n;
|
||||
const max = addressWidth(architecture.data);
|
||||
if (entry.value.value > max || last > max)
|
||||
return err(
|
||||
`raw-binary mapping from ${entry.value.canonical} must fit in the ${architecture.data} address width`,
|
||||
);
|
||||
return ok({
|
||||
architecture: architecture.data,
|
||||
entryPoint: entry.value.canonical,
|
||||
entryPointSource: entry.value.source,
|
||||
});
|
||||
};
|
||||
|
||||
/** Describe the format/architecture/entry pairing without performing I/O. */
|
||||
export const rawBinarySelectionError = (input: {
|
||||
readonly format?: ExecutableFormatHint;
|
||||
readonly architecture?: unknown;
|
||||
readonly entryPoint?: unknown;
|
||||
}): string | undefined => {
|
||||
const hasArchitecture = input.architecture !== undefined;
|
||||
const hasEntry = input.entryPoint !== undefined;
|
||||
if (input.format === "raw-binary") {
|
||||
if (!hasArchitecture || !hasEntry)
|
||||
return "format=raw-binary requires architecture and entry_point";
|
||||
return undefined;
|
||||
}
|
||||
if (hasArchitecture || hasEntry)
|
||||
return "architecture and entry_point apply only with format=raw-binary";
|
||||
return undefined;
|
||||
};
|
||||
@@ -5,5 +5,5 @@ export const PACKAGE_METADATA = {
|
||||
serverSdkVersion: "2.3.1",
|
||||
clientSdkVersion: "2.3.1",
|
||||
coreSdkVersion: "2.3.1",
|
||||
skillVersion: "39",
|
||||
skillVersion: "38",
|
||||
} as const;
|
||||
|
||||
@@ -14,7 +14,6 @@ import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import type { GhidraInstallationInspection } from "./GhidraInstallation.js";
|
||||
import { ghidraMipsProfileParameters } from "./GhidraMipsProfile.js";
|
||||
import { ghidraRawBinaryLanguage } from "./GhidraRawBinaryLanguage.js";
|
||||
|
||||
import {
|
||||
ghidraProcessorUnsupportedReason,
|
||||
@@ -70,57 +69,6 @@ export const resolveGhidraAnalysisProfile = async (
|
||||
: null;
|
||||
if (pspExtension !== null && !pspExtension.ok) return pspExtension;
|
||||
const provider = { ...identity, version: installation.providerVersion };
|
||||
if (target.format === "raw-binary") {
|
||||
if (languageOverride !== undefined)
|
||||
return Promise.resolve(
|
||||
err(
|
||||
new AnalysisUnsupportedTargetError(
|
||||
"resolve_analysis_profile",
|
||||
target.path,
|
||||
"REA_GHIDRA_LANGUAGE_ID cannot override the admitted raw-binary import.",
|
||||
),
|
||||
),
|
||||
);
|
||||
const language = ghidraRawBinaryLanguage(target.architecture);
|
||||
return Promise.resolve(
|
||||
ok({
|
||||
profile: createAnalysisProfile(provider, {
|
||||
target_kind: target.kind,
|
||||
target_format: target.format,
|
||||
architecture: target.architecture,
|
||||
available_architectures: [...target.availableArchitectures].sort(),
|
||||
import_mode: "ephemeral-source-immutable",
|
||||
annotation_policy: "atomic-function-entry-metadata-v1",
|
||||
load_image_observations: "source-mappings-entry-context-v2",
|
||||
function_body_evidence: "complete-inclusive-ranges-v1",
|
||||
function_references: "complete-body-and-entry-reference-manager-v2",
|
||||
string_inventory_evidence: "defined-data-coverage-v1",
|
||||
location_resolution: "explicit-address-exact-entry-symbol-first-v3",
|
||||
instruction_flow_evidence: "decoded-return-pcode-v1",
|
||||
instruction_references: "exact-address-incoming-v1",
|
||||
function_boundary_observations: "ghidra-terminal-call-limitations-v1",
|
||||
no_return_repair:
|
||||
installation.platform === "win32"
|
||||
? "disabled-windows-p0"
|
||||
: "returning-imports-decoded-return-v2",
|
||||
process_launch:
|
||||
installation.platform === "win32"
|
||||
? "official-headless-script-v1"
|
||||
: "inspected-jvm-launch-support-v1",
|
||||
load_image_evidence: "independent-raw-mapping-context-v2",
|
||||
jump_table_evidence: "typed-case-default-blocks-v1",
|
||||
decompiler_jump_loads: true,
|
||||
loader: "BinaryLoader",
|
||||
language_id: language.languageId,
|
||||
compiler_spec_id: language.compilerSpecId,
|
||||
language_selection: "caller-supplied-v1",
|
||||
entry_point: target.entryPoint,
|
||||
entry_seed: "external-entry-and-function-before-analysis-v1",
|
||||
analyzer_preset: "ghidra-default",
|
||||
}),
|
||||
}),
|
||||
);
|
||||
}
|
||||
const dosMz = target.format === "dos-mz";
|
||||
const dosCom = target.format === "dos-com";
|
||||
const dos = dosMz || dosCom;
|
||||
|
||||
+77
-143
@@ -1,8 +1,5 @@
|
||||
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
||||
import type { Stats } from "node:fs";
|
||||
import type { FileHandle } from "node:fs/promises";
|
||||
import { randomBytes, randomUUID } from "node:crypto";
|
||||
import type { Socket } from "node:net";
|
||||
import type { ProgressReporter } from "../application/ProgressReporter.js";
|
||||
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
@@ -45,12 +42,11 @@ import {
|
||||
type GhidraSessionInfo,
|
||||
} from "./GhidraSessionValues.js";
|
||||
import { createGhidraTargetSnapshot } from "./GhidraTargetSnapshot.js";
|
||||
import { readFileHandleChunks } from "../filesystem/readFileHandleChunks.js";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { readBoundedFileBytes } from "../process/BoundedFileBytes.js";
|
||||
import {
|
||||
openRegularFile,
|
||||
RegularFileChangedError,
|
||||
RegularFileAdmissionFailure,
|
||||
sameRegularFileState,
|
||||
} from "../filesystem/RegularFile.js";
|
||||
import { OwnedFileHandle } from "../filesystem/OwnedFileHandle.js";
|
||||
@@ -166,12 +162,7 @@ export class GhidraClient {
|
||||
}
|
||||
|
||||
/** Launch Ghidra once and require its exact post-analysis handshake. */
|
||||
start(
|
||||
signal?: AbortSignal,
|
||||
progress?: ProgressReporter,
|
||||
): Promise<GhidraStartResult> {
|
||||
if (progress !== undefined)
|
||||
return this.#reportStartupWait(this.start(signal), signal, progress);
|
||||
start(signal?: AbortSignal): Promise<GhidraStartResult> {
|
||||
if (this.#closePromise !== undefined)
|
||||
return this.#closePromise.then(
|
||||
() => this.start(signal),
|
||||
@@ -225,41 +216,6 @@ export class GhidraClient {
|
||||
return started;
|
||||
}
|
||||
|
||||
async #reportStartupWait(
|
||||
started: Promise<GhidraStartResult>,
|
||||
signal: AbortSignal | undefined,
|
||||
progress: ProgressReporter,
|
||||
): Promise<GhidraStartResult> {
|
||||
const startedAt = performance.now();
|
||||
let active = true;
|
||||
let reporting = false;
|
||||
const timer = setInterval(() => {
|
||||
if (!active || reporting || signal?.aborted) return;
|
||||
reporting = true;
|
||||
void Promise.resolve()
|
||||
.then(() => {
|
||||
if (!active || signal?.aborted) return;
|
||||
return progress.report({
|
||||
phase: "ghidra_startup",
|
||||
completed: 0,
|
||||
total: null,
|
||||
message: `Waiting for Ghidra startup (${String(Math.floor((performance.now() - startedAt) / 1000))}s elapsed); import, auto-analysis and bridge readiness may still be pending`,
|
||||
});
|
||||
})
|
||||
// Notification failure does not release the owned startup process.
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
reporting = false;
|
||||
});
|
||||
}, 10_000);
|
||||
try {
|
||||
return await started;
|
||||
} finally {
|
||||
active = false;
|
||||
clearInterval(timer);
|
||||
}
|
||||
}
|
||||
|
||||
/** Revalidate live bridge, provider, run, and profile metadata. */
|
||||
async ping(
|
||||
options: GhidraRequestOptions = {},
|
||||
@@ -275,12 +231,9 @@ export class GhidraClient {
|
||||
async callTool(
|
||||
operation: GhidraOperation,
|
||||
parameters: Readonly<Record<string, JsonValue>>,
|
||||
options: {
|
||||
readonly signal?: AbortSignal;
|
||||
readonly progress?: ProgressReporter;
|
||||
} = {},
|
||||
options: { readonly signal?: AbortSignal } = {},
|
||||
): Promise<Result<JsonValue, GhidraSessionError>> {
|
||||
const started = await this.start(options.signal, options.progress);
|
||||
const started = await this.start(options.signal);
|
||||
if (!started.ok) return started;
|
||||
return this.#requestQueue.run(
|
||||
operation,
|
||||
@@ -289,66 +242,12 @@ export class GhidraClient {
|
||||
);
|
||||
}
|
||||
|
||||
/** Read the private immutable source for format parsers that require captured bytes. */
|
||||
readTargetSnapshot(
|
||||
/** Read the private immutable source for independent import verification. */
|
||||
async readTargetSnapshot(
|
||||
maximumBytes?: number,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Result<GhidraTargetSnapshot, GhidraSessionError>> {
|
||||
return this.#withTargetSnapshot(async (handle, initial, path) => {
|
||||
if (
|
||||
maximumBytes !== undefined &&
|
||||
(!Number.isSafeInteger(maximumBytes) || maximumBytes < 0)
|
||||
)
|
||||
throw new RangeError("Snapshot byte limit must be a safe integer");
|
||||
if (maximumBytes !== undefined && initial.size > maximumBytes)
|
||||
return {
|
||||
kind: "over-capacity",
|
||||
sourceBytesAtLeast: initial.size,
|
||||
maximumBytes,
|
||||
};
|
||||
const bytes = await readBoundedFileBytes(
|
||||
handle,
|
||||
maximumBytes ?? initial.size,
|
||||
signal,
|
||||
initial.size,
|
||||
);
|
||||
if (bytes === undefined || bytes.length !== initial.size)
|
||||
throw new RegularFileChangedError(path);
|
||||
return { kind: "captured", bytes };
|
||||
}, signal);
|
||||
}
|
||||
|
||||
/** Measure the complete snapshot identity without retaining its bytes in memory. */
|
||||
hashTargetSnapshot(
|
||||
signal?: AbortSignal,
|
||||
): Promise<
|
||||
Result<
|
||||
{ readonly sha256: string; readonly bytes: number },
|
||||
GhidraSessionError
|
||||
>
|
||||
> {
|
||||
return this.#withTargetSnapshot(async (handle, initial, path) => {
|
||||
const hash = createHash("sha256");
|
||||
let bytes = 0;
|
||||
for await (const chunk of readFileHandleChunks(handle, {
|
||||
end: initial.size,
|
||||
signal,
|
||||
})) {
|
||||
bytes += chunk.length;
|
||||
if (bytes > initial.size) throw new RegularFileChangedError(path);
|
||||
hash.update(chunk);
|
||||
}
|
||||
if (bytes !== initial.size) throw new RegularFileChangedError(path);
|
||||
return { sha256: hash.digest("hex"), bytes };
|
||||
}, signal);
|
||||
}
|
||||
|
||||
async #withTargetSnapshot<T>(
|
||||
read: (handle: FileHandle, initial: Stats, path: string) => Promise<T>,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Result<T, GhidraSessionError>> {
|
||||
const path = this.#snapshotPath;
|
||||
if (path === undefined)
|
||||
if (this.#snapshotPath === undefined)
|
||||
return err(
|
||||
this.#failure(
|
||||
"protocol",
|
||||
@@ -356,42 +255,77 @@ export class GhidraClient {
|
||||
),
|
||||
);
|
||||
try {
|
||||
const handle = await openRegularFile(path, {
|
||||
symlinks: "reject",
|
||||
signal,
|
||||
if (maximumBytes !== undefined) {
|
||||
signal?.throwIfAborted();
|
||||
if (!Number.isSafeInteger(maximumBytes) || maximumBytes < 0)
|
||||
throw new RangeError("Snapshot byte limit must be a safe integer");
|
||||
const handle = await openRegularFile(this.#snapshotPath, {
|
||||
symlinks: "reject",
|
||||
});
|
||||
const owner = new OwnedFileHandle(handle);
|
||||
this.#snapshotOwners.add(owner);
|
||||
let result: GhidraTargetSnapshot;
|
||||
let readFailure: unknown;
|
||||
try {
|
||||
const metadata = await handle.stat();
|
||||
signal?.throwIfAborted();
|
||||
if (metadata.size > maximumBytes)
|
||||
result = {
|
||||
kind: "over-capacity",
|
||||
sourceBytesAtLeast: metadata.size,
|
||||
maximumBytes,
|
||||
};
|
||||
else {
|
||||
const bytes = await readBoundedFileBytes(
|
||||
handle,
|
||||
maximumBytes,
|
||||
signal,
|
||||
metadata.size,
|
||||
);
|
||||
signal?.throwIfAborted();
|
||||
const after = await handle.stat();
|
||||
if (
|
||||
bytes !== undefined &&
|
||||
bytes.length === metadata.size &&
|
||||
sameRegularFileState(metadata, after)
|
||||
) {
|
||||
result = { kind: "captured", bytes };
|
||||
} else if (
|
||||
bytes === undefined &&
|
||||
after.isFile() &&
|
||||
after.size > maximumBytes
|
||||
) {
|
||||
result = {
|
||||
kind: "over-capacity",
|
||||
sourceBytesAtLeast: after.size,
|
||||
maximumBytes,
|
||||
};
|
||||
} else {
|
||||
throw new RegularFileChangedError(this.#snapshotPath);
|
||||
}
|
||||
}
|
||||
} catch (cause: unknown) {
|
||||
readFailure = cause;
|
||||
}
|
||||
try {
|
||||
await owner.close();
|
||||
this.#snapshotOwners.delete(owner);
|
||||
} catch (closeFailure: unknown) {
|
||||
throw new AggregateError(
|
||||
readFailure === undefined
|
||||
? [closeFailure]
|
||||
: [readFailure, closeFailure],
|
||||
"Ghidra target snapshot read or descriptor cleanup failed",
|
||||
);
|
||||
}
|
||||
if (readFailure !== undefined) throw readFailure;
|
||||
return ok(result!);
|
||||
}
|
||||
return ok({
|
||||
kind: "captured",
|
||||
bytes: await readFile(this.#snapshotPath),
|
||||
});
|
||||
const owner = new OwnedFileHandle(handle);
|
||||
this.#snapshotOwners.add(owner);
|
||||
let result: Result<T, unknown>;
|
||||
try {
|
||||
const initial = await handle.stat();
|
||||
signal?.throwIfAborted();
|
||||
if (!Number.isSafeInteger(initial.size) || initial.size < 0)
|
||||
throw new RangeError("Snapshot size must be a safe integer");
|
||||
const value = await read(handle, initial, path);
|
||||
signal?.throwIfAborted();
|
||||
const after = await handle.stat();
|
||||
signal?.throwIfAborted();
|
||||
if (!sameRegularFileState(initial, after))
|
||||
throw new RegularFileChangedError(path);
|
||||
result = ok(value);
|
||||
} catch (cause: unknown) {
|
||||
result = err(cause);
|
||||
}
|
||||
try {
|
||||
await owner.close();
|
||||
this.#snapshotOwners.delete(owner);
|
||||
} catch (closeFailure: unknown) {
|
||||
throw new AggregateError(
|
||||
result.ok ? [closeFailure] : [result.error, closeFailure],
|
||||
"Ghidra target snapshot read or descriptor cleanup failed",
|
||||
);
|
||||
}
|
||||
if (!result.ok) throw result.error;
|
||||
return result;
|
||||
} catch (cause: unknown) {
|
||||
if (cause instanceof RegularFileAdmissionFailure)
|
||||
this.#snapshotOwners.add(cause.owner);
|
||||
return err(
|
||||
this.#failure(
|
||||
signal?.aborted === true ? "cancelled" : "protocol",
|
||||
|
||||
@@ -101,11 +101,6 @@ export interface GhidraHeadlessLauncherOptions {
|
||||
/** Select the admitted 16-bit real-mode MZ import instead of auto-detection. */
|
||||
readonly dosMz?: true;
|
||||
readonly dosCom?: true;
|
||||
readonly rawBinary?: {
|
||||
readonly languageId: string;
|
||||
readonly compilerSpecId: string;
|
||||
readonly baseAddr: string;
|
||||
};
|
||||
/** Explicit import language committed by the analysis profile. */
|
||||
readonly languageOverride?: GhidraLanguageOverride;
|
||||
/** Caller seeds committed by the analysis profile, applied before analysis. */
|
||||
@@ -206,9 +201,6 @@ export class GhidraHeadlessLauncher implements GhidraLauncher {
|
||||
...(this.options.dosMz === undefined
|
||||
? {}
|
||||
: { dosMz: this.options.dosMz }),
|
||||
...(this.options.rawBinary === undefined
|
||||
? {}
|
||||
: { rawBinary: this.options.rawBinary }),
|
||||
...(this.options.languageOverride === undefined
|
||||
? {}
|
||||
: { languageOverride: this.options.languageOverride }),
|
||||
@@ -419,11 +411,6 @@ export interface GhidraHeadlessArgumentOptions {
|
||||
readonly psp?: true;
|
||||
readonly dosMz?: true;
|
||||
readonly dosCom?: true;
|
||||
readonly rawBinary?: {
|
||||
readonly languageId: string;
|
||||
readonly compilerSpecId: string;
|
||||
readonly baseAddr: string;
|
||||
};
|
||||
readonly languageOverride?: GhidraLanguageOverride;
|
||||
/** Canonical seed snapshot passed to the pre-analysis seed script. */
|
||||
readonly seedPath?: string;
|
||||
@@ -439,7 +426,6 @@ export const ghidraHeadlessArguments = (
|
||||
(options.platform ?? process.platform) === "win32" ? win32 : posix;
|
||||
const bridgeDirectory = scriptPath.dirname(options.bridgeScriptPath);
|
||||
const override = options.languageOverride;
|
||||
const rawBinary = options.rawBinary;
|
||||
if (
|
||||
options.psp === true &&
|
||||
(options.dosMz === true ||
|
||||
@@ -449,10 +435,6 @@ export const ghidraHeadlessArguments = (
|
||||
throw new Error(
|
||||
"A PSP ELF import cannot be combined with DOS or a generic Ghidra language override.",
|
||||
);
|
||||
if (options.psp === true && rawBinary !== undefined)
|
||||
throw new Error(
|
||||
"A PSP ELF import cannot be combined with a raw-binary import.",
|
||||
);
|
||||
if (
|
||||
override !== undefined &&
|
||||
(options.dosMz === true || options.dosCom === true)
|
||||
@@ -460,17 +442,6 @@ export const ghidraHeadlessArguments = (
|
||||
throw new Error(
|
||||
"A Ghidra language override cannot be combined with a DOS import.",
|
||||
);
|
||||
if (override !== undefined && rawBinary !== undefined)
|
||||
throw new Error(
|
||||
"A Ghidra language override cannot be combined with a raw-binary import.",
|
||||
);
|
||||
if (
|
||||
rawBinary !== undefined &&
|
||||
(options.dosMz === true || options.dosCom === true)
|
||||
)
|
||||
throw new Error(
|
||||
"A raw-binary import cannot be combined with a DOS import.",
|
||||
);
|
||||
return [
|
||||
options.projectRoot,
|
||||
"rea-project",
|
||||
@@ -496,35 +467,24 @@ export const ghidraHeadlessArguments = (
|
||||
"-cspec",
|
||||
"default",
|
||||
]
|
||||
: rawBinary === undefined
|
||||
? options.psp === true
|
||||
? [
|
||||
"-loader",
|
||||
"PspElfLoader",
|
||||
"-processor",
|
||||
"Allegrex:LE:32:default",
|
||||
"-cspec",
|
||||
"default",
|
||||
]
|
||||
: override !== undefined
|
||||
? [
|
||||
"-processor",
|
||||
override.languageId,
|
||||
...(override.compilerSpecId === undefined
|
||||
? []
|
||||
: ["-cspec", override.compilerSpecId]),
|
||||
]
|
||||
: []
|
||||
: [
|
||||
: options.psp === true
|
||||
? [
|
||||
"-loader",
|
||||
"BinaryLoader",
|
||||
"-loader-baseAddr",
|
||||
rawBinary.baseAddr,
|
||||
"PspElfLoader",
|
||||
"-processor",
|
||||
rawBinary.languageId,
|
||||
"Allegrex:LE:32:default",
|
||||
"-cspec",
|
||||
rawBinary.compilerSpecId,
|
||||
]),
|
||||
"default",
|
||||
]
|
||||
: override !== undefined
|
||||
? [
|
||||
"-processor",
|
||||
override.languageId,
|
||||
...(override.compilerSpecId === undefined
|
||||
? []
|
||||
: ["-cspec", override.compilerSpecId]),
|
||||
]
|
||||
: []),
|
||||
"-readOnly",
|
||||
"-deleteProject",
|
||||
"-log",
|
||||
@@ -539,14 +499,6 @@ export const ghidraHeadlessArguments = (
|
||||
scriptPath.join(bridgeDirectory, "ReaGhidraPrepareCom.java"),
|
||||
]
|
||||
: []),
|
||||
...(rawBinary === undefined
|
||||
? []
|
||||
: [
|
||||
"-preScript",
|
||||
scriptPath.join(bridgeDirectory, "ReaGhidraPrepareRaw.java"),
|
||||
rawBinary.languageId,
|
||||
rawBinary.baseAddr,
|
||||
]),
|
||||
// Seeds follow any loader preparation and precede default auto-analysis.
|
||||
...(options.seedPath === undefined
|
||||
? []
|
||||
|
||||
@@ -12,15 +12,17 @@ import { err, ok, type Result } from "../domain/result.js";
|
||||
import {
|
||||
attestGhidraDosComLoadImage,
|
||||
attestGhidraDosLoadImage,
|
||||
attestGhidraRawBinaryLoadImage,
|
||||
} from "./GhidraLoadImageValues.js";
|
||||
import type { NativeAotPeResult } from "../domain/native/nativeAotPe.js";
|
||||
import type { GhidraClient } from "./GhidraClient.js";
|
||||
import type { GhidraTargetSnapshot } from "./GhidraClient.js";
|
||||
import type { GhidraSessionError } from "./GhidraSessionError.js";
|
||||
|
||||
type LoadImageSnapshotClient = Partial<
|
||||
Pick<GhidraClient, "hashTargetSnapshot" | "readTargetSnapshot">
|
||||
>;
|
||||
type LoadImageSnapshotClient = {
|
||||
readonly readTargetSnapshot?: (
|
||||
maximumBytes?: number,
|
||||
signal?: AbortSignal,
|
||||
) => Promise<Result<GhidraTargetSnapshot, GhidraSessionError>>;
|
||||
};
|
||||
|
||||
type NativeLoadImageAttestationInput = {
|
||||
readonly target: BinaryTarget;
|
||||
@@ -35,7 +37,7 @@ type NativeLoadImageAttestationInput = {
|
||||
const isSignalAborted = (signal: AbortSignal | undefined): boolean =>
|
||||
signal?.aborted === true;
|
||||
|
||||
/** Independently verify measured load-image observations for admitted DOS and raw-binary targets. */
|
||||
/** Independently verify measured load-image observations for admitted DOS targets. */
|
||||
export const attestGhidraNativeLoadImage = async (
|
||||
input: NativeLoadImageAttestationInput,
|
||||
): Promise<Result<JsonValue, AnalysisError>> => {
|
||||
@@ -69,7 +71,7 @@ export const attestGhidraNativeLoadImage = async (
|
||||
nativeLoadImageSchema.parse({
|
||||
status: "unsupported",
|
||||
reason:
|
||||
"Independent load-image verification currently supports DOS MZ, explicit DOS COM, and caller-supplied raw-binary targets only.",
|
||||
"Independent load-image verification currently supports DOS MZ and explicit DOS COM targets only.",
|
||||
observations: {
|
||||
...observations,
|
||||
metadata_recovery: [
|
||||
@@ -96,17 +98,13 @@ export const attestGhidraNativeLoadImage = async (
|
||||
);
|
||||
}
|
||||
}
|
||||
if (
|
||||
target.format !== "dos-mz" &&
|
||||
target.format !== "dos-com" &&
|
||||
target.format !== "raw-binary"
|
||||
) {
|
||||
if (target.format !== "dos-mz" && target.format !== "dos-com") {
|
||||
return ok(
|
||||
jsonValueSchema.parse(
|
||||
nativeLoadImageSchema.parse({
|
||||
status: "unsupported",
|
||||
reason:
|
||||
"Independent load-image verification currently supports DOS MZ, explicit DOS COM, and caller-supplied raw-binary targets only.",
|
||||
"Independent load-image verification currently supports DOS MZ and explicit DOS COM targets only.",
|
||||
observations,
|
||||
limitations: [
|
||||
"Other formats expose measured mappings and source identities; no format-specific verification was performed.",
|
||||
@@ -115,33 +113,6 @@ export const attestGhidraNativeLoadImage = async (
|
||||
),
|
||||
);
|
||||
}
|
||||
if (target.format === "raw-binary") {
|
||||
if (client.hashTargetSnapshot === undefined)
|
||||
return err(
|
||||
new ProviderAdapterError("ghidra", operation, {
|
||||
diagnostics: {
|
||||
reason:
|
||||
"The Ghidra client does not expose its immutable target snapshot identity for independent raw-binary load-image verification.",
|
||||
},
|
||||
}),
|
||||
);
|
||||
const snapshot = await client.hashTargetSnapshot(signal);
|
||||
if (!snapshot.ok) return err(mapSessionError(snapshot.error));
|
||||
if (isSignalAborted(signal))
|
||||
return err(new AnalysisCancelledError(operation));
|
||||
const attested = attestGhidraRawBinaryLoadImage(
|
||||
snapshot.value,
|
||||
target,
|
||||
observations,
|
||||
);
|
||||
return attested.ok
|
||||
? ok(jsonValueSchema.parse(attested.value))
|
||||
: err(
|
||||
new ProviderAdapterError("ghidra", operation, {
|
||||
diagnostics: { reason: attested.error },
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (client.readTargetSnapshot === undefined)
|
||||
return err(
|
||||
new ProviderAdapterError("ghidra", operation, {
|
||||
@@ -151,14 +122,14 @@ export const attestGhidraNativeLoadImage = async (
|
||||
},
|
||||
}),
|
||||
);
|
||||
const snapshot = await client.readTargetSnapshot(undefined, signal);
|
||||
const snapshot = await client.readTargetSnapshot();
|
||||
if (!snapshot.ok) return err(mapSessionError(snapshot.error));
|
||||
if (snapshot.value.kind !== "captured")
|
||||
return err(
|
||||
new ProviderAdapterError("ghidra", operation, {
|
||||
diagnostics: {
|
||||
reason:
|
||||
"The uncapped load-image snapshot was unexpectedly not captured.",
|
||||
"The uncapped DOS load-image snapshot was unexpectedly not captured.",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -7,10 +7,8 @@ import {
|
||||
} from "../domain/native/nativeLoadImage.js";
|
||||
import { parseDosMzHeader, type DosMzHeader } from "../domain/dosMz.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
|
||||
import { validateDosComLength } from "../domain/dosCom.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { ghidraRawBinaryLanguage } from "./GhidraRawBinaryLanguage.js";
|
||||
|
||||
const sha256 = (bytes: Buffer): string =>
|
||||
createHash("sha256").update(bytes).digest("hex");
|
||||
@@ -327,111 +325,3 @@ export const attestGhidraDosComLoadImage = (
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const hexAddress = (value: bigint): string => `0x${value.toString(16)}`;
|
||||
|
||||
/** Verify a caller-supplied raw-binary mapping against measured Ghidra import facts. */
|
||||
export const attestGhidraRawBinaryLoadImage = (
|
||||
snapshot: { readonly sha256: string; readonly bytes: number },
|
||||
target: Extract<BinaryTarget, { format: "raw-binary" }>,
|
||||
observations: NativeLoadImageObservation,
|
||||
): Result<NativeLoadImage, string> => {
|
||||
if (snapshot.sha256 !== target.sha256)
|
||||
return err(
|
||||
"Ghidra raw-binary snapshot digest does not match the admitted target",
|
||||
);
|
||||
const language = ghidraRawBinaryLanguage(target.architecture);
|
||||
const base = BigInt(target.entryPoint);
|
||||
const last = hexAddress(base + BigInt(snapshot.bytes) - 1n);
|
||||
const checks: NativeLoadImageCheck[] = [];
|
||||
const check = (
|
||||
name: string,
|
||||
expected: JsonValue,
|
||||
observed: JsonValue,
|
||||
fileOffset: number | null = null,
|
||||
location: string | null = null,
|
||||
): void => {
|
||||
checks.push({
|
||||
name,
|
||||
matched: JSON.stringify(expected) === JSON.stringify(observed),
|
||||
expected,
|
||||
observed,
|
||||
file_offset: fileOffset,
|
||||
address: location,
|
||||
});
|
||||
};
|
||||
const source = observations.source_files[0];
|
||||
const mapping = observations.mappings[0];
|
||||
check("executable_format", "Raw Binary", observations.executable_format);
|
||||
check("language_id", language.languageId, observations.language_id);
|
||||
check(
|
||||
"compiler_spec_id",
|
||||
language.compilerSpecId,
|
||||
observations.compiler_spec_id,
|
||||
);
|
||||
// BinaryLoader's block base is independent of the Program image base.
|
||||
check("image_base", "0x0", observations.image_base);
|
||||
check("source_file_count", 1, observations.source_files.length);
|
||||
check("source_file_size", snapshot.bytes, source?.size ?? null);
|
||||
check("original_file_sha256", target.sha256, source?.original_sha256 ?? null);
|
||||
check("modified_file_sha256", target.sha256, source?.modified_sha256 ?? null);
|
||||
check("mapping_count", 1, observations.mappings.length);
|
||||
check(
|
||||
"mapping.file_offset",
|
||||
0,
|
||||
mapping?.file_offset ?? null,
|
||||
0,
|
||||
mapping?.start ?? null,
|
||||
);
|
||||
check(
|
||||
"mapping.start",
|
||||
target.entryPoint,
|
||||
mapping?.start ?? null,
|
||||
0,
|
||||
mapping?.start ?? null,
|
||||
);
|
||||
check("mapping.end", last, mapping?.end ?? null, 0, mapping?.end ?? null);
|
||||
check(
|
||||
"mapping.length",
|
||||
snapshot.bytes,
|
||||
mapping?.length ?? null,
|
||||
0,
|
||||
mapping?.start ?? null,
|
||||
);
|
||||
check(
|
||||
"mapping.sha256",
|
||||
snapshot.sha256,
|
||||
mapping?.sha256 ?? null,
|
||||
0,
|
||||
mapping?.start ?? null,
|
||||
);
|
||||
check(
|
||||
"entry_point",
|
||||
target.entryPoint,
|
||||
observations.entry_points.find((entry) => entry === target.entryPoint) ??
|
||||
null,
|
||||
);
|
||||
check("relocation_records", [], observations.relocations);
|
||||
return ok(
|
||||
nativeLoadImageSchema.parse({
|
||||
status: checks.every((item) => item.matched) ? "verified" : "mismatch",
|
||||
format: "raw-binary",
|
||||
target_sha256: target.sha256,
|
||||
architecture: target.architecture,
|
||||
language_id: language.languageId,
|
||||
compiler_spec_id: language.compilerSpecId,
|
||||
base_address: target.entryPoint,
|
||||
file_bytes: snapshot.bytes,
|
||||
entry: { address: target.entryPoint, file_offset: 0 },
|
||||
observations,
|
||||
checks,
|
||||
limitations: [
|
||||
"Raw binary is a headerless interpretation explicitly selected by the caller, not format identification from file bytes.",
|
||||
"Verification covers complete original/modified source identity, mapped file bytes, the caller-supplied entry, and the bound little-endian Ghidra language. File offset 0 is mapped at the entry address.",
|
||||
"Ghidra may report additional language-defined external entries outside the mapped image. They are preserved as observations; verification requires the caller-supplied entry and does not attest other entries.",
|
||||
"Reset vectors, memory-mapped I/O, big-endian and Thumb-only variants, and runtime boot behavior are not modeled or verified. No original executable bytes are changed.",
|
||||
"Mapping ends are inclusive; a mismatching digest identifies its source range, not the first differing byte.",
|
||||
],
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -10,7 +10,6 @@ import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { fixtureDosLoadImage } from "./GhidraLoadImage.fixture.js";
|
||||
import { fixtureRawBinaryLoadImage } from "./GhidraRawBinaryLoadImage.fixture.js";
|
||||
import {
|
||||
nativeAotPeDigest,
|
||||
nativeAotPeFixture,
|
||||
@@ -178,50 +177,6 @@ describe("Ghidra provider", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ghidra raw-binary profile", () => {
|
||||
it("commits BinaryLoader language and caller-supplied entry", async () => {
|
||||
const ghidra = provider();
|
||||
const target: BinaryTarget = {
|
||||
path: "/tmp/ecu.bin",
|
||||
sha256: "a".repeat(64),
|
||||
kind: "executable",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
availableArchitectures: ["arm"],
|
||||
entryPoint: "0x8000000",
|
||||
entryPointSource: "0x08000000",
|
||||
};
|
||||
expect(ghidra.inspectTargetSupport(target).status).toBe("supported");
|
||||
const resolved = await ghidra.resolveAnalysisProfile(target);
|
||||
expect(resolved.ok && resolved.value).toMatchObject({
|
||||
profile: {
|
||||
parameters: {
|
||||
target_format: "raw-binary",
|
||||
architecture: "arm",
|
||||
loader: "BinaryLoader",
|
||||
language_id: "ARM:LE:32:v7",
|
||||
compiler_spec_id: "default",
|
||||
language_selection: "caller-supplied-v1",
|
||||
entry_point: "0x8000000",
|
||||
},
|
||||
},
|
||||
});
|
||||
const shifted = await ghidra.resolveAnalysisProfile({
|
||||
...target,
|
||||
entryPoint: "0x8001000",
|
||||
entryPointSource: "0x8001000",
|
||||
});
|
||||
expect(resolved.ok && shifted.ok).toBe(true);
|
||||
if (!resolved.ok || !shifted.ok || resolved.value.profile === null)
|
||||
throw new Error("expected raw-binary profiles");
|
||||
expect(shifted.value.profile?.digest).not.toBe(
|
||||
resolved.value.profile.digest,
|
||||
);
|
||||
const windows = provider({ ...installationHost(), platform: "win32" });
|
||||
expect(windows.inspectTargetSupport(target).status).toBe("unsupported");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ghidra Mach-O slice support", () => {
|
||||
it("refuses universal targets whose selected slice cannot be enforced", () => {
|
||||
const ghidra = provider();
|
||||
@@ -763,88 +718,6 @@ describe("Ghidra result projection", () => {
|
||||
});
|
||||
|
||||
describe("Ghidra measured load-image projection", () => {
|
||||
it.each(["verified", "changed-snapshot", "cancelled"] as const)(
|
||||
"streams raw snapshot identity and preserves %s outcomes",
|
||||
async (state) => {
|
||||
const fixture = fixtureRawBinaryLoadImage();
|
||||
const controller = new AbortController();
|
||||
const signals: (AbortSignal | undefined)[] = [];
|
||||
const ghidra = provider(installationHost(), () => ({
|
||||
start: () => Promise.resolve(ok(sessionInfo())),
|
||||
callTool: (operation) => {
|
||||
if (operation !== "inspect_native_load_image")
|
||||
throw new Error(`unexpected operation ${operation}`);
|
||||
return Promise.resolve(
|
||||
ok(jsonValueSchema.parse(fixture.observation)),
|
||||
);
|
||||
},
|
||||
readTargetSnapshot: () => {
|
||||
throw new Error(
|
||||
"raw verification must not capture the complete file",
|
||||
);
|
||||
},
|
||||
hashTargetSnapshot: (signal) => {
|
||||
signals.push(signal);
|
||||
if (state === "cancelled") {
|
||||
controller.abort();
|
||||
return Promise.resolve(
|
||||
err(
|
||||
new GhidraSessionError(
|
||||
"cancelled",
|
||||
"Snapshot hashing cancelled",
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Promise.resolve(
|
||||
ok({
|
||||
...fixture.snapshot,
|
||||
...(state === "changed-snapshot"
|
||||
? { sha256: "f".repeat(64) }
|
||||
: {}),
|
||||
}),
|
||||
);
|
||||
},
|
||||
close: () => Promise.resolve(ok(null)),
|
||||
}));
|
||||
const resolved = await ghidra.resolveAnalysisProfile(fixture.target);
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
if (resolved.value.profile === null)
|
||||
throw new Error("expected raw profile");
|
||||
const client = ghidra.createClient(
|
||||
fixture.target,
|
||||
resolved.value.profile,
|
||||
);
|
||||
try {
|
||||
const result = await client.execute(
|
||||
"inspect_native_load_image",
|
||||
{},
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
expect(signals).toEqual([controller.signal]);
|
||||
if (state === "verified") {
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.result).toMatchObject({
|
||||
status: "verified",
|
||||
observations: fixture.observation,
|
||||
});
|
||||
} else {
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag:
|
||||
state === "cancelled"
|
||||
? "AnalysisCancelledError"
|
||||
: "ProviderAdapterError",
|
||||
},
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
"verified",
|
||||
"mismatch",
|
||||
|
||||
@@ -87,18 +87,12 @@ import {
|
||||
windowsNativeAuthorityUnavailableReason,
|
||||
hasWindowsNativeAuthority,
|
||||
} from "../process/WindowsAuthority.js";
|
||||
import { ghidraRawBinaryLanguage } from "./GhidraRawBinaryLanguage.js";
|
||||
|
||||
/** Production seam for exercising provider projection without a real process. */
|
||||
export type GhidraProviderClientFactory = (
|
||||
options: GhidraClientOptions,
|
||||
) => Pick<GhidraClient, "start" | "callTool" | "close"> &
|
||||
Partial<
|
||||
Pick<
|
||||
GhidraClient,
|
||||
"runtimeLineage" | "readTargetSnapshot" | "hashTargetSnapshot"
|
||||
>
|
||||
>;
|
||||
Partial<Pick<GhidraClient, "runtimeLineage" | "readTargetSnapshot">>;
|
||||
|
||||
type GhidraProviderClientInstance = ReturnType<GhidraProviderClientFactory>;
|
||||
|
||||
@@ -446,10 +440,6 @@ export const createGhidraProviderClient = (input: {
|
||||
let extensionFailure: AnalysisError | undefined;
|
||||
// Replaced by the reported outcome once the session handshake is checked.
|
||||
const seedLimitations: string[] = [...ghidraSeedLimitations(seeds)];
|
||||
const rawLanguage =
|
||||
target.format === "raw-binary"
|
||||
? ghidraRawBinaryLanguage(target.architecture)
|
||||
: undefined;
|
||||
const targetLimitations = [
|
||||
...(target.format === "dos-mz"
|
||||
? [
|
||||
@@ -457,13 +447,6 @@ export const createGhidraProviderClient = (input: {
|
||||
"Static DOS analysis does not emulate BIOS, DOS interrupts, device ports, or self-modifying unpacking code. Packed targets require a separately identified unpacked artifact for original-program analysis; appended overlays are not the initialized load module.",
|
||||
]
|
||||
: []),
|
||||
...(target.format === "raw-binary"
|
||||
? [
|
||||
"Headerless raw-binary analysis uses the caller-supplied architecture and entry address; file offset 0 is mapped at that address. Headers are not discovered from file bytes.",
|
||||
"Little-endian generic Ghidra languages are used for x86, x86_64, arm, and arm64. Big-endian, Thumb-only, Cortex-M, and other processor variants are unsupported in this increment.",
|
||||
"Static analysis does not emulate reset vectors, memory-mapped I/O, or firmware boot sequences.",
|
||||
]
|
||||
: []),
|
||||
...(target.kind === "executable" && target.architecture === "mips"
|
||||
? (target.mips.limitations ?? [])
|
||||
: []),
|
||||
@@ -491,15 +474,6 @@ export const createGhidraProviderClient = (input: {
|
||||
: {}),
|
||||
...(target.format === "dos-mz" ? { dosMz: true } : {}),
|
||||
...(target.format === "dos-com" ? { dosCom: true } : {}),
|
||||
...(rawLanguage === undefined || target.format !== "raw-binary"
|
||||
? {}
|
||||
: {
|
||||
rawBinary: {
|
||||
languageId: rawLanguage.languageId,
|
||||
compilerSpecId: rawLanguage.compilerSpecId,
|
||||
baseAddr: target.entryPoint,
|
||||
},
|
||||
}),
|
||||
...(languageOverride === undefined ? {} : { languageOverride }),
|
||||
...(seeds === undefined ? {} : { analysisSeeds: seeds }),
|
||||
platform: installation.platform,
|
||||
@@ -521,18 +495,13 @@ export const createGhidraProviderClient = (input: {
|
||||
expectedLanguageId: "x86:LE:16:Real Mode",
|
||||
expectedCompilerSpecId: "default",
|
||||
}
|
||||
: rawLanguage === undefined
|
||||
? languageOverride === undefined
|
||||
? {}
|
||||
: {
|
||||
expectedLanguageId: languageOverride.languageId,
|
||||
...(languageOverride.compilerSpecId === undefined
|
||||
? {}
|
||||
: { expectedCompilerSpecId: languageOverride.compilerSpecId }),
|
||||
}
|
||||
: languageOverride === undefined
|
||||
? {}
|
||||
: {
|
||||
expectedLanguageId: rawLanguage.languageId,
|
||||
expectedCompilerSpecId: rawLanguage.compilerSpecId,
|
||||
expectedLanguageId: languageOverride.languageId,
|
||||
...(languageOverride.compilerSpecId === undefined
|
||||
? {}
|
||||
: { expectedCompilerSpecId: languageOverride.compilerSpecId }),
|
||||
}),
|
||||
...(psp
|
||||
? {
|
||||
@@ -604,7 +573,7 @@ export const createGhidraProviderClient = (input: {
|
||||
),
|
||||
);
|
||||
if (operation === "health") {
|
||||
const started = await client.start(options?.signal, options?.progress);
|
||||
const started = await client.start(options?.signal);
|
||||
if (!started.ok)
|
||||
return err(
|
||||
projectSessionError(
|
||||
@@ -627,7 +596,7 @@ export const createGhidraProviderClient = (input: {
|
||||
: parseGhidraInventoryInput(operation, parameters);
|
||||
if (!input.ok) return input;
|
||||
if (extensions.length > 0 || seeds !== undefined) {
|
||||
const started = await client.start(options?.signal, options?.progress);
|
||||
const started = await client.start(options?.signal);
|
||||
if (!started.ok)
|
||||
return err(
|
||||
projectSessionError(
|
||||
@@ -639,12 +608,11 @@ export const createGhidraProviderClient = (input: {
|
||||
const failed = await checkExtensions(operation, started.value);
|
||||
if (failed !== undefined) return err(failed);
|
||||
}
|
||||
const called = await client.callTool(operation, input.value, {
|
||||
...(options?.signal === undefined ? {} : { signal: options.signal }),
|
||||
...(options?.progress === undefined
|
||||
? {}
|
||||
: { progress: options.progress }),
|
||||
});
|
||||
const called = await client.callTool(
|
||||
operation,
|
||||
input.value,
|
||||
options?.signal === undefined ? {} : { signal: options.signal },
|
||||
);
|
||||
if (!called.ok)
|
||||
return err(
|
||||
projectSessionError(
|
||||
@@ -669,10 +637,7 @@ export const createGhidraProviderClient = (input: {
|
||||
const address = input.value.address;
|
||||
if (typeof address === "string") {
|
||||
if (target.format === "pe" && nativeAotOwner !== undefined) {
|
||||
const started = await client.start(
|
||||
options?.signal,
|
||||
options?.progress,
|
||||
);
|
||||
const started = await client.start(options?.signal);
|
||||
if (!started.ok)
|
||||
return err(
|
||||
projectSessionError(
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import type { BinaryArchitecture } from "../domain/binaryTargetTypes.js";
|
||||
|
||||
/** Bound Ghidra language for a caller-supplied raw-binary architecture. */
|
||||
export interface GhidraRawBinaryLanguage {
|
||||
readonly languageId: string;
|
||||
readonly compilerSpecId: "default";
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the four caller-visible CPU families to little-endian generic Ghidra
|
||||
* languages. Big-endian, Thumb-only, and Cortex-M variants are out of scope.
|
||||
*/
|
||||
export const ghidraRawBinaryLanguage = (
|
||||
architecture: Exclude<BinaryArchitecture, "mips">,
|
||||
): GhidraRawBinaryLanguage => {
|
||||
switch (architecture) {
|
||||
case "x86":
|
||||
return { languageId: "x86:LE:32:default", compilerSpecId: "default" };
|
||||
case "x86_64":
|
||||
return { languageId: "x86:LE:64:default", compilerSpecId: "default" };
|
||||
case "arm":
|
||||
return { languageId: "ARM:LE:32:v7", compilerSpecId: "default" };
|
||||
case "arm64":
|
||||
return { languageId: "AARCH64:LE:64:v8A", compilerSpecId: "default" };
|
||||
}
|
||||
};
|
||||
@@ -1,62 +0,0 @@
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
import type { NativeLoadImageObservation } from "../domain/native/nativeLoadImage.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
|
||||
|
||||
const hash = (bytes: Buffer): string =>
|
||||
createHash("sha256").update(bytes).digest("hex");
|
||||
|
||||
export const fixtureRawBinaryLoadImage = (): {
|
||||
snapshot: { sha256: string; bytes: number };
|
||||
target: Extract<BinaryTarget, { format: "raw-binary" }>;
|
||||
observation: NativeLoadImageObservation;
|
||||
} => {
|
||||
const bytes = Buffer.from("1eff2fe1", "hex");
|
||||
const digest = hash(bytes);
|
||||
return {
|
||||
snapshot: { sha256: digest, bytes: bytes.length },
|
||||
target: {
|
||||
path: "/tmp/ecu.bin",
|
||||
sha256: digest,
|
||||
kind: "executable",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
availableArchitectures: ["arm"],
|
||||
entryPoint: "0x8000000",
|
||||
entryPointSource: "0x08000000",
|
||||
},
|
||||
observation: {
|
||||
executable_format: "Raw Binary",
|
||||
language_id: "ARM:LE:32:v7",
|
||||
compiler_spec_id: "default",
|
||||
image_base: "0x0",
|
||||
default_address_space: "ram",
|
||||
source_files: [
|
||||
{
|
||||
name: "ecu.bin",
|
||||
size: bytes.length,
|
||||
original_sha256: digest,
|
||||
modified_sha256: digest,
|
||||
},
|
||||
],
|
||||
mappings: [
|
||||
{
|
||||
block: "ram",
|
||||
start: "0x8000000",
|
||||
end: "0x8000003",
|
||||
address_space: "ram",
|
||||
initialized: true,
|
||||
loaded: true,
|
||||
overlay: false,
|
||||
length: bytes.length,
|
||||
source_file_index: 0,
|
||||
file_offset: 0,
|
||||
sha256: digest,
|
||||
},
|
||||
],
|
||||
relocations: [],
|
||||
entry_points: ["0x8000000"],
|
||||
entry_context: [],
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -1,98 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { attestGhidraRawBinaryLoadImage } from "./GhidraLoadImageValues.js";
|
||||
import { fixtureRawBinaryLoadImage } from "./GhidraRawBinaryLoadImage.fixture.js";
|
||||
import { ghidraRawBinaryLanguage } from "./GhidraRawBinaryLanguage.js";
|
||||
|
||||
describe("raw-binary Ghidra language binding", () => {
|
||||
it("maps the four admitted families to little-endian generic languages", () => {
|
||||
expect(ghidraRawBinaryLanguage("x86")).toEqual({
|
||||
languageId: "x86:LE:32:default",
|
||||
compilerSpecId: "default",
|
||||
});
|
||||
expect(ghidraRawBinaryLanguage("x86_64")).toEqual({
|
||||
languageId: "x86:LE:64:default",
|
||||
compilerSpecId: "default",
|
||||
});
|
||||
expect(ghidraRawBinaryLanguage("arm")).toEqual({
|
||||
languageId: "ARM:LE:32:v7",
|
||||
compilerSpecId: "default",
|
||||
});
|
||||
expect(ghidraRawBinaryLanguage("arm64")).toEqual({
|
||||
languageId: "AARCH64:LE:64:v8A",
|
||||
compilerSpecId: "default",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("raw-binary independent load-image checks", () => {
|
||||
it("verifies mapped bytes at the caller-supplied entry", () => {
|
||||
const f = fixtureRawBinaryLoadImage();
|
||||
const result = attestGhidraRawBinaryLoadImage(
|
||||
f.snapshot,
|
||||
f.target,
|
||||
f.observation,
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
ok: true,
|
||||
value: {
|
||||
status: "verified",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
language_id: "ARM:LE:32:v7",
|
||||
base_address: "0x8000000",
|
||||
file_bytes: 4,
|
||||
entry: { address: "0x8000000", file_offset: 0 },
|
||||
},
|
||||
});
|
||||
});
|
||||
it("retains mismatch evidence for a drifted language", () => {
|
||||
const f = fixtureRawBinaryLoadImage();
|
||||
f.observation.language_id = "x86:LE:32:default";
|
||||
const result = attestGhidraRawBinaryLoadImage(
|
||||
f.snapshot,
|
||||
f.target,
|
||||
f.observation,
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
ok: true,
|
||||
value: { status: "mismatch", observations: f.observation },
|
||||
});
|
||||
});
|
||||
it("preserves additional language entries while requiring the caller entry", () => {
|
||||
const f = fixtureRawBinaryLoadImage();
|
||||
f.observation.entry_points = ["0x0", f.target.entryPoint, "0xffff0000"];
|
||||
expect(
|
||||
attestGhidraRawBinaryLoadImage(f.snapshot, f.target, f.observation),
|
||||
).toMatchObject({
|
||||
ok: true,
|
||||
value: { status: "verified", observations: f.observation },
|
||||
});
|
||||
f.observation.entry_points = ["0x0", "0xffff0000"];
|
||||
expect(
|
||||
attestGhidraRawBinaryLoadImage(f.snapshot, f.target, f.observation),
|
||||
).toMatchObject({
|
||||
ok: true,
|
||||
value: {
|
||||
status: "mismatch",
|
||||
checks: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: "entry_point",
|
||||
matched: false,
|
||||
observed: null,
|
||||
}),
|
||||
]),
|
||||
},
|
||||
});
|
||||
});
|
||||
it("rejects stale snapshot identity", () => {
|
||||
const f = fixtureRawBinaryLoadImage();
|
||||
expect(
|
||||
attestGhidraRawBinaryLoadImage(
|
||||
f.snapshot,
|
||||
{ ...f.target, sha256: "f".repeat(64) },
|
||||
f.observation,
|
||||
).ok,
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -140,7 +140,6 @@ export const hopperLoaderArgsForTarget = (
|
||||
return ok(["-l", "WinPE", flag]);
|
||||
case "dos-mz":
|
||||
case "dos-com":
|
||||
case "raw-binary":
|
||||
return err(
|
||||
new ProviderAdapterError("hopper", "resolve_analysis_profile"),
|
||||
);
|
||||
|
||||
@@ -5,27 +5,6 @@ import { silentLogger } from "../logger.js";
|
||||
import { HopperProvider } from "./HopperProvider.js";
|
||||
|
||||
describe("Hopper provider capabilities", () => {
|
||||
it("declines headerless raw-binary targets with a Ghidra-directed reason", () => {
|
||||
const config = parseConfig({});
|
||||
if (!config.ok) throw new Error("expected valid configuration");
|
||||
const provider = new HopperProvider(config.value, silentLogger, {});
|
||||
expect(
|
||||
provider.inspectTargetSupport({
|
||||
path: "/tmp/ecu.bin",
|
||||
sha256: "a".repeat(64),
|
||||
kind: "executable",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
availableArchitectures: ["arm"],
|
||||
entryPoint: "0x8000000",
|
||||
entryPointSource: "0x8000000",
|
||||
}),
|
||||
).toMatchObject({
|
||||
status: "unsupported",
|
||||
code: "target_format_unsupported",
|
||||
reason: expect.stringContaining("Ghidra"),
|
||||
});
|
||||
});
|
||||
it("declines DOS MZ targets with a provider-specific support reason", () => {
|
||||
const config = parseConfig({});
|
||||
if (!config.ok) throw new Error("expected valid configuration");
|
||||
|
||||
@@ -123,14 +123,6 @@ export class HopperProvider implements AnalysisProviderCandidate {
|
||||
reason: "REA's Hopper adapter does not admit MIPS targets.",
|
||||
diagnostics,
|
||||
};
|
||||
if (target.format === "raw-binary")
|
||||
return {
|
||||
status: "unsupported",
|
||||
code: "target_format_unsupported",
|
||||
reason:
|
||||
"Headerless raw-binary analysis requires the Ghidra adapter with a caller-supplied architecture and entry point.",
|
||||
diagnostics,
|
||||
};
|
||||
if (target.format === "dos-mz" || target.format === "dos-com")
|
||||
return {
|
||||
status: "unsupported",
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { parseConfig } from "../config/parseConfig.js";
|
||||
import { IdaProvider } from "./IdaProvider.js";
|
||||
|
||||
describe("IDA provider target support", () => {
|
||||
it("declines headerless raw-binary targets", () => {
|
||||
const config = parseConfig({});
|
||||
if (!config.ok) throw new Error("expected valid configuration");
|
||||
const provider = new IdaProvider(config.value, {});
|
||||
expect(
|
||||
provider.inspectTargetSupport({
|
||||
path: "/tmp/ecu.bin",
|
||||
sha256: "a".repeat(64),
|
||||
kind: "executable",
|
||||
format: "raw-binary",
|
||||
architecture: "arm",
|
||||
availableArchitectures: ["arm"],
|
||||
entryPoint: "0x8000000",
|
||||
entryPointSource: "0x8000000",
|
||||
}),
|
||||
).toMatchObject({
|
||||
status: "unsupported",
|
||||
code: "target_format_unsupported",
|
||||
reason: expect.stringContaining("Ghidra"),
|
||||
});
|
||||
});
|
||||
});
|
||||
+9
-17
@@ -109,23 +109,15 @@ export class IdaProvider implements AnalysisProviderCandidate {
|
||||
"REA's IDA adapter has no verified MIPS lane. Select a supported Ghidra profile instead.",
|
||||
diagnostics,
|
||||
};
|
||||
if (target.kind !== "executable")
|
||||
return {
|
||||
status: "unsupported",
|
||||
code: "target_kind_unsupported",
|
||||
reason:
|
||||
"IDA MCP integration admits executable inputs, not analysis databases. Select the original input binary.",
|
||||
diagnostics,
|
||||
};
|
||||
if (target.format === "raw-binary")
|
||||
return {
|
||||
status: "unsupported",
|
||||
code: "target_format_unsupported",
|
||||
reason:
|
||||
"IDA does not admit headerless raw binaries. Open the target with Ghidra and supply architecture and entry_point.",
|
||||
diagnostics,
|
||||
};
|
||||
return { status: "supported", code: null, reason: null, diagnostics };
|
||||
return target.kind === "executable"
|
||||
? { status: "supported", code: null, reason: null, diagnostics }
|
||||
: {
|
||||
status: "unsupported",
|
||||
code: "target_kind_unsupported",
|
||||
reason:
|
||||
"IDA MCP integration admits executable inputs, not analysis databases. Select the original input binary.",
|
||||
diagnostics,
|
||||
};
|
||||
}
|
||||
async resolveAnalysisProfile(
|
||||
_target: BinaryTarget,
|
||||
|
||||
@@ -22,10 +22,8 @@ export const mcpProgressReporter = (
|
||||
method: "notifications/progress",
|
||||
params: {
|
||||
progressToken: token,
|
||||
// Status phases can repeat their work count while waiting. The
|
||||
// protocol requires every notification to advance; count emitted
|
||||
// observations without inventing a total amount of analysis work.
|
||||
progress: update.sequence,
|
||||
progress: update.completed,
|
||||
...(update.total === null ? {} : { total: update.total }),
|
||||
message: `${update.phase}: ${update.message}`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -12,7 +12,6 @@ import { ProcessCaptureResourceScope } from "../process/capture/ProcessCaptureLi
|
||||
import { ProcessCaptureError } from "../process/capture/ProcessCaptureError.js";
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import type { AnalysisSnapshot } from "../domain/analysisSnapshot.js";
|
||||
import { binaryTargetSummary } from "../application/binary/BinaryTargetSummary.js";
|
||||
import { UnknownRegistryError } from "../domain/unknownRegistryError.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import type { Evidence } from "../domain/evidence.js";
|
||||
@@ -204,12 +203,6 @@ const registerOpenLifecycleTool = ({
|
||||
session.open(input.path, {
|
||||
signal: context.mcpReq.signal,
|
||||
...(input.format === undefined ? {} : { formatHint: input.format }),
|
||||
...(input.architecture === undefined
|
||||
? {}
|
||||
: { architecture: input.architecture }),
|
||||
...(input.entry_point === undefined
|
||||
? {}
|
||||
: { entryPoint: input.entry_point }),
|
||||
...(input.provider_id === undefined
|
||||
? {}
|
||||
: { providerId: input.provider_id }),
|
||||
@@ -220,7 +213,13 @@ const registerOpenLifecycleTool = ({
|
||||
? server.delivery.toCallToolResult(
|
||||
{
|
||||
ok: true,
|
||||
value: binaryTargetSummary(opened.value),
|
||||
value: {
|
||||
path: opened.value.path,
|
||||
format: opened.value.format,
|
||||
kind: opened.value.kind,
|
||||
sha256: opened.value.sha256,
|
||||
architecture: opened.value.architecture ?? null,
|
||||
},
|
||||
},
|
||||
openContract,
|
||||
)
|
||||
|
||||
@@ -67,10 +67,8 @@ describe("derived MCP operation boundary", () => {
|
||||
);
|
||||
|
||||
expect(result).toEqual({ ok: true, value: "complete" });
|
||||
expect(notifications.map(({ params }) => params?.progress)).toEqual([1, 2]);
|
||||
expect(
|
||||
notifications.every(({ params }) => params?.total === undefined),
|
||||
).toBe(true);
|
||||
expect(notifications.map(({ params }) => params?.progress)).toEqual([0, 2]);
|
||||
expect(notifications.every(({ params }) => params?.total === 2)).toBe(true);
|
||||
});
|
||||
|
||||
it("projects synchronous computation failures into a typed result", async () => {
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
||||
import { ROLLDOWN_MODULE_INTEROP } from "../../../src/domain/javascript/javascriptModuleInterop.fixture.js";
|
||||
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
const INTRINSIC_MUTATIONS = [
|
||||
["poisoned.cjs", "({Object} = replacements);"],
|
||||
[
|
||||
"projected.cjs",
|
||||
'const {defineProperty:change} = Object; change(Object,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"decorated.cjs",
|
||||
'@(() => Object) class metadata {}; Object.defineProperty(metadata,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"uncurried.cjs",
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null); change(Object,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"generic-bind.cjs",
|
||||
'const change = Function.prototype.bind.call(Object.defineProperty,null); change(Object,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"replaced-apply.cjs",
|
||||
'Reflect.apply = Object.defineProperty; Reflect.apply(Object,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"bound.cjs",
|
||||
'const change = Object.defineProperty.bind(null,Object,"create"); change({value:customCreate});',
|
||||
],
|
||||
["receiver.cjs", 'Reflect.set({},"create",customCreate,Object);'],
|
||||
] as const;
|
||||
|
||||
const writePoisonedModules = async (root: string): Promise<void> => {
|
||||
for (const [name, mutation] of INTRINSIC_MUTATIONS)
|
||||
await writeFile(
|
||||
join(root, name),
|
||||
`${mutation}
|
||||
${ROLLDOWN_MODULE_INTEROP}
|
||||
let poisoned = require("electron");
|
||||
poisoned = __toESM(poisoned, 1);
|
||||
new poisoned.BrowserWindow({});
|
||||
throw new Error("must not execute poisoned source");`,
|
||||
);
|
||||
};
|
||||
|
||||
cliTest.for(["CLI", "stdio MCP"] as const)(
|
||||
"retains converted Electron windows and preload evidence through %s",
|
||||
async (surface, { cli }) => {
|
||||
const root = await createTestTempDirectory("rea-electron-interop-");
|
||||
await writeFile(
|
||||
join(root, "package.json"),
|
||||
JSON.stringify({ main: "main.cjs" }),
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "preload.js"),
|
||||
'throw new Error("must stay inert");',
|
||||
);
|
||||
await writePoisonedModules(root);
|
||||
const source = `const metadata = {};
|
||||
Object.defineProperty(metadata,"x",{value:1});
|
||||
const decorateMetadata = Object.defineProperty.bind(null,metadata,"bound");
|
||||
decorateMetadata({value:1});
|
||||
const decorateViaCall = Function.prototype.call.bind(Object.defineProperty);
|
||||
decorateViaCall(null,metadata,"uncurried",{value:1});
|
||||
const localFunction = () => {};
|
||||
Object.defineProperty(localFunction,"x",{value:1});
|
||||
const localClass = class {};
|
||||
Object.defineProperty(localClass,"x",{value:1});
|
||||
const localRegExp = /local/;
|
||||
Object.defineProperty(localRegExp,"x",{value:1});
|
||||
Object.defineProperty(hoistedFunction,"x",{value:1});
|
||||
function hoistedFunction() {}
|
||||
const captured = Object.defineProperty;
|
||||
Object.defineProperty = custom;
|
||||
${ROLLDOWN_MODULE_INTEROP.replace("__defProp = Object.defineProperty", "__defProp = captured")}
|
||||
let electron = require("electron");
|
||||
electron = __toESM(electron, 1);
|
||||
new electron.BrowserWindow({webPreferences:{preload:"./preload.js"}});
|
||||
new electron.BrowserWindow({webPreferences:{preload:runtimePath}});
|
||||
var direct;
|
||||
var direct = require("electron");
|
||||
var direct;
|
||||
new direct.BrowserWindow({});
|
||||
const fresh = __toESM(require("electron"), 1);
|
||||
new fresh.BrowserWindow({});
|
||||
const {BrowserWindow: ProjectedWindow} = __toESM(require("electron"));
|
||||
new ProjectedWindow({});
|
||||
const nonNode = __toESM(require("electron"), 0);
|
||||
new nonNode.BrowserWindow({});
|
||||
function identity(mod) {return mod;}
|
||||
const passthrough = identity(require("electron"));
|
||||
new passthrough.BrowserWindow({});
|
||||
const __importStar = () => ({BrowserWindow:FakeWindow});
|
||||
const fake = __importStar(require("electron"));
|
||||
new fake.BrowserWindow({});
|
||||
function decoy(electron) {new electron.BrowserWindow({});}
|
||||
require("./poisoned.cjs");
|
||||
require("./projected.cjs");
|
||||
require("./decorated.cjs");
|
||||
require("./bound.cjs");
|
||||
require("./uncurried.cjs");
|
||||
require("./generic-bind.cjs");
|
||||
require("./replaced-apply.cjs");
|
||||
require("./receiver.cjs");
|
||||
throw new Error("must not execute main");
|
||||
`;
|
||||
await writeFile(join(root, "main.cjs"), source);
|
||||
let document: unknown;
|
||||
if (surface === "CLI") {
|
||||
const response = await cli.run({
|
||||
arguments: ["analyze-javascript-application", root, "--json"],
|
||||
});
|
||||
expect(response.exitCode, response.stderr).toBe(0);
|
||||
document = response.json;
|
||||
} else {
|
||||
const { call } = await connectLocalToolsMcp();
|
||||
const response = await call("analyze_javascript_application", {
|
||||
input_path: root,
|
||||
});
|
||||
expect(response.isError, JSON.stringify(response)).not.toBe(true);
|
||||
document = response.structuredContent;
|
||||
}
|
||||
const result = z
|
||||
.object({ normalized_result: javascriptApplicationAnalysisResultSchema })
|
||||
.parse(document).normalized_result;
|
||||
expect(result.summary).toMatchObject({
|
||||
browser_windows: 7,
|
||||
preload_entrypoints: 1,
|
||||
});
|
||||
expect(result.statistics.parse_failures).toBe(0);
|
||||
expect(result.statistics.parsed_javascript_files).toBe(10);
|
||||
const windows = result.graph.nodes.filter(
|
||||
({ kind }) => kind === "browser-window",
|
||||
);
|
||||
expect(windows).toHaveLength(7);
|
||||
const expectedLines = source
|
||||
.split("\n")
|
||||
.flatMap((line, index) =>
|
||||
/^\s*new (?:(?:electron|direct|fresh|passthrough|nonNode)\.BrowserWindow|ProjectedWindow)\(/u.test(
|
||||
line,
|
||||
)
|
||||
? [index + 1]
|
||||
: [],
|
||||
);
|
||||
const observedLines = windows.flatMap((window) => {
|
||||
const location = window.observations[0]?.evidence.location;
|
||||
return location?.available && location.value.kind === "source-range"
|
||||
? [location.value.start.line]
|
||||
: [];
|
||||
});
|
||||
expect(observedLines.toSorted()).toEqual(expectedLines.toSorted());
|
||||
for (const window of windows) {
|
||||
expect(window.observations[0]?.evidence.location).toMatchObject({
|
||||
available: true,
|
||||
value: { kind: "source-range", source: "main.cjs" },
|
||||
});
|
||||
}
|
||||
expect(
|
||||
windows.flatMap((window) =>
|
||||
window.observations.map(({ properties }) => properties.web_preferences),
|
||||
),
|
||||
).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: "preload",
|
||||
value: {
|
||||
status: "dynamic",
|
||||
value: null,
|
||||
expression: "runtimePath",
|
||||
},
|
||||
}),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -1,103 +0,0 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
cliTest(
|
||||
"rejects a headerless image until architecture and entry are supplied",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-raw-cli-");
|
||||
const path = join(root, "ecu.bin");
|
||||
await writeFile(path, Buffer.from("1eff2fe1", "hex"));
|
||||
const before = await cli.run({
|
||||
arguments: ["inspect", path, "--json"],
|
||||
environment: {
|
||||
HOME: root,
|
||||
XDG_CONFIG_HOME: root,
|
||||
XDG_CACHE_HOME: root,
|
||||
},
|
||||
});
|
||||
expect(before.exitCode).not.toBe(0);
|
||||
expect(JSON.stringify(before.json)).not.toContain("raw-binary");
|
||||
const missing = await cli.run({
|
||||
arguments: ["inspect", path, "--target-format", "raw-binary", "--json"],
|
||||
environment: {
|
||||
HOME: root,
|
||||
XDG_CONFIG_HOME: root,
|
||||
XDG_CACHE_HOME: root,
|
||||
},
|
||||
});
|
||||
expect(missing.exitCode).toBe(1);
|
||||
expect(missing.json).toMatchObject({
|
||||
code: "target_unavailable",
|
||||
details: { reason: expect.stringContaining("architecture") },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"rejects an unaligned AArch64 entry before provider startup",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-raw-cli-alignment-");
|
||||
const path = join(root, "image.bin");
|
||||
await writeFile(path, Buffer.from("c0035fd6", "hex"));
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"inspect",
|
||||
path,
|
||||
"--target-format",
|
||||
"raw-binary",
|
||||
"--architecture",
|
||||
"arm64",
|
||||
"--entry-point",
|
||||
"0x8000001",
|
||||
"--provider",
|
||||
"ghidra",
|
||||
"--json",
|
||||
],
|
||||
environment: { HOME: root, XDG_CONFIG_HOME: root, XDG_CACHE_HOME: root },
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.json).toMatchObject({
|
||||
code: "target_unavailable",
|
||||
details: { reason: expect.stringContaining("must be 4-byte aligned") },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"stops Hopper from claiming a caller-supplied raw-binary image",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-raw-cli-hopper-");
|
||||
const path = join(root, "ecu.bin");
|
||||
await writeFile(path, Buffer.from("1eff2fe1", "hex"));
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"inspect",
|
||||
path,
|
||||
"--target-format",
|
||||
"raw-binary",
|
||||
"--architecture",
|
||||
"arm",
|
||||
"--entry-point",
|
||||
"0x8000000",
|
||||
"--provider",
|
||||
"hopper",
|
||||
"--json",
|
||||
],
|
||||
environment: {
|
||||
HOME: root,
|
||||
XDG_CONFIG_HOME: root,
|
||||
XDG_CACHE_HOME: root,
|
||||
},
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(JSON.stringify(result.json)).toMatch(/Hopper|ghidra|Ghidra|hopper/i);
|
||||
expect(JSON.stringify(result.json)).not.toMatch(
|
||||
/unsupported binary format/i,
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -1,105 +0,0 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
describe("raw-binary admission", () => {
|
||||
it("requires explicit architecture and entry even with a misleading suffix", async () => {
|
||||
const directory = await createTestTempDirectory("rea-raw-target-");
|
||||
const path = join(directory, "fixture.js");
|
||||
const bytes = Buffer.from("1eff2fe1", "hex");
|
||||
await writeFile(path, bytes);
|
||||
const target = await parseBinaryTarget(path, {
|
||||
cwd: directory,
|
||||
hostArchitecture: "arm64",
|
||||
formatHint: "raw-binary",
|
||||
architecture: "arm",
|
||||
entryPoint: "0x08000000",
|
||||
});
|
||||
expect(target).toMatchObject({
|
||||
ok: true,
|
||||
value: {
|
||||
path,
|
||||
format: "raw-binary",
|
||||
kind: "executable",
|
||||
architecture: "arm",
|
||||
availableArchitectures: ["arm"],
|
||||
entryPoint: "0x8000000",
|
||||
entryPointSource: "0x08000000",
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
},
|
||||
});
|
||||
expect(await readFile(path)).toEqual(bytes);
|
||||
const detected = await parseBinaryTarget(path);
|
||||
expect(detected.ok && detected.value.format).not.toBe("raw-binary");
|
||||
});
|
||||
it("rejects raw-binary without architecture and entry", async () => {
|
||||
const directory = await createTestTempDirectory("rea-raw-missing-");
|
||||
const path = join(directory, "fixture.bin");
|
||||
await writeFile(path, Buffer.from("c3", "hex"));
|
||||
expect(
|
||||
await parseBinaryTarget(path, {
|
||||
cwd: directory,
|
||||
hostArchitecture: "x64",
|
||||
formatHint: "raw-binary",
|
||||
}),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "BinaryTargetError",
|
||||
reason: expect.stringContaining("architecture"),
|
||||
},
|
||||
});
|
||||
});
|
||||
it("rejects architecture without format=raw-binary", async () => {
|
||||
const directory = await createTestTempDirectory("rea-raw-unpaired-");
|
||||
const path = join(directory, "fixture.bin");
|
||||
await writeFile(path, Buffer.from("c3", "hex"));
|
||||
expect(
|
||||
await parseBinaryTarget(path, {
|
||||
cwd: directory,
|
||||
hostArchitecture: "x64",
|
||||
architecture: "arm",
|
||||
entryPoint: "0x8000000",
|
||||
}),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "BinaryTargetError",
|
||||
reason: expect.stringContaining("format=raw-binary"),
|
||||
},
|
||||
});
|
||||
});
|
||||
it("rejects an empty image", async () => {
|
||||
const directory = await createTestTempDirectory("rea-raw-empty-");
|
||||
const path = join(directory, "fixture.bin");
|
||||
await writeFile(path, Buffer.alloc(0));
|
||||
expect(
|
||||
await parseBinaryTarget(path, {
|
||||
cwd: directory,
|
||||
hostArchitecture: "x64",
|
||||
formatHint: "raw-binary",
|
||||
architecture: "x86",
|
||||
entryPoint: "0x1000",
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "BinaryTargetError" } });
|
||||
});
|
||||
it("rejects a contradictory target kind", async () => {
|
||||
const directory = await createTestTempDirectory("rea-raw-kind-");
|
||||
const path = join(directory, "fixture.bin");
|
||||
await writeFile(path, Buffer.from("c3", "hex"));
|
||||
expect(
|
||||
await parseBinaryTarget(path, {
|
||||
cwd: directory,
|
||||
hostArchitecture: "x64",
|
||||
targetKind: "database",
|
||||
formatHint: "raw-binary",
|
||||
architecture: "x86",
|
||||
entryPoint: "0x1000",
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "BinaryTargetError" } });
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user