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.



113
114
115
116
117
118
# File 'lib/android/dex/info.rb', line 113

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:



111
112
113
# File 'lib/android/dex/info.rb', line 111

def access_flags
  @access_flags
end

#nameString (readonly)

Returns method name.

Returns:

  • (String)

    method name



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/android/dex/info.rb', line 109

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



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/android/dex/info.rb', line 109

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



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/android/dex/info.rb', line 109

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:



140
141
142
# File 'lib/android/dex/info.rb', line 140

def code_item
  @encoded_method.code_item
end

#definitionString

Returns method definition string.

Returns:

  • (String)

    method definition string



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

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