def delete_chrome_history(path): cols = ('url', 'title') where = "" ids_int = get_chrome_bookmark_ids(path) if ids_int: ids_str = ",".join([str(id0) for id0 in ids_int]) where = "where id not in (%s) " % ids_str cmds = __shred_sqlite_char_columns('urls', cols, where) cmds += __shred_sqlite_char_columns('visits') cols = ('lower_term', 'term') cmds += __shred_sqlite_char_columns('keyword_search_terms', cols) ver = __get_chrome_history(path) if ver >= 20: if ver >= 28: cmds += __shred_sqlite_char_columns( 'downloads', ('current_path', 'target_path')) cmds += __shred_sqlite_char_columns( 'downloads_url_chains', ('url', )) else: cmds += __shred_sqlite_char_columns( 'downloads', ('full_path', 'url')) cmds += __shred_sqlite_char_columns('segments', ('name',)) cmds += __shred_sqlite_char_columns('segment_usage') FileUtilities.execute_sqlite3(path, cmds)
def delete_chrome_history(path): """Clean history from History and Favicon files without affecting bookmarks""" cols = ('url', 'title') where = "" ids_int = get_chrome_bookmark_ids(path) if ids_int: ids_str = ",".join([str(id0) for id0 in ids_int]) where = "where id not in (%s) " % ids_str cmds = __shred_sqlite_char_columns('urls', cols, where) cmds += __shred_sqlite_char_columns('visits') cols = ('lower_term', 'term') cmds += __shred_sqlite_char_columns('keyword_search_terms', cols) ver = __get_chrome_history(path) if ver >= 20: # downloads, segments, segment_usage first seen in Chrome 14, # Google Chrome 15 (database version = 20). # Google Chrome 30 (database version 28) doesn't have full_path, but it # does have current_path and target_path if ver >= 28: cmds += __shred_sqlite_char_columns( 'downloads', ('current_path', 'target_path')) cmds += __shred_sqlite_char_columns( 'downloads_url_chains', ('url', )) else: cmds += __shred_sqlite_char_columns( 'downloads', ('full_path', 'url')) cmds += __shred_sqlite_char_columns('segments', ('name',)) cmds += __shred_sqlite_char_columns('segment_usage') FileUtilities.execute_sqlite3(path, cmds)
def delete_mozilla_favicons(path): """Delete favorites icon in Mozilla places.favicons only if they are not bookmarks (Firefox 3 and family)""" cmds = "" places_path = os.path.join(os.path.dirname(path), 'places.sqlite') cmds += "attach database \"%s\" as places;" % places_path # delete all not bookmarked icon urls urls_where = ( "where page_url not in (select url from places.moz_places where id in " "(select distinct fk from places.moz_bookmarks where fk is not null))") cmds += __shred_sqlite_char_columns('moz_pages_w_icons', ('page_url', ), urls_where) # delete all not bookmarked icons to pages mapping mapping_where = "where page_id not in (select id from moz_pages_w_icons)" cmds += __shred_sqlite_char_columns('moz_icons_to_pages', where=mapping_where) # delete all not bookmarked icons icons_where = "where (id not in (select icon_id from moz_icons_to_pages))" cols = ('icon_url', 'data') cmds += __shred_sqlite_char_columns('moz_icons', cols, where=icons_where) FileUtilities.execute_sqlite3(path, cmds)
def delete_chrome_history(path): """Clean history from History and Favicon files without affecting bookmarks""" if not os.path.exists(path): logger.debug( 'aborting delete_chrome_history() because history does not exist: %s' % path) return cols = ('url', 'title') where = "" ids_int = get_chrome_bookmark_ids(path) if ids_int: ids_str = ",".join([str(id0) for id0 in ids_int]) where = "where id not in (%s) " % ids_str cmds = __shred_sqlite_char_columns('urls', cols, where) cmds += __shred_sqlite_char_columns('visits') # Google Chrome 79 no longer has lower_term in keyword_search_terms cols = ('term', ) cmds += __shred_sqlite_char_columns('keyword_search_terms', cols) ver = __get_chrome_history(path) if ver >= 20: # downloads, segments, segment_usage first seen in Chrome 14, # Google Chrome 15 (database version = 20). # Google Chrome 30 (database version 28) doesn't have full_path, but it # does have current_path and target_path if ver >= 28: cmds += __shred_sqlite_char_columns( 'downloads', ('current_path', 'target_path')) cmds += __shred_sqlite_char_columns('downloads_url_chains', ('url', )) else: cmds += __shred_sqlite_char_columns('downloads', ('full_path', 'url')) cmds += __shred_sqlite_char_columns('segments', ('name', )) cmds += __shred_sqlite_char_columns('segment_usage') FileUtilities.execute_sqlite3(path, cmds)
def delete_chrome_favicons(path): """Delete Google Chrome and Chromium favicons not use in in history for bookmarks""" path_history = os.path.join(os.path.dirname(path), 'History') if os.path.exists(path_history): ver = __get_chrome_history(path) else: # assume it's the newer version ver = 38 cmds = "" if ver >= 4: # Version 4 includes Chromium 12 # Version 20 includes Chromium 14, Google Chrome 15, Google Chrome 19 # Version 22 includes Google Chrome 20 # Version 25 is Google Chrome 26 # Version 26 is Google Chrome 29 # Version 28 is Google Chrome 30 # Version 29 is Google Chrome 37 # Version 32 is Google Chrome 51 # Version 36 is Google Chrome 60 # Version 38 is Google Chrome 64 # Version 42 is Google Chrome 79 # icon_mapping cols = ('page_url', ) where = None if os.path.exists(path_history): cmds += "attach database \"%s\" as History;" % path_history where = "where page_url not in (select distinct url from History.urls)" cmds += __shred_sqlite_char_columns('icon_mapping', cols, where) # favicon images cols = ('image_data', ) where = "where icon_id not in (select distinct icon_id from icon_mapping)" cmds += __shred_sqlite_char_columns('favicon_bitmaps', cols, where) # favicons # Google Chrome 30 (database version 28): image_data moved to table # favicon_bitmaps if ver < 28: cols = ('url', 'image_data') else: cols = ('url', ) where = "where id not in (select distinct icon_id from icon_mapping)" cmds += __shred_sqlite_char_columns('favicons', cols, where) elif 3 == ver: # Version 3 includes Google Chrome 11 cols = ('url', 'image_data') where = None if os.path.exists(path_history): cmds += "attach database \"%s\" as History;" % path_history where = "where id not in(select distinct favicon_id from History.urls)" cmds += __shred_sqlite_char_columns('favicons', cols, where) else: raise RuntimeError('%s is version %d' % (path, ver)) FileUtilities.execute_sqlite3(path, cmds)
def test_get_sqlite_int(self): """Unit test for get_sqlite_int()""" sql = """CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,value LONGVARCHAR); INSERT INTO "meta" VALUES('version','20');""" # create test file filename = self.mkstemp(prefix='bleachbit-test-sqlite') FileUtilities.execute_sqlite3(filename, sql) self.assertExists(filename) # run the test ver = Special.get_sqlite_int(filename, 'select value from meta where key="version"') self.assertEqual(ver, [20])
def delete_chrome_favicons(path): """Delete Google Chrome and Chromium favicons not use in in history for bookmarks""" path_history = os.path.join(os.path.dirname(path), 'History') ver = __get_chrome_history(path) cmds = "" if ver >= 4: # Version 4 includes Chromium 12 # Version 20 includes Chromium 14, Google Chrome 15, Google Chrome 19 # Version 22 includes Google Chrome 20 # Version 25 is Google Chrome 26 # Version 26 is Google Chrome 29 # Version 28 is Google Chrome 30 # Version 29 is Google Chrome 37 # Version 32 is Google Chrome 51 # Version 36 is Google Chrome 60 # Version 38 is Google Chrome 64 # icon_mapping cols = ('page_url',) where = None if os.path.exists(path_history): cmds += "attach database \"%s\" as History;" % path_history where = "where page_url not in (select distinct url from History.urls)" cmds += __shred_sqlite_char_columns('icon_mapping', cols, where) # favicon images cols = ('image_data', ) where = "where icon_id not in (select distinct icon_id from icon_mapping)" cmds += __shred_sqlite_char_columns('favicon_bitmaps', cols, where) # favicons # Google Chrome 30 (database version 28): image_data moved to table # favicon_bitmaps if ver < 28: cols = ('url', 'image_data') else: cols = ('url', ) where = "where id not in (select distinct icon_id from icon_mapping)" cmds += __shred_sqlite_char_columns('favicons', cols, where) elif 3 == ver: # Version 3 includes Google Chrome 11 cols = ('url', 'image_data') where = None if os.path.exists(path_history): cmds += "attach database \"%s\" as History;" % path_history where = "where id not in(select distinct favicon_id from History.urls)" cmds += __shred_sqlite_char_columns('favicons', cols, where) else: raise RuntimeError('%s is version %d' % (path, ver)) FileUtilities.execute_sqlite3(path, cmds)
def test_get_sqlite_int(self): """Unit test for get_sqlite_int()""" sql = """CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,value LONGVARCHAR); INSERT INTO "meta" VALUES('version','20');""" # create test file filename = self.mkstemp(prefix='bleachbit-test-sqlite') FileUtilities.execute_sqlite3(filename, sql) self.assertExists(filename) # run the test ver = Special.get_sqlite_int(filename, 'select value from meta where key="version"') self.assertEqual(ver, [20])
def delete_chrome_keywords(path): cols = ('short_name', 'keyword', 'favicon_url', 'originating_url', 'suggest_url') where = "where not date_created = 0" cmds = __shred_sqlite_char_columns('keywords', cols, where) cmds += "update keywords set usage_count = 0;" ver = __get_chrome_history(path, 'Web Data') if 43 <= ver < 49: cmds += __shred_sqlite_char_columns('keywords_backup', cols, where) cmds += "update keywords_backup set usage_count = 0;" FileUtilities.execute_sqlite3(path, cmds)
def sqlite_clean_helper(self, sql, fn, clean_func, check_func=None, setup_func=None): """Helper for cleaning special SQLite cleaning""" self.assertFalse( sql and fn, "sql and fn are mutually exclusive ways to create the data") if fn: filename = os.path.normpath(os.path.join(self.dir_base, fn)) self.assertExists(filename) # create sqlite file elif sql: # create test file filename = self.mkstemp(prefix='bleachbit-test-sqlite') # additional setup if setup_func: setup_func(filename) # before SQL creation executed, cleaning should fail self.assertRaises(sqlite3.DatabaseError, clean_func, filename) # create FileUtilities.execute_sqlite3(filename, sql) self.assertExists(filename) else: raise RuntimeError('neither fn nor sql supplied') # clean the file old_shred = options.get('shred') options.set('shred', False, commit=False) self.assertFalse(options.get('shred')) clean_func(filename) options.set('shred', True, commit=False) self.assertTrue(options.get('shred')) options.set('shred', old_shred, commit=False) clean_func(filename) self.assertExists(filename) # check if check_func: check_func(self, filename) # tear down FileUtilities.delete(filename) self.assertNotExists(filename)
def delete_mozilla_url_history(path): """Delete URL history in Mozilla places.sqlite (Firefox 3 and family)""" cmds = "" # delete the URLs in moz_places places_suffix = "where id in (select " \ "moz_places.id from moz_places " \ "left join moz_bookmarks on moz_bookmarks.fk = moz_places.id " \ "where moz_bookmarks.id is null); " cols = ('url', 'rev_host', 'title') cmds += __shred_sqlite_char_columns('moz_places', cols, places_suffix) # delete any orphaned annotations in moz_annos annos_suffix = "where id in (select moz_annos.id " \ "from moz_annos " \ "left join moz_places " \ "on moz_annos.place_id = moz_places.id " \ "where moz_places.id is null); " cmds += __shred_sqlite_char_columns( 'moz_annos', ('content', ), annos_suffix) # delete any orphaned favicons fav_suffix = "where id not in (select favicon_id " \ "from moz_places where favicon_id is not null ); " if __sqlite_table_exists(path, 'moz_favicons'): cols = ('url', 'data') cmds += __shred_sqlite_char_columns('moz_favicons', cols, fav_suffix) # delete any orphaned history visits cmds += "delete from moz_historyvisits where place_id not " \ "in (select id from moz_places where id is not null); " # delete any orphaned input history input_suffix = "where place_id not in (select distinct id from moz_places)" cols = ('input', ) cmds += __shred_sqlite_char_columns('moz_inputhistory', cols, input_suffix) # delete the whole moz_hosts table # Reference: https://bugzilla.mozilla.org/show_bug.cgi?id=932036 # Reference: # https://support.mozilla.org/en-US/questions/937290#answer-400987 if __sqlite_table_exists(path, 'moz_hosts'): cmds += __shred_sqlite_char_columns('moz_hosts', ('host',)) cmds += "delete from moz_hosts;" # execute the commands FileUtilities.execute_sqlite3(path, cmds)
def delete_mozilla_url_history(path): """Delete URL history in Mozilla places.sqlite (Firefox 3 and family)""" cmds = "" # delete the URLs in moz_places places_suffix = "where id in (select " \ "moz_places.id from moz_places " \ "left join moz_bookmarks on moz_bookmarks.fk = moz_places.id " \ "where moz_bookmarks.id is null); " cols = ('url', 'rev_host', 'title') cmds += __shred_sqlite_char_columns('moz_places', cols, places_suffix) # delete any orphaned annotations in moz_annos annos_suffix = "where id in (select moz_annos.id " \ "from moz_annos " \ "left join moz_places " \ "on moz_annos.place_id = moz_places.id " \ "where moz_places.id is null); " cmds += __shred_sqlite_char_columns( 'moz_annos', ('content', ), annos_suffix) # delete any orphaned favicons fav_suffix = "where id not in (select favicon_id " \ "from moz_places where favicon_id is not null ); " if __sqlite_table_exists(path, 'moz_favicons'): cols = ('url', 'data') cmds += __shred_sqlite_char_columns('moz_favicons', cols, fav_suffix) # delete any orphaned history visits cmds += "delete from moz_historyvisits where place_id not " \ "in (select id from moz_places where id is not null); " # delete any orphaned input history input_suffix = "where place_id not in (select distinct id from moz_places)" cols = ('input', ) cmds += __shred_sqlite_char_columns('moz_inputhistory', cols, input_suffix) # delete the whole moz_hosts table # Reference: https://bugzilla.mozilla.org/show_bug.cgi?id=932036 # Reference: # https://support.mozilla.org/en-US/questions/937290#answer-400987 if __sqlite_table_exists(path, 'moz_hosts'): cmds += __shred_sqlite_char_columns('moz_hosts', ('host',)) cmds += "delete from moz_hosts;" # execute the commands FileUtilities.execute_sqlite3(path, cmds)
def delete_chrome_keywords(path): """Delete keywords table in Chromium/Google Chrome 'Web Data' database""" cols = ('short_name', 'keyword', 'favicon_url', 'originating_url', 'suggest_url') where = "where not date_created = 0" cmds = __shred_sqlite_char_columns('keywords', cols, where) cmds += "update keywords set usage_count = 0;" ver = __get_chrome_history(path, 'Web Data') if 43 <= ver < 49: # keywords_backup table first seen in Google Chrome 17 / Chromium 17 which is Web Data version 43 # In Google Chrome 25, the table is gone. cmds += __shred_sqlite_char_columns('keywords_backup', cols, where) cmds += "update keywords_backup set usage_count = 0;" FileUtilities.execute_sqlite3(path, cmds)
def delete_chrome_autofill(path): cols = ('name', 'value', 'value_lower') cmds = __shred_sqlite_char_columns('autofill', cols) cols = ('first_name', 'middle_name', 'last_name', 'full_name') cmds += __shred_sqlite_char_columns('autofill_profile_names', cols) cmds += __shred_sqlite_char_columns('autofill_profile_emails', ('email',)) cmds += __shred_sqlite_char_columns('autofill_profile_phones', ('number',)) cols = ('company_name', 'street_address', 'dependent_locality', 'city', 'state', 'zipcode', 'country_code') cmds += __shred_sqlite_char_columns('autofill_profiles', cols) cols = ( 'company_name', 'street_address', 'address_1', 'address_2', 'address_3', 'address_4', 'postal_code', 'country_code', 'language_code', 'recipient_name', 'phone_number') cmds += __shred_sqlite_char_columns('server_addresses', cols) FileUtilities.execute_sqlite3(path, cmds)
def delete_chrome_keywords(path): """Delete keywords table in Chromium/Google Chrome 'Web Data' database""" cols = ('short_name', 'keyword', 'favicon_url', 'originating_url', 'suggest_url') where = "where not date_created = 0" cmds = __shred_sqlite_char_columns('keywords', cols, where) cmds += "update keywords set usage_count = 0;" ver = __get_chrome_history(path, 'Web Data') if 43 <= ver < 49: # keywords_backup table first seen in Google Chrome 17 / Chromium 17 which is Web Data version 43 # In Google Chrome 25, the table is gone. cmds += __shred_sqlite_char_columns('keywords_backup', cols, where) cmds += "update keywords_backup set usage_count = 0;" FileUtilities.execute_sqlite3(path, cmds)
def delete_mozilla_url_history(path): cmds = "" // moz_place에 있는 URL 삭제 places_suffix = "where id in (select " \ "moz_places.id from moz_places " \ "left join moz_bookmarks on moz_bookmarks.fk = moz_places.id " \ "where moz_bookmarks.id is null); " cols = ('url', 'rev_host', 'title') cmds += __shred_sqlite_char_columns('moz_places', cols, places_suffix) //moz_annos에 있는 주석 삭제 annos_suffix = "where id in (select moz_annos.id " \ "from moz_annos " \ "left join moz_places " \ "on moz_annos.place_id = moz_places.id " \ "where moz_places.id is null); " cmds += __shred_sqlite_char_columns( 'moz_annos', ('content', ), annos_suffix) // favicons 삭제 fav_suffix = "where id not in (select favicon_id " \ "from moz_places where favicon_id is not null ); " if __sqlite_table_exists(path, 'moz_favicons'): cols = ('url', 'data') cmds += __shred_sqlite_char_columns('moz_favicons', cols, fav_suffix) // 방문 기록 삭제 cmds += "delete from moz_historyvisits where place_id not " \ "in (select id from moz_places where id is not null); " // input 기록 삭제 input_suffix = "where place_id not in (select distinct id from moz_places)" cols = ('input', ) cmds += __shred_sqlite_char_columns('moz_inputhistory', cols, input_suffix) // moz_hosts 전체 테이블 삭제 if __sqlite_table_exists(path, 'moz_hosts'): cmds += __shred_sqlite_char_columns('moz_hosts', ('host',)) cmds += "delete from moz_hosts;" // commend 실행 FileUtilities.execute_sqlite3(path, cmds)
def delete_chrome_autofill(path): """Delete autofill table in Chromium/Google Chrome 'Web Data' database""" cols = ('name', 'value', 'value_lower') cmds = __shred_sqlite_char_columns('autofill', cols) cols = ('first_name', 'middle_name', 'last_name', 'full_name') cmds += __shred_sqlite_char_columns('autofill_profile_names', cols) cmds += __shred_sqlite_char_columns('autofill_profile_emails', ('email',)) cmds += __shred_sqlite_char_columns('autofill_profile_phones', ('number',)) cols = ('company_name', 'street_address', 'dependent_locality', 'city', 'state', 'zipcode', 'country_code') cmds += __shred_sqlite_char_columns('autofill_profiles', cols) cols = ( 'company_name', 'street_address', 'address_1', 'address_2', 'address_3', 'address_4', 'postal_code', 'country_code', 'language_code', 'recipient_name', 'phone_number') cmds += __shred_sqlite_char_columns('server_addresses', cols) FileUtilities.execute_sqlite3(path, cmds)
def setUp(self): """Create test browser files.""" super(SpecialTestCase, self).setUp() self.dir_base = self.mkdtemp(prefix='bleachbit-test-special') dir_google_chrome_default = os.path.join(self.dir_base, 'google-chrome/Default/') os.makedirs(dir_google_chrome_default) # google-chrome/Default/Bookmarks bookmark_path = os.path.join(dir_google_chrome_default, 'Bookmarks') with open(bookmark_path, 'wb') as f: f.write(chrome_bookmarks) # google-chrome/Default/Web Data FileUtilities.execute_sqlite3( os.path.join(dir_google_chrome_default, 'Web Data'), chrome_webdata) # google-chrome/Default/History FileUtilities.execute_sqlite3( os.path.join(dir_google_chrome_default, 'History'), chrome_history_sql) # google-chrome/Default/databases/Databases.db os.makedirs(os.path.join(dir_google_chrome_default, 'databases')) FileUtilities.execute_sqlite3( os.path.join(dir_google_chrome_default, 'databases/Databases.db'), chrome_databases_db) dir_firefox_default = os.path.join(self.dir_base, 'firefox/default-release/') os.makedirs(dir_firefox_default) # firefox/xxxxx.default-release/places.sqlite FileUtilities.execute_sqlite3( os.path.join(dir_firefox_default, 'places.sqlite'), firefox78_places_sql) # firefox/xxxxx.default-release/favicons.sqlite FileUtilities.execute_sqlite3( os.path.join(dir_firefox_default, 'favicons.sqlite'), firefox78_favicons_sql)
def sqlite_clean_helper(self, sql, fn, clean_func, check_func=None, setup_func=None): """Helper for cleaning special SQLite cleaning""" self.assertFalse(sql and fn, "sql and fn are mutually exclusive ways to create the data") if fn: filename = os.path.normpath(os.path.join(self.dir_base, fn)) self.assertExists(filename) # create sqlite file elif sql: # create test file filename = self.mkstemp(prefix='bleachbit-test-sqlite') # additional setup if setup_func: setup_func(filename) # before SQL creation executed, cleaning should fail self.assertRaises(sqlite3.DatabaseError, clean_func, filename) # create FileUtilities.execute_sqlite3(filename, sql) self.assertExists(filename) else: raise RuntimeError('neither fn nor sql supplied') # clean the file old_shred = options.get('shred') options.set('shred', False, commit=False) self.assertFalse(options.get('shred')) clean_func(filename) options.set('shred', True, commit=False) self.assertTrue(options.get('shred')) options.set('shred', old_shred, commit=False) clean_func(filename) self.assertExists(filename) # check if check_func: check_func(self, filename) # tear down FileUtilities.delete(filename) self.assertNotExists(filename)
def setUp(self): """Create test browser files.""" super(SpecialTestCase, self).setUp() self.dir_base = self.mkdtemp(prefix='bleachbit-test-special') self.dir_google_chrome_default = os.path.join( self.dir_base, 'google-chrome/Default/') os.makedirs(self.dir_google_chrome_default) # google-chrome/Default/Bookmarks bookmark_path = os.path.join(self.dir_google_chrome_default, 'Bookmarks') f = open(bookmark_path, 'w') f.write(chrome_bookmarks) f.close() # google-chrome/Default/Web Data FileUtilities.execute_sqlite3( os.path.join(self.dir_google_chrome_default, 'Web Data'), chrome_webdata) # google-chrome/Default/History FileUtilities.execute_sqlite3( os.path.join(self.dir_google_chrome_default, 'History'), chrome_history_sql) # google-chrome/Default/databases/Databases.db os.makedirs(os.path.join(self.dir_google_chrome_default, 'databases')) FileUtilities.execute_sqlite3( os.path.join(self.dir_google_chrome_default, 'databases/Databases.db'), chrome_databases_db)
def setUp(self): """Create test browser files.""" super(SpecialTestCase, self).setUp() self.dir_base = self.mkdtemp(prefix='bleachbit-test-special') self.dir_google_chrome_default = os.path.join(self.dir_base, 'google-chrome/Default/') os.makedirs(self.dir_google_chrome_default) # google-chrome/Default/Bookmarks bookmark_path = os.path.join( self.dir_google_chrome_default, 'Bookmarks') f = open(bookmark_path, 'w') f.write(chrome_bookmarks) f.close() # google-chrome/Default/Web Data FileUtilities.execute_sqlite3(os.path.join(self.dir_google_chrome_default, 'Web Data'), chrome_webdata) # google-chrome/Default/History FileUtilities.execute_sqlite3(os.path.join(self.dir_google_chrome_default, 'History'), chrome_history_sql) # google-chrome/Default/databases/Databases.db os.makedirs(os.path.join(self.dir_google_chrome_default, 'databases')) FileUtilities.execute_sqlite3( os.path.join(self.dir_google_chrome_default, 'databases/Databases.db'), chrome_databases_db)
def delete_mozilla_favicons(path): """Delete favorites icon in Mozilla places.favicons only if they are not bookmarks (Firefox 3 and family)""" # Use list here because some urls contain semicolon and this # way we aviod wrongly splitting by semicolon in execute_sqlite3. cmds = [] # collect bookmarked urls places_path = os.path.join(os.path.dirname(path), 'places.sqlite') bookmark_urls_cmd = ( "select url from moz_places where id in (select distinct fk from moz_bookmarks where fk is not null)" ) bookmark_urls = get_sqlite(places_path, bookmark_urls_cmd, element_type=str) bookmark_urls = ",".join( ["'{}'".format(url.replace("'", "''")) for url in bookmark_urls]) # delete all not bookmarked icon urls urls_where = "where (page_url not in ({}))".format(bookmark_urls) cmds.append( __shred_sqlite_char_columns('moz_pages_w_icons', ('page_url', ), urls_where)) # delete all not bookmarked icons to pages mapping mapping_where = "where (page_id not in (select id from moz_pages_w_icons))" cmds.append( __shred_sqlite_char_columns('moz_icons_to_pages', where=mapping_where)) # delete all not bookmarked icons icons_where = "where (id not in (select icon_id from moz_icons_to_pages))" cols = ('icon_url', 'data') cmds.append( __shred_sqlite_char_columns('moz_icons', cols, where=icons_where)) FileUtilities.execute_sqlite3(path, None, cmds_as_list=cmds)
def delete_mozilla_url_history(path): """Delete URL history in Mozilla places.sqlite (Firefox 3 and family)""" cmds = "" # delete the URLs in moz_places places_suffix = "where id in (select " \ "moz_places.id from moz_places " \ "left join moz_bookmarks on moz_bookmarks.fk = moz_places.id " \ "where moz_bookmarks.id is null); " cols = ('url', 'rev_host', 'title') cmds += __shred_sqlite_char_columns('moz_places', cols, places_suffix) # For any bookmarks that remain in moz_places, reset the non-character values. cmds += "update moz_places set visit_count=0, frecency=-1, last_visit_date=null;" # delete any orphaned annotations in moz_annos annos_suffix = "where id in (select moz_annos.id " \ "from moz_annos " \ "left join moz_places " \ "on moz_annos.place_id = moz_places.id " \ "where moz_places.id is null); " cmds += __shred_sqlite_char_columns('moz_annos', ('content', ), annos_suffix) # Delete any orphaned favicons. # Firefox 78 no longer has a table named moz_favicons, and it no longer has # a column favicon_id in the table moz_places. (This change probably happened before version 78.) if __sqlite_table_exists(path, 'moz_favicons'): fav_suffix = "where id not in (select favicon_id " \ "from moz_places where favicon_id is not null ); " cols = ('url', 'data') cmds += __shred_sqlite_char_columns('moz_favicons', cols, fav_suffix) # Delete orphaned origins. if __sqlite_table_exists(path, 'moz_origins'): origins_where = 'where id not in (select distinct origin_id from moz_places)' cmds += __shred_sqlite_char_columns('moz_origins', ('host', ), origins_where) # For any remaining origins, reset the statistic. cmds += "update moz_origins set frecency=-1;" if __sqlite_table_exists(path, 'moz_meta'): cmds += "delete from moz_meta where key like 'origin_frecency_%';" # Delete all history visits. cmds += "delete from moz_historyvisits;" # delete any orphaned input history input_suffix = "where place_id not in (select distinct id from moz_places)" cols = ('input', ) cmds += __shred_sqlite_char_columns('moz_inputhistory', cols, input_suffix) # delete the whole moz_hosts table # Reference: https://bugzilla.mozilla.org/show_bug.cgi?id=932036 # Reference: # https://support.mozilla.org/en-US/questions/937290#answer-400987 if __sqlite_table_exists(path, 'moz_hosts'): cmds += __shred_sqlite_char_columns('moz_hosts', ('host', )) cmds += "delete from moz_hosts;" # execute the commands FileUtilities.execute_sqlite3(path, cmds)
def delete_chrome_databases_db(path): """Delete remote HTML5 cookies (avoiding extension data) from the Databases.db file""" cols = ('origin', 'name', 'description') where = "where origin not like 'chrome-%'" cmds = __shred_sqlite_char_columns('Databases', cols, where) FileUtilities.execute_sqlite3(path, cmds)
def delete_chrome_databases_db(path): cols = ('origin', 'name', 'description') where = "where origin not like 'chrome-%'" cmds = __shred_sqlite_char_columns('Databases', cols, where) FileUtilities.execute_sqlite3(path, cmds)
else: cols = ('url', ) where = "where id not in (select distinct icon_id from icon_mapping)" cmds += __shred_sqlite_char_columns('favicons', cols, where) elif 3 == ver: cols = ('url', 'image_data') where = None if os.path.exists(path_history): cmds += "attach database \"%s\" as History;" % path_history where = "where id not in(select distinct favicon_id from History.urls)" cmds += __shred_sqlite_char_columns('favicons', cols, where) else: raise RuntimeError('%s is version %d' % (path, ver)) FileUtilities.execute_sqlite3(path, cmds) // 북마크에 영향을 주지 않고 기록 및 Favicon 파일의 기록 정리 함수 def delete_chrome_history(path): cols = ('url', 'title') where = "" ids_int = get_chrome_bookmark_ids(path) if ids_int: ids_str = ",".join([str(id0) for id0 in ids_int]) where = "where id not in (%s) " % ids_str cmds = __shred_sqlite_char_columns('urls', cols, where) cmds += __shred_sqlite_char_columns('visits') cols = ('lower_term', 'term') cmds += __shred_sqlite_char_columns('keyword_search_terms', cols) ver = __get_chrome_history(path) if ver >= 20:
def delete_chrome_databases_db(path): """Delete remote HTML5 cookies (avoiding extension data) from the Databases.db file""" cols = ('origin', 'name', 'description') where = "where origin not like 'chrome-%'" cmds = __shred_sqlite_char_columns('Databases', cols, where) FileUtilities.execute_sqlite3(path, cmds)