summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py184
-rw-r--r--python/lowlevelil.py12
-rw-r--r--python/mediumlevelil.py1
-rw-r--r--python/types.py4
4 files changed, 152 insertions, 49 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 5e3e765d..8d44872b 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -470,32 +470,74 @@ class BinaryViewType(with_metaclass(_BinaryViewTypeMetaclass, object)):
class Segment(object):
- def __init__(self, start, length, data_offset, data_length, flags, auto_defined):
- self.start = start
- self.length = length
- self.data_offset = data_offset
- self.data_length = data_length
- self.flags = flags
- self.auto_defined = auto_defined
+ def __init__(self, handle):
+ self.handle = handle
+
+ @property
+ def start(self):
+ return core.BNSegmentGetStart(self.handle)
+
+ @property
+ def end(self):
+ return core.BNSegmentGetEnd(self.handle)
@property
def executable(self):
- return (self.flags & SegmentFlag.SegmentExecutable) != 0
+ return (core.BNSegmentGetFlags(self.handle) & SegmentFlag.SegmentExecutable) != 0
@property
def writable(self):
- return (self.flags & SegmentFlag.SegmentWritable) != 0
+ return (core.BNSegmentGetFlags(self.handle) & SegmentFlag.SegmentWritable) != 0
@property
def readable(self):
- return (self.flags & SegmentFlag.SegmentReadable) != 0
+ return (core.BNSegmentGetFlags(self.handle) & SegmentFlag.SegmentReadable) != 0
@property
def end(self):
- return self.start + self.length
+ return core.BNSegmentGetEnd(self.handle)
+
+ @property
+ def data_length(self):
+ return core.BNSegmentGetDataLength(self.handle)
+
+ @property
+ def data_offset(self):
+ return core.BNSegmentGetDataOffset(self.handle)
+
+ @property
+ 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 self.length
+ return core.BNSegmentGetLength(self.handle)
def __repr__(self):
return "<segment: %#x-%#x, %s%s%s>" % (self.start, self.end,
@@ -505,25 +547,55 @@ class Segment(object):
class Section(object):
- def __init__(self, name, section_type, start, length, linked_section, info_section, info_data, align, entry_size, semantics, auto_defined):
- self.name = name
- self.type = section_type
- self.start = start
- self.length = length
- self.linked_section = linked_section
- self.info_section = info_section
- self.info_data = info_data
- self.align = align
- self.entry_size = entry_size
- self.semantics = SectionSemantics(semantics)
- self.auto_defined = auto_defined
+ def __init__(self, handle):
+ self.handle = core.handle_of_type(handle, core.BNSection)
+
+ @property
+ def name(self):
+ return core.BNSectionGetName(self.handle)
+
+ @property
+ def type(self):
+ return core.BNSectionGetType(self.handle)
+
+ @property
+ def start(self):
+ return core.BNSectionGetStart(self.handle)
+
+ @property
+ def linked_section(self):
+ return core.BNSectionLinkedSection(self.handle)
+
+ @property
+ def info_section(self):
+ return core.BNSectionInfoSection(self.handle)
+
+ @property
+ def info_data(self):
+ return core.BNSectionInfoData(self.handle)
+
+ @property
+ def align(self):
+ return core.BNSectionAlign(self.handle)
+
+ @property
+ def entry_size(self):
+ return core.BNSectionEntrySize(self.handle)
+
+ @property
+ def semantics(self):
+ return SectionSemantics(core.BNSectionGetSemantics(self.handle))
+
+ @property
+ def auto_defined(self):
+ return core.BNSectionAutoDefined(self.handle)
@property
def end(self):
- return self.start + self.length
+ return self.start + len(self)
def __len__(self):
- return self.length
+ return core.BNSectionGetLength(self.handle)
def __repr__(self):
return "<section %s: %#x-%#x>" % (self.name, self.start, self.end)
@@ -1034,9 +1106,8 @@ class BinaryView(object):
segment_list = core.BNGetSegments(self.handle, count)
result = []
for i in range(0, count.value):
- result.append(Segment(segment_list[i].start, segment_list[i].length,
- segment_list[i].dataOffset, segment_list[i].dataLength, segment_list[i].flags, segment_list[i].autoDefined))
- core.BNFreeSegmentList(segment_list)
+ result.append(Segment(core.BNNewSegmentReference(segment_list[i])))
+ core.BNFreeSegmentList(segment_list, count.value)
return result
@property
@@ -1046,10 +1117,7 @@ class BinaryView(object):
section_list = core.BNGetSections(self.handle, count)
result = {}
for i in range(0, count.value):
- result[section_list[i].name] = Section(section_list[i].name, section_list[i].type, section_list[i].start,
- section_list[i].length, section_list[i].linkedSection, section_list[i].infoSection,
- section_list[i].infoData, section_list[i].align, section_list[i].entrySize,
- section_list[i].semantics, section_list[i].autoDefined)
+ result[core.BNSectionGetName(section_list[i])] = Section(section_list[i])
core.BNFreeSectionList(section_list, count.value)
return result
@@ -1099,6 +1167,29 @@ class BinaryView(object):
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
+
+ @property
def new_auto_function_analysis_suppressed(self):
"""Whether or not automatically discovered functions will be analyzed"""
return core.BNGetNewAutoFunctionAnalysisSuppressed(self.handle)
@@ -1897,6 +1988,16 @@ class BinaryView(object):
"""
return core.BNIsOffsetCodeSemantics(self.handle, addr)
+ def is_offset_extern_semantics(self, addr):
+ """
+ ``is_offset_extern_semantics`` checks if an virtual address ``addr`` is semantically valid for external references.
+
+ :param int addr: a virtual address to be checked
+ :return: true if the virtual address is valid for writing, false if the virtual address is invalid or error
+ :rtype: bool
+ """
+ return core.BNIsOffsetExternSemantics(self.handle, addr)
+
def is_offset_writable_semantics(self, addr):
"""
``is_offset_writable_semantics`` checks if an virtual address ``addr`` is semantically writable. Some sections
@@ -3458,12 +3559,10 @@ class BinaryView(object):
core.BNRemoveUserSegment(self.handle, start, length)
def get_segment_at(self, addr):
- segment = core.BNSegment()
- if not core.BNGetSegmentAt(self.handle, addr, segment):
+ seg = core.BNGetSegmentAt(self.handle, addr)
+ if not seg:
return None
- result = Segment(segment.start, segment.length, segment.dataOffset, segment.dataLength,
- segment.flags, segment.autoDefined)
- return result
+ return Segment(seg)
def get_address_for_data_offset(self, offset):
address = ctypes.c_ulonglong()
@@ -3492,10 +3591,7 @@ class BinaryView(object):
section_list = core.BNGetSectionsAt(self.handle, addr, count)
result = []
for i in range(0, count.value):
- result.append(Section(section_list[i].name, section_list[i].type, section_list[i].start,
- section_list[i].length, section_list[i].linkedSection, section_list[i].infoSection,
- section_list[i].infoData, section_list[i].align, section_list[i].entrySize,
- section_list[i].semantics, section_list[i].autoDefined))
+ result.append(Section(section_list[i]))
core.BNFreeSectionList(section_list, count.value)
return result
@@ -3503,9 +3599,7 @@ class BinaryView(object):
section = core.BNSection()
if not core.BNGetSectionByName(self.handle, name, section):
return None
- result = Section(section.name, section.type, section.start, section.length, section.linkedSection,
- section.infoSection, section.infoData, section.align, section.entrySize, section.semantics,
- section.autoDefined)
+ result = Section(section)
core.BNFreeSection(section)
return result
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index 41579719..f7f8926c 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -225,6 +225,7 @@ class LowLevelILInstruction(object):
LowLevelILOperation.LLIL_REG_STACK_FREE_REL: [("stack", "reg_stack"), ("dest", "expr")],
LowLevelILOperation.LLIL_CONST: [("constant", "int")],
LowLevelILOperation.LLIL_CONST_PTR: [("constant", "int")],
+ LowLevelILOperation.LLIL_EXTERN_PTR: [("constant", "int"), ("offset", "int")],
LowLevelILOperation.LLIL_FLOAT_CONST: [("constant", "float")],
LowLevelILOperation.LLIL_FLAG: [("src", "flag")],
LowLevelILOperation.LLIL_FLAG_BIT: [("src", "flag"), ("bit", "int")],
@@ -1098,6 +1099,17 @@ class LowLevelILFunction(object):
"""
return self.expr(LowLevelILOperation.LLIL_CONST_PTR, value, size=size)
+ def reloc_pointer(self, size, value):
+ """
+ ``reloc_pointer`` returns an expression for the constant relocated pointer ``value`` with size ``size``
+
+ :param int size: the size of the pointer in bytes
+ :param int value: address referenced by pointer
+ :return: A constant expression of given value and size
+ :rtype: LowLevelILExpr
+ """
+ return self.expr(LowLevelILOperation.LLIL_EXTERN_PTR, value, size=size)
+
def float_const_raw(self, size, value):
"""
``float_const_raw`` returns an expression for the constant raw binary floating point
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index c024d287..a506767c 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -94,6 +94,7 @@ class MediumLevelILInstruction(object):
MediumLevelILOperation.MLIL_ADDRESS_OF_FIELD: [("src", "var"), ("offset", "int")],
MediumLevelILOperation.MLIL_CONST: [("constant", "int")],
MediumLevelILOperation.MLIL_CONST_PTR: [("constant", "int")],
+ MediumLevelILOperation.MLIL_EXTERN_PTR: [("constant", "int"), ("offset", "int")],
MediumLevelILOperation.MLIL_FLOAT_CONST: [("constant", "float")],
MediumLevelILOperation.MLIL_IMPORT: [("constant", "int")],
MediumLevelILOperation.MLIL_ADD: [("left", "expr"), ("right", "expr")],
diff --git a/python/types.py b/python/types.py
index 12e7733f..b78b7109 100644
--- a/python/types.py
+++ b/python/types.py
@@ -192,10 +192,6 @@ class Symbol(object):
def auto(self):
return core.BNIsSymbolAutoDefined(self.handle)
- @auto.setter
- def auto(self, value):
- core.BNSetSymbolAutoDefined(self.handle, value)
-
def __repr__(self):
return "<%s: \"%s\" @ %#x>" % (self.type, self.full_name, self.address)