Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
135 changes: 135 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: build

on:
push:
branches:
- master
pull_request:
branches:
- master

env:
VERSION_MAJOR: 0
VERSION_MINOR: 1

jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
build: ${{ steps.version.outputs.build }}
revision: ${{ steps.version.outputs.revision }}
steps:
- name: checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: generate version
id: version
shell: bash
run: |
BUILD_NUMBER=0
REVISION=${{ github.run_number }}
VERSION="${{ env.VERSION_MAJOR }}.${{ env.VERSION_MINOR }}.${BUILD_NUMBER}.${REVISION}"

echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "build=${BUILD_NUMBER}" >> $GITHUB_OUTPUT
echo "revision=${REVISION}" >> $GITHUB_OUTPUT

echo "Generated version: ${VERSION}"
echo " - Build: ${BUILD_NUMBER}"
echo " - Revision (Run Number): ${REVISION}"

build:
needs: version
strategy:
matrix:
include:
- os: windows-latest
platform: windows
- os: ubuntu-latest
platform: linux

runs-on: ${{ matrix.os }}

steps:
- name: checkout
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 8.0.x

- name: build (Linux)
if: runner.os == 'Linux'
run: |
echo "[+] build linux"
dotnet publish -r linux-x64 --self-contained=true -c Release -p:PublishDir=build /p:Version=${{ needs.version.outputs.version }} /p:FileVersion=${{ needs.version.outputs.version }} /p:AssemblyVersion=${{ needs.version.outputs.version }} /p:ProductVersion=${{ needs.version.outputs.version }}

- name: build (Windows)
if: runner.os == 'Windows'
run: |
echo "[+] build windows"
dotnet publish -r win-x64 --self-contained=true -c Release -p:PublishDir=build /p:Version=${{ needs.version.outputs.version }} /p:FileVersion=${{ needs.version.outputs.version }} /p:AssemblyVersion=${{ needs.version.outputs.version }} /p:ProductVersion=${{ needs.version.outputs.version }}

- name: collect artifacts
shell: bash
run: |
mkdir -p artifacts
cp build/* artifacts/
ls -lh artifacts

- name: upload artifacts
uses: actions/upload-artifact@v3
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
name: ${{ matrix.platform }}-v${{ needs.version.outputs.version }}
path: artifacts/*.*

release:
needs: [ version , build ]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.ref == 'refs/heads/master' && github.event_name == 'push'
steps:
- name: checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: download artifacts
uses: actions/download-artifact@v3
with:
path: artifacts

- name: create release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.version.outputs.version }}
name: release v${{ needs.version.outputs.version }}
generate_releases: true
draft: false
prerelease: true
files: artifacts/*.*

- name: publish to NuGet
if: secrets.NUGET_TOKEN != ''
env:
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}
run: |
echo "[+] Publishing NuGet packages with version ${{ needs.version.outputs.version }}"
shopt -s globstar nullglob

for pkg in artifacts/**/*.nupkg; do
if [[ "$pkg" == *.snupkg ]]; then
continue
fi
echo "-> dotnet nuget push $pkg"
dotnet nuget push "$pkg" \
--api-key "$NUGET_AUTH_TOKEN" \
--source "https://api.nuget.org/v3/index.json" \
--skip-duplicate
done
61 changes: 7 additions & 54 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,54 +1,7 @@
## A streamlined .gitignore for modern .NET projects
## including temporary files, build results, and
## files generated by popular .NET tools. If you are
## developing with Visual Studio, the VS .gitignore
## https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
## has more thorough IDE-specific entries.
##
## Get latest from https://github.com/github/gitignore/blob/main/Dotnet.gitignore

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/

# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/

# ASP.NET Scaffolding
ScaffoldingReadMe.txt

# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg

# Others
~$*
*~
CodeCoverage/

# MSBuild Binary and Structured Log
*.binlog

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# dir
.idea/
obj/
bin/
dist/
build/
Folder.DotSettings.user/
3 changes: 3 additions & 0 deletions .globalconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
is_global = true
dotnet_diagnostic.CA1510.severity = none
dotnet_diagnostic.CA1822.severity = none
33 changes: 33 additions & 0 deletions BinaryNinja.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>BinaryNinja</RootNamespace>
<AssemblyName>BinaryNinja</AssemblyName>

<TargetFramework>net8.0</TargetFramework>
<LangVersion>latestmajor</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>library</OutputType>

<NativeLib>Shared</NativeLib>
<PublishAot>true</PublishAot>
<IsAotCompatible>true</IsAotCompatible>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<!-- version -->
<Version>0.1.0.0</Version>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
<FileVersion>0.1.0.0</FileVersion>
<ProductVersion>0.1.0.0</ProductVersion>
<Company>tinysec.net</Company>
<Product>SharpBinja</Product>
<Copyright>tinysec©2006-2025</Copyright>
<Description>BinaryNinja dotnet bindings</Description>
</PropertyGroup>

<!-- for Windows -->
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'win-x64'">
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
</PropertyGroup>
</Project>
10 changes: 10 additions & 0 deletions Constant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace BinaryNinja
{
public static partial class Core
{
public const byte MaxConfidence = 255;

// BN_CURRENT_CORE_ABI_VERSION 147
public const uint CurrentCoreABIVersion = 147;
}
}
48 changes: 48 additions & 0 deletions Delegate/BNProgressFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

namespace BinaryNinja
{
public delegate bool ProgressDelegate(

// uint64_t param2
ulong param2 ,

// uint64_t param3
ulong param3
);

internal static partial class NativeDelegates
{
/// <summary>
///
/// typedef bool (*BNProgressFunction)(void* param1, uint64_t param2, uint64_t param3)
/// </summary>
[UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.Cdecl)]
internal delegate bool BNProgressFunction(

// void* param1
IntPtr param1 ,

// uint64_t param2
ulong param2 ,

// uint64_t param3
ulong param3
);
}

internal static partial class UnsafeUtils
{
internal static NativeDelegates.BNProgressFunction WrapProgressDelegate(
ProgressDelegate callback)
{
return bool (param1 , param2 , param3) =>
{
return callback(param2 , param3);
};
}
}
}
35 changes: 35 additions & 0 deletions Delegate/MatchConstantDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace BinaryNinja
{
public delegate bool MatchConstantDelegate
(
ulong address ,
LinearDisassemblyLine line
);

internal static partial class NativeDelegates
{
// bool (*matchCallback)(void* matchCtxt, uint64_t addr, BNLinearDisassemblyLine* line)
public delegate bool MatchConstantDelegate(
IntPtr matchCtxt,
ulong address,
IntPtr line
);
}

internal static partial class UnsafeUtils
{
internal static NativeDelegates.MatchConstantDelegate WrapMatchConstantDelegate(
MatchConstantDelegate callback)
{
return bool (matchCtxt , address , line) =>
{
return callback (
address ,
LinearDisassemblyLine.MustFromNativePointer(line)
);
};
}
}
}
35 changes: 35 additions & 0 deletions Delegate/MatchDataDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace BinaryNinja
{
public delegate bool MatchDataDelegate
(
ulong address ,
byte[] data
);

internal static partial class NativeDelegates
{
// bool (*matchCallback)(void* matchCtxt, uint64_t addr, BNDataBuffer* match)
public delegate bool MatchDataDelegate(
IntPtr matchCtxt,
ulong address,
IntPtr match
);
}

internal static partial class UnsafeUtils
{
internal static NativeDelegates.MatchDataDelegate WrapMatchDataDelegate(
MatchDataDelegate callback)
{
return bool (matchCtxt , address , buffer) =>
{
return callback(
address ,
DataBuffer.MustBorrowHandle(buffer).Contents
);
};
}
}
}
Loading