<s> import sys <EOL> from optparse import OptionParser <EOL> from xml . dom import minidom <EOL> import codecs <EOL> from androguard . core import androconf <EOL> from androguard . core . bytecodes import apk <EOL> from androguard . util import read <EOL> option_0 = { <EOL> '<STR_LIT:name>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } <EOL> option_1 = { <EOL> '<STR_LIT:name>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } <EOL> option_2 = { <EOL> '<STR_LIT:name>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } <EOL> option_3 = { <EOL> '<STR_LIT:name>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } <EOL> option_4 = { '<STR_LIT:name>' : ( '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT:1> } <EOL> option_5 = { <EOL> '<STR_LIT:name>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:action>' : '<STR_LIT:count>' <EOL> } <EOL> options = [ option_0 , option_1 , option_2 , option_3 , option_4 , option_5 ] <EOL> def main ( options , arguments ) : <EOL> if options . input != None : <EOL> buff = "<STR_LIT>" <EOL> arscobj = None <EOL> ret_type = androconf . is_android ( options . input ) <EOL> if ret_type == "<STR_LIT>" : <EOL> a = apk . APK ( options . input ) <EOL> arscobj = a . get_android_resources ( ) <EOL> elif ret_type == "<STR_LIT>" : <EOL> arscobj = apk . ARSCParser ( read ( options . input ) ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> return <EOL> if not options . package and not options . type and not options . locale : <EOL> buff = "<STR_LIT>" <EOL> for package in arscobj . get_packages_names ( ) : <EOL> buff += package + "<STR_LIT:\n>" <EOL> for locale in arscobj . get_locales ( package ) : <EOL> buff += "<STR_LIT:\t>" + repr ( locale ) + "<STR_LIT:\n>" <EOL> for ttype in arscobj . get_types ( package , locale ) : <EOL> buff += "<STR_LIT>" + ttype + "<STR_LIT:\n>" <EOL> else : <EOL> package = options . package or arscobj . get_packages_names ( ) [ <NUM_LIT:0> ] <EOL> ttype = options . type or "<STR_LIT>" <EOL> locale = options . locale or '<STR_LIT>' <EOL> buff = minidom . parseString ( getattr ( <EOL> arscobj , "<STR_LIT>" + ttype + "<STR_LIT>" ) ( package , <EOL> locale ) ) . toprettyxml ( ) <EOL> if options . output != None : <EOL> fd = codecs . open ( options . output , "<STR_LIT:w>" , "<STR_LIT:utf-8>" ) <EOL> fd . write ( buff ) <EOL> fd . close ( ) <EOL> else : <EOL> print buff <EOL> elif options . version != None : <EOL> print "<STR_LIT>" % androconf . ANDROGUARD_VERSION <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> parser = OptionParser ( ) <EOL> for option in options : <EOL> param = option [ '<STR_LIT:name>' ] <EOL> del option [ '<STR_LIT:name>' ] <EOL> parser . add_option ( * param , ** option ) <EOL> options , arguments = parser . parse_args ( ) <EOL> sys . argv [ : ] = arguments <EOL> main ( options , arguments ) </s>
