From 31dcbd6d5f12e4bac9935030c11eca2ea887e566 Mon Sep 17 00:00:00 2001 From: Kashiko Koibumi Date: Thu, 30 May 2024 20:59:59 +0900 Subject: [PATCH] add script to revert BLOB-keys into TEXT-keys --- revert_blob_to_text.sh | 3 +++ src/revert_blob_to_text.py | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 revert_blob_to_text.sh create mode 100644 src/revert_blob_to_text.py diff --git a/revert_blob_to_text.sh b/revert_blob_to_text.sh new file mode 100755 index 00000000..fbac98c1 --- /dev/null +++ b/revert_blob_to_text.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +python3 pybitmessage/revert_blob_to_text.py "$@" diff --git a/src/revert_blob_to_text.py b/src/revert_blob_to_text.py new file mode 100644 index 00000000..bd38066d --- /dev/null +++ b/src/revert_blob_to_text.py @@ -0,0 +1,52 @@ +import helper_startup +import state +import shutil +import sqlite3 + +expected_ver = 11 + +print("Looking up database file..") +helper_startup.loadConfig() +db_path = state.appdata + "messages.dat" +print("Database path: {}".format(db_path)) +db_backup_path = db_path + ".blob-keys" +print("Backup path: {}".format(db_backup_path)) +shutil.copyfile(db_path, db_backup_path) +print("Copied to backup") + +print() + +print("Open the database") +conn = sqlite3.connect(db_path) +cur = conn.cursor() + +cur.execute("SELECT value FROM settings WHERE key='version';") +ver = int(cur.fetchall()[0][0]) +print("PyBitmessage database version: {}".format(ver)) +if ver != expected_ver: + print("Error: version must be {}".format(expected_ver)) + conn.close() + print("Quitting..") + quit() +print("Version OK") + +print() + +print("Converting..") +q = "UPDATE inbox SET msgid=CAST(msgid AS TEXT), sighash=CAST(sighash AS TEXT);" +print(q) +cur.execute(q) +q = "UPDATE pubkeys SET transmitdata=CAST(transmitdata AS TEXT);" +print(q) +cur.execute(q) +q = "UPDATE sent SET msgid=CAST(msgid AS TEXT), toripe=CAST(toripe AS TEXT), ackdata=CAST(ackdata AS TEXT);" +print(q) +cur.execute(q) + +print("Commiting..") +conn.commit() +print("Conversion done") + +print("Close the database") +conn.close() +print("Finished")