cea-sec/miasm

View on GitHub
miasm/jitter/codegen.py

Summary

Maintainability
F
3 days
Test Coverage

File codegen.py has 529 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Module to generate C code for a given native @block
"""

from builtins import zip
Severity: Major
Found in miasm/jitter/codegen.py - About 1 day to fix

    Function gen_c_assignments has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

        def gen_c_assignments(self, assignblk):
            """
            Return C information used to generate the C code of the @assignblk
            @assignblk: an AssignBlock instance
            """
    Severity: Minor
    Found in miasm/jitter/codegen.py - About 5 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

    CGen has 30 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class CGen(object):
        """
        Helper to generate C code for a given AsmBlock
        """
    
    
    Severity: Minor
    Found in miasm/jitter/codegen.py - About 3 hrs to fix

      Avoid deeply nested control flow statements.
      Open

                              if src.size <= self.translator.NATIVE_INT_MAX_SIZE:
                                  c_mem.append('MEM_WRITE_BN_INT(jitcpu, %d, %s, %s);' % (
                                      src.size, ptr_str, self.id_to_c(src))
                                  )
                              else:
      Severity: Major
      Found in miasm/jitter/codegen.py - About 45 mins to fix

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

            def gen_dst_goto(self, attrib, instr_offsets, dst2index):
                """
                Generate code for possible @dst2index.
        
                @attrib: an Attributes instance
        Severity: Minor
        Found in miasm/jitter/codegen.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 traverse_expr_dst has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def traverse_expr_dst(self, expr, dst2index):
                """
                Generate the index of the destination label for the @expr
                @dst2index: dictionary to link label to its index
                """
        Severity: Minor
        Found in miasm/jitter/codegen.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 gen_c has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def gen_c(self, block, log_mn=False, log_regs=False):
                """
                Generate the C code for the @block and return it as a list of lines
                @log_mn: log mnemonics
                @log_regs: log registers
        Severity: Minor
        Found in miasm/jitter/codegen.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

        Avoid too many return statements within this function.
        Open

                return ("-1", self.id_to_c(expr))
        Severity: Major
        Found in miasm/jitter/codegen.py - About 30 mins to fix

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

                  for var in viewvalues(prefetchers):
                      if var.size <= self.translator.NATIVE_INT_MAX_SIZE:
                          c_var.append("uint%d_t %s;" % (var.size, var))
                      else:
                          c_var.append("bn_t %s; // %d" % (var, var.size))
          Severity: Major
          Found in miasm/jitter/codegen.py and 1 other location - About 2 hrs to fix
          miasm/jitter/codegen.py on lines 312..315

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

          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 dst.size <= self.translator.NATIVE_INT_MAX_SIZE:
                          c_var.append("uint%d_t %s;" % (new_dst.size, new_dst))
                      else:
                          c_var.append("bn_t %s; // %d" % (new_dst, new_dst.size))
          Severity: Major
          Found in miasm/jitter/codegen.py and 1 other location - About 2 hrs to fix
          miasm/jitter/codegen.py on lines 256..260

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

          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 gen_check_memory_exception(self, address):
                  """Generate C code to check memory exceptions
                  @address: address of the faulty instruction"""
                  dst = self.dst_to_c(address)
                  return (self.CODE_EXCEPTION_MEM_AT_INSTR % (self.C_PC, dst, dst)).split('\n')
          Severity: Major
          Found in miasm/jitter/codegen.py and 1 other location - About 1 hr to fix
          miasm/jitter/codegen.py on lines 325..329

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

          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 gen_check_cpu_exception(self, address):
                  """Generate C code to check cpu exceptions
                  @address: address of the faulty instruction"""
                  dst = self.dst_to_c(address)
                  return (self.CODE_EXCEPTION_AT_INSTR % (self.C_PC, dst, dst)).split('\n')
          Severity: Major
          Found in miasm/jitter/codegen.py and 1 other location - About 1 hr to fix
          miasm/jitter/codegen.py on lines 319..323

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

          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