# Path: iolibrary.py
# def kill_signal_handler(signal, frame):
#     '''
#     Signal handler for killing the execution.
#     '''
#     print('\nExiting the program per your command.')
#     system('rm -f out.out request.txt iolibrary.pyc hillclimbing.pyc constants.pyc connect.pyc parse.pyc sniff.pyc')
#     if not path.exists('history'):
#         mkdir('history')
#     if path.exists('basic_breach.log'):
#         system('mv basic_breach.log history/')
#     if path.exists('full_breach.log'):
#         system('mv full_breach.log history/')
#     if path.exists('debug.log'):
#         system('mv debug.log history/')
#     if path.exists('attack.log'):
#         system('mv attack.log history/')
#     if path.exists('win_count.log'):
#         system('mv win_count.log history/')
#     if path.exists('sniff.log'):
#         system('mv sniff.log history/')
#     if path.exists('sniff_full.log'):
#         system('mv sniff_full.log history/')
#     sys.exit(0)
# 
# def get_arguments_dict(args_list):
#     '''
#     Parse command line arguments that were given to the program that calls this method.
#     '''
#     parser = argparse.ArgumentParser(description='Parser of breach.py output')
#     parser.add_argument('caller_name', metavar='caller_name', help='The program that called the argument parser.')
#     parser.add_argument('--execute_breach', action='store_true', help='Initiate breach attack via breach.py')
#     args = parser.parse_args(args_list)
# 
#     args_dict = {}
#     args_dict['execute_breach'] = True if args.execute_breach else False
#     return args_dict
# 
# def setup_logger(logger_name, log_file, args_dict, level=logging.DEBUG):
#     '''
#     Logger factory.
#     '''
#     l = logging.getLogger(logger_name)
#     l.setLevel(level)
#     formatter = logging.Formatter('%(asctime)s : %(message)s')
#     fileHandler = logging.FileHandler(log_file)
#     fileHandler.setFormatter(formatter)
#     l.addHandler(fileHandler)
#     if args_dict['log_to_screen']:
#         streamHandler = logging.StreamHandler()
#         streamHandler.setFormatter(formatter)
#         l.addHandler(streamHandler)


import socket
import select
import logging
import binascii
import sys
import signal
import constants
from iolibrary import kill_signal_handler, get_arguments_dict, setup_logger
                            self.full_logger.debug('Endpoint connection error')
                            self.full_logger.debug(exc)
                            self.stop(-3)
                            break

                        if len(data) == 0:
                                self.full_logger.info('Endpoint connection closed')
                                self.stop(5)
                                break
                        else:
                                self.basic_logger.debug('Endpoint Packet Length: %d' % len(data))
                                output, past_bytes_endpoint, past_bytes_user, chunked_endpoint_header, chunked_user_header, _ = self.parse(data,
                                                                                                                                           past_bytes_endpoint,
                                                                                                                                           past_bytes_user,
                                                                                                                                           chunked_endpoint_header,
                                                                                                                                           chunked_user_header,
                                                                                                                                           True)
                                self.full_logger.debug(output)
                                try:
                                    self.user_connection.sendall(data)
                                except Exception as exc:
                                    self.full_logger.debug('Endpoint data forwarding error')
                                    self.full_logger.debug(exc)
                                    self.stop(-2)
                                    break
        except:
            self.stop(-1)
        return

if __name__ == '__main__':

# Path: iolibrary.py
# def kill_signal_handler(signal, frame):
#     '''
#     Signal handler for killing the execution.
#     '''
#     print('\nExiting the program per your command.')
#     system('rm -f out.out request.txt iolibrary.pyc hillclimbing.pyc constants.pyc connect.pyc parse.pyc sniff.pyc')
#     if not path.exists('history'):
#         mkdir('history')
#     if path.exists('basic_breach.log'):
#         system('mv basic_breach.log history/')
#     if path.exists('full_breach.log'):
#         system('mv full_breach.log history/')
#     if path.exists('debug.log'):
#         system('mv debug.log history/')
#     if path.exists('attack.log'):
#         system('mv attack.log history/')
#     if path.exists('win_count.log'):
#         system('mv win_count.log history/')
#     if path.exists('sniff.log'):
#         system('mv sniff.log history/')
#     if path.exists('sniff_full.log'):
#         system('mv sniff_full.log history/')
#     sys.exit(0)
# 
# def get_arguments_dict(args_list):
#     '''
#     Parse command line arguments that were given to the program that calls this method.
#     '''
#     parser = argparse.ArgumentParser(description='Parser of breach.py output')
#     parser.add_argument('caller_name', metavar='caller_name', help='The program that called the argument parser.')
#     parser.add_argument('--execute_breach', action='store_true', help='Initiate breach attack via breach.py')
#     args = parser.parse_args(args_list)
# 
#     args_dict = {}
#     args_dict['execute_breach'] = True if args.execute_breach else False
#     return args_dict
# 
# def setup_logger(logger_name, log_file, args_dict, level=logging.DEBUG):
#     '''
#     Logger factory.
#     '''
#     l = logging.getLogger(logger_name)
#     l.setLevel(level)
#     formatter = logging.Formatter('%(asctime)s : %(message)s')
#     fileHandler = logging.FileHandler(log_file)
#     fileHandler.setFormatter(formatter)
#     l.addHandler(fileHandler)
#     if args_dict['log_to_screen']:
#         streamHandler = logging.StreamHandler()
#         streamHandler.setFormatter(formatter)
#         l.addHandler(streamHandler)


# Path: connect.py
import socket
import select
import logging
import binascii
import sys
import signal
import constants
from iolibrary import kill_signal_handler, get_arguments_dict, setup_logger

                            self.full_logger.debug('Endpoint connection error')
                            self.full_logger.debug(exc)
                            self.stop(-3)
                            break

                        if len(data) == 0:
                                self.full_logger.info('Endpoint connection closed')
                                self.stop(5)
                                break
                        else:
                                self.basic_logger.debug('Endpoint Packet Length: %d' % len(data))
                                output, past_bytes_endpoint, past_bytes_user, chunked_endpoint_header, chunked_user_header, _ = self.parse(data,
                                                                                                                                           past_bytes_endpoint,
                                                                                                                                           past_bytes_user,
                                                                                                                                           chunked_endpoint_header,
                                                                                                                                           chunked_user_header,
                                                                                                                                           True)
                                self.full_logger.debug(output)
                                try:
                                    self.user_connection.sendall(data)
                                except Exception as exc:
                                    self.full_logger.debug('Endpoint data forwarding error')
                                    self.full_logger.debug(exc)
                                    self.stop(-2)
                                    break
        except:
            self.stop(-1)
        return

if __name__ == '__main__':

    args_dict = get_arguments_dict(sys.argv)