<s> from re import finditer <EOL> from sys import argv , exc_info <EOL> import struct <EOL> __NAME__ = "<STR_LIT>" <EOL> __VERSION__ = "<STR_LIT:1.0>" <EOL> def usage ( ) : <EOL> print "<STR_LIT>" % __NAME__ <EOL> def getSize ( f , offset ) : <EOL> f . seek ( offset ) <EOL> try : <EOL> size = struct . unpack ( '<STR_LIT:i>' , f . read ( <NUM_LIT:4> ) ) [ <NUM_LIT:0> ] <EOL> except : <EOL> print "<STR_LIT>" , exc_info ( ) [ <NUM_LIT:0> ] <EOL> return - <NUM_LIT:1> <EOL> return size <EOL> def carveDex ( oat_file , dex_offset , oat_file_name ) : <EOL> print "<STR_LIT>" % dex_offset <EOL> size_offset = dex_offset + <NUM_LIT:32> <EOL> dex_size = getSize ( oat_file , size_offset ) <EOL> if dex_size < <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> return - <NUM_LIT:1> <EOL> print "<STR_LIT>" % dex_size <EOL> carved_name = "<STR_LIT>" % ( oat_file_name , hex ( dex_offset ) ) <EOL> print "<STR_LIT>" % carved_name <EOL> try : <EOL> out_file = open ( carved_name , '<STR_LIT:wb>' ) <EOL> oat_file . seek ( dex_offset ) <EOL> out_file . write ( oat_file . read ( dex_size ) ) <EOL> out_file . close ( ) <EOL> except ( IOError , OSError ) as e : <EOL> print "<STR_LIT>" <EOL> return - <NUM_LIT:2> <EOL> return <NUM_LIT:0> <EOL> def processOat ( oat_file_name ) : <EOL> rtn = <NUM_LIT:0> <EOL> print "<STR_LIT>" % oat_file_name <EOL> try : <EOL> f = open ( oat_file_name , '<STR_LIT:r>' ) <EOL> try : <EOL> s = f . read ( ) <EOL> hits = [ m . start ( ) for m in finditer ( '<STR_LIT>' , s ) ] <EOL> for dex_addr in hits : <EOL> rtn |= carveDex ( f , dex_addr , oat_file_name ) <EOL> finally : <EOL> f . close ( ) <EOL> except ( IOError , OSError ) as e : <EOL> print "<STR_LIT>" % oat_file_name <EOL> return - <NUM_LIT:1> <EOL> return rtn <EOL> def main ( args ) : <EOL> rtn = <NUM_LIT:0> <EOL> for oat in args : <EOL> rtn |= processOat ( oat ) <EOL> return rtn <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if len ( argv ) < <NUM_LIT:2> : <EOL> print "<STR_LIT>" <EOL> exit ( usage ( ) ) <EOL> exit ( main ( argv [ <NUM_LIT:1> : ] ) ) </s>
