diff --git a/setup.py b/setup.py index 532e245..1a24318 100755 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ url='http://vdiscover.org/', author='G.Grieco', author_email='gg@cifasis-conicet.gov.ar', - scripts=['fextractor', 'vpredictor', 'tcreator', 'vdp'], + scripts=['fextractor', 'vpredictor', 'tcreator', 'vd'], install_requires=[ "python-ptrace", "scikit-learn" diff --git a/vd b/vd new file mode 100755 index 0000000..172532a --- /dev/null +++ b/vd @@ -0,0 +1,67 @@ +#!/usr/bin/python2 + +""" +This file is part of VDISCOVER. + +VDISCOVER is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +VDISCOVER is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with VDISCOVER. If not, see . + +Copyright 2014 by G.Grieco +""" + +import os +import argparse +import sys +import csv + +#from vdiscover.Detection import WriteTestcase +from vdiscover.Process import Process +from vdiscover.Printer import TypePrinter +from vdiscover.Cluster import Cluster + +if __name__ == "__main__": + + # Arguments + parser = argparse.ArgumentParser(description='') + parser.add_argument("seeds", help="", type=str, default=None) + parser.add_argument("vectorizer", help="", type=str, default=None) + parser.add_argument("cmd", help="", type=str, default=None) + + options = parser.parse_args() + seeds = options.seeds + cmd = options.cmd + vectorizer = options.vectorizer + #outdir = "outdir/"++ + program = cmd.split(" ")[0] + timeout = 5 + envs = dict() + + app = Process(program, envs, timeout, [], [], True) + prt = TypePrinter("/dev/null", program, 0) + traces = [] + + print "Extracting traces.." + for x,y,files in os.walk(seeds): + for f in files: + prepared_cmd = cmd.replace(program,"") + prepared_cmd = prepared_cmd.split("@@") + prepared_cmd = prepared_cmd[0].split(" ") + [x+"/".join(y)+"/"+f] + prepared_cmd[1].split(" ") + prepared_cmd = filter(lambda x: x<>'', prepared_cmd) + events = app.getData(prepared_cmd) + traces.append(prt.print_events(events)) + #print prepared_cmd + #print traces[-1] + + Cluster(vectorizer, None, traces, None, "cluster", "dynamic", None) + + diff --git a/vdiscover/Printer.py b/vdiscover/Printer.py index d2e9c13..c9ec73d 100644 --- a/vdiscover/Printer.py +++ b/vdiscover/Printer.py @@ -100,3 +100,4 @@ def print_events(self, events): self.csvwriter.writerow(row) self.outfile.flush() + return row diff --git a/vdiscover/Utils.py b/vdiscover/Utils.py index dbbce75..da2b427 100644 --- a/vdiscover/Utils.py +++ b/vdiscover/Utils.py @@ -77,7 +77,13 @@ def open_model(model_file): def read_traces(train_file, nsamples, cut=None, maxsize=50): - csvreader = load_csv(train_file) + if type(train_file) == str: + csvreader = load_csv(train_file) + elif type(train_file) == list: + csvreader = train_file + else: + assert(0) + train_features = [] train_programs = [] train_classes = [] @@ -121,7 +127,12 @@ def read_traces(train_file, nsamples, cut=None, maxsize=50): train_classes.append(cl) else: - train_size = file_len(train_file) + if type(train_file) == str: + train_size = file_len(train_file) + elif type(train_file) == list: + train_size = len(csvreader) + + #train_size = file_len(train_file) skip_until = random.randint(0,train_size - nsamples) for i,col in enumerate(csvreader):