summaryrefslogtreecommitdiff
path: root/plugins/bntl_utils/cli/src/main.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2026-02-11 18:04:07 -0800
committerMason Reed <35282038+emesare@users.noreply.github.com>2026-02-23 00:09:44 -0800
commit37008b7fa16837d04c1658868646cad681cbe035 (patch)
tree577c2b62ee47c78a5d31d11f2aa610e441f5c808 /plugins/bntl_utils/cli/src/main.rs
parent837f8590be80b7c98162e70e4f0c1814b83e9d7b (diff)
Add BNTL utility plugin
Allow users to easily create, diff, dump and validate type libraries Supports the following formats: - C header files (via core type parsers) - Binary files (collects exported and imported functions) - WinMD files (via `windows-metadata` crate) - Existing type library files (for easy fixups) - Apiset files (to resolve through forwarded windows dlls) Can be invoked as a regular plugin via UI commands or via CLI. Processing of type libraries inherently requires external linking, processing will automatically merge and deduplicate colliding type libraries so prefer to use inside a project or a directory and process all information (for a given platform) at once, rather than smaller invocations.
Diffstat (limited to 'plugins/bntl_utils/cli/src/main.rs')
-rw-r--r--plugins/bntl_utils/cli/src/main.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/plugins/bntl_utils/cli/src/main.rs b/plugins/bntl_utils/cli/src/main.rs
new file mode 100644
index 00000000..1466da1f
--- /dev/null
+++ b/plugins/bntl_utils/cli/src/main.rs
@@ -0,0 +1,71 @@
+use clap::Parser;
+use tracing::level_filters::LevelFilter;
+use tracing_subscriber::EnvFilter;
+use tracing_subscriber::layer::SubscriberExt;
+use tracing_subscriber::util::SubscriberInitExt;
+
+mod create;
+mod diff;
+mod dump;
+mod input;
+mod validate;
+
+/// Generate, inspect, and validate Binary Ninja type libraries (BNTL)
+#[derive(Parser, Debug)]
+#[clap(author, version, about, long_about = None)]
+struct Cli {
+ #[clap(subcommand)]
+ command: Command,
+}
+
+#[derive(Parser, Debug)]
+pub enum Command {
+ /// Create a new type library from a set of files.
+ Create(create::CreateArgs),
+ /// Dump the type library to a C header file.
+ Dump(dump::DumpArgs),
+ /// Generate a diff between two type libraries.
+ Diff(diff::DiffArgs),
+ /// Validate the type libraries for common errors.
+ Validate(validate::ValidateArgs),
+}
+
+impl Command {
+ pub fn execute(&self) {
+ match self {
+ Command::Create(args) => {
+ args.execute();
+ }
+ Command::Dump(args) => {
+ args.execute();
+ }
+ Command::Diff(args) => {
+ args.execute();
+ }
+ Command::Validate(args) => {
+ args.execute();
+ }
+ }
+ }
+}
+
+fn main() {
+ let cli = Cli::parse();
+ tracing_subscriber::registry()
+ .with(tracing_subscriber::fmt::layer())
+ .with(
+ EnvFilter::builder()
+ .with_default_directive(LevelFilter::INFO.into())
+ .from_env_lossy(),
+ )
+ .init();
+
+ // Capture logs from Binary Ninja
+ let _listener = binaryninja::tracing::TracingLogListener::new().register();
+
+ // Initialize Binary Ninja, requires a headless compatible license like commercial or ultimate.
+ let _session = binaryninja::headless::Session::new()
+ .expect("Failed to create headless binary ninja session");
+
+ cli.command.execute();
+}