logfile argument, waf update
parent
5f1a85b763
commit
a76854e457
73
run.py
73
run.py
|
@ -10,7 +10,7 @@ class Sins():
|
|||
logger = logging.getLogger()
|
||||
|
||||
def __init__(self, parent, seed=None, run_dir=None):
|
||||
self.logger.info('execute\n{}'.format((
|
||||
self.logger.info('execute\n {}'.format((
|
||||
(parent, seed, run_dir))
|
||||
))
|
||||
|
||||
|
@ -20,14 +20,18 @@ class Sins():
|
|||
|
||||
self.seed = os.path.abspath(seed)
|
||||
|
||||
if os.path.isdir(run_dir):
|
||||
self.run_dir = os.path.abspath(run_dir)
|
||||
shutil.copy2(args.seed, args.dir)
|
||||
else:
|
||||
self.run_dir = os.path.dirname(self.seed)
|
||||
self.run_dir = os.path.abspath(run_dir)
|
||||
|
||||
if not os.path.isdir(self.run_dir):
|
||||
try:
|
||||
os.mkdir(self.run_dir)
|
||||
except:
|
||||
self.run_dir = os.path.dirname(self.seed)
|
||||
|
||||
shutil.copy2(self.seed, self.run_dir)
|
||||
|
||||
parsed = self.parent, self.seed, self.run_dir
|
||||
self.logger.info('parsed\n{}'.format((parsed)))
|
||||
self.logger.info('parsed\n {}'.format((parsed)))
|
||||
|
||||
while True:
|
||||
self.execute(self.parent, self.seed, self.run_dir)
|
||||
|
@ -50,7 +54,7 @@ class Sins():
|
|||
return None
|
||||
|
||||
def execute(self, parent, scrap, cwd):
|
||||
self.logger.info('execute\n{}'.format(((parent, scrap, cwd))))
|
||||
self.logger.info('execute\n {}'.format(((parent, scrap, cwd))))
|
||||
subprocess.run([parent, scrap], cwd=cwd)
|
||||
|
||||
|
||||
|
@ -82,26 +86,45 @@ if __name__ == '__main__':
|
|||
import argparse
|
||||
import sys
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
# handler = logging.FileHandler(filename='sins.log')
|
||||
handler = logging.StreamHandler()
|
||||
formatter = logging.Formatter(
|
||||
'#%(asctime)s %(name)s %(levelname)s\n##%(message)s\n'
|
||||
parser = argparse.ArgumentParser(
|
||||
description='position independent code (PIC) mutation experiment.'
|
||||
)
|
||||
handler.setFormatter(formatter)
|
||||
logger.addHandler(handler)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-seed', default='build/scrap.asm.2.o')
|
||||
parser.add_argument('-parent', default='build/sins')
|
||||
parser.add_argument('-dir', default='sandbox')
|
||||
parser.add_argument('-dumps', action='store_true')
|
||||
parser.add_argument('-build', action='store_true')
|
||||
parser.add_argument('-provision', action='store_true')
|
||||
parser.add_argument('--verbose', '-v', action='count')
|
||||
parser.add_argument('-build', action='store_true',
|
||||
help='build parent and seed PIC image, exit.')
|
||||
parser.add_argument('-provision', action='store_true',
|
||||
help='provision ubuntu for run, exit.')
|
||||
parser.add_argument('-logfile', help='log to file.')
|
||||
parser.add_argument('-seed', default='build/scrap.asm.2.o',
|
||||
help='path to PIC image.')
|
||||
parser.add_argument('-parent', default='build/sins',
|
||||
help='path to parent process.')
|
||||
parser.add_argument('-dir', default='sandbox',
|
||||
help='path to execution directory.')
|
||||
parser.add_argument('-dumps', action='store_true',
|
||||
help='dump hex values of scraps in directory, exit.')
|
||||
args = parser.parse_args()
|
||||
|
||||
logger = logging.getLogger()
|
||||
formatter = logging.Formatter(
|
||||
'#%(asctime)s %(levelname)s\n##%(message)s\n'
|
||||
)
|
||||
|
||||
if args.verbose:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
else:
|
||||
print('Verbose not set, running in silence.')
|
||||
|
||||
if args.logfile:
|
||||
file_handler = logging.FileHandler(args.logfile, 'a')
|
||||
file_handler.setFormatter(formatter)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.addHandler(file_handler)
|
||||
else:
|
||||
stream_handler = logging.StreamHandler()
|
||||
stream_handler.setFormatter(formatter)
|
||||
logger.addHandler(stream_handler)
|
||||
|
||||
if args.provision:
|
||||
provision = ['sudo', 'sh', 'provision-ubuntu.sh']
|
||||
prov_proc = subprocess.run(provision)
|
||||
|
|
Loading…
Reference in New Issue