diff --git a/generation.c b/generation.c index 5326cea..4a8c0c9 100644 --- a/generation.c +++ b/generation.c @@ -4,6 +4,7 @@ #include #include #include +#include int reproduce(unsigned char *pic_address, int pic_size) { @@ -14,8 +15,6 @@ int reproduce(unsigned char *pic_address, int pic_size) printf("%02X", pic_address[iter]); } - printf("\n"); - return_value = 1; CLONE_CLEANUP: if (NULL != pic_address) @@ -113,13 +112,18 @@ int main(int argc, const char **argv) char *hex_string = argv[1]; int rand_offset = atoi(argv[2]); char rand_flip = atoi(argv[3]); - + pid_t process_id; int return_value = 0; - return_value = generation(hex_string, rand_offset, rand_flip); - if (!return_value) + process_id = fork(); + + if(0 == process_id) { - exit(1); + return_value = generation(hex_string, rand_offset, rand_flip); + if (return_value) + { + exit(1); + } } return 0; diff --git a/run.py b/run.py index 4a260cf..34ff696 100644 --- a/run.py +++ b/run.py @@ -4,13 +4,15 @@ import logging import os import shutil import subprocess +import binascii +import random class Sins(): logger = logging.getLogger() def __init__(self, parent, seed=None, run_dir=None): - self.logger.info('execute\n {}'.format(( + self.logger.info('run: {}'.format(( (parent, seed, run_dir)) )) @@ -34,17 +36,26 @@ class Sins(): self.logger.info('parsed\n {}'.format((parsed))) paths = (self.seed) - children = 0 while True: for path in paths: scrap_path = os.path.join(self.run_dir, path) if os.path.isfile(scrap_path): - children += self.execute( + with open(scrap_path, 'rb') as scrap_file: + scrap_bin = scrap_file.read() + + scrap_hex = binascii.b2a_hex(scrap_bin).upper() + + child = self.generation( self.parent, - scrap_path, + scrap_hex, + str(random.randint(0, len(scrap_hex))), + str(random.randint(0, 255)), self.run_dir ) - self.logger.info('"children": "{}",'.format(children)) + + if child: + raise Exception(child) + paths = sorted(os.listdir(self.run_dir)) def scrap_recent(self, run_dir): @@ -55,11 +66,18 @@ class Sins(): return None - def execute(self, parent, scrap, cwd): - self.logger.debug('execute\n {}'.format(((parent, scrap, cwd)))) - proc = subprocess.run([parent, scrap], cwd=cwd, stdout=subprocess.PIPE) + def generation(self, parent, scrap, offset, flip, cwd): + self.logger.debug( + 'generation: {}'.format((parent, scrap, offset, flip, cwd)) + ) + + proc = subprocess.run( + [parent, scrap, offset, flip], + cwd=cwd, + stdout=subprocess.PIPE + ) children = proc.stdout - return int(children) + return children def hex_dumps(scrap_dir): @@ -97,9 +115,9 @@ if __name__ == '__main__': 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', + parser.add_argument('-seed', default='build/seed.asm.2.o', help='path to PIC image.') - parser.add_argument('-parent', default='build/sins', + parser.add_argument('-parent', default='build/generation', help='path to parent process.') parser.add_argument('-dir', default='sandbox', help='path to execution directory.')