changeset 142:50d09eba5166

Fix the issue of getting negative indices for _DEX_ClassData. - It caused by calling _optimize_classdata() at end of restore_dependencies() while the values cames from depend_idx_rel.get_value(). The values had been optimized. - Solution is to get value from <child>.data_idx while unlinking.
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 15 Aug 2011 10:04:12 +0800
parents 90690a001172
children c56c7cf32b88
files paraspace/dex_deptracker.py paraspace/tests/injection_test.py
diffstat 2 files changed, 39 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dex_deptracker.py	Sun Aug 14 21:18:48 2011 +0800
+++ b/paraspace/dex_deptracker.py	Mon Aug 15 10:04:12 2011 +0800
@@ -1180,14 +1180,14 @@
             set_child(node, depon.data_idx)
         elif dep_type == dexfile.depend_idx_rel:
             dep, dummy = _resolve_name_path(node.origin_path)
-            idx = dep.get_value(obj, parents)
+            idx = obj.data_idx
             set_child(node, idx)
         else:
             raise TypeError, 'invalid depend type %s' % (repr(dep_type))
         pass
 
+    _optimize_classdata(dexroot)
     _sync_DEXFile_fields(dexroot)
-    _optimize_classdata(dexroot)
     pass
 
 
--- a/paraspace/tests/injection_test.py	Sun Aug 14 21:18:48 2011 +0800
+++ b/paraspace/tests/injection_test.py	Mon Aug 15 10:04:12 2011 +0800
@@ -745,3 +745,40 @@
             pass
         pass
     pass
+
+
+## \brief Test case for getting negative indices in _DEX_ClassDAta.
+#
+# It, possibly, caused by appling _optimize_classdata() at end of
+# restore_dependencies().  But, value was comes from
+# depend_idx_rel.get_value().  It already deoptimize the value.
+#
+def negative_depend_idx_rel_test():
+    from paraspace.dex_deptracker import prepare_dep_decls
+    from paraspace.dex_deptracker import dex_sort_sorted_arrays
+    from paraspace.injection import inject_redir
+    
+    _install_dexfile_4_deptracker()
+    
+    all_dep_decls = prepare_dep_decls()
+    
+    srcdir = os.path.dirname(__file__)
+    datapath = os.path.join(srcdir, '..', '..', 'data')
+
+    fake_path = os.path.join(datapath, 'fakefile.dex')
+    hello_path = os.path.join(datapath, 'helloworld.dex')
+    
+    fake_dex = dexfile.DEXFile.open(fake_path)
+    fake_linked = dexfile.DEXFile_linked.build_dependencies(fake_dex,
+                                                            all_dep_decls)
+
+    hello_dex = dexfile.DEXFile.open(hello_path)
+    hello_linked = dexfile.DEXFile_linked.build_dependencies(hello_dex,
+                                                             all_dep_decls)
+
+    inject_redir(fake_linked, 'Lcom/codemud/fakefile/fakefile;',
+                 hello_linked, 'Ljava/io/File;', all_dep_decls)
+
+    print len(hello_linked.classDatas.items)
+    hello_linked.to_str()
+    pass