diff --git a/lgtm.yml b/lgtm.yml new file mode 100644 index 00000000..821793e5 --- /dev/null +++ b/lgtm.yml @@ -0,0 +1,6 @@ +queries: + - exclude: py/clear-text-logging-sensitive-data + +path_classifiers: + examples: + - examples/ diff --git a/manticore/core/plugin.py b/manticore/core/plugin.py index df8356fc..18e780ee 100644 --- a/manticore/core/plugin.py +++ b/manticore/core/plugin.py @@ -129,7 +129,6 @@ class ExtendedTracer(Plugin): def did_write_memory_callback(self, state, where, value, size): if self.current_pc == where: raise Exception - return entry = {"type": "mem_write", "where": where, "value": value, "size": size} state.context.setdefault(self.context_key, []).append(entry) diff --git a/manticore/core/smtlib/constraints.py b/manticore/core/smtlib/constraints.py index dbbc1802..37240996 100644 --- a/manticore/core/smtlib/constraints.py +++ b/manticore/core/smtlib/constraints.py @@ -326,7 +326,7 @@ class ConstraintSet: name=migrated_name, ).array else: - raise NotImplemented( + raise NotImplementedError( f"Unknown expression type {type(foreign_var)} encountered during expression migration" ) # Update the var to var mapping diff --git a/manticore/core/smtlib/solver.py b/manticore/core/smtlib/solver.py index ec77e474..c6f23436 100644 --- a/manticore/core/smtlib/solver.py +++ b/manticore/core/smtlib/solver.py @@ -274,7 +274,6 @@ class Z3Solver(Solver): # self._proc.wait() except Exception as e: logger.error(str(e)) - pass def _reset(self, constraints=None): """Auxiliary method to reset the smtlib external solver to initial defaults""" diff --git a/manticore/core/state.py b/manticore/core/state.py index b3623f72..d5a8927d 100644 --- a/manticore/core/state.py +++ b/manticore/core/state.py @@ -61,7 +61,7 @@ class SerializeState(Concretize): disk so that analysis can later be resumed from this point. """ - def setstate(self, state, _value): + def _setstate(self, state, _value): with open(self.filename, "wb") as statef: PickleSerializer().serialize(state, statef) @@ -69,7 +69,7 @@ class SerializeState(Concretize): super().__init__( f"Saving state to {filename}", BitVecConstant(32, 0), - setstate=self.setstate, + setstate=self._setstate, policy="ONE", **kwargs, ) diff --git a/manticore/ethereum/abi.py b/manticore/ethereum/abi.py index 710973c2..dfbcab45 100644 --- a/manticore/ethereum/abi.py +++ b/manticore/ethereum/abi.py @@ -264,7 +264,7 @@ class ABI: result.append(ABI._deserialize(ty[2], buf, dyn_offset)) dyn_offset += ty_size else: - raise NotImplemented + raise NotImplementedError(f"Could not deserialize type: {ty[0]}") return result diff --git a/manticore/ethereum/manticore.py b/manticore/ethereum/manticore.py index 43f7302e..5bc7c650 100644 --- a/manticore/ethereum/manticore.py +++ b/manticore/ethereum/manticore.py @@ -513,7 +513,7 @@ class ManticoreEVM(ManticoreBase): for _ in range(rep): result.append(self._make_symbolic_arguments(ty[2])) else: - raise NotImplemented + raise NotImplementedError(f"Could not produce symbolic argument of type {ty[0]}") return result diff --git a/manticore/native/cpu/aarch64.py b/manticore/native/cpu/aarch64.py index 139b8a0d..2957c5fb 100644 --- a/manticore/native/cpu/aarch64.py +++ b/manticore/native/cpu/aarch64.py @@ -2837,9 +2837,7 @@ class Aarch64Cpu(Cpu): insn_rx += "1{5}" assert re.match(insn_rx, cpu.insn_bit_str) - # XXX: Assumes sequential execution. - pass # XXX: Support DUP (element). @instruction diff --git a/manticore/native/cpu/arm.py b/manticore/native/cpu/arm.py index 0def2f98..6d87aea8 100644 --- a/manticore/native/cpu/arm.py +++ b/manticore/native/cpu/arm.py @@ -4,6 +4,7 @@ import logging import struct import capstone as cs +import operator as ops from .abstractcpu import Abi, Cpu, Interruption, Operand, RegisterFile, SyscallAbi from .abstractcpu import instruction as abstract_instruction @@ -763,8 +764,8 @@ class Armv7Cpu(Cpu): return "ASR" return OP_NAME_MAP.get(name, name) - def _wrap_operands(self, ops): - return [Armv7Operand(self, op) for op in ops] + def _wrap_operands(self, operands): + return [Armv7Operand(self, op) for op in operands] def should_commit_flags(cpu): # workaround for a capstone bug (issue #980); @@ -1515,7 +1516,8 @@ class Armv7Cpu(Cpu): op2_val, carry = op2.read(with_carry=True) result = operation(op1.read(), op2_val) else: - op1_val, carry = op1.read(with_carry=True) + # We _do_ use this form, contrary to what LGTM says + op1_val, carry = op1.read(with_carry=True) # lgtm [py/call/wrong-arguments] result = operation(op1_val) if dest is not None: dest.write(result) @@ -1524,9 +1526,9 @@ class Armv7Cpu(Cpu): @instruction(can_take_denormalized_mod_imm=True) def ORR(cpu, dest, op1, op2=None): if op2 is not None: - cpu._bitwise_instruction(lambda x, y: x | y, dest, op1, op2) + cpu._bitwise_instruction(ops.or_, dest, op1, op2) else: - cpu._bitwise_instruction(lambda x, y: x | y, dest, dest, op1) + cpu._bitwise_instruction(ops.or_, dest, dest, op1) @instruction(can_take_denormalized_mod_imm=True) def ORN(cpu, dest, op1, op2=None): @@ -1538,20 +1540,20 @@ class Armv7Cpu(Cpu): @instruction(can_take_denormalized_mod_imm=True) def EOR(cpu, dest, op1, op2=None): if op2 is not None: - cpu._bitwise_instruction(lambda x, y: x ^ y, dest, op1, op2) + cpu._bitwise_instruction(ops.xor, dest, op1, op2) else: - cpu._bitwise_instruction(lambda x, y: x ^ y, dest, dest, op1) + cpu._bitwise_instruction(ops.xor, dest, dest, op1) @instruction(can_take_denormalized_mod_imm=True) def AND(cpu, dest, op1, op2=None): if op2 is not None: - cpu._bitwise_instruction(lambda x, y: x & y, dest, op1, op2) + cpu._bitwise_instruction(ops.and_, dest, op1, op2) else: - cpu._bitwise_instruction(lambda x, y: x & y, dest, dest, op1) + cpu._bitwise_instruction(ops.and_, dest, dest, op1) @instruction(can_take_denormalized_mod_imm=True) def TEQ(cpu, op1, op2=None): - cpu._bitwise_instruction(lambda x, y: x ^ y, None, op1, op2) + cpu._bitwise_instruction(ops.xor, None, op1, op2) cpu.commit_flags() @instruction(can_take_denormalized_mod_imm=True) diff --git a/manticore/native/memory.py b/manticore/native/memory.py index 761b4a9c..5ccc14e4 100644 --- a/manticore/native/memory.py +++ b/manticore/native/memory.py @@ -63,6 +63,7 @@ class ConcretizeMemory(MemoryException): self.message = f"Concretizing memory address {address} size {size}" else: self.message = message + super().__init__(self.message, address) self.mem = mem self.address = address self.size = size diff --git a/manticore/platforms/decree.py b/manticore/platforms/decree.py index 6fb8633f..130b4ce7 100644 --- a/manticore/platforms/decree.py +++ b/manticore/platforms/decree.py @@ -1082,12 +1082,8 @@ class SDecree(Decree): data = [] for i in range(count): - if False: - # Too slow for the new age. - value = self.constraints.new_bitvec(8, name="RANDOM_%04d" % self.random) - self.constraints.add(symb == cgcrandom.stream[self.random]) - else: - value = cgcrandom.stream[self.random] + # TODO - should value be symbolic? + value = cgcrandom.stream[self.random] data.append(value) self.random += 1 diff --git a/manticore/platforms/linux.py b/manticore/platforms/linux.py index faab019c..357b5956 100644 --- a/manticore/platforms/linux.py +++ b/manticore/platforms/linux.py @@ -161,8 +161,11 @@ class File: return -class ProcSelfMaps(File): +# TODO - we should consider refactoring File so that we don't have to mute these errors +class ProcSelfMaps(File): # lgtm [py/missing-call-to-init] def __init__(self, flags: int, linux): + # WARN: Does not call File.__init__. Should have the File API, but we manually + # manage the underlying file and mode self.file = tempfile.NamedTemporaryFile(mode="w", delete=False) self.file.write(linux.current.memory.__proc_self__) self.file.close() @@ -172,8 +175,10 @@ class ProcSelfMaps(File): self.file = open(self.file.name, mode) -class Directory(File): +class Directory(File): # lgtm [py/missing-call-to-init] def __init__(self, path: str, flags: int): + # WARN: Does not call File.__init__ because we don't want to open the directory, + # even though we still want it to present the same API as File assert os.path.isdir(path) self.fd = os.open(path, flags) diff --git a/manticore/wasm/executor.py b/manticore/wasm/executor.py index 7bc14c98..ccb2ef5f 100644 --- a/manticore/wasm/executor.py +++ b/manticore/wasm/executor.py @@ -1454,8 +1454,8 @@ class Executor(Eventful): stack.push(F32.cast(c1)) return raise NotImplementedError("f32_demote_f64") - c1 = struct.unpack("f", struct.pack("d", c1)[:4])[0] - stack.push(F32.cast(c1)) + # c1 = struct.unpack("f", struct.pack("d", c1)[:4])[0] + # stack.push(F32.cast(c1)) def f64_convert_s_i32(self, store, stack): stack.has_type_on_top(I32, 1) diff --git a/manticore/wasm/structure.py b/manticore/wasm/structure.py index 172d14c3..81ca79a7 100644 --- a/manticore/wasm/structure.py +++ b/manticore/wasm/structure.py @@ -1082,7 +1082,7 @@ class ModuleInstance(Eventful): ty = f.type assert len(ty.result_types) <= 1 local_vars: typing.List[Value] = [] - for v in [stack.pop() for _t in ty.param_types][::-1]: + for v in [stack.pop() for _ in ty.param_types][::-1]: assert not isinstance(v, (Label, Activation)) local_vars.append(v) @@ -1846,7 +1846,7 @@ class Stack(Eventful): raise RuntimeError("Couldn't find a frame on the stack") -class AtomicStack(Stack): +class AtomicStack(Stack): # lgtm [py/missing-call-to-init] """ Allows for the rolling-back of the stack in the event of a concretization exception. Inherits from Stack so that the types will be correct, but never calls `super`. diff --git a/scripts/gdb.py b/scripts/gdb.py index 6079353f..81b1c747 100644 --- a/scripts/gdb.py +++ b/scripts/gdb.py @@ -95,7 +95,6 @@ def getM(m): return int(correspond(f"x/xg {m}\n").strip().split("\t")[-1], 0) except Exception as e: raise e - return 0 def getPid(): @@ -138,5 +137,5 @@ def get_arch(): _arch = "armv7" else: print(infotarget) - raise NotImplemented + raise NotImplementedError return _arch diff --git a/scripts/prof.py b/scripts/prof.py index b77c76a2..3f1ef7f6 100644 --- a/scripts/prof.py +++ b/scripts/prof.py @@ -7,15 +7,19 @@ from __future__ import print_function from sys import argv, exit from manticore.native import Manticore +from manticore.core.plugin import Profiler def profile(program, sort="cumulative"): print(f'[*] Profiling program "{program}"') m = Manticore(program) - m.run(should_profile=True) + profiler = Profiler() + m.register_plugin(profiler) + m.run() + m.finalize() - stats = m.get_profiling_stats() + stats = profiler.get_profiling_data() print(f"[*] Loaded profiling data.") if stats is None: diff --git a/tests/auto_generators/make_dump.py b/tests/auto_generators/make_dump.py index 269924f6..259342ad 100644 --- a/tests/auto_generators/make_dump.py +++ b/tests/auto_generators/make_dump.py @@ -158,7 +158,7 @@ def read_operand(o): elif o.type == X86_OP_REG: reg_name = str(instruction.reg_name(o.reg).upper()) return gdb.getR(reg_name) - raise NotImplemented + raise NotImplementedError(f"Unknown operand typ: {o.type}") STACK_INSTRUCTIONS = [