def main(): """Wrap the program logic inside a function.""" logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) print 'RecuperaBit', __version__ print __copyright__, '<%s>' % __email__ print 'Released under the', __license__ print '' parser = argparse.ArgumentParser( description='Reconstruct the directory structure of possibly damaged ' 'filesystems.') parser.add_argument('path', type=str, help='path to the disk image') parser.add_argument('-s', '--savefile', type=str, help='path of the scan save file') parser.add_argument('-w', '--overwrite', action='store_true', help='force overwrite of the save file') parser.add_argument('-o', '--outputdir', type=str, help='directory for restored contents' ' and output files') args = parser.parse_args() try: image = open(args.path, 'rb') except IOError: logging.error('Unable to open image file!') exit(1) read_results = False write_results = False # Set output directory if args.outputdir is None: logging.info('No output directory specified, defaulting to ' 'recuperabit_output') args.outputdir = 'recuperabit_output' # Try to reload information from the savefile if args.savefile is not None: if args.overwrite: logging.info('Results will be saved to %s', args.savefile) write_results = True else: logging.info('Checking if results already exist.') try: savefile = open(args.savefile, 'rb') logging.info('Results will be read from %s', args.savefile) read_results = True except IOError: logging.info('Unable to open save file.') logging.info('Results will be saved to %s', args.savefile) write_results = True if read_results: logging.info('The save file exists. Trying to read it...') try: indexes = pickle.load(savefile) except IndexError: logging.error('Malformed save file!') exit(1) else: indexes = itertools.count() # Ask for confirmation before beginning the process try: confirm = raw_input('Type [Enter] to start the analysis or ' '"exit" / "quit" / "q" to quit: ') except EOFError: print '' exit(0) if confirm in ('exit', 'quit', 'q'): exit(0) # Create the output directory if not logic.makedirs(args.outputdir): logging.error('Cannot create output directory!') exit(1) scanners = [pl(image) for pl in plugins] interesting = utils.feed_all(image, scanners, indexes) logging.info('First scan completed') if write_results: logging.info('Saving results to %s', args.savefile) savefile = open(args.savefile, 'wb') pickle.dump(interesting, savefile) # Ask for partitions parts = {} for scanner in scanners: parts.update(scanner.get_partitions()) shorthands = list(enumerate(parts)) logging.info('%i partitions found.', len(parts)) while True: print '\nWrite command ("help" for details):' print '>', try: command = raw_input().strip().split(' ') except EOFError: print '' exit(0) cmd = command[0] arguments = command[1:] interpret(cmd, arguments, parts, shorthands, args.outputdir)
def main(): """Wrap the program logic inside a function.""" logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) print 'RecuperaBit', __version__ print __copyright__, '<%s>' % __email__ print 'Released under the', __license__ print '' parser = argparse.ArgumentParser( description='Reconstruct the directory structure of possibly damaged ' 'filesystems.' ) parser.add_argument('path', type=str, help='path to the disk image') parser.add_argument( '-s', '--savefile', type=str, help='path of the scan save file' ) parser.add_argument( '-w', '--overwrite', action='store_true', help='force overwrite of the save file' ) parser.add_argument( '-o', '--outputdir', type=str, help='directory for restored contents' ' and output files' ) args = parser.parse_args() try: image = open(args.path, 'rb') except IOError: logging.error('Unable to open image file!') exit(1) read_results = False write_results = False # Set output directory if args.outputdir is None: logging.info('No output directory specified, defaulting to ' 'recuperabit_output') args.outputdir = 'recuperabit_output' # Try to reload information from the savefile if args.savefile is not None: if args.overwrite: logging.info('Results will be saved to %s', args.savefile) write_results = True else: logging.info('Checking if results already exist.') try: savefile = open(args.savefile, 'rb') logging.info('Results will be read from %s', args.savefile) read_results = True except IOError: logging.info('Unable to open save file.') logging.info('Results will be saved to %s', args.savefile) write_results = True if read_results: logging.info('The save file exists. Trying to read it...') try: indexes = pickle.load(savefile) except IndexError: logging.error('Malformed save file!') exit(1) else: indexes = itertools.count() # Ask for confirmation before beginning the process try: confirm = raw_input('Type [Enter] to start the analysis or ' '"exit" / "quit" / "q" to quit: ') except EOFError: print '' exit(0) if confirm in ('exit', 'quit', 'q'): exit(0) scanners = [pl(image) for pl in plugins] interesting = utils.feed_all(image, scanners, indexes) logging.info('First scan completed') if write_results: logging.info('Saving results to %s', args.savefile) savefile = open(args.savefile, 'wb') pickle.dump(interesting, savefile) # Ask for partitions parts = {} for scanner in scanners: parts.update(scanner.get_partitions()) shorthands = list(enumerate(parts)) logging.info('%i partitions found.', len(parts)) while True: print '\nWrite command ("help" for details):' print '>', try: command = raw_input().strip().split(' ') except EOFError: print '' exit(0) cmd = command[0] arguments = command[1:] interpret(cmd, arguments, parts, shorthands, args.outputdir)