FIX: improved the compareFingerprintDir, split find fingerprint functions, bug fixes

This commit is contained in:
JohnE 2016-02-22 13:22:00 -08:00
parent 44e853484b
commit f738006147
3 changed files with 40 additions and 19 deletions

21
dbfp.py
View File

@ -63,13 +63,24 @@ def indexFingerprints(fp_dir):
# #
def compareFingerprintDir(file_in, fp_dir): def compareFingerprintDir(file_in, fp_dir):
try:
db = FingerprintDB() db = FingerprintDB()
db.scanDBFile(file_in) db.scanDBFile(file_in)
md5_db = db.getMD5DB()
md5_tables = db.getMD5Tables()
fp = FingerprintIndex() fp = FingerprintIndex()
fp.openIndex(fp_dir) fp.openIndex(fp_dir)
fp_list = fp.findFP(md5_db, md5_tables)
# search for fingerprints with exact database match
fp_ret = fp.findFP(db.getMD5DB())
if (fp_ret):
print "Database matche(s) found"
print "RESULTS:"
for fp_list in fp_ret:
for fp in fp_list[1].split(','):
print fp
print
# search for fingerprints with similar tables
else:
fp_list = fp.findFPTables(db.getMD5Tables())
results = [] 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
@ -77,9 +88,13 @@ def compareFingerprintDir(file_in, fp_dir):
percent = db.compareDB(fq_fp) percent = db.compareDB(fq_fp)
results.append(percent) results.append(percent)
print "Table matche(s) found"
print "RESULTS: {}".format(results) print "RESULTS: {}".format(results)
results.sort() results.sort()
print "RESULTS: {}".format(results) print "RESULTS: {}".format(results)
except Exception as ex:
print "Error comparing fingerprint"
print ex
# #
def androidPull(): def androidPull():

View File

@ -148,6 +148,9 @@ class FingerprintDB:
def getMD5DB(self): def getMD5DB(self):
return self.db_hash return self.db_hash
def getMD5Tables(self):
return self.table_hashes
# #
# def getMD5Tables(self): # def getMD5Tables(self):
# if (self.table_hashes): # if (self.table_hashes):

View File

@ -72,12 +72,16 @@ class FingerprintIndex:
raise FingerprintIndexWrite("Error creating an index file\n") raise FingerprintIndexWrite("Error creating an index file\n")
return retVal return retVal
# # looking for databases with exact schema match
def findFP(self, md5_db, md5_tables): # RETURN: (fingerprint list, json_filename list, fingerprint count)
def findFP(self, md5_db):
rows = self.__qDatabaseMD5(md5_db) rows = self.__qDatabaseMD5(md5_db)
if len(rows) > 0: if len(rows) > 0:
return rows return rows
return None
# return an a list of json fingerprint files to open
def findFPTables(self, md5_tables):
for md5_table in md5_tables: for md5_table in md5_tables:
retval = {} retval = {}
rows = self.__qTableMD5(md5_table) rows = self.__qTableMD5(md5_table)
@ -86,7 +90,6 @@ class FingerprintIndex:
fps = fp_list.split(',') fps = fp_list.split(',')
for fp in fps: for fp in fps:
retval[fp] = 1 retval[fp] = 1
#print "***** __qTableMD5 *****\n{}\n".format(retval.keys())
return retval.keys() return retval.keys()
# #