Class ElasticDatabase
java.lang.Object
ghidra.features.bsim.query.elastic.ElasticDatabase
- All Implemented Interfaces:
FunctionDatabase,AutoCloseable
Implement the BSim database interface on top of an ElasticSearch back-end
ElasticSearch holds records as JSON documents. Documents
are stored in a specific "index". The primary BSim document index/types are:
executable/exe is executable metadata corresponding to the ExecutableRecord object
executable/function is function metadata corresponding to the FunctionDescription object
vector/vector is the main feature vector corresponding to an LSHVector object
meta/meta is a document containing the duplication count for a particular feature vector
-
Nested Class Summary
Nested classes/interfaces inherited from interface ghidra.features.bsim.query.FunctionDatabase
FunctionDatabase.BSimError, FunctionDatabase.ConnectionType, FunctionDatabase.DatabaseNonFatalException, FunctionDatabase.ErrorCategory, FunctionDatabase.Status -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close down (the connection with) the databaseintReturn -1 if info layout version is earlier than current client expectation Return 1 if info layout version is later than current client expectation Return 0 if info version and client version are the sameprotected voidconvertDescriptionRows(SimilarityResult similarityResult, com.google.gson.JsonArray descRows, VectorResult vectorResult, DescriptionManager manager, SignatureRecord sigRecord) Convert function documents, presented as an array of JSON objects, that all share a single feature vector returned by a nearest neighbor query, into FunctionDescriptions and a full SimilarityResult.protected intcountExecutables(String filter) Place the same query for executables asqueryExecutables(DescriptionManager, List, int, String, boolean, String).static StringgetInfo()If the last query failed to produce a response, use this method to recover the error messageReturn theserver info objectfor this databasebooleanInitialize (a connection with) the database.booleanSend a query to the database.recoverExternalFunctionId(String exeName, String funcName, String arch) Given the name of an executable library, its architecture, and a function name, return the id of the document describing this specific function.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ghidra.features.bsim.query.FunctionDatabase
changePassword, getOverviewFunctionsPerStage, getQueriedFunctionsPerStage, isPasswordChangeAllowed
-
Field Details
-
LAYOUT_VERSION
public static final int LAYOUT_VERSION- See Also:
-
MAX_VECTOR_OVERALL
public static final int MAX_VECTOR_OVERALL- See Also:
-
MAX_FUNCTION_WINDOW
public static final int MAX_FUNCTION_WINDOW- See Also:
-
MAX_FUNCTIONUPDATE_WINDOW
public static final int MAX_FUNCTIONUPDATE_WINDOW- See Also:
-
MAX_VECTORCOUNT_WINDOW
public static final int MAX_VECTORCOUNT_WINDOW- See Also:
-
MAX_VECTORDELETE_WINDOW
public static final int MAX_VECTORDELETE_WINDOW- See Also:
-
MAX_FUNCTION_BULK
public static final int MAX_FUNCTION_BULK- See Also:
-
MAX_VECTOR_BULK
public static final int MAX_VECTOR_BULK- See Also:
-
-
Constructor Details
-
ElasticDatabase
Construct the database connection given a URL. The URL protocol must be http, and the URL path must contain exactly one element naming the particular repository on the server.- Parameters:
baseURL- is the http URL- Throws:
MalformedURLException- if the URL is malformed
-
-
Method Details
-
escape
-
countExecutables
Place the same query for executables asqueryExecutables(DescriptionManager, List, int, String, boolean, String). Except we only return the count of matching records.- Parameters:
filter- is the option filter options for the count- Returns:
- the number of matching executables matching the filter
- Throws:
ElasticException- is there is a server-side issue with the query
-
convertDescriptionRows
protected void convertDescriptionRows(SimilarityResult similarityResult, com.google.gson.JsonArray descRows, VectorResult vectorResult, DescriptionManager manager, SignatureRecord sigRecord) throws ElasticException, LSHException Convert function documents, presented as an array of JSON objects, that all share a single feature vector returned by a nearest neighbor query, into FunctionDescriptions and a full SimilarityResult. Each function document will be parsed into a FunctionDescription, and a SimilarityNote will be created describing its similarity to the query vector based on the raw VectorResult data.- Parameters:
similarityResult- is the container for the SimilarityNotesdescRows- is the array of JSON function documentsvectorResult- is the raw vector query resultmanager- is the container for new FunctionDescriptionssigRecord- is the shared feature vector- Throws:
ElasticException- for communication problems with the serverLSHException- for problems adding new records to the container
-
isInitialized
public boolean isInitialized()- Returns:
- true if a connection has been successfully initialized
-
getStatus
- Specified by:
getStatusin interfaceFunctionDatabase- Returns:
- the status of the current connection with this database
-
getConnectionType
- Specified by:
getConnectionTypein interfaceFunctionDatabase- Returns:
- the type of connection
-
getUserName
- Specified by:
getUserNamein interfaceFunctionDatabase- Returns:
- username (being used to establish connection)
-
getLSHVectorFactory
- Specified by:
getLSHVectorFactoryin interfaceFunctionDatabase- Returns:
- factory the database is using to create LSHVector objects
-
getInfo
- Specified by:
getInfoin interfaceFunctionDatabase- Returns:
- an information object giving general characteristics and descriptions of this database
-
compareLayout
public int compareLayout()Description copied from interface:FunctionDatabaseReturn -1 if info layout version is earlier than current client expectation Return 1 if info layout version is later than current client expectation Return 0 if info version and client version are the same- Specified by:
compareLayoutin interfaceFunctionDatabase- Returns:
- comparison of actual database layout with layout expected by client
-
getServerInfo
Description copied from interface:FunctionDatabaseReturn theserver info objectfor this database- Specified by:
getServerInfoin interfaceFunctionDatabase- Returns:
- the server info object
-
getURLString
- Specified by:
getURLStringin interfaceFunctionDatabase
-
initialize
public boolean initialize()Description copied from interface:FunctionDatabaseInitialize (a connection with) the database. If initialization is not successful, this routine will return false and an error description can be obtained using getLastError- Specified by:
initializein interfaceFunctionDatabase- Returns:
- true if the database ready for querying
-
close
public void close()Description copied from interface:FunctionDatabaseClose down (the connection with) the database- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceFunctionDatabase
-
getLastError
Description copied from interface:FunctionDatabaseIf the last query failed to produce a response, use this method to recover the error message- Specified by:
getLastErrorin interfaceFunctionDatabase- Returns:
- a String describing the error
-
query
Description copied from interface:FunctionDatabaseSend a query to the database. The response is returned as a QueryResponseRecord. If this is null, an error has occurred and an error message can be obtained from getLastError- Specified by:
queryin interfaceFunctionDatabase- Parameters:
query- an object describing the query- Returns:
- the response object or null if there is an error
-
recoverExternalFunctionId
public String recoverExternalFunctionId(String exeName, String funcName, String arch) throws ElasticException Given the name of an executable library, its architecture, and a function name, return the id of the document describing this specific function. These 3 Strings are designed to uniquely identify a library function.- Parameters:
exeName- is the name of the executablefuncName- is the name of the functionarch- is the executable architecture- Returns:
- the document id of the matching function
- Throws:
ElasticException- if the function (the executable) doesn't exist
-