changeset 46:94e80f7a61b5

Add dex_deptracker.restore_dependencies()
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 19 Jun 2011 21:08:31 +0800
parents 71218ba3bc8a
children cd4e3584ed7f
files paraspace/dex_deptracker.py
diffstat 1 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dex_deptracker.py	Sun Jun 19 20:53:28 2011 +0800
+++ b/paraspace/dex_deptracker.py	Sun Jun 19 21:08:31 2011 +0800
@@ -667,6 +667,43 @@
     pass
 
 
+## \brief Restore to raw value before linking for dependencies.
+#
+def restore_dependencies(dexroot, all_dep_decls):
+    for obj, parents, name_path in \
+            _travel_dex_relocatable(dexroot):
+        if name_path not in all_dep_decls:
+            continue
+
+        imm_parent = parents[-1]
+        if isinstance(imm_parent, dexfile.cond) and not imm_parent.is_true:
+            continue
+
+        dep = all_dep_decls[name_path]
+        dep_type = dep[0]
+        if dep_type == dexfile.depend_off_rel:
+            depon1 = _rel_offset_marker.find_depon(dep[1], parents)
+            depon2 = _rel_offset_marker.find_depon(dep[2], parents)
+
+            name = name_path.split('.')[-1]
+            off = depon2.data_offset - depon1.data_offset
+            _dex_tree_set_child(imm_parent, name, off)
+        elif dep_type == dexfile.depend_off:
+            depon_name_path = dep[1]
+            depon = markers_info[depon_name_path][obj]
+            name = name_path.split('.')[-1]
+            _dex_tree_set_child(imm_parent, name, depon.data_offset)
+        elif dep_type == dexfile.depend_idx:
+            depon_name_path = dep[1]
+            depon = markers_info[depon_name_path][obj]
+            name = name_path.split('.')[-1]
+            _dex_tree_set_child(imm_parent, name, depon.data_idx)
+        else:
+            raise TypeError, 'invalid depend type %s' % (repr(dep_type))
+        pass
+    pass
+
+
 def _sync_dependencies():
     pass