Class: Headdesk::Apk::Class

Inherits:
Object
  • Object
show all
Defined in:
lib/headdesk/apk/class.rb

Overview

A Smali bytecode class

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(smali_file) ⇒ Class

Returns a new instance of Class.



19
20
21
# File 'lib/headdesk/apk/class.rb', line 19

def initialize(smali_file)
  @smali = File.read(smali_file)
end

Class Method Details

.path_for(decl) ⇒ Object

Formats:

android/content/Context
android.content.Context


15
16
17
# File 'lib/headdesk/apk/class.rb', line 15

def self.path_for(decl)
  File.join(*decl.split(%r{[\/,\.]}))
end

Instance Method Details

#field(name) ⇒ Object



38
39
40
41
42
43
# File 'lib/headdesk/apk/class.rb', line 38

def field(name)
  matchdata = /^\.field .* #{name}.* = "(.*)"$/.match(@smali)
  return nil unless matchdata

  Field.new(matchdata)
end

#field?(name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/headdesk/apk/class.rb', line 34

def field?(name)
  field(name) != false
end

#method(name) ⇒ Object



27
28
29
30
31
32
# File 'lib/headdesk/apk/class.rb', line 27

def method(name)
  matchdata = /(^\.method .* #{name}.*$[\s\S]*?\.end method)/.match(@smali)
  return nil unless matchdata

  Method.new(matchdata)
end

#method?(name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/headdesk/apk/class.rb', line 23

def method?(name)
  method(name) != false
end