BSim Databases from the Command Line

The bsim command-line utility, located in the support directory of a Ghidra distribution, is used to create, populate, and manage BSim databases. It works for all BSim database backends. This utility offers a number of commands, many of which have several options. In this section, we cover only a small subset of the possibilities.

Running bsim with no arguments will print a detailed usage message.

Generating Signature Files

The first step is to create signature files from the binaries in the Ghidra project. Signature files are XML files which contain the BSim signatures and metadata needed by the BSim server.

Important: It’s simplest to exit Ghidra before performing the next steps, because:

To generate the signature files, execute the following commands in a shell (adjust as necessary for Windows).

cd <ghidra_install_dir>/support
mkdir ~/bsim_sigs
./bsim generatesigs ghidra:/<ghidra_project_dir>/postgres_object_files --bsim file:/<database_dir>/example ~/bsim_sigs

Committing Signature Files

Now, we commit the signatures to the BSim database with the following command (still in the support directory).

./bsim commitsigs file:/<database_dir>/example ~/bsim_sigs 

Once the signatures have been committed, start Ghidra again.

Aside: Creating a Database

We continue to use the database example, so this step isn’t necessary for the exercises.

However, if we hadn’t created example using CreateH2BSimDatabaseScript.java, we could have used the following command:

./bsim createdatabase file:/<database_dir>/example medium_nosize

Aside: Executable Categories and Function Tags

It’s worth a brief note about Executable Categories and Function Tags, although they are not used in any of the following exercises.

A BSim database can record user-defined metadata about an executable (executable categories) or about a function (function tags). Categories and tags can then be used as filter elements in a BSim query. For example, you could restrict a BSim query to search only in executables of the category “OPEN_SOURCE” or to functions which have been tagged “COMPRESSION_FUNCTIONS”.

Executable categories in BSim are implemented using program properties, and function tags in BSim correspond to function tags in Ghidra. Properties and tags both have uses in Ghidra which are independent of BSim. So, if we want a BSim database to record a particular category or tag, we must indicate that explicitly.

For example, to inform the database that we wish to record the ORIGIN category, you would execute the command

./bsim addexecategory file:/<database_dir>/example ORIGIN

Executable categories can be added to a program using the script SetExecutableCategoryScript.java.

Next Section: Evaluating Matches and Applying Information