<s> import sys <EOL> import logging <EOL> import argparse <EOL> from impacket . examples import logger <EOL> from impacket import version <EOL> from impacket . ese import ESENT_DB <EOL> def dumpPage ( ese , pageNum ) : <EOL> data = ese . getPage ( pageNum ) <EOL> data . dump ( ) <EOL> def exportTable ( ese , tableName ) : <EOL> cursor = ese . openTable ( tableName ) <EOL> if cursor is None : <EOL> logging . error ( '<STR_LIT>' % tableName ) <EOL> return <EOL> i = <NUM_LIT:1> <EOL> print "<STR_LIT>" % tableName <EOL> while True : <EOL> try : <EOL> record = ese . getNextRow ( cursor ) <EOL> except : <EOL> logging . error ( '<STR_LIT>' ) <EOL> continue <EOL> if record is None : <EOL> break <EOL> print "<STR_LIT>" % i <EOL> for j in record . keys ( ) : <EOL> if record [ j ] is not None : <EOL> print "<STR_LIT>" % ( j , record [ j ] ) <EOL> i += <NUM_LIT:1> <EOL> def main ( ) : <EOL> print version . BANNER <EOL> logger . init ( ) <EOL> parser = argparse . ArgumentParser ( add_help = True , description = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , help = '<STR_LIT>' ) <EOL> subparsers = parser . add_subparsers ( help = '<STR_LIT>' , dest = '<STR_LIT:action>' ) <EOL> dump_parser = subparsers . add_parser ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> dump_parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , required = True , help = '<STR_LIT>' ) <EOL> subparsers . add_parser ( '<STR_LIT:info>' , help = '<STR_LIT>' ) <EOL> export_parser = subparsers . add_parser ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> export_parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , required = True , help = '<STR_LIT>' ) <EOL> if len ( sys . argv ) == <NUM_LIT:1> : <EOL> parser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> options = parser . parse_args ( ) <EOL> if options . debug is True : <EOL> logging . getLogger ( ) . setLevel ( logging . DEBUG ) <EOL> else : <EOL> logging . getLogger ( ) . setLevel ( logging . INFO ) <EOL> ese = ESENT_DB ( options . databaseFile ) <EOL> try : <EOL> if options . action . upper ( ) == '<STR_LIT>' : <EOL> ese . printCatalog ( ) <EOL> elif options . action . upper ( ) == '<STR_LIT>' : <EOL> dumpPage ( ese , int ( options . page ) ) <EOL> elif options . action . upper ( ) == '<STR_LIT>' : <EOL> exportTable ( ese , options . table ) <EOL> else : <EOL> logging . error ( '<STR_LIT>' % options . action ) <EOL> raise <EOL> except Exception , e : <EOL> print e <EOL> ese . close ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) <EOL> sys . exit ( <NUM_LIT:1> ) </s>
