Skip to content

Commit 326cb30

Browse files
committed
Add BinaryView::GetDataOffsetForAddress
1 parent 1ff4891 commit 326cb30

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

binaryninjaapi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6434,6 +6434,8 @@ namespace BinaryNinja {
64346434
*/
64356435
bool GetAddressForDataOffset(uint64_t offset, uint64_t& addr);
64366436

6437+
bool GetDataOffsetForAddress(uint64_t addr, uint64_t& offset);
6438+
64376439
/*! Creates an analysis-defined section that can help inform analysis by clarifying what types of data exist in
64386440
what ranges
64396441

binaryninjacore.h

Lines changed: 1 addition & 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 69
40+
#define BN_CURRENT_CORE_ABI_VERSION 70
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

binaryview.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4795,6 +4795,19 @@ bool BinaryView::GetAddressForDataOffset(uint64_t offset, uint64_t& addr)
47954795
}
47964796

47974797

4798+
bool BinaryView::GetDataOffsetForAddress(uint64_t addr, uint64_t& offset)
4799+
{
4800+
auto segment = GetSegmentAt(addr);
4801+
if (segment && segment->GetStart() <= addr && addr < segment->GetEnd())
4802+
{
4803+
offset = 0;
4804+
offset = addr - segment->GetStart() + segment->GetDataOffset();
4805+
return true;
4806+
}
4807+
return false;
4808+
}
4809+
4810+
47984811
void BinaryView::AddAutoSection(const string& name, uint64_t start, uint64_t length, BNSectionSemantics semantics,
47994812
const string& type, uint64_t align, uint64_t entrySize, const string& linkedSection, const string& infoSection,
48004813
uint64_t infoData)

0 commit comments

Comments
 (0)