cea-sec/miasm

View on GitHub
miasm/core/types.py

Summary

Maintainability
F
4 days
Test Coverage

File types.py has 1269 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""This module provides classes to manipulate pure C types as well as their
representation in memory. A typical usecase is to use this module to
easily manipylate structures backed by a VmMngr object (a miasm sandbox virtual
memory):

Severity: Major
Found in miasm/core/types.py - About 3 days to fix

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

    def to_type(obj):
        """If possible, return the Type associated with @obj, otherwise raises
        a ValueError.
    
        Works with a Type instance (returns obj) or a MemType subclass or instance
    Severity: Minor
    Found in miasm/core/types.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 set has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def set(self, vm, addr, val):
            # MemSizedArray assignment
            if isinstance(val, MemSizedArray):
                if val.array_len != self.array_len or len(val) != self.size:
                    raise ValueError("Size mismatch in MemSizedArray assignment")
    Severity: Minor
    Found in miasm/core/types.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_encoding has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def add_encoding(cls, enc_name, str_enc=None, getter=None, setter=None,
    Severity: Minor
    Found in miasm/core/types.py - About 35 mins to fix

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

      def set_str(vm, addr, s, enc, end=u'\x00'):
      Severity: Minor
      Found in miasm/core/types.py - About 35 mins to fix

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

        def get_str(vm, addr, enc, max_char=None, end=u'\x00'):
        Severity: Minor
        Found in miasm/core/types.py - About 35 mins to fix

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

              def gen_fields(cls, fields=None):
                  """Generate the fields of this class (so that they can be accessed with
                  self.<field_name>) from a @fields list, as described in the class doc.
          
                  Useful in case of a type cyclic dependency. For example, the following
          Severity: Minor
          Found in miasm/core/types.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 set_item has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def set_item(self, vm, addr, idx, item):
                  """Sets one or multiple items in this array (@idx can be an int, long
                  or slice).
                  """
                  if isinstance(idx, slice):
          Severity: Minor
          Found in miasm/core/types.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

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

              def __eq__(self, other):
                  return self.__class__ == other.__class__ and \
                          self.field_type == other.field_type and \
                          self.array_len == other.array_len
          Severity: Major
          Found in miasm/core/types.py and 1 other location - About 1 hr to fix
          miasm/core/types.py on lines 687..690

          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 46.

          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

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

              def __eq__(self, other):
                  return self.__class__ == other.__class__ and \
                          self.fields == other.fields and \
                          self.name == other.name
          Severity: Major
          Found in miasm/core/types.py and 1 other location - About 1 hr to fix
          miasm/core/types.py on lines 879..882

          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 46.

          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

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

              def __eq__(self, other):
                  return self.__class__ == other.__class__ and self._fmt == other._fmt
          Severity: Major
          Found in miasm/core/types.py and 2 other locations - About 45 mins to fix
          miasm/core/objc.py on lines 498..500
          miasm/core/types.py on lines 1123..1124

          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 35.

          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

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

              def __eq__(self, other):
                  return self.__class__ == other.__class__ and self._enc == other._enc
          Severity: Major
          Found in miasm/core/types.py and 2 other locations - About 45 mins to fix
          miasm/core/objc.py on lines 498..500
          miasm/core/types.py on lines 379..380

          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 35.

          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