本文整理汇总了Python中ssdeep.hash_from_file方法的典型用法代码示例。如果您正苦于以下问题:Python ssdeep.hash_from_file方法的具体用法?Python ssdeep.hash_from_file怎么用?Python ssdeep.hash_from_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ssdeep
的用法示例。
在下文中一共展示了ssdeep.hash_from_file方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_ssdeep
# 需要导入模块: import ssdeep [as 别名]
# 或者: from ssdeep import hash_from_file [as 别名]
def get_ssdeep(filename):
"""There are two Python bindings for ssdeep, each with a different interface. So we try
Jose's pyssdeep first and if it fails, try the one from pypi. Just install one or the other:
http://code.google.com/p/pyssdeep/
http://pypi.python.org/packages/source/s/ssdeep/ssdeep-2.5.tar.gz#md5=fd9e5271c01ca389cc621ae306327ab6
"""
try:
from ssdeep import ssdeep
s = ssdeep()
return s.hash_file(filename)
except:
try:
import ssdeep
return ssdeep.hash_from_file(filename)
except:
pass
return ''
示例2: get_ssdeep
# 需要导入模块: import ssdeep [as 别名]
# 或者: from ssdeep import hash_from_file [as 别名]
def get_ssdeep(filename):
"""There are two Python bindings for ssdeep, each with a different interface. So we try
Jose's pyssdeep first and if it fails, try the one from pypi. Just install one or the other:
http://code.google.com/p/pyssdeep/
http://pypi.python.org/packages/source/s/ssdeep/ssdeep-2.5.tar.gz#md5=fd9e5271c01ca389cc621ae306327ab6
"""
try:
from ssdeep import ssdeep
s = ssdeep()
return s.hash_file(filename)
except:
try:
import ssdeep
return ssdeep.hash_from_file(filename)
except:
pass
示例3: get_ssdeep
# 需要导入模块: import ssdeep [as 别名]
# 或者: from ssdeep import hash_from_file [as 别名]
def get_ssdeep(self):
try:
return ssdeep.hash_from_file(self.filename)
except ImportError:
pass
return ''
# this requires pefile v1.2.10-139 +
示例4: file_info
# 需要导入模块: import ssdeep [as 别名]
# 或者: from ssdeep import hash_from_file [as 别名]
def file_info(filename):
info = []
with open(filename, 'rb') as f:
file = f.read()
info.append("File: {}".format(filename))
info.append("Size: {} bytes".format(os.path.getsize(filename)))
info.append("Type: {}".format(magic.from_file(filename, mime=True)))
info.append("MD5: {}".format(hashlib.md5(file).hexdigest()))
info.append("SHA1: {}".format(hashlib.sha1(file).hexdigest()))
if ssdeep_r:
info.append("ssdeep: {}".format(ssdeep.hash_from_file(filename)))
return info
示例5: get_ssdeep
# 需要导入模块: import ssdeep [as 别名]
# 或者: from ssdeep import hash_from_file [as 别名]
def get_ssdeep(self):
try:
return ssdeep.hash_from_file(self.filepath)
except Exception as e:
self.logger.exception('%s: %s' % (Exception, e))
示例6: scan
# 需要导入模块: import ssdeep [as 别名]
# 或者: from ssdeep import hash_from_file [as 别名]
def scan(filelist):
results = []
for fname in filelist:
goodtogo = False
i = 0
# Ran into a weird issue with file locking, this fixes it
while not goodtogo and i < 5:
try:
ssdeep_hash = ssdeep.hash_from_file(fname)
chunksize, chunk, double_chunk = ssdeep_hash.split(':')
chunksize = int(chunksize)
doc = {
'ssdeep_hash': ssdeep_hash,
'chunksize': chunksize,
'chunk': chunk,
'double_chunk': double_chunk,
'analyzed': 'false',
'matches': {},
}
results.append((fname, doc))
goodtogo = True
except Exception as e:
print('ssdeeper:', e)
time.sleep(3)
i += 1
metadata = {}
metadata["Name"] = NAME
metadata["Type"] = TYPE
metadata["Include"] = False
return (results, metadata)
示例7: main
# 需要导入模块: import ssdeep [as 别名]
# 或者: from ssdeep import hash_from_file [as 别名]
def main(known_file, comparison, output_type):
"""
The main function handles the main operations of the script
:param known_file: path to known file
:param comparison: path to look for similar files
:param output_type: type of output to provide
:return: None
"""
# Check output formats
if output_type not in OUTPUT_OPTS:
logger.error(
"Unsupported output format '{}' selected. Please "
"use one of {}".format(
output_type, ", ".join(OUTPUT_OPTS)))
sys.exit(2)
elif output_type == 'csv':
# Special handling for CSV headers
print('"similarity","known_file","known_hash",'
'"comp_file","comp_hash"')
# Check provided file paths
known_file = os.path.abspath(known_file)
comparison = os.path.abspath(comparison)
# Generate ssdeep signature for known file
if not os.path.exists(known_file):
logger.error("Error - path {} not found".format(
comparison))
sys.exit(1)
known_hash = ssdeep.hash_from_file(known_file)
# Generate and test ssdeep signature for comparison file(s)
if os.path.isdir(comparison):
# Process files in folders
for root, _, files in os.walk(comparison):
for f in files:
file_entry = os.path.join(root, f)
comp_hash = ssdeep.hash_from_file(file_entry)
comp_val = ssdeep.compare(known_hash, comp_hash)
output(known_file, known_hash,
file_entry, comp_hash,
comp_val, output_type)
elif os.path.isfile(comparison):
# Process a single file
comp_hash = ssdeep.hash_from_file(comparison)
comp_val = ssdeep.compare(known_hash, comp_hash)
output(known_file, known_hash, file_entry, comp_hash,
comp_val, output_type)
else:
logger.error("Error - path {} not found".format(
comparison))
sys.exit(1)
开发者ID:PacktPublishing,项目名称:Learning-Python-for-Forensics-Second-Edition,代码行数:57,代码来源:ssdeep_python.py