ANSSI-FR/polichombr

View on GitHub

Showing 1,243 of 1,244 total issues

Perceived complexity for checkCall is too high. [35/7]
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 tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

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

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

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.

Method calculate_machoc_hash has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

  def self.calculate_machoc_hash(dasm)
    @fullFuncSign = ''
    @fullHashSign = ''
    @listoffunct = []
    dasm.function.each do |addr, _symb|
Severity: Minor
Found in polichombr/analysis_tools/AnalyzeIt.rb - About 4 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

Cyclomatic complexity for getArg is too high. [27/6]
Open

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

    carg = 0

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 checkCall has 100 lines of code (exceeds 25 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: Major
Found in polichombr/analysis_tools/AnalyzeIt.rb - About 4 hrs to fix

    Perceived complexity for getArg is too high. [27/7]
    Open

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

    This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

    Example:

    def my_method                   # 1
      if cond                       # 1
        case var                    # 2 (0.8 + 4 * 0.2, rounded)
        when 1 then func_one
        when 2 then func_two
        when 3 then func_three
        when 4..10 then func_other
        end
      else                          # 1
        do_something until a && b   # 2
      end                           # ===
    end                             # 7 complexity points

    Assignment Branch Condition size for parseInstr is too high. [33.44/15]
    Open

    def parseInstr(di)
      return di.to_s.gsub('\\', '\\\\\\').gsub('"', '\\"') if $SVG.nil?
      ret = nil
      if (di.opcode.name == 'call') && (di.instruction.args.length == 1)
        if di.instruction.args.first.to_s[0..3] == 'loc_'

    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

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

    @webuiview.route('/family/<int:family_id>/deletefile/<int:file_id>/')
    @login_required
    def delete_family_file(family_id, file_id):
        """
        Delete a family attached file.
    Severity: Major
    Found in polichombr/views/webui_families.py and 1 other location - About 3 hrs to fix
    polichombr/views/webui_families.py on lines 239..248

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

    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

    @webuiview.route('/family/<int:family_id>/deleteitem/<int:item_id>/')
    @login_required
    def delete_family_item(family_id, item_id):
        """
        Delete a family detection item.
    Severity: Major
    Found in polichombr/views/webui_families.py and 1 other location - About 3 hrs to fix
    polichombr/views/webui_families.py on lines 212..221

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

    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

    @webuiview.route('/sample/<int:sample_id>/removefam/<int:family_id>')
    @login_required
    def ui_sample_remove_family(sample_id, family_id):
        """
        Add or remove the current user to the sample's users.
    Severity: Major
    Found in polichombr/views/webui_sample.py and 1 other location - About 3 hrs to fix
    polichombr/views/webui_sample.py on lines 197..206

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

    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

    @webuiview.route("/sample/<int:sample_id>/checkfield/<int:checklist_id>/")
    @login_required
    def check_field(sample_id, checklist_id):
        """
        Check or uncheck a checklist element.
    Severity: Major
    Found in polichombr/views/webui_sample.py and 1 other location - About 3 hrs to fix
    polichombr/views/webui_sample.py on lines 221..230

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

    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

    Assignment Branch Condition size for printSubCallTree is too high. [32.88/15]
    Open

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

    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. [26/10]
    Open

    def printCallTree(fromaddr, toaddr)
      @currenttree_done = []
      i = 0
      @glinestree = 9999
      log('')

    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.

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

    dasm.decoded.each do |_addr, di|
      if di.instruction.to_s =~ /(564d5868h|5658h)/ || (di.opcode.name == 'sidt') || (di.opcode.name == 'sgdt') || (di.opcode.name == 'sldt') || (di.opcode.name == 'str')
        @instrAntiVM << di
      end
      if di.instruction.to_s =~ /(IsDebuggerPresent|cmp .*, 0CCh|pop ss|SeDebugPrivilege|IsBadWritePtr)/ || (di.opcode.name == 'rtdsc')

    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.

    Method printSubCallTree has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def printSubCallTree(fromaddr, toaddr, indent, cnt)
      return if fromaddr == toaddr
      i = 0
      space1 = ''
      indent.each do |_id, iscontinue|
    Severity: Minor
    Found in polichombr/analysis_tools/AnalyzeIt.rb - 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

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

      File.open(opts[:outfile], 'w') do |fd|
        tbdi.each do |addr|
          di = dasm.di_at(addr)
          next unless di.opcode.name == 'call'
          tdi = dasm.di_at(di.next_addr)

    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.

    FamilyController has 28 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class FamilyController(object):
        """
            Family object controller.
        """
    
    
    Severity: Minor
    Found in polichombr/controllers/family.py - About 3 hrs to fix

      Method has too many lines. [24/10]
      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 if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

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

      dasm.decoded.each do |_addr, di|
        next unless (di.opcode.name == 'xor') && (di.instruction.args.first.to_s != di.instruction.args.last.to_s) && MetasmUtils.is_looping(di)
        next if @CryptoBlocks.include? di.block.address
        @CryptoBlocks << di.block.address
        next if di.instruction.args.last.to_s == '-1'

      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.

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

      class PEExport(db.Model):
          __tablename__ = 'peexport'
          id = db.Column(db.Integer(), primary_key=True)
          module_name = db.Column(db.String(), index=True)
          function_name = db.Column(db.String())
      Severity: Major
      Found in polichombr/models/analysis.py and 1 other location - About 3 hrs to fix
      polichombr/models/analysis.py on lines 71..75

      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

      Severity
      Category
      Status
      Source
      Language