changeset 121:7644cb633d4b

Synchronize value of fields of DEXFile. - It keeps field value of header and maps consistence with latest data layout.
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 06 Aug 2011 08:49:30 +0800
parents c7a5de2d2334
children 6e4b6414789b
files paraspace/dex_deptracker.py paraspace/dexfile.py
diffstat 2 files changed, 73 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dex_deptracker.py	Fri Aug 05 21:51:35 2011 +0800
+++ b/paraspace/dex_deptracker.py	Sat Aug 06 08:49:30 2011 +0800
@@ -843,6 +843,77 @@
     pass
 
 
+def _sync_dex_header(dex):
+    header = dex.header
+    map_items = dex.maps.items.items
+    for map_item in map_items:
+        itype = map_item.type
+        map_name = dexfile._DEX_MapItem.types[itype]
+        if map_name == 'kDexTypeHeaderItem':
+            pass
+        elif map_name == 'kDexTypeStringIdItem':
+            header.stringIdsSize = map_item.size
+            header.stringIdsOff = map_item.offset
+            pass
+        elif map_name == 'kDexTypeTypeIdItem':
+            header.typeIdsSize = map_item.size
+            header.typeIdsOff = map_item.offset
+            pass
+        elif map_name == 'kDexTypeProtoIdItem':
+            header.protoIdsSize = map_item.size
+            header.protoIdsOff = map_item.offset
+            pass
+        elif map_name == 'kDexTypeFieldIdItem':
+            header.fieldIdsSize = map_item.size
+            header.fieldIdsOff = map_item.offset
+            pass
+        elif map_name == 'kDexTypeMethodIdItem':
+            header.methodIdsSize = map_item.size
+            header.methodIdsOff = map_item.offset
+            pass
+        elif map_name == 'kDexTypeClassDefItem':
+            header.classDefsSize = map_item.size
+            header.classDefsOff = map_item.offset
+            pass
+        elif map_name == 'kDexTypeMapList':
+            header.mapOff = map_item.offset
+            pass
+        pass
+    
+    classdef_raw_size = dexfile.array.sizeof(dex.classDefs)
+    header.dataOff = header.classDefsOff + classdef_raw_size
+    header.dataSize = header.fileSize - header.dataOff
+    pass
+
+
+def _sync_dex_maps(dex):
+    map_items = dex.maps.items.items
+    moff = dexfile.man_off(0)
+
+    for map_item in map_items:
+        attr_name = dexfile.DEXFile.block_defs[map_item.type]
+        obj = getattr(dex, attr_name)
+        
+        data_sz = obj.sizeof(obj)
+        map_item.offset = moff(data_sz)
+        if attr_name not in ('maps', 'header'):
+            map_item.size = len(obj.items)
+        else:
+            map_item.size = obj.sizeof(obj)
+            pass
+        pass
+    pass
+
+
+def _sync_DEXFile_fields(dex):
+    dex.compute_size()
+    dex.header.fileSize = dex.sizeof(dex)
+    
+    _sync_dex_maps(dex)
+    _sync_dex_header(dex)
+    pass
+
+
 ## \brief Restore to raw value before linking for dependencies.
 #
 def restore_dependencies(dexroot, all_dep_decls):
@@ -875,6 +946,8 @@
         else:
             raise TypeError, 'invalid depend type %s' % (repr(dep_type))
         pass
+
+    _sync_DEXFile_fields(dexroot)
     pass
 
 
--- a/paraspace/dexfile.py	Fri Aug 05 21:51:35 2011 +0800
+++ b/paraspace/dexfile.py	Sat Aug 06 08:49:30 2011 +0800
@@ -1649,8 +1649,6 @@
     def make_checksum(self):
         from paraspace.tools import adler32
         
-        self.compute_size()
-        self.header.fileSize = self.sizeof(self)
         raw = self.to_str()
         sz = self.header.fileSize
         nosum = _DEX_header.magic.sizeof(self.header.magic) + \