From aae6c3aecdb04e8a6e33799287737a33a634418d Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Mon, 9 Jan 2017 21:58:55 -0500 Subject: Wrapping some unwrapped enumeration values, and adding il basic block indexing --- python/architecture.py | 2 +- python/binaryview.py | 4 ++-- python/function.py | 11 ++++++----- python/lowlevelil.py | 12 ++++++++++-- 4 files changed, 19 insertions(+), 10 deletions(-) (limited to 'python') diff --git a/python/architecture.py b/python/architecture.py index c95c71a0..f1440ca3 100644 --- a/python/architecture.py +++ b/python/architecture.py @@ -176,7 +176,7 @@ class Architecture(object): self._flag_roles = {} self.__dict__["flag_roles"] = {} for flag in self.__dict__["flags"]: - role = core.BNGetArchitectureFlagRole(self.handle, self._flags[flag]) + role = FlagRole(core.BNGetArchitectureFlagRole(self.handle, self._flags[flag])) self.__dict__["flag_roles"][flag] = role self._flag_roles[self._flags[flag]] = role diff --git a/python/binaryview.py b/python/binaryview.py index b19ecbd6..3467dcc3 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -708,7 +708,7 @@ class BinaryView(object): @property def endianness(self): """Endianness of the binary (read-only)""" - return core.BNGetDefaultEndianness(self.handle) + return Endianness(core.BNGetDefaultEndianness(self.handle)) @property def address_size(self): @@ -1577,7 +1577,7 @@ class BinaryView(object): :rtype: ModificationStatus or str """ if length is None: - return core.BNGetModification(self.handle, addr) + return ModificationStatus(core.BNGetModification(self.handle, addr)) data = (ModificationStatus * length)() length = core.BNGetModificationArray(self.handle, addr, data, length) return data[0:length] diff --git a/python/function.py b/python/function.py index e3c79312..1843dd3d 100644 --- a/python/function.py +++ b/python/function.py @@ -25,7 +25,8 @@ import ctypes # Binary Ninja components import _binaryninjacore as core from enums import (FunctionGraphType, BranchType, SymbolType, InstructionTextTokenType, - HighlightStandardColor, RegisterValueType, ImplicitRegisterExtend, DisassemblyOption, IntegerDisplayType) + HighlightStandardColor, HighlightColorStyle, RegisterValueType, ImplicitRegisterExtend, + DisassemblyOption, IntegerDisplayType) import architecture import highlight import associateddatastore @@ -47,7 +48,7 @@ class LookupTableEntry(object): class RegisterValue(object): def __init__(self, arch, value): - self.type = value.state + self.type = RegisterValueType(value.state) if value.state == RegisterValueType.EntryValue: self.reg = arch.get_reg_name(value.reg) elif value.state == RegisterValueType.OffsetFromEntryValue: @@ -682,7 +683,7 @@ class Function(object): def get_int_display_type(self, instr_addr, value, operand, arch=None): if arch is None: arch = self.arch - return core.BNGetIntegerConstantDisplayType(self.handle, arch.handle, instr_addr, value, operand) + return IntegerDisplayType(core.BNGetIntegerConstantDisplayType(self.handle, arch.handle, instr_addr, value, operand)) def set_int_display_type(self, instr_addr, value, operand, display_type, arch=None): """ @@ -831,7 +832,7 @@ class DisassemblyTextLine(object): class FunctionGraphEdge: def __init__(self, branch_type, arch, target, points): - self.type = branch_type + self.type = BranchType(branch_type) self.arch = arch self.target = target self.points = points @@ -1237,7 +1238,7 @@ class InstructionTextToken(object): """ def __init__(self, token_type, text, value = 0, size = 0, operand = 0xffffffff): - self.type = token_type + self.type = InstructionTextTokenType(token_type) self.text = text self.value = value self.size = size diff --git a/python/lowlevelil.py b/python/lowlevelil.py index 4564bf13..419e8513 100644 --- a/python/lowlevelil.py +++ b/python/lowlevelil.py @@ -118,8 +118,7 @@ class LowLevelILInstruction(object): self.function = func self.expr_index = expr_index self.instr_index = instr_index - self.operation = instr.operation - self.operation_name = LowLevelILOperation(instr.operation) + self.operation = LowLevelILOperation(instr.operation) self.size = instr.size self.address = instr.address self.source_operand = instr.sourceOperand @@ -1261,6 +1260,15 @@ class LowLevelILBasicBlock(basicblock.BasicBlock): for idx in xrange(self.start, self.end): yield self.il_function[idx] + def __getitem__(self, idx): + size = self.end - self.start + if idx > size or idx < -size: + raise IndexError("list index is out of range") + if idx >= 0: + return self.il_function[idx + self.start] + else: + return self.il_function[self.end + idx] + def LLIL_TEMP(n): return n | 0x80000000 -- cgit v1.3.1