本文整理汇总了Python中pydeep.hash_file函数的典型用法代码示例。如果您正苦于以下问题:Python hash_file函数的具体用法?Python hash_file怎么用?Python hash_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hash_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buf_hashes
def buf_hashes(buf, algo='sha256'):
if not buf:
return None
if algo == 'crc32':
return "%X" % (zlib.crc32(buf) & 0xffffffff)
elif algo == 'adler32':
return "%X" % (zlib.adler32(buf) & 0xffffffff)
elif algo == 'md5':
hasher = hashlib.md5()
elif algo == 'sha1':
hasher = hashlib.sha1()
elif algo == 'sha224':
hasher = hashlib.sha224()
elif algo == 'sha256':
hasher = hashlib.sha256()
elif algo == 'sha384':
hasher = hashlib.sha384()
elif algo == 'sha512':
hasher = hashlib.sha512()
elif algo == 'ssdeep':
return pydeep.hash_file(filename)
else:
return None
hasher.update(buf)
return hasher.hexdigest()
示例2: file_hashes
def file_hashes(filename, algo='sha256', blocksize=65536):
file_handle = open(filename, 'rb')
buf = file_handle.read(blocksize)
if algo == 'crc32':
return "%X" % (zlib.crc32(open(filename,"rb").read()) & 0xffffffff)
elif algo == 'adler32':
return "%X" % (zlib.adler32(open(filename,"rb").read()) & 0xffffffff)
elif algo == 'md5':
hasher = hashlib.md5()
elif algo == 'sha1':
hasher = hashlib.sha1()
elif algo == 'sha224':
hasher = hashlib.sha224()
elif algo == 'sha256':
hasher = hashlib.sha256()
elif algo == 'sha384':
hasher = hashlib.sha384()
elif algo == 'sha512':
hasher = hashlib.sha512()
elif algo == 'ssdeep':
return pydeep.hash_file(filename)
else:
return None
while len(buf) > 0:
hasher.update(buf)
buf = file_handle.read(blocksize)
return hasher.hexdigest()
示例3: hashfile
def hashfile(path, targetfile):
'''This function returns a hash from a given file.'''
md5 = hashlib.md5()
sha1 = hashlib.sha1()
sha256 = hashlib.sha256()
sha512 = hashlib.sha512()
fullfile = path + "/" + targetfile
with open(fullfile, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
md5.update(data)
sha1.update(data)
sha256.update(data)
sha512.update(data)
hdict = {
'fileformat': magic.from_file(fullfile, mime=True),
'filename': str(targetfile),
'filesize': os.path.getsize(fullfile),
'md5': md5.hexdigest(),
'sha1': sha1.hexdigest(),
'sha256': sha256.hexdigest(),
'sha512': sha512.hexdigest(),
'ssdeep': pydeep.hash_file(fullfile)
}
return hdict
示例4: get_ssdeep
def get_ssdeep(self):
if not HAVE_SSDEEP:
return ''
try:
return pydeep.hash_file(self.path)
except Exception:
return ''
示例5: test_pydeep
def test_pydeep():
for test in testL:
filename, filelen, filehash = test
data = io.open(filename, 'rb').read()
hash_buf = pydeep.hash_buf(data)
hash_file = pydeep.hash_file(filename)
assert len(data) == filelen, "File length error"
assert hash_buf == filehash, "Error hashing %s using hash_buf"%filename
assert hash_file == filehash, "Error hashing %s using hash_file"%filename
示例6: get_ssdeep
def get_ssdeep(self):
""" Obtem o hash SSDEEP do arquivo """
if not HAVE_SSDEEP:
return ''
if self.file_data is None:
return ''
try:
return pydeep.hash_file(self.file_path)
except Exception:
return ''
示例7: get_ssdeep
def get_ssdeep(self):
"""Get SSDEEP.
@return: SSDEEP.
"""
if not HAVE_SSDEEP:
return None
try:
return pydeep.hash_file(self.file_path)
except Exception:
return None
示例8: get_ssdeep
def get_ssdeep(self):
if not HAVE_SSDEEP:
return None
try:
if Config().api.use_aws:
return pydeep.hash_buffer(self.data)
else:
return pydeep.hash_file(self.path)
except Exception:
return None
示例9: get_ssdeep
def get_ssdeep(self):
"""Get SSDEEP.
@return: SSDEEP.
"""
if not HAVE_PYDEEP:
if not File.notified_pydeep:
File.notified_pydeep = True
log.warning("Unable to import pydeep (install with `pip install pydeep`)")
return None
try:
return pydeep.hash_file(self.file_path)
except Exception:
return None
示例10: analyze
def analyze(self, config, filename):
"""Analyze the file."""
# sanity check to make sure we can run
if self.is_activated == False:
return False
log = logging.getLogger('Mastiff.Plugins.' + self.name)
log.info('Starting execution.')
log.info('Generating fuzzy hash.')
try:
my_fuzzy = pydeep.hash_file(filename)
except pydeep.error, err:
log.error('Could not generate fuzzy hash: %s', err)
return False
示例11: ssdeepMe
def ssdeepMe(path):
if path is not None:
return pydeep.hash_file(path)
else:
print("Ssdeep: provide a file path")
return ""
示例12: get_ssdeep
def get_ssdeep(malware_path):
return pydeep.hash_file(malware_path)
示例13: str
#!/usr/bin/env python
#ssdeep insto hashin'! - since ssdeep is natively an unwieldy PITA.
#https://pypi.python.org/pypi/pydeep
#PhG
import sys, pydeep
pd1 = pydeep.hash_file(sys.argv[1])
pd2 = pydeep.hash_file(sys.argv[2])
percent = str(pydeep.compare(pd1, pd2))
print "SSDeep has determined that these files are " + percent +"% alike."
#pd0 = pydeep.hash_file("VirusShare_ab208f0b517ba9850f1551c9555b5313")
#pd1 = pydeep.hash_file("VirusShare_6570163cd34454b3d1476c134d44b9d9")
示例14: ssdeep
def ssdeep(filename):
return pydeep.hash_file(filename)
示例15: engine
#!/usr/bin/env python
#ssdeep massive comparision engine (fancy way of saying... shitty script)
#there's no reason to do this... idk wtf I was doing. This makes no sense. Broken.
import sys
import pydeep
pd0 = pydeep.hash_file(sys.argv[1])
pd1 = sys.argv[2]
#Import our ssdeep file.
def deepImp(pd1) :
deepDict = []
with open(pd1, 'r') as deepFiles:
for row in deepFiles:
deepDict.append(row[1])
return ssdeepDir
deepImpList = deepImp(pd1)
x = str(pydeep.compare(pd0, pd1))
print "SSDeep has determined that the DeepImportHash between" + (sys.argv[1]) + " and " + deepImpList + " are " + x +"% alike."