# HG changeset patch # User Thinker K.F. Li # Date 1313373852 -28800 # Node ID 50d09eba516605f0030ea243091e5534fe994baf # Parent 90690a0011721fe31bb97e059252cdaf835dbeb3 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 .data_idx while unlinking. diff -r 90690a001172 -r 50d09eba5166 paraspace/dex_deptracker.py --- 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 diff -r 90690a001172 -r 50d09eba5166 paraspace/tests/injection_test.py --- 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