cea-sec/miasm

View on GitHub
miasm/ir/translators/C.py

Summary

Maintainability
F
5 days
Test Coverage

Function from_ExprOp has a Cognitive Complexity of 106 (exceeds 5 allowed). Consider refactoring.
Open

    def from_ExprOp(self, expr):
        if len(expr.args) == 1:
            if expr.op == 'parity':
                arg = expr.args[0]
                out = self.from_expr(arg)
Severity: Minor
Found in miasm/ir/translators/C.py - About 2 days 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

File C.py has 467 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from miasm.ir.translators.translator import Translator
from miasm.core.utils import size2mask
from miasm.expression.expression import ExprInt, ExprCond, ExprCompose, \
    TOK_EQUAL, \
    TOK_INF_SIGNED, TOK_INF_UNSIGNED, \
Severity: Minor
Found in miasm/ir/translators/C.py - About 7 hrs to fix

    Function from_ExprCompose has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def from_ExprCompose(self, expr):
            if expr.size <= self.NATIVE_INT_MAX_SIZE:
    
                out = []
                size = get_c_common_next_pow2(expr.size)
    Severity: Minor
    Found in miasm/ir/translators/C.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 too many return statements within this function.
    Open

                    return out
    Severity: Major
    Found in miasm/ir/translators/C.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                      return '(((%s&%s) %s (%s&%s))&%s)' % (
      Severity: Major
      Found in miasm/ir/translators/C.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return "%s(%s, %s)" % (expr.op,
        Severity: Major
        Found in miasm/ir/translators/C.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return out
          Severity: Major
          Found in miasm/ir/translators/C.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return out
            Severity: Major
            Found in miasm/ir/translators/C.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return out
              Severity: Major
              Found in miasm/ir/translators/C.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                return out
                Severity: Major
                Found in miasm/ir/translators/C.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                  return out
                  Severity: Major
                  Found in miasm/ir/translators/C.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                    return "%s_fp%d(%s)" % (
                    Severity: Major
                    Found in miasm/ir/translators/C.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return out
                      Severity: Major
                      Found in miasm/ir/translators/C.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                        return "%s_%d(%s, %s)" % (
                        Severity: Major
                        Found in miasm/ir/translators/C.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return "((%s)&%s)" % (
                          Severity: Major
                          Found in miasm/ir/translators/C.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                            return out
                            Severity: Major
                            Found in miasm/ir/translators/C.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                              return "%s(%s)" % (func, self.from_expr(expr.args[0]))
                              Severity: Major
                              Found in miasm/ir/translators/C.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                                return self.from_expr(new_expr)
                                Severity: Major
                                Found in miasm/ir/translators/C.py - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                                  return "fpu_%s%d(%s)" % (
                                  Severity: Major
                                  Found in miasm/ir/translators/C.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                    return "%s_%d(%s)" % (expr.op, size, self.from_expr(arg))
                                    Severity: Major
                                    Found in miasm/ir/translators/C.py - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                      return "%s(%s)" % (func, self.from_expr(expr.args[0]))
                                      Severity: Major
                                      Found in miasm/ir/translators/C.py - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                        return out
                                        Severity: Major
                                        Found in miasm/ir/translators/C.py - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                          return out
                                          Severity: Major
                                          Found in miasm/ir/translators/C.py - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                            return out
                                            Severity: Major
                                            Found in miasm/ir/translators/C.py - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                              return out
                                              Severity: Major
                                              Found in miasm/ir/translators/C.py - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                                return "segm2addr(jitcpu, %s, %s)" % (
                                                Severity: Major
                                                Found in miasm/ir/translators/C.py - About 30 mins to fix

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

                                                      def from_ExprMem(self, expr):
                                                          ptr = expr.ptr
                                                          if ptr.size <= self.NATIVE_INT_MAX_SIZE:
                                                              new_ptr = self.from_expr(ptr)
                                                              if expr.size <= self.NATIVE_INT_MAX_SIZE:
                                                  Severity: Minor
                                                  Found in miasm/ir/translators/C.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

                                                          if expr.size <= self.NATIVE_INT_MAX_SIZE:
                                                              # BN ptr, Native Mem
                                                              return "MEM_LOOKUP_BN_INT(jitcpu, %d, %s)" % (expr.size, new_ptr)
                                                          else:
                                                              # BN ptr, BN mem
                                                  Severity: Major
                                                  Found in miasm/ir/translators/C.py and 1 other location - About 1 hr to fix
                                                  miasm/ir/translators/C.py on lines 127..132

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

                                                  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

                                                              if expr.size <= self.NATIVE_INT_MAX_SIZE:
                                                                  # Native ptr, Native Mem
                                                                  return "MEM_LOOKUP_%.2d(jitcpu, %s)" % (expr.size, new_ptr)
                                                              else:
                                                                  # Native ptr, BN mem
                                                  Severity: Major
                                                  Found in miasm/ir/translators/C.py and 1 other location - About 1 hr to fix
                                                  miasm/ir/translators/C.py on lines 136..141

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

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

                                                                  new_expr = ExprCompose(
                                                                      arg,
                                                                      ExprCond(
                                                                          arg.msb(),
                                                                          ExprInt(size2mask(add_size), add_size),
                                                  Severity: Major
                                                  Found in miasm/ir/translators/C.py and 2 other locations - About 40 mins to fix
                                                  miasm/expression/simplifications_explicit.py on lines 16..21
                                                  miasm/jitter/llvmconvert.py on lines 903..908

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

                                                  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 not expr.args[0].size <= self.NATIVE_INT_MAX_SIZE:
                                                                      raise ValueError("Bad semantic: fpu do operations do not support such size")
                                                  Severity: Minor
                                                  Found in miasm/ir/translators/C.py and 1 other location - About 35 mins to fix
                                                  miasm/ir/translators/C.py on lines 364..365

                                                  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

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

                                                                  if not expr.args[0].size <= self.NATIVE_INT_MAX_SIZE:
                                                                      raise ValueError("Bad semantic: fpu do operations do not support such size")
                                                  Severity: Minor
                                                  Found in miasm/ir/translators/C.py and 1 other location - About 35 mins to fix
                                                  miasm/ir/translators/C.py on lines 355..356

                                                  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