diff options
| author | Peter LaFosse <peter@vector35.com> | 2021-09-05 12:30:47 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2021-09-06 11:46:44 -0400 |
| commit | 7070c4efa14e8816d5c429c5c92bf1ad9a4f30eb (patch) | |
| tree | a0c5b6b12db79117fe0802d55adc60fc02b91775 /python | |
| parent | 6d279124d1ee8c03dec6938f8a4ebb08f646b4c2 (diff) | |
Fix import of log
Diffstat (limited to 'python')
| -rw-r--r-- | python/architecture.py | 120 | ||||
| -rw-r--r-- | python/binaryview.py | 108 | ||||
| -rw-r--r-- | python/callingconvention.py | 42 | ||||
| -rw-r--r-- | python/datarender.py | 8 | ||||
| -rw-r--r-- | python/debuginfo.py | 6 | ||||
| -rw-r--r-- | python/downloadprovider.py | 38 | ||||
| -rw-r--r-- | python/fileaccessor.py | 8 | ||||
| -rw-r--r-- | python/filemetadata.py | 8 | ||||
| -rw-r--r-- | python/flowgraph.py | 16 | ||||
| -rw-r--r-- | python/functionrecognizer.py | 6 | ||||
| -rw-r--r-- | python/interaction.py | 30 | ||||
| -rw-r--r-- | python/plugin.py | 36 | ||||
| -rw-r--r-- | python/scriptingprovider.py | 53 | ||||
| -rw-r--r-- | python/transform.py | 10 | ||||
| -rw-r--r-- | python/update.py | 4 | ||||
| -rw-r--r-- | python/websocketprovider.py | 8 | ||||
| -rw-r--r-- | python/workflow.py | 8 |
17 files changed, 255 insertions, 254 deletions
diff --git a/python/architecture.py b/python/architecture.py index bbed133a..15b0e7ff 100644 --- a/python/architecture.py +++ b/python/architecture.py @@ -28,7 +28,7 @@ import binaryninja from . import _binaryninjacore as core from .enums import (Endianness, ImplicitRegisterExtend, BranchType, LowLevelILFlagCondition, FlagRole, LowLevelILOperation) -from . import log +from .log import log_error from . import lowlevelil from . import types from . import databuffer @@ -554,42 +554,42 @@ class Architecture(metaclass=_ArchitectureMetaClass): try: return self.endianness except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return Endianness.LittleEndian def _get_address_size(self, ctxt): try: return self.address_size except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 8 def _get_default_integer_size(self, ctxt): try: return self.default_int_size except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 4 def _get_instruction_alignment(self, ctxt): try: return self.instr_alignment except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 1 def _get_max_instruction_length(self, ctxt): try: return self.max_instr_length except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 16 def _get_opcode_display_length(self, ctxt): try: return self.opcode_display_length except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 8 def _get_associated_arch_by_address(self, ctxt, addr): @@ -598,7 +598,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): addr[0] = new_addr return ctypes.cast(result.handle, ctypes.c_void_p).value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return ctypes.cast(self.handle, ctypes.c_void_p).value def _get_instruction_info(self, ctxt, data, addr, max_len, result): @@ -625,7 +625,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): result[0].branchArch[i] = arch.handle return True except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_instruction_text(self, ctxt, data, addr, length, result, count): @@ -644,7 +644,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_token_lists[ptr.value] = (ptr.value, token_buf) return True except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _free_instruction_text(self, tokens, count): @@ -654,7 +654,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): raise ValueError("freeing token list that wasn't allocated") del self._pending_token_lists[buf.value] except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_instruction_low_level_il(self, ctxt, data, addr, length, il): try: @@ -667,7 +667,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): length[0] = result return True except OSError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_register_name(self, ctxt, reg): @@ -676,7 +676,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return core.BNAllocString(self._regs_by_index[reg]) return core.BNAllocString("") except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return core.BNAllocString("") def _get_flag_name(self, ctxt, flag): @@ -685,7 +685,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return core.BNAllocString(self._flags_by_index[flag]) return core.BNAllocString("") except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return core.BNAllocString("") def _get_flag_write_type_name(self, ctxt, write_type:FlagWriteTypeIndex): @@ -694,7 +694,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return core.BNAllocString(self._flag_write_types_by_index[write_type]) return core.BNAllocString("") except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return core.BNAllocString("") def _get_semantic_flag_class_name(self, ctxt, sem_class): @@ -703,7 +703,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return core.BNAllocString(self._semantic_flag_classes_by_index[sem_class]) return core.BNAllocString("") except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return core.BNAllocString("") def _get_semantic_flag_group_name(self, ctxt, sem_group): @@ -712,7 +712,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return core.BNAllocString(self._semantic_flag_groups_by_index[sem_group]) return core.BNAllocString("") except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return core.BNAllocString("") def _get_full_width_registers(self, ctxt, count): @@ -726,7 +726,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -741,7 +741,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -756,7 +756,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, flag_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -771,7 +771,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, type_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -786,7 +786,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, class_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -801,7 +801,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, group_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -831,7 +831,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, flag_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -849,7 +849,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, flag_buf) return result.value except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -870,7 +870,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_condition_lists[result.value] = (result, cond_buf) return result.value except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -881,7 +881,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): raise ValueError("freeing condition list that wasn't allocated") del self._pending_condition_lists[buf.value] except (ValueError, KeyError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_flags_written_by_flag_write_type(self, ctxt, write_type, count): try: @@ -897,7 +897,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, flag_buf) return result.value except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -908,7 +908,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): else: return 0 except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _get_flag_write_low_level_il(self, ctxt, op, size, write_type, flag, operands, operand_count, il): @@ -928,7 +928,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return self.get_flag_write_low_level_il(op, size, write_type_name, flag_name, operand_list, lowlevelil.LowLevelILFunction(self, core.BNNewLowLevelILFunctionReference(il))) except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_flag_condition_low_level_il(self, ctxt, cond, sem_class, il): @@ -940,7 +940,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return self.get_flag_condition_low_level_il(cond, sem_class_name, lowlevelil.LowLevelILFunction(self, core.BNNewLowLevelILFunctionReference(il))) except OSError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _get_semantic_flag_group_low_level_il(self, ctxt, sem_group, il): @@ -952,7 +952,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return self.get_semantic_flag_group_low_level_il(sem_group_name, lowlevelil.LowLevelILFunction(self, core.BNNewLowLevelILFunctionReference(il))) except OSError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _free_register_list(self, ctxt, regs): @@ -962,7 +962,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): raise ValueError("freeing register list that wasn't allocated") del self._pending_reg_lists[buf.value] except (ValueError, KeyError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_register_info(self, ctxt, reg, result): try: @@ -981,7 +981,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): else: result[0].extend = info.extend except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) result[0].fullWidthRegister = 0 result[0].offset = 0 result[0].size = 0 @@ -993,7 +993,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): try: return self._all_regs[self.stack_pointer] except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _get_link_register(self, ctxt): @@ -1002,7 +1002,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return 0xffffffff return self._all_regs[self.link_reg] except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _get_global_registers(self, ctxt, count): @@ -1015,7 +1015,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -1029,7 +1029,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -1039,7 +1039,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return core.BNAllocString(self._reg_stacks_by_index[reg_stack]) return core.BNAllocString("") except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return core.BNAllocString("") def _get_all_register_stacks(self, ctxt, count): @@ -1053,7 +1053,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -1077,7 +1077,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): result[0].topRelativeCount = 0 result[0].stackTopReg = self._all_regs[info.stack_top_reg] except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) result[0].firstStorageReg = 0 result[0].firstTopRelativeReg = 0 result[0].storageCount = 0 @@ -1090,7 +1090,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): return core.BNAllocString(self._intrinsics_by_index[intrinsic][0]) return core.BNAllocString("") except (KeyError, OSError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return core.BNAllocString("") def _get_all_intrinsics(self, ctxt, count): @@ -1104,7 +1104,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except KeyError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -1124,7 +1124,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): count[0] = 0 return None except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -1139,7 +1139,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): core.BNFreeType(name_and_types[i].type) del self._pending_name_and_type_lists[buf.value] except (ValueError, KeyError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_intrinsic_outputs(self, ctxt, intrinsic, count): try: @@ -1156,7 +1156,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): count[0] = 0 return None except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -1171,7 +1171,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): core.BNFreeType(types[i].type) del self._pending_type_lists[buf.value] except (ValueError, KeyError): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _assemble(self, ctxt, code, addr, result, errors): """ @@ -1188,11 +1188,11 @@ class Architecture(metaclass=_ArchitectureMetaClass): core.BNSetDataBufferContents(result, buf, len(data)) return True except ValueError as e: # Overridden `assemble` functions should raise a ValueError if the input was invalid (with a reasonable error message) - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) errors[0] = core.BNAllocString(str(e)) return False except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) errors[0] = core.BNAllocString("Unhandled exception during assembly.\n") return False @@ -1202,7 +1202,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): ctypes.memmove(buf, data, length) return self.is_never_branch_patch_available(buf.raw, addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _is_always_branch_patch_available(self, ctxt, data, addr, length): @@ -1211,7 +1211,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): ctypes.memmove(buf, data, length) return self.is_always_branch_patch_available(buf.raw, addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _is_invert_branch_patch_available(self, ctxt, data, addr, length): @@ -1220,7 +1220,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): ctypes.memmove(buf, data, length) return self.is_invert_branch_patch_available(buf.raw, addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _is_skip_and_return_zero_patch_available(self, ctxt, data, addr, length): @@ -1229,7 +1229,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): ctypes.memmove(buf, data, length) return self.is_skip_and_return_zero_patch_available(buf.raw, addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _is_skip_and_return_value_patch_available(self, ctxt, data, addr, length): @@ -1238,7 +1238,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): ctypes.memmove(buf, data, length) return self.is_skip_and_return_value_patch_available(buf.raw, addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _convert_to_nop(self, ctxt, data, addr, length): @@ -1253,7 +1253,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): ctypes.memmove(data, result, len(result)) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _always_branch(self, ctxt, data, addr, length): @@ -1268,7 +1268,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): ctypes.memmove(data, result, len(result)) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _invert_branch(self, ctxt, data, addr, length): @@ -1283,7 +1283,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): ctypes.memmove(data, result, len(result)) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _skip_and_return_value(self, ctxt, data, addr, length, value): @@ -1298,7 +1298,7 @@ class Architecture(metaclass=_ArchitectureMetaClass): ctypes.memmove(data, result, len(result)) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def get_associated_arch_by_address(self, addr:int) -> Tuple['Architecture', int]: @@ -1436,8 +1436,8 @@ class Architecture(metaclass=_ArchitectureMetaClass): assert index is not None return index except KeyError: - log.log_error(f"Failed to map string {reg} to register index: ") - log.log_error(traceback.format_exc()) + log_error(f"Failed to map string {reg} to register index: ") + log_error(traceback.format_exc()) elif isinstance(reg, lowlevelil.ILRegister): return reg.index elif isinstance(reg, RegisterIndex): diff --git a/python/binaryview.py b/python/binaryview.py index b20d20e0..930eac18 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -43,7 +43,7 @@ from .enums import (AnalysisState, SymbolType, TypeClass, BinaryViewEventType, FunctionGraphType, TagReferenceType, TagTypeType, StructureVariant, RegisterValueType) from . import associateddatastore # required for _BinaryViewAssociatedDataStore -from . import log +from .log import log_error, log_warn from . import typelibrary from . import fileaccessor from . import databuffer @@ -273,7 +273,7 @@ class AnalysisCompletionEvent: else: self.callback() # type: ignore except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _empty_callback(self): pass @@ -338,7 +338,7 @@ class BinaryViewEvent: view_obj = BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) callback(view_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @dataclass(frozen=True) @@ -424,67 +424,67 @@ class BinaryDataNotificationCallbacks: try: self._notify.data_written(self._view, offset, length) except OSError: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _data_inserted(self, ctxt, view:core.BNBinaryView, offset:int, length:int) -> None: try: self._notify.data_inserted(self._view, offset, length) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _data_removed(self, ctxt, view:core.BNBinaryView, offset:int, length:int) -> None: try: self._notify.data_removed(self._view, offset, length) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _function_added(self, ctxt, view:core.BNBinaryView, func:core.BNFunction) -> None: try: self._notify.function_added(self._view, _function.Function(self._view, core.BNNewFunctionReference(func))) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _function_removed(self, ctxt, view:core.BNBinaryView, func:core.BNFunction) -> None: try: self._notify.function_removed(self._view, _function.Function(self._view, core.BNNewFunctionReference(func))) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _function_updated(self, ctxt, view:core.BNBinaryView, func:core.BNFunction) -> None: try: self._notify.function_updated(self._view, _function.Function(self._view, core.BNNewFunctionReference(func))) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _function_update_requested(self, ctxt, view:core.BNBinaryView, func:core.BNFunction) -> None: try: self._notify.function_update_requested(self._view, _function.Function(self._view, core.BNNewFunctionReference(func))) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _data_var_added(self, ctxt, view:core.BNBinaryView, var:core.BNDataVariable) -> None: try: self._notify.data_var_added(self._view, DataVariable.from_core_struct(var[0], self._view)) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _data_var_removed(self, ctxt, view:core.BNBinaryView, var:core.BNDataVariable) -> None: try: self._notify.data_var_removed(self._view, DataVariable.from_core_struct(var[0], self._view)) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _data_var_updated(self, ctxt, view:core.BNBinaryView, var:core.BNDataVariable) -> None: try: self._notify.data_var_updated(self._view, DataVariable.from_core_struct(var[0], self._view)) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _data_metadata_updated(self, ctxt, view:core.BNBinaryView, offset:int) -> None: try: self._notify.data_metadata_updated(self._view, offset) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _tag_type_updated(self, ctxt, view:core.BNBinaryView, tag_type:core.BNTagType) -> None: try: @@ -492,7 +492,7 @@ class BinaryDataNotificationCallbacks: assert core_tag_type is not None, "core.BNNewTagTypeReference returned None" self._notify.tag_type_updated(self._view, TagType(core_tag_type)) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _tag_added(self, ctxt, view:core.BNBinaryView, tag_ref:core.BNTagReference) -> None: try: @@ -513,7 +513,7 @@ class BinaryDataNotificationCallbacks: addr = tag_ref[0].addr self._notify.tag_added(self._view, tag, ref_type, auto_defined, arch, func, addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _tag_updated(self, ctxt, view:core.BNBinaryView, tag_ref:core.BNTagReference) -> None: try: @@ -534,7 +534,7 @@ class BinaryDataNotificationCallbacks: addr = tag_ref[0].addr self._notify.tag_updated(self._view, tag, ref_type, auto_defined, arch, func, addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _tag_removed(self, ctxt, view:core.BNBinaryView, tag_ref:core.BNTagReference) -> None: try: @@ -555,58 +555,58 @@ class BinaryDataNotificationCallbacks: addr = tag_ref[0].addr self._notify.tag_removed(self._view, tag, ref_type, auto_defined, arch, func, addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _symbol_added(self, ctxt, view:core.BNBinaryView, sym:core.BNSymbol) -> None: try: self._notify.symbol_added(self._view, _types.Symbol(None, None, None, handle = core.BNNewSymbolReference(sym))) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _symbol_updated(self, ctxt, view:core.BNBinaryView, sym:core.BNSymbol) -> None: try: self._notify.symbol_updated(self._view, _types.Symbol(None, None, None, handle = core.BNNewSymbolReference(sym))) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _symbol_removed(self, ctxt, view:core.BNBinaryView, sym:core.BNSymbol) -> None: try: self._notify.symbol_removed(self._view, _types.Symbol(None, None, None, handle = core.BNNewSymbolReference(sym))) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _string_found(self, ctxt, view:core.BNBinaryView, string_type:int, offset:int, length:int) -> None: try: self._notify.string_found(self._view, StringType(string_type), offset, length) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _string_removed(self, ctxt, view:core.BNBinaryView, string_type:int, offset:int, length:int) -> None: try: self._notify.string_removed(self._view, StringType(string_type), offset, length) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _type_defined(self, ctxt, view:core.BNBinaryView, name:str, type_obj:'_types.Type') -> None: try: qualified_name = _types.QualifiedName._from_core_struct(name[0]) self._notify.type_defined(self._view, qualified_name, _types.Type.create(core.BNNewTypeReference(type_obj), platform = self._view.platform)) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _type_undefined(self, ctxt, view:core.BNBinaryView, name:str, type_obj:'_types.Type') -> None: try: qualified_name = _types.QualifiedName._from_core_struct(name[0]) self._notify.type_undefined(self._view, qualified_name, _types.Type.create(core.BNNewTypeReference(type_obj), platform = self._view.platform)) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _type_ref_changed(self, ctxt, view:core.BNBinaryView, name:str, type_obj:'_types.Type') -> None: try: qualified_name = _types.QualifiedName._from_core_struct(name[0]) self._notify.type_ref_changed(self._view, qualified_name, _types.Type.create(core.BNNewTypeReference(type_obj), platform = self._view.platform)) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @property def view(self) -> 'BinaryView': @@ -904,7 +904,7 @@ class BinaryViewType(metaclass=_BinaryViewTypeMetaclass): if plat: return ctypes.cast(core.BNNewPlatformReference(plat.handle), ctypes.c_void_p).value except: - binaryninja.log.log_error(traceback.format_exc()) + binaryninja.log_error(traceback.format_exc()) return None callback_obj = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.POINTER(core.BNMetadata))(lambda ctxt, view, meta: callback(cb, view, meta)) @@ -1483,7 +1483,7 @@ class BinaryView: assert view_handle is not None, "core.BNNewViewReference returned None" return ctypes.cast(view_handle, ctypes.c_void_p).value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return None @classmethod @@ -1498,7 +1498,7 @@ class BinaryView: assert view_handle is not None, "core.BNNewViewReference returned None" return ctypes.cast(view_handle, ctypes.c_void_p).value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return None @classmethod @@ -1507,7 +1507,7 @@ class BinaryView: # I'm not sure whats going on here even so I've suppressed the linter warning return cls.is_valid_for_data(BinaryView(handle=core.BNNewViewReference(data))) # type: ignore except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @classmethod @@ -1522,7 +1522,7 @@ class BinaryView: else: return None except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return None @staticmethod @@ -2084,20 +2084,20 @@ class BinaryView: try: return self.init() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _external_ref_taken(self, ctxt): try: self.__class__._registered_instances.append(self) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _external_ref_released(self, ctxt): try: self.__class__._registered_instances.remove(self) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _read(self, ctxt, dest, offset, length): try: @@ -2109,7 +2109,7 @@ class BinaryView: ctypes.memmove(dest, data, len(data)) return len(data) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _write(self, ctxt, offset, src, length): @@ -2118,7 +2118,7 @@ class BinaryView: ctypes.memmove(data, src, length) return self.perform_write(offset, data.raw) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _insert(self, ctxt, offset, src, length): @@ -2127,112 +2127,112 @@ class BinaryView: ctypes.memmove(data, src, length) return self.perform_insert(offset, data.raw) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _remove(self, ctxt, offset, length): try: return self.perform_remove(offset, length) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _get_modification(self, ctxt, offset): try: return self.perform_get_modification(offset) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return ModificationStatus.Original def _is_valid_offset(self, ctxt, offset): try: return self.perform_is_valid_offset(offset) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _is_offset_readable(self, ctxt, offset): try: return self.perform_is_offset_readable(offset) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _is_offset_writable(self, ctxt, offset): try: return self.perform_is_offset_writable(offset) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _is_offset_executable(self, ctxt, offset): try: return self.perform_is_offset_executable(offset) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_next_valid_offset(self, ctxt, offset): try: return self.perform_get_next_valid_offset(offset) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return offset def _get_start(self, ctxt): try: return self.perform_get_start() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _get_length(self, ctxt): try: return self.perform_get_length() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _get_entry_point(self, ctxt): try: return self.perform_get_entry_point() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _is_executable(self, ctxt): try: return self.perform_is_executable() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_default_endianness(self, ctxt): try: return self.perform_get_default_endianness() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return Endianness.LittleEndian def _is_relocatable(self, ctxt): try: return self.perform_is_relocatable() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_address_size(self, ctxt): try: return self.perform_get_address_size() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 8 def _save(self, ctxt, file_accessor): try: return self.perform_save(fileaccessor.CoreFileAccessor(file_accessor)) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def init(self) -> bool: @@ -5109,7 +5109,7 @@ class BinaryView: return None if str_ref.type != StringType.AsciiString: partial = False - log.log_warn("Partial string not supported at {}".format(hex(addr))) + log_warn("Partial string not supported at {}".format(hex(addr))) start = addr if partial else str_ref.start length = str_ref.length - (addr - str_ref.start) if partial else str_ref.length return StringReference(self, StringType(str_ref.type), start, length) @@ -6306,7 +6306,7 @@ class BinaryView: """ result = False if core.BNIsUIEnabled() and not force: - log.log_warn("The BinaryView rebase API does not update cooresponding UI components. If the BinaryView is not associated with the UI rerun with 'force = True'.") + log_warn("The BinaryView rebase API does not update cooresponding UI components. If the BinaryView is not associated with the UI rerun with 'force = True'.") return None if progress_func is None: result = core.BNRebase(self.handle, address) diff --git a/python/callingconvention.py b/python/callingconvention.py index 683aebe8..5b816e20 100644 --- a/python/callingconvention.py +++ b/python/callingconvention.py @@ -24,7 +24,7 @@ from typing import Optional # Binary Ninja components from . import _binaryninjacore as core -from . import log +from .log import log_error from . import variable from . import function from . import architecture @@ -199,7 +199,7 @@ class CallingConvention: self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -214,7 +214,7 @@ class CallingConvention: self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -229,7 +229,7 @@ class CallingConvention: self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -244,7 +244,7 @@ class CallingConvention: self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -255,51 +255,51 @@ class CallingConvention: raise ValueError("freeing register list that wasn't allocated") del self._pending_reg_lists[buf.value] except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _arg_regs_share_index(self, ctxt): try: return self.__class__.arg_regs_share_index except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _arg_regs_used_for_varargs(self, ctxt): try: return self.__class__.arg_regs_for_varargs except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _stack_reserved_for_arg_regs(self, ctxt): try: return self.__class__.stack_reserved_for_arg_regs except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _stack_adjusted_on_return(self, ctxt): try: return self.__class__.stack_adjusted_on_return except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _eligible_for_heuristics(self, ctxt): try: return self.__class__.eligible_for_heuristics except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_int_return_reg(self, ctxt): try: if not isinstance(self.__class__.int_return_reg, str): - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False return self.arch.regs[self.__class__.int_return_reg].index except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_high_int_return_reg(self, ctxt): @@ -308,7 +308,7 @@ class CallingConvention: return 0xffffffff return self.arch.regs[self.__class__.high_int_return_reg].index except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_float_return_reg(self, ctxt): @@ -317,7 +317,7 @@ class CallingConvention: return 0xffffffff return self.arch.regs[self.__class__.float_return_reg].index except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_global_pointer_reg(self, ctxt): @@ -326,7 +326,7 @@ class CallingConvention: return 0xffffffff return self.arch.regs[self.__class__.global_pointer_reg].index except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_implicitly_defined_regs(self, ctxt, count): @@ -340,7 +340,7 @@ class CallingConvention: self._pending_reg_lists[result.value] = (result, reg_buf) return result.value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -350,7 +350,7 @@ class CallingConvention: reg_name = self.arch.get_reg_name(reg) api_obj = self.perform_get_incoming_reg_value(reg_name, func_obj)._to_core_struct() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) api_obj = variable.Undetermined()._to_core_struct() result[0].state = api_obj.state result[0].value = api_obj.value @@ -361,7 +361,7 @@ class CallingConvention: reg_name = self.arch.get_reg_name(reg) api_obj = self.perform_get_incoming_flag_value(reg_name, func_obj)._to_core_struct() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) api_obj = variable.Undetermined()._to_core_struct() result[0].state = api_obj.state result[0].value = api_obj.value @@ -378,7 +378,7 @@ class CallingConvention: result[0].index = out_var.index result[0].storage = out_var.storage except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) result[0].type = in_var[0].type result[0].index = in_var[0].index result[0].storage = in_var[0].storage @@ -395,7 +395,7 @@ class CallingConvention: result[0].index = out_var.index result[0].storage = out_var.storage except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) result[0].type = in_var[0].type result[0].index = in_var[0].index result[0].storage = in_var[0].storage diff --git a/python/datarender.py b/python/datarender.py index cf7a79e7..577ecdae 100644 --- a/python/datarender.py +++ b/python/datarender.py @@ -28,7 +28,7 @@ from . import filemetadata from . import binaryview from . import function from . import enums -from . import log +from .log import log_error from . import types from . import highlight from . import types @@ -110,7 +110,7 @@ class DataRenderer: try: self.perform_free_object(ctxt) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _is_valid_for_data(self, ctxt, view, addr, type, context, ctxCount): try: @@ -122,7 +122,7 @@ class DataRenderer: pycontext.append(TypeContext(types.Type.create(core.BNNewTypeReference(context[i].type)), context[i].offset)) return self.perform_is_valid_for_data(ctxt, view, addr, type, pycontext) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _get_lines_for_data(self, ctxt, view, addr, type, prefix, prefixCount, width, count, typeCtx, ctxCount): @@ -165,7 +165,7 @@ class DataRenderer: return ctypes.cast(line_buf, ctypes.c_void_p).value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return None def perform_free_object(self, ctxt): diff --git a/python/debuginfo.py b/python/debuginfo.py index bafc977c..1c23542c 100644 --- a/python/debuginfo.py +++ b/python/debuginfo.py @@ -29,7 +29,7 @@ from . import _binaryninjacore as core from . import callingconvention from . import platform from . import types as _types -from . import log +from .log import log_error from . import binaryview from . import filemetadata @@ -102,7 +102,7 @@ class _DebugInfoParserMetaClass(type): view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) return callback(view_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @staticmethod @@ -114,7 +114,7 @@ class _DebugInfoParserMetaClass(type): assert parser_ref is not None, "core.BNNewDebugInfoReference returned None" callback(DebugInfo(parser_ref), view_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @classmethod def register(cls, name: str, is_valid: Callable[['binaryview.BinaryView'], bool], parse_info: Callable[["DebugInfo", 'binaryview.BinaryView'], None]) -> "DebugInfoParser": diff --git a/python/downloadprovider.py b/python/downloadprovider.py index d45efdf6..cf63a6f1 100644 --- a/python/downloadprovider.py +++ b/python/downloadprovider.py @@ -30,7 +30,7 @@ from urllib.parse import urlencode import binaryninja import binaryninja._binaryninjacore as core from . import settings -from . import log +from .log import log_error def to_bytes(field): @@ -76,13 +76,13 @@ class DownloadInstance(object): self.__class__._registered_instances.remove(self) self.perform_destroy_instance() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _perform_request(self, ctxt, url): try: return self.perform_request(url) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return -1 def _perform_custom_request(self, ctxt, method, url, header_count, header_keys, header_values, response): @@ -115,7 +115,7 @@ class DownloadInstance(object): except Exception as e: out_response[0] = None core.BNSetErrorForDownloadInstance(self.handle, e.__class__.__name__) - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return -1 if py_response is not None: @@ -135,7 +135,7 @@ class DownloadInstance(object): return 0 if py_response is not None else -1 except: out_response[0] = None - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return -1 def _free_response(self, ctxt, response): @@ -166,7 +166,7 @@ class DownloadInstance(object): return bytes_len except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _write_callback(self, data, len, ctxt): @@ -175,7 +175,7 @@ class DownloadInstance(object): self._response = self._response + str_bytes return len except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def get_response(self, url): @@ -292,7 +292,7 @@ class DownloadProvider(metaclass=_DownloadProviderMetaclass): assert download_instance is not None, "core.BNNewDownloadInstanceReference returned None" return ctypes.cast(download_instance, ctypes.c_void_p).value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return None def create_instance(self): @@ -382,7 +382,7 @@ try: return -1 except: core.BNSetErrorForDownloadInstance(self.handle, "Unknown Exception!") - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return -1 return 0 @@ -476,11 +476,11 @@ if not _loaded and (sys.platform != "win32") and (sys.version_info >= (2, 7, 9)) except URLError as e: core.BNSetErrorForDownloadInstance(self.handle, e.__class__.__name__) - log.log_error(str(e)) + log_error(str(e)) return -1 except: core.BNSetErrorForDownloadInstance(self.handle, "Unknown Exception!") - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return -1 return 0 @@ -558,12 +558,12 @@ if not _loaded and (sys.platform != "win32") and (sys.version_info >= (2, 7, 9)) if not _loaded: if sys.platform == "win32": - log.log_error("The pip requests package is required for network connectivity!") - log.log_error("Please install the requests package into the selected Python environment:") - log.log_error(" python -m pip install requests") + log_error("The pip requests package is required for network connectivity!") + log_error("Please install the requests package into the selected Python environment:") + log_error(" python -m pip install requests") else: - log.log_error("On Python versions below 2.7.9, the pip requests[security] package is required for network connectivity!") - log.log_error("On an Ubuntu 14.04 install, the following three commands are sufficient to enable networking for the current user:") - log.log_error(" sudo apt install python-pip") - log.log_error(" python -m pip install pip --upgrade --user") - log.log_error(" python -m pip install requests[security] --upgrade --user") + log_error("On Python versions below 2.7.9, the pip requests[security] package is required for network connectivity!") + log_error("On an Ubuntu 14.04 install, the following three commands are sufficient to enable networking for the current user:") + log_error(" sudo apt install python-pip") + log_error(" python -m pip install pip --upgrade --user") + log_error(" python -m pip install requests[security] --upgrade --user") diff --git a/python/fileaccessor.py b/python/fileaccessor.py index 7d46c5c5..bbb171e1 100644 --- a/python/fileaccessor.py +++ b/python/fileaccessor.py @@ -23,7 +23,7 @@ import ctypes # Binary Ninja components from . import _binaryninjacore as core -from . import log +from .log import log_error class FileAccessor: def __init__(self): @@ -49,7 +49,7 @@ class FileAccessor: try: return self.get_length() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _read(self, ctxt, dest, offset, length): @@ -62,7 +62,7 @@ class FileAccessor: ctypes.memmove(dest, data, len(data)) return len(data) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _write(self, ctxt, offset, src, length): @@ -71,7 +71,7 @@ class FileAccessor: ctypes.memmove(data, src, length) return self.write(offset, data.raw) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 diff --git a/python/filemetadata.py b/python/filemetadata.py index 40d937a4..5a3e4d4e 100644 --- a/python/filemetadata.py +++ b/python/filemetadata.py @@ -27,7 +27,7 @@ import binaryninja from . import _binaryninjacore as core from .enums import SaveOption from . import associateddatastore #required for _FileMetadataAssociatedDataStore -from . import log +from .log import log_error from . import binaryview ProgressFuncType = Callable[[int, int], bool] @@ -46,7 +46,7 @@ class NavigationHandler: try: view = self.get_current_view() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) view = "" return core.BNAllocString(view) @@ -54,14 +54,14 @@ class NavigationHandler: try: return self.get_current_offset() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return 0 def _navigate(self, ctxt:Any, view:ViewName, offset:int) -> bool: try: return self.navigate(view, offset) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def get_current_view(self) -> str: diff --git a/python/flowgraph.py b/python/flowgraph.py index 65287f19..922cc933 100644 --- a/python/flowgraph.py +++ b/python/flowgraph.py @@ -33,7 +33,7 @@ from . import lowlevelil from . import mediumlevelil from . import highlevelil from . import basicblock -from . import log +from .log import log_error from . import highlight from . import interaction @@ -348,7 +348,7 @@ class FlowGraphLayoutRequest: if self.on_complete is not None: self.on_complete() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @property def complete(self): @@ -464,19 +464,19 @@ class FlowGraph: try: self.prepare_for_layout() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _populate_nodes(self, ctxt): try: self.populate_nodes() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _complete_layout(self, ctxt): try: self.complete_layout() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _update(self, ctxt): try: @@ -487,20 +487,20 @@ class FlowGraph: assert flow_graph is not None, "core.BNNewFlowGraphReference returned None" return ctypes.cast(flow_graph, ctypes.c_void_p).value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return None def _external_ref_taken(self, ctxt): try: self.__class__._registered_instances.append(self) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _external_ref_released(self, ctxt): try: self.__class__._registered_instances.remove(self) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def finish_prepare_for_layout(self): """ diff --git a/python/functionrecognizer.py b/python/functionrecognizer.py index 55af199d..9466bd63 100644 --- a/python/functionrecognizer.py +++ b/python/functionrecognizer.py @@ -26,7 +26,7 @@ from . import function from . import filemetadata from . import binaryview from . import lowlevelil -from . import log +from .log import log_error from . import mediumlevelil @@ -60,7 +60,7 @@ class FunctionRecognizer: il = lowlevelil.LowLevelILFunction(func.arch, handle = core.BNNewLowLevelILFunctionReference(il)) return self.recognize_low_level_il(view, func, il) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def recognize_low_level_il(self, data, func, il): @@ -74,7 +74,7 @@ class FunctionRecognizer: il = mediumlevelil.MediumLevelILFunction(func.arch, handle = core.BNNewMediumLevelILFunctionReference(il)) return self.recognize_medium_level_il(view, func, il) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def recognize_medium_level_il(self, data, func, il): diff --git a/python/interaction.py b/python/interaction.py index a8b0abbc..279b669a 100644 --- a/python/interaction.py +++ b/python/interaction.py @@ -26,7 +26,7 @@ from typing import Optional from . import _binaryninjacore as core from .enums import FormInputFieldType, MessageBoxIcon, MessageBoxButtonSet, MessageBoxButtonResult, ReportType from . import binaryview -from . import log +from .log import log_error from . import flowgraph @@ -504,7 +504,7 @@ class InteractionHandler: view = None self.show_plain_text_report(view, title, contents) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _show_markdown_report(self, ctxt, view, title, contents, plaintext): try: @@ -514,7 +514,7 @@ class InteractionHandler: view = None self.show_markdown_report(view, title, contents, plaintext) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _show_html_report(self, ctxt, view, title, contents, plaintext): try: @@ -524,7 +524,7 @@ class InteractionHandler: view = None self.show_html_report(view, title, contents, plaintext) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _show_graph_report(self, ctxt, view, title, graph): try: @@ -534,13 +534,13 @@ class InteractionHandler: view = None self.show_graph_report(view, title, flowgraph.CoreFlowGraph(core.BNNewFlowGraphReference(graph))) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _show_report_collection(self, ctxt, title, reports): try: self.show_report_collection(title, ReportCollection(core.BNNewReportCollectionReference(reports))) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_text_line_input(self, ctxt, result, prompt, title): try: @@ -550,7 +550,7 @@ class InteractionHandler: result[0] = core.BNAllocString(str(value)) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_int_input(self, ctxt, result, prompt, title): try: @@ -560,7 +560,7 @@ class InteractionHandler: result[0] = value return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_address_input(self, ctxt, result, prompt, title, view, current_address): try: @@ -574,7 +574,7 @@ class InteractionHandler: result[0] = value return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_choice_input(self, ctxt, result, prompt, title, choice_buf, count): try: @@ -587,7 +587,7 @@ class InteractionHandler: result[0] = value return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_open_filename_input(self, ctxt, result, prompt, ext): try: @@ -597,7 +597,7 @@ class InteractionHandler: result[0] = core.BNAllocString(str(value)) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_save_filename_input(self, ctxt, result, prompt, ext, default_name): try: @@ -607,7 +607,7 @@ class InteractionHandler: result[0] = core.BNAllocString(str(value)) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_directory_name_input(self, ctxt, result, prompt, default_name): try: @@ -617,7 +617,7 @@ class InteractionHandler: result[0] = core.BNAllocString(str(value)) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _get_form_input(self, ctxt, fields, count, title): try: @@ -657,13 +657,13 @@ class InteractionHandler: field_objs[i]._fill_core_result(fields[i]) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _show_message_box(self, ctxt, title, text, buttons, icon): try: return self.show_message_box(title, text, buttons, icon) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def show_plain_text_report(self, view, title, contents): pass diff --git a/python/plugin.py b/python/plugin.py index cf6ab0f9..e5c16af7 100644 --- a/python/plugin.py +++ b/python/plugin.py @@ -29,7 +29,7 @@ from .enums import PluginCommandType from . import filemetadata from . import binaryview from . import function -from . import log +from .log import log_error from . import lowlevelil from . import mediumlevelil @@ -116,7 +116,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) action(view_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @staticmethod def _address_action(view, addr, action): @@ -125,7 +125,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) action(view_obj, addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @staticmethod def _range_action(view, addr, length, action): @@ -134,7 +134,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) action(view_obj, addr, length) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @staticmethod def _function_action(view, func, action): @@ -144,7 +144,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = function.Function(view_obj, core.BNNewFunctionReference(func)) action(view_obj, func_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @staticmethod def _low_level_il_function_action(view, func, action): @@ -155,7 +155,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner) action(view_obj, func_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @staticmethod def _low_level_il_instruction_action(view, func, instr, action): @@ -166,7 +166,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner) action(view_obj, func_obj[instr]) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @staticmethod def _medium_level_il_function_action(view, func, action): @@ -177,7 +177,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = mediumlevelil.MediumLevelILFunction(owner.arch, core.BNNewMediumLevelILFunctionReference(func), owner) action(view_obj, func_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @staticmethod def _medium_level_il_instruction_action(view, func, instr, action): @@ -188,7 +188,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = mediumlevelil.MediumLevelILFunction(owner.arch, core.BNNewMediumLevelILFunctionReference(func), owner) action(view_obj, func_obj[instr]) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @staticmethod def _default_is_valid(view, is_valid): @@ -199,7 +199,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) return is_valid(view_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @staticmethod @@ -211,7 +211,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) return is_valid(view_obj, addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @staticmethod @@ -223,7 +223,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view)) return is_valid(view_obj, addr, length) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @staticmethod @@ -236,7 +236,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = function.Function(view_obj, core.BNNewFunctionReference(func)) return is_valid(view_obj, func_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @staticmethod @@ -250,7 +250,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner) return is_valid(view_obj, func_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @staticmethod @@ -264,7 +264,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = lowlevelil.LowLevelILFunction(owner.arch, core.BNNewLowLevelILFunctionReference(func), owner) return is_valid(view_obj, func_obj[instr]) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @staticmethod @@ -278,7 +278,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = mediumlevelil.MediumLevelILFunction(owner.arch, core.BNNewMediumLevelILFunctionReference(func), owner) return is_valid(view_obj, func_obj) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @staticmethod @@ -292,7 +292,7 @@ class PluginCommand(metaclass=_PluginCommandMetaClass): func_obj = mediumlevelil.MediumLevelILFunction(owner.arch, core.BNNewMediumLevelILFunctionReference(func), owner) return is_valid(view_obj, func_obj[instr]) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @classmethod @@ -615,7 +615,7 @@ class MainThreadActionHandler: try: self.add_action(MainThreadAction(action)) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def add_action(self, action): pass diff --git a/python/scriptingprovider.py b/python/scriptingprovider.py index 94f76bcd..4bd1c49d 100644 --- a/python/scriptingprovider.py +++ b/python/scriptingprovider.py @@ -35,12 +35,13 @@ from typing import Type as TypeHintType # Binary Ninja components import binaryninja -from . import bncompleter, log +from . import bncompleter from . import _binaryninjacore as core from . import settings from . import binaryview from . import basicblock from . import function +from .log import log_info, log_error, is_output_redirected_to_log from .pluginmanager import RepositoryManager from .enums import ScriptingProviderExecuteResult, ScriptingProviderInputReadyState @@ -84,19 +85,19 @@ class ScriptingOutputListener: try: self.notify_output(text) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _error(self, ctxt, text): try: self.notify_error(text) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _input_ready_state_changed(self, ctxt, state): try: self.notify_input_ready_state_changed(state) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def notify_output(self, text): pass @@ -137,20 +138,20 @@ class ScriptingInstance: try: self.perform_destroy_instance() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _execute_script_input(self, ctxt, text): try: return self.perform_execute_script_input(text) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return ScriptingProviderExecuteResult.InvalidScriptInput def _cancel_script_input(self, ctxt): try: return self.perform_cancel_script_input() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return ScriptingProviderExecuteResult.ScriptExecutionCancelled def _set_current_binary_view(self, ctxt, view): @@ -161,7 +162,7 @@ class ScriptingInstance: view = None self.perform_set_current_binary_view(view) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _set_current_function(self, ctxt, func): try: @@ -171,7 +172,7 @@ class ScriptingInstance: func = None self.perform_set_current_function(func) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _set_current_basic_block(self, ctxt, block): try: @@ -189,19 +190,19 @@ class ScriptingInstance: block = None self.perform_set_current_basic_block(block) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _set_current_address(self, ctxt, addr): try: self.perform_set_current_address(addr) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _set_current_selection(self, ctxt, begin, end): try: self.perform_set_current_selection(begin, end) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _complete_input(self, ctxt, text, state): try: @@ -209,7 +210,7 @@ class ScriptingInstance: text = text.decode("charmap") return ctypes.cast(self.perform_complete_input(text, state).encode("utf-8"), ctypes.c_void_p).value # type: ignore except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return "".encode("utf-8") @abc.abstractmethod @@ -361,7 +362,7 @@ class ScriptingProvider(metaclass=_ScriptingProviderMetaclass): assert script_instance is not None, "core.BNNewScriptingInstanceReference returned None" return ctypes.cast(script_instance, ctypes.c_void_p).value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return None def create_instance(self) -> Optional[ScriptingInstance]: @@ -436,7 +437,7 @@ class _PythonScriptingInstanceOutput: interpreter = PythonScriptingInstance._interpreter.value if interpreter is None: - if log.is_output_redirected_to_log(): + if is_output_redirected_to_log(): self.buffer += data while True: i = self.buffer.find('\n') @@ -446,9 +447,9 @@ class _PythonScriptingInstanceOutput: self.buffer = self.buffer[i + 1:] if self.is_error: - log.log_error(line) + log_error(line) else: - log.log_info(line) + log_info(line) else: self.orig.write(data) else: @@ -510,7 +511,7 @@ class BlacklistedDict(dict): def __setitem__(self, k, v): if self.blacklist_enabled and k in self.__blacklist: - log.log_error('Setting variable "{}" will have no affect as it is automatically controlled by the ScriptingProvider.'.format(k)) + log_error('Setting variable "{}" will have no affect as it is automatically controlled by the ScriptingProvider.'.format(k)) super(BlacklistedDict, self).__setitem__(k, v) def enable_blacklist(self, enabled): @@ -836,9 +837,9 @@ class PythonScriptingProvider(ScriptingProvider): __import__(module) return True except KeyError: - log.log_error(f"Failed to find python plugin: {repo_path}/{module}") + log_error(f"Failed to find python plugin: {repo_path}/{module}") except ImportError as ie: - log.log_error(f"Failed to import python plugin: {repo_path}/{module}: {ie}") + log_error(f"Failed to import python plugin: {repo_path}/{module}: {ie}") return False def _run_args(self, args): @@ -936,15 +937,15 @@ class PythonScriptingProvider(ScriptingProvider): python_bin_override = settings.Settings().get_string("python.binaryOverride") python_bin, status = self._get_executable_for_libpython(python_lib, python_bin_override) if python_bin is not None and not self._pip_exists(str(python_bin)): - log.log_error(f"Pip not installed for configured python: {python_bin}.\n" + log_error(f"Pip not installed for configured python: {python_bin}.\n" "Please install pip or switch python versions.") return False if sys.platform == "darwin" and not any([python_bin, python_lib, python_bin_override]): - log.log_error(f"Plugin requirement installation unsupported on MacOS with bundled Python: {status}\n" + log_error(f"Plugin requirement installation unsupported on MacOS with bundled Python: {status}\n" "Please specify a path to a python library in the 'Python Interpreter' setting") return False elif python_bin is None: - log.log_error(f"Unable to discover python executable required for installing python modules: {status}\n" + log_error(f"Unable to discover python executable required for installing python modules: {status}\n" "Please specify a path to a python binary in the 'Python Path Override'") return False @@ -952,7 +953,7 @@ class PythonScriptingProvider(ScriptingProvider): "import sys; sys.stdout.write(f'{sys.version_info.major}.{sys.version_info.minor}')"]).decode("utf-8") python_lib_version = f"{sys.version_info.major}.{sys.version_info.minor}" if (python_bin_version != python_lib_version): - log.log_error(f"Python Binary Setting {python_bin_version} incompatible with python library {python_lib_version}") + log_error(f"Python Binary Setting {python_bin_version} incompatible with python library {python_lib_version}") return False args:List[str] = [str(python_bin), "-m", "pip", "--isolated", "--disable-pip-version-check"] @@ -973,10 +974,10 @@ class PythonScriptingProvider(ScriptingProvider): site_package_dir.mkdir(parents=True, exist_ok=True) args.extend(["--target", str(site_package_dir)]) args.extend(list(filter(len, modules.split("\n")))) - log.log_info(f"Running pip {args}") + log_info(f"Running pip {args}") status, result = self._run_args(args) if not status: - log.log_error(f"Error while attempting to install requirements {result}") + log_error(f"Error while attempting to install requirements {result}") return status def _module_installed(self, ctx, module:str) -> bool: diff --git a/python/transform.py b/python/transform.py index 7c5a45ad..b847b0c6 100644 --- a/python/transform.py +++ b/python/transform.py @@ -24,7 +24,7 @@ import abc # Binary Ninja components import binaryninja -from . import log +from .log import log_error from . import databuffer from . import _binaryninjacore as core from .enums import TransformType @@ -181,7 +181,7 @@ class Transform(metaclass=_TransformMetaClass): self._pending_param_lists[result.value] = (result, param_buf) return result.value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) count[0] = 0 return None @@ -192,7 +192,7 @@ class Transform(metaclass=_TransformMetaClass): raise ValueError("freeing parameter list that wasn't allocated") del self._pending_param_lists[buf.value] except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _decode(self, ctxt, input_buf, output_buf, params, count): try: @@ -208,7 +208,7 @@ class Transform(metaclass=_TransformMetaClass): core.BNSetDataBufferContents(output_buf, result, len(result)) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _encode(self, ctxt, input_buf, output_buf, params, count): @@ -225,7 +225,7 @@ class Transform(metaclass=_TransformMetaClass): core.BNSetDataBufferContents(output_buf, result, len(result)) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False @abc.abstractmethod diff --git a/python/update.py b/python/update.py index 5f3b55df..33323546 100644 --- a/python/update.py +++ b/python/update.py @@ -25,7 +25,7 @@ import ctypes import binaryninja from . import _binaryninjacore as core from .enums import UpdateResult -from . import log +from .log import log_error @@ -78,7 +78,7 @@ class UpdateProgressCallback: return self.func(progress, total) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) @property def active(cls): diff --git a/python/websocketprovider.py b/python/websocketprovider.py index 2157d13a..d5d14436 100644 --- a/python/websocketprovider.py +++ b/python/websocketprovider.py @@ -34,7 +34,7 @@ else: import binaryninja._binaryninjacore as core import binaryninja -from . import log +from .log import log_error @@ -82,7 +82,7 @@ class WebsocketClient(object): self.__class__._registered_clients.remove(self) self.perform_destroy_client() except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def _connect(self, ctxt, host, header_count, header_keys, header_values): # Extract headers @@ -102,7 +102,7 @@ class WebsocketClient(object): self.perform_write(data_bytes) return True except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return False def _disconnect(self, ctxt): @@ -271,7 +271,7 @@ class WebsocketProvider(metaclass=_WebsocketProviderMetaclass): return None return ctypes.cast(core.BNNewWebsocketClientReference(result.handle), ctypes.c_void_p).value except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) return None def create_instance(self): diff --git a/python/workflow.py b/python/workflow.py index 45ef97f9..1f909232 100644 --- a/python/workflow.py +++ b/python/workflow.py @@ -24,7 +24,7 @@ from typing import List, Union, Callable, Optional, Any # Binary Ninja components import binaryninja -from . import log +from .log import log_error from . import _binaryninjacore as core from .flowgraph import FlowGraph, CoreFlowGraph @@ -54,10 +54,10 @@ class Activity(object): if self.action is not None: self.action(ac) except: - log.log_error(traceback.format_exc()) + log_error(traceback.format_exc()) def __del__(self): - log.log_error("Activity DEL called!") + log_error("Activity DEL called!") if self.handle is not None: core.BNFreeActivity(self.handle) @@ -158,7 +158,7 @@ class Workflow(metaclass=_WorkflowMetaclass): >>> pwf = Workflow().clone("PythonLogWarnWorkflow") >>> pwf.show_topology() - >>> pwf.register_activity(Activity("PythonLogWarn", action=lambda analysis_context: log.log_warn("PythonLogWarn Called!"))) + >>> pwf.register_activity(Activity("PythonLogWarn", action=lambda analysis_context: log_warn("PythonLogWarn Called!"))) >>> pwf.insert("core.function.basicBlockAnalysis", ["PythonLogWarn"]) >>> pwf.register() |
