# HG changeset patch # User Thinker K.F. Li # Date 1306921884 -28800 # Node ID f36b14d1f1222374f3cc54fb288b4cbf7566a38f # Parent d0806672da04bd5e1d2c600d8c942681fee677f4 collect dependencies for classes in dexfile.py diff -r d0806672da04 -r f36b14d1f122 paraspace/dexfile.py --- a/paraspace/dexfile.py Wed Jun 01 13:42:11 2011 +0800 +++ b/paraspace/dexfile.py Wed Jun 01 17:51:24 2011 +0800 @@ -1344,6 +1344,58 @@ pass +_nest_types = (array, cond, switch) + + +def _dig_clazz(clazz_name, clazz, population): + deps = {} + + for attr in dir(clazz): + namelist = [clazz_name, attr] + value_type = getattr(clazz, attr) + while isinstance(value_type, _nest_types) or \ + (type(value_type) == type and + issubclass(value_type, _nest_types)): + if isinstance(value_type, array): + namelist.append('items') + value_type = value_type.child_type + elif isinstance(value_type, cond): + namelist.append('value') + value_type = value_type.child_type + elif isinstance(value_type, switch): + namelist.append('value') + value_type = value_type.child_type + pass + pass + + if isinstance(value_type, depend): + from_name = '.'.join(namelist) + if isinstance(value_type, depend_off): + depend_name = value_type.depend_on + deps[from_name] = (depend_off, depend_name) + elif isinstance(value_type, depend_off_rel): + depend_name = value_type.depend_on + relative_to = value_type.relative_to + deps[from_name] = (depend_off_rel, depend_name, relative_to) + pass + pass + pass + return deps + +def collect_dependencies(): + population = dict([(name, value) + for name, value in globals().items() + if name.startswith('_DEX_')]) + + all_deps = {} + for clazz_name, clazz in population.items(): + deps = _dig_clazz(clazz_name, clazz, population) + all_deps.update(deps) + pass + + return all_deps + + if __name__ == '__main__': dex = DEXFile.open('../data/testdata1.dex') @@ -1412,4 +1464,10 @@ map.types[map.type], map.size, map.offset) + pass + + import pprint + print + print 'Dependencies' + pprint.pprint(collect_dependencies()) pass