Class: Android::Dex
- Inherits:
-
Object
- Object
- Android::Dex
- Defined in:
- lib/android/dex.rb,
lib/android/dex/info.rb,
lib/android/dex/utils.rb,
lib/android/dex/dex_object.rb,
lib/android/dex/access_flag.rb
Overview
parsed dex object
Defined Under Namespace
Classes: AccessFlag, ClassAccessFlag, ClassInfo, DexObject, FieldInfo, MethodAccessFlag, MethodInfo
Constant Summary collapse
- TYPE_DESCRIPTOR =
{ 'V' => 'void', 'Z' => 'boolean', 'B' => 'byte', 'S' => 'short', 'C' => 'short', 'I' => 'int', 'J' => 'long', 'F' => 'float', 'D' => 'double' }
Instance Attribute Summary collapse
-
#classes ⇒ Array<Dex::ClassInfo>
readonly
Array of class information.
-
#data ⇒ String
readonly
Dex binary data.
-
#field_ids ⇒ Object
readonly
Returns the value of attribute field_ids.
-
#header ⇒ Dex::Header
(also: #h)
readonly
Dex header information.
-
#method_ids ⇒ Object
readonly
Returns the value of attribute method_ids.
-
#proto_ids ⇒ Object
readonly
Returns the value of attribute proto_ids.
-
#strings ⇒ Array<String>
readonly
strings in dex file.
Class Method Summary collapse
-
.sleb128(data, offset = 0) ⇒ Integer
parse sleb128(signed integer) data.
-
.uleb128(data, offset = 0) ⇒ Integer
parse uleb128(unsigned integer) data.
-
.uleb128p1(data, offset = 0) ⇒ Integer
parse uleb128 + 1 data.
Instance Method Summary collapse
-
#initialize(data) ⇒ Dex
constructor
A new instance of Dex.
- #inspect ⇒ Object
- #type_resolve(typeid) ⇒ Object
Constructor Details
#initialize(data) ⇒ Dex
Returns a new instance of Dex.
22 23 24 25 26 27 |
# File 'lib/android/dex.rb', line 22 def initialize(data) @data = data @data.force_encoding(Encoding::ASCII_8BIT) @classes = [] parse() end |
Instance Attribute Details
#classes ⇒ Array<Dex::ClassInfo> (readonly)
Returns array of class information.
18 19 20 |
# File 'lib/android/dex.rb', line 18 def classes @classes end |
#data ⇒ String (readonly)
Returns dex binary data.
16 17 18 |
# File 'lib/android/dex.rb', line 16 def data @data end |
#field_ids ⇒ Object (readonly)
Returns the value of attribute field_ids.
20 21 22 |
# File 'lib/android/dex.rb', line 20 def field_ids @field_ids end |
#header ⇒ Dex::Header (readonly) Also known as: h
Returns dex header information.
12 13 14 |
# File 'lib/android/dex.rb', line 12 def header @header end |
#method_ids ⇒ Object (readonly)
Returns the value of attribute method_ids.
20 21 22 |
# File 'lib/android/dex.rb', line 20 def method_ids @method_ids end |
#proto_ids ⇒ Object (readonly)
Returns the value of attribute proto_ids.
20 21 22 |
# File 'lib/android/dex.rb', line 20 def proto_ids @proto_ids end |
#strings ⇒ Array<String> (readonly)
strings in dex file.
10 11 12 |
# File 'lib/android/dex.rb', line 10 def strings @strings end |
Class Method Details
.sleb128(data, offset = 0) ⇒ Integer
parse sleb128(signed integer) data
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/android/dex/utils.rb', line 32 def sleb128(data, offset=0) result = 0 shift = 0 d = data[offset...data.size] (0..4).each do |i| byte = d.getbyte(i) result |=((byte & 0x7F) << shift) return (0 == (byte & 0x40) ? result : result - (1 << (shift+7))), i+1 if ((byte & 0x80) == 0) shift += 7 end end |
.uleb128(data, offset = 0) ⇒ Integer
parse uleb128(unsigned integer) data
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/android/dex/utils.rb', line 9 def uleb128(data, offset=0) result = 0 shift = 0 d = data[offset...data.size] (0..4).each do |i| byte = d.getbyte(i) result |= ((byte & 0x7f) << shift) return result, i+1 if ((byte & 0x80) == 0) shift += 7 end end |
.uleb128p1(data, offset = 0) ⇒ Integer
parse uleb128 + 1 data
24 25 26 27 |
# File 'lib/android/dex/utils.rb', line 24 def uleb128p1(data, offset=0) ret, len = self.uleb128(data, offset) return (ret - 1), len end |
Instance Method Details
#inspect ⇒ Object
33 34 35 |
# File 'lib/android/dex.rb', line 33 def inspect "<Android::Dex @classes => #{@classes.size}, datasize => #{@data.size}>" end |
#type_resolve(typeid) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/android/dex.rb', line 52 def type_resolve(typeid) type = strings[@type_ids[typeid]] if type.start_with? '[' type = type[1..type.size] return TYPE_DESCRIPTOR.fetch(type, type) + "[]" # TODO: recursive else return TYPE_DESCRIPTOR.fetch(type, type) end end |