Class: Android::Dex::ClassInfo
- Inherits:
-
Object
- Object
- Android::Dex::ClassInfo
- 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
- #access_flags ⇒ ClassAccessFlag readonly
- #class_data ⇒ DexObject::ClassDataItem readonly
- #class_def ⇒ DexObject::ClassDefItem readonly
-
#direct_methods ⇒ Array<MethodInfo>
readonly
Direct methods.
-
#instance_fields ⇒ Array<FieldInfo>
readonly
Instance fields.
-
#name ⇒ String
readonly
return full namespace of class.
-
#static_fields ⇒ Array<FieldInfo>
readonly
Static fields.
-
#super_class ⇒ String
readonly
Super class name.
-
#virtual_methods ⇒ Array<MethodInfo>
readonly
Virtual methods.
Instance Method Summary collapse
-
#definition ⇒ String
Class difinition.
-
#initialize(class_def, dex) ⇒ ClassInfo
constructor
A new instance of ClassInfo.
-
#type ⇒ String
Convert name to human readable string.
Constructor Details
#initialize(class_def, dex) ⇒ ClassInfo
Returns a new instance of ClassInfo.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/android/dex/info.rb', line 60 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_flags ⇒ ClassAccessFlag (readonly)
17 18 19 |
# File 'lib/android/dex/info.rb', line 17 def access_flags @access_flags end |
#class_data ⇒ DexObject::ClassDataItem (readonly)
28 29 30 |
# File 'lib/android/dex/info.rb', line 28 def class_data @class_data end |
#class_def ⇒ DexObject::ClassDefItem (readonly)
30 31 32 |
# File 'lib/android/dex/info.rb', line 30 def class_def @class_def end |
#direct_methods ⇒ Array<MethodInfo> (readonly)
Returns direct methods.
23 24 25 |
# File 'lib/android/dex/info.rb', line 23 def direct_methods @direct_methods end |
#instance_fields ⇒ Array<FieldInfo> (readonly)
Returns instance fields.
21 22 23 |
# File 'lib/android/dex/info.rb', line 21 def instance_fields @instance_fields end |
#name ⇒ String (readonly)
return full namespace of class
sample value like ‘Landroidx/activity/Cancellable;`
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/android/dex/info.rb', line 12 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 # return full namespace of class # # sample value like `Landroidx/activity/Cancellable;` # # @return [String] class name def name @name ||= @dex.type_resolve(@class_def[:class_idx]) end def super_class @super_class ||= if @class_def[:superclass_idx] != NO_INDEX @dex.type_resolve(@class_def[:superclass_idx]) else nil end end # Convert name to human readable string # # From `Landroidx/activity/Cancellable;` to `androidx.activity.Cancellable` # # @return [String] human readable name def type @type ||= name.gsub('/', '.')[1..-2] 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_fields ⇒ Array<FieldInfo> (readonly)
Returns static fields.
19 20 21 |
# File 'lib/android/dex/info.rb', line 19 def static_fields @static_fields end |
#super_class ⇒ String (readonly)
Returns super class name.
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/android/dex/info.rb', line 12 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 # return full namespace of class # # sample value like `Landroidx/activity/Cancellable;` # # @return [String] class name def name @name ||= @dex.type_resolve(@class_def[:class_idx]) end def super_class @super_class ||= if @class_def[:superclass_idx] != NO_INDEX @dex.type_resolve(@class_def[:superclass_idx]) else nil end end # Convert name to human readable string # # From `Landroidx/activity/Cancellable;` to `androidx.activity.Cancellable` # # @return [String] human readable name def type @type ||= name.gsub('/', '.')[1..-2] 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_methods ⇒ Array<MethodInfo> (readonly)
Returns virtual methods.
25 26 27 |
# File 'lib/android/dex/info.rb', line 25 def virtual_methods @virtual_methods end |
Instance Method Details
#definition ⇒ String
Returns class difinition.
75 76 77 78 |
# File 'lib/android/dex/info.rb', line 75 def definition ret = "#{access_flags} class #{name}" super_class.nil? ? ret : ret + " extends #{super_class}" end |
#type ⇒ String
Convert name to human readable string
From ‘Landroidx/activity/Cancellable;` to `androidx.activity.Cancellable`
54 55 56 |
# File 'lib/android/dex/info.rb', line 54 def type @type ||= name.gsub('/', '.')[1..-2] end |