Skip to content

Commit 77da98d

Browse files
committed
Add SectionMap with bulk operations and batch section APIs.
1 parent 31d963f commit 77da98d

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

binaryninjaapi.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7840,6 +7840,15 @@ namespace BinaryNinja {
78407840
uint64_t entrySize = 0, const std::string& linkedSection = "", const std::string& infoSection = "",
78417841
uint64_t infoData = 0);
78427842

7843+
/*! Adds multiple automatically defined sections in a batch operation
7844+
7845+
This method is more efficient than calling AddAutoSection multiple times as it only triggers
7846+
one SectionMap rebuild for all sections.
7847+
7848+
\param sections Vector of BNSectionInfo describing the sections to add
7849+
*/
7850+
void AddAutoSections(const std::vector<BNSectionInfo>& sections);
7851+
78437852
/*! Remove an automatically defined section by name
78447853

78457854
\param name Name of the section
@@ -7867,6 +7876,17 @@ namespace BinaryNinja {
78677876
uint64_t entrySize = 0, const std::string& linkedSection = "", const std::string& infoSection = "",
78687877
uint64_t infoData = 0);
78697878

7879+
/*! Adds multiple user-defined sections in a batch operation
7880+
7881+
This method is more efficient than calling AddUserSection multiple times as it only triggers
7882+
one SectionMap rebuild for all sections.
7883+
7884+
Note that all data specified must already be mapped by an existing segment.
7885+
7886+
\param sections Vector of BNSectionInfo describing the sections to add
7887+
*/
7888+
void AddUserSections(const std::vector<BNSectionInfo>& sections);
7889+
78707890
/*! Remove a user defined section by name
78717891

78727892
\param name Name of the section to remove

binaryninjacore.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// Current ABI version for linking to the core. This is incremented any time
3838
// there are changes to the API that affect linking, including new functions,
3939
// new types, or modifications to existing functions or types.
40-
#define BN_CURRENT_CORE_ABI_VERSION 150
40+
#define BN_CURRENT_CORE_ABI_VERSION 151
4141

4242
// Minimum ABI version that is supported for loading of plugins. Plugins that
4343
// are linked to an ABI version less than this will not be able to load and
@@ -3682,6 +3682,19 @@ extern "C"
36823682
uint32_t flags;
36833683
} BNSegmentInfo;
36843684

3685+
typedef struct BNSectionInfo {
3686+
const char* name;
3687+
uint64_t start;
3688+
uint64_t length;
3689+
BNSectionSemantics semantics;
3690+
const char* type;
3691+
uint64_t align;
3692+
uint64_t entrySize;
3693+
const char* linkedSection;
3694+
const char* infoSection;
3695+
uint64_t infoData;
3696+
} BNSectionInfo;
3697+
36853698
typedef bool(*BNCollaborationAnalysisConflictHandler)(void*, const char** keys, BNAnalysisMergeConflict** conflicts, size_t conflictCount);
36863699
typedef bool(*BNCollaborationNameChangesetFunction)(void*, BNCollaborationChangeset*);
36873700

@@ -4566,10 +4579,12 @@ extern "C"
45664579
BINARYNINJACOREAPI void BNAddAutoSection(BNBinaryView* view, const char* name, uint64_t start, uint64_t length,
45674580
BNSectionSemantics semantics, const char* type, uint64_t align, uint64_t entrySize, const char* linkedSection,
45684581
const char* infoSection, uint64_t infoData);
4582+
BINARYNINJACOREAPI void BNAddAutoSections(BNBinaryView* view, const BNSectionInfo* sectionInfo, size_t count);
45694583
BINARYNINJACOREAPI void BNRemoveAutoSection(BNBinaryView* view, const char* name);
45704584
BINARYNINJACOREAPI void BNAddUserSection(BNBinaryView* view, const char* name, uint64_t start, uint64_t length,
45714585
BNSectionSemantics semantics, const char* type, uint64_t align, uint64_t entrySize, const char* linkedSection,
45724586
const char* infoSection, uint64_t infoData);
4587+
BINARYNINJACOREAPI void BNAddUserSections(BNBinaryView* view, const BNSectionInfo* sectionInfo, size_t count);
45734588
BINARYNINJACOREAPI void BNRemoveUserSection(BNBinaryView* view, const char* name);
45744589
BINARYNINJACOREAPI BNSection** BNGetSections(BNBinaryView* view, size_t* count);
45754590
BINARYNINJACOREAPI BNSection** BNGetSectionsAt(BNBinaryView* view, uint64_t addr, size_t* count);

binaryview.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5269,6 +5269,12 @@ void BinaryView::AddAutoSection(const string& name, uint64_t start, uint64_t len
52695269
}
52705270

52715271

5272+
void BinaryView::AddAutoSections(const vector<BNSectionInfo>& sections)
5273+
{
5274+
BNAddAutoSections(m_object, sections.data(), sections.size());
5275+
}
5276+
5277+
52725278
void BinaryView::RemoveAutoSection(const string& name)
52735279
{
52745280
BNRemoveAutoSection(m_object, name.c_str());
@@ -5284,6 +5290,12 @@ void BinaryView::AddUserSection(const string& name, uint64_t start, uint64_t len
52845290
}
52855291

52865292

5293+
void BinaryView::AddUserSections(const vector<BNSectionInfo>& sections)
5294+
{
5295+
BNAddUserSections(m_object, sections.data(), sections.size());
5296+
}
5297+
5298+
52875299
void BinaryView::RemoveUserSection(const string& name)
52885300
{
52895301
BNRemoveUserSection(m_object, name.c_str());

python/binaryview.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10054,6 +10054,16 @@ def add_auto_section(
1005410054
info_data
1005510055
)
1005610056

10057+
def add_auto_sections(self, sections: List[core.BNSectionInfo]) -> None:
10058+
"""
10059+
``add_auto_sections`` Adds analysis sections that specify semantic information about regions of the binary
10060+
10061+
:param List[core.BNSectionInfo] sections: list of sections to add
10062+
:rtype: None
10063+
"""
10064+
section_list = (core.BNSectionInfo * len(sections))(*sections)
10065+
core.BNAddAutoSections(self.handle, section_list, len(sections))
10066+
1005710067
def remove_auto_section(self, name: str) -> None:
1005810068
core.BNRemoveAutoSection(self.handle, name)
1005910069

@@ -10083,6 +10093,16 @@ def add_user_section(
1008310093
info_data
1008410094
)
1008510095

10096+
def add_user_sections(self, sections: List[core.BNSectionInfo]) -> None:
10097+
"""
10098+
``add_user_sections`` Adds user-defined sections that specify semantic information about regions of the binary
10099+
10100+
:param List[core.BNSectionInfo] sections: list of sections to add
10101+
:rtype: None
10102+
"""
10103+
section_list = (core.BNSectionInfo * len(sections))(*sections)
10104+
core.BNAddUserSections(self.handle, section_list, len(sections))
10105+
1008610106
def remove_user_section(self, name: str) -> None:
1008710107
core.BNRemoveUserSection(self.handle, name)
1008810108

0 commit comments

Comments
 (0)