diff --git a/dbfp.py b/dbfp.py index 80e49aa..f3d5634 100644 --- a/dbfp.py +++ b/dbfp.py @@ -131,6 +131,18 @@ def queryMD5(fp_dir, md5_db): except Exception as ex: print "ERROR: {}".format(ex) +# +def insertFP(db_file, fp_file, fp_idx_dir): + dbfp = FingerprintDB() + fpidx = FingerprintIndex() + fpidx.openIndex(fp_idx_dir) + if (db_file): + dbfp.scanDBFile(db_file) + # db.debugFingerprint() + fpidx.insertFP(dbfp, db_file) + elif (fp_file): + db.importJson(fp_file) + fpidx.insertFP(dbfp, fp_file) # in_dir: fully qualified directory path to find sqlite files def __createFingerprint(in_dir, out_dir, dir_name): @@ -190,7 +202,8 @@ def parseArgs(): parser.add_argument('-an', '--app_name', required=False) parser.add_argument('-av', '--app_version', required=False) parser.add_argument('-n', '--notes', required=False) - parser.add_argument('-android_pull', required=False, action='store_true', help="automated pull of applications from a physical android phone") + parser.add_argument('-idxf', action='store_true', help="add a fingerprint to the index") + parser.add_argument('-android_pull', action='store_true', help="automated pull of applications from a physical android phone") parser.add_argument('-v', '--verbose', action='store_true', help="will set logging level to INFO") parser.add_argument('-vv', '--vverbose', action='store_true', help="will set logging level to DEBUG") parser.add_argument('-l', '--logging', action='store_true', help="will supercede the -v option and send all logging to a file, logging.DEBUG") @@ -207,7 +220,9 @@ def parseArgs(): else: logging.basicConfig(level=logging.CRITICAL) - if (args.database and args.fingerprint): + if args.idxf and args.fpdir and (args.database or args.fingerprint): + insertFP(args.database, args.fingerprint, args.fpdir) + elif (args.database and args.fingerprint): compareFingerprint(args.database, args.fingerprint) elif (args.database and args.fpdir): compareFingerprintDir(args.database, args.fpdir) diff --git a/docs/devnotes b/docs/devnotes index acb0b36..8249ffc 100644 --- a/docs/devnotes +++ b/docs/devnotes @@ -22,6 +22,8 @@ http://stackoverflow.com/questions/11942762/get-application-version-name-using-a com.google.android.gms__node.db 0b48447805d645966439e1b4042d2625 +"sqlite_sequence": "079355c84d8b3b1511a504e08aab7fd2" + [ Regression Testing ] diff --git a/libs/exceptions.py b/libs/exceptions.py index 3633d65..28b5a56 100644 --- a/libs/exceptions.py +++ b/libs/exceptions.py @@ -10,6 +10,10 @@ class FingerprintIndexOpen(Exception): """Error opening an index file""" pass +class FingerprintIndexInsert(Exception): + """Error creating an index file""" + pass + class FingerprintIndexWrite(Exception): """Error creating an index file""" pass diff --git a/libs/fingerprint.py b/libs/fingerprint.py index ec44aff..bdf1117 100644 --- a/libs/fingerprint.py +++ b/libs/fingerprint.py @@ -78,6 +78,11 @@ class FingerprintDB: logging.error(ex) return -3 + # create and index of table hashes + self.table_hashes = {} + for key in self.tables.keys(): + self.table_hashes[key] = self.tables[key].hash() + # flag is used to determine if the class has data self.init = True self.filein = filein @@ -144,14 +149,15 @@ class FingerprintDB: return self.db_hash # - def getMD5Tables(self): - if (self.table_hashes): - return self.table_hashes + # def getMD5Tables(self): + # if (self.table_hashes): + # return self.table_hashes - self.table_hashes = [] - for key in self.tables.keys(): - self.table_hashes.append(self.tables[key].hash()) - return self.table_hashes + # self.table_hashes = {} + # for key in self.tables.keys(): + # self.table_hashes[key] = self.tables[key].hash() + # # self.table_hashes.append(self.tables[key].hash()) + # return self.table_hashes # def __importJsonDBSchema(self, file_json): diff --git a/libs/fingerprint_index.py b/libs/fingerprint_index.py index 7f447ab..82acb60 100644 --- a/libs/fingerprint_index.py +++ b/libs/fingerprint_index.py @@ -78,6 +78,16 @@ class FingerprintIndex: rows = self.__qDatabaseMD5(md5_db) return rows + def insertFP(self, dbfp, file_name): + print "***** ***** WTF ***** *****" + try: + print "WTF222: {}".format(dbfp.table_hashes.values()) + self.__insertMod_md5_all(dbfp.db_hash, dbfp.table_hashes.values(), file_name) + self.__insertMod_md5_tables(dbfp.table_hashes.values(), file_name) + except Exception as ex: + logging.error(ex) + raise FingerprintIndexOpen("Error inserting fingerprint into index file\n") + # def __qDatabaseMD5(self, md5_db): try: @@ -142,8 +152,6 @@ class FingerprintIndex: # only parese files with .json eextension if not re.search(r'.*\.json', file): naCount = naCount+1 - pass - #print file fq_file = fp_dir + os.path.sep + file db.importJson(fq_file) self.__insertMod_md5_all(db.db_hash, db.table_hashes.values(), file)