Skip to content

Commit

Permalink
Detect and report ERROR status in analysis checker
Browse files Browse the repository at this point in the history
  • Loading branch information
fmagin committed Jul 31, 2024
1 parent 1aa2a69 commit d863bcf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import ghidra.util.task.TaskLauncher;
import ghidra.util.task.TaskMonitor;

import static ai.reveng.toolkit.ghidra.ReaiPluginPackage.INVALID_BINARY_ID;

/**
* This plugin provides features for performing binary code similarity using the
* RevEng.AI API
Expand Down Expand Up @@ -117,6 +119,7 @@ private void setupActions() {
TaskLauncher.launchModal("Create new Analysis for Binary", monitor -> {
monitor.setMessage("Uploading binary...");
apiService.upload(context.getProgram());
monitor.setProgress(99);
monitor.setMessage("Launching Analysis");
BinaryID binID = apiService.analyse(context.getProgram());
Msg.showInfo(this, null, ReaiPluginPackage.WINDOW_PREFIX + "Create new Analysis for Binary",
Expand Down Expand Up @@ -212,6 +215,17 @@ public void monitoredRun(TaskMonitor monitor) {
Msg.showInfo(this, null, ReaiPluginPackage.WINDOW_PREFIX + "Analysis Status",
"Analysis is complete for binary with ID: " + binID.value());
break;
} else if (result == AnalysisStatus.Error) {
// Load analysis logs
String logs = apiService.getApi().getAnalysisLogs(binID);
Msg.showError(this, null, ReaiPluginPackage.WINDOW_PREFIX + "Analysis Status",
"Analysis failed for binary with ID %s.\nAnalysis Logs:%s.".formatted(binID.value(), logs));
// Clear the binary ID from the program options
currentProgram.withTransaction("Clear errored Binary ID from Program Options", () -> {
apiService.addBinaryIDtoProgramOptions(currentProgram, new BinaryID(INVALID_BINARY_ID));
});
break;

}
try {
Thread.sleep(5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ public List<Collection> collectionQuickSearch(String searchTerm) {
return List.of();
}

@Override
public String getAnalysisLogs(BinaryID binID) {
return null;
}

@Override
public List<ModelInfo> models() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ public List<Collection> collectionQuickSearch(String searchTerm) {
return result;
}

@Override
public String getAnalysisLogs(BinaryID binID) {
var request = requestBuilderForEndpoint("logs/" + binID.value())
.build();
var response = sendRequest(request);
return response.getString("logs");
}

public JSONObject health(){
// The health check has no version prefix
URI uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@ List<FunctionMatch> annSymbolsForFunctions(List<FunctionID> fID,
List<ModelInfo> models();

List<Collection> collectionQuickSearch(String searchTerm);

String getAnalysisLogs(BinaryID binID);

}

0 comments on commit d863bcf

Please sign in to comment.