Last active
June 20, 2023 07:49
-
-
Save simryang/4b6fdb45ea86f1913c2e027d511d75cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # linux environment is recommended. not tested on other environment. tested on Ubuntu 20.04 | |
| # python3 leveldb_dump_joseph.py '/mnt/d/Users/USERID/Chrome/User Data/Default/Local Extension Settings/chphlpgkkbolifaimnlloiipkdnihall' > result.csv | |
| # result is tab seperated values(TSV). save result to *.csv and import on new excel documents with 'tab' seperator | |
| # original code from https://gist.github.com/dexX7/cbd16b05f1f3870b7afc | |
| # I made this code from original for recovering OneTab bookmarks | |
| import binascii | |
| import sys | |
| import json | |
| import yaml | |
| import pprint | |
| # pip3 install leveldb | |
| import leveldb | |
| def b2x(b): | |
| """Convert bytes to a hex string""" | |
| if sys.version > '3': | |
| return binascii.hexlify(b).decode('utf8') | |
| else: | |
| return binascii.hexlify(b) | |
| def db_count(filepath): | |
| """Prints number of records in LevelDB database""" | |
| db = leveldb.LevelDB(filepath) | |
| count = 1 | |
| for k in db.RangeIter(None, None, False): | |
| count += 1 | |
| print(count) | |
| def db_dump(filepath, to_hex=0): | |
| """Prints records of LevelDB database""" | |
| db = leveldb.LevelDB(filepath) | |
| for k, v in db.RangeIter(None, None): | |
| if to_hex: | |
| k = b2x(k) | |
| v = b2x(v) | |
| if k.decode() != 'state': | |
| continue | |
| # print("key=", k.decode()) | |
| # print("value=", json.loads(v.decode())) | |
| # print(v.decode()) | |
| decoded = v.decode() | |
| tmp = json.loads(decoded) | |
| tmp3 = json.loads(tmp) | |
| return tmp3 | |
| # print(yaml.dump(temp, default_flow_style=False)) | |
| # print(json.loads(v.decode())) | |
| # return json.loads(v.decode()) | |
| # print('%s %s\n' % (k, v,)) | |
| if __name__ == '__main__': | |
| if len(sys.argv) == 1: | |
| print('Dumps or counts content of one or more LevelDB databases.') | |
| print('Binary entries can be converted to hex.\n') | |
| print('Usage:') | |
| print(' python %s [--count] [--binary] path1 [path2, path3, ...]\n' % (sys.argv[0],)) | |
| print('Examples:') | |
| print(' python %s ~/.bitcoin/testnet3/MP_spinfo/' % (sys.argv[0],)) | |
| print(' python %s --count ~/.bitcoin/testnet3/MP_txlist/' % (sys.argv[0],)) | |
| print(' python %s --binary ~/.bitcoin/testnet3/chainstate/' % (sys.argv[0],)) | |
| count = 0 | |
| to_hex = 0 | |
| for arg in sys.argv[1:]: | |
| if '--count' in arg: | |
| count = 1 | |
| continue | |
| if '--binary' in arg: | |
| to_hex = 1 | |
| continue | |
| if count: | |
| db_count(arg) | |
| else: | |
| # db_dump(arg, to_hex) | |
| ret = db_dump(arg, to_hex) | |
| tablist = ret["tabGroups"] | |
| csv_list = [] | |
| for tabnode in tablist: | |
| inner = tabnode['tabsMeta'] | |
| for node in inner: | |
| csv_list.append(f"{node['title']}\t{node['url']}") | |
| csv_list.sort() | |
| for line in csv_list: | |
| print(line) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
levelup db dumper for chrome onetab plugin