diff options
| author | Peter LaFosse <peter@vector35.com> | 2017-01-02 16:15:07 -0500 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2017-01-02 16:15:07 -0500 |
| commit | 2421d9a6e6e86ff3f37056a68454b7437fb60860 (patch) | |
| tree | 3b41f418698d458d12c9c0862141d29a57b9bd1f /python | |
| parent | e3fa8dcb0e4e6cb97a4b45ba1919048e5eae578d (diff) | |
Manual merging with dev
Diffstat (limited to 'python')
| -rw-r--r-- | python/binaryview.py | 29 | ||||
| -rw-r--r-- | python/bntype.py | 18 | ||||
| -rw-r--r-- | python/examples/nsf.py | 138 | ||||
| -rw-r--r-- | python/lowlevelil.py | 267 |
4 files changed, 307 insertions, 145 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 7c85cd52..b4be159c 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -590,6 +590,16 @@ class BinaryView(object): @classmethod def set_default_session_data(cls, name, value): + """ + ```set_default_session_data``` saves a variable to the BinaryView. + :param name: name of the variable to be saved + :param value: value of the variable to be saved + + :Example: + >>> BinaryView.set_default_session_data("variable_name", "value") + >>> bv.session_data.variable_name + 'value' + """ _BinaryViewAssociatedDataStore.set_default(name, value) def __del__(self): @@ -1932,6 +1942,19 @@ class BinaryView(object): return basicblock.BasicBlock(self, block) def get_code_refs(self, addr, length=None): + """ + ``get_code_refs`` returns a list of ReferenceSource objects (xrefs or cross-references) that point to the provided virtual address. + + :param int addr: virtual address to query for references + :return: List of References for the given virtual address + :rtype: list(ReferenceSource) + :Example: + + >>> bv.get_code_refs(here) + [<ref: x86@0x4165ff>] + >>> + + """ count = ctypes.c_ulonglong(0) if length is None: refs = core.BNGetCodeReferences(self.handle, addr, count) @@ -3434,7 +3457,7 @@ class BinaryWriter(object): def write16(self, value): """ - ```` writes the lowest order two bytes from the integer ``value`` to the current offset, using internal endianness. + ``write16`` writes the lowest order two bytes from the integer ``value`` to the current offset, using internal endianness. :param int value: integer value to write. :return: boolean True on success, False on failure. @@ -3444,7 +3467,7 @@ class BinaryWriter(object): def write32(self, value): """ - ```` writes the lowest order four bytes from the integer ``value`` to the current offset, using internal endianness. + ``write32`` writes the lowest order four bytes from the integer ``value`` to the current offset, using internal endianness. :param int value: integer value to write. :return: boolean True on success, False on failure. @@ -3454,7 +3477,7 @@ class BinaryWriter(object): def write64(self, value): """ - ```` writes the lowest order eight bytes from the integer ``value`` to the current offset, using internal endianness. + ``write64`` writes the lowest order eight bytes from the integer ``value`` to the current offset, using internal endianness. :param int value: integer value to write. :return: boolean True on success, False on failure. diff --git a/python/bntype.py b/python/bntype.py index 9f070168..1822c5df 100644 --- a/python/bntype.py +++ b/python/bntype.py @@ -235,8 +235,8 @@ class Type(object): return Type(core.BNCreateBoolType()) @classmethod - def int(self, width, sign = True): - return Type(core.BNCreateIntegerType(width, sign)) + def int(self, width, sign = True, altname=""): + return Type(core.BNCreateIntegerType(width, sign, altname)) @classmethod def float(self, width): @@ -251,13 +251,13 @@ class Type(object): return Type(core.BNCreateUnknownType(unknown_type.handle)) @classmethod - def enumeration_type(self, arch, e, width = None): + def enumeration_type(self, arch, e, width=None): if width is None: width = arch.default_int_size return Type(core.BNCreateEnumerationType(e.handle, width)) @classmethod - def pointer(self, arch, t, const = False): + def pointer(self, arch, t, const=False): return Type(core.BNCreatePointerType(arch.handle, t.handle, const)) @classmethod @@ -265,7 +265,7 @@ class Type(object): return Type(core.BNCreateArrayType(t.handle, count)) @classmethod - def function(self, ret, params, calling_convention = None, variable_arguments = False): + def function(self, ret, params, calling_convention=None, variable_arguments=False): param_buf = (core.BNNameAndType * len(params))() for i in xrange(0, len(params)): if isinstance(params[i], Type): @@ -287,7 +287,7 @@ class Type(object): class UnknownType(object): - def __init__(self, handle = None): + def __init__(self, handle=None): if handle is None: self.handle = core.BNCreateUnknownType() else: @@ -324,7 +324,7 @@ class StructureMember(object): class Structure(object): - def __init__(self, handle = None): + def __init__(self, handle=None): if handle is None: self.handle = core.BNCreateStructure() else: @@ -416,7 +416,7 @@ class EnumerationMember(object): class Enumeration(object): - def __init__(self, handle = None): + def __init__(self, handle=None): if handle is None: self.handle = core.BNCreateEnumeration() else: @@ -472,7 +472,7 @@ class TypeParserResult(object): return "{types: %s, variables: %s, functions: %s}" % (self.types, self.variables, self.functions) -def preprocess_source(source, filename = None, include_dirs = []): +def preprocess_source(source, filename=None, include_dirs=[]): """ ``preprocess_source`` run the C preprocessor on the given source or source filename. diff --git a/python/examples/nsf.py b/python/examples/nsf.py new file mode 100644 index 00000000..9d4ebd5c --- /dev/null +++ b/python/examples/nsf.py @@ -0,0 +1,138 @@ +# Copyright (c) 2015-2016 Vector 35 LLC +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# +# Simple NSF file loader, primarily for analyzing: +# https://scarybeastsecurity.blogspot.com/2016/11/0day-exploit-compromising-linux-desktop.html +# + +from binaryninja import * +import struct +import traceback +import os + +class NSFView(BinaryView): + name = "NSF" + long_name = "Nintendo Sound Format" + + def __init__(self, data): + BinaryView.__init__(self, parent_view = data, file_metadata = data.file) + + @classmethod + def is_valid_for_data(self, data): + hdr = data.read(0, 128) + if len(hdr) < 128: + return False + if hdr[0:5] != "NESM\x1a": + return False + song_count = struct.unpack("B", hdr[6])[0] + if song_count < 1: + log_info("Appears to be an NSF, but no songs.") + return False + return True + + def init(self): + try: + hdr = self.parent_view.read(0, 128) + self.version = struct.unpack("B", hdr[5])[0] + self.song_count = struct.unpack("B", hdr[6])[0] + self.starting_song = struct.unpack("B", hdr[7])[0] + self.load_address = struct.unpack("<H", hdr[8:10])[0] + self.init_address = struct.unpack("<H", hdr[10:12])[0] + self.play_address = struct.unpack("<H", hdr[12:14])[0] + self.song_name = hdr[15].split('\0')[0] + self.artist_name = hdr[46].split('\0')[0] + self.copyright_name = hdr[78].split('\0')[0] + self.play_speed_ntsc = struct.unpack("<H", hdr[110:112])[0] + self.bank_switching = hdr[112:120] + self.play_speed_pal = struct.unpack("<H", hdr[120:122])[0] + self.pal_ntsc_bits = struct.unpack("B", hdr[122])[0] + self.pal = True if (self.pal_ntsc_bits & 1) == 1 else False + self.ntsc = not self.pal + if self.pal_ntsc_bits & 2 == 2: + self.pal = True + self.ntsc = True + self.extra_sound_bits = struct.unpack("B", hdr[123])[0] + + if self.bank_switching == "\0"*8: + #no bank switching + self.load_address & 0xFFF + self.rom_offset = 128 + + else: + #bank switching not implemented + log_info("Bank switching not implemented in this loader.") + + # Add mapping for RAM and hardware registers, not backed by file contents + self.add_auto_segment(0, 0x8000, 0, 0, SegmentReadable | SegmentWritable | SegmentExecutable) + + # Add ROM mappings + self.add_auto_segment(0x8000, 0x4000, self.rom_offset, 0x4000, + SegmentReadable | SegmentExecutable) + + self.define_auto_symbol(Symbol(FunctionSymbol, self.play_address, "_play")) + self.define_auto_symbol(Symbol(FunctionSymbol, self.init_address, "_init")) + self.add_entry_point(Architecture['6502'].standalone_platform, self.init_address) + self.add_function(Architecture['6502'].standalone_platform, self.play_address) + + # Hardware registers + self.define_auto_symbol(Symbol(DataSymbol, 0x2000, "PPUCTRL")) + self.define_auto_symbol(Symbol(DataSymbol, 0x2001, "PPUMASK")) + self.define_auto_symbol(Symbol(DataSymbol, 0x2002, "PPUSTATUS")) + self.define_auto_symbol(Symbol(DataSymbol, 0x2003, "OAMADDR")) + self.define_auto_symbol(Symbol(DataSymbol, 0x2004, "OAMDATA")) + self.define_auto_symbol(Symbol(DataSymbol, 0x2005, "PPUSCROLL")) + self.define_auto_symbol(Symbol(DataSymbol, 0x2006, "PPUADDR")) + self.define_auto_symbol(Symbol(DataSymbol, 0x2007, "PPUDATA")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4000, "SQ1_VOL")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4001, "SQ1_SWEEP")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4002, "SQ1_LO")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4003, "SQ1_HI")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4004, "SQ2_VOL")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4005, "SQ2_SWEEP")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4006, "SQ2_LO")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4007, "SQ2_HI")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4008, "TRI_LINEAR")) + self.define_auto_symbol(Symbol(DataSymbol, 0x400a, "TRI_LO")) + self.define_auto_symbol(Symbol(DataSymbol, 0x400b, "TRI_HI")) + self.define_auto_symbol(Symbol(DataSymbol, 0x400c, "NOISE_VOL")) + self.define_auto_symbol(Symbol(DataSymbol, 0x400e, "NOISE_LO")) + self.define_auto_symbol(Symbol(DataSymbol, 0x400f, "NOISE_HI")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4010, "DMC_FREQ")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4011, "DMC_RAW")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4012, "DMC_START")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4013, "DMC_LEN")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4014, "OAMDMA")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4015, "SND_CHN")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4016, "JOY1")) + self.define_auto_symbol(Symbol(DataSymbol, 0x4017, "JOY2")) + + return True + except: + log_error(traceback.format_exc()) + return False + + def perform_is_executable(self): + return True + + def perform_get_entry_point(self): + return struct.unpack("<H", str(self.perform_read(0x0a, 2)))[0] + +NSFView.register() diff --git a/python/lowlevelil.py b/python/lowlevelil.py index 2f1c7608..7025a7c1 100644 --- a/python/lowlevelil.py +++ b/python/lowlevelil.py @@ -43,76 +43,76 @@ class LowLevelILInstruction(object): """ ILOperations = { - core.BNLowLevelILOperation.LLIL_NOP: [], - core.BNLowLevelILOperation.LLIL_SET_REG: [("dest", "reg"), ("src", "expr")], + core.BNLowLevelILOperation.LLIL_NOP: [], + core.BNLowLevelILOperation.LLIL_SET_REG: [("dest", "reg"), ("src", "expr")], core.BNLowLevelILOperation.LLIL_SET_REG_SPLIT: [("hi", "reg"), ("lo", "reg"), ("src", "expr")], - core.BNLowLevelILOperation.LLIL_SET_FLAG: [("dest", "flag"), ("src", "expr")], - core.BNLowLevelILOperation.LLIL_LOAD: [("src", "expr")], - core.BNLowLevelILOperation.LLIL_STORE: [("dest", "expr"), ("src", "expr")], - core.BNLowLevelILOperation.LLIL_PUSH: [("src", "expr")], - core.BNLowLevelILOperation.LLIL_POP: [], - core.BNLowLevelILOperation.LLIL_REG: [("src", "reg")], - core.BNLowLevelILOperation.LLIL_CONST: [("value", "int")], - core.BNLowLevelILOperation.LLIL_FLAG: [("src", "flag")], - core.BNLowLevelILOperation.LLIL_FLAG_BIT: [("src", "flag"), ("bit", "int")], - core.BNLowLevelILOperation.LLIL_ADD: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_ADC: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_SUB: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_SBB: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_AND: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_OR: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_XOR: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_LSL: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_LSR: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_ASR: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_ROL: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_RLC: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_ROR: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_RRC: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_MUL: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_MULU_DP: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_MULS_DP: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_DIVU: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_DIVU_DP: [("hi", "expr"), ("lo", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_DIVS: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_DIVS_DP: [("hi", "expr"), ("lo", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_MODU: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_MODU_DP: [("hi", "expr"), ("lo", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_MODS: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_MODS_DP: [("hi", "expr"), ("lo", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_NEG: [("src", "expr")], - core.BNLowLevelILOperation.LLIL_NOT: [("src", "expr")], - core.BNLowLevelILOperation.LLIL_SX: [("src", "expr")], - core.BNLowLevelILOperation.LLIL_ZX: [("src", "expr")], - core.BNLowLevelILOperation.LLIL_JUMP: [("dest", "expr")], - core.BNLowLevelILOperation.LLIL_JUMP_TO: [("dest", "expr"), ("targets", "int_list")], - core.BNLowLevelILOperation.LLIL_CALL: [("dest", "expr")], - core.BNLowLevelILOperation.LLIL_RET: [("dest", "expr")], - core.BNLowLevelILOperation.LLIL_NORET: [], - core.BNLowLevelILOperation.LLIL_IF: [("condition", "expr"), ("true", "int"), ("false", "int")], - core.BNLowLevelILOperation.LLIL_GOTO: [("dest", "int")], - core.BNLowLevelILOperation.LLIL_FLAG_COND: [("condition", "cond")], - core.BNLowLevelILOperation.LLIL_CMP_E: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_CMP_NE: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_CMP_SLT: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_CMP_ULT: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_CMP_SLE: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_CMP_ULE: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_CMP_SGE: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_CMP_UGE: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_CMP_SGT: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_CMP_UGT: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_TEST_BIT: [("left", "expr"), ("right", "expr")], - core.BNLowLevelILOperation.LLIL_BOOL_TO_INT: [("src", "expr")], - core.BNLowLevelILOperation.LLIL_SYSCALL: [], - core.BNLowLevelILOperation.LLIL_BP: [], - core.BNLowLevelILOperation.LLIL_TRAP: [("value", "int")], - core.BNLowLevelILOperation.LLIL_UNDEF: [], - core.BNLowLevelILOperation.LLIL_UNIMPL: [], - core.BNLowLevelILOperation.LLIL_UNIMPL_MEM: [("src", "expr")] + core.BNLowLevelILOperation.LLIL_SET_FLAG: [("dest", "flag"), ("src", "expr")], + core.BNLowLevelILOperation.LLIL_LOAD: [("src", "expr")], + core.BNLowLevelILOperation.LLIL_STORE: [("dest", "expr"), ("src", "expr")], + core.BNLowLevelILOperation.LLIL_PUSH: [("src", "expr")], + core.BNLowLevelILOperation.LLIL_POP: [], + core.BNLowLevelILOperation.LLIL_REG: [("src", "reg")], + core.BNLowLevelILOperation.LLIL_CONST: [("value", "int")], + core.BNLowLevelILOperation.LLIL_FLAG: [("src", "flag")], + core.BNLowLevelILOperation.LLIL_FLAG_BIT: [("src", "flag"), ("bit", "int")], + core.BNLowLevelILOperation.LLIL_ADD: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_ADC: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_SUB: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_SBB: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_AND: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_OR: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_XOR: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_LSL: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_LSR: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_ASR: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_ROL: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_RLC: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_ROR: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_RRC: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_MUL: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_MULU_DP: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_MULS_DP: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_DIVU: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_DIVU_DP: [("hi", "expr"), ("lo", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_DIVS: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_DIVS_DP: [("hi", "expr"), ("lo", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_MODU: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_MODU_DP: [("hi", "expr"), ("lo", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_MODS: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_MODS_DP: [("hi", "expr"), ("lo", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_NEG: [("src", "expr")], + core.BNLowLevelILOperation.LLIL_NOT: [("src", "expr")], + core.BNLowLevelILOperation.LLIL_SX: [("src", "expr")], + core.BNLowLevelILOperation.LLIL_ZX: [("src", "expr")], + core.BNLowLevelILOperation.LLIL_JUMP: [("dest", "expr")], + core.BNLowLevelILOperation.LLIL_JUMP_TO: [("dest", "expr"), ("targets", "int_list")], + core.BNLowLevelILOperation.LLIL_CALL: [("dest", "expr")], + core.BNLowLevelILOperation.LLIL_RET: [("dest", "expr")], + core.BNLowLevelILOperation.LLIL_NORET: [], + core.BNLowLevelILOperation.LLIL_IF: [("condition", "expr"), ("true", "int"), ("false", "int")], + core.BNLowLevelILOperation.LLIL_GOTO: [("dest", "int")], + core.BNLowLevelILOperation.LLIL_FLAG_COND: [("condition", "cond")], + core.BNLowLevelILOperation.LLIL_CMP_E: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_CMP_NE: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_CMP_SLT: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_CMP_ULT: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_CMP_SLE: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_CMP_ULE: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_CMP_SGE: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_CMP_UGE: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_CMP_SGT: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_CMP_UGT: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_TEST_BIT: [("left", "expr"), ("right", "expr")], + core.BNLowLevelILOperation.LLIL_BOOL_TO_INT: [("src", "expr")], + core.BNLowLevelILOperation.LLIL_SYSCALL: [], + core.BNLowLevelILOperation.LLIL_BP: [], + core.BNLowLevelILOperation.LLIL_TRAP: [("value", "int")], + core.BNLowLevelILOperation.LLIL_UNDEF: [], + core.BNLowLevelILOperation.LLIL_UNIMPL: [], + core.BNLowLevelILOperation.LLIL_UNIMPL_MEM: [("src", "expr")] } - def __init__(self, func, expr_index, instr_index = None): + def __init__(self, func, expr_index, instr_index=None): instr = core.BNGetLowLevelILByIndex(func.handle, expr_index) self.function = func self.expr_index = expr_index @@ -411,7 +411,7 @@ class LowLevelILFunction(object): :return: The expression ``[addr].size`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_LOAD, addr.index, size = size) + return self.expr(core.BNLowLevelILOperation.LLIL_LOAD, addr.index, size=size) def store(self, size, addr, value): """ @@ -423,7 +423,7 @@ class LowLevelILFunction(object): :return: The expression ``[addr].size = value`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_STORE, addr.index, value.index, size = size) + return self.expr(core.BNLowLevelILOperation.LLIL_STORE, addr.index, value.index, size=size) def push(self, size, value): """ @@ -434,7 +434,7 @@ class LowLevelILFunction(object): :return: The expression push(value) :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_PUSH, value.index, size = size) + return self.expr(core.BNLowLevelILOperation.LLIL_PUSH, value.index, size=size) def pop(self, size): """ @@ -444,7 +444,7 @@ class LowLevelILFunction(object): :return: The expression ``pop`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_POP, size = size) + return self.expr(core.BNLowLevelILOperation.LLIL_POP, size=size) def reg(self, size, reg): """ @@ -457,7 +457,7 @@ class LowLevelILFunction(object): """ if isinstance(reg, str): reg = self.arch.regs[reg].index - return self.expr(core.BNLowLevelILOperation.LLIL_REG, reg, size = size) + return self.expr(core.BNLowLevelILOperation.LLIL_REG, reg, size=size) def const(self, size, value): """ @@ -468,7 +468,7 @@ class LowLevelILFunction(object): :return: A constant expression of given value and size :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_CONST, value, size = size) + return self.expr(core.BNLowLevelILOperation.LLIL_CONST, value, size=size) def flag(self, reg): """ @@ -490,9 +490,9 @@ class LowLevelILFunction(object): :return: A constant expression of given value and size ``FLAG.reg = bit`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_FLAG_BIT, self.arch.get_flag_by_name(reg), bit, size = size) + return self.expr(core.BNLowLevelILOperation.LLIL_FLAG_BIT, self.arch.get_flag_by_name(reg), bit, size=size) - def add(self, size, a, b, flags = None): + def add(self, size, a, b, flags=None): """ ``add`` adds expression ``a`` to expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -504,9 +504,9 @@ class LowLevelILFunction(object): :return: The expression ``add.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_ADD, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_ADD, a.index, b.index, size=size, flags=flags) - def add_carry(self, size, a, b, flags = None): + def add_carry(self, size, a, b, flags=None): """ ``add_carry`` adds with carry expression ``a`` to expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -518,9 +518,9 @@ class LowLevelILFunction(object): :return: The expression ``adc.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_ADC, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_ADC, a.index, b.index, size=size, flags=flags) - def sub(self, size, a, b, flags = None): + def sub(self, size, a, b, flags=None): """ ``sub`` subtracts expression ``b`` from expression ``a`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -532,9 +532,9 @@ class LowLevelILFunction(object): :return: The expression ``sub.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_SUB, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_SUB, a.index, b.index, size=size, flags=flags) - def sub_borrow(self, size, a, b, flags = None): + def sub_borrow(self, size, a, b, flags=None): """ ``sub_borrow`` subtracts with borrow expression ``b`` from expression ``a`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -546,9 +546,9 @@ class LowLevelILFunction(object): :return: The expression ``sbc.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_SBB, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_SBB, a.index, b.index, size=size, flags=flags) - def and_expr(self, size, a, b, flags = None): + def and_expr(self, size, a, b, flags=None): """ ``and_expr`` bitwise and's expression ``a`` and expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -560,9 +560,9 @@ class LowLevelILFunction(object): :return: The expression ``and.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_AND, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_AND, a.index, b.index, size=size, flags=flags) - def or_expr(self, size, a, b, flags = None): + def or_expr(self, size, a, b, flags=None): """ ``or_expr`` bitwise or's expression ``a`` and expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -574,9 +574,9 @@ class LowLevelILFunction(object): :return: The expression ``or.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_OR, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_OR, a.index, b.index, size=size, flags=flags) - def xor_expr(self, size, a, b, flags = None): + def xor_expr(self, size, a, b, flags=None): """ ``xor_expr`` xor's expression ``a`` with expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -588,9 +588,9 @@ class LowLevelILFunction(object): :return: The expression ``xor.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_XOR, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_XOR, a.index, b.index, size=size, flags=flags) - def shift_left(self, size, a, b, flags = None): + def shift_left(self, size, a, b, flags=None): """ ``shift_left`` subtracts with borrow expression ``b`` from expression ``a`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -602,9 +602,9 @@ class LowLevelILFunction(object): :return: The expression ``lsl.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_LSL, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_LSL, a.index, b.index, size=size, flags=flags) - def logical_shift_right(self, size, a, b, flags = None): + def logical_shift_right(self, size, a, b, flags=None): """ ``logical_shift_right`` shifts logically right expression ``a`` by expression ``b`` potentially setting flags ``flags``and returning an expression of ``size`` bytes. @@ -616,9 +616,9 @@ class LowLevelILFunction(object): :return: The expression ``lsr.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_LSR, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_LSR, a.index, b.index, size=size, flags=flags) - def arith_shift_right(self, size, a, b, flags = None): + def arith_shift_right(self, size, a, b, flags=None): """ ``arith_shift_right`` shifts arithmatic right expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -630,9 +630,9 @@ class LowLevelILFunction(object): :return: The expression ``asr.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_ASR, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_ASR, a.index, b.index, size=size, flags=flags) - def rotate_left(self, size, a, b, flags = None): + def rotate_left(self, size, a, b, flags=None): """ ``rotate_left`` bitwise rotates left expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -644,9 +644,9 @@ class LowLevelILFunction(object): :return: The expression ``rol.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_ROL, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_ROL, a.index, b.index, size=size, flags=flags) - def rotate_left_carry(self, size, a, b, flags = None): + def rotate_left_carry(self, size, a, b, flags=None): """ ``rotate_left_carry`` bitwise rotates left with carry expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -658,9 +658,9 @@ class LowLevelILFunction(object): :return: The expression ``rcl.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.LLIL_RLC, a.index, b.index, size = size, flags = flags) + return self.expr(core.LLIL_RLC, a.index, b.index, size=size, flags=flags) - def rotate_right(self, size, a, b, flags = None): + def rotate_right(self, size, a, b, flags=None): """ ``rotate_right`` bitwise rotates right expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -672,9 +672,9 @@ class LowLevelILFunction(object): :return: The expression ``ror.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_ROR, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_ROR, a.index, b.index, size=size, flags=flags) - def rotate_right_carry(self, size, a, b, flags = None): + def rotate_right_carry(self, size, a, b, flags=None): """ ``rotate_right_carry`` bitwise rotates right with carry expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -686,9 +686,9 @@ class LowLevelILFunction(object): :return: The expression ``rcr.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_RRC, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_RRC, a.index, b.index, size=size, flags=flags) - def mult(self, size, a, b, flags = None): + def mult(self, size, a, b, flags=None): """ ``mult`` multiplies expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -700,9 +700,9 @@ class LowLevelILFunction(object): :return: The expression ``sbc.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_MUL, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_MUL, a.index, b.index, size=size, flags=flags) - def mult_double_prec_signed(self, size, a, b, flags = None): + def mult_double_prec_signed(self, size, a, b, flags=None): """ ``mult_double_prec_signed`` multiplies signed with double precision expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -714,9 +714,9 @@ class LowLevelILFunction(object): :return: The expression ``muls.dp.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_MULS_DP, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_MULS_DP, a.index, b.index, size=size, flags=flags) - def mult_double_prec_unsigned(self, size, a, b, flags = None): + def mult_double_prec_unsigned(self, size, a, b, flags=None): """ ``mult_double_prec_unsigned`` multiplies unsigned with double precision expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -728,9 +728,9 @@ class LowLevelILFunction(object): :return: The expression ``muls.dp.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_MULU_DP, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_MULU_DP, a.index, b.index, size=size, flags=flags) - def div_signed(self, size, a, b, flags = None): + def div_signed(self, size, a, b, flags=None): """ ``div_signed`` signed divide expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -742,9 +742,9 @@ class LowLevelILFunction(object): :return: The expression ``divs.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_DIVS, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_DIVS, a.index, b.index, size=size, flags=flags) - def div_double_prec_signed(self, size, hi, lo, b, flags = None): + def div_double_prec_signed(self, size, hi, lo, b, flags=None): """ ``div_double_prec_signed`` signed double precision divide using expression ``hi`` and expression ``lo`` as a single double precision register by expression ``b`` potentially setting flags ``flags`` and returning an @@ -758,9 +758,9 @@ class LowLevelILFunction(object): :return: The expression ``divs.dp.<size>{<flags>}(hi:lo, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_DIVS_DP, hi.index, lo.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_DIVS_DP, hi.index, lo.index, b.index, size=size, flags=flags) - def div_unsigned(self, size, a, b, flags = None): + def div_unsigned(self, size, a, b, flags=None): """ ``div_unsigned`` unsigned divide expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -772,9 +772,9 @@ class LowLevelILFunction(object): :return: The expression ``divs.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_DIVS, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_DIVS, a.index, b.index, size=size, flags=flags) - def div_double_prec_unsigned(self, size, hi, lo, b, flags = None): + def div_double_prec_unsigned(self, size, hi, lo, b, flags=None): """ ``div_double_prec_unsigned`` unsigned double precision divide using expression ``hi`` and expression ``lo`` as a single double precision register by expression ``b`` potentially setting flags ``flags`` and returning an @@ -788,9 +788,9 @@ class LowLevelILFunction(object): :return: The expression ``divs.dp.<size>{<flags>}(hi:lo, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_DIVS_DP, hi.index, lo.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_DIVS_DP, hi.index, lo.index, b.index, size=size, flags=flags) - def mod_signed(self, size, a, b, flags = None): + def mod_signed(self, size, a, b, flags=None): """ ``mod_signed`` signed modulus expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -802,9 +802,9 @@ class LowLevelILFunction(object): :return: The expression ``mods.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_MODS, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_MODS, a.index, b.index, size=size, flags=flags) - def mod_double_prec_signed(self, size, hi, lo, b, flags = None): + def mod_double_prec_signed(self, size, hi, lo, b, flags=None): """ ``mod_double_prec_signed`` signed double precision modulus using expression ``hi`` and expression ``lo`` as a single double precision register by expression ``b`` potentially setting flags ``flags`` and returning an expression @@ -818,9 +818,9 @@ class LowLevelILFunction(object): :return: The expression ``mods.dp.<size>{<flags>}(hi:lo, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_MODS_DP, hi.index, lo.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_MODS_DP, hi.index, lo.index, b.index, size=size, flags=flags) - def mod_unsigned(self, size, a, b, flags = None): + def mod_unsigned(self, size, a, b, flags=None): """ ``mod_unsigned`` unsigned modulus expression ``a`` by expression ``b`` potentially setting flags ``flags`` and returning an expression of ``size`` bytes. @@ -832,9 +832,9 @@ class LowLevelILFunction(object): :return: The expression ``modu.<size>{<flags>}(a, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_MODS, a.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_MODS, a.index, b.index, size=size, flags=flags) - def mod_double_prec_unsigned(self, size, hi, lo, b, flags = None): + def mod_double_prec_unsigned(self, size, hi, lo, b, flags=None): """ ``mod_double_prec_unsigned`` unsigned double precision modulus using expression ``hi`` and expression ``lo`` as a single double precision register by expression ``b`` potentially setting flags ``flags`` and returning an @@ -848,9 +848,9 @@ class LowLevelILFunction(object): :return: The expression ``modu.dp.<size>{<flags>}(hi:lo, b)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_MODS_DP, hi.index, lo.index, b.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_MODS_DP, hi.index, lo.index, b.index, size=size, flags=flags) - def neg_expr(self, size, value, flags = None): + def neg_expr(self, size, value, flags=None): """ ``neg_expr`` two's complement sign negation of expression ``value`` of size ``size`` potentially setting flags @@ -860,9 +860,9 @@ class LowLevelILFunction(object): :return: The expression ``neg.<size>{<flags>}(value)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_NEG, value.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_NEG, value.index, size=size, flags=flags) - def not_expr(self, size, value, flags = None): + def not_expr(self, size, value, flags=None): """ ``not_expr`` bitwise inverse of expression ``value`` of size ``size`` potentially setting flags @@ -872,29 +872,30 @@ class LowLevelILFunction(object): :return: The expression ``not.<size>{<flags>}(value)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_NOT, value.index, size = size, flags = flags) + return self.expr(core.BNLowLevelILOperation.LLIL_NOT, value.index, size=size, flags=flags) - def sign_extend(self, size, value): + def sign_extend(self, size, value, flags=None): """ ``sign_extend`` two's complement sign-extends the expression in ``value`` to ``size`` bytes :param int size: the size of the result in bytes - :param LowLevelILExpr value: the expression to sign extend + :param LowLevelILExpr value: the expression to sign extn + :param str flags: optional, flags to set :return: The expression ``sx.<size>(value)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_SX, value.index, size = size) + return self.expr(core.BNLowLevelILOperation.LLIL_SX, value.index, size=size, flags=flags) def zero_extend(self, size, value): """ - ``sign_extend`` zero-extends the expression in ``value`` to ``size`` bytes + ``zero_extend`` zero-extends the expression in ``value`` to ``size`` bytes :param int size: the size of the result in bytes :param LowLevelILExpr value: the expression to zero extend :return: The expression ``sx.<size>(value)`` :rtype: LowLevelILExpr """ - return self.expr(core.BNLowLevelILOperation.LLIL_ZX, value.index, size = size) + return self.expr(core.BNLowLevelILOperation.LLIL_ZX, value.index, size=size) def jump(self, dest): """ |
