Class: StringDecryptor

Inherits:
Plugin
  • Object
show all
Includes:
CommonRegex, Logging
Defined in:
lib/dex-oracle/plugins/string_decryptor.rb

Constant Summary collapse

STRING_DECRYPT =
Regexp.new(
  '^[ \t]*(' +
  CONST_STRING + '\s+' \
  'invoke-static \{[vp]\d+\}, L([^;]+);->([^\(]+\(Ljava/lang/String;\))Ljava/lang/String;' \
  '\s+' +
  MOVE_RESULT_OBJECT + ')'
)
MODIFIER =
-> (_, output, out_reg) { "const-string #{out_reg}, \"#{output.split('').collect { |e| e.inspect[1..-2] }.join}\"" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, logger, #logger, logger=

Methods inherited from Plugin

apply_batch, apply_outputs, dumb_replace, init_plugins, plugin_classes, plugins

Constructor Details

#initialize(driver, smali_files, methods) ⇒ StringDecryptor

Returns a new instance of StringDecryptor.



20
21
22
23
24
25
# File 'lib/dex-oracle/plugins/string_decryptor.rb', line 20

def initialize(driver, smali_files, methods)
  @driver = driver
  @smali_files = smali_files
  @methods = methods
  @optimizations = Hash.new(0)
end

Instance Attribute Details

#optimizationsObject (readonly)

Returns the value of attribute optimizations.



5
6
7
# File 'lib/dex-oracle/plugins/string_decryptor.rb', line 5

def optimizations
  @optimizations
end

Instance Method Details

#processObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dex-oracle/plugins/string_decryptor.rb', line 27

def process
  method_to_target_to_contexts = {}
  @methods.each do |method|
    logger.info("Decrypting strings #{method.descriptor}")
    target_to_contexts = {}
    target_to_contexts.merge!(decrypt_strings(method))
    target_to_contexts.map { |_, v| v.uniq! }
    method_to_target_to_contexts[method] = target_to_contexts unless target_to_contexts.empty?
  end

  made_changes = false
  made_changes |= Plugin.apply_batch(@driver, method_to_target_to_contexts, MODIFIER)

  made_changes
end