Skip to content

Instantly share code, notes, and snippets.

@simon816
Created August 21, 2018 16:15
Show Gist options
  • Save simon816/afde4d57d5dab8e80120e35596008834 to your computer and use it in GitHub Desktop.
Save simon816/afde4d57d5dab8e80120e35596008834 to your computer and use it in GitHub Desktop.
Calculate Chrome bookmarks checksum
from hashlib import md5
# See https://chromium.googlesource.com/chromium/src/+/master/components/bookmarks/browser/bookmark_codec.cc
def regen_checksum(roots):
digest = md5()
def digest_url(url):
digest.update(url['id'].encode('ascii'))
digest.update(url['name'].encode('UTF-16-LE'))
digest.update(b'url')
digest.update(url['url'].encode('ascii'))
def digest_folder(folder):
digest.update(folder['id'].encode('ascii'))
digest.update(folder['name'].encode('UTF-16-LE'))
digest.update(b'folder')
for child in folder['children']:
update_digest(child)
def update_digest(node):
{
'folder': digest_folder,
'url': digest_url
}[node['type']](node)
update_digest(roots['bookmark_bar'])
update_digest(roots['other'])
update_digest(roots['synced'])
return digest.hexdigest()
if __name__ == '__main__':
import json
import sys
if len(sys.argv) != 2:
print("Usage:", sys.argv[0], "<Bookmarks JSON file>")
exit(1)
with open(sys.argv[1], 'r', encoding='utf8') as f:
bookmarks = json.load(f)
print(regen_checksum(bookmarks['roots']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment