changeset 87:cd1ee85853f4

Add injection.py
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 23 Jul 2011 23:02:39 +0800
parents 793af8437efe
children bbe8d5cbe368
files paraspace/injection.py
diffstat 1 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paraspace/injection.py	Sat Jul 23 23:02:39 2011 +0800
@@ -0,0 +1,47 @@
+
+def _deep_travel(obj, cloner, adjuster, visit_log=None):
+    from paraspace.dexfile import _dex_type
+    
+    if not visit_log:
+        visit_log = {}
+        pass
+
+    if id(obj) in visit_log:
+        return visit_log[id(obj)]
+
+    attrs = [attr for attr in dir(obj)
+             if not attr.startswith('_') and \
+                 isinstance(getattr(obj, attr), _dex_type)]
+    
+    pass
+
+
+def dexfile_insert_class(dex, class_def):
+    classId_orig = class_def.classIdx
+    if dex_find_type(dex, class_orig):
+        raise RuntimeError, 'duplicated type'
+    classId = dex_dup_insert_type(dex, classId_orig)
+    
+    superclassId_orig = class_def.superclassId
+    superclassId = dex_find_type(dex, superclassId_orig) or \
+        dex_dup_insert_type(dex, superclassId_orig)
+    
+    if dex.interfacesOffRef.is_true:
+        interfaces_orig = dex.interfacesOffRef.value
+        interfaces = dex_dup_insert_typelist(dex, interfaces_org)
+        pass
+    
+    sourceFileIdx_orig = dex.sourceFileIdx
+    sourceFileIdx = dex_find_type(dex, sourceFileIdx_orig) or \
+        dex_dup_insert_type(dex, sourceFileIdx_orig)
+
+    if dex.annotationsOffRef.is_true:
+        annotations_orig = dex.annotationsOffRef.value
+        annotations = dex_dup_insert(dex, annotations_orig)
+        pass
+
+    if dex.classDataOffRef.is_true:
+        class_data_orig = dex.classDataOffRef.value
+        class_data = dex_dup_insert(dex, class_data_orig)
+        pass
+    pass