ducky/tools/ld.py

Summary

Maintainability
F
4 days
Test Coverage

Function resolve_relocations has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
Open

def resolve_relocations(info, f_out, f_ins):
  logger, D = get_logger(), get_logger().debug

  D('')
  D('----- * ----- * ----- * ----- * -----')
Severity: Minor
Found in ducky/tools/ld.py - About 1 day 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 ld.py has 450 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import ast
import collections
import logging
import os
import re
Severity: Minor
Found in ducky/tools/ld.py - About 6 hrs to fix

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

    def fix_section_bases(info, f_out):
      logger, D = get_logger(), get_logger().debug
    
      D('----- * ----- * ----- * ----- * -----')
      D('Fixing base addresses of sections')
    Severity: Minor
    Found in ducky/tools/ld.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 main has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def main():
      import optparse
      from . import add_common_options, parse_options
    
      parser = optparse.OptionParser()
    Severity: Minor
    Found in ducky/tools/ld.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 link_files has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def link_files(info, files_in, file_out):
      D = get_logger().debug
    
      fs_in = []
    
    
    Severity: Minor
    Found in ducky/tools/ld.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 __init__ has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def __init__(self, filepath = None):
        self._filepath = filepath
    
        self._dst_section_start = collections.OrderedDict()
        self._dst_section_map = collections.OrderedDict()
    Severity: Minor
    Found in ducky/tools/ld.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 merge_object_into has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def merge_object_into(info, f_dst, f_src):
      D = get_logger().debug
    
      D('----- * ----- * ----- * ----- * -----')
      D('Merging %s file', f_src.name)
    Severity: Minor
    Found in ducky/tools/ld.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 _apply_patch has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def _apply_patch(self, value):
        re = self._re
        se = self._se
    
        self.DEBUG('  value=%s', UINT32_FMT(value))
    Severity: Minor
    Found in ducky/tools/ld.py - About 1 hr to fix

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

        def __init__(self, re, se, symbol_name, section, original_section = None, section_offset = 0):
      Severity: Minor
      Found in ducky/tools/ld.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                  if f_src != f_in and se.flags.globally_visible == 0:
                    raise UnknownSymbolError('Symbol "%s" is not globally visible' % symbol_name)
        
        
        Severity: Major
        Found in ducky/tools/ld.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    if len(symbol_family) > 1:
                      D('  multiple candidates:')
                      for se, f_src in symbol_family:
                        D('    %s from file %s', se, f_src.name)
          
          
          Severity: Major
          Found in ducky/tools/ld.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                      if symbol_name not in section_symbols:
                        raise UnknownSymbolError('No such symbol "%s", referenced from %s' % (symbol_name, f_in.name))
            
            
            Severity: Major
            Found in ducky/tools/ld.py - About 45 mins to fix

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

                def _apply_patch(self, value):
                  re = self._re
                  se = self._se
              
                  self.DEBUG('  value=%s', UINT32_FMT(value))
              Severity: Minor
              Found in ducky/tools/ld.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 resolve_symbols has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              def resolve_symbols(info, f_out, f_ins):
                D = get_logger().debug
              
                D('Resolve symbols - compute their new addresses')
              
              
              Severity: Minor
              Found in ducky/tools/ld.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

                  value = content[content_index] | (content[content_index + 1] << 8) | (content[content_index + 2] << 16) | (content[content_index + 3] << 24)
              Severity: Major
              Found in ducky/tools/ld.py and 1 other location - About 4 hrs to fix
              ducky/tools/objdump.py on lines 126..126

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

              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 section.header.base < base:
                      logger.error('Cannot place %s to a requested base - previous section is too long', name)
                      logger.error('  header: %s', section.header)
                      dump_sections()
                      sys.exit(1)
              Severity: Minor
              Found in ducky/tools/ld.py and 1 other location - About 55 mins to fix
              ducky/tools/ld.py on lines 243..247

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

              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 base + section.header.data_size >= 0xFFFFFFFF:
                      logger.error('Cannot place %s to a base - no space left', name)
                      logger.error('  header: %s', section.header)
                      dump_sections()
                      sys.exit(1)
              Severity: Minor
              Found in ducky/tools/ld.py and 1 other location - About 55 mins to fix
              ducky/tools/ld.py on lines 254..258

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

              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