# HG changeset patch # User Thinker K.F. Li # Date 1308547935 -28800 # Node ID cd4e3584ed7f58f9c78528183180cb1ff069f45b # Parent 94e80f7a61b56dec0f438d2d5bf237c62833acd6 Add update_offset() diff -r 94e80f7a61b5 -r cd4e3584ed7f paraspace/dex_deptracker.py --- a/paraspace/dex_deptracker.py Sun Jun 19 21:08:31 2011 +0800 +++ b/paraspace/dex_deptracker.py Mon Jun 20 13:32:15 2011 +0800 @@ -203,7 +203,14 @@ pass -def _travel_dex_relocatable(root_obj, parents=[]): +## \brief Travel the tree of relocatable objects and their attributes. +# +# \param skip_func is a function that returns true for skip a subtree. +# +# \ref skip_func is called for every relocatable and their attributes +# to determines if visiting the object and subtree. +# +def _travel_dex_relocatable(root_obj, parents=[], skip_func=None): stk = [(root_obj, parents, root_obj.__class__.__name__)] def make_travel_info(obj, obj_name, child_name, parents): @@ -218,6 +225,8 @@ while stk: obj, parents, obj_name = stk.pop(0) + if skip_func and skip_func(obj, parents, obj_name): + continue yield (obj, parents, obj_name) if isinstance(obj, list): @@ -667,6 +676,41 @@ pass +def _build_depon_dep_map(all_dep_decls): + def _build_sub_depon_dep(from_path, dep): + depon1 = dep[1] + sub = [(depon1, from_path)] + dep_type = dep[0] + if dep_type == dexfile.depend_off_rel: + depon2 = dep[2] + sub.append((depon2, from_path)) + pass + + return sub + + depon_dep_lsts = [_build_sub_depon_dep(from_path, dep) + for from_path, dep in all_dep_decls.items()] + depon_dep_lst = chain(*depon_dep_lsts) + depon_dep_map = dict(depon_dep_lst) + pass + + +def update_offset(dexroot, all_dep_decls): + depon_dep_map = _build_sub_depon_dep(all_dep_decls) + + def skip_dep(obj, parents, name_path): + if name_path in all_dep_decls: + return True + return False + + for obj, parents, name_path in \ + _travel_dex_relocatable(dexroot, skip_func=skip_dep): + if name_path not in depon_dep_map: + continue + pass + pass + + ## \brief Restore to raw value before linking for dependencies. # def restore_dependencies(dexroot, all_dep_decls):