Class: Android::Dex::ClassInfo

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

Overview

class information in dex

Constant Summary collapse

NO_INDEX =

no index flag

0xffffffff

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_def, dex) ⇒ ClassInfo

Returns a new instance of ClassInfo.

Parameters:

  • class_def (Dex::ClassDefItem)
  • dex (Dex)

    dex class instance



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/android/dex/info.rb', line 42

def initialize(class_def, dex)
  @class_def = class_def
  @dex = dex
  @access_flags = ClassAccessFlag.new(@class_def[:access_flags])
  @class_data = @class_def.class_data_item
  @static_fields = @instance_fields = @direct_methods = @virtual_methods = []
  unless @class_data.nil?
    @static_fields = cls2info(@class_data[:static_fields], FieldInfo, :field_idx_diff)
    @instance_fields = cls2info(@class_data[:instance_fields], FieldInfo, :field_idx_diff)
    @direct_methods = cls2info(@class_data[:direct_methods], MethodInfo, :method_idx_diff)
    @virtual_methods = cls2info(@class_data[:virtual_methods], MethodInfo, :method_idx_diff)
  end
end

Instance Attribute Details

#access_flagsClassAccessFlag (readonly)

Returns:



15
16
17
# File 'lib/android/dex/info.rb', line 15

def access_flags
  @access_flags
end

#class_dataDexObject::ClassDataItem (readonly)



26
27
28
# File 'lib/android/dex/info.rb', line 26

def class_data
  @class_data
end

#class_defDexObject::ClassDefItem (readonly)



28
29
30
# File 'lib/android/dex/info.rb', line 28

def class_def
  @class_def
end

#direct_methodsArray<MethodInfo> (readonly)

Returns direct methods.

Returns:



21
22
23
# File 'lib/android/dex/info.rb', line 21

def direct_methods
  @direct_methods
end

#instance_fieldsArray<FieldInfo> (readonly)

Returns instance fields.

Returns:



19
20
21
# File 'lib/android/dex/info.rb', line 19

def instance_fields
  @instance_fields
end

#nameString (readonly)

Returns class name.

Returns:

  • (String)

    class name



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/android/dex/info.rb', line 10

class ClassInfo
  # no index flag
  NO_INDEX = 0xffffffff

  # @return [ClassAccessFlag]
  attr_reader :access_flags
  # @return [Array<FieldInfo>] static fields
  attr_reader :static_fields
  # @return [Array<FieldInfo>] instance fields
  attr_reader :instance_fields
  # @return [Array<MethodInfo>] direct methods
  attr_reader :direct_methods
  # @return [Array<MethodInfo>] virtual methods
  attr_reader :virtual_methods

  # @return [DexObject::ClassDataItem]
  attr_reader :class_data
  # @return [DexObject::ClassDefItem]
  attr_reader :class_def

  def name
    @dex.type_resolve(@class_def[:class_idx])
  end
  def super_class
    if @class_def[:superclass_idx] != NO_INDEX
      @super_class = @dex.type_resolve(@class_def[:superclass_idx]) 
    else
      nil
    end
  end
  # @param [Dex::ClassDefItem] class_def
  # @param [Dex] dex dex class instance
  def initialize(class_def, dex)
    @class_def = class_def
    @dex = dex
    @access_flags = ClassAccessFlag.new(@class_def[:access_flags])
    @class_data = @class_def.class_data_item
    @static_fields = @instance_fields = @direct_methods = @virtual_methods = []
    unless @class_data.nil?
      @static_fields = cls2info(@class_data[:static_fields], FieldInfo, :field_idx_diff)
      @instance_fields = cls2info(@class_data[:instance_fields], FieldInfo, :field_idx_diff)
      @direct_methods = cls2info(@class_data[:direct_methods], MethodInfo, :method_idx_diff)
      @virtual_methods = cls2info(@class_data[:virtual_methods], MethodInfo, :method_idx_diff)
    end
  end

  # @return [String] class difinition
  def definition
    ret = "#{access_flags} class #{name}"
    super_class.nil? ? ret : ret + " extends #{super_class}"
  end

  private
  def cls2info(arr, cls, idx_key)
    idx = 0
    ret = []
    arr.each do |item|
      idx += item[idx_key]
      ret << cls.new(item, idx, @dex)
    end
    ret
  end
end

#static_fieldsArray<FieldInfo> (readonly)

Returns static fields.

Returns:



17
18
19
# File 'lib/android/dex/info.rb', line 17

def static_fields
  @static_fields
end

#super_classString (readonly)

Returns super class name.

Returns:

  • (String)

    super class name



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/android/dex/info.rb', line 10

class ClassInfo
  # no index flag
  NO_INDEX = 0xffffffff

  # @return [ClassAccessFlag]
  attr_reader :access_flags
  # @return [Array<FieldInfo>] static fields
  attr_reader :static_fields
  # @return [Array<FieldInfo>] instance fields
  attr_reader :instance_fields
  # @return [Array<MethodInfo>] direct methods
  attr_reader :direct_methods
  # @return [Array<MethodInfo>] virtual methods
  attr_reader :virtual_methods

  # @return [DexObject::ClassDataItem]
  attr_reader :class_data
  # @return [DexObject::ClassDefItem]
  attr_reader :class_def

  def name
    @dex.type_resolve(@class_def[:class_idx])
  end
  def super_class
    if @class_def[:superclass_idx] != NO_INDEX
      @super_class = @dex.type_resolve(@class_def[:superclass_idx]) 
    else
      nil
    end
  end
  # @param [Dex::ClassDefItem] class_def
  # @param [Dex] dex dex class instance
  def initialize(class_def, dex)
    @class_def = class_def
    @dex = dex
    @access_flags = ClassAccessFlag.new(@class_def[:access_flags])
    @class_data = @class_def.class_data_item
    @static_fields = @instance_fields = @direct_methods = @virtual_methods = []
    unless @class_data.nil?
      @static_fields = cls2info(@class_data[:static_fields], FieldInfo, :field_idx_diff)
      @instance_fields = cls2info(@class_data[:instance_fields], FieldInfo, :field_idx_diff)
      @direct_methods = cls2info(@class_data[:direct_methods], MethodInfo, :method_idx_diff)
      @virtual_methods = cls2info(@class_data[:virtual_methods], MethodInfo, :method_idx_diff)
    end
  end

  # @return [String] class difinition
  def definition
    ret = "#{access_flags} class #{name}"
    super_class.nil? ? ret : ret + " extends #{super_class}"
  end

  private
  def cls2info(arr, cls, idx_key)
    idx = 0
    ret = []
    arr.each do |item|
      idx += item[idx_key]
      ret << cls.new(item, idx, @dex)
    end
    ret
  end
end

#virtual_methodsArray<MethodInfo> (readonly)

Returns virtual methods.

Returns:



23
24
25
# File 'lib/android/dex/info.rb', line 23

def virtual_methods
  @virtual_methods
end

Instance Method Details

#definitionString

Returns class difinition.

Returns:

  • (String)

    class difinition



57
58
59
60
# File 'lib/android/dex/info.rb', line 57

def definition
  ret = "#{access_flags} class #{name}"
  super_class.nil? ? ret : ret + " extends #{super_class}"
end