# Path: umap2/apps/emulate.py
# class Umap2EmulationApp(Umap2App):
# 
#     def run(self):
#         self.fuzzer = self.get_fuzzer()
#         self.phy = self.load_phy(self.options['--phy'])
#         self.dev = self.load_device(self.options['--class'], self.phy)
#         try:
#             self.dev.connect()
#             self.dev.run()
#         except KeyboardInterrupt:
#             self.logger.info('user terminated the run')
#         except:
#             self.logger.error('Got exception while connecting/running device')
#             self.logger.error(traceback.format_exc())
#         self.dev.disconnect()
# 
#     def get_fuzzer(self):
#         return None
# 
# Path: umap2/fuzz/helpers.py
# class StageLogger(object):
# 
#     def __init__(self, filename):
#         self.filename = filename
#         self.fd = None
# 
#     def start(self):
#         self.fd = open(self.filename, 'wb')
# 
#     def stop(self):
#         if self.fd:
#             self.fd.close()
# 
#     def log_stage(self, stage):
#         if self.fd:
#             self.fd.write(stage + '\n')
#             self.fd.flush()
# 
# def set_stage_logger(logger):
#     '''
#     Set a new stage logger
#     '''
#     global stage_logger
#     stage_logger = logger


import time
from umap2.apps.emulate import Umap2EmulationApp
from umap2.fuzz.helpers import StageLogger, set_stage_logger
#!/usr/bin/env python
'''
Prepare stages for USB fuzzing

Usage:
    umap2stages -P=PHY_INFO -C=DEVICE_CLASS -s=FILE [-q] [--vid=VID] [--pid=PID] [-v ...]

Options:
    -P --phy PHY_INFO       physical layer info, see list below
    -C --class DEVICE_CLASS class of the device or path to python file with device class
    -s --stage-file FILE    file to store list of stages in
    -q --quiet              quiet mode. only print warning/error messages
    -v --verbose            verbosity level
    --vid VID               override vendor ID
    --pid PID               override product ID

Physical layer:
    fd:<serial_port>        use facedancer connected to given serial port
    gadgetfs                use gadgetfs (requires mounting of gadgetfs beforehand)
'''


class Umap2MakeStagesApp(Umap2EmulationApp):

    def load_device(self, dev_name, phy):
        self.start_time = time.time()
        self.stage_file_name = self.options['--stage-file']

# Path: umap2/apps/emulate.py
# class Umap2EmulationApp(Umap2App):
# 
#     def run(self):
#         self.fuzzer = self.get_fuzzer()
#         self.phy = self.load_phy(self.options['--phy'])
#         self.dev = self.load_device(self.options['--class'], self.phy)
#         try:
#             self.dev.connect()
#             self.dev.run()
#         except KeyboardInterrupt:
#             self.logger.info('user terminated the run')
#         except:
#             self.logger.error('Got exception while connecting/running device')
#             self.logger.error(traceback.format_exc())
#         self.dev.disconnect()
# 
#     def get_fuzzer(self):
#         return None
# 
# Path: umap2/fuzz/helpers.py
# class StageLogger(object):
# 
#     def __init__(self, filename):
#         self.filename = filename
#         self.fd = None
# 
#     def start(self):
#         self.fd = open(self.filename, 'wb')
# 
#     def stop(self):
#         if self.fd:
#             self.fd.close()
# 
#     def log_stage(self, stage):
#         if self.fd:
#             self.fd.write(stage + '\n')
#             self.fd.flush()
# 
# def set_stage_logger(logger):
#     '''
#     Set a new stage logger
#     '''
#     global stage_logger
#     stage_logger = logger


# Path: umap2/apps/makestages.py
import time
from umap2.apps.emulate import Umap2EmulationApp
from umap2.fuzz.helpers import StageLogger, set_stage_logger

#!/usr/bin/env python
'''
Prepare stages for USB fuzzing

Usage:
    umap2stages -P=PHY_INFO -C=DEVICE_CLASS -s=FILE [-q] [--vid=VID] [--pid=PID] [-v ...]

Options:
    -P --phy PHY_INFO       physical layer info, see list below
    -C --class DEVICE_CLASS class of the device or path to python file with device class
    -s --stage-file FILE    file to store list of stages in
    -q --quiet              quiet mode. only print warning/error messages
    -v --verbose            verbosity level
    --vid VID               override vendor ID
    --pid PID               override product ID

Physical layer:
    fd:<serial_port>        use facedancer connected to given serial port
    gadgetfs                use gadgetfs (requires mounting of gadgetfs beforehand)
'''


class Umap2MakeStagesApp(Umap2EmulationApp):

    def load_device(self, dev_name, phy):
        self.start_time = time.time()
        self.stage_file_name = self.options['--stage-file']

        stage_logger = StageLogger(self.stage_file_name)