cea-sec/miasm

View on GitHub
miasm/arch/msp430/arch.py

Summary

Maintainability
F
1 wk
Test Coverage

File arch.py has 509 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#-*- coding:utf-8 -*-

from builtins import range

import logging
Severity: Major
Found in miasm/arch/msp430/arch.py - About 1 day to fix

    Function decode has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        def decode(self, v):
            size = 16
            if hasattr(self.parent, 'size'):
                size = [16, 8][self.parent.size.value]
            v = v & self.lmask
    Severity: Minor
    Found in miasm/arch/msp430/arch.py - About 3 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 encode has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def encode(self):
            e = self.expr
            if e in self.reg_info.expr:
                self.parent.a_s.value = 0
                self.value = self.reg_info.expr.index(e)
    Severity: Minor
    Found in miasm/arch/msp430/arch.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 arg2str has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

        def arg2str(expr, index=None, loc_db=None):
            if isinstance(expr, ExprId):
                o = str(expr)
            elif isinstance(expr, ExprInt):
                o = str(expr)
    Severity: Minor
    Found in miasm/arch/msp430/arch.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 arg2html has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def arg2html(expr, index=None, loc_db=None):
            if isinstance(expr, ExprId) or isinstance(expr, ExprInt) or expr.is_loc():
                return color_expr_html(expr, loc_db)
            elif isinstance(expr, ExprOp) and expr.op == "autoinc":
                o = "@%s+" % color_expr_html(expr.args[0], loc_db)
    Severity: Minor
    Found in miasm/arch/msp430/arch.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 asm_ast_to_expr has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def asm_ast_to_expr(self, value, loc_db):
            if isinstance(value, AstId):
                name = value.name
                if is_expr(name):
                    return name
    Severity: Minor
    Found in miasm/arch/msp430/arch.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 flen has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def flen(cls, mode, v):
            if v['a_s'] == 0b00:
                return None
            elif v['a_s'] == 0b01:
                if v['sreg'] in [3]:
    Severity: Minor
    Found in miasm/arch/msp430/arch.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 encode has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def encode(self):
            e = self.expr
            if e in self.reg_info.expr:
                self.parent.a_d.value = 0
                self.value = self.reg_info.expr.index(e)
    Severity: Minor
    Found in miasm/arch/msp430/arch.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

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

        def decode(self, v):
            if hasattr(self.parent, 'size'):
                size = [16, 8][self.parent.size.value]
            else:
                size = 16
    Severity: Minor
    Found in miasm/arch/msp430/arch.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

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

        def gen_modes(cls, subcls, name, bases, dct, fields):
    Severity: Minor
    Found in miasm/arch/msp430/arch.py - About 35 mins to fix

      Avoid too many return statements within this function.
      Open

              return None
      Severity: Major
      Found in miasm/arch/msp430/arch.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return self.name in ['call']
        Severity: Major
        Found in miasm/arch/msp430/arch.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return 16
          Severity: Major
          Found in miasm/arch/msp430/arch.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                        return ExprInt(value.value, 16)
            Severity: Major
            Found in miasm/arch/msp430/arch.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return None
              Severity: Major
              Found in miasm/arch/msp430/arch.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return None
                Severity: Major
                Found in miasm/arch/msp430/arch.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return ExprMem(ptr, value.size)
                  Severity: Major
                  Found in miasm/arch/msp430/arch.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return ExprOp(value.op, *args)
                    Severity: Major
                    Found in miasm/arch/msp430/arch.py - About 30 mins to fix

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

                          @classmethod
                          def getbits(cls, bs, attrib, start, n):
                              if not n:
                                  return 0
                              o = 0
                      Severity: Major
                      Found in miasm/arch/msp430/arch.py and 1 other location - About 1 day to fix
                      miasm/arch/sh4/arch.py on lines 509..530

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

                      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 encode(self):
                              if not isinstance(self.expr, ExprInt):
                                  return False
                              v = int(self.expr)
                              if (1 << (self.l - 1)) & v:
                      Severity: Major
                      Found in miasm/arch/msp430/arch.py and 1 other location - About 7 hrs to fix
                      miasm/arch/sh4/arch.py on lines 288..296

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

                      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 decode(self, v):
                              v = v & self.lmask
                              if (1 << (self.l - 1)) & v:
                                  v |= ~0 ^ self.lmask
                              v = self.decodeval(v)
                      Severity: Major
                      Found in miasm/arch/msp430/arch.py and 1 other location - About 5 hrs to fix
                      miasm/arch/arm/arch.py on lines 995..1001

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

                      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

                          @classmethod
                          def getbytes(cls, bs, offset, l=1):
                              out = b""
                              for _ in range(l):
                                  n_offset = (offset & ~1) + 1 - offset % 2
                      Severity: Major
                      Found in miasm/arch/msp430/arch.py and 1 other location - About 4 hrs to fix
                      miasm/arch/sh4/arch.py on lines 532..539

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

                      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 6 locations. Consider refactoring.
                      Open

                      def addop(name, fields, args=None, alias=False):
                          dct = {"fields": fields}
                          dct["alias"] = alias
                          if args is not None:
                              dct['args'] = args
                      Severity: Major
                      Found in miasm/arch/msp430/arch.py and 5 other locations - About 3 hrs to fix
                      miasm/arch/arm/arch.py on lines 1707..1712
                      miasm/arch/arm/arch.py on lines 1715..1720
                      miasm/arch/mips32/arch.py on lines 269..274
                      miasm/arch/ppc/arch.py on lines 561..566
                      miasm/arch/sh4/arch.py on lines 665..670

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

                      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 cb_deref_off(tokens):
                          assert len(tokens) == 2
                          result = AstMem(tokens[1] + tokens[0], 16)
                          return result
                      Severity: Major
                      Found in miasm/arch/msp430/arch.py and 2 other locations - About 2 hrs to fix
                      miasm/arch/sh4/arch.py on lines 68..71
                      miasm/arch/sh4/arch.py on lines 74..77

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

                      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

                                      o = "%s(%s)" % (
                                          color_expr_html(expr.ptr.args[1], loc_db),
                                          color_expr_html(expr.ptr.args[0], loc_db)
                      Severity: Major
                      Found in miasm/arch/msp430/arch.py and 1 other location - About 1 hr to fix
                      miasm/arch/mep/arch.py on lines 118..120

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

                      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 cb_deref_nooff(tokens):
                          assert len(tokens) == 1
                          result = AstMem(tokens[0], 16)
                          return result
                      Severity: Major
                      Found in miasm/arch/msp430/arch.py and 1 other location - About 1 hr to fix
                      miasm/arch/sh4/arch.py on lines 50..53

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

                      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 7 locations. Consider refactoring.
                      Open

                          @classmethod
                          def gen_modes(cls, subcls, name, bases, dct, fields):
                              dct['mode'] = None
                              return [(subcls, name, bases, dct, fields)]
                      Severity: Major
                      Found in miasm/arch/msp430/arch.py and 6 other locations - About 45 mins to fix
                      miasm/arch/aarch64/arch.py on lines 569..572
                      miasm/arch/arm/arch.py on lines 741..744
                      miasm/arch/arm/arch.py on lines 839..842
                      miasm/arch/mips32/arch.py on lines 253..256
                      miasm/arch/ppc/arch.py on lines 290..293
                      miasm/arch/sh4/arch.py on lines 550..553

                      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 2 locations. Consider refactoring.
                      Open

                      bs_f1 = bs_name(
                          l=4, name={
                              'mov': 4, 'add': 5, 'addc': 6, 'subc': 7, 'sub': 8, 'cmp': 9,
                              'dadd': 10, 'bit': 11, 'bic': 12, 'bis': 13, 'xor': 14, 'and': 15})
                      Severity: Minor
                      Found in miasm/arch/msp430/arch.py and 1 other location - About 35 mins to fix
                      miasm/arch/mips32/arch.py on lines 628..640

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

                      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