|
|
|
@ -8,7 +8,7 @@ from sqlalchemy import exists, desc
|
|
|
|
|
from tempfile import TemporaryDirectory |
|
|
|
|
import logging |
|
|
|
|
|
|
|
|
|
from .mutation import generation, flip, seed_shell |
|
|
|
|
from .mutation import generation, mutate, seed_shell, growth |
|
|
|
|
from .orm import db_config, ScrapNode |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -48,18 +48,6 @@ def sins():
|
|
|
|
|
|
|
|
|
|
logger.info(now) |
|
|
|
|
|
|
|
|
|
seed_data = seed_shell |
|
|
|
|
|
|
|
|
|
if args.seed: |
|
|
|
|
seed = Path(args.seed) |
|
|
|
|
|
|
|
|
|
with seed.open('rb') as seed_file: |
|
|
|
|
seed_data = seed_file.read() |
|
|
|
|
|
|
|
|
|
seed = ScrapNode(child=seed_data) |
|
|
|
|
|
|
|
|
|
logger.debug(f'seed:\n{seed}') |
|
|
|
|
|
|
|
|
|
if args.output: |
|
|
|
|
db_path = Path(f'{args.output}/sins.sqlite') |
|
|
|
|
else: |
|
|
|
@ -68,38 +56,48 @@ def sins():
|
|
|
|
|
|
|
|
|
|
session = db_config(db_path) |
|
|
|
|
logger.info(f'db_path: {db_path}') |
|
|
|
|
recent = session.query(ScrapNode).order_by(desc('ctime')).first() |
|
|
|
|
|
|
|
|
|
if args.seed: |
|
|
|
|
seed_path = Path(args.seed) |
|
|
|
|
|
|
|
|
|
with seed_path.open('rb') as seed_file: |
|
|
|
|
seed_data = seed_file.read() |
|
|
|
|
|
|
|
|
|
seed = ScrapNode(child=seed_data) |
|
|
|
|
|
|
|
|
|
exists = session.query(ScrapNode).filter( |
|
|
|
|
ScrapNode.checksum == seed.checksum) |
|
|
|
|
|
|
|
|
|
if exists: |
|
|
|
|
seed = exists[0] |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
session.add(seed) |
|
|
|
|
session.commit() |
|
|
|
|
logger.debug(f'args.seed:\n{seed}') |
|
|
|
|
elif recent: |
|
|
|
|
seed = recent |
|
|
|
|
logger.debug(f'recent:\n{seed}') |
|
|
|
|
else: |
|
|
|
|
recent = session.query(ScrapNode).order_by(desc('ctime')).first() |
|
|
|
|
|
|
|
|
|
if recent: |
|
|
|
|
logger.debug(f'recent:\n{recent}') |
|
|
|
|
seed = recent |
|
|
|
|
seed = ScrapNode(child=seed_shell) |
|
|
|
|
session.add(seed) |
|
|
|
|
session.commit() |
|
|
|
|
logger.debug(f'seed_shell:\n{seed}') |
|
|
|
|
|
|
|
|
|
parent = seed |
|
|
|
|
|
|
|
|
|
queue = Queue() |
|
|
|
|
|
|
|
|
|
while True: |
|
|
|
|
lineage = 0 |
|
|
|
|
scrap = flip(parent.image) |
|
|
|
|
|
|
|
|
|
while lineage < args.lineage: |
|
|
|
|
scrap = mutate(parent.image) |
|
|
|
|
logger.debug(f'lineage: {lineage}') |
|
|
|
|
result = None |
|
|
|
|
|
|
|
|
|
proc = Process(target=generation, args=(queue, scrap)) |
|
|
|
|
proc.start() |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
result = queue.get(timeout=1) |
|
|
|
|
except Empty: |
|
|
|
@ -110,10 +108,11 @@ def sins():
|
|
|
|
|
lineage += 1 |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
scrap = growth(shellcode=scrap, length=result) |
|
|
|
|
|
|
|
|
|
parent = ScrapNode(child=scrap, parent_id=parent.id) |
|
|
|
|
parent.length = result |
|
|
|
|
session.add(parent) |
|
|
|
|
session.commit() |
|
|
|
|
|
|
|
|
|
logger.info(f'scrap:\n{parent}') |
|
|
|
|
lineage = 0 |
|
|
|
|
scrap = flip(parent.image) |
|
|
|
|