diff --git a/dbfp.py b/dbfp.py index d656102..29a8f28 100644 --- a/dbfp.py +++ b/dbfp.py @@ -28,10 +28,9 @@ def compareFingerprint(file_in, file_json): # def createFingerprint(file_in, app_name, app_ver, notes): print "Reading database file: {}".format(file_in) - db = FingerprintDB() - retVal = db.scanDBFile(file_in) - - if (retVal > 0): + try: + db = FingerprintDB() + db.scanDBFile(file_in) if app_name: db.setAppName(app_name) if app_ver: @@ -40,8 +39,8 @@ def createFingerprint(file_in, app_name, app_ver, notes): db.setNotes(notes) filename = db.writeFingerprint() print "Fingerprint generated: {}".format(filename) - else: - print db.getErrorString(retVal) + except Exception as ex: + print ex # def indexFingerprints(fp_dir): @@ -59,26 +58,28 @@ def indexFingerprints(fp_dir): print " {} files skipped (N/A, not a fingerprint file)".format(retVal[2]) print except Exception as ex: - print "ERROR: issue creating the index\n{}\n".format(ex) + print "ERROR: issue creating the index\n{}".format(ex) # def compareFingerprintDir(file_in, fp_dir): try: db = FingerprintDB() db.scanDBFile(file_in) + + logging.info("MD5 DB == {}".format(db.getMD5DB())) + logging.info("MD5 TB == {}".format(db.getMD5Tables())) + fp = FingerprintIndex() fp.openIndex(fp_dir) # search for fingerprints with exact database match - # fp_ret = fp.findFP(db.getMD5DB()) - fp_ret = None + 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: logging.info("Searching for md5 tables: {}".format(db.getMD5Tables())) @@ -124,7 +125,7 @@ def androidPull(): fin_count += count print "Fingerprints created: {}".format(str(count)) - print "\nTotal Fingerprints created: {}\n".format(str(fin_count)) + print "\nTotal Fingerprints created: {}".format(str(fin_count)) # def androidData(data_dir): @@ -147,7 +148,7 @@ def androidData(data_dir): count = __createFingerprint(in_dir, out_dir, ddir) fin_count += count - print "COMPLETED: created {} fingerprints\n".format(str(fin_count)) + print "COMPLETED: created {} fingerprints".format(str(fin_count)) # def queryMD5(fp_dir, md5_db): @@ -275,3 +276,4 @@ def parseArgs(): if __name__ == "__main__": main() + print diff --git a/libs/exceptions.py b/libs/exceptions.py index 28b5a56..3bd2aef 100644 --- a/libs/exceptions.py +++ b/libs/exceptions.py @@ -6,6 +6,10 @@ class FingerprintWrite(Exception): """Error writing the fingerprint to a file""" pass +class FingerprintReadNoData(Exception): + """File contains no data""" + pass + class FingerprintIndexOpen(Exception): """Error opening an index file""" pass @@ -21,3 +25,4 @@ class FingerprintIndexWrite(Exception): class FingerprintMD5(Exception): """Error creating an MD5 sum""" pass + diff --git a/libs/fingerprint.py b/libs/fingerprint.py index 92517bc..21386d8 100644 --- a/libs/fingerprint.py +++ b/libs/fingerprint.py @@ -8,7 +8,7 @@ import hashlib import time import logging from libs.toolbox import ToolBox -from libs.exceptions import FingerprintWrite, FingerprintMD5 +from libs.exceptions import FingerprintWrite, FingerprintMD5, FingerprintReadNoData delimeter = "|" @@ -62,7 +62,7 @@ class FingerprintDB: (self.conn, self.cur) = self.__openDB(filein) except Exception, ex: logging.info(ex) - return -2 + raise try: # extract file name from path+filename @@ -76,20 +76,16 @@ class FingerprintDB: self.__createMD5DB() except Exception as ex: logging.error(ex) - return -3 + raise # create and index of table hashes self.table_hashes = {} - print "*****" - print self.tables for key in self.tables.keys(): - print self.tables[key] self.table_hashes[key] = self.tables[key].hash() # flag is used to determine if the class has data self.init = True self.filein = filein - return 1 # def writeFingerprint(self): @@ -278,22 +274,24 @@ class FingerprintDB: # read a sqlite database by parsing the create table strings # sqlmaster = "SELECT name, sql FROM sqlite_master WHERE type='table'" def __readDatabase(self): + flag = False rows = self.cur.execute(self.sqlmaster) - row = self.cur.fetchone() - if (not row): - raise Exception - - newTable = TableSchema() - newTable.loadTable(row[0], row[1]) - self.table_names.append(newTable.name()) - self.tables[newTable.name()] = newTable + # row = self.cur.fetchone() + # newTable = TableSchema() + # newTable.loadTable(row[0], row[1]) + # self.table_names.append(newTable.name()) + # self.tables[newTable.name()] = newTable for row in rows: + flag = True newTable = TableSchema() newTable.loadTable(row[0], row[1]) self.table_names.append(newTable.name()) self.tables[newTable.name()] = newTable + if (not flag): + raise FingerprintReadNoData("No data, possible zero byte file") + # def debugFingerprint(self): if self.tables: