#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 29 03:33:51 2019

@author: admin
"""

import numpy as np
import os
import cv2
import pandas as pd

#reshape size of malware images uniformly
size = 32
feature=np.zeros((9111,1024)) #(8966,1024)
print(feature)
labels = ['NONE']*(9111)
i=-1
count=0


directory1 = 'securityshield_images'
your_path = '/Volumes/ESD-USB/Project/images/'+ directory1+'/' #static path is given . Update as per your system
filelist = os.listdir(your_path)


try:
    
    for file in filelist:
        img = cv2.imread(os.path.join(your_path,file),0) 
        #print(img)
        compressed = cv2.resize(img,(size,size))
        i=i+1
        flattened = compressed.flatten()
        feature[i]=flattened
        labels[i]='securityshield'
except:
    count=count+1
    print("file not read"+file)
    #labels.append('NaN')

directory1 = 'winwebsec_images'

your_path = '/Volumes/ESD-USB/Project/images/'+ directory1+'/'
filelist = os.listdir(your_path)

try:
    
    for file in filelist:
        img = cv2.imread(os.path.join(your_path,file),0) 
        #print(img)
        compressed = cv2.resize(img,(size,size))
        flattened = compressed.flatten()
        i=i+1
        feature[i]=flattened
        labels[i]='winwebsec'
except:
    count=count+1
    print("file not read"+file)   
    #labels.append('NaN')

directory1 = 'zbot_images'

your_path = '/Volumes/ESD-USB/Project/images/'+ directory1+'/'
filelist = os.listdir(your_path)

try:
    
    for file in filelist:
        img = cv2.imread(os.path.join(your_path,file),0) 
        #print(img)
        compressed = cv2.resize(img,(size,size))
        flattened = compressed.flatten()
        i=i+1
        feature[i]=flattened
        labels[i]='zbot'
except:
    count=count+1
    print("file not read"+file)   
    #labels.append('NaN')

directory1 = 'zeroaccess_images'

your_path = '/Volumes/ESD-USB/Project/images/'+ directory1+'/'
filelist = os.listdir(your_path)

try:
    
    for file in filelist:
        img = cv2.imread(os.path.join(your_path,file),0) 
        #print(img)
        compressed = cv2.resize(img,(size,size))
        flattened = compressed.flatten()
        i=i+1
        feature[i]=flattened
        labels[i]='zeroaccess'
except:
    count=count+1
    print("file not read"+file)
    #labels.append('NaN')
feature=feature[:9110] #[:9110]
labels=labels[:9110] #[:9110]

#making csv of flattened array and label
a=['']*1024
for i in range(1024):
    a[i]='features'+str(i)
feature=pd.DataFrame(feature,columns=a)
feature.to_csv('/Users/admin/Desktop/feature.csv',sep=',')
labels=pd.DataFrame({'label':labels})
labels.to_csv('/Users/admin/Desktop/labels.csv',sep=',')
#data = pd.DataFrame({'feature':feature,'label':labesls})
#data.to_csv('malware_data_final.csv',sep=',')



    
    
    
    
    
    
    