from threading import *
from tkinter import *
from tkinter.filedialog import askopenfilename
import tkinter, tkinter.scrolledtext
import os
import sys
import urllib.request
import glob
import time
import hashlib
import quarantaene
from vta import vtapi
import argparse

os_name = sys.platform
terminations = []

if "win" in os_name:
    if not os.path.exists("MultiAV\\Quarantine\\"):
        os.makedirs("MultiAV\\Quarantine\\")
    quarantine_folder = "MultiAV\\Quarantine\\*"
    file_to_quarantine = "MultiAV\\Quarantine\\"
    transfer = os. getcwd() + "\\Transfer\\*"
else:
    if not os.path.exists("MultiAV/Quarantine/"):
        os.makedirs("MultiAV/Quarantine/")
    quarantine_folder = "MultiAV/Quarantine/*"
    file_to_quarantine = "MultiAV/Quarantine/"
    transfer = os. getcwd() + "/Transfer/*"

main = None
update_button = None
details_button = None
scan_button = None
quit_button = None
b_delete = None
b_delete_all = None
b_restore = None
b_restore_all = None
b_add_file = None
text_box = None
li = None
file= None

def quarantine():
    global text_box
    global terminations
    global li
    global b_delete
    global b_delete_all
    global b_restore
    global b_restore_all
    global b_add_file
    k = 0
    while True:
        tmp = len(li.get(k))
        if tmp == 0:
            break
        else:
            li.delete(0, tmp)
            k += 1
    li.update()
    terminations = glob.glob(quarantine_folder)
    if terminations == []:
        text_box.insert(END, "[ + ] No files in quarantine\n", "positive")
        text_box.tag_config('positive', foreground="green")
        text_box.see(END)
        text_box.update()
    else:
        text_box.insert(END, "[ + ] Files in quarantine:\n", "positive")
        text_box.tag_config('positive', foreground="green")
        text_box.see(END)
        text_box.update()
        for i in terminations:
            text_box.insert(END, "[ * ] " + i + "\n", "info")
            text_box.tag_config("info", background = "red")
            text_box.see(END)
            text_box.update()
            li.insert(END, i)
            li.update()
    b_delete_all["command"] =lambda:button_action_handler("delete_all")
    b_delete["command"] = lambda:button_action_handler("delete")
    b_restore["command"] = lambda:button_action_handler("restore")
    b_restore_all["command"] = lambda:button_action_handler("restore_all")
    b_add_file["command"] = lambda:button_action_handler("add_file")

def delete(file, ALL):
    global li
    global text_box
    global terminations
    if len(terminations) != 0:
        if ALL == 1:
            for i in range(len(terminations)):
                os.remove(terminations[i])
                text_box.insert(END, "[ + ] Deletion successful: \n" + terminations[i] + "\n", "positive")
                text_box.tag_config("positive", foreground="green")
                text_box.see(END)
                text_box.update()
                li.delete(0, len(terminations[i]))
                li.update()
        elif ALL == 0:
            os.remove(file)
            li.delete(ACTIVE, len(file))
            li.update()
            text_box.insert(END, "[ + ] Deletion successful:\n" + file + "\n", "positive")
            text_box.tag_config("positive", foreground="green")
            text_box.see(END)
            text_box.update()
        terminations = glob.glob(quarantine_folder)
        for i in terminations:
            li.insert(END, i)
        li.update()
    else:
        text_box.insert(END, "[ - ] Unable to locate any files\n", "negative")
        text_box.tag_config("negative", foreground="red")
        text_box.see(END)
        text_box.update()

def restore(file, ALL):
    global li
    global text_box
    global terminations
    if len(terminations) != 0:
        if ALL == 1:
            for i in range(len(terminations)):
                quarantaene.decode_base64(terminations[i])
                text_box.insert(END, "[ + ] Successfully restored\n" + terminations[i] + "\n", 'positive')
                text_box.tag_config('positive', foreground="green")
                text_box.see(END)
                text_box.update()
                li.delete(0, len(terminations[i]))
                li.update()
        elif ALL == 0:
            quarantaene.decode_base64(file)
            li.delete(ACTIVE, len(file))
            text_box.insert(END, "[ + ] Successfully restored\n" + file + "\n", "positive")
            text_box.tag_config("positive", foreground="green")
            text_box.see(END)
            text_box.update()
        terminations = glob.glob(quarantine_folder)
        for i in terminations:
            li.insert(END, i)
        li.update()
    else:
        text_box.insert(END, "[ - ] Unable to locate any files\n", "negative")
        text_box.tag_config("negative", foreground="red")
        text_box.see(END)
        text_box.update()

def add_file_to_quarantine():
    global li
    global terminations
    file = askopenfilename()
    quarantaene.encode_base64(file, file_to_quarantine)
    text_box.insert(END, "[ + ] Moved to quarantine:\n" + file + "\n", "positive")
    text_box.tag_config("positive", foreground="green")
    text_box.see(END)
    text_box.update()
    li.update()
    k = 0
    while True:
        tmp = len(li.get(k))
        if tmp == 0:
            break
        else:
            li.delete(0, tmp)
            k += 1
    li.update()
    terminations = glob.glob(quarantine_folder)
    for i in terminations:
        li.insert(END, i)
        li.update()

def parse_options():
    parser = argparse.ArgumentParser()
    parser.add_argument("-F", "--results-file", dest="sfile",
                        help="Get report of previously scanned file. If the "
                        "given filename cannot be found/opened, we'll assume "
                        "it's a hash.")
    parser.add_argument("-f", "--file", dest="file",
                        help="Scan file")
    parser.add_argument("-v", "--verbose", default=False, action="store_true",
                        dest="verbose", help="Print complete reply")
    return parser.parse_args()

def automatic_scan(path):
    global text_box
    global md5hash
    match = False
    file = path
    start = time.time()
    text_box.insert(END, "[ * ] Scanning " + file + "\n")
    text_box.see(END)
    text_box.update()
    arg = parse_options()
    arg.file=file
    vt = vtapi(arg.verbose)
    vt.sendfile(arg.file)

    try:
        f = open(file, "rb")
        content = f.read()
        f.close()
        content = create_md5(content)
        md5hash=content.decode("utf-8")
        text_box.insert(END, "MD5-Hash: " + md5hash + "\n")
        text_box.see(END)
        text_box.update()

    except MemoryError:
        text_box.insert(END, "[ - ] Unable to create MD5-Hash:\n----->MemoryError!\n", 'negative')
        text_box.insert(END, "[ ! ] Only select files under 1 GB\n", "negative")
        text_box.tag_config('negative', foreground="red")
        text_box.see(END)
        text_box.update()
        return None
    except Exception as e:
        text_box.insert(END, "[ ! ] Unable to handle problem\n[ ! ] Try again/file might be corrupted\n", "negative")
        text_box.tag_config('negative', foreground="red")
        text_box.see(END)
        text_box.update()
        return None

    while(True):
        scan_result=vt.print_scan_results(vt.results("file", md5hash))
        if(scan_result!=0):
            un=scan_result.count("Clean")
            line_count=scan_result.count("\n")-2
            percent=100-((un/line_count)*100)
            if(percent!=0):
                match=True
            break

    text_box.insert(END, "[ * ] Scan duration: {0}\n".format(round(time.time()-start, 2)))
    text_box.see(END)
    text_box.update()
    if (match==True):
        quarantaene.encode_base64(file, file_to_quarantine)
        text_box.insert(END, "[ ! ] Threat found: {0}%\n[ ! ] File was moved into quarantine\n".format(percent), "important")
        text_box.tag_config("important", foreground="red")
        text_box.see(END)
        text_box.update()
    else:
        text_box.insert(END, "[ + ] No threat was found\n", "positive")
        text_box.tag_config("positive", foreground="green")
        text_box.see(END)
        text_box.update()

def scan():
    global text_box
    global md5hash
    match = False
    file = askopenfilename()
    start = time.time()
    text_box.insert(END, "[ * ] Scanning " + file + "\n")
    text_box.see(END)
    text_box.update()
    arg = parse_options()
    arg.file=file
    vt = vtapi(arg.verbose)
    vt.sendfile(arg.file)

    try:
        f = open(file, "rb")
        content = f.read()
        f.close()
        content = create_md5(content)
        md5hash=content.decode("utf-8")
        text_box.insert(END, "MD5-Hash: " + md5hash + "\n")
        text_box.see(END)
        text_box.update()

    except MemoryError:
        text_box.insert(END, "[ - ] Unable to create MD5-Hash:\n----->MemoryError!\n", 'negative')
        text_box.insert(END, "[ ! ] Only select files under 1 GB\n", "negative")
        text_box.tag_config('negative', foreground="red")
        text_box.see(END)
        text_box.update()
        return None
    except Exception as e:
        text_box.insert(END, "[ ! ] Unable to handle problem\n[ ! ] Try again/file might be corrupted\n", "negative")
        text_box.tag_config('negative', foreground="red")
        text_box.see(END)
        text_box.update()
        return None

    while(True):
        scan_result=vt.print_scan_results(vt.results("file", md5hash))
        if(scan_result!=0):
            un=scan_result.count("Clean")
            line_count=scan_result.count("\n")-2
            percent=100-((un/line_count)*100)
            if(percent!=0):
                match=True
            break

    text_box.insert(END, "[ * ] Scan duration: {0}\n".format(round(time.time()-start, 2)))
    text_box.see(END)
    text_box.update()
    if (match==True):
        quarantaene.encode_base64(file, file_to_quarantine)
        text_box.insert(END, "[ ! ] Threat found: {0}%\n[ ! ] File was moved into quarantine\n".format(percent), "important")
        text_box.tag_config("important", foreground="red")
        text_box.see(END)
        text_box.update()
    else:
        text_box.insert(END, "[ + ] No threat was found\n", "positive")
        text_box.tag_config("positive", foreground="green")
        text_box.see(END)
        text_box.update()

def create_md5(content):
    md = hashlib.md5()
    md.update(content)
    return bytes(md.hexdigest(), "utf-8")


def detailedReport():
    global text_box
    global md5hash
    arg = parse_options()
    arg.sfile=md5hash
    vt = vtapi(arg.verbose)
    scan_result1=vt.print_scan_results(vt.results("file", md5hash))
    text_box.insert(END, scan_result1)
    text_box.see(END)
    text_box.update()

def update():
    global text_box

def closing():
    main.destroy()
    sys.exit()

def button_action_handler(s):
    global text_box
    global b_delete
    global b_delete_all
    global b_restore
    global b_restore_all
    global b_add_file
    global li

    if s == "delete":
        tb = Thread(target=delete, args=(li.get(ACTIVE),0))
        tb.start()
    if s == "delete_all":
        tb = Thread(target=delete, args=(0,1))
        tb.start()
    if s == "restore":
        tb = Thread(target=restore, args=(li.get(ACTIVE),0))
        tb.start()
    if s == "restore_all":
        tb = Thread(target=restore, args=(0,1))
        tb.start()
    if s == "add_file":
        tb = Thread(target=add_file_to_quarantine)
        tb.start()
    if s == "details_button":
        tb = Thread(target=detailedReport)
        tb.start()
    if s == "scan_button":
        tb = Thread(target=scan)
        tb.start()
    if s == "update_button":
        tb = Thread(target=update)
        tb.start()
    if s == "details_button":
        tb = Thread(target=detailedReport)
        tb.start()
    if s == "quarantine_button":
        if li.winfo_viewable()  == 0:
            b_delete.place(x = 605, y = 109)
            b_delete_all.place(x = 605, y = 134)
            b_restore.place(x = 605, y = 159)
            b_restore_all.place(x = 605, y = 184)
            b_add_file.place(x = 605, y = 209)
            li.place(x = 605, y = 0)
            tb = Thread(target=quarantine)
            tb.start()
        if li.winfo_viewable() == 1:
            b_delete.place_forget()
            b_delete_all.place_forget()
            b_restore.place_forget()
            b_restore_all.place_forget()
            b_add_file.place_forget()
            li.place_forget()
    if s == "quit_button":
        tb = Thread(target=closing)
        tb.start()

def gui_thread():
    global main
    global update_button
    global details_button
    global scan_button
    global url_scan_button
    global url_scan_button
    global quit_button
    global text_box
    global li
    global b_delete
    global b_delete_all
    global b_restore
    global b_restore_all
    global b_add_file

    main = tkinter.Tk()
    main.title("MultiAV")
    main.wm_iconbitmap("")
    main.geometry("800x240")
    main.resizable(False, False)
    hoehe = 2
    breite = 16

    scan_button = tkinter.Button(main,text = "Scan", command=lambda:button_action_handler("scan_button"), height = hoehe, width = breite)
    scan_button.grid(row = 0, column = 0)
    details_button = tkinter.Button(main,text = "Detailed Result", command=lambda:button_action_handler("details_button"), height = hoehe, width = breite)
    details_button.grid(row = 1, column = 0)
    update_button = tkinter.Button(main,text = "Update", command=lambda:button_action_handler("update_button"), height = hoehe, width = breite)
    update_button.grid(row = 2, column = 0)
    quarantine_button = tkinter.Button(main,text = "Quarantine", command=lambda:button_action_handler("quarantine_button"), height = hoehe, width = breite)
    quarantine_button.grid(row = 3, column = 0)
    quit_button = tkinter.Button(main,text = "Close", command=lambda:button_action_handler("quit_button"), height = hoehe, width = breite)
    quit_button.grid(row = 4, column = 0, sticky="w")
    b_delete = tkinter.Button(main,text = "Remove current", height=0, width = 21, justify=CENTER)
    b_delete_all = tkinter.Button(main,text = "Remove all", height = 0, width = 21, justify=CENTER)
    b_restore = tkinter.Button(main,text = "Restore current", height=0, width = 21, justify=CENTER)
    b_restore_all = tkinter.Button(main,text = "Restore all", height = 0, width = 21, justify=CENTER)
    b_add_file = tkinter.Button(main,text = "Add file", height = 0, width = 21, justify=CENTER)
    b_delete.place(x = 605, y = 109)
    b_delete_all.place(x = 605, y = 134)
    b_restore.place(x = 605, y = 159)
    b_restore_all.place(x = 605, y = 184)
    b_add_file.place(x = 605, y = 209)
    b_delete.place_forget()
    b_delete_all.place_forget()
    b_restore.place_forget()
    b_restore_all.place_forget()
    b_add_file.place_forget()

    text_box = tkinter.scrolledtext.ScrolledText(main)
    text_box.place(height = 240, width = 454,x = 153, y = 0)

    li = tkinter.Listbox(main, height=6, width = 24)
    li.place(x = 605, y = 0)
    li.place_forget()

    text_box.insert(END, "Your System is Protected\n", "VIP")
    text_box.tag_config("VIP", background='yellow')
    text_box.insert(END, "[ + ] Preparing the program\n", 'positive')
    text_box.tag_config('positive', foreground='green')
    text_box.see(END)
    text_box.update()

    list_of_files = glob.glob(transfer)
    if(len(list_of_files)>0):
        latest_file = max(list_of_files, key=os.path.getctime)
        automatic_scan(latest_file)
    main.mainloop()

t_main = Thread(target=gui_thread)
t_main.start()

from threading import *
from tkinter import *
from tkinter.filedialog import askopenfilename
import tkinter, tkinter.scrolledtext
import os
import sys
import urllib.request
import glob
import time
import hashlib
import quarantaene
from vta import vtapi
import argparse

os_name = sys.platform
terminations = []

if "win" in os_name:
    if not os.path.exists("MultiAV\\Quarantine\\"):
        os.makedirs("MultiAV\\Quarantine\\")
    quarantine_folder = "MultiAV\\Quarantine\\*"
    file_to_quarantine = "MultiAV\\Quarantine\\"
    transfer = os. getcwd() + "\\Transfer\\*"
else:
    if not os.path.exists("MultiAV/Quarantine/"):
        os.makedirs("MultiAV/Quarantine/")
    quarantine_folder = "MultiAV/Quarantine/*"
    file_to_quarantine = "MultiAV/Quarantine/"
    transfer = os. getcwd() + "/Transfer/*"

main = None
update_button = None
details_button = None
scan_button = None
quit_button = None
b_delete = None
b_delete_all = None
b_restore = None
b_restore_all = None
b_add_file = None
text_box = None
li = None
file= None

def quarantine():
    global text_box
    global terminations
    global li
    global b_delete
    global b_delete_all
    global b_restore
    global b_restore_all
    global b_add_file
    k = 0
    while True:
        tmp = len(li.get(k))
        if tmp == 0:
            break
        else:
            li.delete(0, tmp)
            k += 1
    li.update()
    terminations = glob.glob(quarantine_folder)
    if terminations == []:
        text_box.insert(END, "[ + ] No files in quarantine\n", "positive")
        text_box.tag_config('positive', foreground="green")
        text_box.see(END)
        text_box.update()
    else:
        text_box.insert(END, "[ + ] Files in quarantine:\n", "positive")
        text_box.tag_config('positive', foreground="green")
        text_box.see(END)
        text_box.update()
        for i in terminations:
            text_box.insert(END, "[ * ] " + i + "\n", "info")
            text_box.tag_config("info", background = "red")
            text_box.see(END)
            text_box.update()
            li.insert(END, i)
            li.update()
    b_delete_all["command"] =lambda:button_action_handler("delete_all")
    b_delete["command"] = lambda:button_action_handler("delete")
    b_restore["command"] = lambda:button_action_handler("restore")
    b_restore_all["command"] = lambda:button_action_handler("restore_all")
    b_add_file["command"] = lambda:button_action_handler("add_file")

def delete(file, ALL):
    global li
    global text_box
    global terminations
    if len(terminations) != 0:
        if ALL == 1:
            for i in range(len(terminations)):
                os.remove(terminations[i])
                text_box.insert(END, "[ + ] Deletion successful: \n" + terminations[i] + "\n", "positive")
                text_box.tag_config("positive", foreground="green")
                text_box.see(END)
                text_box.update()
                li.delete(0, len(terminations[i]))
                li.update()
        elif ALL == 0:
            os.remove(file)
            li.delete(ACTIVE, len(file))
            li.update()
            text_box.insert(END, "[ + ] Deletion successful:\n" + file + "\n", "positive")
            text_box.tag_config("positive", foreground="green")
            text_box.see(END)
            text_box.update()
        terminations = glob.glob(quarantine_folder)
        for i in terminations:
            li.insert(END, i)
        li.update()
    else:
        text_box.insert(END, "[ - ] Unable to locate any files\n", "negative")
        text_box.tag_config("negative", foreground="red")
        text_box.see(END)
        text_box.update()

def restore(file, ALL):
    global li
    global text_box
    global terminations
    if len(terminations) != 0:
        if ALL == 1:
            for i in range(len(terminations)):
                quarantaene.decode_base64(terminations[i])
                text_box.insert(END, "[ + ] Successfully restored\n" + terminations[i] + "\n", 'positive')
                text_box.tag_config('positive', foreground="green")
                text_box.see(END)
                text_box.update()
                li.delete(0, len(terminations[i]))
                li.update()
        elif ALL == 0:
            quarantaene.decode_base64(file)
            li.delete(ACTIVE, len(file))
            text_box.insert(END, "[ + ] Successfully restored\n" + file + "\n", "positive")
            text_box.tag_config("positive", foreground="green")
            text_box.see(END)
            text_box.update()
        terminations = glob.glob(quarantine_folder)
        for i in terminations:
            li.insert(END, i)
        li.update()
    else:
        text_box.insert(END, "[ - ] Unable to locate any files\n", "negative")
        text_box.tag_config("negative", foreground="red")
        text_box.see(END)
        text_box.update()

def add_file_to_quarantine():
    global li
    global terminations
    file = askopenfilename()
    quarantaene.encode_base64(file, file_to_quarantine)
    text_box.insert(END, "[ + ] Moved to quarantine:\n" + file + "\n", "positive")
    text_box.tag_config("positive", foreground="green")
    text_box.see(END)
    text_box.update()
    li.update()
    k = 0
    while True:
        tmp = len(li.get(k))
        if tmp == 0:
            break
        else:
            li.delete(0, tmp)
            k += 1
    li.update()
    terminations = glob.glob(quarantine_folder)
    for i in terminations:
        li.insert(END, i)
        li.update()

def parse_options():
    parser = argparse.ArgumentParser()
    parser.add_argument("-F", "--results-file", dest="sfile",
                        help="Get report of previously scanned file. If the "
                        "given filename cannot be found/opened, we'll assume "
                        "it's a hash.")
    parser.add_argument("-f", "--file", dest="file",
                        help="Scan file")
    parser.add_argument("-v", "--verbose", default=False, action="store_true",
                        dest="verbose", help="Print complete reply")
    return parser.parse_args()

def automatic_scan(path):
    global text_box
    global md5hash
    match = False
    file = path
    start = time.time()
    text_box.insert(END, "[ * ] Scanning " + file + "\n")
    text_box.see(END)
    text_box.update()
    arg = parse_options()
    arg.file=file
    vt = vtapi(arg.verbose)
    vt.sendfile(arg.file)

    try:
        f = open(file, "rb")
        content = f.read()
        f.close()
        content = create_md5(content)
        md5hash=content.decode("utf-8")
        text_box.insert(END, "MD5-Hash: " + md5hash + "\n")
        text_box.see(END)
        text_box.update()

    except MemoryError:
        text_box.insert(END, "[ - ] Unable to create MD5-Hash:\n----->MemoryError!\n", 'negative')
        text_box.insert(END, "[ ! ] Only select files under 1 GB\n", "negative")
        text_box.tag_config('negative', foreground="red")
        text_box.see(END)
        text_box.update()
        return None
    except Exception as e:
        text_box.insert(END, "[ ! ] Unable to handle problem\n[ ! ] Try again/file might be corrupted\n", "negative")
        text_box.tag_config('negative', foreground="red")
        text_box.see(END)
        text_box.update()
        return None

    while(True):
        scan_result=vt.print_scan_results(vt.results("file", md5hash))
        if(scan_result!=0):
            un=scan_result.count("Clean")
            line_count=scan_result.count("\n")-2
            percent=100-((un/line_count)*100)
            if(percent!=0):
                match=True
            break

    text_box.insert(END, "[ * ] Scan duration: {0}\n".format(round(time.time()-start, 2)))
    text_box.see(END)
    text_box.update()
    if (match==True):
        quarantaene.encode_base64(file, file_to_quarantine)
        text_box.insert(END, "[ ! ] Threat found: {0}%\n[ ! ] File was moved into quarantine\n".format(percent), "important")
        text_box.tag_config("important", foreground="red")
        text_box.see(END)
        text_box.update()
    else:
        text_box.insert(END, "[ + ] No threat was found\n", "positive")
        text_box.tag_config("positive", foreground="green")
        text_box.see(END)
        text_box.update()

def scan():
    global text_box
    global md5hash
    match = False
    file = askopenfilename()
    start = time.time()
    text_box.insert(END, "[ * ] Scanning " + file + "\n")
    text_box.see(END)
    text_box.update()
    arg = parse_options()
    arg.file=file
    vt = vtapi(arg.verbose)
    vt.sendfile(arg.file)

    try:
        f = open(file, "rb")
        content = f.read()
        f.close()
        content = create_md5(content)
        md5hash=content.decode("utf-8")
        text_box.insert(END, "MD5-Hash: " + md5hash + "\n")
        text_box.see(END)
        text_box.update()

    except MemoryError:
        text_box.insert(END, "[ - ] Unable to create MD5-Hash:\n----->MemoryError!\n", 'negative')
        text_box.insert(END, "[ ! ] Only select files under 1 GB\n", "negative")
        text_box.tag_config('negative', foreground="red")
        text_box.see(END)
        text_box.update()
        return None
    except Exception as e:
        text_box.insert(END, "[ ! ] Unable to handle problem\n[ ! ] Try again/file might be corrupted\n", "negative")
        text_box.tag_config('negative', foreground="red")
        text_box.see(END)
        text_box.update()
        return None

    while(True):
        scan_result=vt.print_scan_results(vt.results("file", md5hash))
        if(scan_result!=0):
            un=scan_result.count("Clean")
            line_count=scan_result.count("\n")-2
            percent=100-((un/line_count)*100)
            if(percent!=0):
                match=True
            break

    text_box.insert(END, "[ * ] Scan duration: {0}\n".format(round(time.time()-start, 2)))
    text_box.see(END)
    text_box.update()
    if (match==True):
        quarantaene.encode_base64(file, file_to_quarantine)
        text_box.insert(END, "[ ! ] Threat found: {0}%\n[ ! ] File was moved into quarantine\n".format(percent), "important")
        text_box.tag_config("important", foreground="red")
        text_box.see(END)
        text_box.update()
    else:
        text_box.insert(END, "[ + ] No threat was found\n", "positive")
        text_box.tag_config("positive", foreground="green")
        text_box.see(END)
        text_box.update()

def create_md5(content):
    md = hashlib.md5()
    md.update(content)
    return bytes(md.hexdigest(), "utf-8")


def detailedReport():
    global text_box
    global md5hash
    arg = parse_options()
    arg.sfile=md5hash
    vt = vtapi(arg.verbose)
    scan_result1=vt.print_scan_results(vt.results("file", md5hash))
    text_box.insert(END, scan_result1)
    text_box.see(END)
    text_box.update()

def update():
    global text_box

def closing():
    main.destroy()
    sys.exit()

def button_action_handler(s):
    global text_box
    global b_delete
    global b_delete_all
    global b_restore
    global b_restore_all
    global b_add_file
    global li

    if s == "delete":
        tb = Thread(target=delete, args=(li.get(ACTIVE),0))
        tb.start()
    if s == "delete_all":
        tb = Thread(target=delete, args=(0,1))
        tb.start()
    if s == "restore":
        tb = Thread(target=restore, args=(li.get(ACTIVE),0))
        tb.start()
    if s == "restore_all":
        tb = Thread(target=restore, args=(0,1))
        tb.start()
    if s == "add_file":
        tb = Thread(target=add_file_to_quarantine)
        tb.start()
    if s == "details_button":
        tb = Thread(target=detailedReport)
        tb.start()
    if s == "scan_button":
        tb = Thread(target=scan)
        tb.start()
    if s == "update_button":
        tb = Thread(target=update)
        tb.start()
    if s == "details_button":
        tb = Thread(target=detailedReport)
        tb.start()
    if s == "quarantine_button":
        if li.winfo_viewable()  == 0:
            b_delete.place(x = 605, y = 109)
            b_delete_all.place(x = 605, y = 134)
            b_restore.place(x = 605, y = 159)
            b_restore_all.place(x = 605, y = 184)
            b_add_file.place(x = 605, y = 209)
            li.place(x = 605, y = 0)
            tb = Thread(target=quarantine)
            tb.start()
        if li.winfo_viewable() == 1:
            b_delete.place_forget()
            b_delete_all.place_forget()
            b_restore.place_forget()
            b_restore_all.place_forget()
            b_add_file.place_forget()
            li.place_forget()
    if s == "quit_button":
        tb = Thread(target=closing)
        tb.start()

def gui_thread():
    global main
    global update_button
    global details_button
    global scan_button
    global url_scan_button
    global url_scan_button
    global quit_button
    global text_box
    global li
    global b_delete
    global b_delete_all
    global b_restore
    global b_restore_all
    global b_add_file

    main = tkinter.Tk()
    main.title("MultiAV")
    main.wm_iconbitmap("")
    main.geometry("800x240")
    main.resizable(False, False)
    hoehe = 2
    breite = 16

    scan_button = tkinter.Button(main,text = "Scan", command=lambda:button_action_handler("scan_button"), height = hoehe, width = breite)
    scan_button.grid(row = 0, column = 0)
    details_button = tkinter.Button(main,text = "Detailed Result", command=lambda:button_action_handler("details_button"), height = hoehe, width = breite)
    details_button.grid(row = 1, column = 0)
    update_button = tkinter.Button(main,text = "Update", command=lambda:button_action_handler("update_button"), height = hoehe, width = breite)
    update_button.grid(row = 2, column = 0)
    quarantine_button = tkinter.Button(main,text = "Quarantine", command=lambda:button_action_handler("quarantine_button"), height = hoehe, width = breite)
    quarantine_button.grid(row = 3, column = 0)
    quit_button = tkinter.Button(main,text = "Close", command=lambda:button_action_handler("quit_button"), height = hoehe, width = breite)
    quit_button.grid(row = 4, column = 0, sticky="w")
    b_delete = tkinter.Button(main,text = "Remove current", height=0, width = 21, justify=CENTER)
    b_delete_all = tkinter.Button(main,text = "Remove all", height = 0, width = 21, justify=CENTER)
    b_restore = tkinter.Button(main,text = "Restore current", height=0, width = 21, justify=CENTER)
    b_restore_all = tkinter.Button(main,text = "Restore all", height = 0, width = 21, justify=CENTER)
    b_add_file = tkinter.Button(main,text = "Add file", height = 0, width = 21, justify=CENTER)
    b_delete.place(x = 605, y = 109)
    b_delete_all.place(x = 605, y = 134)
    b_restore.place(x = 605, y = 159)
    b_restore_all.place(x = 605, y = 184)
    b_add_file.place(x = 605, y = 209)
    b_delete.place_forget()
    b_delete_all.place_forget()
    b_restore.place_forget()
    b_restore_all.place_forget()
    b_add_file.place_forget()

    text_box = tkinter.scrolledtext.ScrolledText(main)
    text_box.place(height = 240, width = 454,x = 153, y = 0)

    li = tkinter.Listbox(main, height=6, width = 24)
    li.place(x = 605, y = 0)
    li.place_forget()

    text_box.insert(END, "Your System is Protected\n", "VIP")
    text_box.tag_config("VIP", background='yellow')
    text_box.insert(END, "[ + ] Preparing the program\n", 'positive')
    text_box.tag_config('positive', foreground='green')
    text_box.see(END)
    text_box.update()

    list_of_files = glob.glob(transfer)
    if(len(list_of_files)>0):
        latest_file = max(list_of_files, key=os.path.getctime)
        automatic_scan(latest_file)
    main.mainloop()

t_main = Thread(target=gui_thread)
t_main.start()
