changeset 17:d0806672da04

Declare dependencies for dexfile.py
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 01 Jun 2011 13:42:11 +0800
parents 712e76c3d791
children f36b14d1f122
files paraspace/dexfile.py
diffstat 1 files changed, 60 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dexfile.py	Wed Jun 01 10:10:05 2011 +0800
+++ b/paraspace/dexfile.py	Wed Jun 01 13:42:11 2011 +0800
@@ -444,7 +444,7 @@
     pass
 
 
-class cond(composite):
+class cond(relocatable):
     condition = None
     child_type = None
     value = None
@@ -488,7 +488,7 @@
     pass
 
 
-class switch(composite):
+class switch(relocatable):
     selector = None
     map = None
     child_type = None
@@ -556,6 +556,50 @@
     pass
 
 
+class depend(relocatable):
+    depend_on = None
+    child_type = None
+    
+    def __init__(self, depend_on):
+        self.depend_on = depend_on
+        pass
+
+    def __call__(self, child_type):
+        self.child_type = child_type
+        return self
+
+    def parse(self, parent, data, off):
+        v = self.child_type.parse(parent, data, off)
+        return v
+
+    def sizeof(self, v):
+        v = self.child_type.sizeof(v)
+        return v
+
+    def compute_size(self, child):
+        if issubclass(self.child_type, relocatable):
+            self.child_type.compute_size(child)
+            pass
+        pass
+
+    def to_str(self, child):
+        return self.child_type.to_str(child)
+    pass
+
+
+class depend_off(depend):
+    pass
+
+
+class depend_off_rel(depend):
+    relative_to = None
+
+    def __init__(self, relative_to, depend_on):
+        super(depend_off_rel, self).__init__(depend_on)
+        pass
+    pass
+
+
 class _DEX_header(composite):
     magic = rawstr(8)
     checksum = uint32
@@ -631,7 +675,7 @@
 
 
 class _DEX_StringId(composite):
-    stringDataOff = uint32
+    stringDataOff = depend_off('_DEX_StringDataItem')(uint32)
 
     child_names = ('stringDataOff',)
     pass
@@ -647,7 +691,7 @@
 class _DEX_ProtoId(composite):
     shortyIdx = uint32
     returnTypeIdx = uint32
-    parametersOff = uint32
+    parametersOff = depend_off('_DEX_TypeList')(uint32)
     
     child_names = 'shortyIdx returnTypeIdx parametersOff'.split()
     pass
@@ -675,11 +719,11 @@
     classIdx = uint32
     accessFlags = uint32
     superclassIdx = uint32
-    interfacesOff = uint32
+    interfacesOff = depend_off('_DEX_TypeList')(uint32)
     sourceFileIdx = uint32
-    annotationsOff = uint32
+    annotationsOff = depend_off('_DEX_AnnotationsDirectoryItem')(uint32)
     classDataOff = uint32
-    staticValuesOff = uint32
+    staticValuesOff = depend_off('_DEX_EncodedArrayItem')(uint32)
     
     child_names = \
         'classIdx accessFlags superclassIdx interfacesOff ' \
@@ -710,7 +754,7 @@
 class _DEX_Method(composite):
     methodIdx = uleb128
     accessFlags = uleb128
-    codeOff = uleb128
+    codeOff = depend_off('_DEX_Code')(uleb128)
 
     child_names = 'methodIdx accessFlags codeOff'.split()
     pass
@@ -741,7 +785,8 @@
 class _DEX_Try(composite):
     startAddr = uint32
     insnCount = uint16
-    handlerOff = uint16
+    handlerOff = depend_off_rel('_DEX_Code.handlers_size',
+                                '_DEX_Catch')(uint16)
 
     child_names = 'startAddr insnCount handlerOff'.split()
     pass
@@ -787,7 +832,7 @@
     insSize = uint16
     outsSize = uint16
     triesSize = uint16
-    debugInfoOff = uint32
+    debugInfoOff = depend_off('_DEX_DebugInfoItem')(uint32)
     insnsSize = uint32
     insns = rawstr_size_name('insnsSize', 2)
     
@@ -812,7 +857,7 @@
 
 class _DEX_AnnotationSetItem(composite):
     size = uint32
-    annotationOffs = array('size', uint32)
+    annotationOffs = array('size', depend_off('_DEX_AnnotationItem')(uint32))
 
     child_names = 'size annotationOffs'.split()
     pass
@@ -820,7 +865,7 @@
 
 class _DEX_FieldAnnotationsItem(composite):
     fieldIdx = uint32
-    annotationsOff = uint32
+    annotationsOff = depend_off('_DEX_AnnotationSetItem')(uint32)
     
     child_names = 'fieldIdx annotationsOff'.split()
     pass
@@ -828,7 +873,7 @@
 
 class _DEX_MethodAnnotationsItem(composite):
     methodIdx = uint32
-    annotationsOff = uint32
+    annotationsOff = depend_off('_DEX_AnnotationSetItem')(uint32)
 
     child_names = 'methodIdx annotationsOff'.split()
     pass
@@ -836,14 +881,14 @@
 
 class _DEX_ParameterAnnotationsItem(composite):
     methodIdx = uint32
-    annotationsOff = uint32
+    annotationsOff = depend_off('_DEX_AnnotationSetItem')(uint32)
 
     child_names = 'methodIdx annotationsOff'.split()
     pass
 
 
 class _DEX_AnnotationsDirectoryItem(composite):
-    classAnnotationsOff = uint32
+    classAnnotationsOff = depend_off('_DEX_AnnotationSetItem')(uint32)
     fieldsSize = uint32
     methodsSize = uint32
     parametersSize = uint32