Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54e89bd5c8 | ||
|
|
30128a03cf | ||
|
|
e049ef70f7 | ||
|
|
bbf0638e88 | ||
|
|
242e2b0001 |
@@ -169,6 +169,14 @@ repeat parsing. Returned-row exhaustion
|
|||||||
does not prove complete metadata or absence under partial/unavailable coverage;
|
does not prove complete metadata or absence under partial/unavailable coverage;
|
||||||
preserve build-local tokens and their artifact/MVID scope.
|
preserve build-local tokens and their artifact/MVID scope.
|
||||||
|
|
||||||
|
`inspect_managed_members` always returns the assembly-wide `member_refs`, even
|
||||||
|
for one selected type. For questions about a selected type, select
|
||||||
|
`detail: "summary"` with `type_names`; it returns the selection (with unmatched
|
||||||
|
names), coverage and per-collection counts. Page rows with
|
||||||
|
`view: {kind: "managed-members", collection: "call_edges", offset: 0, limit: 64}`
|
||||||
|
over `types`, `exported_types`, `fields`, `methods`, `member_refs`, `call_edges`,
|
||||||
|
`field_accesses` or `user_strings`.
|
||||||
|
|
||||||
### .NET NativeAOT
|
### .NET NativeAOT
|
||||||
|
|
||||||
NativeAOT binaries contain native machine code, so ordinary CIL decompilers
|
NativeAOT binaries contain native machine code, so ordinary CIL decompilers
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ import ghidra.program.model.listing.Function;
|
|||||||
import ghidra.program.model.listing.FunctionIterator;
|
import ghidra.program.model.listing.FunctionIterator;
|
||||||
import ghidra.program.model.listing.Instruction;
|
import ghidra.program.model.listing.Instruction;
|
||||||
import ghidra.program.model.listing.InstructionIterator;
|
import ghidra.program.model.listing.InstructionIterator;
|
||||||
|
import ghidra.program.model.listing.Listing;
|
||||||
import ghidra.program.model.listing.Variable;
|
import ghidra.program.model.listing.Variable;
|
||||||
import ghidra.program.model.mem.MemoryBlock;
|
import ghidra.program.model.mem.MemoryBlock;
|
||||||
import ghidra.program.model.mem.MemoryBlockSourceInfo;
|
import ghidra.program.model.mem.MemoryBlockSourceInfo;
|
||||||
@@ -405,7 +406,9 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
case "xrefs" -> xrefs(request.params);
|
case "xrefs" -> xrefs(request.params);
|
||||||
case "analyze_function" -> {
|
case "analyze_function" -> {
|
||||||
FunctionAnalysisObservation observation = analyzeFunctionObservation(request.params);
|
FunctionAnalysisObservation observation = analyzeFunctionObservation(request.params);
|
||||||
yield functionObservation(observation.dossier(), observation.limitations());
|
JsonObject result = functionObservation(observation.dossier(), observation.limitations());
|
||||||
|
result.add("relationship_coverage", observation.relationshipCoverage());
|
||||||
|
yield result;
|
||||||
}
|
}
|
||||||
case "set_address_name", "set_addresses_names" -> {
|
case "set_address_name", "set_addresses_names" -> {
|
||||||
if (!descriptor.transport.equals("unix-socket"))
|
if (!descriptor.transport.equals("unix-socket"))
|
||||||
@@ -1016,12 +1019,19 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
for (Function item : ordered) {
|
for (Function item : ordered) {
|
||||||
result.add(canonicalAddress(item.getEntryPoint()));
|
result.add(canonicalAddress(item.getEntryPoint()));
|
||||||
}
|
}
|
||||||
return functionObservation(
|
if (callers) {
|
||||||
result,
|
JsonObject observation = functionObservation(result, noReturnCallLimitations(
|
||||||
noReturnCallLimitations(
|
|
||||||
currentProgram.getListing().getInstructions(function.getBody(), true)
|
currentProgram.getListing().getInstructions(function.getBody(), true)
|
||||||
)
|
));
|
||||||
|
observation.add("relationship_coverage", callRelationshipCoverage(null,
|
||||||
|
unrepresentedIncomingCalls(function, observed)));
|
||||||
|
monitor.checkCancelled();
|
||||||
|
return observation;
|
||||||
|
}
|
||||||
|
CallBoundaryObservation calls = callBoundaryObservation(
|
||||||
|
function, currentProgram.getListing().getInstructions(function.getBody(), true), observed, false, null
|
||||||
);
|
);
|
||||||
|
return callRelationshipObservation(result, calls);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonObject procedureInfo(JsonObject params) throws Exception {
|
private JsonObject procedureInfo(JsonObject params) throws Exception {
|
||||||
@@ -1071,18 +1081,10 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
result.addProperty("direction", direction);
|
result.addProperty("direction", direction);
|
||||||
result.add("references", edges);
|
result.add("references", edges);
|
||||||
result.addProperty("reference_kinds_available", true);
|
result.addProperty("reference_kinds_available", true);
|
||||||
JsonArray unresolvedCalls = new JsonArray();
|
JsonArray unresolvedCalls = direction.equals("outgoing")
|
||||||
if (direction.equals("outgoing")) for (Instruction instruction : scanInstructions(function, Integer.MAX_VALUE).instructions) {
|
? callBoundaryObservation(
|
||||||
if (!instruction.getFlowType().isCall()) continue;
|
function, currentProgram.getListing().getInstructions(function.getBody(), true), null, true, references
|
||||||
boolean resolved = false;
|
).unresolvedCalls() : new JsonArray();
|
||||||
for (Reference reference : instruction.getReferencesFrom()) if (reference.getReferenceType().isCall()) resolved = true;
|
|
||||||
if (!resolved) {
|
|
||||||
JsonObject site = new JsonObject();
|
|
||||||
site.addProperty("address", canonicalAddress(instruction.getAddress()));
|
|
||||||
site.addProperty("reason", "Instruction decoder identifies a call but ReferenceManager supplies no call destination");
|
|
||||||
unresolvedCalls.add(site);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.add("unresolved_calls", unresolvedCalls);
|
result.add("unresolved_calls", unresolvedCalls);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1490,16 +1492,28 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
InstructionScan scan = scanInstructions(function, Integer.MAX_VALUE);
|
InstructionScan scan = scanInstructions(function, Integer.MAX_VALUE);
|
||||||
DecompileResults decompilation = decompile(function);
|
DecompileResults decompilation = decompile(function);
|
||||||
String pseudocode = decompiledText(decompilation);
|
String pseudocode = decompiledText(decompilation);
|
||||||
List<Reference> incomingReferences = collectReferences(function, "incoming")
|
JsonObject availability = new JsonObject();
|
||||||
.stream()
|
availability.add("pseudocode", facetAvailability(
|
||||||
|
pseudocode != null,
|
||||||
|
function.isExternal() ? "Ghidra does not decompile external functions."
|
||||||
|
: function.getBody().isEmpty() ? "Ghidra has no function body to decompile."
|
||||||
|
: "Ghidra completed decompilation without returning pseudocode."
|
||||||
|
));
|
||||||
|
if (pseudocode == null) {
|
||||||
|
pseudocode = "";
|
||||||
|
}
|
||||||
|
List<Reference> bodyIncoming = collectReferences(function, "incoming");
|
||||||
|
List<Reference> incomingReferences = bodyIncoming.stream()
|
||||||
.filter(reference -> !function.getBody().contains(reference.getFromAddress()))
|
.filter(reference -> !function.getBody().contains(reference.getFromAddress()))
|
||||||
.toList();
|
.toList();
|
||||||
List<Reference> outgoingReferences = collectReferences(function, "outgoing");
|
List<Reference> outgoingReferences = collectReferences(function, "outgoing");
|
||||||
JsonArray incoming = referenceEdges(incomingReferences);
|
JsonArray incoming = referenceEdges(incomingReferences);
|
||||||
JsonArray outgoing = referenceEdges(outgoingReferences);
|
JsonArray outgoing = referenceEdges(outgoingReferences);
|
||||||
JsonArray comments = comments(scan.instructions);
|
JsonArray comments = comments(function);
|
||||||
JsonArray callers = procedureIdentities(function.getCallingFunctions(monitor));
|
Set<Function> callerFunctions = function.getCallingFunctions(monitor);
|
||||||
JsonArray callees = procedureIdentities(function.getCalledFunctions(monitor));
|
JsonArray callers = procedureIdentities(callerFunctions);
|
||||||
|
Set<Function> calleeFunctions = function.getCalledFunctions(monitor);
|
||||||
|
JsonArray callees = procedureIdentities(calleeFunctions);
|
||||||
JsonArray referencedStrings = referencedStrings(outgoingReferences);
|
JsonArray referencedStrings = referencedStrings(outgoingReferences);
|
||||||
JsonArray referencedNames = referencedNames(outgoingReferences);
|
JsonArray referencedNames = referencedNames(outgoingReferences);
|
||||||
JsonArray blocks = basicBlockValues(function);
|
JsonArray blocks = basicBlockValues(function);
|
||||||
@@ -1511,7 +1525,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
procedure.add("locals", functionLocals(function));
|
procedure.add("locals", functionLocals(function));
|
||||||
JsonObject result = new JsonObject();
|
JsonObject result = new JsonObject();
|
||||||
result.add("procedure", procedure);
|
result.add("procedure", procedure);
|
||||||
result.addProperty("pseudocode", pseudocode == null ? "" : pseudocode);
|
result.addProperty("pseudocode", pseudocode);
|
||||||
result.add("assembly", assembly);
|
result.add("assembly", assembly);
|
||||||
result.add("comments", comments);
|
result.add("comments", comments);
|
||||||
result.add("callers", callers);
|
result.add("callers", callers);
|
||||||
@@ -1520,20 +1534,6 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
result.add("outgoing_references", outgoing);
|
result.add("outgoing_references", outgoing);
|
||||||
result.add("referenced_strings", referencedStrings);
|
result.add("referenced_strings", referencedStrings);
|
||||||
result.add("referenced_names", referencedNames);
|
result.add("referenced_names", referencedNames);
|
||||||
JsonObject facets = new JsonObject();
|
|
||||||
JsonObject pseudocodeAvailability = new JsonObject();
|
|
||||||
pseudocodeAvailability.addProperty("available", pseudocode != null);
|
|
||||||
if (pseudocode == null) {
|
|
||||||
pseudocodeAvailability.addProperty("reason", "Ghidra did not supply pseudocode.");
|
|
||||||
}
|
|
||||||
facets.add("pseudocode", pseudocodeAvailability);
|
|
||||||
for (String facet : List.of("assembly", "comments", "callers", "callees",
|
|
||||||
"references", "strings_names", "cfg")) {
|
|
||||||
JsonObject available = new JsonObject();
|
|
||||||
available.addProperty("available", true);
|
|
||||||
facets.add(facet, available);
|
|
||||||
}
|
|
||||||
result.add("facet_availability", facets);
|
|
||||||
boolean swift = swiftProgram();
|
boolean swift = swiftProgram();
|
||||||
boolean aarch64 = currentProgram.getLanguageID().getIdAsString().startsWith("AARCH64:");
|
boolean aarch64 = currentProgram.getLanguageID().getIdAsString().startsWith("AARCH64:");
|
||||||
SwiftStringLiteralDecode swiftLiterals = swift && aarch64 ? swiftStringLiterals(function) : null;
|
SwiftStringLiteralDecode swiftLiterals = swift && aarch64 ? swiftStringLiterals(function) : null;
|
||||||
@@ -1547,6 +1547,15 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
nativeApiBoundary(function, decompilation)
|
nativeApiBoundary(function, decompilation)
|
||||||
);
|
);
|
||||||
result.add("native_value_flow", nativeValueFlow(decompilation));
|
result.add("native_value_flow", nativeValueFlow(decompilation));
|
||||||
|
// Successful full queries distinguish collected empty sets from missing facts.
|
||||||
|
// Availability does not claim that Ghidra resolved every runtime relationship.
|
||||||
|
for (String facet : List.of("comments", "callers", "callees", "references", "strings_names", "cfg")) {
|
||||||
|
availability.add(facet, facetAvailability(true, null));
|
||||||
|
}
|
||||||
|
availability.add("assembly", facetAvailability(
|
||||||
|
!scan.truncated(), "The function instruction scan was truncated."
|
||||||
|
));
|
||||||
|
result.add("facet_availability", availability);
|
||||||
JsonArray limitations = new JsonArray();
|
JsonArray limitations = new JsonArray();
|
||||||
limitations.add(
|
limitations.add(
|
||||||
"Unresolved computed or indirect flows without target addresses are not represented as reference edges."
|
"Unresolved computed or indirect flows without target addresses are not represented as reference edges."
|
||||||
@@ -1574,8 +1583,10 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
"Swift String literal decoding is implemented for AArch64 register pairs only; no Swift literals were decoded for this architecture."
|
"Swift String literal decoding is implemented for AArch64 register pairs only; no Swift literals were decoded for this architecture."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
List<String> boundaryLimitations = noReturnCallLimitations(scan.instructions);
|
CallBoundaryObservation calls = callBoundaryObservation(
|
||||||
for (String limitation : boundaryLimitations) {
|
function, scan.instructions, calleeFunctions, true, outgoingReferences);
|
||||||
|
result.add("unresolved_calls", calls.unresolvedCalls());
|
||||||
|
for (String limitation : calls.limitations()) {
|
||||||
limitations.add(limitation);
|
limitations.add(limitation);
|
||||||
}
|
}
|
||||||
if (decompilation != null && decompilation.getErrorMessage() != null &&
|
if (decompilation != null && decompilation.getErrorMessage() != null &&
|
||||||
@@ -1583,7 +1594,14 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
limitations.add("Ghidra decompiler diagnostic: " + decompilation.getErrorMessage());
|
limitations.add("Ghidra decompiler diagnostic: " + decompilation.getErrorMessage());
|
||||||
}
|
}
|
||||||
result.add("limitations", limitations);
|
result.add("limitations", limitations);
|
||||||
return new FunctionAnalysisObservation(result, boundaryLimitations);
|
monitor.checkCancelled();
|
||||||
|
int missingCallers = 0;
|
||||||
|
for (Reference reference : bodyIncoming) {
|
||||||
|
monitor.checkCancelled();
|
||||||
|
if (unrepresentedCaller(reference, callerFunctions)) missingCallers++;
|
||||||
|
}
|
||||||
|
return new FunctionAnalysisObservation(result, calls.limitations(),
|
||||||
|
callRelationshipCoverage(calls, missingCallers));
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonObject nativeValueFlow(DecompileResults decompilation) throws Exception {
|
private JsonObject nativeValueFlow(DecompileResults decompilation) throws Exception {
|
||||||
@@ -3287,54 +3305,202 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static JsonObject facetAvailability(boolean available, String reason) {
|
||||||
|
JsonObject result = new JsonObject();
|
||||||
|
result.addProperty("available", available);
|
||||||
|
if (!available) result.addProperty("reason", reason);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonObject callRelationshipObservation(JsonElement value, CallBoundaryObservation calls)
|
||||||
|
throws Exception {
|
||||||
|
monitor.checkCancelled();
|
||||||
|
JsonObject result = functionObservation(value, calls.limitations());
|
||||||
|
result.add("relationship_coverage", callRelationshipCoverage(calls, null));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject callRelationshipCoverage(
|
||||||
|
CallBoundaryObservation calls, Integer missingCallers) {
|
||||||
|
JsonObject coverage = completeResolvedCallCoverage();
|
||||||
|
Integer omitted = calls == null ? null : calls.unrepresentedCalleeCalls();
|
||||||
|
JsonArray directions = new JsonArray();
|
||||||
|
if (missingCallers != null && missingCallers > 0) directions.add("callers");
|
||||||
|
String callerLimitation = missingCallers != null && missingCallers > 0
|
||||||
|
? "Ghidra's caller inventory omits sources of " + missingCallers +
|
||||||
|
" call reference(s) into this function's body." : null;
|
||||||
|
if ((calls != null && omitted == null) || (calls == null && missingCallers == null)) {
|
||||||
|
coverage.addProperty("status", "unknown");
|
||||||
|
String reason = calls == null ? "No call inventory was examined."
|
||||||
|
: "The callee inventory was not examined alongside decoded call targets.";
|
||||||
|
coverage.addProperty("reason", reason + (callerLimitation == null ? "" : " " + callerLimitation));
|
||||||
|
if (calls == null && missingCallers == null) directions.add("callers");
|
||||||
|
directions.add("callees");
|
||||||
|
coverage.add("limited_directions", directions);
|
||||||
|
return coverage;
|
||||||
|
}
|
||||||
|
JsonArray limitations = new JsonArray();
|
||||||
|
if (callerLimitation != null) limitations.add(callerLimitation);
|
||||||
|
if (omitted != null && omitted > 0) {
|
||||||
|
limitations.add("Ghidra's callee inventory omits targets of " + omitted +
|
||||||
|
" call reference(s) or decoded call(s) without destinations.");
|
||||||
|
directions.add("callees");
|
||||||
|
}
|
||||||
|
if (!limitations.isEmpty()) {
|
||||||
|
coverage.addProperty("status", "partial");
|
||||||
|
coverage.add("limitations", limitations);
|
||||||
|
coverage.add("limited_directions", directions);
|
||||||
|
}
|
||||||
|
return coverage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject completeResolvedCallCoverage() {
|
||||||
|
JsonObject coverage = new JsonObject();
|
||||||
|
coverage.addProperty("status", "complete");
|
||||||
|
JsonArray diagnostics = new JsonArray();
|
||||||
|
diagnostics.add(
|
||||||
|
"Only resolved Ghidra call references are returned; unresolved computed or indirect calls remain unknown, while function classifications distinguish thunks and externals."
|
||||||
|
);
|
||||||
|
coverage.add("diagnostics", diagnostics);
|
||||||
|
return coverage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean unrepresentedCaller(Reference reference, Set<Function> callers) {
|
||||||
|
if (!reference.getReferenceType().isCall()) return false;
|
||||||
|
Function caller = containingFunction(reference.getFromAddress());
|
||||||
|
return caller == null || !callers.contains(caller);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int unrepresentedIncomingCalls(Function function, Set<Function> callers)
|
||||||
|
throws Exception {
|
||||||
|
int[] omitted = { 0 };
|
||||||
|
visitReferences(function, "incoming", reference -> {
|
||||||
|
if (unrepresentedCaller(reference, callers)) omitted[0]++;
|
||||||
|
});
|
||||||
|
return omitted[0];
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> noReturnCallLimitations(Iterable<Instruction> instructions)
|
private List<String> noReturnCallLimitations(Iterable<Instruction> instructions)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
List<String> limitations = new ArrayList<>();
|
List<String> limitations = new ArrayList<>();
|
||||||
for (Instruction instruction : instructions) {
|
for (Instruction instruction : instructions) {
|
||||||
monitor.checkCancelled();
|
monitor.checkCancelled();
|
||||||
if (!instruction.getFlowType().isCall() || !instruction.getFlowType().isTerminal()) {
|
String limitation = terminalCallLimitation(instruction);
|
||||||
continue;
|
if (limitation != null) limitations.add(limitation);
|
||||||
}
|
|
||||||
Address[] destinations = instruction.getFlows();
|
|
||||||
StringBuilder limitation = new StringBuilder();
|
|
||||||
limitation.append("Ghidra Listing reports a terminal call at ")
|
|
||||||
.append(canonicalAddress(instruction.getAddress()));
|
|
||||||
if (destinations.length == 0) {
|
|
||||||
limitation.append(" with no resolved callee; its no-return basis is unknown.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
limitation.append(" to ");
|
|
||||||
for (int index = 0; index < destinations.length; index++) {
|
|
||||||
if (index > 0) limitation.append(", ");
|
|
||||||
Address destination = destinations[index];
|
|
||||||
limitation.append(canonicalAddress(destination));
|
|
||||||
Function target = currentProgram.getFunctionManager().getFunctionAt(destination);
|
|
||||||
if (target == null) {
|
|
||||||
limitation.append(" (callee identity unknown)");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
limitation.append(" ").append(procedureName(target));
|
|
||||||
limitation.append(" (external=").append(target.isExternal());
|
|
||||||
limitation.append(", thunk=").append(target.isThunk());
|
|
||||||
limitation.append(", hasNoReturn=").append(target.hasNoReturn()).append(")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
limitation.append("; fallthrough is excluded by Ghidra's flow model.");
|
|
||||||
Function target = destinations.length == 1
|
|
||||||
? currentProgram.getFunctionManager().getFunctionAt(destinations[0])
|
|
||||||
: null;
|
|
||||||
if (target != null && target.hasNoReturn()) {
|
|
||||||
limitation.append(" This records Ghidra's FunctionManager flag, not an independent verification that the callee cannot return.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
limitation.append(" The reason for the terminal flow is not established by this observation.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
limitations.add(limitation.toString());
|
|
||||||
}
|
}
|
||||||
return limitations;
|
return limitations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CallBoundaryObservation callBoundaryObservation(
|
||||||
|
Function function, Iterable<Instruction> instructions, Set<Function> returnedCallees,
|
||||||
|
boolean includeUnresolvedSites, List<Reference> observedReferences)
|
||||||
|
throws Exception {
|
||||||
|
List<String> limitations = new ArrayList<>();
|
||||||
|
CallBoundaryReferences calls = new CallBoundaryReferences(returnedCallees, includeUnresolvedSites);
|
||||||
|
if (observedReferences == null) visitReferences(function, "outgoing", calls::observe);
|
||||||
|
else for (Reference reference : observedReferences) {
|
||||||
|
monitor.checkCancelled();
|
||||||
|
calls.observe(reference);
|
||||||
|
}
|
||||||
|
for (Instruction instruction : instructions) {
|
||||||
|
monitor.checkCancelled();
|
||||||
|
String limitation = terminalCallLimitation(instruction);
|
||||||
|
if (limitation != null) limitations.add(limitation);
|
||||||
|
if (!instruction.getFlowType().isCall()) continue;
|
||||||
|
boolean destination = false;
|
||||||
|
for (Reference reference : instruction.getReferencesFrom()) {
|
||||||
|
if (!reference.getReferenceType().isCall()) continue;
|
||||||
|
destination = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!destination) {
|
||||||
|
calls.unrepresented++;
|
||||||
|
calls.unresolved(instruction.getAddress(),
|
||||||
|
"Instruction decoder identifies a call but ReferenceManager supplies no call destination");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new CallBoundaryObservation(List.copyOf(limitations),
|
||||||
|
returnedCallees == null ? null : calls.unrepresented, calls.unresolvedCalls());
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class CallBoundaryReferences {
|
||||||
|
private final Set<Function> returnedCallees;
|
||||||
|
private final TreeMap<Address, String> unresolved;
|
||||||
|
private int unrepresented;
|
||||||
|
|
||||||
|
CallBoundaryReferences(Set<Function> returnedCallees, boolean includeUnresolvedSites) {
|
||||||
|
this.returnedCallees = returnedCallees;
|
||||||
|
unresolved = includeUnresolvedSites ? new TreeMap<>() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void observe(Reference reference) {
|
||||||
|
if (!reference.getReferenceType().isCall()) return;
|
||||||
|
// Reference identity follows the same containing-function owner as referenceEdge.
|
||||||
|
Function target = containingFunction(reference.getToAddress());
|
||||||
|
if (returnedCallees != null && (target == null || !returnedCallees.contains(target)))
|
||||||
|
unrepresented++;
|
||||||
|
if (target == null) unresolved(reference.getFromAddress(),
|
||||||
|
"A call destination has no known containing Ghidra procedure");
|
||||||
|
}
|
||||||
|
|
||||||
|
void unresolved(Address address, String reason) {
|
||||||
|
if (unresolved != null) unresolved.put(address, reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray unresolvedCalls() {
|
||||||
|
if (unresolved == null) return null;
|
||||||
|
JsonArray result = new JsonArray();
|
||||||
|
for (var item : unresolved.entrySet()) {
|
||||||
|
JsonObject site = new JsonObject();
|
||||||
|
site.addProperty("address", canonicalAddress(item.getKey()));
|
||||||
|
site.addProperty("reason", item.getValue());
|
||||||
|
result.add(site);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String terminalCallLimitation(Instruction instruction) {
|
||||||
|
if (!instruction.getFlowType().isCall() || !instruction.getFlowType().isTerminal())
|
||||||
|
return null;
|
||||||
|
Address[] destinations = instruction.getFlows();
|
||||||
|
StringBuilder limitation = new StringBuilder();
|
||||||
|
limitation.append("Ghidra Listing reports a terminal call at ")
|
||||||
|
.append(canonicalAddress(instruction.getAddress()));
|
||||||
|
if (destinations.length == 0) {
|
||||||
|
limitation.append(" with no resolved callee; its no-return basis is unknown.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
limitation.append(" to ");
|
||||||
|
for (int index = 0; index < destinations.length; index++) {
|
||||||
|
if (index > 0) limitation.append(", ");
|
||||||
|
Address destination = destinations[index];
|
||||||
|
limitation.append(canonicalAddress(destination));
|
||||||
|
Function target = currentProgram.getFunctionManager().getFunctionAt(destination);
|
||||||
|
if (target == null) {
|
||||||
|
limitation.append(" (callee identity unknown)");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
limitation.append(" ").append(procedureName(target));
|
||||||
|
limitation.append(" (external=").append(target.isExternal());
|
||||||
|
limitation.append(", thunk=").append(target.isThunk());
|
||||||
|
limitation.append(", hasNoReturn=").append(target.hasNoReturn()).append(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
limitation.append("; fallthrough is excluded by Ghidra's flow model.");
|
||||||
|
Function target = destinations.length == 1
|
||||||
|
? currentProgram.getFunctionManager().getFunctionAt(destinations[0])
|
||||||
|
: null;
|
||||||
|
if (target != null && target.hasNoReturn()) {
|
||||||
|
limitation.append(" This records Ghidra's FunctionManager flag, not an independent verification that the callee cannot return.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
limitation.append(" The reason for the terminal flow is not established by this observation.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return limitation.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private static String renderAssembly(List<Instruction> instructions) {
|
private static String renderAssembly(List<Instruction> instructions) {
|
||||||
return String.join("\n", renderAssemblyLines(instructions));
|
return String.join("\n", renderAssemblyLines(instructions));
|
||||||
}
|
}
|
||||||
@@ -3358,15 +3524,27 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
private List<Reference> collectReferences(
|
private List<Reference> collectReferences(
|
||||||
Function function,
|
Function function,
|
||||||
String direction) throws Exception {
|
String direction) throws Exception {
|
||||||
|
TreeMap<String, Reference> observed = new TreeMap<>();
|
||||||
|
visitReferences(function, direction, reference -> addReference(observed, reference));
|
||||||
|
List<Reference> result = new ArrayList<>(observed.values());
|
||||||
|
result.sort(REFERENCE_ORDER);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
private interface ReferenceVisitor {
|
||||||
|
void accept(Reference reference) throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void visitReferences(Function function, String direction, ReferenceVisitor visitor)
|
||||||
|
throws Exception {
|
||||||
// References can target instruction interiors or originate in embedded
|
// References can target instruction interiors or originate in embedded
|
||||||
// data. Use actual body ownership, including an external's exact entry.
|
// data. Use actual body ownership, including an external's exact entry.
|
||||||
AddressSet scope = new AddressSet(function.getBody());
|
AddressSet scope = functionObservationScope(function);
|
||||||
scope.add(function.getEntryPoint());
|
|
||||||
boolean outgoing = direction.equals("outgoing");
|
boolean outgoing = direction.equals("outgoing");
|
||||||
AddressIterator addresses = outgoing
|
AddressIterator addresses = outgoing
|
||||||
? currentProgram.getReferenceManager().getReferenceSourceIterator(scope, true)
|
? currentProgram.getReferenceManager().getReferenceSourceIterator(scope, true)
|
||||||
: currentProgram.getReferenceManager().getReferenceDestinationIterator(scope, true);
|
: currentProgram.getReferenceManager().getReferenceDestinationIterator(scope, true);
|
||||||
TreeMap<String, Reference> observed = new TreeMap<>();
|
|
||||||
while (addresses.hasNext()) {
|
while (addresses.hasNext()) {
|
||||||
monitor.checkCancelled();
|
monitor.checkCancelled();
|
||||||
Address address = addresses.next();
|
Address address = addresses.next();
|
||||||
@@ -3374,7 +3552,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
for (Reference reference : currentProgram.getReferenceManager()
|
for (Reference reference : currentProgram.getReferenceManager()
|
||||||
.getReferencesFrom(address)) {
|
.getReferencesFrom(address)) {
|
||||||
monitor.checkCancelled();
|
monitor.checkCancelled();
|
||||||
addReference(observed, reference);
|
if (!reference.isEntryPointReference()) visitor.accept(reference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -3382,19 +3560,14 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
.getReferencesTo(address);
|
.getReferencesTo(address);
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
monitor.checkCancelled();
|
monitor.checkCancelled();
|
||||||
addReference(observed, iterator.next());
|
Reference reference = iterator.next();
|
||||||
|
if (!reference.isEntryPointReference()) visitor.accept(reference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<Reference> result = new ArrayList<>(observed.values());
|
|
||||||
result.sort(REFERENCE_ORDER);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addReference(TreeMap<String, Reference> observed, Reference reference) {
|
private static void addReference(TreeMap<String, Reference> observed, Reference reference) {
|
||||||
if (reference.isEntryPointReference()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String key = canonicalAddress(reference.getFromAddress()) + "\u0000" +
|
String key = canonicalAddress(reference.getFromAddress()) + "\u0000" +
|
||||||
canonicalAddress(reference.getToAddress()) + "\u0000" +
|
canonicalAddress(reference.getToAddress()) + "\u0000" +
|
||||||
reference.getReferenceType().getName() + "\u0000" +
|
reference.getReferenceType().getName() + "\u0000" +
|
||||||
@@ -3403,6 +3576,12 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
observed.putIfAbsent(key, reference);
|
observed.putIfAbsent(key, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static AddressSet functionObservationScope(Function function) {
|
||||||
|
AddressSet scope = new AddressSet(function.getBody());
|
||||||
|
scope.add(function.getEntryPoint());
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
private JsonArray referenceEdges(List<Reference> references) {
|
private JsonArray referenceEdges(List<Reference> references) {
|
||||||
JsonArray result = new JsonArray();
|
JsonArray result = new JsonArray();
|
||||||
for (Reference reference : references) {
|
for (Reference reference : references) {
|
||||||
@@ -3556,23 +3735,28 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JsonArray comments(List<Instruction> instructions) {
|
private JsonArray comments(Function function) throws Exception {
|
||||||
|
Listing listing = currentProgram.getListing();
|
||||||
|
AddressSet scope = functionObservationScope(function);
|
||||||
|
AddressIterator addresses = listing.getCommentAddressIterator(scope, true);
|
||||||
TreeMap<String, JsonObject> observed = new TreeMap<>();
|
TreeMap<String, JsonObject> observed = new TreeMap<>();
|
||||||
for (Instruction instruction : instructions) {
|
while (addresses.hasNext()) {
|
||||||
|
monitor.checkCancelled();
|
||||||
|
Address address = addresses.next();
|
||||||
for (CommentType type : CommentType.values()) {
|
for (CommentType type : CommentType.values()) {
|
||||||
String text = instruction.getComment(type);
|
String text = listing.getComment(type, address);
|
||||||
if (text == null || text.isEmpty()) {
|
if (text == null || text.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String kind = type == CommentType.EOL ? "inline" : "comment";
|
String kind = type == CommentType.EOL ? "inline" : "comment";
|
||||||
JsonObject item = new JsonObject();
|
JsonObject item = new JsonObject();
|
||||||
item.addProperty("address", canonicalAddress(instruction.getAddress()));
|
item.addProperty("address", canonicalAddress(address));
|
||||||
item.addProperty("kind", kind);
|
item.addProperty("kind", kind);
|
||||||
item.addProperty("text", text);
|
item.addProperty("text", text);
|
||||||
String key = canonicalAddress(instruction.getAddress()) + "\u0000" +
|
String key = canonicalAddress(address) + "\u0000" +
|
||||||
kind + "\u0000" + type.name() + "\u0000" + text;
|
kind + "\u0000" + type.name() + "\u0000" + text;
|
||||||
observed.put(key, item);
|
observed.put(key, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JsonArray result = new JsonArray();
|
JsonArray result = new JsonArray();
|
||||||
observed.values().forEach(result::add);
|
observed.values().forEach(result::add);
|
||||||
@@ -4508,7 +4692,8 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
|||||||
private record InventoryItem(Address address, String value, JsonObject facts) {}
|
private record InventoryItem(Address address, String value, JsonObject facts) {}
|
||||||
private record AddressNameRequest(String inputAddress, Address address, String name) {}
|
private record AddressNameRequest(String inputAddress, Address address, String name) {}
|
||||||
private record FunctionEntry(Function function, InventoryItem item) {}
|
private record FunctionEntry(Function function, InventoryItem item) {}
|
||||||
private record FunctionAnalysisObservation(JsonObject dossier, List<String> limitations) {}
|
private record FunctionAnalysisObservation(JsonObject dossier, List<String> limitations, JsonObject relationshipCoverage) {}
|
||||||
|
private record CallBoundaryObservation(List<String> limitations, Integer unrepresentedCalleeCalls, JsonArray unresolvedCalls) {}
|
||||||
private record SwiftStringLiteralDecode(JsonArray literals, JsonArray omissions) {}
|
private record SwiftStringLiteralDecode(JsonArray literals, JsonArray omissions) {}
|
||||||
private record SwiftLiteralLayout(
|
private record SwiftLiteralLayout(
|
||||||
String representation,
|
String representation,
|
||||||
|
|||||||
@@ -265,6 +265,21 @@ The user-level MCP paths follow the editor's VS Code layout. Trae's official
|
|||||||
documentation describes the raw JSON editor without specifying those paths;
|
documentation describes the raw JSON editor without specifying those paths;
|
||||||
loading this registration in Trae remains unverified.
|
loading this registration in Trae remains unverified.
|
||||||
|
|
||||||
|
## WorkBuddy
|
||||||
|
|
||||||
|
For [WorkBuddy](https://www.workbuddy.cn/docs/workbuddy/From-Beginner-to-Expert-Guide/Function-Description/MCP-Guide), setup writes `mcpServers.rea` into the
|
||||||
|
global `~/.workbuddy/mcp.json` (a standard `mcpServers` JSON file at the user
|
||||||
|
home root on every platform). Entries carry `command`, `args`, and `env`;
|
||||||
|
stdio is the default transport. WorkBuddy discovers personal skills from
|
||||||
|
`~/.workbuddy/skills` (`%userprofile%\.workbuddy\skills` on Windows), so
|
||||||
|
setup installs its skill copy there.
|
||||||
|
|
||||||
|
The global MCP path is a plain JSON file; setup preserves every other server
|
||||||
|
and top-level key when it upserts `rea`. WorkBuddy also reads a project-level
|
||||||
|
`<project>/.workbuddy/mcp.json`, which setup does not touch: it registers the
|
||||||
|
user-level file only. Loading this registration and real REA tool calls
|
||||||
|
through WorkBuddy are verified.
|
||||||
|
|
||||||
## ZCode
|
## ZCode
|
||||||
|
|
||||||
For [ZCode](https://zcode.z.ai/en/docs/mcp-services), setup registers `rea` in the nested `mcp.servers` table of the
|
For [ZCode](https://zcode.z.ai/en/docs/mcp-services), setup registers `rea` in the nested `mcp.servers` table of the
|
||||||
|
|||||||
@@ -288,11 +288,12 @@ hosted connector; see [its configuration](client-configuration.md#other-client-s
|
|||||||
| Qoder | `qoder` |
|
| Qoder | `qoder` |
|
||||||
| Factory Droid | `droid` |
|
| Factory Droid | `droid` |
|
||||||
| Trae | `trae` |
|
| Trae | `trae` |
|
||||||
|
| WorkBuddy | `workbuddy` |
|
||||||
| ZCode | `zcode` |
|
| ZCode | `zcode` |
|
||||||
| DeepSeek Harness | `dsh` |
|
| DeepSeek Harness | `dsh` |
|
||||||
|
|
||||||
`dsh` and `kimi` require a release containing them. The registry check above does
|
`dsh`, `kimi`, and `workbuddy` require a release containing them. The registry
|
||||||
not cover them.
|
check above does not cover them.
|
||||||
|
|
||||||
See [client configuration and troubleshooting](client-configuration.md) for
|
See [client configuration and troubleshooting](client-configuration.md) for
|
||||||
configuration paths, profiles, trust policies, and schema-limit workarounds.
|
configuration paths, profiles, trust policies, and schema-limit workarounds.
|
||||||
|
|||||||
@@ -81,6 +81,40 @@ including the existing `inspect-analysis-view` CLI. Session record lifetime and
|
|||||||
export/import semantics remain unchanged. A server without Evidence retention
|
export/import semantics remain unchanged. A server without Evidence retention
|
||||||
rejects selected summary before analysis; complete delivery remains available.
|
rejects selected summary before analysis; complete delivery remains available.
|
||||||
|
|
||||||
|
### Member summary and retained member rows
|
||||||
|
|
||||||
|
Complete `inspect_managed_members` delivery always includes the assembly-wide
|
||||||
|
`member_refs` and `exported_types`, which `type_names` does not narrow, so even
|
||||||
|
one selected or unmatched type can return megabytes. Select
|
||||||
|
`{"path":"/absolute/path/Assembly.dll","type_names":["Namespace.Type"],"detail":"summary"}`
|
||||||
|
to keep the complete source in the session and receive identity, metadata
|
||||||
|
status, the selection with its unmatched names, coverage/issues, the separate
|
||||||
|
user-string coverage, limitations and per-collection counts. Then page original
|
||||||
|
rows with view kind `managed-members`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"source": {
|
||||||
|
"kind": "retained-evidence",
|
||||||
|
"evidence_id": "<parent_evidence_id>"
|
||||||
|
},
|
||||||
|
"view": {
|
||||||
|
"kind": "managed-members",
|
||||||
|
"collection": "call_edges",
|
||||||
|
"offset": 0,
|
||||||
|
"limit": 64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Collections are `types`, `exported_types`, `fields`, `methods`, `member_refs`,
|
||||||
|
`call_edges`, `field_accesses` and `user_strings` (the literals). Each page names
|
||||||
|
its collection, retains original rows, order, tokens, signatures and body facts,
|
||||||
|
and carries the source selection and coverage; `user_strings` pages carry the
|
||||||
|
literal pool's own coverage. Older Evidence that never examined exported types
|
||||||
|
or user strings reports a null count and refuses those pages rather than
|
||||||
|
returning an empty one.
|
||||||
|
|
||||||
## Shipped scope
|
## Shipped scope
|
||||||
|
|
||||||
The canonical parser admits PE/CLI bytes and their metadata/CIL without loading
|
The canonical parser admits PE/CLI bytes and their metadata/CIL without loading
|
||||||
|
|||||||
@@ -215,6 +215,27 @@ async function verifyNativeValueAdapters(
|
|||||||
const functionEvidence = parseEvidence(analyzed.structuredContent);
|
const functionEvidence = parseEvidence(analyzed.structuredContent);
|
||||||
assert.equal(functionEvidence.operation, "analyze_function");
|
assert.equal(functionEvidence.operation, "analyze_function");
|
||||||
assert.equal(functionEvidence.provider.id, "ghidra");
|
assert.equal(functionEvidence.provider.id, "ghidra");
|
||||||
|
assert.deepEqual(
|
||||||
|
functionEvidence.normalized_result.facet_availability,
|
||||||
|
Object.fromEntries(
|
||||||
|
[
|
||||||
|
"pseudocode",
|
||||||
|
"assembly",
|
||||||
|
"comments",
|
||||||
|
"callers",
|
||||||
|
"callees",
|
||||||
|
"references",
|
||||||
|
"strings_names",
|
||||||
|
"cfg",
|
||||||
|
].map((facet) => [facet, { available: true }]),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
assert.equal(functionEvidence.relationship_coverage?.status, "complete");
|
||||||
|
assert.ok(
|
||||||
|
functionEvidence.relationship_coverage.diagnostics.some((diagnostic) =>
|
||||||
|
diagnostic.includes("indirect calls remain unknown"),
|
||||||
|
),
|
||||||
|
);
|
||||||
const functionProfile = analysisProfileSchema.parse(
|
const functionProfile = analysisProfileSchema.parse(
|
||||||
functionEvidence.analysis_profile,
|
functionEvidence.analysis_profile,
|
||||||
);
|
);
|
||||||
@@ -247,6 +268,7 @@ async function verifyNativeValueAdapters(
|
|||||||
assert.ok(
|
assert.ok(
|
||||||
comparisonEvidence.evidence_links.includes(functionEvidence.evidence_id),
|
comparisonEvidence.evidence_links.includes(functionEvidence.evidence_id),
|
||||||
);
|
);
|
||||||
|
await verifyUnresolvedCallEvidence(client);
|
||||||
const bundle = await client.callTool({
|
const bundle = await client.callTool({
|
||||||
name: "get_evidence_bundle",
|
name: "get_evidence_bundle",
|
||||||
arguments: {},
|
arguments: {},
|
||||||
@@ -307,3 +329,63 @@ async function verifyNativeValueAdapters(
|
|||||||
unknowns: cliGraph.unknowns.length,
|
unknowns: cliGraph.unknowns.length,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function verifyUnresolvedCallEvidence(client) {
|
||||||
|
const inventory = await client.callTool({
|
||||||
|
name: "list_procedures",
|
||||||
|
arguments: {},
|
||||||
|
});
|
||||||
|
assert.notEqual(inventory.isError, true, JSON.stringify(inventory));
|
||||||
|
const procedures = parseEvidence(
|
||||||
|
inventory.structuredContent,
|
||||||
|
).normalized_result;
|
||||||
|
const indirect = procedures.find((item) =>
|
||||||
|
item.value.endsWith("rea_ghidra_inventory_indirect"),
|
||||||
|
);
|
||||||
|
const leaf = procedures.find((item) =>
|
||||||
|
item.value.endsWith("rea_ghidra_inventory_leaf"),
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
indirect && leaf,
|
||||||
|
"Source fixture lacks the unresolved callback and its possible target",
|
||||||
|
);
|
||||||
|
const analyzed = await client.callTool(
|
||||||
|
{ name: "analyze_function", arguments: { procedure: indirect.address } },
|
||||||
|
{ timeout: 180000 },
|
||||||
|
);
|
||||||
|
assert.notEqual(analyzed.isError, true, JSON.stringify(analyzed));
|
||||||
|
const evidence = parseEvidence(analyzed.structuredContent);
|
||||||
|
assert.equal(evidence.relationship_coverage?.status, "partial");
|
||||||
|
assert.ok(evidence.normalized_result.unresolved_calls.length > 0);
|
||||||
|
const traced = await client.callTool(
|
||||||
|
{
|
||||||
|
name: "trace_call_path",
|
||||||
|
arguments: {
|
||||||
|
start: indirect.address,
|
||||||
|
goal: leaf.address,
|
||||||
|
direction: "forward",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ timeout: 180000 },
|
||||||
|
);
|
||||||
|
assert.notEqual(traced.isError, true, JSON.stringify(traced));
|
||||||
|
const trace = parseEvidence(traced.structuredContent).normalized_result;
|
||||||
|
assert.equal(trace.goal_status, "unknown");
|
||||||
|
assert.equal(trace.truncated, true);
|
||||||
|
assert.ok(trace.residual_unknowns.length > 0);
|
||||||
|
const compared = await client.callTool(
|
||||||
|
{
|
||||||
|
name: "compare_functions",
|
||||||
|
arguments: {
|
||||||
|
left: analyzed.structuredContent,
|
||||||
|
right: analyzed.structuredContent,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ timeout: 180000 },
|
||||||
|
);
|
||||||
|
assert.notEqual(compared.isError, true, JSON.stringify(compared));
|
||||||
|
assert.equal(
|
||||||
|
parseEvidence(compared.structuredContent).normalized_result.status,
|
||||||
|
"unknown",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ export async function verifyGhidraBoundaries(
|
|||||||
assert.deepEqual(externalDossier.callees, []);
|
assert.deepEqual(externalDossier.callees, []);
|
||||||
assert.deepEqual(externalDossier.facet_availability.pseudocode, {
|
assert.deepEqual(externalDossier.facet_availability.pseudocode, {
|
||||||
available: false,
|
available: false,
|
||||||
reason: "Ghidra did not supply pseudocode.",
|
reason: "Ghidra does not decompile external functions.",
|
||||||
});
|
});
|
||||||
for (const facet of [
|
for (const facet of [
|
||||||
"assembly",
|
"assembly",
|
||||||
|
|||||||
@@ -606,6 +606,14 @@ export const SUPPORTED_CLIENT_DEFINITIONS = [
|
|||||||
markerPath: traeUserDirectory,
|
markerPath: traeUserDirectory,
|
||||||
format: "json",
|
format: "json",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "workbuddy",
|
||||||
|
displayName: "WorkBuddy",
|
||||||
|
skillPath: [".workbuddy", "skills"],
|
||||||
|
configPath: [".workbuddy", "mcp.json"],
|
||||||
|
markerPath: [".workbuddy"],
|
||||||
|
format: "json",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "grok_build",
|
name: "grok_build",
|
||||||
displayName: "Grok Build",
|
displayName: "Grok Build",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -21,13 +21,13 @@ export const managedTargetInputSchema = z.strictObject({
|
|||||||
.optional(),
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Delivery selection belongs only to artifact inspection, not member/native queries. */
|
/** Delivery selection belongs to artifact and member inspection, not native queries. */
|
||||||
export const managedArtifactInputSchema = managedTargetInputSchema.extend({
|
export const managedArtifactInputSchema = managedTargetInputSchema.extend({
|
||||||
detail: analysisDetailSchema.unwrap().optional(),
|
detail: analysisDetailSchema.unwrap().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Member inspection may select declaring types before members are decoded. */
|
/** Member inspection may select declaring types before members are decoded. */
|
||||||
export const managedMembersInputSchema = managedTargetInputSchema.extend({
|
export const managedMembersInputSchema = managedArtifactInputSchema.extend({
|
||||||
type_names: z
|
type_names: z
|
||||||
.array(
|
.array(
|
||||||
z
|
z
|
||||||
@@ -87,7 +87,7 @@ export const MANAGED_TOOL_CONTRACTS = [
|
|||||||
name: "inspect_managed_members",
|
name: "inspect_managed_members",
|
||||||
...toolContractMetadata("inspect_managed_members"),
|
...toolContractMetadata("inspect_managed_members"),
|
||||||
description:
|
description:
|
||||||
"Inspect PE/CLI metadata members, signatures, raw CIL hashes, decoded-instruction-tuple hashes, separately reported exception regions, call edges, field-access anchors, and the #US string literals that ldstr loads, without loading or executing target code. Select type_names to decode only the members of those exact declaring types and the literals their bodies load, which keeps large assemblies such as a base class library within the representation budget. Metadata tokens are reported as build-local coordinates bound to the artifact SHA-256 and MVID; the tuple hash does not resolve them or fully commit control flow.",
|
'Inspect PE/CLI metadata members, signatures, raw CIL hashes, decoded-instruction-tuple hashes, separately reported exception regions, call edges, field-access anchors, and the #US string literals that ldstr loads, without loading or executing target code. Select type_names to decode only the members of those exact declaring types and the literals their bodies load, which keeps large assemblies such as a base class library within the representation budget. Metadata tokens are reported as build-local coordinates bound to the artifact SHA-256 and MVID; the tuple hash does not resolve them or fully commit control flow. Omitted or complete detail returns every collection, including the assembly-wide member_refs and exported_types, which type_names does not narrow. Select detail: "summary" for identity, metadata status, selection with unmatched names, coverage/issues, limitations and per-collection counts; it retains complete Evidence and returns a linked inspect_analysis_view summary. Page original rows with view kind managed-members, normalized_result.parent_evidence_id and collection types/exported_types/fields/methods/member_refs/call_edges/field_accesses/user_strings.',
|
||||||
kind: "managed-provider",
|
kind: "managed-provider",
|
||||||
inputSchema: managedMembersInputSchema,
|
inputSchema: managedMembersInputSchema,
|
||||||
outputSchema: memberOutputSchema,
|
outputSchema: memberOutputSchema,
|
||||||
@@ -103,6 +103,14 @@ export const MANAGED_TOOL_CONTRACTS = [
|
|||||||
type_names: ["System.Threading.Monitor"],
|
type_names: ["System.Threading.Monitor"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Summarize selected managed types and retain their members",
|
||||||
|
input: {
|
||||||
|
path: "/tmp/mscorlib.dll",
|
||||||
|
type_names: ["System.Threading.Monitor"],
|
||||||
|
detail: "summary",
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
artifactInventorySummaryViewResultSchema,
|
artifactInventorySummaryViewResultSchema,
|
||||||
machoSummaryViewResultSchema,
|
machoSummaryViewResultSchema,
|
||||||
managedArtifactSummaryViewResultSchema,
|
managedArtifactSummaryViewResultSchema,
|
||||||
|
managedMemberSummaryViewResultSchema,
|
||||||
} from "../domain/analysisView/analysisView.js";
|
} from "../domain/analysisView/analysisView.js";
|
||||||
import { evidenceBundleSummarySchema } from "../domain/evidenceRecordSummary.js";
|
import { evidenceBundleSummarySchema } from "../domain/evidenceRecordSummary.js";
|
||||||
import { BINARY_ARCHITECTURES } from "../domain/binaryTargetTypes.js";
|
import { BINARY_ARCHITECTURES } from "../domain/binaryTargetTypes.js";
|
||||||
@@ -418,7 +419,12 @@ export const managedOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
|
|||||||
managedArtifactSummaryViewResultSchema,
|
managedArtifactSummaryViewResultSchema,
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
inspect_managed_members: evidenceResultOf(managedMemberInspectionSchema),
|
inspect_managed_members: evidenceResultOf(
|
||||||
|
z.union([
|
||||||
|
managedMemberInspectionSchema,
|
||||||
|
managedMemberSummaryViewResultSchema,
|
||||||
|
]),
|
||||||
|
),
|
||||||
inspect_managed_native_boundaries: evidenceResultOf(
|
inspect_managed_native_boundaries: evidenceResultOf(
|
||||||
managedNativeBoundaryInspectionSchema,
|
managedNativeBoundaryInspectionSchema,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -49,6 +49,13 @@ import {
|
|||||||
managedSummarySchema,
|
managedSummarySchema,
|
||||||
managedViewContextSchema,
|
managedViewContextSchema,
|
||||||
} from "./managedArtifactView.js";
|
} from "./managedArtifactView.js";
|
||||||
|
import {
|
||||||
|
projectManagedMemberView,
|
||||||
|
managedMembersViewRequestSchema,
|
||||||
|
managedMembersViewPageSchema,
|
||||||
|
managedMemberSummarySchema,
|
||||||
|
managedMembersViewContextSchema,
|
||||||
|
} from "./managedMemberView.js";
|
||||||
import {
|
import {
|
||||||
projectWasmArtifactView,
|
projectWasmArtifactView,
|
||||||
wasmViewRequestSchema,
|
wasmViewRequestSchema,
|
||||||
@@ -208,6 +215,7 @@ export const analysisViewRequestSchema = z.discriminatedUnion("kind", [
|
|||||||
machoViewRequestSchema,
|
machoViewRequestSchema,
|
||||||
evmViewRequestSchema,
|
evmViewRequestSchema,
|
||||||
managedViewRequestSchema,
|
managedViewRequestSchema,
|
||||||
|
managedMembersViewRequestSchema,
|
||||||
androidViewRequestSchema,
|
androidViewRequestSchema,
|
||||||
apiSurfaceViewSchema,
|
apiSurfaceViewSchema,
|
||||||
captureViewRequestSchema,
|
captureViewRequestSchema,
|
||||||
@@ -328,6 +336,7 @@ const viewResultBase = {
|
|||||||
"inspect_macho",
|
"inspect_macho",
|
||||||
"inspect_evm_interface",
|
"inspect_evm_interface",
|
||||||
"inspect_managed_artifact",
|
"inspect_managed_artifact",
|
||||||
|
"inspect_managed_members",
|
||||||
"inspect_web_network_capture",
|
"inspect_web_network_capture",
|
||||||
"inspect_android_package",
|
"inspect_android_package",
|
||||||
"inspect_pcap_capture",
|
"inspect_pcap_capture",
|
||||||
@@ -396,6 +405,13 @@ export const managedArtifactSummaryViewResultSchema = z.strictObject({
|
|||||||
summary: managedSummarySchema,
|
summary: managedSummarySchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** Exact member selection, coverage and counts for the selected delivery. */
|
||||||
|
export const managedMemberSummaryViewResultSchema = z.strictObject({
|
||||||
|
...summaryViewResultBase,
|
||||||
|
parent_operation: z.literal("inspect_managed_members"),
|
||||||
|
summary: managedMemberSummarySchema,
|
||||||
|
});
|
||||||
|
|
||||||
/** Exact historical capture summary, with no body or member-inventory payload. */
|
/** Exact historical capture summary, with no body or member-inventory payload. */
|
||||||
export const webNetworkCaptureSummaryViewResultSchema = z.strictObject({
|
export const webNetworkCaptureSummaryViewResultSchema = z.strictObject({
|
||||||
...summaryViewResultBase,
|
...summaryViewResultBase,
|
||||||
@@ -446,6 +462,7 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
|||||||
machoSummarySchema,
|
machoSummarySchema,
|
||||||
evmSummarySchema,
|
evmSummarySchema,
|
||||||
managedSummarySchema,
|
managedSummarySchema,
|
||||||
|
managedMemberSummarySchema,
|
||||||
captureSummarySchema,
|
captureSummarySchema,
|
||||||
androidPackageSummarySchema,
|
androidPackageSummarySchema,
|
||||||
pcapSummarySchema,
|
pcapSummarySchema,
|
||||||
@@ -529,6 +546,14 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
|||||||
...managedViewContextSchema.shape,
|
...managedViewContextSchema.shape,
|
||||||
parent_operation: z.literal("inspect_managed_artifact"),
|
parent_operation: z.literal("inspect_managed_artifact"),
|
||||||
}),
|
}),
|
||||||
|
z.strictObject({
|
||||||
|
kind: z.literal("managed-members"),
|
||||||
|
view: managedMembersViewRequestSchema,
|
||||||
|
page: managedMembersViewPageSchema,
|
||||||
|
...viewResultBase,
|
||||||
|
...managedMembersViewContextSchema.shape,
|
||||||
|
parent_operation: z.literal("inspect_managed_members"),
|
||||||
|
}),
|
||||||
z.strictObject({
|
z.strictObject({
|
||||||
kind: z.literal("android"),
|
kind: z.literal("android"),
|
||||||
view: androidViewRequestSchema,
|
view: androidViewRequestSchema,
|
||||||
@@ -622,6 +647,10 @@ export type UnsignedAnalysisView =
|
|||||||
Extract<AnalysisViewResult, { readonly kind: "managed" }>,
|
Extract<AnalysisViewResult, { readonly kind: "managed" }>,
|
||||||
"view_digest"
|
"view_digest"
|
||||||
>
|
>
|
||||||
|
| Omit<
|
||||||
|
Extract<AnalysisViewResult, { readonly kind: "managed-members" }>,
|
||||||
|
"view_digest"
|
||||||
|
>
|
||||||
| Omit<
|
| Omit<
|
||||||
Extract<AnalysisViewResult, { readonly kind: "android" }>,
|
Extract<AnalysisViewResult, { readonly kind: "android" }>,
|
||||||
"view_digest"
|
"view_digest"
|
||||||
@@ -674,7 +703,7 @@ const unsupportedParent = (
|
|||||||
new AnalysisUnsupportedTargetError(
|
new AnalysisUnsupportedTargetError(
|
||||||
INSPECT_ANALYSIS_VIEW_OPERATION,
|
INSPECT_ANALYSIS_VIEW_OPERATION,
|
||||||
parentArtifactPath(parent),
|
parentArtifactPath(parent),
|
||||||
`Parent Evidence operation ${JSON.stringify(parent.operation)} does not support analysis views. Use completed binary layout, JavaScript application, native function, artifact inventory/inspection, WASM, Mach-O, EVM, managed artifact, Android package, Dart AOT, or web network capture Evidence.`,
|
`Parent Evidence operation ${JSON.stringify(parent.operation)} does not support analysis views. Use completed binary layout, JavaScript application, native function, artifact inventory/inspection, WASM, Mach-O, EVM, managed artifact or member, Android package, Dart AOT, or web network capture Evidence.`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const parentArtifactPath = (parent: AnalysisViewParent): string => {
|
const parentArtifactPath = (parent: AnalysisViewParent): string => {
|
||||||
@@ -704,6 +733,7 @@ const retainedViewProjectors = new Map<string, typeof projectWasmArtifactView>([
|
|||||||
["inspect_macho", projectMachoView],
|
["inspect_macho", projectMachoView],
|
||||||
["inspect_evm_interface", projectEvmInterfaceView],
|
["inspect_evm_interface", projectEvmInterfaceView],
|
||||||
["inspect_managed_artifact", projectManagedArtifactView],
|
["inspect_managed_artifact", projectManagedArtifactView],
|
||||||
|
["inspect_managed_members", projectManagedMemberView],
|
||||||
["inspect_android_package", projectAndroidPackageView],
|
["inspect_android_package", projectAndroidPackageView],
|
||||||
["inspect_dart_aot", projectDartAotView],
|
["inspect_dart_aot", projectDartAotView],
|
||||||
["inspect_artifact", projectArtifactInventoryView],
|
["inspect_artifact", projectArtifactInventoryView],
|
||||||
|
|||||||
@@ -51,6 +51,24 @@ export const managedViewContextSchema = z.strictObject({
|
|||||||
source_coverage: managedArtifactInspectionSchema.shape.coverage,
|
source_coverage: managedArtifactInspectionSchema.shape.coverage,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** Token scope and identity limits shared by every managed metadata view. */
|
||||||
|
export const managedViewIdentityUnknowns = (
|
||||||
|
parent: AnalysisViewParent,
|
||||||
|
mvid: string | null,
|
||||||
|
): string[] => [
|
||||||
|
"Metadata tokens are build-local coordinates bound to the recorded artifact SHA-256 and module MVID; this view does not load or execute the assembly.",
|
||||||
|
...(parent.subject == null
|
||||||
|
? [
|
||||||
|
"The parent has no recorded subject; its normalized artifact identity cannot be cross-checked against a subject digest.",
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
...(mvid === null
|
||||||
|
? [
|
||||||
|
"The module MVID is unknown; tokens cannot establish a cross-observation module match.",
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
];
|
||||||
|
|
||||||
/** Project authenticated metadata without reading a path or invoking a provider. */
|
/** Project authenticated metadata without reading a path or invoking a provider. */
|
||||||
export const projectManagedArtifactView = (
|
export const projectManagedArtifactView = (
|
||||||
parent: AnalysisViewParent,
|
parent: AnalysisViewParent,
|
||||||
@@ -96,17 +114,7 @@ export const projectManagedArtifactView = (
|
|||||||
limitations: uniqueSorted([...parent.limitations, ...report.limitations]),
|
limitations: uniqueSorted([...parent.limitations, ...report.limitations]),
|
||||||
unknowns: [
|
unknowns: [
|
||||||
"Collection counts and pages cover producer-returned rows; metadata completeness remains the original metadata status and coverage, not an absence claim about unreturned rows.",
|
"Collection counts and pages cover producer-returned rows; metadata completeness remains the original metadata status and coverage, not an absence claim about unreturned rows.",
|
||||||
"Metadata tokens are build-local coordinates bound to the recorded artifact SHA-256 and module MVID; this view does not load or execute the assembly.",
|
...managedViewIdentityUnknowns(parent, identity_scope.requires_mvid),
|
||||||
...(parent.subject == null
|
|
||||||
? [
|
|
||||||
"The parent has no recorded subject; its normalized artifact identity cannot be cross-checked against a subject digest.",
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
...(identity_scope.requires_mvid === null
|
|
||||||
? [
|
|
||||||
"The module MVID is unknown; tokens cannot establish a cross-observation module match.",
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
if (view.kind === "summary") {
|
if (view.kind === "summary") {
|
||||||
|
|||||||
@@ -0,0 +1,270 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
import type { AnalysisError } from "../analysisErrorBase.js";
|
||||||
|
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||||
|
import { analysisInputErrorFromIssues } from "../inputIssueProjection.js";
|
||||||
|
import {
|
||||||
|
managedMemberInspectionSchema,
|
||||||
|
type ManagedMemberInspection,
|
||||||
|
} from "../managed/managedArtifact.js";
|
||||||
|
import { err, ok, type Result } from "../result.js";
|
||||||
|
import {
|
||||||
|
analysisViewInputError,
|
||||||
|
type AnalysisViewParent,
|
||||||
|
type AnalysisViewRequest,
|
||||||
|
type UnsignedAnalysisView,
|
||||||
|
} from "./analysisView.js";
|
||||||
|
import {
|
||||||
|
completeWithinViewCoverage,
|
||||||
|
pageViewCoverage,
|
||||||
|
} from "./analysisViewCoverage.js";
|
||||||
|
import { managedViewIdentityUnknowns } from "./managedArtifactView.js";
|
||||||
|
|
||||||
|
const member = managedMemberInspectionSchema.shape;
|
||||||
|
|
||||||
|
/** Original member rows; offsets count entries in the returned parent collection. */
|
||||||
|
export const managedMembersViewRequestSchema = z.strictObject({
|
||||||
|
kind: z.literal("managed-members"),
|
||||||
|
collection: z.enum([
|
||||||
|
"types",
|
||||||
|
"exported_types",
|
||||||
|
"fields",
|
||||||
|
"methods",
|
||||||
|
"member_refs",
|
||||||
|
"call_edges",
|
||||||
|
"field_accesses",
|
||||||
|
"user_strings",
|
||||||
|
]),
|
||||||
|
offset: z.number().int().nonnegative().default(0),
|
||||||
|
limit: z.number().int().positive().default(64),
|
||||||
|
});
|
||||||
|
|
||||||
|
const rowsOf = <C extends string, S extends z.ZodArray>(
|
||||||
|
collection: C,
|
||||||
|
rows: S,
|
||||||
|
) => z.strictObject({ collection: z.literal(collection), rows });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rows of one collection, keyed by that collection: several row schemas accept
|
||||||
|
* each other's rows after stripping keys, so no union may pick one by order.
|
||||||
|
*/
|
||||||
|
export const managedMembersViewPageSchema = z.discriminatedUnion("collection", [
|
||||||
|
rowsOf("types", member.types),
|
||||||
|
rowsOf("exported_types", member.exported_types.unwrap().unwrap()),
|
||||||
|
rowsOf("fields", member.fields),
|
||||||
|
rowsOf("methods", member.methods),
|
||||||
|
rowsOf("member_refs", member.member_refs),
|
||||||
|
rowsOf("call_edges", member.call_edges),
|
||||||
|
rowsOf("field_accesses", member.field_accesses),
|
||||||
|
rowsOf("user_strings", member.user_strings.unwrap().unwrap().shape.literals),
|
||||||
|
]);
|
||||||
|
|
||||||
|
type ManagedMembersViewPage = z.infer<typeof managedMembersViewPageSchema>;
|
||||||
|
|
||||||
|
const nullableCount = z.number().int().nonnegative().nullable();
|
||||||
|
|
||||||
|
/** Keep identity, selection and coverage; member collections remain retained. */
|
||||||
|
export const managedMemberSummarySchema = z.strictObject({
|
||||||
|
artifact: member.artifact,
|
||||||
|
module: member.module,
|
||||||
|
metadata: member.metadata,
|
||||||
|
identity_scope: member.identity_scope,
|
||||||
|
selection: member.selection.unwrap(),
|
||||||
|
coverage: member.coverage,
|
||||||
|
user_strings: z
|
||||||
|
.strictObject({
|
||||||
|
state: member.user_strings.unwrap().unwrap().shape.state,
|
||||||
|
issues: member.user_strings.unwrap().unwrap().shape.issues,
|
||||||
|
})
|
||||||
|
.nullable(),
|
||||||
|
limitations: member.limitations,
|
||||||
|
reported_counts: z.strictObject({
|
||||||
|
types: z.number().int().nonnegative(),
|
||||||
|
exported_types: nullableCount,
|
||||||
|
fields: z.number().int().nonnegative(),
|
||||||
|
methods: z.number().int().nonnegative(),
|
||||||
|
member_refs: z.number().int().nonnegative(),
|
||||||
|
call_edges: z.number().int().nonnegative(),
|
||||||
|
field_accesses: z.number().int().nonnegative(),
|
||||||
|
user_strings: nullableCount,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const managedMembersViewContextSchema = z.strictObject({
|
||||||
|
identity_scope: member.identity_scope,
|
||||||
|
selection: member.selection.unwrap(),
|
||||||
|
source_metadata_status: member.metadata.shape.status,
|
||||||
|
source_coverage: member.coverage,
|
||||||
|
});
|
||||||
|
|
||||||
|
type ManagedMembersViewRequest = z.infer<
|
||||||
|
typeof managedMembersViewRequestSchema
|
||||||
|
>;
|
||||||
|
type MemberCollection = ManagedMembersViewRequest["collection"];
|
||||||
|
|
||||||
|
const slice = <C extends MemberCollection, T>(
|
||||||
|
collection: C,
|
||||||
|
rows: readonly T[] | null | undefined,
|
||||||
|
{ offset, limit }: { readonly offset: number; readonly limit: number },
|
||||||
|
) =>
|
||||||
|
rows == null
|
||||||
|
? null
|
||||||
|
: {
|
||||||
|
page: { collection, rows: rows.slice(offset, offset + limit) },
|
||||||
|
total: rows.length,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** One page of a collection, or null when the parent never examined it. */
|
||||||
|
const collectionPage = (
|
||||||
|
report: ManagedMemberInspection,
|
||||||
|
view: ManagedMembersViewRequest,
|
||||||
|
): { readonly page: ManagedMembersViewPage; readonly total: number } | null => {
|
||||||
|
const { collection } = view;
|
||||||
|
switch (collection) {
|
||||||
|
case "types":
|
||||||
|
return slice(collection, report.types, view);
|
||||||
|
case "exported_types":
|
||||||
|
return slice(collection, report.exported_types, view);
|
||||||
|
case "fields":
|
||||||
|
return slice(collection, report.fields, view);
|
||||||
|
case "methods":
|
||||||
|
return slice(collection, report.methods, view);
|
||||||
|
case "member_refs":
|
||||||
|
return slice(collection, report.member_refs, view);
|
||||||
|
case "call_edges":
|
||||||
|
return slice(collection, report.call_edges, view);
|
||||||
|
case "field_accesses":
|
||||||
|
return slice(collection, report.field_accesses, view);
|
||||||
|
case "user_strings":
|
||||||
|
return slice(collection, report.user_strings?.literals, view);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Everything but the member collections, which are replaced by their counts. */
|
||||||
|
const summarizeMembers = (
|
||||||
|
report: ManagedMemberInspection,
|
||||||
|
): z.infer<typeof managedMemberSummarySchema> => {
|
||||||
|
const {
|
||||||
|
types,
|
||||||
|
exported_types,
|
||||||
|
fields,
|
||||||
|
methods,
|
||||||
|
member_refs,
|
||||||
|
call_edges,
|
||||||
|
field_accesses,
|
||||||
|
user_strings,
|
||||||
|
...identity
|
||||||
|
} = report;
|
||||||
|
return {
|
||||||
|
...identity,
|
||||||
|
user_strings:
|
||||||
|
user_strings === null
|
||||||
|
? null
|
||||||
|
: { state: user_strings.state, issues: user_strings.issues },
|
||||||
|
reported_counts: {
|
||||||
|
types: types.length,
|
||||||
|
exported_types: exported_types?.length ?? null,
|
||||||
|
fields: fields.length,
|
||||||
|
methods: methods.length,
|
||||||
|
member_refs: member_refs.length,
|
||||||
|
call_edges: call_edges.length,
|
||||||
|
field_accesses: field_accesses.length,
|
||||||
|
user_strings: user_strings?.literals.length ?? null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Project authenticated member Evidence without reading a path or invoking a provider. */
|
||||||
|
export const projectManagedMemberView = (
|
||||||
|
parent: AnalysisViewParent,
|
||||||
|
view: AnalysisViewRequest,
|
||||||
|
): Result<UnsignedAnalysisView, AnalysisError> => {
|
||||||
|
if (view.kind !== "summary" && view.kind !== "managed-members")
|
||||||
|
return err(
|
||||||
|
analysisViewInputError([
|
||||||
|
{
|
||||||
|
path: ["view"],
|
||||||
|
reason: "invalid_value",
|
||||||
|
message:
|
||||||
|
"Managed member inspection supports summary and managed-members views.",
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
const parsed = managedMemberInspectionSchema.safeParse(
|
||||||
|
parent.normalizedResult,
|
||||||
|
);
|
||||||
|
if (!parsed.success)
|
||||||
|
return err(
|
||||||
|
analysisInputErrorFromIssues(
|
||||||
|
"inspect_analysis_view",
|
||||||
|
parsed.error.issues.map((issue) => ({
|
||||||
|
...issue,
|
||||||
|
path: ["source", "normalized_result", ...issue.path],
|
||||||
|
})),
|
||||||
|
{ source: { normalized_result: parent.normalizedResult } },
|
||||||
|
{ cause: parsed.error },
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const report = parsed.data;
|
||||||
|
const shared = {
|
||||||
|
parent_evidence_id: parent.evidenceId,
|
||||||
|
parent_operation: "inspect_managed_members" as const,
|
||||||
|
parent_digest: parent.evidenceId.slice(3),
|
||||||
|
artifact: { path: report.artifact.path, sha256: report.artifact.sha256 },
|
||||||
|
limitations: uniqueSorted([...parent.limitations, ...report.limitations]),
|
||||||
|
unknowns: [
|
||||||
|
"Collection counts and pages cover producer-returned rows; member completeness remains the original coverage, not an absence claim about unreturned rows.",
|
||||||
|
...(report.selection === null
|
||||||
|
? []
|
||||||
|
: [
|
||||||
|
"Exported types and member references cover the whole assembly; the other collections cover only the selected declaring types.",
|
||||||
|
]),
|
||||||
|
...managedViewIdentityUnknowns(
|
||||||
|
parent,
|
||||||
|
report.identity_scope.requires_mvid,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
if (view.kind === "summary") {
|
||||||
|
const summary = summarizeMembers(report);
|
||||||
|
const total = Object.values(summary.reported_counts).reduce<number>(
|
||||||
|
(sum, count) => sum + (count ?? 0),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
return ok({
|
||||||
|
kind: "summary",
|
||||||
|
view,
|
||||||
|
...shared,
|
||||||
|
summary,
|
||||||
|
coverage: completeWithinViewCoverage(total, total),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const selected = collectionPage(report, view);
|
||||||
|
if (selected === null)
|
||||||
|
return err(
|
||||||
|
analysisViewInputError([
|
||||||
|
{
|
||||||
|
path: ["view", "collection"],
|
||||||
|
reason: "invalid_value",
|
||||||
|
message: `The parent Evidence did not examine ${view.collection}; repeat inspect_managed_members with the current runtime to record it.`,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
const { page, total } = selected;
|
||||||
|
return ok({
|
||||||
|
kind: "managed-members",
|
||||||
|
view,
|
||||||
|
page,
|
||||||
|
...shared,
|
||||||
|
identity_scope: report.identity_scope,
|
||||||
|
selection: report.selection,
|
||||||
|
source_metadata_status: report.metadata.status,
|
||||||
|
source_coverage:
|
||||||
|
view.collection === "user_strings" && report.user_strings !== null
|
||||||
|
? {
|
||||||
|
state: report.user_strings.state,
|
||||||
|
issues: report.user_strings.issues,
|
||||||
|
}
|
||||||
|
: report.coverage,
|
||||||
|
coverage: pageViewCoverage(view.offset, page.rows.length, total),
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -337,6 +337,42 @@ describe("call path topology and capacity", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("directional call relationship coverage", () => {
|
||||||
|
it.each([
|
||||||
|
{
|
||||||
|
directions: ["callers"] as ["callers"],
|
||||||
|
status: "not_found",
|
||||||
|
exhaustive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
directions: ["callees"] as ["callees"],
|
||||||
|
status: "unknown",
|
||||||
|
exhaustive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
directions: ["callers", "callees"] as ["callers", "callees"],
|
||||||
|
status: "unknown",
|
||||||
|
exhaustive: false,
|
||||||
|
},
|
||||||
|
])(
|
||||||
|
"uses $directions coverage for the forward search",
|
||||||
|
({ directions, status, exhaustive }) => {
|
||||||
|
const limitation = "The inventory omitted a reference.";
|
||||||
|
const relationshipCoverage: RelationshipCoverage = {
|
||||||
|
status: "partial",
|
||||||
|
limitations: [limitation],
|
||||||
|
limited_directions: directions,
|
||||||
|
};
|
||||||
|
const result = run([
|
||||||
|
observe("0x1000", ["0x2000"], "rea-workflow", { relationshipCoverage }),
|
||||||
|
observe("0x2000", [], "rea-workflow", { relationshipCoverage }),
|
||||||
|
]);
|
||||||
|
expect(result).toMatchObject({ status, search_scope: { exhaustive } });
|
||||||
|
expect(result.limitations).toContain(limitation);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
describe("explicit call relationship coverage", () => {
|
describe("explicit call relationship coverage", () => {
|
||||||
it("accumulates 150,000 partial reasons without argument-stack exhaustion", () => {
|
it("accumulates 150,000 partial reasons without argument-stack exhaustion", () => {
|
||||||
const result = run([
|
const result = run([
|
||||||
|
|||||||
+8
-10
@@ -1,3 +1,4 @@
|
|||||||
|
import { relationshipCoverageLimitations } from "./relationshipCoverage.js";
|
||||||
import {
|
import {
|
||||||
callPathInputSchema,
|
callPathInputSchema,
|
||||||
callPathResultSchema,
|
callPathResultSchema,
|
||||||
@@ -10,7 +11,7 @@ import {
|
|||||||
parseFunctionEvidence,
|
parseFunctionEvidence,
|
||||||
type FunctionSnapshot,
|
type FunctionSnapshot,
|
||||||
} from "./functionDossierEvidence.js";
|
} from "./functionDossierEvidence.js";
|
||||||
import { isCallerOnlyUnknownCoverage } from "./functionCallCoverage.js";
|
import { isCallerOnlyIncompleteCoverage } from "./functionCallCoverage.js";
|
||||||
import { compareUnicodeCodePoints } from "./unicodeCodePointOrder.js";
|
import { compareUnicodeCodePoints } from "./unicodeCodePointOrder.js";
|
||||||
|
|
||||||
/** Minimal directed caller-to-callee adjacency for call-path search. */
|
/** Minimal directed caller-to-callee adjacency for call-path search. */
|
||||||
@@ -240,15 +241,12 @@ const inspectSearch = ({
|
|||||||
const coverage = snapshot.evidence.relationship_coverage;
|
const coverage = snapshot.evidence.relationship_coverage;
|
||||||
for (const limitation of snapshot.limitations)
|
for (const limitation of snapshot.limitations)
|
||||||
limitations.push(limitation);
|
limitations.push(limitation);
|
||||||
if (coverage?.status === "partial")
|
if (coverage !== null) {
|
||||||
for (const limitation of coverage.limitations)
|
for (const limitation of relationshipCoverageLimitations(coverage))
|
||||||
limitations.push(limitation);
|
limitations.push(limitation);
|
||||||
else if (coverage?.status === "unknown")
|
for (const diagnostic of coverage.diagnostics ?? [])
|
||||||
limitations.push(coverage.reason);
|
limitations.push(diagnostic);
|
||||||
for (const diagnostic of coverage !== null && "diagnostics" in coverage
|
}
|
||||||
? coverage.diagnostics
|
|
||||||
: [])
|
|
||||||
limitations.push(diagnostic);
|
|
||||||
// The requested goal is a terminal for this search. Its outgoing edges
|
// The requested goal is a terminal for this search. Its outgoing edges
|
||||||
// cannot add a path to the goal, so its dossier limits are contextual
|
// cannot add a path to the goal, so its dossier limits are contextual
|
||||||
// but do not make the searched start-to-goal closure incomplete.
|
// but do not make the searched start-to-goal closure incomplete.
|
||||||
@@ -268,7 +266,7 @@ const inspectSearch = ({
|
|||||||
coverage === null
|
coverage === null
|
||||||
? snapshot.limitations.length > 0
|
? snapshot.limitations.length > 0
|
||||||
: coverage.status !== "complete" &&
|
: coverage.status !== "complete" &&
|
||||||
!isCallerOnlyUnknownCoverage(coverage)
|
!isCallerOnlyIncompleteCoverage(coverage)
|
||||||
)
|
)
|
||||||
incompleteExpandedCoverage = true;
|
incompleteExpandedCoverage = true;
|
||||||
} else if (node === goal) {
|
} else if (node === goal) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
combineFunctionRelationshipCoverage,
|
combineFunctionRelationshipCoverage,
|
||||||
isCallerOnlyUnknownCoverage,
|
isCallerOnlyIncompleteCoverage,
|
||||||
} from "./functionCallCoverage.js";
|
} from "./functionCallCoverage.js";
|
||||||
import type { RelationshipCoverage } from "./relationshipCoverage.js";
|
import type { RelationshipCoverage } from "./relationshipCoverage.js";
|
||||||
|
|
||||||
@@ -22,14 +22,14 @@ const cappedCallees: RelationshipCoverage = {
|
|||||||
};
|
};
|
||||||
const complete: RelationshipCoverage = { status: "complete" };
|
const complete: RelationshipCoverage = { status: "complete" };
|
||||||
|
|
||||||
describe("isCallerOnlyUnknownCoverage", () => {
|
describe("isCallerOnlyIncompleteCoverage", () => {
|
||||||
it("detects unknown callers beside complete callees", () => {
|
it("detects unknown callers beside complete callees", () => {
|
||||||
const combined = combineFunctionRelationshipCoverage(
|
const combined = combineFunctionRelationshipCoverage(
|
||||||
unknownCallers,
|
unknownCallers,
|
||||||
complete,
|
complete,
|
||||||
);
|
);
|
||||||
expect(combined.status).toBe("unknown");
|
expect(combined.status).toBe("unknown");
|
||||||
expect(isCallerOnlyUnknownCoverage(combined)).toBe(true);
|
expect(isCallerOnlyIncompleteCoverage(combined)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects unknown callees beside complete callers", () => {
|
it("rejects unknown callees beside complete callers", () => {
|
||||||
@@ -37,7 +37,7 @@ describe("isCallerOnlyUnknownCoverage", () => {
|
|||||||
complete,
|
complete,
|
||||||
unknownCallees,
|
unknownCallees,
|
||||||
);
|
);
|
||||||
expect(isCallerOnlyUnknownCoverage(combined)).toBe(false);
|
expect(isCallerOnlyIncompleteCoverage(combined)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects unknown coverage on both sides", () => {
|
it("rejects unknown coverage on both sides", () => {
|
||||||
@@ -45,7 +45,7 @@ describe("isCallerOnlyUnknownCoverage", () => {
|
|||||||
unknownCallers,
|
unknownCallers,
|
||||||
unknownCallees,
|
unknownCallees,
|
||||||
);
|
);
|
||||||
expect(isCallerOnlyUnknownCoverage(combined)).toBe(false);
|
expect(isCallerOnlyIncompleteCoverage(combined)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects unknown callers beside IDA-capped callees", () => {
|
it("rejects unknown callers beside IDA-capped callees", () => {
|
||||||
@@ -54,11 +54,37 @@ describe("isCallerOnlyUnknownCoverage", () => {
|
|||||||
cappedCallees,
|
cappedCallees,
|
||||||
);
|
);
|
||||||
expect(combined.status).toBe("unknown");
|
expect(combined.status).toBe("unknown");
|
||||||
expect(isCallerOnlyUnknownCoverage(combined)).toBe(false);
|
expect(isCallerOnlyIncompleteCoverage(combined)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects complete coverage", () => {
|
it("rejects complete coverage", () => {
|
||||||
const combined = combineFunctionRelationshipCoverage(complete, complete);
|
const combined = combineFunctionRelationshipCoverage(complete, complete);
|
||||||
expect(isCallerOnlyUnknownCoverage(combined)).toBe(false);
|
expect(isCallerOnlyIncompleteCoverage(combined)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("retains caller-only partial coverage without relying on limitation wording", () => {
|
||||||
|
const combined = combineFunctionRelationshipCoverage(
|
||||||
|
{ status: "partial", limitations: ["Missing incoming references."] },
|
||||||
|
complete,
|
||||||
|
);
|
||||||
|
expect(combined).toMatchObject({ limited_directions: ["callers"] });
|
||||||
|
expect(isCallerOnlyIncompleteCoverage(combined)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses explicit directions even when explanation text contains direction labels", () => {
|
||||||
|
expect(
|
||||||
|
isCallerOnlyIncompleteCoverage({
|
||||||
|
status: "unknown",
|
||||||
|
reason: "Callers: unavailable. Callees: diagnostic text.",
|
||||||
|
limited_directions: ["callers"],
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
expect(
|
||||||
|
isCallerOnlyIncompleteCoverage({
|
||||||
|
status: "unknown",
|
||||||
|
reason: "Callers: unavailable.",
|
||||||
|
limited_directions: ["callees"],
|
||||||
|
}),
|
||||||
|
).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
import type { RelationshipCoverage } from "./relationshipCoverage.js";
|
import {
|
||||||
|
relationshipCoverageLimitations,
|
||||||
|
type RelationshipCoverage,
|
||||||
|
} from "./relationshipCoverage.js";
|
||||||
import type { FunctionDossier } from "./hopperValues.js";
|
import type { FunctionDossier } from "./hopperValues.js";
|
||||||
import { uniqueSorted } from "./canonicalOrdering.js";
|
import { uniqueSorted } from "./canonicalOrdering.js";
|
||||||
|
|
||||||
@@ -15,25 +18,25 @@ export const combineFunctionRelationshipCoverage = (
|
|||||||
{ direction: "callees" as const, coverage: callees },
|
{ direction: "callees" as const, coverage: callees },
|
||||||
];
|
];
|
||||||
const diagnostics = uniqueSorted(
|
const diagnostics = uniqueSorted(
|
||||||
reads.flatMap(({ coverage }) =>
|
reads.flatMap(({ coverage }) => coverage?.diagnostics ?? []),
|
||||||
coverage !== undefined && "diagnostics" in coverage
|
|
||||||
? coverage.diagnostics
|
|
||||||
: [],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
const details = diagnostics.length > 0 ? { diagnostics } : {};
|
const details = diagnostics.length > 0 ? { diagnostics } : {};
|
||||||
|
const callersLimited = callers?.status !== "complete";
|
||||||
|
const calleesLimited = callees?.status !== "complete";
|
||||||
|
const limited_directions: Extract<
|
||||||
|
RelationshipCoverage,
|
||||||
|
{ status: "partial" }
|
||||||
|
>["limited_directions"] = callersLimited
|
||||||
|
? calleesLimited
|
||||||
|
? ["callers", "callees"]
|
||||||
|
: ["callers"]
|
||||||
|
: ["callees"];
|
||||||
const reasons = reads.flatMap(({ direction, coverage }) => {
|
const reasons = reads.flatMap(({ direction, coverage }) => {
|
||||||
const label =
|
const label =
|
||||||
direction === "callers" ? callerCoveragePrefix : calleeCoveragePrefix;
|
direction === "callers" ? callerCoveragePrefix : calleeCoveragePrefix;
|
||||||
const limitations =
|
return relationshipCoverageLimitations(coverage).map(
|
||||||
coverage === undefined
|
(reason) => `${label}${reason}`,
|
||||||
? ["Provider did not report relationship coverage."]
|
);
|
||||||
: coverage.status === "unknown"
|
|
||||||
? [coverage.reason]
|
|
||||||
: coverage.status === "partial"
|
|
||||||
? coverage.limitations
|
|
||||||
: [];
|
|
||||||
return limitations.map((reason) => `${label}${reason}`);
|
|
||||||
});
|
});
|
||||||
if (
|
if (
|
||||||
reads.some(
|
reads.some(
|
||||||
@@ -43,54 +46,48 @@ export const combineFunctionRelationshipCoverage = (
|
|||||||
return {
|
return {
|
||||||
status: "unknown",
|
status: "unknown",
|
||||||
reason: uniqueSorted(reasons).join(" "),
|
reason: uniqueSorted(reasons).join(" "),
|
||||||
|
limited_directions,
|
||||||
...details,
|
...details,
|
||||||
};
|
};
|
||||||
if (reasons.length > 0)
|
if (reasons.length > 0)
|
||||||
return {
|
return {
|
||||||
status: "partial",
|
status: "partial",
|
||||||
limitations: uniqueSorted(reasons),
|
limitations: uniqueSorted(reasons),
|
||||||
|
limited_directions,
|
||||||
...details,
|
...details,
|
||||||
};
|
};
|
||||||
return { status: "complete", ...details };
|
return { status: "complete", ...details };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether combined relationship coverage is unknown only on the caller side.
|
* Forward searches depend on callee coverage. Preserve the historical
|
||||||
* The combine helper above prefixes each direction's reasons, so a reason
|
* unknown-reason encoding when reading observations without explicit directions.
|
||||||
* that carries the caller prefix and no callee prefix records observed
|
|
||||||
* callees with unobservable callers. Forward (callee-edge) searches stay
|
|
||||||
* exhaustive under that caveat; the caller reason remains a limitation.
|
|
||||||
*/
|
*/
|
||||||
export const isCallerOnlyUnknownCoverage = (
|
export const isCallerOnlyIncompleteCoverage = (
|
||||||
coverage: RelationshipCoverage,
|
coverage: RelationshipCoverage,
|
||||||
): boolean =>
|
): boolean => {
|
||||||
coverage.status === "unknown" &&
|
if (coverage.status === "complete") return false;
|
||||||
coverage.reason.startsWith(callerCoveragePrefix) &&
|
if (coverage.limited_directions !== undefined)
|
||||||
!coverage.reason.includes(calleeCoveragePrefix);
|
return !coverage.limited_directions.some(
|
||||||
|
(direction) => direction === "callees",
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
coverage.status === "unknown" &&
|
||||||
|
coverage.reason.startsWith(callerCoveragePrefix) &&
|
||||||
|
!coverage.reason.includes(calleeCoveragePrefix)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/** Explain why two resolved call sets cannot establish call-set equality. */
|
/** Explain why two resolved call sets cannot establish call-set equality. */
|
||||||
export const functionCallCoverageLimitations = (
|
export const functionCallCoverageLimitations = (
|
||||||
coverage: RelationshipCoverage | null,
|
coverage: RelationshipCoverage | null,
|
||||||
dossier: Pick<FunctionDossier, "unresolved_calls">,
|
dossier: Pick<FunctionDossier, "unresolved_calls">,
|
||||||
): string[] => {
|
): string[] => {
|
||||||
const limitations =
|
return uniqueSorted([
|
||||||
coverage === null
|
...relationshipCoverageLimitations(coverage),
|
||||||
? ["Provider did not report relationship coverage."]
|
...(coverage?.status === "complete" ? [] : (coverage?.diagnostics ?? [])),
|
||||||
: coverage.status === "unknown"
|
|
||||||
? [
|
|
||||||
coverage.reason,
|
|
||||||
...("diagnostics" in coverage ? coverage.diagnostics : []),
|
|
||||||
]
|
|
||||||
: coverage.status === "partial"
|
|
||||||
? [
|
|
||||||
...coverage.limitations,
|
|
||||||
...("diagnostics" in coverage ? coverage.diagnostics : []),
|
|
||||||
]
|
|
||||||
: [];
|
|
||||||
limitations.push(
|
|
||||||
...(dossier.unresolved_calls ?? []).map(
|
...(dossier.unresolved_calls ?? []).map(
|
||||||
({ address, reason }) => `Unresolved call at ${address}: ${reason}`,
|
({ address, reason }) => `Unresolved call at ${address}: ${reason}`,
|
||||||
),
|
),
|
||||||
);
|
]);
|
||||||
return uniqueSorted(limitations);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
||||||
|
|
||||||
|
const endpoints = (source: string) =>
|
||||||
|
analyzeJavaScriptStaticSource(source).endpoints.map(
|
||||||
|
({ kind, value, mechanism }) => ({ kind, value, mechanism }),
|
||||||
|
);
|
||||||
|
|
||||||
|
describe("server-sent event endpoints", () => {
|
||||||
|
it("reports EventSource URLs like WebSocket URLs", () => {
|
||||||
|
expect(
|
||||||
|
endpoints(`
|
||||||
|
new WebSocket("wss://chat.example/ws");
|
||||||
|
new EventSource("/api/chat/stream");
|
||||||
|
new window.EventSource("https://chat.example/events", { withCredentials: true });
|
||||||
|
`),
|
||||||
|
).toEqual([
|
||||||
|
{
|
||||||
|
kind: "network",
|
||||||
|
value: "wss://chat.example/ws",
|
||||||
|
mechanism: "call:WebSocket",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kind: "network",
|
||||||
|
value: "/api/chat/stream",
|
||||||
|
mechanism: "call:EventSource",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kind: "network",
|
||||||
|
value: "https://chat.example/events",
|
||||||
|
mechanism: "call:window.EventSource",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps a dynamic EventSource URL unreported", () => {
|
||||||
|
expect(endpoints("new EventSource(url);")).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
||||||
|
|
||||||
|
const endpoints = (source: string) =>
|
||||||
|
analyzeJavaScriptStaticSource(source).endpoints.map(
|
||||||
|
({ kind, value, mechanism }) => ({ kind, value, mechanism }),
|
||||||
|
);
|
||||||
|
|
||||||
|
describe("beacon endpoints", () => {
|
||||||
|
it("reports navigator.sendBeacon URLs", () => {
|
||||||
|
expect(
|
||||||
|
endpoints(`
|
||||||
|
navigator.sendBeacon("/api/telemetry", payload);
|
||||||
|
window.navigator.sendBeacon("https://metrics.example/collect");
|
||||||
|
`),
|
||||||
|
).toEqual([
|
||||||
|
{
|
||||||
|
kind: "network",
|
||||||
|
value: "/api/telemetry",
|
||||||
|
mechanism: "call:navigator.sendBeacon",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kind: "network",
|
||||||
|
value: "https://metrics.example/collect",
|
||||||
|
mechanism: "call:window.navigator.sendBeacon",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps a dynamic beacon URL unreported", () => {
|
||||||
|
expect(endpoints("navigator.sendBeacon(url, payload);")).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -554,7 +554,13 @@ export const endpointArgument = (
|
|||||||
receiverFact?: JavaScriptOpenReceiverFact,
|
receiverFact?: JavaScriptOpenReceiverFact,
|
||||||
): string | undefined => {
|
): string | undefined => {
|
||||||
if (receiverFact === "window") return undefined;
|
if (receiverFact === "window") return undefined;
|
||||||
if (name === "fetch" || name.endsWith(".fetch") || name === "WebSocket")
|
if (
|
||||||
|
name === "fetch" ||
|
||||||
|
name.endsWith(".fetch") ||
|
||||||
|
name === "WebSocket" ||
|
||||||
|
name === "EventSource" ||
|
||||||
|
name.endsWith(".EventSource")
|
||||||
|
)
|
||||||
return stringValue(args[0]);
|
return stringValue(args[0]);
|
||||||
if (name.endsWith(".open"))
|
if (name.endsWith(".open"))
|
||||||
return xhrOpenUrl(name, args[0], args[1], receiverFact);
|
return xhrOpenUrl(name, args[0], args[1], receiverFact);
|
||||||
@@ -574,6 +580,9 @@ export const endpointArgument = (
|
|||||||
? undefined
|
? undefined
|
||||||
: value;
|
: value;
|
||||||
}
|
}
|
||||||
|
// navigator.sendBeacon(url, data) queues a POST to its first argument.
|
||||||
|
if (name === "sendBeacon" || name.endsWith(".sendBeacon"))
|
||||||
|
return stringValue(args[0]);
|
||||||
if (name.endsWith("loadURL")) return stringValue(args[0]);
|
if (name.endsWith("loadURL")) return stringValue(args[0]);
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,24 +1,51 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
const diagnostics = z.array(z.string().min(1)).min(1);
|
const diagnostics = z.array(z.string().min(1)).min(1).exactOptional();
|
||||||
const completeCoverage = z.strictObject({ status: z.literal("complete") });
|
const completeCoverage = z.strictObject({
|
||||||
|
status: z.literal("complete"),
|
||||||
|
diagnostics,
|
||||||
|
});
|
||||||
|
const limitedDirections = z.union([
|
||||||
|
z.tuple([z.literal("callers")]).check(z.minLength(1), z.maxLength(1)),
|
||||||
|
z.tuple([z.literal("callees")]).check(z.minLength(1), z.maxLength(1)),
|
||||||
|
z
|
||||||
|
.tuple([z.literal("callers"), z.literal("callees")])
|
||||||
|
.check(z.minLength(2), z.maxLength(2)),
|
||||||
|
]);
|
||||||
const partialCoverage = z.strictObject({
|
const partialCoverage = z.strictObject({
|
||||||
status: z.literal("partial"),
|
status: z.literal("partial"),
|
||||||
limitations: z.array(z.string().min(1)).min(1),
|
limitations: z.array(z.string().min(1)).min(1),
|
||||||
|
limited_directions: limitedDirections.exactOptional(),
|
||||||
|
diagnostics,
|
||||||
});
|
});
|
||||||
const unknownCoverage = z.strictObject({
|
const unknownCoverage = z.strictObject({
|
||||||
status: z.literal("unknown"),
|
status: z.literal("unknown"),
|
||||||
reason: z.string().min(1),
|
reason: z.string().min(1),
|
||||||
|
limited_directions: limitedDirections.exactOptional(),
|
||||||
|
diagnostics,
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Explicit coverage state for a provider's observed caller/callee set. */
|
/** Explicit coverage state for a provider's observed caller/callee set. */
|
||||||
export const relationshipCoverageSchema = z.union([
|
export const relationshipCoverageSchema = z.discriminatedUnion("status", [
|
||||||
completeCoverage,
|
completeCoverage,
|
||||||
completeCoverage.extend({ diagnostics }),
|
|
||||||
partialCoverage,
|
partialCoverage,
|
||||||
partialCoverage.extend({ diagnostics }),
|
|
||||||
unknownCoverage,
|
unknownCoverage,
|
||||||
unknownCoverage.extend({ diagnostics }),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export type RelationshipCoverage = z.infer<typeof relationshipCoverageSchema>;
|
export type RelationshipCoverage = z.infer<typeof relationshipCoverageSchema>;
|
||||||
|
|
||||||
|
/** Reasons the observed relationship inventory cannot establish completeness. */
|
||||||
|
export const relationshipCoverageLimitations = (
|
||||||
|
coverage: RelationshipCoverage | null | undefined,
|
||||||
|
): readonly string[] => {
|
||||||
|
switch (coverage?.status) {
|
||||||
|
case undefined:
|
||||||
|
return ["Provider did not report relationship coverage."];
|
||||||
|
case "complete":
|
||||||
|
return [];
|
||||||
|
case "partial":
|
||||||
|
return coverage.limitations;
|
||||||
|
case "unknown":
|
||||||
|
return [coverage.reason];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ import {
|
|||||||
NATIVE_AOT_PROFILE_CONTRACT_REVISION,
|
NATIVE_AOT_PROFILE_CONTRACT_REVISION,
|
||||||
} from "../domain/native/nativeAotPe.js";
|
} from "../domain/native/nativeAotPe.js";
|
||||||
|
|
||||||
|
const callRelationshipCoverage = "function-body-call-coverage-v5";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The processor language REA pins for this target, or undefined when Ghidra may
|
* The processor language REA pins for this target, or undefined when Ghidra may
|
||||||
* select from the header. The committed profile and the session readback both
|
* select from the header. The committed profile and the session readback both
|
||||||
@@ -125,7 +127,7 @@ export const resolveGhidraAnalysisProfile = async (
|
|||||||
load_image_observations: "source-mappings-entry-context-v2",
|
load_image_observations: "source-mappings-entry-context-v2",
|
||||||
function_body_evidence: "complete-inclusive-ranges-v1",
|
function_body_evidence: "complete-inclusive-ranges-v1",
|
||||||
function_references: "complete-body-and-entry-reference-manager-v2",
|
function_references: "complete-body-and-entry-reference-manager-v2",
|
||||||
call_relationship_coverage: "resolved-call-reference-diagnostics-v1",
|
call_relationship_coverage: callRelationshipCoverage,
|
||||||
function_dossier_coverage:
|
function_dossier_coverage:
|
||||||
"observed-facets-and-call-relationships-v1",
|
"observed-facets-and-call-relationships-v1",
|
||||||
string_inventory_evidence: "defined-data-coverage-v1",
|
string_inventory_evidence: "defined-data-coverage-v1",
|
||||||
@@ -222,7 +224,7 @@ export const resolveGhidraAnalysisProfile = async (
|
|||||||
load_image_observations: "source-mappings-entry-context-v2",
|
load_image_observations: "source-mappings-entry-context-v2",
|
||||||
function_body_evidence: "complete-inclusive-ranges-v1",
|
function_body_evidence: "complete-inclusive-ranges-v1",
|
||||||
function_references: "complete-body-and-entry-reference-manager-v2",
|
function_references: "complete-body-and-entry-reference-manager-v2",
|
||||||
call_relationship_coverage: "resolved-call-reference-diagnostics-v1",
|
call_relationship_coverage: callRelationshipCoverage,
|
||||||
function_dossier_coverage: "observed-facets-and-call-relationships-v1",
|
function_dossier_coverage: "observed-facets-and-call-relationships-v1",
|
||||||
string_inventory_evidence: "defined-data-coverage-v1",
|
string_inventory_evidence: "defined-data-coverage-v1",
|
||||||
location_resolution: "explicit-address-exact-entry-symbol-first-v3",
|
location_resolution: "explicit-address-exact-entry-symbol-first-v3",
|
||||||
|
|||||||
@@ -43,7 +43,120 @@ const parseFunctionValueFixture = (
|
|||||||
return parsed.ok ? { ok: true as const, value: parsed.value.value } : parsed;
|
return parsed.ok ? { ok: true as const, value: parsed.value.value } : parsed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
describe("Ghidra unresolved call locations", () => {
|
||||||
|
it("rejects a noncanonical unresolved call site rather than retaining unverifiable location evidence", () => {
|
||||||
|
expect(
|
||||||
|
parseGhidraFunctionResult("analyze_function", {
|
||||||
|
value: {
|
||||||
|
...functionDossierSchema.parse(ghidraFunctionDossier()),
|
||||||
|
unresolved_calls: [
|
||||||
|
{ address: "not-an-address", reason: "No call destination." },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
limitations: [],
|
||||||
|
relationship_coverage: {
|
||||||
|
status: "partial",
|
||||||
|
limitations: ["An unresolved call remains."],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).toMatchObject({ ok: false, error: { _tag: "AnalysisOutputError" } });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("Ghidra function-analysis result values", () => {
|
describe("Ghidra function-analysis result values", () => {
|
||||||
|
it("retains unavailable pseudocode instead of treating its empty representation as observed source", () => {
|
||||||
|
const availability = {
|
||||||
|
pseudocode: {
|
||||||
|
available: false,
|
||||||
|
reason: "Ghidra does not decompile external functions.",
|
||||||
|
},
|
||||||
|
comments: { available: true },
|
||||||
|
};
|
||||||
|
const parsed = parseGhidraFunctionResult("analyze_function", {
|
||||||
|
value: {
|
||||||
|
...functionDossierSchema.parse(ghidraFunctionDossier()),
|
||||||
|
pseudocode: "",
|
||||||
|
facet_availability: availability,
|
||||||
|
},
|
||||||
|
limitations: [],
|
||||||
|
});
|
||||||
|
expect(parsed).toMatchObject({
|
||||||
|
ok: true,
|
||||||
|
value: { value: { pseudocode: "", facet_availability: availability } },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it.each([
|
||||||
|
{ status: "complete", diagnostics: ["Resolved static references only."] },
|
||||||
|
{
|
||||||
|
status: "partial",
|
||||||
|
limitations: ["Only the first instruction range was examined."],
|
||||||
|
},
|
||||||
|
{ status: "unknown", reason: "Relationship inventory was unavailable." },
|
||||||
|
{
|
||||||
|
status: "partial",
|
||||||
|
limitations: ["Missing callers."],
|
||||||
|
limited_directions: ["callers"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: "unknown",
|
||||||
|
reason: "Missing callees.",
|
||||||
|
limited_directions: ["callees"],
|
||||||
|
},
|
||||||
|
])("preserves observed $status relationship coverage", (coverage) => {
|
||||||
|
const parsed = parseGhidraFunctionResult("analyze_function", {
|
||||||
|
value: ghidraFunctionDossier(),
|
||||||
|
limitations: [],
|
||||||
|
relationship_coverage: coverage,
|
||||||
|
});
|
||||||
|
expect(parsed).toMatchObject({
|
||||||
|
ok: true,
|
||||||
|
value: { relationshipCoverage: coverage },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves omitted relationship coverage for legacy observations", () => {
|
||||||
|
const parsed = parseGhidraFunctionResult("analyze_function", {
|
||||||
|
value: ghidraFunctionDossier(),
|
||||||
|
limitations: [],
|
||||||
|
});
|
||||||
|
if (!parsed.ok) throw parsed.error;
|
||||||
|
expect(parsed.value).not.toHaveProperty("relationshipCoverage");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Ghidra relationship metadata validation", () => {
|
||||||
|
it.each([
|
||||||
|
{ status: "partial", limitations: [] },
|
||||||
|
{ status: "unknown", reason: "" },
|
||||||
|
{ status: "complete", limitations: ["Truncated."] },
|
||||||
|
{ status: "partial", limitations: ["Truncated."], limited_directions: [] },
|
||||||
|
{
|
||||||
|
status: "partial",
|
||||||
|
limitations: ["Truncated."],
|
||||||
|
limited_directions: ["callers", "callers"],
|
||||||
|
},
|
||||||
|
{ status: "unknown", reason: "Missing.", limited_directions: ["incoming"] },
|
||||||
|
{ status: "complete", limited_directions: ["callers"] },
|
||||||
|
])("rejects malformed relationship coverage %j", (coverage) => {
|
||||||
|
expect(
|
||||||
|
parseGhidraFunctionResult("analyze_function", {
|
||||||
|
value: ghidraFunctionDossier(),
|
||||||
|
limitations: [],
|
||||||
|
relationship_coverage: coverage,
|
||||||
|
}),
|
||||||
|
).toMatchObject({ ok: false, error: { _tag: "AnalysisOutputError" } });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rejects relationship metadata on unrelated function operations", () => {
|
||||||
|
expect(
|
||||||
|
parseGhidraFunctionResult("procedure_assembly", {
|
||||||
|
value: "ret",
|
||||||
|
limitations: [],
|
||||||
|
relationship_coverage: { status: "complete" },
|
||||||
|
}),
|
||||||
|
).toMatchObject({ ok: false, error: { _tag: "AnalysisOutputError" } });
|
||||||
|
});
|
||||||
|
|
||||||
it("preserves file-offset resolution in Evidence locations and rejects inexact offsets", () => {
|
it("preserves file-offset resolution in Evidence locations and rejects inexact offsets", () => {
|
||||||
const selection = {
|
const selection = {
|
||||||
file_offset: 0x210,
|
file_offset: 0x210,
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ import {
|
|||||||
import { nativeApiBoundarySchema } from "../domain/native/nativeApiBoundary.js";
|
import { nativeApiBoundarySchema } from "../domain/native/nativeApiBoundary.js";
|
||||||
import { nativeValueFlowSchema } from "../domain/native/nativeValueFlow.js";
|
import { nativeValueFlowSchema } from "../domain/native/nativeValueFlow.js";
|
||||||
import type { EvidenceLocation } from "../domain/evidence.js";
|
import type { EvidenceLocation } from "../domain/evidence.js";
|
||||||
|
import {
|
||||||
|
relationshipCoverageSchema,
|
||||||
|
type RelationshipCoverage,
|
||||||
|
} from "../domain/relationshipCoverage.js";
|
||||||
import { err, ok, type Result } from "../domain/result.js";
|
import { err, ok, type Result } from "../domain/result.js";
|
||||||
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
||||||
import {
|
import {
|
||||||
@@ -307,6 +311,7 @@ const ghidraFunctionDossier = functionDossierSchema
|
|||||||
...value.comments.map(({ address }) => address),
|
...value.comments.map(({ address }) => address),
|
||||||
...value.callers.map(({ address }) => address),
|
...value.callers.map(({ address }) => address),
|
||||||
...value.callees.map(({ address }) => address),
|
...value.callees.map(({ address }) => address),
|
||||||
|
...(value.unresolved_calls ?? []).map(({ address }) => address),
|
||||||
...value.incoming_references.flatMap(referenceAddresses),
|
...value.incoming_references.flatMap(referenceAddresses),
|
||||||
...value.outgoing_references.flatMap(referenceAddresses),
|
...value.outgoing_references.flatMap(referenceAddresses),
|
||||||
...value.referenced_strings.flatMap(({ address, source_address }) => [
|
...value.referenced_strings.flatMap(({ address, source_address }) => [
|
||||||
@@ -419,6 +424,7 @@ const functionBoundaryObservationOperations: ReadonlySet<GhidraFunctionOperation
|
|||||||
const functionObservationEnvelope = z.strictObject({
|
const functionObservationEnvelope = z.strictObject({
|
||||||
value: z.unknown(),
|
value: z.unknown(),
|
||||||
limitations: z.array(z.string()),
|
limitations: z.array(z.string()),
|
||||||
|
relationship_coverage: relationshipCoverageSchema.exactOptional(),
|
||||||
selection: z
|
selection: z
|
||||||
.strictObject({
|
.strictObject({
|
||||||
file_offset: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
file_offset: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
||||||
@@ -432,6 +438,7 @@ export interface ParsedGhidraFunctionResult {
|
|||||||
readonly value: JsonValue;
|
readonly value: JsonValue;
|
||||||
readonly limitations: readonly string[];
|
readonly limitations: readonly string[];
|
||||||
readonly locations?: readonly EvidenceLocation[];
|
readonly locations?: readonly EvidenceLocation[];
|
||||||
|
readonly relationshipCoverage?: RelationshipCoverage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Require exact, bounded Java-bridge function output before creating Evidence. */
|
/** Require exact, bounded Java-bridge function output before creating Evidence. */
|
||||||
@@ -442,6 +449,7 @@ export const parseGhidraFunctionResult = (
|
|||||||
let observation: {
|
let observation: {
|
||||||
readonly value: unknown;
|
readonly value: unknown;
|
||||||
readonly limitations: readonly string[];
|
readonly limitations: readonly string[];
|
||||||
|
readonly relationship_coverage?: RelationshipCoverage;
|
||||||
readonly selection?: z.infer<
|
readonly selection?: z.infer<
|
||||||
typeof functionObservationEnvelope
|
typeof functionObservationEnvelope
|
||||||
>["selection"];
|
>["selection"];
|
||||||
@@ -450,13 +458,17 @@ export const parseGhidraFunctionResult = (
|
|||||||
const envelope = functionObservationEnvelope.safeParse(value);
|
const envelope = functionObservationEnvelope.safeParse(value);
|
||||||
if (
|
if (
|
||||||
!envelope.success ||
|
!envelope.success ||
|
||||||
|
(operation !== "analyze_function" &&
|
||||||
|
operation !== "procedure_callers" &&
|
||||||
|
operation !== "procedure_callees" &&
|
||||||
|
envelope.data.relationship_coverage !== undefined) ||
|
||||||
(operation !== "procedure_pseudo_code" &&
|
(operation !== "procedure_pseudo_code" &&
|
||||||
envelope.data.selection !== undefined)
|
envelope.data.selection !== undefined)
|
||||||
)
|
)
|
||||||
return err(
|
return err(
|
||||||
new AnalysisOutputError(
|
new AnalysisOutputError(
|
||||||
operation,
|
operation,
|
||||||
"Ghidra bridge omitted the function observation envelope",
|
"Ghidra bridge returned an invalid function observation envelope for this operation",
|
||||||
envelope.success ? undefined : { cause: envelope.error },
|
envelope.success ? undefined : { cause: envelope.error },
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -469,6 +481,9 @@ export const parseGhidraFunctionResult = (
|
|||||||
? ok({
|
? ok({
|
||||||
value: jsonValueSchema.parse(parsed.data),
|
value: jsonValueSchema.parse(parsed.data),
|
||||||
limitations: observation.limitations,
|
limitations: observation.limitations,
|
||||||
|
...(observation.relationship_coverage === undefined
|
||||||
|
? {}
|
||||||
|
: { relationshipCoverage: observation.relationship_coverage }),
|
||||||
...(observation.selection === undefined
|
...(observation.selection === undefined
|
||||||
? {}
|
? {}
|
||||||
: {
|
: {
|
||||||
|
|||||||
@@ -633,7 +633,7 @@ describe("Ghidra client projection", () => {
|
|||||||
expect(resolved.value.profile.parameters).toMatchObject({
|
expect(resolved.value.profile.parameters).toMatchObject({
|
||||||
language_id: "auto-from-header",
|
language_id: "auto-from-header",
|
||||||
compiler_spec_id: "auto-default",
|
compiler_spec_id: "auto-default",
|
||||||
call_relationship_coverage: "resolved-call-reference-diagnostics-v1",
|
call_relationship_coverage: "function-body-call-coverage-v5",
|
||||||
function_dossier_coverage: "observed-facets-and-call-relationships-v1",
|
function_dossier_coverage: "observed-facets-and-call-relationships-v1",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -870,7 +870,16 @@ describe("Ghidra relationship coverage", () => {
|
|||||||
Promise.resolve(
|
Promise.resolve(
|
||||||
ok(
|
ok(
|
||||||
operation === "procedure_callees"
|
operation === "procedure_callees"
|
||||||
? { value: ["0x2000"], limitations: [] }
|
? {
|
||||||
|
value: ["0x2000"],
|
||||||
|
limitations: [],
|
||||||
|
relationship_coverage: {
|
||||||
|
status: "complete",
|
||||||
|
diagnostics: [
|
||||||
|
"Only resolved Ghidra call references are returned; unresolved computed or indirect calls remain unknown, while function classifications distinguish thunks and externals.",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
: { value: [], limitations: [] },
|
: { value: [], limitations: [] },
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import type {
|
|||||||
CapabilityDescriptor,
|
CapabilityDescriptor,
|
||||||
ProviderIdentity,
|
ProviderIdentity,
|
||||||
} from "../application/AnalysisProvider.js";
|
} from "../application/AnalysisProvider.js";
|
||||||
import type { RelationshipCoverage } from "../domain/relationshipCoverage.js";
|
|
||||||
import {
|
import {
|
||||||
hasWindowsNativeAuthority,
|
hasWindowsNativeAuthority,
|
||||||
windowsNativeAuthorityUnavailableReason,
|
windowsNativeAuthorityUnavailableReason,
|
||||||
@@ -44,22 +43,6 @@ const stringInventoryLimitation =
|
|||||||
const searchLimitation =
|
const searchLimitation =
|
||||||
"Regex mode uses Java Pattern semantics. Matcher or compiler stack exhaustion returns a resource constraint without closing the session; literal mode avoids regex recursion and returns complete matching values.";
|
"Regex mode uses Java Pattern semantics. Matcher or compiler stack exhaustion returns a resource constraint without closing the session; literal mode avoids regex recursion and returns complete matching values.";
|
||||||
|
|
||||||
const resolvedCallReferenceLimitation =
|
|
||||||
"Only resolved Ghidra call references are returned; unresolved computed or indirect calls remain unknown, while function classifications distinguish thunks and externals.";
|
|
||||||
|
|
||||||
/** Relationship-only caveats belong to each observed caller/callee result. */
|
|
||||||
export const relationshipCoverageFor = (
|
|
||||||
operation: string,
|
|
||||||
): RelationshipCoverage | undefined =>
|
|
||||||
operation === "procedure_callers" ||
|
|
||||||
operation === "procedure_callees" ||
|
|
||||||
operation === "analyze_function"
|
|
||||||
? {
|
|
||||||
status: "complete",
|
|
||||||
diagnostics: [resolvedCallReferenceLimitation],
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
/** Limitation text for one admitted operation, including the common base. */
|
/** Limitation text for one admitted operation, including the common base. */
|
||||||
export const limitationsFor = (operation: string): readonly string[] => {
|
export const limitationsFor = (operation: string): readonly string[] => {
|
||||||
const common = [
|
const common = [
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import {
|
|||||||
} from "../domain/analysisErrorCore.js";
|
} from "../domain/analysisErrorCore.js";
|
||||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||||
import type { EvidenceLocation } from "../domain/evidence.js";
|
import type { EvidenceLocation } from "../domain/evidence.js";
|
||||||
|
import type { RelationshipCoverage } from "../domain/relationshipCoverage.js";
|
||||||
import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
|
import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
|
||||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||||
import { err, ok, type Result } from "../domain/result.js";
|
import { err, ok, type Result } from "../domain/result.js";
|
||||||
@@ -86,7 +87,6 @@ import {
|
|||||||
healthLimitations,
|
healthLimitations,
|
||||||
windowsP0Limitations,
|
windowsP0Limitations,
|
||||||
limitationsFor,
|
limitationsFor,
|
||||||
relationshipCoverageFor,
|
|
||||||
} from "./GhidraProviderCapabilities.js";
|
} from "./GhidraProviderCapabilities.js";
|
||||||
import type { GhidraSessionError } from "./GhidraSessionError.js";
|
import type { GhidraSessionError } from "./GhidraSessionError.js";
|
||||||
import {
|
import {
|
||||||
@@ -733,8 +733,8 @@ export const createGhidraProviderClient = (input: {
|
|||||||
rawResult: JsonValue,
|
rawResult: JsonValue,
|
||||||
observationLimitations: readonly string[] = [],
|
observationLimitations: readonly string[] = [],
|
||||||
locations: readonly EvidenceLocation[] = [],
|
locations: readonly EvidenceLocation[] = [],
|
||||||
|
relationshipCoverage?: RelationshipCoverage,
|
||||||
) => {
|
) => {
|
||||||
const relationshipCoverage = relationshipCoverageFor(operation);
|
|
||||||
return createAnalysisExecution(normalized, committedProfile.provider, {
|
return createAnalysisExecution(normalized, committedProfile.provider, {
|
||||||
rawResult,
|
rawResult,
|
||||||
locations,
|
locations,
|
||||||
@@ -838,12 +838,14 @@ export const createGhidraProviderClient = (input: {
|
|||||||
let normalized: JsonValue;
|
let normalized: JsonValue;
|
||||||
let observationLimitations: readonly string[] = [];
|
let observationLimitations: readonly string[] = [];
|
||||||
let observationLocations: readonly EvidenceLocation[] = [];
|
let observationLocations: readonly EvidenceLocation[] = [];
|
||||||
|
let relationshipCoverage: RelationshipCoverage | undefined;
|
||||||
if (isGhidraFunctionOperation(operation)) {
|
if (isGhidraFunctionOperation(operation)) {
|
||||||
const result = parseGhidraFunctionResult(operation, called.value);
|
const result = parseGhidraFunctionResult(operation, called.value);
|
||||||
if (!result.ok) return result;
|
if (!result.ok) return result;
|
||||||
normalized = result.value.value;
|
normalized = result.value.value;
|
||||||
observationLimitations = result.value.limitations;
|
observationLimitations = result.value.limitations;
|
||||||
observationLocations = result.value.locations ?? [];
|
observationLocations = result.value.locations ?? [];
|
||||||
|
relationshipCoverage = result.value.relationshipCoverage;
|
||||||
} else {
|
} else {
|
||||||
const result = parseGhidraInventoryResult(operation, called.value);
|
const result = parseGhidraInventoryResult(operation, called.value);
|
||||||
if (!result.ok) return result;
|
if (!result.ok) return result;
|
||||||
@@ -939,6 +941,7 @@ export const createGhidraProviderClient = (input: {
|
|||||||
called.value,
|
called.value,
|
||||||
observationLimitations,
|
observationLimitations,
|
||||||
observationLocations,
|
observationLocations,
|
||||||
|
relationshipCoverage,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { silentLogger } from "../logger.js";
|
|||||||
import { GhidraProvider } from "./GhidraProvider.js";
|
import { GhidraProvider } from "./GhidraProvider.js";
|
||||||
import { GhidraSessionError } from "./GhidraSessionError.js";
|
import { GhidraSessionError } from "./GhidraSessionError.js";
|
||||||
import { GHIDRA_SESSION_CAPABILITIES } from "./GhidraSessionValues.js";
|
import { GHIDRA_SESSION_CAPABILITIES } from "./GhidraSessionValues.js";
|
||||||
|
import type { RelationshipCoverage } from "../domain/relationshipCoverage.js";
|
||||||
|
|
||||||
const TARGET: BinaryTarget = {
|
const TARGET: BinaryTarget = {
|
||||||
path: "/tmp/ghidra-cache-fixture",
|
path: "/tmp/ghidra-cache-fixture",
|
||||||
@@ -23,7 +24,7 @@ const TARGET: BinaryTarget = {
|
|||||||
|
|
||||||
// Exercise the real provider descriptors, profile, input/output projection and
|
// Exercise the real provider descriptors, profile, input/output projection and
|
||||||
// session cache; only the installed Ghidra process is replaced at its seam.
|
// session cache; only the installed Ghidra process is replaced at its seam.
|
||||||
const fixture = (version = "12.1.4") => {
|
const fixture = (version = "12.1.4", coverage?: RelationshipCoverage) => {
|
||||||
const config = parseConfig({ GHIDRA_INSTALL_DIR: "/opt/ghidra" });
|
const config = parseConfig({ GHIDRA_INSTALL_DIR: "/opt/ghidra" });
|
||||||
if (!config.ok) throw config.error;
|
if (!config.ok) throw config.error;
|
||||||
const calls: string[] = [];
|
const calls: string[] = [];
|
||||||
@@ -113,7 +114,13 @@ const fixture = (version = "12.1.4") => {
|
|||||||
return ok(
|
return ok(
|
||||||
operation === "procedure_pseudo_code" ||
|
operation === "procedure_pseudo_code" ||
|
||||||
operation === "analyze_function"
|
operation === "analyze_function"
|
||||||
? { value, limitations: [] }
|
? {
|
||||||
|
value,
|
||||||
|
limitations: [],
|
||||||
|
...(operation === "analyze_function" && coverage !== undefined
|
||||||
|
? { relationship_coverage: coverage }
|
||||||
|
: {}),
|
||||||
|
}
|
||||||
: value,
|
: value,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -133,42 +140,119 @@ const open = async (session: ReturnType<typeof fixture>["session"]) => {
|
|||||||
expect((await session.openResolvedTarget(preview.value)).ok).toBe(true);
|
expect((await session.openResolvedTarget(preview.value)).ok).toBe(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("Ghidra snapshot cache", () => {
|
describe("Ghidra relationship coverage replay", () => {
|
||||||
it("refuses snapshots whose profile predates typed incoming references", async () => {
|
it.each([
|
||||||
const initial = fixture();
|
undefined,
|
||||||
await open(initial.session);
|
{ status: "complete", diagnostics: ["Resolved static references only."] },
|
||||||
const snapshot = initial.session.exportAnalysisSnapshot();
|
{ status: "partial", limitations: ["Instruction coverage was truncated."] },
|
||||||
if (!snapshot.ok) throw snapshot.error;
|
{ status: "unknown", reason: "Relationship inventory was unavailable." },
|
||||||
await initial.session.close();
|
{
|
||||||
const profile = snapshot.value.binding.analysis_profile;
|
status: "partial",
|
||||||
expect(profile.parameters.instruction_references).toBe(
|
limitations: ["Missing callers."],
|
||||||
"exact-address-incoming-v1",
|
limited_directions: ["callers"],
|
||||||
);
|
},
|
||||||
const legacy = {
|
] satisfies (RelationshipCoverage | undefined)[])(
|
||||||
...snapshot.value,
|
"preserves relationship coverage %j through live execution, cache and snapshot replay",
|
||||||
binding: {
|
async (coverage) => {
|
||||||
...snapshot.value.binding,
|
const initial = fixture("12.1.4", coverage);
|
||||||
analysis_profile: createAnalysisProfile(
|
await open(initial.session);
|
||||||
profile.provider,
|
const parameters = { procedure: "0x1000" };
|
||||||
Object.fromEntries(
|
for (let i = 0; i < 2; i++) {
|
||||||
Object.entries(profile.parameters).filter(
|
const execution = await initial.session.execute(
|
||||||
([key]) => key !== "instruction_references",
|
"analyze_function",
|
||||||
),
|
parameters,
|
||||||
),
|
);
|
||||||
),
|
if (!execution.ok) throw execution.error;
|
||||||
},
|
expect(execution.value.relationshipCoverage).toEqual(coverage);
|
||||||
};
|
}
|
||||||
const replay = fixture();
|
expect(initial.calls).toEqual(["analyze_function"]);
|
||||||
const imported = replay.session.importAnalysisSnapshot(legacy);
|
const snapshot = initial.session.exportAnalysisSnapshot();
|
||||||
if (!imported.ok) throw imported.error;
|
if (!snapshot.ok) throw snapshot.error;
|
||||||
expect(await replay.session.previewTarget(TARGET)).toMatchObject({
|
await initial.session.close();
|
||||||
ok: false,
|
const replay = fixture();
|
||||||
error: { _tag: "EvidenceIntegrityError" },
|
expect(replay.session.importAnalysisSnapshot(snapshot.value).ok).toBe(
|
||||||
});
|
true,
|
||||||
expect(replay.calls).toEqual([]);
|
);
|
||||||
await replay.session.close();
|
await open(replay.session);
|
||||||
});
|
const execution = await replay.session.execute(
|
||||||
|
"analyze_function",
|
||||||
|
parameters,
|
||||||
|
);
|
||||||
|
if (!execution.ok) throw execution.error;
|
||||||
|
expect(execution.value.relationshipCoverage ?? undefined).toEqual(
|
||||||
|
coverage,
|
||||||
|
);
|
||||||
|
expect(replay.calls).toEqual([]);
|
||||||
|
await replay.session.close();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Ghidra snapshot profile admission", () => {
|
||||||
|
it.each([
|
||||||
|
{
|
||||||
|
parameter: "instruction_references",
|
||||||
|
current: "exact-address-incoming-v1",
|
||||||
|
legacy: undefined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parameter: "call_relationship_coverage",
|
||||||
|
current: "function-body-call-coverage-v5",
|
||||||
|
legacy: "resolved-call-reference-diagnostics-v1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parameter: "call_relationship_coverage",
|
||||||
|
current: "function-body-call-coverage-v5",
|
||||||
|
legacy: "decoded-call-target-coverage-v2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parameter: "call_relationship_coverage",
|
||||||
|
current: "function-body-call-coverage-v5",
|
||||||
|
legacy: "decoded-call-target-coverage-v3",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parameter: "call_relationship_coverage",
|
||||||
|
current: "function-body-call-coverage-v5",
|
||||||
|
legacy: "function-body-call-coverage-v4",
|
||||||
|
},
|
||||||
|
])(
|
||||||
|
"refuses snapshots with outdated $parameter semantics",
|
||||||
|
async ({ parameter, current, legacy: prior }) => {
|
||||||
|
const initial = fixture();
|
||||||
|
await open(initial.session);
|
||||||
|
const snapshot = initial.session.exportAnalysisSnapshot();
|
||||||
|
if (!snapshot.ok) throw snapshot.error;
|
||||||
|
await initial.session.close();
|
||||||
|
const profile = snapshot.value.binding.analysis_profile;
|
||||||
|
expect(profile.parameters[parameter]).toBe(current);
|
||||||
|
const legacy = {
|
||||||
|
...snapshot.value,
|
||||||
|
binding: {
|
||||||
|
...snapshot.value.binding,
|
||||||
|
analysis_profile: createAnalysisProfile(profile.provider, {
|
||||||
|
...Object.fromEntries(
|
||||||
|
Object.entries(profile.parameters).filter(
|
||||||
|
([key]) => key !== parameter,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
...(prior === undefined ? {} : { [parameter]: prior }),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const replay = fixture();
|
||||||
|
const imported = replay.session.importAnalysisSnapshot(legacy);
|
||||||
|
if (!imported.ok) throw imported.error;
|
||||||
|
expect(await replay.session.previewTarget(TARGET)).toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
error: { _tag: "EvidenceIntegrityError" },
|
||||||
|
});
|
||||||
|
expect(replay.calls).toEqual([]);
|
||||||
|
await replay.session.close();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Ghidra snapshot cache", () => {
|
||||||
it.each([
|
it.each([
|
||||||
{ operation: "analyze_function", parameters: { procedure: "0x1000" } },
|
{ operation: "analyze_function", parameters: { procedure: "0x1000" } },
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,6 +16,15 @@ import { registerEvidenceTools } from "./registerEvidenceTools.js";
|
|||||||
import { runManagedProviderExecution } from "../composition/directAnalysis.js";
|
import { runManagedProviderExecution } from "../composition/directAnalysis.js";
|
||||||
import { isManagedToolName } from "../contracts/managed/managedToolContracts.js";
|
import { isManagedToolName } from "../contracts/managed/managedToolContracts.js";
|
||||||
|
|
||||||
|
/** Operations whose caller may select a retained summary instead of complete delivery. */
|
||||||
|
const summarizesRetainedEvidence = (
|
||||||
|
operation: string,
|
||||||
|
parameters: Readonly<Record<string, unknown>>,
|
||||||
|
): boolean =>
|
||||||
|
(operation === "inspect_managed_artifact" ||
|
||||||
|
operation === "inspect_managed_members") &&
|
||||||
|
parameters.detail === "summary";
|
||||||
|
|
||||||
/** Register execution-free managed PE/CLI inspection. */
|
/** Register execution-free managed PE/CLI inspection. */
|
||||||
export const registerManagedTools = (
|
export const registerManagedTools = (
|
||||||
server: EvidenceMcpServer,
|
server: EvidenceMcpServer,
|
||||||
@@ -34,11 +43,8 @@ export const registerManagedTools = (
|
|||||||
execute: async (operation, parameters, executionOptions) => {
|
execute: async (operation, parameters, executionOptions) => {
|
||||||
if (!isManagedToolName(operation))
|
if (!isManagedToolName(operation))
|
||||||
return analysis.execute(operation, parameters, executionOptions);
|
return analysis.execute(operation, parameters, executionOptions);
|
||||||
const { detail: _detail, ...artifactParameters } = parameters;
|
const { detail: _detail, ...providerParameters } = parameters;
|
||||||
if (
|
if (summarizesRetainedEvidence(operation, parameters)) {
|
||||||
operation === "inspect_managed_artifact" &&
|
|
||||||
parameters.detail === "summary"
|
|
||||||
) {
|
|
||||||
const ready = requireAnalysisViewRetention(operation, {
|
const ready = requireAnalysisViewRetention(operation, {
|
||||||
recordEvidence: options.recordEvidence,
|
recordEvidence: options.recordEvidence,
|
||||||
evidenceById: options.evidenceById,
|
evidenceById: options.evidenceById,
|
||||||
@@ -69,9 +75,7 @@ export const registerManagedTools = (
|
|||||||
path,
|
path,
|
||||||
operation,
|
operation,
|
||||||
executionOptions?.signal,
|
executionOptions?.signal,
|
||||||
operation === "inspect_managed_artifact"
|
providerParameters,
|
||||||
? artifactParameters
|
|
||||||
: parameters,
|
|
||||||
);
|
);
|
||||||
if (execution.ok && typeof requestedPath === "string")
|
if (execution.ok && typeof requestedPath === "string")
|
||||||
selectedManagedPath = requestedPath;
|
selectedManagedPath = requestedPath;
|
||||||
@@ -82,8 +86,7 @@ export const registerManagedTools = (
|
|||||||
...options,
|
...options,
|
||||||
analysisForAdmission,
|
analysisForAdmission,
|
||||||
projectEvidence: (operation, parameters, evidence) =>
|
projectEvidence: (operation, parameters, evidence) =>
|
||||||
operation === "inspect_managed_artifact" &&
|
summarizesRetainedEvidence(operation, parameters)
|
||||||
parameters.detail === "summary"
|
|
||||||
? summarizeRetainedAnalysis(evidence, {
|
? summarizeRetainedAnalysis(evidence, {
|
||||||
recordEvidence: options.recordEvidence,
|
recordEvidence: options.recordEvidence,
|
||||||
evidenceById: options.evidenceById,
|
evidenceById: options.evidenceById,
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ describe("client configuration filesystem lifecycle", () => {
|
|||||||
"kimi",
|
"kimi",
|
||||||
"vscode",
|
"vscode",
|
||||||
"trae",
|
"trae",
|
||||||
|
"workbuddy",
|
||||||
"grok_build",
|
"grok_build",
|
||||||
"omp",
|
"omp",
|
||||||
"pi",
|
"pi",
|
||||||
|
|||||||
@@ -0,0 +1,159 @@
|
|||||||
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||||
|
import { join } from "node:path";
|
||||||
|
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
|
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
|
||||||
|
import { npxRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
|
||||||
|
import { configureClientConfiguration } from "../../../src/application/SetupClientConfiguration.js";
|
||||||
|
import { skillDestinations } from "../../../src/application/SetupSkill.js";
|
||||||
|
import { supportedClients } from "../../../src/application/SupportedClients.js";
|
||||||
|
import { systemUninstallHost } from "../../../src/application/Uninstall.js";
|
||||||
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||||
|
import { clearClientLocationEnvironment } from "../../fixtures/clientEnvironment.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The registration command setup writes on the host running the tests. Windows
|
||||||
|
* wraps it in `cmd.exe /d /c`, so the expected entry follows the host too.
|
||||||
|
*/
|
||||||
|
const command = npxRegistrationCommand(process.platform);
|
||||||
|
|
||||||
|
beforeEach(clearClientLocationEnvironment);
|
||||||
|
afterEach(() => vi.unstubAllEnvs());
|
||||||
|
|
||||||
|
const workbuddyPath = (
|
||||||
|
home: string,
|
||||||
|
platform: NodeJS.Platform = process.platform,
|
||||||
|
env: Parameters<typeof supportedClients>[2] = {},
|
||||||
|
) =>
|
||||||
|
supportedClients(home, platform, env).find(
|
||||||
|
({ name }) => name === "workbuddy",
|
||||||
|
);
|
||||||
|
|
||||||
|
describe("WorkBuddy configuration paths", () => {
|
||||||
|
it("resolves the global mcp.json under the home root", () => {
|
||||||
|
expect(workbuddyPath("/home/a")?.configPath).toBe(
|
||||||
|
join("/home/a", ".workbuddy", "mcp.json"),
|
||||||
|
);
|
||||||
|
expect(workbuddyPath("/Users/a")?.markerPath).toBe(
|
||||||
|
join("/Users/a", ".workbuddy"),
|
||||||
|
);
|
||||||
|
expect(workbuddyPath("C:\\Users\\a", "win32")?.configPath).toBe(
|
||||||
|
join("C:\\Users\\a", ".workbuddy", "mcp.json"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resolves the registration format as the plain mcpServers JSON dialect", () => {
|
||||||
|
expect(workbuddyPath("/home/a")?.format).toBe("json");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resolves the personal skills directory under the home root", () => {
|
||||||
|
expect(
|
||||||
|
skillDestinations("/home/a", ["workbuddy"]).map(({ path }) => path),
|
||||||
|
).toEqual([
|
||||||
|
join("/home/a", ".workbuddy", "skills", "reverse-engineer-anything"),
|
||||||
|
]);
|
||||||
|
expect(
|
||||||
|
skillDestinations("C:\\Users\\a", ["workbuddy"], {}, "win32").map(
|
||||||
|
({ path }) => path,
|
||||||
|
),
|
||||||
|
).toEqual([
|
||||||
|
join("C:\\Users\\a", ".workbuddy", "skills", "reverse-engineer-anything"),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("WorkBuddy JSON registration", () => {
|
||||||
|
const workbuddyClient = async () => {
|
||||||
|
const home = await createTestTempDirectory("rea-workbuddy-");
|
||||||
|
const client = workbuddyPath(home, process.platform);
|
||||||
|
if (client?.markerPath === undefined)
|
||||||
|
throw new Error("missing WorkBuddy client");
|
||||||
|
await mkdir(client.markerPath, { recursive: true });
|
||||||
|
return { home, client };
|
||||||
|
};
|
||||||
|
|
||||||
|
it("upserts rea into mcpServers while preserving unrelated settings", async () => {
|
||||||
|
const { home, client } = await workbuddyClient();
|
||||||
|
await writeFile(
|
||||||
|
client.configPath,
|
||||||
|
`{
|
||||||
|
"mcpServers": {
|
||||||
|
"other": { "command": "other-server" }
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
(await configureClientConfiguration(client, {}, command)).status,
|
||||||
|
).toBe("configured");
|
||||||
|
const parsed = JSON.parse(await readFile(client.configPath, "utf8"));
|
||||||
|
expect(parsed.mcpServers.other).toEqual({ command: "other-server" });
|
||||||
|
expect(parsed.mcpServers.rea).toEqual({
|
||||||
|
command: command[0],
|
||||||
|
args: command.slice(1),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
||||||
|
status: "unchanged",
|
||||||
|
});
|
||||||
|
expect(
|
||||||
|
(
|
||||||
|
await readClientRegistrationStatuses(home, undefined, {
|
||||||
|
platform: process.platform,
|
||||||
|
environment: {},
|
||||||
|
})
|
||||||
|
).find(({ client }) => client === "workbuddy"),
|
||||||
|
).toMatchObject({ state: "aligned", command });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("creates the mcpServers table in an existing mcp.json without servers", async () => {
|
||||||
|
const { client } = await workbuddyClient();
|
||||||
|
await writeFile(
|
||||||
|
client.configPath,
|
||||||
|
JSON.stringify({ unrelated: { setting: true } }, null, 2),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
(await configureClientConfiguration(client, {}, command)).status,
|
||||||
|
).toBe("configured");
|
||||||
|
const parsed = JSON.parse(await readFile(client.configPath, "utf8"));
|
||||||
|
expect(parsed.unrelated).toEqual({ setting: true });
|
||||||
|
expect(parsed.mcpServers.rea).toEqual({
|
||||||
|
command: command[0],
|
||||||
|
args: command.slice(1),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("registers into an empty mcp.json", async () => {
|
||||||
|
const { client } = await workbuddyClient();
|
||||||
|
await writeFile(client.configPath, "");
|
||||||
|
expect(
|
||||||
|
(await configureClientConfiguration(client, {}, command)).status,
|
||||||
|
).toBe("configured");
|
||||||
|
const parsed = JSON.parse(await readFile(client.configPath, "utf8"));
|
||||||
|
expect(parsed.mcpServers.rea).toEqual({
|
||||||
|
command: command[0],
|
||||||
|
args: command.slice(1),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes only the rea entry on uninstall", async () => {
|
||||||
|
const { home, client } = await workbuddyClient();
|
||||||
|
await writeFile(
|
||||||
|
client.configPath,
|
||||||
|
JSON.stringify(
|
||||||
|
{ mcpServers: { other: { command: "other-server" } } },
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await configureClientConfiguration(client, {}, command);
|
||||||
|
|
||||||
|
expect((await systemUninstallHost(home).removeClient(client)).status).toBe(
|
||||||
|
"removed",
|
||||||
|
);
|
||||||
|
const parsed = JSON.parse(await readFile(client.configPath, "utf8"));
|
||||||
|
expect(parsed.mcpServers.other).toEqual({ command: "other-server" });
|
||||||
|
expect(parsed.mcpServers.rea).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||||
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||||
|
import { expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { FUNCTION_COMPARISON_EXAMPLE } from "../../../src/contracts/functionComparisonExample.js";
|
||||||
|
import { createEvidence } from "../../../src/domain/evidence.js";
|
||||||
|
import { functionDossierSchema } from "../../../src/domain/hopperValues.js";
|
||||||
|
import type { RelationshipCoverage } from "../../../src/domain/relationshipCoverage.js";
|
||||||
|
import { createServer } from "../../../src/server/createServer.js";
|
||||||
|
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||||
|
|
||||||
|
const observe = (relationshipCoverage: RelationshipCoverage) => {
|
||||||
|
const template = FUNCTION_COMPARISON_EXAMPLE.left;
|
||||||
|
if (template.subject === null)
|
||||||
|
throw new Error("Expected artifact-bound fixture");
|
||||||
|
const dossier = functionDossierSchema.parse(template.normalized_result);
|
||||||
|
return createEvidence(
|
||||||
|
{
|
||||||
|
path: template.subject.local_path,
|
||||||
|
sha256: template.subject.digest.sha256,
|
||||||
|
format: template.subject.format,
|
||||||
|
},
|
||||||
|
template.provider,
|
||||||
|
{
|
||||||
|
operation: "analyze_function",
|
||||||
|
parameters: template.parameters,
|
||||||
|
result: { ...dossier, callees: [], unresolved_calls: [] },
|
||||||
|
confidence: template.confidence,
|
||||||
|
authority: template.authority,
|
||||||
|
relationshipCoverage,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
it("preserves directional gaps through advertised schemas and public path reconstruction", async () => {
|
||||||
|
const session = createTestBinarySession(() => {
|
||||||
|
throw new Error("Offline call paths must not launch a provider");
|
||||||
|
});
|
||||||
|
const server = createServer({ kind: "session", session });
|
||||||
|
const client = new Client({ name: "function-call-directions", version: "1" });
|
||||||
|
const [clientTransport, serverTransport] =
|
||||||
|
InMemoryTransport.createLinkedPair();
|
||||||
|
try {
|
||||||
|
await server.connect(serverTransport);
|
||||||
|
await client.connect(clientTransport);
|
||||||
|
const advertised = (await client.listTools()).tools.find(
|
||||||
|
({ name }) => name === "build_call_path",
|
||||||
|
);
|
||||||
|
if (advertised === undefined)
|
||||||
|
throw new Error("Missing build_call_path contract");
|
||||||
|
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||||
|
expect(ajv.validateSchema(advertised.inputSchema)).toBe(true);
|
||||||
|
const validate = ajv.compile(advertised.inputSchema);
|
||||||
|
for (const { directions, status, exhaustive } of [
|
||||||
|
{
|
||||||
|
directions: ["callers"] as ["callers"],
|
||||||
|
status: "not_found",
|
||||||
|
exhaustive: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
directions: ["callees"] as ["callees"],
|
||||||
|
status: "unknown",
|
||||||
|
exhaustive: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
directions: ["callers", "callees"] as ["callers", "callees"],
|
||||||
|
status: "unknown",
|
||||||
|
exhaustive: false,
|
||||||
|
},
|
||||||
|
]) {
|
||||||
|
const limitation =
|
||||||
|
"An observed call reference is absent from the inventory.";
|
||||||
|
const coverage: RelationshipCoverage = {
|
||||||
|
status: "partial",
|
||||||
|
limitations: [limitation],
|
||||||
|
limited_directions: directions,
|
||||||
|
};
|
||||||
|
const observation = observe(coverage);
|
||||||
|
expect(session.recordEvidence(observation).ok).toBe(true);
|
||||||
|
const input = {
|
||||||
|
functions: [observation],
|
||||||
|
start: { address: "0x1000" },
|
||||||
|
goal: { address: "0x9999" },
|
||||||
|
};
|
||||||
|
expect(validate(input), JSON.stringify(validate.errors)).toBe(true);
|
||||||
|
for (const limited_directions of [
|
||||||
|
[],
|
||||||
|
["callers", "callers"],
|
||||||
|
["callees", "callees"],
|
||||||
|
["callers", "callees", "callers"],
|
||||||
|
["incoming"],
|
||||||
|
])
|
||||||
|
expect(
|
||||||
|
validate({
|
||||||
|
...input,
|
||||||
|
functions: [
|
||||||
|
{
|
||||||
|
...observation,
|
||||||
|
relationship_coverage: {
|
||||||
|
...coverage,
|
||||||
|
limited_directions,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
).toBe(false);
|
||||||
|
const result = await client.callTool({
|
||||||
|
name: "build_call_path",
|
||||||
|
arguments: input,
|
||||||
|
});
|
||||||
|
if (result.isError) throw new Error(JSON.stringify(result));
|
||||||
|
expect(result.structuredContent).toMatchObject({
|
||||||
|
normalized_result: {
|
||||||
|
status,
|
||||||
|
search_scope: { exhaustive },
|
||||||
|
limitations: expect.arrayContaining([limitation]),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const comparison = await client.callTool({
|
||||||
|
name: "compare_functions",
|
||||||
|
arguments: { left: observation, right: observation },
|
||||||
|
});
|
||||||
|
if (comparison.isError) throw new Error(JSON.stringify(comparison));
|
||||||
|
expect(comparison.structuredContent).toMatchObject({
|
||||||
|
normalized_result: {
|
||||||
|
dimensions: expect.arrayContaining([
|
||||||
|
expect.objectContaining({ dimension: "calls", status: "unknown" }),
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// Each scenario owns its Evidence and residual-unknown ledger.
|
||||||
|
const closed = await session.close();
|
||||||
|
if (!closed.ok) throw closed.error;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
await Promise.allSettled([session.close(), client.close(), server.close()]);
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -15,9 +15,17 @@ import {
|
|||||||
type GhidraFunctionOperation,
|
type GhidraFunctionOperation,
|
||||||
} from "../../../src/ghidra/GhidraFunctionValues.js";
|
} from "../../../src/ghidra/GhidraFunctionValues.js";
|
||||||
|
|
||||||
it.each([true, false])(
|
it.each([
|
||||||
"compares observed empty Ghidra facets while preserving pseudocode availability (%s)",
|
{ pseudocodeAvailable: true, reportsCoverage: true },
|
||||||
async (pseudocodeAvailable) => {
|
{ pseudocodeAvailable: false, reportsCoverage: true },
|
||||||
|
{ pseudocodeAvailable: true, reportsCoverage: false },
|
||||||
|
{ pseudocodeAvailable: false, reportsCoverage: false },
|
||||||
|
])(
|
||||||
|
"compares observed empty Ghidra facets with pseudocode=$pseudocodeAvailable and coverage=$reportsCoverage",
|
||||||
|
async ({ pseudocodeAvailable, reportsCoverage }) => {
|
||||||
|
const coverage = reportsCoverage
|
||||||
|
? { status: "complete" as const }
|
||||||
|
: undefined;
|
||||||
const dossier = functionDossierSchema.parse(ghidraFunctionDossier());
|
const dossier = functionDossierSchema.parse(ghidraFunctionDossier());
|
||||||
Object.assign(dossier, {
|
Object.assign(dossier, {
|
||||||
comments: [],
|
comments: [],
|
||||||
@@ -47,7 +55,13 @@ it.each([true, false])(
|
|||||||
if (operation !== "analyze_function")
|
if (operation !== "analyze_function")
|
||||||
throw new Error(`Unexpected operation: ${operation}`);
|
throw new Error(`Unexpected operation: ${operation}`);
|
||||||
return Promise.resolve(
|
return Promise.resolve(
|
||||||
ok({ value: jsonValueSchema.parse(dossier), limitations: [] }),
|
ok({
|
||||||
|
value: jsonValueSchema.parse(dossier),
|
||||||
|
limitations: [],
|
||||||
|
...(coverage === undefined
|
||||||
|
? {}
|
||||||
|
: { relationship_coverage: coverage }),
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -61,9 +75,7 @@ it.each([true, false])(
|
|||||||
harness.session,
|
harness.session,
|
||||||
analyzed.structuredContent,
|
analyzed.structuredContent,
|
||||||
);
|
);
|
||||||
expect(evidence.relationship_coverage).toMatchObject({
|
expect(evidence.relationship_coverage).toEqual(coverage ?? null);
|
||||||
status: "complete",
|
|
||||||
});
|
|
||||||
expect(evidence.normalized_result).toEqual(dossier);
|
expect(evidence.normalized_result).toEqual(dossier);
|
||||||
const reply = await harness.mcp.callTool({
|
const reply = await harness.mcp.callTool({
|
||||||
name: "compare_functions",
|
name: "compare_functions",
|
||||||
@@ -86,7 +98,7 @@ it.each([true, false])(
|
|||||||
pseudocode: pseudocodeAvailable ? "unchanged" : "unknown",
|
pseudocode: pseudocodeAvailable ? "unchanged" : "unknown",
|
||||||
assembly: "unchanged",
|
assembly: "unchanged",
|
||||||
comments: "unchanged",
|
comments: "unchanged",
|
||||||
calls: "unchanged",
|
calls: reportsCoverage ? "unchanged" : "unknown",
|
||||||
references: "unchanged",
|
references: "unchanged",
|
||||||
strings_names: "unchanged",
|
strings_names: "unchanged",
|
||||||
cfg: "unchanged",
|
cfg: "unchanged",
|
||||||
@@ -96,9 +108,7 @@ it.each([true, false])(
|
|||||||
evidence.parameters,
|
evidence.parameters,
|
||||||
);
|
);
|
||||||
if (!replay.ok) throw replay.error;
|
if (!replay.ok) throw replay.error;
|
||||||
expect(replay.value.relationshipCoverage).toEqual(
|
expect(replay.value.relationshipCoverage).toEqual(coverage);
|
||||||
evidence.relationship_coverage,
|
|
||||||
);
|
|
||||||
expect(harness.calls).toEqual(["analyze_function"]);
|
expect(harness.calls).toEqual(["analyze_function"]);
|
||||||
} finally {
|
} finally {
|
||||||
await harness.close();
|
await harness.close();
|
||||||
|
|||||||
@@ -49,16 +49,13 @@ it("returns a first-call overview and pages the unchanged source after its file
|
|||||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||||
expect(ajv.validateSchema(definition.inputSchema)).toBe(true);
|
expect(ajv.validateSchema(definition.inputSchema)).toBe(true);
|
||||||
expect(ajv.validateSchema(outputSchema)).toBe(true);
|
expect(ajv.validateSchema(outputSchema)).toBe(true);
|
||||||
for (const name of [
|
expect(
|
||||||
"inspect_managed_members",
|
ajv.validate(
|
||||||
"inspect_managed_native_boundaries",
|
catalog.find((x) => x.name === "inspect_managed_native_boundaries")!
|
||||||
])
|
.inputSchema,
|
||||||
expect(
|
{ path, detail: "summary" },
|
||||||
ajv.validate(catalog.find((x) => x.name === name)!.inputSchema, {
|
),
|
||||||
path,
|
).toBe(false);
|
||||||
detail: "summary",
|
|
||||||
}),
|
|
||||||
).toBe(false);
|
|
||||||
const reply = await client.callTool({
|
const reply = await client.callTool({
|
||||||
name: "inspect_managed_artifact",
|
name: "inspect_managed_artifact",
|
||||||
arguments: { path, detail: "summary" },
|
arguments: { path, detail: "summary" },
|
||||||
@@ -239,11 +236,15 @@ it("refuses selected delivery before file access when the server cannot retain E
|
|||||||
const [a, b] = InMemoryTransport.createLinkedPair();
|
const [a, b] = InMemoryTransport.createLinkedPair();
|
||||||
await server.connect(b);
|
await server.connect(b);
|
||||||
await client.connect(a);
|
await client.connect(a);
|
||||||
const rejected = await client.callTool({
|
for (const name of ["inspect_managed_artifact", "inspect_managed_members"]) {
|
||||||
name: "inspect_managed_artifact",
|
const rejected = await client.callTool({
|
||||||
arguments: { path: join(directory, "absent.dll"), detail: "summary" },
|
name,
|
||||||
});
|
arguments: { path: join(directory, "absent.dll"), detail: "summary" },
|
||||||
expect(parseMcpToolError(rejected).error.code).toBe("capability_unavailable");
|
});
|
||||||
|
expect(parseMcpToolError(rejected).error.code).toBe(
|
||||||
|
"capability_unavailable",
|
||||||
|
);
|
||||||
|
}
|
||||||
const complete = await client.callTool({
|
const complete = await client.callTool({
|
||||||
name: "inspect_managed_artifact",
|
name: "inspect_managed_artifact",
|
||||||
arguments: { path },
|
arguments: { path },
|
||||||
|
|||||||
@@ -0,0 +1,200 @@
|
|||||||
|
import { writeFile, unlink } from "node:fs/promises";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||||
|
import { expect, it, onTestFinished } from "vitest";
|
||||||
|
import { composeBinarySession } from "../../../src/application/binary/BinarySessionComposition.js";
|
||||||
|
import { AnalysisProviderRegistry } from "../../../src/application/binary/AnalysisProviderRegistry.js";
|
||||||
|
import { inspectAnalysisView } from "../../../src/application/analysisView/AnalysisViewService.js";
|
||||||
|
import { ManagedStaticProvider } from "../../../src/dotnet/ManagedStaticProvider.js";
|
||||||
|
import { buildManagedPeFixture } from "../../../src/dotnet/ManagedPe.fixture.js";
|
||||||
|
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
|
||||||
|
import {
|
||||||
|
analysisViewResultSchema,
|
||||||
|
managedMemberSummaryViewResultSchema,
|
||||||
|
} from "../../../src/domain/analysisView/analysisView.js";
|
||||||
|
import { managedMemberInspectionSchema } from "../../../src/domain/managed/managedArtifact.js";
|
||||||
|
import { createApplicationMcpHarness } from "../../fixtures/applicationMcpHarness.js";
|
||||||
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||||
|
|
||||||
|
const COLLECTIONS = [
|
||||||
|
"types",
|
||||||
|
"exported_types",
|
||||||
|
"fields",
|
||||||
|
"methods",
|
||||||
|
"member_refs",
|
||||||
|
"call_edges",
|
||||||
|
"field_accesses",
|
||||||
|
"user_strings",
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
const createHarness = async () => {
|
||||||
|
const session = composeBinarySession(new AnalysisProviderRegistry([]), [
|
||||||
|
new ManagedStaticProvider(),
|
||||||
|
]);
|
||||||
|
const harness = await createApplicationMcpHarness({ session });
|
||||||
|
onTestFinished(harness.close);
|
||||||
|
return harness;
|
||||||
|
};
|
||||||
|
|
||||||
|
it("summarizes selected members and pages every original collection after the file disappears", async () => {
|
||||||
|
const directory = await createTestTempDirectory("rea-member-summary-");
|
||||||
|
const path = join(directory, "fixture.dll");
|
||||||
|
await writeFile(path, buildManagedPeFixture({ methodRowCount: 2 }));
|
||||||
|
const { client, session } = await createHarness();
|
||||||
|
const definition = (await client.listTools()).tools.find(
|
||||||
|
(x) => x.name === "inspect_managed_members",
|
||||||
|
);
|
||||||
|
if (definition?.outputSchema === undefined)
|
||||||
|
throw new Error("Managed member schemas are absent");
|
||||||
|
const outputSchema: Record<string, unknown> = definition.outputSchema;
|
||||||
|
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||||
|
expect(ajv.validateSchema(definition.inputSchema)).toBe(true);
|
||||||
|
expect(ajv.validateSchema(outputSchema)).toBe(true);
|
||||||
|
const type_names = ["Fixture.Program", "Missing.Type"];
|
||||||
|
expect(
|
||||||
|
ajv.validate(definition.inputSchema, {
|
||||||
|
path,
|
||||||
|
type_names,
|
||||||
|
detail: "summary",
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
const reply = await client.callTool({
|
||||||
|
name: "inspect_managed_members",
|
||||||
|
arguments: { path, type_names, detail: "summary" },
|
||||||
|
});
|
||||||
|
expect(reply.isError).not.toBe(true);
|
||||||
|
expect(
|
||||||
|
ajv.validate(outputSchema, reply.structuredContent),
|
||||||
|
JSON.stringify(ajv.errors),
|
||||||
|
).toBe(true);
|
||||||
|
const receipt = parseEvidence(reply.structuredContent);
|
||||||
|
const view = managedMemberSummaryViewResultSchema.parse(
|
||||||
|
receipt.normalized_result,
|
||||||
|
);
|
||||||
|
const parent = session.evidenceById(view.parent_evidence_id);
|
||||||
|
if (parent === undefined)
|
||||||
|
throw new Error("Complete member source was not retained");
|
||||||
|
expect(parent.operation).toBe("inspect_managed_members");
|
||||||
|
expect(receipt.evidence_links).toEqual([parent.evidence_id]);
|
||||||
|
const report = managedMemberInspectionSchema.parse(parent.normalized_result);
|
||||||
|
expect(view.summary.selection).toEqual({
|
||||||
|
type_names,
|
||||||
|
unmatched_type_names: ["Missing.Type"],
|
||||||
|
});
|
||||||
|
expect(view.summary.coverage).toEqual(report.coverage);
|
||||||
|
expect(view.summary.identity_scope).toEqual(report.identity_scope);
|
||||||
|
expect(view.summary).not.toHaveProperty("methods");
|
||||||
|
expect(report.methods.length).toBeGreaterThan(0);
|
||||||
|
expect(report.member_refs.length).toBeGreaterThan(0);
|
||||||
|
for (const detail of [undefined, "complete"]) {
|
||||||
|
const complete = parseEvidence(
|
||||||
|
(
|
||||||
|
await client.callTool({
|
||||||
|
name: "inspect_managed_members",
|
||||||
|
arguments: { path, type_names, ...(detail ? { detail } : {}) },
|
||||||
|
})
|
||||||
|
).structuredContent,
|
||||||
|
);
|
||||||
|
expect(complete.operation).toBe("inspect_managed_members");
|
||||||
|
expect(complete.normalized_result).toEqual(parent.normalized_result);
|
||||||
|
}
|
||||||
|
const original = JSON.stringify(parent);
|
||||||
|
await unlink(path);
|
||||||
|
for (const collection of COLLECTIONS) {
|
||||||
|
const rows =
|
||||||
|
collection === "user_strings"
|
||||||
|
? report.user_strings?.literals
|
||||||
|
: report[collection];
|
||||||
|
if (rows == null) throw new Error(`${collection} was not examined`);
|
||||||
|
expect(view.summary.reported_counts[collection]).toBe(rows.length);
|
||||||
|
const paged: unknown[] = [];
|
||||||
|
for (let offset: number | null = 0; offset !== null;) {
|
||||||
|
const result = await client.callTool({
|
||||||
|
name: "inspect_analysis_view",
|
||||||
|
arguments: {
|
||||||
|
source: {
|
||||||
|
kind: "retained-evidence",
|
||||||
|
evidence_id: parent.evidence_id,
|
||||||
|
},
|
||||||
|
view: { kind: "managed-members", collection, offset, limit: 1 },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(result.isError).not.toBe(true);
|
||||||
|
const page = analysisViewResultSchema.parse(
|
||||||
|
parseEvidence(result.structuredContent).normalized_result,
|
||||||
|
);
|
||||||
|
if (page.kind !== "managed-members")
|
||||||
|
throw new Error("Unexpected page kind");
|
||||||
|
expect(page.page.collection).toBe(collection);
|
||||||
|
expect(page.selection).toEqual(report.selection);
|
||||||
|
expect(page.coverage.total).toBe(rows.length);
|
||||||
|
paged.push(...page.page.rows);
|
||||||
|
offset = page.coverage.next_offset;
|
||||||
|
}
|
||||||
|
// Method rows carry body facts that a looser row schema would strip.
|
||||||
|
expect(paged).toEqual(rows);
|
||||||
|
}
|
||||||
|
expect(JSON.stringify(session.evidenceById(parent.evidence_id))).toBe(
|
||||||
|
original,
|
||||||
|
);
|
||||||
|
const portable = inspectAnalysisView({
|
||||||
|
source: { kind: "inline", evidence: parent },
|
||||||
|
view: { kind: "summary" },
|
||||||
|
});
|
||||||
|
if (!portable.ok) throw portable.error;
|
||||||
|
expect(portable.value.normalized_result).toEqual(view);
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
|
it("keeps collections that historical member Evidence never examined unknown", async () => {
|
||||||
|
const directory = await createTestTempDirectory("rea-member-historical-");
|
||||||
|
const path = join(directory, "fixture.dll");
|
||||||
|
await writeFile(path, buildManagedPeFixture());
|
||||||
|
const { client } = await createHarness();
|
||||||
|
const parent = parseEvidence(
|
||||||
|
(
|
||||||
|
await client.callTool({
|
||||||
|
name: "inspect_managed_members",
|
||||||
|
arguments: { path },
|
||||||
|
})
|
||||||
|
).structuredContent,
|
||||||
|
);
|
||||||
|
const {
|
||||||
|
exported_types: _exported,
|
||||||
|
user_strings: _strings,
|
||||||
|
selection: _selection,
|
||||||
|
...recorded
|
||||||
|
} = managedMemberInspectionSchema.parse(parent.normalized_result);
|
||||||
|
const historical = createEvidence(undefined, parent.provider, {
|
||||||
|
operation: parent.operation,
|
||||||
|
parameters: parent.parameters,
|
||||||
|
result: recorded,
|
||||||
|
limitations: parent.limitations,
|
||||||
|
authority: parent.authority,
|
||||||
|
});
|
||||||
|
const summary = inspectAnalysisView({
|
||||||
|
source: { kind: "inline", evidence: historical },
|
||||||
|
view: { kind: "summary" },
|
||||||
|
});
|
||||||
|
if (!summary.ok) throw summary.error;
|
||||||
|
const view = managedMemberSummaryViewResultSchema.parse(
|
||||||
|
summary.value.normalized_result,
|
||||||
|
);
|
||||||
|
expect(view.summary.reported_counts.exported_types).toBeNull();
|
||||||
|
expect(view.summary.reported_counts.user_strings).toBeNull();
|
||||||
|
expect(view.summary.user_strings).toBeNull();
|
||||||
|
expect(view.summary.selection).toBeNull();
|
||||||
|
expect(view.unknowns.join(" ")).toContain("no recorded subject");
|
||||||
|
for (const collection of ["exported_types", "user_strings"] as const)
|
||||||
|
expect(
|
||||||
|
inspectAnalysisView({
|
||||||
|
source: { kind: "inline", evidence: historical },
|
||||||
|
view: { kind: "managed-members", collection, offset: 0, limit: 1 },
|
||||||
|
}),
|
||||||
|
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||||
|
expect(
|
||||||
|
inspectAnalysisView({
|
||||||
|
source: { kind: "inline", evidence: historical },
|
||||||
|
view: { kind: "managed", collection: "attributes", offset: 0, limit: 1 },
|
||||||
|
}),
|
||||||
|
).toMatchObject({ ok: false, error: { _tag: "AnalysisInputError" } });
|
||||||
|
}, 30000);
|
||||||
@@ -12,6 +12,8 @@ import ghidra.program.model.listing.FlowOverride;
|
|||||||
import ghidra.program.model.listing.Function;
|
import ghidra.program.model.listing.Function;
|
||||||
import ghidra.program.model.listing.Instruction;
|
import ghidra.program.model.listing.Instruction;
|
||||||
import ghidra.program.model.symbol.SourceType;
|
import ghidra.program.model.symbol.SourceType;
|
||||||
|
import ghidra.program.model.symbol.Reference;
|
||||||
|
import ghidra.program.model.symbol.RefType;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -20,9 +22,12 @@ import java.util.HexFormat;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/** Injects reported analysis flags into imported ELF/Mach-O functions; never executes target code. */
|
/** Injects reported analysis flags into imported ELF/Mach-O functions; never executes target code. */
|
||||||
public class ReaNoReturnProbe extends GhidraScript {
|
public class ReaNoReturnProbe extends GhidraScript {
|
||||||
|
private record MemoryCallReference(Address source, Address target, RefType type,
|
||||||
|
SourceType sourceType, int operandIndex, boolean primary) {}
|
||||||
private final JsonArray checks = new JsonArray();
|
private final JsonArray checks = new JsonArray();
|
||||||
private final Map<Function, Address> originalEnds = new LinkedHashMap<>();
|
private final Map<Function, Address> originalEnds = new LinkedHashMap<>();
|
||||||
private final Map<Function, String> originalSignatures = new LinkedHashMap<>();
|
private final Map<Function, String> originalSignatures = new LinkedHashMap<>();
|
||||||
@@ -85,6 +90,114 @@ public class ReaNoReturnProbe extends GhidraScript {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void knownInteriorCall(GhidraScript bridge) throws Exception {
|
||||||
|
Function caller = function("rea_tls_chain");
|
||||||
|
Function target = function("rea_tls");
|
||||||
|
Address interior = target.getEntryPoint().add(1);
|
||||||
|
require("interior_target_is_owned", currentProgram.getFunctionManager().getFunctionAt(interior) == null &&
|
||||||
|
target.equals(currentProgram.getFunctionManager().getFunctionContaining(interior)));
|
||||||
|
Instruction call = null;
|
||||||
|
for (Instruction instruction : currentProgram.getListing().getInstructions(caller.getBody(), true)) {
|
||||||
|
if (instruction.getFlowType().isCall()) { call = instruction; break; }
|
||||||
|
}
|
||||||
|
if (call == null) throw new IllegalStateException("Missing real call instruction");
|
||||||
|
var references = currentProgram.getReferenceManager();
|
||||||
|
List<Reference> originals = new ArrayList<>();
|
||||||
|
List<MemoryCallReference> saved = new ArrayList<>();
|
||||||
|
for (Reference reference : call.getReferencesFrom()) {
|
||||||
|
if (!reference.getReferenceType().isCall()) continue;
|
||||||
|
originals.add(reference);
|
||||||
|
saved.add(new MemoryCallReference(reference.getFromAddress(), reference.getToAddress(),
|
||||||
|
reference.getReferenceType(), reference.getSource(), reference.getOperandIndex(), reference.isPrimary()));
|
||||||
|
}
|
||||||
|
require("original_call_reference_present", !originals.isEmpty());
|
||||||
|
Reference changed = null;
|
||||||
|
try {
|
||||||
|
for (Reference reference : originals) references.delete(reference);
|
||||||
|
changed = references.addMemoryReference(call.getAddress(), interior,
|
||||||
|
RefType.UNCONDITIONAL_CALL, SourceType.USER_DEFINED, 0);
|
||||||
|
require("interior_target_omitted_by_callee_getter", !caller.getCalledFunctions(monitor).contains(target));
|
||||||
|
JsonObject query = new JsonObject();
|
||||||
|
query.addProperty("document", currentProgram.getName());
|
||||||
|
query.addProperty("procedure", caller.getName());
|
||||||
|
query.addProperty("direction", "outgoing");
|
||||||
|
Method read = bridge.getClass().getDeclaredMethod("procedureReferences", JsonObject.class);
|
||||||
|
read.setAccessible(true);
|
||||||
|
JsonObject output = (JsonObject) read.invoke(bridge, query);
|
||||||
|
require("interior_reference_keeps_known_procedure", output.getAsJsonArray("references").asList().stream().anyMatch(
|
||||||
|
edge -> !edge.getAsJsonObject().get("target_procedure").isJsonNull() &&
|
||||||
|
edge.getAsJsonObject().getAsJsonObject("target_procedure").get("name").getAsString().equals(target.getName())));
|
||||||
|
require("known_reference_is_not_also_unresolved", output.getAsJsonArray("unresolved_calls").isEmpty());
|
||||||
|
query.remove("direction");
|
||||||
|
Method callees = bridge.getClass().getDeclaredMethod("procedureCalls", JsonObject.class, boolean.class);
|
||||||
|
callees.setAccessible(true);
|
||||||
|
JsonObject inventory = (JsonObject) callees.invoke(bridge, query, false);
|
||||||
|
require("omitted_callee_inventory_stays_partial", inventory.getAsJsonObject("relationship_coverage").get("status").getAsString().equals("partial"));
|
||||||
|
require("omitted_callee_direction_is_explicit",
|
||||||
|
inventory.getAsJsonObject("relationship_coverage").getAsJsonArray("limited_directions").toString().equals("[\"callees\"]"));
|
||||||
|
require("interior_caller_omitted_by_entry_getter", !target.getCallingFunctions(monitor).contains(caller));
|
||||||
|
query.addProperty("procedure", target.getName());
|
||||||
|
JsonObject incoming = (JsonObject) callees.invoke(bridge, query, true);
|
||||||
|
require("off_entry_caller_inventory_stays_partial",
|
||||||
|
incoming.getAsJsonObject("relationship_coverage").get("status").getAsString().equals("partial"));
|
||||||
|
require("off_entry_caller_direction_is_explicit",
|
||||||
|
incoming.getAsJsonObject("relationship_coverage").getAsJsonArray("limited_directions").toString().equals("[\"callers\"]"));
|
||||||
|
JsonObject dossierQuery = new JsonObject();
|
||||||
|
dossierQuery.addProperty("procedure", target.getName());
|
||||||
|
Method analyze = bridge.getClass().getDeclaredMethod("analyzeFunctionObservation", JsonObject.class);
|
||||||
|
analyze.setAccessible(true);
|
||||||
|
Object observation = analyze.invoke(bridge, dossierQuery);
|
||||||
|
Method coverage = observation.getClass().getDeclaredMethod("relationshipCoverage");
|
||||||
|
coverage.setAccessible(true);
|
||||||
|
require("dossier_preserves_caller_only_gap",
|
||||||
|
((JsonObject) coverage.invoke(observation)).getAsJsonArray("limited_directions").toString().equals("[\"callers\"]"));
|
||||||
|
} finally {
|
||||||
|
if (changed != null) references.delete(changed);
|
||||||
|
for (MemoryCallReference reference : saved) {
|
||||||
|
Reference restored = references.addMemoryReference(reference.source(), reference.target(),
|
||||||
|
reference.type(), reference.sourceType(), reference.operandIndex());
|
||||||
|
references.setPrimary(restored, reference.primary());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nonCallInstructionReference(GhidraScript bridge) throws Exception {
|
||||||
|
Function caller = function("rea_tls_chain");
|
||||||
|
Function target = function("rea_memcpy");
|
||||||
|
Instruction source = null;
|
||||||
|
for (Instruction instruction : currentProgram.getListing().getInstructions(caller.getBody(), true)) {
|
||||||
|
if (!instruction.getFlowType().isCall()) { source = instruction; break; }
|
||||||
|
}
|
||||||
|
if (source == null) throw new IllegalStateException("Missing non-call instruction");
|
||||||
|
var references = currentProgram.getReferenceManager();
|
||||||
|
Reference added = references.addMemoryReference(source.getAddress(), target.getEntryPoint().add(1),
|
||||||
|
RefType.UNCONDITIONAL_CALL, SourceType.USER_DEFINED, -1);
|
||||||
|
try {
|
||||||
|
require("non_call_reference_target_omitted", !caller.getCalledFunctions(monitor).contains(target));
|
||||||
|
JsonObject query = new JsonObject();
|
||||||
|
query.addProperty("document", currentProgram.getName());
|
||||||
|
query.addProperty("procedure", caller.getName());
|
||||||
|
Method read = bridge.getClass().getDeclaredMethod("procedureCalls", JsonObject.class, boolean.class);
|
||||||
|
read.setAccessible(true);
|
||||||
|
JsonObject output = (JsonObject) read.invoke(bridge, query, false);
|
||||||
|
require("non_call_instruction_reference_stays_partial",
|
||||||
|
output.getAsJsonObject("relationship_coverage").get("status").getAsString().equals("partial"));
|
||||||
|
query.addProperty("direction", "outgoing");
|
||||||
|
Method edges = bridge.getClass().getDeclaredMethod("procedureReferences", JsonObject.class);
|
||||||
|
edges.setAccessible(true);
|
||||||
|
JsonObject known = (JsonObject) edges.invoke(bridge, query);
|
||||||
|
require("non_call_known_reference_is_not_unresolved", known.getAsJsonArray("unresolved_calls").isEmpty());
|
||||||
|
references.delete(added);
|
||||||
|
Address unknown = currentProgram.getMemory().getMaxAddress().add(0x1000);
|
||||||
|
added = references.addMemoryReference(source.getAddress(), unknown,
|
||||||
|
RefType.UNCONDITIONAL_CALL, SourceType.USER_DEFINED, -1);
|
||||||
|
JsonObject unresolved = (JsonObject) edges.invoke(bridge, query);
|
||||||
|
require("non_call_unknown_reference_keeps_site", unresolved.getAsJsonArray("unresolved_calls").size() == 1);
|
||||||
|
} finally {
|
||||||
|
references.delete(added);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
String[] args = getScriptArgs();
|
String[] args = getScriptArgs();
|
||||||
@@ -164,6 +277,8 @@ public class ReaNoReturnProbe extends GhidraScript {
|
|||||||
Object output = pseudocode.invoke(bridge, query);
|
Object output = pseudocode.invoke(bridge, query);
|
||||||
require("recovered_pseudocode", output instanceof JsonObject value &&
|
require("recovered_pseudocode", output instanceof JsonObject value &&
|
||||||
value.get("value").getAsString().contains("rea_after_call"));
|
value.get("value").getAsString().contains("rea_after_call"));
|
||||||
|
nonCallInstructionReference(bridge);
|
||||||
|
knownInteriorCall(bridge);
|
||||||
} finally {
|
} finally {
|
||||||
((ghidra.app.decompiler.DecompInterface) field.get(bridge)).dispose();
|
((ghidra.app.decompiler.DecompInterface) field.get(bridge)).dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user