vendredi 26 janvier 2018

Creating an IF statement to insert within the canvas widget

I am trying to create three solutions to match checksums

  1. Creating a match of an md5 hash
  2. Creating a matchof a crc checksum
  3. Adding the subdirList to the canvas as well as 1 & 2

I understand that i need to create an if statement and add it to my canvas.itemconfig but quite unsure of how i need to structure them

from tkinter import *
import os
import hashlib
import zlib

root=Tk()
class ScanningOS():
    pass

#lloyds.docx, 2215.jpg matching

#match = 15f330107c51887cbca3e33f19f44026, 5f5c5f86
#if match == 15f330107c51887cbca3e33f19f44026:
    #print ('Match Detected %s' % output)

rootDir = r"C:\Users\Ghost\Documents\MalwareTest"
output = []
for dirName, subdirList, fileList in os.walk(rootDir, topdown=True):
    print('Directory:', dirName)
    for x in fileList:
        hashupdate = hashlib.md5()
        with open(os.path.join(dirName, x), 'rb') as f:
            hashupdate.update(f.read())
        output.append('Filename: {} \t MD5: {}'.format(x, hashupdate.hexdigest()))
output = '\n'.join(output)
print(output)

buffersize = 65536

with open(r"C:\Users\Ghost\Documents\MalwareTest\2215.jpg", 'rb') as afile:
    buffr = afile.read(buffersize)
    crcvalue = 0
    while len(buffr) > 0:
        crcvalue = zlib.crc32(buffr, crcvalue)
        buffr = afile.read(buffersize)

print(format(crcvalue & 0xFFFFFFFF, '08x'))

centerLabel = Label(root, bg='white', width=65, height=13, padx=3, pady=3, anchor=NW,relief=SUNKEN)
centerLabel.place(x=100, y=67) 

canvas= Canvas(centerLabel,bg='#FFFFFF',width=440,height=180,relief=SUNKEN)
canvas_id = canvas.create_text(15, 15, anchor="nw")
canvas.itemconfig(canvas_id, text="Directory: {}\n{}\n".format(rootDir, output))

xbar= Scrollbar(centerLabel,orient="horizontal", command=canvas.xview)
xbar.pack(side=BOTTOM,fill=X)
xbar.config(command=canvas.xview)
ybar= Scrollbar(centerLabel,orient="vertical", command=canvas.yview)
ybar.pack(side=RIGHT,fill=Y)
ybar.config(command=canvas.yview)

canvas.config(width=440,height=180)
canvas.configure(scrollregion = canvas.bbox("all"))
canvas.config(xscrollcommand=xbar.set, yscrollcommand=ybar.set)
canvas.pack(side=LEFT,expand=True,fill=BOTH)

root.mainloop()

  • The checksums have been identified as match = 15f330107c51887cbca3e33f19f44026, 5f5c5f86 which is file lloyds.docx and 2215.jpg

Example structure is:

    Directory: C:\Users\Ghost\Documents\MalwareTest
Directory: C:\Users\Ghost\Documents\MalwareTest\New folder (subdirList)
Filename: 2215.jpg   MD5: a26ea006064799dd2a640b5d7edf613a (Matching File)

Aucun commentaire:

Enregistrer un commentaire