Skip to content

Instantly share code, notes, and snippets.

@o0101
Forked from simon816/chrome_bookmark_checksum.py
Created January 2, 2022 16:21
Show Gist options
  • Save o0101/53e2d0159bc60fbff55abc9f60e36da0 to your computer and use it in GitHub Desktop.
Save o0101/53e2d0159bc60fbff55abc9f60e36da0 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