CalebFenton/dex-oracle

View on GitHub
lib/dex-oracle/plugins/undexguard.rb

Summary

Maintainability
A
55 mins
Test Coverage

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

class Undexguard < Plugin
  attr_reader :optimizations

  include Logging
  include CommonRegex

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

Assignment Branch Condition size for decrypt_multi_bytes is too high. [20.71/15]
Open

  def decrypt_multi_bytes(method)
    target_to_contexts = {}
    target_id_to_output = {}
    matches = method.body.scan(MULTI_BYTES_DECRYPT)
    @optimizations[:string_decrypts] += matches.size if matches

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

Assignment Branch Condition size for process is too high. [19.95/15]
Open

  def process
    method_to_target_to_contexts = {}
    @methods.each do |method|
      logger.info("Undexguarding #{method.descriptor} - stage 1/2")
      target_to_contexts = {}

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

Avoid parameter lists longer than 5 parameters. [10/5]
Open

    matches.each do |original, iv_str, out_reg, iv_class_name, iv_method_signature, iv2_str, iv2_class_name, iv2_method_signature, dec_class_name, dec_method_signature|

This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

Avoid parameter lists longer than 5 parameters. [10/5]
Open

    matches.each do |original, _, arg1, _, arg2, _, arg3, class_name, method_signature, out_reg|

This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

Avoid parameter lists longer than 5 parameters. [7/5]
Open

    matches.each do |original, _, encrypted, _, class_name, method_signature, out_reg|

This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

Avoid parameter lists longer than 5 parameters. [6/5]
Open

    matches.each do |original, _, arg1, class_name, method_signature, out_reg|

This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

Use match? instead of =~ when MatchData is not used.
Open

    if str =~ /\A\[(?:\d+(?:,\d+)*)?\]\z/

In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

Example:

# bad
def foo
  if x =~ /re/
    do_something
  end
end

# bad
def foo
  if x.match(/re/)
    do_something
  end
end

# bad
def foo
  if /re/ === x
    do_something
  end
end

# good
def foo
  if x.match?(/re/)
    do_something
  end
end

# good
def foo
  if x =~ /re/
    do_something(Regexp.last_match)
  end
end

# good
def foo
  if x.match(/re/)
    do_something($~)
  end
end

# good
def foo
  if /re/ === x
    do_something($~)
  end
end

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

  def lookup_strings_1int(method)
    target_to_contexts = {}
    matches = method.body.scan(STRING_LOOKUP_1INT)
    @optimizations[:string_lookups] += matches.size if matches
    matches.each do |original, _, arg1, class_name, method_signature, out_reg|
Severity: Major
Found in lib/dex-oracle/plugins/undexguard.rb and 2 other locations - About 55 mins to fix
lib/dex-oracle/plugins/indexed_class_lookup.rb on lines 53..65
lib/dex-oracle/plugins/indexed_string_lookup.rb on lines 45..57

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

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

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

    if str =~ /\A\[(?:\d+(?:,\d+)*)?\]\z/

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

The use of eval is a serious security risk.
Open

      str = eval(str)

This cop checks for the use of Kernel#eval and Binding#eval.

Example:

# bad

eval(something)
binding.eval(something)

Do not use spaces between -> and opening brace in lambda literals
Open

  MODIFIER = -> (_, output, out_reg) { "const-string #{out_reg}, \"#{output.split('').collect { |e| e.inspect[1..-2] }.join}\"" }

This cop checks for spaces between -> and opening parameter brace in lambda literals.

Example: EnforcedStyle: requirenospace (default)

# bad
  a = -> (x, y) { x + y }

  # good
  a = ->(x, y) { x + y }

Example: EnforcedStyle: require_space

# bad
  a = ->(x, y) { x + y }

  # good
  a = -> (x, y) { x + y }

Missing magic comment # frozen_string_literal: true.
Open

require_relative '../logging'

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: when_needed (default)

# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
  # ...
end

# good
# frozen_string_literal: true

module Foo
  # ...
end

Example: EnforcedStyle: always

# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Example: EnforcedStyle: never

# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true

module Baz
  # ...
end

# good
module Baz
  # ...
end

There are no issues that match your filters.

Category
Status