mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
* fix(javascript): require exact loader suffix case * fix(javascript): share exact loader mode across import resolution * test(process): align symlink fixture with filesystem checkpoints * test(javascript): normalize the module resolution oracle path separators * test(frida): assert the CLI spawn Evidence contract * test(mcp): use an unsupported analysis-view parent * test(browser): separate source-location line bounds from parity * fix(javascript): preserve uncertain loader provenance * test(javascript): cover uncertain require resolution * fix(javascript): retain conditional Electron evidence * fix(javascript): preserve timed semantic provenance * fix(javascript): retain conditional builtin effects * test(javascript): distinguish bundled host authority * fix(javascript): preserve nested loader invocation identity * test(javascript): qualify Electron fixture authority * fix(javascript): preserve loader invocation authority * fix(javascript): respect source order for resolver escapes * fix(javascript): check nested loader callable mutations * fix(javascript): retain conditional constructor requests * fix(reference): retain constructor loader relationships * fix(reference): follow nested loader callable paths * refactor(javascript): share callable mutation interpretation * fix(javascript): require exact package loader suffixes * refactor(javascript): unify conditional relation evidence * refactor(javascript): unify conditional node evidence * fix(javascript): retain unknown authority for mixed case sources * fix(javascript): preserve loader uncertainty for dotfiles * fix(reference): classify javascript suffix dotfiles * test(reference): cover suffix dotfiles through cli * fix(javascript): retain equivalent conditional built-in origins * fix(javascript): preserve wrapped resolver operation * fix(javascript): retain nested conditional built-in receivers * test(javascript): declare CommonJS in native addon fixtures * fix(javascript): retain wrapped resolver candidates * style: format merged native command schema * fix(javascript): preserve uncertain loader authority * test(javascript): require candidate preload evidence * test(javascript): cover reference loader member writes --------- Co-authored-by: ShuaixinHuang <1836656514@qq.com>
166 lines
5.7 KiB
TypeScript
166 lines
5.7 KiB
TypeScript
import { resolveArtifactPathByContext } from "./JavaScriptArtifactPathResolution.js";
|
|
import { javascriptSourceRangeKey } from "../../domain/javascript/javascriptSourceCoordinates.js";
|
|
import type { ElectronNativeAddonBindingFinding } from "../../domain/javascript/electronStaticAnalysisTypes.js";
|
|
import type { JavaScriptArtifactFile } from "../../domain/javascript/javascriptArtifactFiles.js";
|
|
import {
|
|
artifactLocalIdentity,
|
|
javascriptAnalysisCoverage,
|
|
type JavaScriptArtifactGraphContext,
|
|
type JavaScriptArtifactGraphCoverage,
|
|
} from "./JavaScriptArtifactGraphContext.js";
|
|
import { compositeKey } from "../../domain/unicodeCodePointOrder.js";
|
|
import { javascriptDisplayText } from "../../domain/javascript/javascriptAstValues.js";
|
|
import {
|
|
addElectronInferenceEdge,
|
|
electronFindingEvidence,
|
|
electronFindingSourceNode,
|
|
electronObservationIdentity,
|
|
} from "./ElectronBoundaryGraphContext.js";
|
|
|
|
interface NativeBindingInput {
|
|
readonly context: JavaScriptArtifactGraphContext;
|
|
readonly file: JavaScriptArtifactFile;
|
|
readonly value: ElectronNativeAddonBindingFinding;
|
|
readonly coverage: JavaScriptArtifactGraphCoverage;
|
|
}
|
|
|
|
/** Project JavaScript-requested native addon binding and re-export surfaces. */
|
|
export const addElectronNativeBoundaries = (
|
|
context: JavaScriptArtifactGraphContext,
|
|
): void => {
|
|
for (const analyzed of context.analysis.files) {
|
|
const { file, javascript } = analyzed;
|
|
if (javascript === null) continue;
|
|
const coverage = javascriptAnalysisCoverage(javascript);
|
|
for (const value of javascript.electron.native_addon_bindings)
|
|
addNativeBinding({ context, file, value, coverage });
|
|
}
|
|
};
|
|
|
|
const addNativeBinding = (input: NativeBindingInput): void => {
|
|
const { context, file, value, coverage } = input;
|
|
const source = electronFindingSourceNode(
|
|
context,
|
|
file,
|
|
value.module_key,
|
|
value.module_runtime,
|
|
);
|
|
if (source === undefined) return;
|
|
const resolved =
|
|
value.loader_authority === "candidate"
|
|
? null
|
|
: resolveArtifactPathByContext({
|
|
declaredPath: value.specifier,
|
|
sourcePath: file.path,
|
|
context: "module-specifier",
|
|
files: context.filesByPath,
|
|
jsonDocuments: context.analysis.jsonDocuments,
|
|
directoryPaths: context.directoryPaths,
|
|
moduleKind: value.module_kind,
|
|
}).resolved_path;
|
|
// Extension probing can resolve `./addon.node` to `addon.node.js`; only a
|
|
// native-addon artifact can expose the requested binding.
|
|
const addon =
|
|
resolved === null ||
|
|
context.filesByPath.get(resolved)?.kind !== "native-addon"
|
|
? undefined
|
|
: context.fileNodes.get(resolved);
|
|
const bindingKey = compositeKey([
|
|
file.path,
|
|
value.specifier,
|
|
value.binding_kind,
|
|
value.members,
|
|
value.namespace_access ?? null,
|
|
value.dynamic_member_access ?? null,
|
|
javascriptSourceRangeKey(value.location),
|
|
]);
|
|
const binding = context.accumulator.addNode({
|
|
kind: "native-export",
|
|
identity:
|
|
value.loader_authority === "candidate"
|
|
? artifactLocalIdentity(
|
|
file.sha256,
|
|
"javascript-requested-native-export",
|
|
bindingKey,
|
|
)
|
|
: electronObservationIdentity(
|
|
context,
|
|
"javascript-requested-native-export",
|
|
bindingKey,
|
|
),
|
|
observations: [
|
|
{
|
|
label:
|
|
value.members.map(javascriptDisplayText).join(", ") ||
|
|
value.specifier,
|
|
properties: {
|
|
specifier: value.specifier,
|
|
binding_kind: value.binding_kind,
|
|
requested_members: value.members,
|
|
namespace_access: value.namespace_access ?? null,
|
|
dynamic_member_access: value.dynamic_member_access ?? null,
|
|
resolved_path: resolved,
|
|
native_export_verification: "not-performed",
|
|
...(value.loader_authority === "candidate"
|
|
? { loader_authority: "candidate" }
|
|
: {}),
|
|
},
|
|
evidence: electronFindingEvidence(
|
|
{
|
|
sha256: file.sha256,
|
|
path: file.path,
|
|
range: value.location,
|
|
operation: "observe-native-addon-binding",
|
|
coverage,
|
|
limitations: [
|
|
"JavaScript syntax identifies requested member names; it does not prove that the native binary exports or implements them.",
|
|
],
|
|
},
|
|
value.loader_authority,
|
|
),
|
|
},
|
|
],
|
|
});
|
|
addElectronInferenceEdge(context, {
|
|
source,
|
|
target: binding,
|
|
file,
|
|
range: value.location,
|
|
coverage,
|
|
relation: value.binding_kind === "re-export" ? "exposes" : "imports",
|
|
operation: "map-native-addon-binding",
|
|
loaderAuthority: value.loader_authority,
|
|
properties: {
|
|
specifier: value.specifier,
|
|
binding_kind: value.binding_kind,
|
|
requested_members: value.members,
|
|
namespace_access: value.namespace_access ?? null,
|
|
dynamic_member_access: value.dynamic_member_access ?? null,
|
|
},
|
|
limitations: [
|
|
"Requested JavaScript members are not verified native exports.",
|
|
],
|
|
});
|
|
if (addon === undefined || resolved === null) return;
|
|
addElectronInferenceEdge(context, {
|
|
source: addon,
|
|
target: binding,
|
|
file,
|
|
range: value.location,
|
|
coverage,
|
|
relation: "exposes",
|
|
operation: "associate-native-addon-requested-exports",
|
|
properties: {
|
|
resolved_path: resolved,
|
|
requested_members: value.members,
|
|
namespace_access: value.namespace_access ?? null,
|
|
dynamic_member_access: value.dynamic_member_access ?? null,
|
|
verified: false,
|
|
},
|
|
confidence: "medium",
|
|
limitations: [
|
|
"The .node artifact path is resolved, but requested JavaScript members have not been verified against native symbols.",
|
|
],
|
|
});
|
|
};
|