Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions sententia/src/main/java/nl/nfi/sententia/FunctionDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,36 @@
import ghidra.util.exception.InvalidInputException;



public class FunctionDescriptor {
public String name;
public String binaryName;
List<List<Object>> functionCFG;
public String architecture;
public String binarySHA256;

public FunctionDescriptor(Function function) throws InvalidInputException, CancelledException {
this(function.getName(), SententiaUtil.getFunctionCFG(function), function.getProgram().getName(), function.getProgram().getExecutableSHA256());
this(
function.getName(),
SententiaUtil.getFunctionCFG(function),
function.getProgram().getName(),
SententiaUtil.toArchitecture(function.getProgram().getLanguageID()),
function.getProgram().getExecutableSHA256()
);
}


public FunctionDescriptor(String functionName, List<List<Object>> functionCFG, String binaryName, String binarySHA256) {

public FunctionDescriptor(String functionName, List<List<Object>> functionCFG, String architecture, String binaryName, String binarySHA256) {
this.name = functionName;
this.functionCFG = functionCFG;
this.architecture = architecture;
this.binaryName = binaryName;
this.binarySHA256 = binarySHA256;
}

public JSONObject toJson() {
JSONObject jsonFunctionDescriptor = new JSONObject();
jsonFunctionDescriptor.put("name", this.name);

jsonFunctionDescriptor.put("label", this.name);
jsonFunctionDescriptor.put("cfg", this.functionCFG);
jsonFunctionDescriptor.put("architecture", this.architecture);
jsonFunctionDescriptor.put("binary_name", this.binaryName);
jsonFunctionDescriptor.put("binary_sha256", this.binarySHA256);
return jsonFunctionDescriptor;
Expand Down
8 changes: 4 additions & 4 deletions sententia/src/main/java/nl/nfi/sententia/SententiaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public List<SententiaResult> getMatchingFunctions(FunctionDescriptor descriptor,
ArrayList<SententiaResult> results = new ArrayList<>();

// Construct the full URL
URI targetURI = new URI(this.serverURL.toString() + API_URL + "/search");
URI targetURI = new URI(this.serverURL.toString() + API_URL + "/functions/search");

// Prepare the JSON payload
String jsonPayload = descriptor.toJson().toJSONString();
Expand All @@ -67,9 +67,9 @@ public List<SententiaResult> getMatchingFunctions(FunctionDescriptor descriptor,
// Process the response
for (Object result : jsonResponse) {
JSONObject jsonResult = (JSONObject) result;
if (jsonResult.get("function") instanceof String && jsonResult.get("similarity") instanceof Double) {
if (jsonResult.get("label") instanceof String && jsonResult.get("similarity") instanceof Double) {
results.add(new SententiaResult(
(String) jsonResult.get("function"),
(String) jsonResult.get("label"),
(Double) jsonResult.get("similarity")
));
} else {
Expand All @@ -85,7 +85,7 @@ public List<SententiaResult> getMatchingFunctions(FunctionDescriptor descriptor,
}

public void addSignatureToDB(FunctionDescriptor descriptor) throws IOException, URISyntaxException, InterruptedException {
URI targetURI = new URI(serverURL.toString() + API_URL + "/add");
URI targetURI = new URI(serverURL.toString() + API_URL + "/functions");

// Prepare the JSON payload
String jsonPayload = descriptor.toJson().toJSONString();
Expand Down
6 changes: 6 additions & 0 deletions sententia/src/main/java/nl/nfi/sententia/SententiaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.block.CodeBlock;
import ghidra.program.model.block.SimpleBlockModel;
import ghidra.program.model.lang.LanguageID;
import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Function;
import ghidra.util.exception.CancelledException;
Expand Down Expand Up @@ -42,4 +43,9 @@ public static List<List<Object>> getFunctionCFG(Function function)

return functionCFG;
}

public static String toArchitecture(LanguageID languageId) {
// TODO: translate languageId (e.g. x86:LE:32:default) to one of (amd64, arm64, i386, riscv64)
return languageId.getIdAsString();
}
}