mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 13:11:18 -05:00
refactor(ghidra): compute the bridge read-only rule once (#15442)
This commit is contained in:
@@ -376,8 +376,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
||||
throw new IOException("Windows Ghidra P0 does not admit metadata recovery or database mutation.");
|
||||
analysisExtensions.analyze(descriptor.analysisExtensions, currentProgram, monitor);
|
||||
// Read-only sessions keep the discovered limitation but cannot mark blocks volatile.
|
||||
protectLoaderInitializedRelocations(
|
||||
!descriptor.existingProject && descriptor.transport.equals("unix-socket"));
|
||||
protectLoaderInitializedRelocations(!descriptor.readOnly());
|
||||
initializeDecompiler();
|
||||
checkpointModification = currentProgram.getModificationNumber();
|
||||
serve(descriptor);
|
||||
@@ -706,8 +705,10 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
||||
"Ghidra auto-analysis did not complete for this Program"
|
||||
);
|
||||
}
|
||||
if (descriptor.existingProject && isMutatingOperation(request.method))
|
||||
throw new RequestFailure("method_unavailable", "Existing Ghidra project sessions are read-only");
|
||||
if (descriptor.readOnly() && isMutatingOperation(request.method))
|
||||
throw new RequestFailure("method_unavailable", descriptor.existingProject
|
||||
? "Existing Ghidra project sessions are read-only"
|
||||
: "Windows P0 does not admit database mutation");
|
||||
switch (request.method) {
|
||||
case "list_names" -> writeStreamingSuccess(writer, request.id, listNames(request.params));
|
||||
case "list_procedures" -> writeStreamingSuccess(writer, request.id, listProcedures(request.params));
|
||||
@@ -762,22 +763,10 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
||||
if (observation.decompilerFailed()) result.addProperty("cache_policy", "live");
|
||||
yield result;
|
||||
}
|
||||
case "set_address_name", "set_addresses_names" -> {
|
||||
if (!descriptor.transport.equals("unix-socket"))
|
||||
throw new RequestFailure("method_unavailable", "Windows P0 does not admit database mutation");
|
||||
yield request.method.equals("set_address_name")
|
||||
? setAddressName(request.params) : setAddressesNames(request.params);
|
||||
}
|
||||
case "annotate_native_function" -> {
|
||||
if (!descriptor.transport.equals("unix-socket"))
|
||||
throw new RequestFailure("method_unavailable", "Windows P0 does not admit database mutation");
|
||||
yield annotateNativeFunction(request.params);
|
||||
}
|
||||
case "define_native_data_types" -> {
|
||||
if (!descriptor.transport.equals("unix-socket"))
|
||||
throw new RequestFailure("method_unavailable", "Windows P0 does not admit database mutation");
|
||||
yield defineNativeDataTypes(request.params);
|
||||
}
|
||||
case "set_address_name" -> setAddressName(request.params);
|
||||
case "set_addresses_names" -> setAddressesNames(request.params);
|
||||
case "annotate_native_function" -> annotateNativeFunction(request.params);
|
||||
case "define_native_data_types" -> defineNativeDataTypes(request.params);
|
||||
default -> throw new RequestFailure(
|
||||
"method_unavailable",
|
||||
"Bridge method is unavailable"
|
||||
@@ -793,7 +782,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
||||
/** Internal lifecycle request: the destination is inside this owned runtime. */
|
||||
private JsonObject checkpointProgram(JsonObject params, SessionDescriptor descriptor) throws Exception {
|
||||
requireKeys(params, Set.of("path", "force"));
|
||||
if (descriptor.existingProject || !descriptor.transport.equals("unix-socket"))
|
||||
if (descriptor.readOnly())
|
||||
throw new RequestFailure("method_unavailable", "This Program has no checkpoint authority");
|
||||
Path output = Path.of(requireString(params, "path")).toAbsolutePath().normalize();
|
||||
if (!output.getParent().equals(checkpointDirectory) ||
|
||||
@@ -840,7 +829,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
||||
result.addProperty("run_id", descriptor.runId);
|
||||
result.addProperty("profile_digest", descriptor.profileDigest);
|
||||
result.add("provider", provider);
|
||||
boolean readOnly = descriptor.existingProject || !descriptor.transport.equals("unix-socket");
|
||||
boolean readOnly = descriptor.readOnly();
|
||||
result.addProperty("read_only", readOnly);
|
||||
if (descriptor.existingProject) {
|
||||
result.add("analysis_complete", JsonNull.INSTANCE);
|
||||
@@ -9025,7 +9014,12 @@ public final class ReaGhidraBridge extends HeadlessScript {
|
||||
int decompileTimeoutSeconds,
|
||||
boolean existingProject,
|
||||
List<String> entryContextRegisters
|
||||
) {}
|
||||
) {
|
||||
/** Existing projects and Windows (non-unix-socket) sessions have no mutation or checkpoint authority. */
|
||||
boolean readOnly() {
|
||||
return existingProject || !transport.equals("unix-socket");
|
||||
}
|
||||
}
|
||||
private static ValueFlowLimits defaultValueFlowLimits() {
|
||||
return new ValueFlowLimits(DEFAULT_HIGH_PCODE_OPS, DEFAULT_HIGH_PCODE_INPUTS_PER_OP, DEFAULT_HIGH_PCODE_DEF_USE_EDGES);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user