Skip to content

Commit f19a65c

Browse files
LyleMiDongdongshe
authored andcommitted
update: make it python2/3 compatible (#14)
* update: make it python2/3 compatible * update: make it python2/3 compatible
1 parent af6e0d9 commit f19a65c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

nn.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def process_data():
5656

5757
# get MAX_FILE_SIZE
5858
cwd = os.getcwd()
59-
max_file_name = call(['ls', '-S', cwd + '/seeds/']).split('\n')[0].rstrip('\n')
59+
max_file_name = call(['ls', '-S', cwd + '/seeds/']).decode('utf8').split('\n')[0].rstrip('\n')
6060
MAX_FILE_SIZE = os.path.getsize(cwd + '/seeds/' + max_file_name)
6161

6262
# create directories to save label, spliced seeds, variant length seeds, crashes and mutated seeds.
@@ -84,7 +84,7 @@ def process_data():
8484
except subprocess.CalledProcessError:
8585
print("find a crash")
8686
for line in out.splitlines():
87-
edge = line.split(':')[0]
87+
edge = line.split(b':')[0]
8888
tmp_cnt.append(edge)
8989
tmp_list.append(edge)
9090
raw_bitmap[f] = tmp_list
@@ -115,11 +115,11 @@ def generate_training_data(lb, ub):
115115
seed = np.zeros((ub - lb, MAX_FILE_SIZE))
116116
bitmap = np.zeros((ub - lb, MAX_BITMAP_SIZE))
117117
for i in range(lb, ub):
118-
tmp = open(seed_list[i], 'r').read()
118+
tmp = open(seed_list[i], 'rb').read()
119119
ln = len(tmp)
120120
if ln < MAX_FILE_SIZE:
121-
tmp = tmp + (MAX_FILE_SIZE - ln) * '\0'
122-
seed[i - lb] = [ord(j) for j in list(tmp)]
121+
tmp = tmp + (MAX_FILE_SIZE - ln) * b'\x00'
122+
seed[i - lb] = [j for j in bytearray(tmp)]
123123

124124
for i in range(lb, ub):
125125
file_name = "./bitmaps/" + seed_list[i].split('/')[-1] + ".npy"
@@ -181,23 +181,23 @@ def train_generate(batch_size):
181181

182182
def vectorize_file(fl):
183183
seed = np.zeros((1, MAX_FILE_SIZE))
184-
tmp = open(fl, 'r').read()
184+
tmp = open(fl, 'rb').read()
185185
ln = len(tmp)
186186
if ln < MAX_FILE_SIZE:
187-
tmp = tmp + (MAX_FILE_SIZE - ln) * '\0'
188-
seed[0] = [ord(j) for j in list(tmp)]
187+
tmp = tmp + (MAX_FILE_SIZE - ln) * b'\x00'
188+
seed[0] = [j for j in bytearray(tmp)]
189189
seed = seed.astype('float32') / 255
190190
return seed
191191

192192
# splice two seeds to a new seed
193193

194194

195195
def splice_seed(fl1, fl2, idxx):
196-
tmp1 = open(fl1, 'r').read()
196+
tmp1 = open(fl1, 'rb').read()
197197
ret = 1
198198
randd = fl2
199199
while(ret == 1):
200-
tmp2 = open(randd, 'r').read()
200+
tmp2 = open(randd, 'rb').read()
201201
if len(tmp1) >= len(tmp2):
202202
lenn = len(tmp2)
203203
head = tmp2
@@ -221,8 +221,8 @@ def splice_seed(fl1, fl2, idxx):
221221
head = list(head)
222222
tail = list(tail)
223223
tail[:splice_at] = head[:splice_at]
224-
with open('./splice_seeds/tmp_' + str(idxx), 'w') as f:
225-
f.write("".join(tail))
224+
with open('./splice_seeds/tmp_' + str(idxx), 'wb') as f:
225+
f.write(bytearray(tail))
226226
ret = 0
227227
print((f_diff, l_diff))
228228
randd = random.choice(seed_list)
@@ -404,14 +404,14 @@ def setup_server():
404404
conn, addr = sock.accept()
405405
print('connected by neuzz execution moduel' + str(addr))
406406
gen_grad('train')
407-
conn.sendall("start")
407+
conn.sendall(b"start")
408408
while True:
409409
data = conn.recv(1024)
410410
if not data:
411411
break
412412
else:
413413
gen_grad(data)
414-
conn.sendall("start")
414+
conn.sendall(b"start")
415415
conn.close()
416416

417417

0 commit comments

Comments
 (0)