Mercurial > paraspace
view examples/inject_redir.py @ 137:987fead83ce3
Fix issue that dalvik complaining fail to verify code.
- Since order of typeId and methodId are changed, index values in
code block of methods are invalid after sorting sorted arrays.
- We add dex_sort_sorted_arrays_consistent() function as a wrapper
of dex_sort_sorted_arrays(). It remap indices mentioned in code
blocks after sorting.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 10 Aug 2011 14:04:02 +0800 |
parents | 044bfc415577 |
children |
line wrap: on
line source
## \file # # This is an example of inject a class from source to destinate DEX, and # rewrite all references of a specified class with the injected one and its # methods. All calls of specified class will be redirected to the # injected class. # from paraspace.dexfile import DEXFile, DEXFile_linked from paraspace.dex_deptracker import prepare_dep_decls from paraspace.injection import inject_redir import sys if len(sys.argv) != 6: print >> sys.stderr, \ 'usage: %s <src dex> <inject class> ' \ '<dst dex> <redirect class> <output>' % \ (sys.argv[0]) sys.exit(1) pass if __name__ == '__main__': src_dexname = sys.argv[1] inj_classname = sys.argv[2] dst_dexname = sys.argv[3] redir_classname = sys.argv[4] output_name = sys.argv[5] decls = prepare_dep_decls() src_dex = DEXFile.open(src_dexname) src_linked = DEXFile_linked.build_dependencies(src_dex, decls) dst_dex = DEXFile.open(dst_dexname) dst_linked = DEXFile_linked.build_dependencies(dst_dex, decls) inject_redir(src_linked, inj_classname, dst_linked, redir_classname, decls) restore_raw = dst_linked.to_str() ofile = open(output_name, 'w') ofile.write(restore_raw) ofile.close() pass