Class: SmaliFile

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/dex-oracle/smali_file.rb

Constant Summary collapse

ACCESSOR =
/(?:abstract|annotation|constructor|enum|final|interface|native|private|protected|public|static|strictfp|synchronized|synthetic|transient|volatile)/
TYPE =
/(?:[IJFDZBCV]|L[^;]+;)/
CLASS =
/^\.class (?:#{ACCESSOR} )+(L[^;]+;)/
SUPER =
/^\.super (L[^;]+;)/
INTERFACE =
/^\.implements (L[^;]+;)/
FIELD =
/^\.field (?:#{ACCESSOR} )+([^\s]+)$/
METHOD =
/^\.method (?:#{ACCESSOR} )+([^\s]+)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, logger, #logger, logger=

Constructor Details

#initialize(file_path) ⇒ SmaliFile

Returns a new instance of SmaliFile.



19
20
21
22
23
# File 'lib/dex-oracle/smali_file.rb', line 19

def initialize(file_path)
  @file_path = file_path
  @modified = false
  parse(file_path)
end

Instance Attribute Details

#classObject (readonly)

Returns the value of attribute class.



7
8
9
# File 'lib/dex-oracle/smali_file.rb', line 7

def class
  @class
end

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/dex-oracle/smali_file.rb', line 7

def content
  @content
end

#fieldsObject (readonly)

Returns the value of attribute fields.



7
8
9
# File 'lib/dex-oracle/smali_file.rb', line 7

def fields
  @fields
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



7
8
9
# File 'lib/dex-oracle/smali_file.rb', line 7

def file_path
  @file_path
end

#interfacesObject (readonly)

Returns the value of attribute interfaces.



7
8
9
# File 'lib/dex-oracle/smali_file.rb', line 7

def interfaces
  @interfaces
end

#methodsObject (readonly)

Returns the value of attribute methods.



7
8
9
# File 'lib/dex-oracle/smali_file.rb', line 7

def methods
  @methods
end

#superObject (readonly)

Returns the value of attribute super.



7
8
9
# File 'lib/dex-oracle/smali_file.rb', line 7

def super
  @super
end

Instance Method Details

#to_sObject



35
36
37
# File 'lib/dex-oracle/smali_file.rb', line 35

def to_s
  @class
end

#updateObject



25
26
27
28
29
30
31
32
33
# 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