# HG changeset patch # User Thinker K.F. Li # Date 1308846788 -28800 # Node ID 6e4cf690572964d05b0bea06e7f2b8e515c47e16 # Parent 870312703ba101e7ed8fe9973fc961ad5b69a8da Seeking parents in reversed order for _build_associations() diff -r 870312703ba1 -r 6e4cf6905729 paraspace/dex_deptracker.py --- a/paraspace/dex_deptracker.py Thu Jun 23 09:32:51 2011 +0800 +++ b/paraspace/dex_deptracker.py Fri Jun 24 00:33:08 2011 +0800 @@ -166,7 +166,14 @@ def _dex_tree_get_child(obj, child_name): child_parts = child_name.split('.') + last_child_part = '' for child_part in child_parts: + if isinstance(obj, dexfile.cond) and not obj.is_true: + raise AttributeError, \ + 'dexfile.cond is not true for %s of %s' % \ + (last_child_part, child_name) + last_child_part = child_part + if isinstance(obj, list): idx = int(child_part) obj = obj[idx] @@ -587,14 +594,17 @@ for obj, parents, name_path in \ _travel_dex_relocatable(root_obj): if isinstance(obj, dexfile._objs_asso): - for parent in parents: + rev_parents = list(parents) + rev_parents.reverse() + for parent in rev_parents: if isinstance(parent, dexfile.composite): break pass + print parent, obj.left left_elts = _dex_tree_get_child(parent, obj.left) right_elts = _dex_tree_get_child(parent, obj.right) - obj.build_associations() + obj.build_associations(left_elts, right_elts) pass pass pass diff -r 870312703ba1 -r 6e4cf6905729 paraspace/dexfile.py --- a/paraspace/dexfile.py Thu Jun 23 09:32:51 2011 +0800 +++ b/paraspace/dexfile.py Fri Jun 24 00:33:08 2011 +0800 @@ -366,6 +366,21 @@ # def build_associations(self, left, right): raise NotImplementedError, 'build_associations is not implemented' + + def parse(self, parent, data, off): + return self + + def sizeof(self, obj): + return 0 + + def to_str(self): + return '' + + def compute_size(self): + pass + + def children(self): + return [] pass @@ -1061,7 +1076,7 @@ child_names = \ 'registersSize insSize outsSize triesSize debugInfoOff ' \ 'insnsSize insns padding try_items handlers_size ' \ - 'catch_handler_items padding2'.split() + 'catch_handler_items try_catch_asso padding2'.split() pass diff -r 870312703ba1 -r 6e4cf6905729 paraspace/tests/dexfile_test.py --- a/paraspace/tests/dexfile_test.py Thu Jun 23 09:32:51 2011 +0800 +++ b/paraspace/tests/dexfile_test.py Fri Jun 24 00:33:08 2011 +0800 @@ -248,6 +248,13 @@ code_item = dex.codeItems.items[0] assert code_item.debugInfoOff.__class__.__name__ == '_DEX_DebugInfoItem' + + code_item = dex.codeItems.items[4] + assert code_item.try_items.value + try_item = code_item.try_items.value.items[0] + assert try_item.catch_ref is not None + catch_item = code_item.catch_handler_items.value.items[0] + assert catch_item.try_ref is not None anno_dir_item = dex.annotationsDirectoryItems.items[0] assert isinstance(anno_dir_item.classAnnotationsOffRef.value,