Skip to content

Commit 9f4b1c1

Browse files
author
gaa-cifasis
committed
improvements
1 parent 5c3fb35 commit 9f4b1c1

File tree

5 files changed

+64
-38
lines changed

5 files changed

+64
-38
lines changed

fextractor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ if __name__ == "__main__":
155155
print "Execution of",program,"failed!"
156156
exit(-1)
157157

158-
prt.print_events(original_events)
158+
prt.print_events(program,original_events)
159159

160160
for (i, (d, mutated)) in enumerate(mutated_input_generator):
161161

162162
if i >= max_mut:
163163
break
164164

165165
events = app.getData(prepare_inputs(mutated))
166-
prt.print_events(events)
166+
prt.print_events(program,events)

vd

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,77 @@ Copyright 2014 by G.Grieco
2020
"""
2121

2222
import os
23+
import os.path
2324
import argparse
2425
import sys
2526
import csv
27+
import random
28+
29+
csv.field_size_limit(sys.maxsize)
30+
sys.setrecursionlimit(1024*1024*1024)
2631

2732
#from vdiscover.Detection import WriteTestcase
2833
from vdiscover.Process import Process
2934
from vdiscover.Printer import TypePrinter
30-
from vdiscover.Cluster import Cluster
31-
35+
from vdiscover.Cluster import PlotDeepRepr
36+
from vdiscover.Utils import update_progress
3237
if __name__ == "__main__":
3338

3439
# Arguments
3540
parser = argparse.ArgumentParser(description='')
36-
parser.add_argument("seeds", help="", type=str, default=None)
37-
parser.add_argument("vectorizer", help="", type=str, default=None)
41+
parser.add_argument("-i", help="", type=str, default=None, required=True, dest="seeds")
42+
parser.add_argument("-o", help="", type=str, default=None, required=True, dest="out")
43+
#parser.add_argument("-v", help="", type=str, default=None, required=True, dest="vectorizer")
44+
#parser.add_argument("-m", help="", type=str, default="afl", dest="fuzzer")
3845
parser.add_argument("cmd", help="", type=str, default=None)
3946

4047
options = parser.parse_args()
4148
seeds = options.seeds
49+
outfile = options.out
50+
fuzzer = options.fuzzer
4251
cmd = options.cmd
4352
vectorizer = options.vectorizer
44-
#outdir = "outdir/"++
4553
program = cmd.split(" ")[0]
54+
programf = program.replace("/","__")
4655
timeout = 5
4756
envs = dict()
57+
traces_path = outfile#outdir+"/traces.raw"
58+
59+
if os.path.exists(traces_path):
60+
traces = traces_path
61+
else:
4862

49-
app = Process(program, envs, timeout, [], [], True)
50-
prt = TypePrinter("/dev/null", program, 0)
51-
traces = []
63+
app = Process(program, envs, timeout, [], [], True)
64+
prt = TypePrinter(traces_path, program, 0)
65+
traces = []
66+
all_files = []
5267

53-
print "Extracting traces.."
54-
for x,y,files in os.walk(seeds):
55-
for f in files:
68+
print "Extracting traces.."
69+
for x,y,files in os.walk(seeds):
70+
nfiles = len(files)
71+
#print "Processing directory ","./"++("/".join(y)), "with", nfiles, "seeds"
72+
for f in files:
73+
all_files.append(x+"/".join(y)+"/"+f)
74+
75+
random.shuffle(all_files)
76+
nfiles = len(all_files)
77+
78+
for progress,testcase in enumerate(all_files):
79+
#print testcase
80+
progress = round(float(progress)/nfiles, 2)
81+
update_progress(progress)
5682
prepared_cmd = cmd.replace(program,"")
5783
prepared_cmd = prepared_cmd.split("@@")
58-
prepared_cmd = prepared_cmd[0].split(" ") + [x+"/".join(y)+"/"+f] + prepared_cmd[1].split(" ")
84+
prepared_cmd = prepared_cmd[0].split(" ") + [testcase] + prepared_cmd[1].split(" ")
5985
prepared_cmd = filter(lambda x: x<>'', prepared_cmd)
6086
events = app.getData(prepared_cmd)
61-
traces.append(prt.print_events(events))
87+
traces.append(prt.print_events(testcase,events))
6288
#print prepared_cmd
6389
#print traces[-1]
6490

65-
Cluster(vectorizer, None, traces, None, "cluster", "dynamic", None)
91+
#clustered_traces = PlotDeepRepr(vectorizer, traces, None, "dynamic", None, outdir)
92+
#clusters = dict()
93+
#for label, cluster in clustered_traces:
94+
# clusters[cluster] = clusters.get(cluster, []) + [label]
6695

67-
96+
#print clusters

vdiscover/Cluster.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
import numpy as np
2727
import matplotlib.pyplot as plt
2828
import matplotlib as mpl
29+
import pylab as plb
2930

3031
from Utils import *
3132
from Pipeline import *
3233

33-
def PlotDeepRepr(model_file, train_file, valid_file, ftype, nsamples):
34+
def PlotDeepRepr(model_file, train_file, valid_file, ftype, nsamples, outdir):
3435

35-
f = gzip.open(model_file+".pre")
36+
f = open(model_file+".pre")
3637
preprocessor = pickle.load(f)
3738

3839
import h5py
@@ -43,20 +44,14 @@ def PlotDeepRepr(model_file, train_file, valid_file, ftype, nsamples):
4344
g = f['layer_{}'.format(k)]
4445
layers.append([g['param_{}'.format(p)] for p in range(g.attrs['nb_params'])])
4546

46-
#assert(0)
47-
48-
#preprocessor = old_model.mypreprocessor
49-
50-
#print preprocessor.tokenizer
51-
#print preprocessor.tokenizer.word_counts
5247
max_features = len(preprocessor.tokenizer.word_counts)
5348

5449
batch_size = 100
5550
window_size = 300
5651
maxlen = window_size
5752

5853
embedding_dims = 20
59-
nb_filters = 250
54+
nb_filters = 50
6055
filter_length = 3
6156
hidden_dims = 250
6257

@@ -136,21 +131,23 @@ def PlotDeepRepr(model_file, train_file, valid_file, ftype, nsamples):
136131
x = gauss(0,0.1) + x
137132
y = gauss(0,0.1) + y
138133
plt.scatter(x, y, c = colors[cluster_label % ncolors])
139-
#plt.text(x-0.05, y+0.01, label.split("-")[-1].split(".")[0])
134+
plt.text(x-0.05, y+0.01, label.split("/")[-1])
140135

141136
for i,[x,y] in enumerate(cluster_centers):
142137
plt.plot(x, y, 'o', markerfacecolor=colors[i % ncolors],
143138
markeredgecolor='k', markersize=7)
144139

145140
plt.title('Estimated number of clusters: %d' % n_clusters)
146141

142+
plb.savefig(outdir+"/plot.png")
147143
plt.show()
144+
145+
return zip(labels, cluster_labels)
146+
#csvwriter = open_csv(train_file+".clusters")
147+
#for (label, cluster_label) in zip(labels, cluster_labels):
148+
# csvwriter.writerow([label, cluster_label])
148149

149-
csvwriter = open_csv(train_file+".clusters")
150-
for (label, cluster_label) in zip(labels, cluster_labels):
151-
csvwriter.writerow([label, cluster_label])
152-
153-
print "Clusters dumped!"
150+
#print "Clusters dumped!"
154151

155152

156153
def TrainDeepRepr(model_file, train_file, valid_file, ftype, nsamples):
@@ -304,7 +301,7 @@ def ClusterScikit(model_file, train_file, valid_file, ftype, nsamples):
304301
plt.show()
305302
"""
306303

307-
def Cluster(model_file, out_file, train_file, valid_file, ttype, ftype, nsamples):
304+
def Cluster(model_file, out_file, train_file, valid_file, ttype, ftype, nsamples, outfile):
308305

309306
if ttype == "cluster":
310307

@@ -319,4 +316,4 @@ def Cluster(model_file, out_file, train_file, valid_file, ttype, ftype, nsamples
319316
if model_file is None:
320317
TrainDeepRepr(out_file, train_file, valid_file, ftype, nsamples)
321318
else:
322-
PlotDeepRepr(model_file, train_file, valid_file, ftype, nsamples)
319+
PlotDeepRepr(model_file, train_file, valid_file, ftype, nsamples, outfile)

vdiscover/Printer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def preprocess(self, event):
7272

7373
return r
7474

75-
def print_events(self, events):
75+
def print_events(self, label, events):
7676

7777
r = list()
7878

@@ -93,7 +93,7 @@ def print_events(self, events):
9393
for x,y in events:
9494
trace = trace+x+"="+y+" "
9595

96-
row = [self.pname,trace]
96+
row = [self.pname+":"+label,trace]
9797

9898
if self.mclass is not None:
9999
row.append(self.mclass)

vdiscover/data/prototypes.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ string bindtextdomain(string, string);
159159
string textdomain(string);
160160

161161
; libio.h
162-
char _IO_getc(file);
163-
int _IO_putc(char,file);
162+
;char _IO_getc(file);
163+
;int _IO_putc(char,file);
164164

165165
; locale.h
166166
string setlocale(int, string);

0 commit comments

Comments
 (0)