Ghidra is a software reverse engineering (SRE) framework
BSim: Add getmetadata subcommand to bsim
Andras Gemesc10a91fa3e97
diff --git a/Ghidra/Features/BSim/src/main/help/help/topics/BSim/CommandLineReference.html b/Ghidra/Features/BSim/src/main/help/help/topics/BSim/CommandLineReference.htmlindex 3c1f478a84..9e3a52e813 100644--- a/Ghidra/Features/BSim/src/main/help/help/topics/BSim/CommandLineReference.html+++ b/Ghidra/Features/BSim/src/main/help/help/topics/BSim/CommandLineReference.html@@ -268,6 +268,7 @@<CODE class "computeroutput">bsim createdatabase <bsimURL> <config_template> [--name|-n "<name>"] [--owner|-o "<owner>"] [--description|-d "<text>"] [--nocallgraph]bsim setmetadata <bsimURL> [--name|-n "<name>"] [--owner|-o "<owner>"] [--description|-d "<text>"]\n" ++ bsim getmetadata <bsimURL>bsim addexecategory <bsimURL> <category_name> [--date]bsim addfunctiontag <bsimURL> <tag_name>bsim dropindex <bsimURL>@@ -373,6 +374,16 @@string describing the intended contents of the new repository.</P></DD>+ <DT><SPAN class="term"><SPAN class=+ "bold"><STRONG>getmetadata</STRONG></SPAN></SPAN></DT>++ <DD>+ <P>Show the global <SPAN class="emphasis"><EM>name</EM></SPAN>, <SPAN class=+ "emphasis"><EM>owner</EM></SPAN>, and <SPAN class=+ "emphasis"><EM>description</EM></SPAN> metadata associated with a BSim server. A+ BSim server URL is required.</P>+ </DD>+<DT><SPAN class="term"><SPAN class="bold"><STRONG>addexecategory</STRONG></SPAN></SPAN></DT>diff --git a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BSimLaunchable.java b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BSimLaunchable.javaindex 6cebdb57ff..38ac030c6f 100644--- a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BSimLaunchable.java+++ b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BSimLaunchable.java@@ -60,6 +60,7 @@ public class BSimLaunchable implements GhidraLaunchable {*/private static final String COMMAND_CREATE_DATABASE = defineCommand("createdatabase");private static final String COMMAND_SET_METADATA = defineCommand("setmetadata");+ private static final String COMMAND_GET_METADATA = defineCommand("getmetadata");private static final String COMMAND_ADD_EXE_CATEGORY = defineCommand("addexecategory");private static final String COMMAND_ADD_FUNCTION_TAG = defineCommand("addfunctiontag");private static final String COMMAND_DROP_INDEX = defineCommand("dropindex");@@ -146,6 +147,7 @@ public class BSimLaunchable implements GhidraLaunchable {private static final Set<String> PREWARM_OPTIONS = Set.of();private static final Set<String> SET_METADATA_OPTIONS =Set.of(NAME_OPTION, OWNER_OPTION, DESCRIPTION_OPTION);+ private static final Set<String> GET_METADATA_OPTIONS = Set.of();private static final Set<String> ADD_EXE_CATEGORY_OPTIONS = Set.of(CATEGORY_DATE_OPTION);private static final Set<String> ADD_FUNCTION_TAG_OPTIONS = Set.of();private static final Set<String> DUMP_SIGS_OPTIONS =@@ -166,6 +168,7 @@ public class BSimLaunchable implements GhidraLaunchable {static {ALLOWED_OPTION_MAP.put(COMMAND_CREATE_DATABASE, CREATE_DATABASE_OPTIONS);ALLOWED_OPTION_MAP.put(COMMAND_SET_METADATA, SET_METADATA_OPTIONS);+ ALLOWED_OPTION_MAP.put(COMMAND_GET_METADATA, GET_METADATA_OPTIONS);ALLOWED_OPTION_MAP.put(COMMAND_ADD_EXE_CATEGORY, ADD_EXE_CATEGORY_OPTIONS);ALLOWED_OPTION_MAP.put(COMMAND_ADD_FUNCTION_TAG, ADD_FUNCTION_TAG_OPTIONS);ALLOWED_OPTION_MAP.put(COMMAND_DROP_INDEX, DROP_INDEX_OPTIONS);@@ -401,6 +404,10 @@ public class BSimLaunchable implements GhidraLaunchable {bsimURL = BSimClientFactory.deriveBSimURL(urlstring);doInstallMetadata(subParams);}+ else if (COMMAND_GET_METADATA.equals(command)) {+ bsimURL = BSimClientFactory.deriveBSimURL(urlstring);+ doPrintMetadata(subParams);+ }else if (COMMAND_ADD_EXE_CATEGORY.equals(command)) {bsimURL = BSimClientFactory.deriveBSimURL(urlstring);doInstallCategory(subParams);@@ -852,6 +859,22 @@ public class BSimLaunchable implements GhidraLaunchable {}}+ /**+ * Prints the BSim database metadata.+ *+ * This variant of the print metadata method is intended for command-line+ * users.+ *+ * @param params the command-line params+ * @throws IOException if there's an error establishing the database connection+ */+ private void doPrintMetadata(List<String> params) throws IOException, LSHException {++ try (BulkSignatures bsim = getBulkSignatures()) {+ bsim.printMetadata();+ }+ }+/*** Inserts a new category name into the BSim database.*@@ -949,6 +972,7 @@ public class BSimLaunchable implements GhidraLaunchable {"USAGE: bsim [command] required-args... [OPTIONS...]\n" +" createdatabase <bsimURL> <config_template> [--name|-n \"<name>\"] [--owner|-o \"<owner>\"] [--description|-d \"<text>\"] [--nocallgraph]\n" +" setmetadata <bsimURL> [--name|-n \"<name>\"] [--owner|-o \"<owner>\"] [--description|-d \"<text>\"]\n" ++ " getmetadata <bsimURL>\n" +" addexecategory <bsimURL> <category_name> [--date]\n" +" addfunctiontag <bsimURL> <tag_name>\n" +" dropindex <bsimURL>\n" +diff --git a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.javaindex 76e2ae4179..0d04fbf43e 100755--- a/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java+++ b/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java@@ -758,6 +758,19 @@ public class BulkSignatures implements AutoCloseable {Msg.info(this, " Description: " + info.description);}+ /**+ * Prints the metadata.+ *+ * @throws IOException if there's an error establishing the database connection+ */+ public void printMetadata() throws IOException {+ DatabaseInformation info = establishQueryServerConnection(false);+ Msg.info(this, "BSim metadata: ");+ Msg.info(this, " Database: " + info.databasename);+ Msg.info(this, " Owner: " + info.owner);+ Msg.info(this, " Description: " + info.description);+ }+/*** Performs the work of installing a new category name. This will build the query* object, establish the database connection, and perform the query.