from __future__ import print_function
import MySQLdb
import glob
import os

MAX_CNT = 400

mat_mal=[[0 for i in range(MAX_CNT)] for i in range(MAX_CNT)]
mat_prob= [[0 for i in range(MAX_CNT)] for i in range(MAX_CNT)]
syscall_count = [0 for i in range(MAX_CNT)]

def printmat(mapped_so_far):
        for i in range(mapped_so_far):
            for j in range(mapped_so_far):
                if(syscall_count[i]!=0 and mat_mal[i][j]!=0): print (mat_mal[i][j]*1.0/syscall_count[i], end=" ")
                else: print(0, end=" ")
            print("")

##        for i in range(mapped_so_far):
##            print(syscall_count[i])


def disconnectdb(db):
    db.commit()
    db.close()



def mapping(cursor):
    for filename in glob.glob("malware_parsed_syscall_csv/*.csv"):
        with open(filename) as f:
            content = f.readlines()

        prev_sys_id = -1
        for s in content:
            s = s[:len(s)-1]
            if(s=="" or s==" "):
                continue
            result_cnt = cursor.execute("select `sys_id` from `syscall_map` where `syscall`= '"+s+"'")
            if(result_cnt==0):
                #print(s)
                cursor.execute("INSERT INTO `syscall_map` (`syscall`, `sys_id`) VALUES ('"+ s +"', NULL);")
                cursor.execute("select `sys_id` from `syscall_map` where `syscall`= '"+s+"'")

            result = cursor.fetchone()
            sys_id=result[0]
            #print(sys_id)
            syscall_count[sys_id] += 1
            if(prev_sys_id !=-1):
                mat_mal[prev_sys_id][sys_id] += 1
            prev_sys_id = sys_id

    cursor.execute("SELECT max(`sys_id`) FROM `syscall_map`;");
    mapped_so_far=  cursor.fetchone()[0]
    printmat(mapped_so_far)
    #print("")


def main():

    db = MySQLdb.connect(host="localhost", port=3306, user="root", passwd="", db="malware_detection")
    cursor = db.cursor()
    mapping(cursor)
    disconnectdb(db)
    
if __name__== "__main__":
    main()

4034b0e3d323a5b0eab3e537cea14609f709ee4e
<mask token>


def printmat(mapped_so_far):
    for i in range(mapped_so_far):
        for j in range(mapped_so_far):
            if syscall_count[i] != 0 and mat_mal[i][j] != 0:
                print(mat_mal[i][j] * 1.0 / syscall_count[i], end=' ')
            else:
                print(0, end=' ')
        print('')


def disconnectdb(db):
    db.commit()
    db.close()


<mask token>


def main():
    db = MySQLdb.connect(host='localhost', port=3306, user='root', passwd=
        '', db='malware_detection')
    cursor = db.cursor()
    mapping(cursor)
    disconnectdb(db)


<mask token>

<mask token>


def printmat(mapped_so_far):
    for i in range(mapped_so_far):
        for j in range(mapped_so_far):
            if syscall_count[i] != 0 and mat_mal[i][j] != 0:
                print(mat_mal[i][j] * 1.0 / syscall_count[i], end=' ')
            else:
                print(0, end=' ')
        print('')


def disconnectdb(db):
    db.commit()
    db.close()


def mapping(cursor):
    for filename in glob.glob('malware_parsed_syscall_csv/*.csv'):
        with open(filename) as f:
            content = f.readlines()
        prev_sys_id = -1
        for s in content:
            s = s[:len(s) - 1]
            if s == '' or s == ' ':
                continue
            result_cnt = cursor.execute(
                "select `sys_id` from `syscall_map` where `syscall`= '" + s +
                "'")
            if result_cnt == 0:
                cursor.execute(
                    "INSERT INTO `syscall_map` (`syscall`, `sys_id`) VALUES ('"
                     + s + "', NULL);")
                cursor.execute(
                    "select `sys_id` from `syscall_map` where `syscall`= '" +
                    s + "'")
            result = cursor.fetchone()
            sys_id = result[0]
            syscall_count[sys_id] += 1
            if prev_sys_id != -1:
                mat_mal[prev_sys_id][sys_id] += 1
            prev_sys_id = sys_id
    cursor.execute('SELECT max(`sys_id`) FROM `syscall_map`;')
    mapped_so_far = cursor.fetchone()[0]
    printmat(mapped_so_far)


def main():
    db = MySQLdb.connect(host='localhost', port=3306, user='root', passwd=
        '', db='malware_detection')
    cursor = db.cursor()
    mapping(cursor)
    disconnectdb(db)


<mask token>

<mask token>


def printmat(mapped_so_far):
    for i in range(mapped_so_far):
        for j in range(mapped_so_far):
            if syscall_count[i] != 0 and mat_mal[i][j] != 0:
                print(mat_mal[i][j] * 1.0 / syscall_count[i], end=' ')
            else:
                print(0, end=' ')
        print('')


def disconnectdb(db):
    db.commit()
    db.close()


def mapping(cursor):
    for filename in glob.glob('malware_parsed_syscall_csv/*.csv'):
        with open(filename) as f:
            content = f.readlines()
        prev_sys_id = -1
        for s in content:
            s = s[:len(s) - 1]
            if s == '' or s == ' ':
                continue
            result_cnt = cursor.execute(
                "select `sys_id` from `syscall_map` where `syscall`= '" + s +
                "'")
            if result_cnt == 0:
                cursor.execute(
                    "INSERT INTO `syscall_map` (`syscall`, `sys_id`) VALUES ('"
                     + s + "', NULL);")
                cursor.execute(
                    "select `sys_id` from `syscall_map` where `syscall`= '" +
                    s + "'")
            result = cursor.fetchone()
            sys_id = result[0]
            syscall_count[sys_id] += 1
            if prev_sys_id != -1:
                mat_mal[prev_sys_id][sys_id] += 1
            prev_sys_id = sys_id
    cursor.execute('SELECT max(`sys_id`) FROM `syscall_map`;')
    mapped_so_far = cursor.fetchone()[0]
    printmat(mapped_so_far)


def main():
    db = MySQLdb.connect(host='localhost', port=3306, user='root', passwd=
        '', db='malware_detection')
    cursor = db.cursor()
    mapping(cursor)
    disconnectdb(db)


if __name__ == '__main__':
    main()

from __future__ import print_function
import MySQLdb
import glob
import os
MAX_CNT = 400
mat_mal = [[(0) for i in range(MAX_CNT)] for i in range(MAX_CNT)]
mat_prob = [[(0) for i in range(MAX_CNT)] for i in range(MAX_CNT)]
syscall_count = [(0) for i in range(MAX_CNT)]


def printmat(mapped_so_far):
    for i in range(mapped_so_far):
        for j in range(mapped_so_far):
            if syscall_count[i] != 0 and mat_mal[i][j] != 0:
                print(mat_mal[i][j] * 1.0 / syscall_count[i], end=' ')
            else:
                print(0, end=' ')
        print('')


def disconnectdb(db):
    db.commit()
    db.close()


def mapping(cursor):
    for filename in glob.glob('malware_parsed_syscall_csv/*.csv'):
        with open(filename) as f:
            content = f.readlines()
        prev_sys_id = -1
        for s in content:
            s = s[:len(s) - 1]
            if s == '' or s == ' ':
                continue
            result_cnt = cursor.execute(
                "select `sys_id` from `syscall_map` where `syscall`= '" + s +
                "'")
            if result_cnt == 0:
                cursor.execute(
                    "INSERT INTO `syscall_map` (`syscall`, `sys_id`) VALUES ('"
                     + s + "', NULL);")
                cursor.execute(
                    "select `sys_id` from `syscall_map` where `syscall`= '" +
                    s + "'")
            result = cursor.fetchone()
            sys_id = result[0]
            syscall_count[sys_id] += 1
            if prev_sys_id != -1:
                mat_mal[prev_sys_id][sys_id] += 1
            prev_sys_id = sys_id
    cursor.execute('SELECT max(`sys_id`) FROM `syscall_map`;')
    mapped_so_far = cursor.fetchone()[0]
    printmat(mapped_so_far)


def main():
    db = MySQLdb.connect(host='localhost', port=3306, user='root', passwd=
        '', db='malware_detection')
    cursor = db.cursor()
    mapping(cursor)
    disconnectdb(db)


if __name__ == '__main__':
    main()

from __future__ import print_function
import MySQLdb
import glob
import os

MAX_CNT = 400

mat_mal=[[0 for i in range(MAX_CNT)] for i in range(MAX_CNT)]
mat_prob= [[0 for i in range(MAX_CNT)] for i in range(MAX_CNT)]
syscall_count = [0 for i in range(MAX_CNT)]

def printmat(mapped_so_far):
        for i in range(mapped_so_far):
            for j in range(mapped_so_far):
                if(syscall_count[i]!=0 and mat_mal[i][j]!=0): print (mat_mal[i][j]*1.0/syscall_count[i], end=" ")
                else: print(0, end=" ")
            print("")

##        for i in range(mapped_so_far):
##            print(syscall_count[i])


def disconnectdb(db):
    db.commit()
    db.close()



def mapping(cursor):
    for filename in glob.glob("malware_parsed_syscall_csv/*.csv"):
        with open(filename) as f:
            content = f.readlines()

        prev_sys_id = -1
        for s in content:
            s = s[:len(s)-1]
            if(s=="" or s==" "):
                continue
            result_cnt = cursor.execute("select `sys_id` from `syscall_map` where `syscall`= '"+s+"'")
            if(result_cnt==0):
                #print(s)
                cursor.execute("INSERT INTO `syscall_map` (`syscall`, `sys_id`) VALUES ('"+ s +"', NULL);")
                cursor.execute("select `sys_id` from `syscall_map` where `syscall`= '"+s+"'")

            result = cursor.fetchone()
            sys_id=result[0]
            #print(sys_id)
            syscall_count[sys_id] += 1
            if(prev_sys_id !=-1):
                mat_mal[prev_sys_id][sys_id] += 1
            prev_sys_id = sys_id

    cursor.execute("SELECT max(`sys_id`) FROM `syscall_map`;");
    mapped_so_far=  cursor.fetchone()[0]
    printmat(mapped_so_far)
    #print("")


def main():

    db = MySQLdb.connect(host="localhost", port=3306, user="root", passwd="", db="malware_detection")
    cursor = db.cursor()
    mapping(cursor)
    disconnectdb(db)
    
if __name__== "__main__":
    main()
