cea-sec/miasm

View on GitHub
miasm/analysis/dse.py

Summary

Maintainability
F
3 days
Test Coverage

File dse.py has 526 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Dynamic symbolic execution module.

Offers a way to have a symbolic execution along a concrete one.
Basically, this is done through DSEEngine class, with scheme:

Severity: Major
Found in miasm/analysis/dse.py - About 1 day to fix

    Function handle has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle(self, cur_addr):
            cur_addr = canonize_to_exprloc(self.lifter.loc_db, cur_addr)
            symb_pc = self.eval_expr(self.lifter.IRDst)
            possibilities = possible_values(symb_pc)
            cur_path_constraint = set() # path_constraint for the concrete path
    Severity: Minor
    Found in miasm/analysis/dse.py - About 7 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _check_state has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def _check_state(self):
            """Check the current state against the concrete one"""
            errors = [] # List of DriftInfo
    
            for symbol in self.symb.modified_expr:
    Severity: Minor
    Found in miasm/analysis/dse.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function callback has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def callback(self, _):
            """Called before each instruction"""
            # Assert synchronization with concrete execution
            self._check_state()
    
    
    Severity: Minor
    Found in miasm/analysis/dse.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function add_lib_handler has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def add_lib_handler(self, libimp, namespace):
            """Add search for handler based on a @libimp libimp instance
    
            Known functions will be looked by {name}_symb or {name}_{ord}_symb in the @namespace
            """
    Severity: Minor
    Found in miasm/analysis/dse.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid deeply nested control flow statements.
    Open

                            if expr.is_mem():
                                addr_range = expr_range(expr.ptr)
                                # At upper bounds, add the size of the memory access
                                # if addr (- [a, b], then @size[addr] reachables
                                # values are in @8[a, b + size[
    Severity: Major
    Found in miasm/analysis/dse.py - About 45 mins to fix

      Function mem_read has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def mem_read(self, expr_mem):
              if not expr_mem.ptr.is_int():
                  return super(ESETrackModif, self).mem_read(expr_mem)
              dst_addr = int(expr_mem.ptr)
      
      
      Severity: Minor
      Found in miasm/analysis/dse.py - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Avoid deeply nested control flow statements.
      Open

                              if not value.is_int():
                                  raise TypeError("Rely on a symbolic memory case, " \
                                                  "address 0x%x" % address)
                              path_constraint.add(ExprAssign(expr_mem, value))
      Severity: Major
      Found in miasm/analysis/dse.py - About 45 mins to fix

        Function __init__ has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, machine, loc_db, produce_solution=PRODUCE_SOLUTION_CODE_COV,
        Severity: Minor
        Found in miasm/analysis/dse.py - About 35 mins to fix

          Function _update_state_from_concrete_symb has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def _update_state_from_concrete_symb(self, symbexec, cpu=True, mem=False):
                  if mem:
                      # Values will be retrieved from the concrete execution if they are
                      # not present
                      symbexec.symbols.symbols_mem.base_to_memarray.clear()
          Severity: Minor
          Found in miasm/analysis/dse.py - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function restore_snapshot has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def restore_snapshot(self, snapshot, memory=True):
                  """Restore a @snapshot taken with .take_snapshot
                  @snapshot: .take_snapshot output
                  @memory: (optional) if set, also restore the memory
                  """
          Severity: Minor
          Found in miasm/analysis/dse.py - About 25 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

                      if isinstance(fname, tuple):
                          fname = b"%s_%d_symb" % (force_bytes(fname[0]), fname[1])
                      else:
                          fname = b"%s_symb" % force_bytes(fname)
          Severity: Major
          Found in miasm/analysis/dse.py and 1 other location - About 2 hrs to fix
          miasm/analysis/dse.py on lines 262..265

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 55.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

                      if isinstance(fname, tuple):
                          fname = b"%s_%d_symb" % (force_bytes(fname[0]), fname[1])
                      else:
                          fname = b"%s_symb" % force_bytes(fname)
          Severity: Major
          Found in miasm/analysis/dse.py and 1 other location - About 2 hrs to fix
          miasm/analysis/dse.py on lines 269..272

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 55.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status