Class: Android::Dex::MethodInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/android/dex/info.rb

Overview

method info object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoded_method, method_id, dex) ⇒ MethodInfo

Returns a new instance of MethodInfo.



132
133
134
135
136
137
# File 'lib/android/dex/info.rb', line 132

def initialize(encoded_method, method_id, dex)
  @encoded_method = encoded_method
  @method_id = method_id
  @dex = dex
  @access_flags = MethodAccessFlag.new(encoded_method[:access_flags])
end

Instance Attribute Details

#access_flagsMethodAccessFlag (readonly)

Returns:



130
131
132
# File 'lib/android/dex/info.rb', line 130

def access_flags
  @access_flags
end

#nameString (readonly)

Returns method name.

Returns:

  • (String)

    method name



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/android/dex/info.rb', line 128

class MethodInfo
  # @return [MethodAccessFlag]
  attr_reader :access_flags

  def initialize(encoded_method, method_id, dex)
    @encoded_method = encoded_method
    @method_id = method_id
    @dex = dex
    @access_flags = MethodAccessFlag.new(encoded_method[:access_flags])
  end
  def name
    @dex.strings[@dex.method_ids[@method_id][:name_idx]]
  end
  def ret_type
    @dex.type_resolve(proto[:return_type_idx])
  end
  def parameters
    unless proto[:parameters_off] == 0
      list = DexObject::TypeList.new(@dex.data, proto[:parameters_off])
      list[:list].map { |item| @dex.type_resolve(item) }
    else
      []
    end
  end

  # @return [String] method definition string
  def definition
    "#{access_flags.to_s} #{ret_type} #{name}(#{parameters.join(', ')});"
  end

  # @return [DexObject::CodeItem]
  def code_item
    @encoded_method.code_item
  end

  private
  def proto
    @dex.proto_ids[@dex.method_ids[@method_id][:proto_idx]]
  end
end

#parametersArray<String> (readonly)

Returns method parameters.

Returns:

  • (Array<String>)

    method parameters



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/android/dex/info.rb', line 128

class MethodInfo
  # @return [MethodAccessFlag]
  attr_reader :access_flags

  def initialize(encoded_method, method_id, dex)
    @encoded_method = encoded_method
    @method_id = method_id
    @dex = dex
    @access_flags = MethodAccessFlag.new(encoded_method[:access_flags])
  end
  def name
    @dex.strings[@dex.method_ids[@method_id][:name_idx]]
  end
  def ret_type
    @dex.type_resolve(proto[:return_type_idx])
  end
  def parameters
    unless proto[:parameters_off] == 0
      list = DexObject::TypeList.new(@dex.data, proto[:parameters_off])
      list[:list].map { |item| @dex.type_resolve(item) }
    else
      []
    end
  end

  # @return [String] method definition string
  def definition
    "#{access_flags.to_s} #{ret_type} #{name}(#{parameters.join(', ')});"
  end

  # @return [DexObject::CodeItem]
  def code_item
    @encoded_method.code_item
  end

  private
  def proto
    @dex.proto_ids[@dex.method_ids[@method_id][:proto_idx]]
  end
end

#ret_typeString (readonly)

Return type of the method

Returns:

  • (String)

    return type of the method



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/android/dex/info.rb', line 128

class MethodInfo
  # @return [MethodAccessFlag]
  attr_reader :access_flags

  def initialize(encoded_method, method_id, dex)
    @encoded_method = encoded_method
    @method_id = method_id
    @dex = dex
    @access_flags = MethodAccessFlag.new(encoded_method[:access_flags])
  end
  def name
    @dex.strings[@dex.method_ids[@method_id][:name_idx]]
  end
  def ret_type
    @dex.type_resolve(proto[:return_type_idx])
  end
  def parameters
    unless proto[:parameters_off] == 0
      list = DexObject::TypeList.new(@dex.data, proto[:parameters_off])
      list[:list].map { |item| @dex.type_resolve(item) }
    else
      []
    end
  end

  # @return [String] method definition string
  def definition
    "#{access_flags.to_s} #{ret_type} #{name}(#{parameters.join(', ')});"
  end

  # @return [DexObject::CodeItem]
  def code_item
    @encoded_method.code_item
  end

  private
  def proto
    @dex.proto_ids[@dex.method_ids[@method_id][:proto_idx]]
  end
end

Instance Method Details

#code_itemDexObject::CodeItem

Returns:



159
160
161
# File 'lib/android/dex/info.rb', line 159

def code_item
  @encoded_method.code_item
end

#definitionString

Returns method definition string.

Returns:

  • (String)

    method definition string



154
155
156
# File 'lib/android/dex/info.rb', line 154

def definition
  "#{access_flags.to_s} #{ret_type} #{name}(#{parameters.join(', ')});"
end