class SmaliFile
Constants
- ACCESSOR
- CLASS
- FIELD
- INTERFACE
- METHOD
- SUPER
- TYPE
Attributes
class[R]
content[R]
fields[R]
file_path[R]
interfaces[R]
methods[R]
super[R]
Public Class Methods
new(file_path)
click to toggle source
# File lib/dex-oracle/smali_file.rb, line 19 def initialize(file_path) @file_path = file_path @modified = false parse(file_path) end
Public Instance Methods
to_s()
click to toggle source
# File lib/dex-oracle/smali_file.rb, line 35 def to_s @class end
update()
click to toggle source
# File lib/dex-oracle/smali_file.rb, line 25 def update @methods.each do |m| next unless m.modified logger.debug("Updating method: #{m}") update_method(m) m.modified = false end File.open(@file_path, 'w') { |f| f.write(@content) } end
Private Instance Methods
build_method_regex(method_signature)
click to toggle source
# File lib/dex-oracle/smali_file.rb, line 78 def build_method_regex(method_signature) /^\.method (?:#{ACCESSOR} )+#{Regexp.escape(method_signature)}(.+?)^\.end method$/m end
parse(file_path)
click to toggle source
# File lib/dex-oracle/smali_file.rb, line 41 def parse(file_path) logger.debug("Parsing: #{file_path} ...") @content = File.open(file_path, 'r:UTF-8', &:read) @class = @content[CLASS, 1] @super = @content[SUPER, 1] @interfaces = [] @content.scan(INTERFACE).each { |m| @interfaces << m.first } @fields = [] @content.scan(FIELD).each { |m| @fields << SmaliField.new(@class, m.first) } parse_methods end
parse_methods()
click to toggle source
# File lib/dex-oracle/smali_file.rb, line 53 def parse_methods @methods = [] method_signature = nil in_method = false body = nil @content.each_line do |line| if in_method if /^\.end method$/ =~ line in_method = false @methods << SmaliMethod.new(@class, method_signature, body) next end body << line else next unless line.include?('.method ') m = METHOD.match(line) next unless m in_method = true method_signature = m.captures.first body = "\n" end end end
update_method(method)
click to toggle source
# File lib/dex-oracle/smali_file.rb, line 82 def update_method(method) body_regex = build_method_regex(method.signature) @content[body_regex, 1] = method.body end