From 635c06c68ec72e579573f87ab86996b5952bf853 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Fri, 29 Jun 2018 16:54:48 -0400 Subject: Add api for querying relocation --- python/binaryview.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'python') diff --git a/python/binaryview.py b/python/binaryview.py index 0b090a9a..ba99f9f9 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -466,6 +466,33 @@ class Segment(object): def data_end(self): return core.BNSegmentGetDataEnd(self.handle) + @property + def reloction_count(self): + return core.BNSegmentGetRelocationsCount(self.handle) + + @property + def relocation_ranges(self): + """List of relocation range tuples (read-only)""" + + count = ctypes.c_ulonglong() + ranges = core.BNSegmentGetRelocationRanges(self.handle, count) + result = [] + for i in xrange(0, count.value): + result.append((ranges[i].start, ranges[i].end)) + core.BNFreeRelocationRanges(ranges, count) + return result + + def relocation_ranges_at(self, addr): + """List of relocation range tuples (read-only)""" + + count = ctypes.c_ulonglong() + ranges = core.BNSegmentGetRelocationRangesAtAddress(self.handle, addr, count) + result = [] + for i in xrange(0, count.value): + result.append((ranges[i].start, ranges[i].end)) + core.BNFreeRelocationRanges(ranges, count) + return result + def __len__(self): return core.BNSegmentGetLength(self.handle) @@ -1074,6 +1101,29 @@ class BinaryView(object): def max_function_size_for_analysis(self, size): core.BNSetMaxFunctionSizeForAnalysis(self.handle, size) + @property + def relocation_ranges(self): + """List of relocation range tuples (read-only)""" + + count = ctypes.c_ulonglong() + ranges = core.BNGetRelocationRanges(self.handle, count) + result = [] + for i in xrange(0, count.value): + result.append((ranges[i].start, ranges[i].end)) + core.BNFreeRelocationRanges(ranges, count) + return result + + def relocation_ranges_at(self, addr): + """List of relocation range tuples for a given address""" + + count = ctypes.c_ulonglong() + ranges = core.BNGetRelocationRangesAtAddress(self.handle, addr, count) + result = [] + for i in xrange(0, count.value): + result.append((ranges[i].start, ranges[i].end)) + core.BNFreeRelocationRanges(ranges, count) + return result + def __len__(self): return int(core.BNGetViewLength(self.handle)) -- cgit v1.3.1