GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tinysec/sharp-binaryninja: BinaryNinja dotnet C# Bindings (Typed, Safe, Native AOT Ready)

BranchesTags
Open more actions menu

Latest commit

 

History

204 Commits
204 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
Architecture
Architecture
 
 
Delegate
Delegate
 
 
Enumeration
Enumeration
 
 
Form
Form
 
 
Function
Function
 
 
Handle
Handle
 
 
HighLevelIL
HighLevelIL
 
 
IL
IL
 
 
LowLevelIL
LowLevelIL
 
 
MediumLevelIL
MediumLevelIL
 
 
Misc
Misc
 
 
Report
Report
 
 
Struct
Struct
 
 
Type
Type
 
 
.gitignore
.gitignore
 
 
.globalconfig
.globalconfig
 
 
BinaryNinja.csproj
BinaryNinja.csproj
 
 
Constant.cs
Constant.cs
 
 
ConstantRenderer.cs
ConstantRenderer.cs
 
 
CustomStringType.cs
CustomStringType.cs
 
 
GlobalPluginCommand.cs
GlobalPluginCommand.cs
 
 
ILFunctionNavigation.cs
ILFunctionNavigation.cs
 
 
InteractionFormApi.cs
InteractionFormApi.cs
 
 
InteractionHandler.cs
InteractionHandler.cs
 
 
InteractionHandlerForms.cs
InteractionHandlerForms.cs
 
 
InteractionHandlerInputs.cs
InteractionHandlerInputs.cs
 
 
InteractionHandlerRegistration.cs
InteractionHandlerRegistration.cs
 
 
InteractionHandlerReports.cs
InteractionHandlerReports.cs
 
 
LICENSE
LICENSE
 
 
LibraryResolver.cs
LibraryResolver.cs
 
 
Logging.cs
Logging.cs
 
 
MainThread.cs
MainThread.cs
 
 
NavigationExtensions.cs
NavigationExtensions.cs
 
 
PluginCommandGlobal.cs
PluginCommandGlobal.cs
 
 
ProjectNotification.cs
ProjectNotification.cs
 
 
README.md
README.md
 
 
ScopedAllocator.cs
ScopedAllocator.cs
 
 
StringRecognizer.cs
StringRecognizer.cs
 
 
UnsafeUtils.cs
UnsafeUtils.cs
 
 
Utils.cs
Utils.cs
 
 
WebsocketDelegates.cs
WebsocketDelegates.cs
 
 
WorkerQueues.cs
WorkerQueues.cs
 
 

Repository files navigation

BinaryNinja C# Bindings (Typed, Safe, Native AOT Ready)

NuGet License Platforms .NET

Modern, fully statically typed C# bindings for the Binary Ninja C API. Designed for safety, performance, and Native AOT compatibility. Use it as a dynamic library in your apps, compile CLI tools with Native AOT, or build native Binary Ninja plugins.

  • Statically typed API surface
  • 100% SafeHandle-based resource management
  • Idiomatic IDisposable/Dispose pattern
  • Native AOT friendly (no reflection-heavy runtime dependencies)
  • Works with .NET 8.0+

WARNING

  • Do not use this in production. The API is experimental and may introduce breaking changes without notice.

Install

dotnet add package BinaryNinja

Requirements

  • .NET 8.0 or newer
  • Binary Ninja installed (Desktop or Headless)
  • Ensure the Binary Ninja native libraries are discoverable at runtime:
    • environment variable: BINARYNINJA_BASE or BINARYNINJA_HOME (points to Binary Ninja installation root)

Using in cli

using System;
using BinaryNinja;

class Program
{
    static void Main()
    {
        NativeLibrary.SetDllImportResolver(
            typeof(BinaryNinja.Core).Assembly,
            new LibraryResolver().ResolveDllImport
		);
			
        Core.InitPlugins(true);
        
        using BinaryView? view = BinaryView.LoadFile("driver.sys.bndb");
        
        if (null == view)
        {
            throw new Exception("load fail");
        }
        
        foreach(Function function in view.Functions)
        {
            Console.WriteLine(function.RawName);
        }
       
        Core.Shutdown();
    }
}

Using in Plugin

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using BinaryNinja;

namespace Dummy
{
	public static class Plugin
	{
		static Plugin()
		{
			NativeLibrary.SetDllImportResolver(
				typeof(BinaryNinja.Core).Assembly,
				new LibraryResolver().ResolveDllImport
			);
		}
		
		[UnmanagedCallersOnly(
			EntryPoint = "CorePluginABIVersion", 
			CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })
		]
		public static uint CorePluginABIVersion()
		{
			return BinaryNinja.Core.CurrentCoreABIVersion;
		}
		
		[UnmanagedCallersOnly(EntryPoint = "CorePluginInit", CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
		public static byte CorePluginInit()
		{
			BinaryNinja.Core.LogInfo("[+] i am native aot plugin\n");
			
			BinaryNinja.Core.LogInfo( $"[+] Core CurrentCoreABIVersion: {Core.GetCurrentCoreABIVersion()}\n");
			
			BinaryNinja.Core.LogInfo( $"[+] Core MinimumCoreABIVersion: {Core.GetMinimumCoreABIVersion()}\n");
			
			BinaryNinja.Core.LogInfo( $"[+] Plugin CurrentCoreABIVersion: {Core.CurrentCoreABIVersion }\n");
			
			BinaryNinja.Logger logger = BinaryNinja.Logger.GetOrCreateLogger("Dummy");
			
			logger.LogInfo("[+] use private logger\n");
			
			BinaryNinja.PluginCommand.RegisterPluginCommand(
				"Dummy command",
				"Dummy command description",
				Plugin.DefaultCommand,
				Plugin.DefaultIsValid
			);
			
			logger.LogInfo("[+] init done.");
			
			return 1; // success
		}
        
        public static void DefaultCommand(BinaryView view )
		{
			Logger logger = BinaryNinja.Logger.GetOrCreateLogger("Dummy");
			
			logger.LogInfo($"view length: {view.Length}");

			Core.OpenUrl("https://github.com/tinysec/binaryninja");
			
			Function? function = view.ChooseFunction();
			
			if (null != function)
			{
				logger.LogInfo($"function , RawName: {function.RawName}");
			}
		}

		public static bool DefaultIsValid(BinaryView view )
		{
			return true;
		}
	}
}

Troubleshooting

  • DllNotFoundException / EntryPointNotFoundException
    • Ensure set BINARYNINJA_BASE
    • On Native AOT, confirm your RID is correct and you published with PublishAot=true
  • AccessViolationException
    • Check lifetime: ensure using-statements dispose views/sessions before exit
    • Make sure the target BN C API functions exist in the installed version

About

BinaryNinja dotnet C# Bindings (Typed, Safe, Native AOT Ready)

Topics

binaryninjadotnet

Resources

Readme
GPL-3.0 license
Activity

Stars

22 stars

Watchers

0 watching

Forks

4 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.