changeset 10:123c7a8bbf4c

Parse EncodedArrayItems
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 24 May 2011 23:47:16 +0800
parents 9a49826b26d4
children 409e2cd76f72
files paraspace/dexfile.py
diffstat 1 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dexfile.py	Tue May 24 15:02:50 2011 +0800
+++ b/paraspace/dexfile.py	Tue May 24 23:47:16 2011 +0800
@@ -868,6 +868,31 @@
     pass
 
 
+class _DEX_EncodedArrayItem(object):
+    elements = None
+
+    data_size = None
+
+    def parse(self, data, off):
+        moff = man_off(off)
+
+        size, sh = _uleb128(data[moff():moff() + 5])
+        moff(sh)
+
+        def parse_element():
+            element = _DEX_AnnotationMember()
+            element.parse_noname(data, moff())
+            moff(element.data_size)
+            return element
+
+        self.elements = [parse_element()
+                         for i in range(size)]
+
+        self.data_size = moff() - off
+        pass
+    pass
+
+
 class DEXFile(object):
     _data = None
     _header = None
@@ -884,6 +909,7 @@
     _annotationSetItems = None
     _annotationsDirectoryItems = None
     _annotationItems = None
+    _encodedArrayItems = None
     
     def __init__(self):
         pass
@@ -1171,6 +1197,24 @@
         self._header = header
         pass
 
+    def _parse_encodedArrayItems(self):
+        data = self._data
+        
+        encodedArrayItem_map = \
+            self.find_map_item_name('kDexTypeEncodedArrayItem')
+        
+        moff = man_off(encodedArrayItem_map.offset)
+
+        def parse_encodedArrayItem():
+            item = _DEX_EncodedArrayItem()
+            item.parse(data, moff())
+            moff(item.data_size)
+            return item
+
+        self._encodedArrayItems = [parse_encodedArrayItem()
+                                   for i in range(encodedArrayItem_map.size)]
+        pass
+
     def parse(self, data):
         self._data = data
         self._parse_header()
@@ -1187,6 +1231,7 @@
         self._parse_annotationSetItems()
         self._parse_annotationsDirectoryItems()
         self._parse_annotationItems()
+        self._parse_encodedArrayItems()
         pass
     pass
 
@@ -1260,6 +1305,11 @@
     print
     print 'AnnotationItems size is %d bytes' % (bytes)
     
+    bytes = sum([encodeditem.data_size
+                 for encodeditem in dex._encodedArrayItems])
+    print
+    print 'EncodedArrayItems size is %d bytes' % (bytes)
+    
     print
     print 'Data maps'
     maps = dex._maps