#NEWLINE# def print_db( database ) : #NEWLINE# #INDENT# 'Prints out database content.\n    ' #NEWLINE# if PY3 : #NEWLINE# #INDENT# conn = sqlite3 . connect ( str ( database ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# conn = sqlite3 . connect ( database . path ) #NEWLINE# #UNINDENT# conn . row_factory = sqlite3 . Row #NEWLINE# conn . text_factory = ( lambda x : unicode_ ( x , 'utf-8' , 'replace' ) ) #NEWLINE# cur = conn . cursor ( ) #NEWLINE# processes = cur . execute ( '\n        SELECT id, parent, timestamp, exit_timestamp, exitcode, cpu_time\n        FROM processes;\n        ' ) #NEWLINE# print ( '\nProcesses:' ) #NEWLINE# header = '+------+--------+-------+------------------+------------------+----------+' #NEWLINE# print ( header ) #NEWLINE# print ( '|  id  | parent |  exit |     timestamp    |  exit timestamp  | cpu time |' ) #NEWLINE# print ( header ) #NEWLINE# for ( r_id , r_parent , r_timestamp , r_endtime , r_exit , r_cpu_time ) in processes : #NEWLINE# #INDENT# f_id = '{0: 5d} ' . format ( r_id ) #NEWLINE# if ( r_parent is not None ) : #NEWLINE# #INDENT# f_parent = '{0: 7d} ' . format ( r_parent ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f_parent = '        ' #NEWLINE# #UNINDENT# if ( r_exit & 256 ) : #NEWLINE# #INDENT# f_exit = ' sig{0: <2d} ' . format ( r_exit ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f_exit = '    {0: <2d} ' . format ( r_exit ) #NEWLINE# #UNINDENT# f_timestamp = '{0: 17d} ' . format ( r_timestamp ) #NEWLINE# f_endtime = '{0: 17d} ' . format ( r_endtime ) #NEWLINE# if ( r_cpu_time >= 0 ) : #NEWLINE# #INDENT# f_cputime = '{0: 9.2f} ' . format ( ( r_cpu_time * 0.001 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f_cputime = '          ' #NEWLINE# #UNINDENT# print ( '|' . join ( ( '' , f_id , f_parent , f_exit , f_timestamp , f_endtime , f_cputime , '' ) ) ) #NEWLINE# print ( header ) #NEWLINE# #UNINDENT# cur . close ( ) #NEWLINE# cur = conn . cursor ( ) #NEWLINE# processes = cur . execute ( '\n        SELECT id, name, timestamp, process, argv\n        FROM executed_files;\n        ' ) #NEWLINE# print ( '\nExecuted files:' ) #NEWLINE# header = '+--------+------------------+---------+---------------------------------------+' #NEWLINE# print ( header ) #NEWLINE# print ( '|   id   |     timestamp    | process | name and argv                         |' ) #NEWLINE# print ( header ) #NEWLINE# for ( r_id , r_name , r_timestamp , r_process , r_argv ) in processes : #NEWLINE# #INDENT# f_id = '{0: 7d} ' . format ( r_id ) #NEWLINE# f_timestamp = '{0: 17d} ' . format ( r_timestamp ) #NEWLINE# f_proc = '{0: 8d} ' . format ( r_process ) #NEWLINE# argv = r_argv . split ( '\x00' ) #NEWLINE# if ( not argv [ ( - 1 ) ] ) : #NEWLINE# #INDENT# argv = argv [ : ( - 1 ) ] #NEWLINE# #UNINDENT# cmdline = ' ' . join ( ( shell_escape ( a ) for a in argv ) ) #NEWLINE# if ( argv [ 0 ] not in ( r_name , os . path . basename ( r_name ) ) ) : #NEWLINE# #INDENT# cmdline = ( '(%s) %s' % ( shell_escape ( r_name ) , cmdline ) ) #NEWLINE# #UNINDENT# f_cmdline = ' {0: <37s} ' . format ( cmdline ) #NEWLINE# print ( '|' . join ( ( '' , f_id , f_timestamp , f_proc , f_cmdline , '' ) ) ) #NEWLINE# print ( header ) #NEWLINE# #UNINDENT# cur . close ( ) #NEWLINE# cur = conn . cursor ( ) #NEWLINE# processes = cur . execute ( '\n        SELECT id, name, timestamp, mode, process\n        FROM opened_files;\n        ' ) #NEWLINE# print ( '\nFiles:' ) #NEWLINE# header = '+--------+------------------+---------+------+--------------------------------+' #NEWLINE# print ( header ) #NEWLINE# print ( '|   id   |     timestamp    | process | mode | name                           |' ) #NEWLINE# print ( header ) #NEWLINE# for ( r_id , r_name , r_timestamp , r_mode , r_process ) in processes : #NEWLINE# #INDENT# f_id = '{0: 7d} ' . format ( r_id ) #NEWLINE# f_timestamp = '{0: 17d} ' . format ( r_timestamp ) #NEWLINE# f_proc = '{0: 8d} ' . format ( r_process ) #NEWLINE# f_mode = '{0: 5d} ' . format ( r_mode ) #NEWLINE# f_name = ' {0: <30s} ' . format ( r_name ) #NEWLINE# print ( '|' . join ( ( '' , f_id , f_timestamp , f_proc , f_mode , f_name , '' ) ) ) #NEWLINE# print ( header ) #NEWLINE# #UNINDENT# cur . close ( ) #NEWLINE# cur = conn . cursor ( ) #NEWLINE# connections = cur . execute ( '\n        SELECT DISTINCT inbound, family, protocol, address\n        FROM connections\n        ORDER BY inbound, family, timestamp;\n        ' ) #NEWLINE# header_shown = ( - 1 ) #NEWLINE# current_family = current_protocol = None #NEWLINE# for ( r_inbound , r_family , r_protocol , r_address ) in connections : #NEWLINE# #INDENT# if ( header_shown < r_inbound ) : #NEWLINE# #INDENT# if r_inbound : #NEWLINE# #INDENT# print ( '\nIncoming connections:' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( '\nRemote connections:' ) #NEWLINE# #UNINDENT# header_shown = r_inbound #NEWLINE# current_family = None #NEWLINE# #UNINDENT# if ( current_family != r_family ) : #NEWLINE# #INDENT# print ( ( '    %s' % r_family ) ) #NEWLINE# current_family = r_family #NEWLINE# current_protocol = None #NEWLINE# #UNINDENT# if ( current_protocol != r_protocol ) : #NEWLINE# #INDENT# print ( ( '      %s' % r_protocol ) ) #NEWLINE# current_protocol = r_protocol #NEWLINE# #UNINDENT# print ( ( '        %s' % r_address ) ) #NEWLINE# #UNINDENT# conn . close ( )