Mercurial > paraspace
view examples/inject_redir.py @ 149:d4533a59c694
inject_classdefs() also inject relative _DEX_StringIds.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 15 Aug 2011 21:51:39 +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