ANSSI-FR/polichombr

View on GitHub

Showing 1,243 of 1,244 total issues

File AnalyzeIt.rb has 1196 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require './metasm/metasm'
include Metasm

require 'pp'
require 'date'
Severity: Major
Found in polichombr/analysis_tools/AnalyzeIt.rb - About 3 days to fix

    Assignment Branch Condition size for getArg is too high. [162.7/15]
    Open

      def self.getArg(addrori, arg)
        di = $gdasm.di_at(addrori)
        return nil unless defined?(di.opcode)
    
        carg = 0

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    File sample.py has 868 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    """
        This file is part of Polichombr.
    
        (c) 2017 ANSSI-FR
    
    
    Severity: Major
    Found in polichombr/controllers/sample.py - About 2 days to fix

      Method getArg has a Cognitive Complexity of 88 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.getArg(addrori, arg)
          di = $gdasm.di_at(addrori)
          return nil unless defined?(di.opcode)
      
          carg = 0
      Severity: Minor
      Found in polichombr/analysis_tools/AnalyzeIt.rb - 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

      Method checkCall has a Cognitive Complexity of 85 (exceeds 5 allowed). Consider refactoring.
      Open

      def checkCall(strFunc, xrefCall)
        basefunc = MetasmUtils.find_start_of_function(xrefCall)
        unless basefunc.nil?
          log('')
          log("Top of function : #{PoliUtils.poliLinkAddr(basefunc)} ; Top of block : #{PoliUtils.poliLinkAddr($gdasm.di_at(xrefCall).block.list[0].address)}")
      Severity: Minor
      Found in polichombr/analysis_tools/AnalyzeIt.rb - 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

      Assignment Branch Condition size for checkCall is too high. [113.2/15]
      Open

      def checkCall(strFunc, xrefCall)
        basefunc = MetasmUtils.find_start_of_function(xrefCall)
        unless basefunc.nil?
          log('')
          log("Top of function : #{PoliUtils.poliLinkAddr(basefunc)} ; Top of block : #{PoliUtils.poliLinkAddr($gdasm.di_at(xrefCall).block.list[0].address)}")

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Method has too many lines. [100/10]
      Open

      def checkCall(strFunc, xrefCall)
        basefunc = MetasmUtils.find_start_of_function(xrefCall)
        unless basefunc.nil?
          log('')
          log("Top of function : #{PoliUtils.poliLinkAddr(basefunc)} ; Top of block : #{PoliUtils.poliLinkAddr($gdasm.di_at(xrefCall).block.list[0].address)}")

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Assignment Branch Condition size for find_start_of_function is too high. [92.66/15]
      Open

        def self.find_start_of_function(address)
          blocks = []
          di = $gdasm.di_at(address)
          return nil unless defined?(di.instruction)
          return nil unless defined?(di.block)

      This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

      Class has too many lines. [122/100]
      Open

      class MetasmUtils
        def self.is_linked_block(di, start_address)
          result = false
          @loopcount += 1
          return false if @loopcount > 500

      This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      SampleController has 56 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class SampleController(object):
      
          """
              Wrapper to the Sample model. It is in charge of managing the creation,
              extraction and modification of samples, and all of directly related
      Severity: Major
      Found in polichombr/controllers/sample.py - About 1 day to fix

        Assignment Branch Condition size for repareIatLinks is too high. [64.27/15]
        Open

        def repareIatLinks
          $gdasm.decoded.each do |_addr, di|
            next unless (di.opcode.name == 'mov') && defined?(di.instruction.args.last.symbolic.target)
            label = $gdasm.get_label_at(di.instruction.args.last.symbolic.target.bind.reduce)
            if label =~ /^iat_/

        This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

        Method has too many lines. [58/10]
        Open

          def self.getArg(addrori, arg)
            di = $gdasm.di_at(addrori)
            return nil unless defined?(di.opcode)
        
            carg = 0

        This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

        Assignment Branch Condition size for calculate_machoc_hash is too high. [53.76/15]
        Open

          def self.calculate_machoc_hash(dasm)
            @fullFuncSign = ''
            @fullHashSign = ''
            @listoffunct = []
            dasm.function.each do |addr, _symb|

        This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

        Cyclomatic complexity for checkCall is too high. [43/6]
        Open

        def checkCall(strFunc, xrefCall)
          basefunc = MetasmUtils.find_start_of_function(xrefCall)
          unless basefunc.nil?
            log('')
            log("Top of function : #{PoliUtils.poliLinkAddr(basefunc)} ; Top of block : #{PoliUtils.poliLinkAddr($gdasm.di_at(xrefCall).block.list[0].address)}")

        This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

        An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

        Method has too many lines. [44/10]
        Open

        def printSubCallTree(fromaddr, toaddr, indent, cnt)
          return if fromaddr == toaddr
          i = 0
          space1 = ''
          indent.each do |_id, iscontinue|

        This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

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

        class StringsItem(db.Model):
        
            """
            Strings contained in a binary file. Strings types are defined by the
            StringsType enum class.
        Severity: Major
        Found in polichombr/models/sample.py and 1 other location - About 5 hrs to fix
        polichombr/models/sample.py on lines 20..31

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

        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

        class SampleMetadata(db.Model):
        
            """
                Generic table used to store generic file metadata. Type must be
                defined in the SampleMetadataType enum class below. Value contains
        Severity: Major
        Found in polichombr/models/sample.py and 1 other location - About 5 hrs to fix
        polichombr/models/sample.py on lines 98..108

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

        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

        Block has too many lines. [86/25]
        Open

        tbdi.each do |addr|
          di = dasm.di_at(addr)
          comment = ''
          if di.address == entrypoints[0]
            if dasm.get_label_at(di.address)

        This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

        File family.py has 387 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        """
            This file is part of Polichombr.
        
            (c) 2018 ANSSI-FR
        
        
        Severity: Minor
        Found in polichombr/controllers/family.py - About 5 hrs to fix

          File connection.py has 382 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          """
              Skelenox: the collaborative IDA Pro Agent
          
              This file is part of Polichombr
                  (c) ANSSI-FR 2018
          Severity: Minor
          Found in skelenox_plugin/connection.py - About 5 hrs to fix
            Severity
            Category
            Status
            Source
            Language