MOD: improved the fingerprint comparison algorithm and the output
This commit is contained in:
parent
76a9dd1f8b
commit
ff1d7ab9ac
20
dbfp.py
20
dbfp.py
|
@ -61,7 +61,7 @@ def indexFingerprints(fp_dir):
|
||||||
|
|
||||||
#
|
#
|
||||||
def compareFPIndex(fp_dir, db_in, json_in):
|
def compareFPIndex(fp_dir, db_in, json_in):
|
||||||
# try:
|
try:
|
||||||
db = FingerprintDB()
|
db = FingerprintDB()
|
||||||
if (db_in):
|
if (db_in):
|
||||||
db.scanDBFile(db_in)
|
db.scanDBFile(db_in)
|
||||||
|
@ -83,23 +83,17 @@ def compareFPIndex(fp_dir, db_in, json_in):
|
||||||
print fp
|
print fp
|
||||||
# search for fingerprints with similar tables
|
# search for fingerprints with similar tables
|
||||||
else:
|
else:
|
||||||
|
print "[ Table percent match: ]"
|
||||||
logging.info("Searching for md5 tables: {}".format(db.getMD5Tables()))
|
logging.info("Searching for md5 tables: {}".format(db.getMD5Tables()))
|
||||||
fp_list = fp.findFPTables(db.getMD5Tables().values())
|
fp_list = fp.findFPTables(db.getMD5Tables().values())
|
||||||
results = []
|
|
||||||
for fp in fp_list:
|
for fp in fp_list:
|
||||||
fq_fp = fp_dir + os.path.sep + fp
|
fq_fp = fp_dir + os.path.sep + fp[0]
|
||||||
logging.info("Comparing fingerprint: {}".format(fq_fp))
|
logging.info("Comparing fingerprint: {}".format(fq_fp))
|
||||||
percent = db.compareDB(fq_fp)
|
percent = db.compareDB(fq_fp)
|
||||||
results.append(percent)
|
print "{:2.2f}%: {}".format(percent, fp[0])
|
||||||
|
except Exception as ex:
|
||||||
print "Table matche(s) found"
|
print "ERROR: error occured while comparing fingerprint"
|
||||||
print "RESULTS: {}".format(results)
|
print ex
|
||||||
results.sort()
|
|
||||||
print "RESULTS: {}".format(results)
|
|
||||||
# except Exception as ex:
|
|
||||||
# print "Error comparing fingerprint"
|
|
||||||
# print ex
|
|
||||||
|
|
||||||
#
|
#
|
||||||
def androidPull():
|
def androidPull():
|
||||||
fin_count = 0
|
fin_count = 0
|
||||||
|
|
|
@ -142,7 +142,6 @@ class FingerprintDB:
|
||||||
fp = FingerprintDB();
|
fp = FingerprintDB();
|
||||||
fp.__importJsonDBSchema(filejson)
|
fp.__importJsonDBSchema(filejson)
|
||||||
result = self.__DBSchemaCompare(fp)
|
result = self.__DBSchemaCompare(fp)
|
||||||
print "[ Percetage == %f]".format(result)
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -177,6 +176,7 @@ class FingerprintDB:
|
||||||
self.db_hash = dbmd5
|
self.db_hash = dbmd5
|
||||||
self.table_hashes = dbht
|
self.table_hashes = dbht
|
||||||
self.file_details = metadata
|
self.file_details = metadata
|
||||||
|
self.init = True
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.error("ERROR: problem loading json file: \n{}\n{}".format(file_json, ex))
|
logging.error("ERROR: problem loading json file: \n{}\n{}".format(file_json, ex))
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ class FingerprintDB:
|
||||||
if (diff_total == all_total):
|
if (diff_total == all_total):
|
||||||
percentage = 0
|
percentage = 0
|
||||||
else:
|
else:
|
||||||
percentage = float(diff_total / all_total)
|
percentage = 100 * float(all_total-diff_total) / float(all_total)
|
||||||
else:
|
else:
|
||||||
percentage = 100
|
percentage = 100
|
||||||
return percentage
|
return percentage
|
||||||
|
|
|
@ -96,18 +96,10 @@ class FingerprintIndex:
|
||||||
retval[fp] = retval[fp] + 1
|
retval[fp] = retval[fp] + 1
|
||||||
else:
|
else:
|
||||||
retval[fp] = 1
|
retval[fp] = 1
|
||||||
logging.debug("findFPTables::retval=={}\n".format(retval))
|
# logging.debug("findFPTables::retval=={}\n".format(retval))
|
||||||
|
retval_sorted = sorted(retval.items(), key=itemgetter(1), reverse=True)
|
||||||
# retval_sorted = sorted(retval.items(), key==lambda x: x[1])
|
# logging.debug("findFPTables::retval_sorted=={}\n".format(retval_sorted))
|
||||||
retval_sorted = sorted(retval.items(), key=itemgetter(1))
|
|
||||||
# retval_sorted = []
|
|
||||||
# vals = retval.values()
|
|
||||||
# vals.sort()
|
|
||||||
# for val in vals:
|
|
||||||
# retval_sorted.append(retval[val])
|
|
||||||
logging.debug("findFPTables::retval_sorted=={}\n".format(retval_sorted))
|
|
||||||
return retval_sorted
|
return retval_sorted
|
||||||
# return retval.keys()
|
|
||||||
|
|
||||||
#
|
#
|
||||||
def findDB(self, md5_db):
|
def findDB(self, md5_db):
|
||||||
|
|
Loading…
Reference in New Issue