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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Handle/BNBinaryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5268,6 +5268,34 @@ public void AddAutoSection(
infoData
);
}

public void AddAutoSections(SectionInfo[] sections)
{
if (null == sections)
{
throw new ArgumentNullException(nameof(sections));
}

using (ScopedAllocator allocator = new ScopedAllocator())
{
BNSectionInfo[] nativeSections = new BNSectionInfo[sections.Length];
for (int i = 0; i < sections.Length; i++)
{
if (null == sections[i])
{
throw new ArgumentException("Section entries cannot be null.", nameof(sections));
}

nativeSections[i] = sections[i].ToNative(allocator);
}

NativeMethods.BNAddAutoSections(
this.handle,
allocator.AllocStructArray(nativeSections),
new UIntPtr((uint)nativeSections.Length)
);
}
}

public void RemoveAutoSection(string name)
{
Expand Down Expand Up @@ -5301,6 +5329,34 @@ public void AddUserSection(
infoData
);
}

public void AddUserSections(SectionInfo[] sections)
{
if (null == sections)
{
throw new ArgumentNullException(nameof(sections));
}

using (ScopedAllocator allocator = new ScopedAllocator())
{
BNSectionInfo[] nativeSections = new BNSectionInfo[sections.Length];
for (int i = 0; i < sections.Length; i++)
{
if (null == sections[i])
{
throw new ArgumentException("Section entries cannot be null.", nameof(sections));
}

nativeSections[i] = sections[i].ToNative(allocator);
}

NativeMethods.BNAddUserSections(
this.handle,
allocator.AllocStructArray(nativeSections),
new UIntPtr((uint)nativeSections.Length)
);
}
}

public void RemoveUserSection(string name)
{
Expand Down
79 changes: 79 additions & 0 deletions Struct/BNSectionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Runtime.InteropServices;

namespace BinaryNinja
{
[StructLayout(LayoutKind.Sequential)]
internal struct BNSectionInfo
{
internal IntPtr name;
internal ulong start;
internal ulong length;
internal SectionSemantics semantics;
internal IntPtr type;
internal ulong align;
internal ulong entrySize;
internal IntPtr linkedSection;
internal IntPtr infoSection;
internal ulong infoData;
}

/// <summary>Describes a section for a bulk add operation.</summary>
public sealed class SectionInfo
{
public string Name { get; set; }
public ulong Start { get; set; }
public ulong Length { get; set; }
public SectionSemantics Semantics { get; set; }
public string Type { get; set; }
public ulong Align { get; set; }
public ulong EntrySize { get; set; }
public string LinkedSection { get; set; }
public string InfoSection { get; set; }
public ulong InfoData { get; set; }

public SectionInfo(
string name,
ulong start,
ulong length,
SectionSemantics semantics = SectionSemantics.DefaultSectionSemantics,
string type = "",
ulong align = 1,
ulong entrySize = 1,
string linkedSection = "",
string infoSection = "",
ulong infoData = 0
)
{
this.Name = name ?? throw new ArgumentNullException(nameof(name));
this.Start = start;
this.Length = length;
this.Semantics = semantics;
this.Type = type ?? throw new ArgumentNullException(nameof(type));
this.Align = align;
this.EntrySize = entrySize;
this.LinkedSection = linkedSection
?? throw new ArgumentNullException(nameof(linkedSection));
this.InfoSection = infoSection
?? throw new ArgumentNullException(nameof(infoSection));
this.InfoData = infoData;
}

internal BNSectionInfo ToNative(ScopedAllocator allocator)
{
return new BNSectionInfo()
{
name = allocator.AllocUtf8String(this.Name),
start = this.Start,
length = this.Length,
semantics = this.Semantics,
type = allocator.AllocUtf8String(this.Type),
align = this.Align,
entrySize = this.EntrySize,
linkedSection = allocator.AllocUtf8String(this.LinkedSection),
infoSection = allocator.AllocUtf8String(this.InfoSection),
infoData = this.InfoData,
};
}
}
}
Loading