Class: Unreflector

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

Constant Summary collapse

CLASS_FOR_NAME =
'invoke-static \{[vp]\d+\}, Ljava\/lang\/Class;->forName\(Ljava\/lang\/String;\)Ljava\/lang\/Class;'.freeze
CONST_CLASS_REGEX =
Regexp.new(
  '^[ \t]*(' +
  CONST_STRING + '\s+' +
  CLASS_FOR_NAME + '\s+' +
  MOVE_RESULT_OBJECT + ')'
)
VIRTUAL_FIELD_LOOKUP =
Regexp.new(
  '^[ \t]*(' +
  CONST_STRING + '\s+' \
  'invoke-static \{[vp]\d+\}, Ljava\/lang\/Class;->forName\(Ljava\/lang\/String;\)Ljava\/lang\/Class;\s+' +
  MOVE_RESULT_OBJECT + '\s+' +
  CONST_STRING + '\s+' \
  'invoke-virtual \{[vp]\d+, [vp]\d+\}, Ljava\/lang\/Class;->getField\(Ljava\/lang\/String;\)Ljava\/lang\/reflect\/Field;\s+' +
  MOVE_RESULT_OBJECT + '\s+' \
  'invoke-virtual \{[vp]\d+, ([vp]\d+)\}, Ljava\/lang\/reflect\/Field;->get\(Ljava\/lang\/Object;\)Ljava\/lang\/Object;\s+' +
  MOVE_RESULT_OBJECT + ')'
)
STATIC_FIELD_LOOKUP =
Regexp.new(
  '^[ \t]*(' +
  CONST_STRING + '\s+' +
  CLASS_FOR_NAME + '\s+' +
  MOVE_RESULT_OBJECT + '\s+' +
  CONST_STRING +
  'invoke-virtual \{[vp]\d+, [vp]\d+\}, Ljava\/lang\/Class;->getField\(Ljava\/lang\/String;\)Ljava\/lang\/reflect\/Field;\s+' +
  MOVE_RESULT_OBJECT + '\s+' \
  'const/4 [vp]\d+, 0x0\s+' \
  'invoke-virtual \{[vp]\d+, ([vp]\d+)\}, Ljava\/lang\/reflect\/Field;->get\(Ljava\/lang\/Object;\)Ljava\/lang\/Object;\s+' +
  MOVE_RESULT_OBJECT +
  ')'
)
CLASS_LOOKUP_MODIFIER =
-> (_, output, out_reg) { "const-class #{out_reg}, #{output}" }

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) ⇒ Unreflector

Returns a new instance of Unreflector.



47
48
49
50
51
52
# File 'lib/dex-oracle/plugins/unreflector.rb', line 47

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/unreflector.rb', line 5

def optimizations
  @optimizations
end

Instance Method Details

#processObject



54
55
56
57
58
59
60
61
62
# File 'lib/dex-oracle/plugins/unreflector.rb', line 54

def process
  made_changes = false
  @methods.each do |method|
    logger.info("Unreflecting #{method.descriptor}")
    made_changes |= lookup_classes(method)
  end

  made_changes
end