Skip to content

Commit

Permalink
added vd + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gaa-cifasis committed Oct 1, 2015
1 parent 2261756 commit 974b388
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
url='http://vdiscover.org/',
author='G.Grieco',
author_email='[email protected]',
scripts=['fextractor', 'vpredictor', 'tcreator', 'vdp'],
scripts=['fextractor', 'vpredictor', 'tcreator', 'vd'],
install_requires=[
"python-ptrace",
"scikit-learn"
Expand Down
67 changes: 67 additions & 0 deletions vd
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
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)


1 change: 1 addition & 0 deletions vdiscover/Printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ def print_events(self, events):

self.csvwriter.writerow(row)
self.outfile.flush()
return row
15 changes: 13 additions & 2 deletions vdiscover/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 974b388

Please sign in to comment.